[LoRaWAN] Improve modem switching
This commit is contained in:
parent
9f04da29af
commit
ef0cfddd01
2 changed files with 45 additions and 4 deletions
|
@ -3299,10 +3299,13 @@ int16_t LoRaWANNode::findDataRate(uint8_t dr, DataRate_t* dataRate) {
|
|||
return(state);
|
||||
}
|
||||
|
||||
ModemType_t modemNew;
|
||||
|
||||
uint8_t dataRateBand = this->band->dataRates[dr];
|
||||
|
||||
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_MODEM) {
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_LORA):
|
||||
modemNew = ModemType_t::LoRa;
|
||||
dataRate->lora.spreadingFactor = ((dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_SF) >> 3) + 7;
|
||||
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_BW) {
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ):
|
||||
|
@ -3320,18 +3323,55 @@ int16_t LoRaWANNode::findDataRate(uint8_t dr, DataRate_t* dataRate) {
|
|||
dataRate->lora.codingRate = 5;
|
||||
break;
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_FSK):
|
||||
modemNew = ModemType_t::FSK;
|
||||
dataRate->fsk.bitRate = 50;
|
||||
dataRate->fsk.freqDev = 25;
|
||||
break;
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_LR_FHSS):
|
||||
// not yet supported by DataRate_t
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
modemNew = ModemType_t::LRFHSS;
|
||||
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_BW) {
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_BW_137_KHZ):
|
||||
dataRate->lrFhss.bw = 137.0;
|
||||
dataRate->lrFhss.narrowGrid = 1;
|
||||
break;
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_BW_336_KHZ):
|
||||
dataRate->lrFhss.bw = 336.0;
|
||||
dataRate->lrFhss.narrowGrid = 1;
|
||||
break;
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_BW_1523_KHZ):
|
||||
dataRate->lrFhss.bw = 1523.0;
|
||||
dataRate->lrFhss.narrowGrid = 0;
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
switch(dataRateBand & RADIOLIB_LORAWAN_DATA_RATE_CR) {
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_CR_1_3):
|
||||
dataRate->lrFhss.bw = 1;
|
||||
break;
|
||||
case(RADIOLIB_LORAWAN_DATA_RATE_CR_2_3):
|
||||
dataRate->lrFhss.bw = 2;
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
state = this->phyLayer->checkDataRate(*dataRate);
|
||||
// get the currently configured modem from the radio
|
||||
ModemType_t modemCurrent;
|
||||
state = this->phyLayer->getModem(&modemCurrent);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// if the required modem is different than the current one, change over
|
||||
if(modemNew != modemCurrent) {
|
||||
state = this->phyLayer->setModem(modemNew);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
state = this->phyLayer->checkDataRate(*dataRate);
|
||||
return(state);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,13 +60,14 @@
|
|||
#define RADIOLIB_LORAWAN_DATA_RATE_SF_9 (0x02 << 3) // 5 3 SF9
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_SF_8 (0x01 << 3) // 5 3 SF8
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_SF_7 (0x00 << 3) // 5 3 SF7
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW (0x03 << 1) // 2 1 bandwith mask
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW (0x03 << 1) // 2 1 bandwidth mask
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW_125_KHZ (0x00 << 1) // 2 1 125 kHz
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW_250_KHZ (0x01 << 1) // 2 1 250 kHz
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW_500_KHZ (0x02 << 1) // 2 1 LoRa bandwidth: 500 kHz
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW_137_KHZ (0x00 << 1) // 2 1 137 kHz
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW_336_KHZ (0x01 << 1) // 2 1 336 kHz
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_BW_1523_KHZ (0x02 << 1) // 2 1 LR-FHSS bandwidth: 1523 kHz
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_CR (0x01 << 0) // 0 0 coding rate mask
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_CR_1_3 (0x00 << 0) // 0 0 LR-FHSS coding rate: 1/3
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_CR_2_3 (0x01 << 0) // 0 0 2/3
|
||||
#define RADIOLIB_LORAWAN_DATA_RATE_UNUSED (0xFF << 0) // 7 0 unused data rate
|
||||
|
|
Loading…
Add table
Reference in a new issue