[SX127x] Implemented data rate check
This commit is contained in:
parent
b734e23460
commit
a4b148d609
8 changed files with 113 additions and 1 deletions
|
@ -252,6 +252,27 @@ int16_t SX1272::setDataRate(DataRate_t dr) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t SX1272::checkDataRate(DataRate_t dr) {
|
||||||
|
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||||
|
|
||||||
|
// select interpretation based on active modem
|
||||||
|
int16_t modem = getActiveModem();
|
||||||
|
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||||
|
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||||
|
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return(state);
|
||||||
|
}
|
||||||
|
|
||||||
int16_t SX1272::setOutputPower(int8_t power) {
|
int16_t SX1272::setOutputPower(int8_t power) {
|
||||||
return(this->setOutputPower(power, false));
|
return(this->setOutputPower(power, false));
|
||||||
}
|
}
|
||||||
|
@ -306,7 +327,7 @@ int16_t SX1272::setGain(uint8_t gain) {
|
||||||
|
|
||||||
// get modem
|
// get modem
|
||||||
int16_t modem = getActiveModem();
|
int16_t modem = getActiveModem();
|
||||||
if(modem == RADIOLIB_SX127X_LORA){
|
if(modem == RADIOLIB_SX127X_LORA) {
|
||||||
// set gain
|
// set gain
|
||||||
if(gain == 0) {
|
if(gain == 0) {
|
||||||
// gain set to 0, enable AGC loop
|
// gain set to 0, enable AGC loop
|
||||||
|
|
|
@ -183,6 +183,13 @@ class SX1272: public SX127x {
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t setDataRate(DataRate_t dr) override;
|
int16_t setDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Check the data rate can be configured by this module.
|
||||||
|
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||||
|
\returns \ref status_codes
|
||||||
|
*/
|
||||||
|
int16_t checkDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
|
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
|
||||||
|
|
|
@ -92,4 +92,25 @@ int16_t SX1273::setDataRate(DataRate_t dr) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t SX1273::checkDataRate(DataRate_t dr) {
|
||||||
|
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||||
|
|
||||||
|
// select interpretation based on active modem
|
||||||
|
int16_t modem = getActiveModem();
|
||||||
|
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||||
|
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||||
|
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return(state);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -55,6 +55,13 @@ class SX1273: public SX1272 {
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t setDataRate(DataRate_t dr) override;
|
int16_t setDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Check the data rate can be configured by this module.
|
||||||
|
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||||
|
\returns \ref status_codes
|
||||||
|
*/
|
||||||
|
int16_t checkDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
#if !RADIOLIB_GODMODE
|
#if !RADIOLIB_GODMODE
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -134,4 +134,25 @@ int16_t SX1277::setDataRate(DataRate_t dr) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t SX1277::checkDataRate(DataRate_t dr) {
|
||||||
|
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||||
|
|
||||||
|
// select interpretation based on active modem
|
||||||
|
int16_t modem = getActiveModem();
|
||||||
|
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||||
|
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||||
|
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return(state);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -76,6 +76,13 @@ class SX1277: public SX1278 {
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t setDataRate(DataRate_t dr) override;
|
int16_t setDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Check the data rate can be configured by this module.
|
||||||
|
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||||
|
\returns \ref status_codes
|
||||||
|
*/
|
||||||
|
int16_t checkDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
#if !RADIOLIB_GODMODE
|
#if !RADIOLIB_GODMODE
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -266,6 +266,27 @@ int16_t SX1278::setDataRate(DataRate_t dr) {
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t SX1278::checkDataRate(DataRate_t dr) {
|
||||||
|
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||||
|
|
||||||
|
// select interpretation based on active modem
|
||||||
|
int16_t modem = getActiveModem();
|
||||||
|
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||||
|
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||||
|
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||||
|
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return(state);
|
||||||
|
}
|
||||||
|
|
||||||
int16_t SX1278::setOutputPower(int8_t power) {
|
int16_t SX1278::setOutputPower(int8_t power) {
|
||||||
return(this->setOutputPower(power, false));
|
return(this->setOutputPower(power, false));
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,6 +193,13 @@ class SX1278: public SX127x {
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t setDataRate(DataRate_t dr) override;
|
int16_t setDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Check the data rate can be configured by this module.
|
||||||
|
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||||
|
\returns \ref status_codes
|
||||||
|
*/
|
||||||
|
int16_t checkDataRate(DataRate_t dr) override;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
|
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
|
||||||
|
|
Loading…
Add table
Reference in a new issue