-
-
Couldn't load subscription status.
- Fork 659
Description
At present, when a CRC error is reported from the device the packet is silently dropped. It would be extremely helpful to report this error to the user for a number of reasons. Firstly, just to know there is an issue, maybe radio settings can be adjusted to improve reception. Secondly, as per page 40 of the SX127x datasheet...
At the end of the payload, the RxDone interrupt is generated together with the interrupt PayloadCrcError if the payload CRC is not valid. However, even when the CRC is not valid, the data are written in the FIFO data buffer for post processing. Following the RxDone interrupt the radio goes to Standby mode.
This means if the packet has some other layer of validation it might be recoverable, or in the case of human readable text, can just be pass to the user for big brain processing.
Suggestions for handling. In sync mode via parsePacket we are currently not using error codes of any sort as that function returns int packetSize. We could utilize <0 to signify error states. Alternatively we could add an error flag to the LoRa object to be checked if parsePacket returns 0. Could look something like...
if(LoRa.parsePacket() == 0) {
if(LoRa.parseError & LORA_ERR_CRC) {
while(LoRa.available()) ... // do stuff with malformed packet
}
}
For async methods (using onReceive) it makes sense to add an error handling callback. Error codes can be shared with those above and would be passed to a callback handler specifically for errors. This would require registering a handler with onError similarly to how onReceive and the new onTxDone handlers work.