[SX127x] Added software timeout when using blocking receive without DIO1 (#566)
This commit is contained in:
parent
ffb2c15a50
commit
cb5fd16710
1 changed files with 23 additions and 4 deletions
|
@ -208,15 +208,34 @@ int16_t SX127x::receive(uint8_t* data, size_t len) {
|
||||||
state = startReceive(len, RADIOLIB_SX127X_RXSINGLE);
|
state = startReceive(len, RADIOLIB_SX127X_RXSINGLE);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
// wait for packet reception or timeout (100 LoRa symbols)
|
// if no DIO1 is provided, use software timeout (100 LoRa symbols, same as hardware timeout)
|
||||||
|
uint32_t timeout = 0;
|
||||||
|
if(_mod->getGpio() == RADIOLIB_NC) {
|
||||||
|
float symbolLength = (float) (uint32_t(1) << _sf) / (float) _bw;
|
||||||
|
timeout = 100*symbolLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait for packet reception or timeout
|
||||||
|
uint32_t start = _mod->micros();
|
||||||
while(!_mod->digitalRead(_mod->getIrq())) {
|
while(!_mod->digitalRead(_mod->getIrq())) {
|
||||||
_mod->yield();
|
_mod->yield();
|
||||||
|
|
||||||
|
if(_mod->getGpio() != RADIOLIB_NC) {
|
||||||
|
// no GPIO pin provided, use software timeout
|
||||||
|
if(_mod->micros() - start > timeout) {
|
||||||
|
clearIRQFlags();
|
||||||
|
return(RADIOLIB_ERR_RX_TIMEOUT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// GPIO provided, use that
|
||||||
if(_mod->digitalRead(_mod->getGpio())) {
|
if(_mod->digitalRead(_mod->getGpio())) {
|
||||||
clearIRQFlags();
|
clearIRQFlags();
|
||||||
return(RADIOLIB_ERR_RX_TIMEOUT);
|
return(RADIOLIB_ERR_RX_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||||
// calculate timeout (500 % of expected time-on-air)
|
// calculate timeout (500 % of expected time-on-air)
|
||||||
uint32_t timeout = getTimeOnAir(len) * 5;
|
uint32_t timeout = getTimeOnAir(len) * 5;
|
||||||
|
|
Loading…
Add table
Reference in a new issue