diff --git a/src/modules/SX127x/SX1272.cpp b/src/modules/SX127x/SX1272.cpp index 06646d1f..28fedba3 100644 --- a/src/modules/SX127x/SX1272.cpp +++ b/src/modules/SX127x/SX1272.cpp @@ -66,10 +66,7 @@ void SX1272::reset() { } int16_t SX1272::setFrequency(float freq) { - // check frequency range - if((freq < 860.0) || (freq > 1020.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 860.0, 1020.0, ERR_INVALID_FREQUENCY); // set frequency and if successful, save the new setting int16_t state = SX127x::setFrequencyRaw(freq); diff --git a/src/modules/SX127x/SX1276.cpp b/src/modules/SX127x/SX1276.cpp index 40a141a4..2fecd63a 100644 --- a/src/modules/SX127x/SX1276.cpp +++ b/src/modules/SX127x/SX1276.cpp @@ -35,10 +35,7 @@ int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync } int16_t SX1276::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 1020.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, ERR_INVALID_FREQUENCY); // SX1276/77/78 Errata fixes if(getActiveModem() == SX127X_LORA) { diff --git a/src/modules/SX127x/SX1277.cpp b/src/modules/SX127x/SX1277.cpp index bed5a84e..715d8853 100644 --- a/src/modules/SX127x/SX1277.cpp +++ b/src/modules/SX127x/SX1277.cpp @@ -35,10 +35,7 @@ int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync } int16_t SX1277::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 1020.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 1020.0, ERR_INVALID_FREQUENCY); // SX1276/77/78 Errata fixes if(getActiveModem() == SX127X_LORA) { diff --git a/src/modules/SX127x/SX1278.cpp b/src/modules/SX127x/SX1278.cpp index 5989aa13..af3fc0b3 100644 --- a/src/modules/SX127x/SX1278.cpp +++ b/src/modules/SX127x/SX1278.cpp @@ -61,10 +61,7 @@ void SX1278::reset() { } int16_t SX1278::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 525.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 525.0, ERR_INVALID_FREQUENCY); // SX1276/77/78 Errata fixes if(getActiveModem() == SX127X_LORA) { diff --git a/src/modules/SX127x/SX1279.cpp b/src/modules/SX127x/SX1279.cpp index 3468b0b1..1b45c9b7 100644 --- a/src/modules/SX127x/SX1279.cpp +++ b/src/modules/SX127x/SX1279.cpp @@ -35,10 +35,7 @@ int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync } int16_t SX1279::setFrequency(float freq) { - // check frequency range - if((freq < 137.0) || (freq > 960.0)) { - return(ERR_INVALID_FREQUENCY); - } + RADIOLIB_CHECK_RANGE(freq, 137.0, 960.0, ERR_INVALID_FREQUENCY); // set frequency return(SX127x::setFrequencyRaw(freq)); diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 5eab0195..15053fd9 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -647,13 +647,9 @@ int16_t SX127x::setBitRate(float br) { // check allowed bit rate if(_ook) { - if((br < 1.2) || (br > 32.768)) { - return(ERR_INVALID_BIT_RATE); - } + RADIOLIB_CHECK_RANGE(br, 1.2, 32.768, ERR_INVALID_BIT_RATE); } else { - if((br < 1.2) || (br > 300.0)) { - return(ERR_INVALID_BIT_RATE); - } + RADIOLIB_CHECK_RANGE(br, 1.2, 300.0, ERR_INVALID_BIT_RATE); } // set mode to STANDBY @@ -701,10 +697,7 @@ int16_t SX127x::setRxBandwidth(float rxBw) { return(ERR_WRONG_MODEM); } - // check allowed bandwidth values - if(!((rxBw >= 2.6) && (rxBw <= 250.0))) { - return(ERR_INVALID_RX_BANDWIDTH); - } + RADIOLIB_CHECK_RANGE(rxBw, 2.6, 250.0, ERR_INVALID_RX_BANDWIDTH); // set mode to STANDBY int16_t state = setMode(SX127X_STANDBY); @@ -738,10 +731,7 @@ int16_t SX127x::setSyncWord(uint8_t* syncWord, size_t len) { return(ERR_WRONG_MODEM); } - // check constraints - if((len > 8) || (len < 1)) { - return(ERR_INVALID_SYNC_WORD); - } + RADIOLIB_CHECK_RANGE(len, 1, 8, ERR_INVALID_SYNC_WORD); // sync word must not contain value 0x00 for(uint8_t i = 0; i < len; i++) { @@ -887,9 +877,7 @@ int16_t SX127x::setRSSIConfig(uint8_t smoothingSamples, int8_t offset) { return(ERR_INVALID_NUM_SAMPLES); } - if(!((offset >= -16) && (offset <= 15))) { - return(ERR_INVALID_RSSI_OFFSET); - } + RADIOLIB_CHECK_RANGE(offset, -16, 15, ERR_INVALID_RSSI_OFFSET); // set new register values state = _mod->SPIsetRegValue(SX127X_REG_RSSI_CONFIG, offset, 7, 3);