[SX127x] Using range check macro

This commit is contained in:
jgromes 2020-03-30 19:29:29 +02:00
parent d58a4c008e
commit 274b38d556
6 changed files with 10 additions and 37 deletions

View file

@ -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);

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -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));

View file

@ -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);