kopia lustrzana https://github.com/sh123/esp32_loraprs
Allow specifying some more lora parameters from config.h
rodzic
fb541e2a48
commit
886a0a91d5
16
config.h
16
config.h
|
@ -53,13 +53,15 @@
|
||||||
#define CFG_LORA_USE_CAD true // set to true to utilize carrier detection
|
#define CFG_LORA_USE_CAD true // set to true to utilize carrier detection
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// lora protocol default parameters
|
// lora protocol default parameters (they need to match between devices!!!)
|
||||||
#define CFG_LORA_FREQ 433.775E6
|
#define CFG_LORA_FREQ 433.775e6 // frequency in MHz
|
||||||
#define CFG_LORA_BW 125e3
|
#define CFG_LORA_BW 125e3 // bandwidth (from 7.8 kHz up to 500 kHz)
|
||||||
#define CFG_LORA_SF 12
|
#define CFG_LORA_SF 12 // spreading factor (7 - 12)
|
||||||
#define CFG_LORA_CR 7
|
#define CFG_LORA_CR 7 // coding rate (5 - 8)
|
||||||
#define CFG_LORA_PWR 20
|
#define CFG_LORA_CRC 1 // 0 - disabled, 1 - 1 byte, 2 - 2 bytes
|
||||||
#define CFG_LORA_ENABLE_CRC true // set to false for speech data
|
#define CFG_LORA_EXPLICIT true // header mode, true - explicit, false - implicit
|
||||||
|
#define CFG_LORA_SYNC 0x34 // sync word (0x12 - private, 0x34 - public)
|
||||||
|
#define CFG_LORA_PWR 20 // output power in dBm
|
||||||
|
|
||||||
// wifi client and AP options
|
// wifi client and AP options
|
||||||
#define CFG_WIFI_ENABLE_AP false // run as wifi access point (for CFG_KISS_TCP_IP mode)
|
#define CFG_WIFI_ENABLE_AP false // run as wifi access point (for CFG_KISS_TCP_IP mode)
|
||||||
|
|
|
@ -30,14 +30,15 @@ void initializeConfig(LoraPrs::Config &cfg) {
|
||||||
// client/server mode switch
|
// client/server mode switch
|
||||||
cfg.IsClientMode = CFG_IS_CLIENT_MODE;
|
cfg.IsClientMode = CFG_IS_CLIENT_MODE;
|
||||||
|
|
||||||
// lora parameters
|
// lora parameters, mus match on devices
|
||||||
cfg.LoraFreq = CFG_LORA_FREQ;
|
cfg.LoraFreq = CFG_LORA_FREQ;
|
||||||
cfg.LoraBw = CFG_LORA_BW;
|
cfg.LoraBw = CFG_LORA_BW;
|
||||||
cfg.LoraSf = CFG_LORA_SF;
|
cfg.LoraSf = CFG_LORA_SF;
|
||||||
cfg.LoraCodingRate = CFG_LORA_CR;
|
cfg.LoraCodingRate = CFG_LORA_CR;
|
||||||
cfg.LoraSync = 0x34;
|
cfg.LoraSync = CFG_LORA_SYNC;
|
||||||
|
cfg.LoraCrc = CFG_LORA_CRC; // set to 0 to disable
|
||||||
|
cfg.LoraExplicit = CFG_LORA_EXPLICIT;
|
||||||
cfg.LoraPower = CFG_LORA_PWR;
|
cfg.LoraPower = CFG_LORA_PWR;
|
||||||
cfg.LoraEnableCrc = CFG_LORA_ENABLE_CRC; // set to false for speech streaming data
|
|
||||||
|
|
||||||
// lora pinouts
|
// lora pinouts
|
||||||
cfg.LoraPinSs = CFG_LORA_PIN_SS;
|
cfg.LoraPinSs = CFG_LORA_PIN_SS;
|
||||||
|
|
|
@ -17,8 +17,9 @@ struct Config
|
||||||
int LoraSf; // lora spreading factor, e.g. 12
|
int LoraSf; // lora spreading factor, e.g. 12
|
||||||
int LoraCodingRate; // lora coding rate, e.g. 7
|
int LoraCodingRate; // lora coding rate, e.g. 7
|
||||||
int LoraPower; // lora power level in dbm, 20
|
int LoraPower; // lora power level in dbm, 20
|
||||||
int LoraSync; // lora sync word/packet id, 0x3f
|
int LoraSync; // lora sync word/packet id, 0x34
|
||||||
bool LoraEnableCrc; // lora crc check enabled
|
int LoraCrc; // lora crc mode, 0 - disabled, 1 - 1 byte, 2 - 2 bytes
|
||||||
|
bool LoraExplicit; // lora header mode, true - explicit, false - implicit
|
||||||
|
|
||||||
// lora hardware pinouts and isr
|
// lora hardware pinouts and isr
|
||||||
byte LoraPinSs; // lora ss pin
|
byte LoraPinSs; // lora ss pin
|
||||||
|
|
|
@ -68,7 +68,7 @@ void Service::setup(const Config &conf)
|
||||||
|
|
||||||
// peripherals, LoRa
|
// peripherals, LoRa
|
||||||
setupLora(config_.LoraFreq, config_.LoraBw, config_.LoraSf,
|
setupLora(config_.LoraFreq, config_.LoraBw, config_.LoraSf,
|
||||||
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, config_.LoraEnableCrc);
|
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, config_.LoraCrc, config_.LoraExplicit);
|
||||||
|
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
if (!config_.LoraUseIsr) {
|
if (!config_.LoraUseIsr) {
|
||||||
|
@ -193,18 +193,20 @@ bool Service::reconnectAprsis()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int sync, bool enableCrc)
|
void Service::setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit)
|
||||||
{
|
{
|
||||||
|
isImplicitHeaderMode_ = !isExplicit;
|
||||||
|
isImplicitHeaderMode_ = sf == 6; // must be implicit for SF6
|
||||||
|
|
||||||
LOG_INFO("Initializing LoRa");
|
LOG_INFO("Initializing LoRa");
|
||||||
LOG_INFO("Frequency:", loraFreq, "Hz");
|
LOG_INFO("Frequency:", loraFreq, "Hz");
|
||||||
LOG_INFO("Bandwidth:", bw, "Hz");
|
LOG_INFO("Bandwidth:", bw, "Hz");
|
||||||
LOG_INFO("Spreading:", sf);
|
LOG_INFO("Spreading:", sf);
|
||||||
LOG_INFO("Coding rate:", cr);
|
LOG_INFO("Coding rate:", cr);
|
||||||
LOG_INFO("Power:", pwr, "dBm");
|
LOG_INFO("Power:", pwr, "dBm");
|
||||||
LOG_INFO("Sync:", "0x" + String(sync, 16));
|
LOG_INFO("Sync:", "0x" + String(sync, HEX));
|
||||||
LOG_INFO("CRC:", enableCrc ? "enabled" : "disabled");
|
LOG_INFO("CRC:", crcBytes);
|
||||||
|
LOG_INFO("Header:", isImplicitHeaderMode_ ? "implicit" : "explicit");
|
||||||
isImplicitHeaderMode_ = sf == 6;
|
|
||||||
|
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
radio_ = std::make_shared<MODULE_NAME>(new Module(config_.LoraPinSs, config_.LoraPinA, config_.LoraPinRst, config_.LoraPinB));
|
radio_ = std::make_shared<MODULE_NAME>(new Module(config_.LoraPinSs, config_.LoraPinA, config_.LoraPinRst, config_.LoraPinB));
|
||||||
|
@ -212,8 +214,7 @@ void Service::setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int syn
|
||||||
if (state != ERR_NONE) {
|
if (state != ERR_NONE) {
|
||||||
LOG_ERROR("Radio start error:", state);
|
LOG_ERROR("Radio start error:", state);
|
||||||
}
|
}
|
||||||
radio_->setCRC(enableCrc);
|
radio_->setCRC(crcBytes);
|
||||||
//radio_->forceLDRO(false);
|
|
||||||
#ifdef USE_SX126X
|
#ifdef USE_SX126X
|
||||||
#pragma message("Using SX126X")
|
#pragma message("Using SX126X")
|
||||||
LOG_INFO("Using SX126X module");
|
LOG_INFO("Using SX126X module");
|
||||||
|
@ -235,6 +236,12 @@ void Service::setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int syn
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (isImplicitHeaderMode_) {
|
||||||
|
radio_->implicitHeader(0xff);
|
||||||
|
} else {
|
||||||
|
radio_->explicitHeader();
|
||||||
|
}
|
||||||
|
|
||||||
state = radio_->startReceive();
|
state = radio_->startReceive();
|
||||||
if (state != ERR_NONE) {
|
if (state != ERR_NONE) {
|
||||||
LOG_ERROR("Receive start error:", state);
|
LOG_ERROR("Receive start error:", state);
|
||||||
|
@ -818,10 +825,10 @@ void Service::onRadioControlCommand(const std::vector<byte> &rawCommand) {
|
||||||
config_.LoraCodingRate = be16toh(setHardware->cr);
|
config_.LoraCodingRate = be16toh(setHardware->cr);
|
||||||
config_.LoraPower = be16toh(setHardware->pwr);
|
config_.LoraPower = be16toh(setHardware->pwr);
|
||||||
config_.LoraSync = be16toh(setHardware->sync);
|
config_.LoraSync = be16toh(setHardware->sync);
|
||||||
config_.LoraEnableCrc = setHardware->crc;
|
int crcType = setHardware->crc ? config_.LoraCrc : 0;
|
||||||
|
|
||||||
setupLora(config_.LoraFreq, config_.LoraBw, config_.LoraSf,
|
setupLora(config_.LoraFreq, config_.LoraBw, config_.LoraSf,
|
||||||
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, config_.LoraEnableCrc);
|
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, crcType, config_.LoraExplicit);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Radio control command of wrong size");
|
LOG_ERROR("Radio control command of wrong size");
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ private:
|
||||||
void printConfig();
|
void printConfig();
|
||||||
|
|
||||||
void setupWifi(const String &wifiName, const String &wifiKey);
|
void setupWifi(const String &wifiName, const String &wifiKey);
|
||||||
void setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int sync, bool enableCrc);
|
void setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int sync, int crcBytes, bool isExplicit);
|
||||||
void setupBt(const String &btName);
|
void setupBt(const String &btName);
|
||||||
|
|
||||||
void reconnectWifi() const;
|
void reconnectWifi() const;
|
||||||
|
|
Ładowanie…
Reference in New Issue