[RFM9x] Added assert macro
This commit is contained in:
parent
751fb6431c
commit
be701ed120
3 changed files with 34 additions and 68 deletions
|
@ -7,47 +7,30 @@ RFM95::RFM95(Module* mod) : SX1278(mod) {
|
||||||
int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) {
|
int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) {
|
||||||
// execute common part
|
// execute common part
|
||||||
int16_t state = SX127x::begin(RFM95_CHIP_VERSION, syncWord, currentLimit, preambleLength);
|
int16_t state = SX127x::begin(RFM95_CHIP_VERSION, syncWord, currentLimit, preambleLength);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure settings not accessible by API
|
// configure settings not accessible by API
|
||||||
state = config();
|
state = config();
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure publicly accessible settings
|
// configure publicly accessible settings
|
||||||
state = setFrequency(freq);
|
state = setFrequency(freq);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setBandwidth(bw);
|
state = setBandwidth(bw);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setSpreadingFactor(sf);
|
state = setSpreadingFactor(sf);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setCodingRate(cr);
|
state = setCodingRate(cr);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setOutputPower(power);
|
state = setOutputPower(power);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setGain(gain);
|
state = setGain(gain);
|
||||||
if(state != ERR_NONE) {
|
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +39,7 @@ int16_t RFM95::setFrequency(float freq) {
|
||||||
if((freq < 868.0) || (freq > 915.0)) {
|
if((freq < 868.0) || (freq > 915.0)) {
|
||||||
return(ERR_INVALID_FREQUENCY);
|
return(ERR_INVALID_FREQUENCY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set frequency
|
// set frequency
|
||||||
return(SX127x::setFrequencyRaw(freq));
|
return(SX127x::setFrequencyRaw(freq));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,47 +7,30 @@ RFM96::RFM96(Module* mod) : SX1278(mod) {
|
||||||
int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) {
|
int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) {
|
||||||
// execute common part
|
// execute common part
|
||||||
int16_t state = SX127x::begin(RFM9X_CHIP_VERSION, syncWord, currentLimit, preambleLength);
|
int16_t state = SX127x::begin(RFM9X_CHIP_VERSION, syncWord, currentLimit, preambleLength);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure settings not accessible by API
|
// configure settings not accessible by API
|
||||||
state = config();
|
state = config();
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure publicly accessible settings
|
// configure publicly accessible settings
|
||||||
state = setFrequency(freq);
|
state = setFrequency(freq);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setBandwidth(bw);
|
state = setBandwidth(bw);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setSpreadingFactor(sf);
|
state = setSpreadingFactor(sf);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setCodingRate(cr);
|
state = setCodingRate(cr);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setOutputPower(power);
|
state = setOutputPower(power);
|
||||||
if(state != ERR_NONE) {
|
RADIOLIB_ASSERT(state);
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
state = setGain(gain);
|
state = setGain(gain);
|
||||||
if(state != ERR_NONE) {
|
|
||||||
return(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(state);
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +39,7 @@ int16_t RFM96::setFrequency(float freq) {
|
||||||
if((freq < 433.0) || (freq > 470.0)) {
|
if((freq < 433.0) || (freq > 470.0)) {
|
||||||
return(ERR_INVALID_FREQUENCY);
|
return(ERR_INVALID_FREQUENCY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set frequency
|
// set frequency
|
||||||
return(SX127x::setFrequencyRaw(freq));
|
return(SX127x::setFrequencyRaw(freq));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ int16_t RFM97::setSpreadingFactor(uint8_t sf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t newSpreadingFactor;
|
uint8_t newSpreadingFactor;
|
||||||
|
|
||||||
// check allowed spreading factor values
|
// check allowed spreading factor values
|
||||||
switch(sf) {
|
switch(sf) {
|
||||||
case 6:
|
case 6:
|
||||||
|
@ -29,7 +29,7 @@ int16_t RFM97::setSpreadingFactor(uint8_t sf) {
|
||||||
default:
|
default:
|
||||||
return(ERR_INVALID_SPREADING_FACTOR);
|
return(ERR_INVALID_SPREADING_FACTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set spreading factor and if successful, save the new setting
|
// set spreading factor and if successful, save the new setting
|
||||||
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
|
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
|
||||||
if(state == ERR_NONE) {
|
if(state == ERR_NONE) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue