[RF69] Fixed known binary receive length (#408)

This commit is contained in:
jgromes 2021-11-21 21:17:26 +01:00
parent 90b9bd02fb
commit 1d4295feed
2 changed files with 21 additions and 4 deletions

View file

@ -347,9 +347,12 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
RADIOLIB_ASSERT(state);
// get packet length
size_t length = len;
if(len == RADIOLIB_RF69_MAX_PACKET_LENGTH) {
length = getPacketLength();
size_t length = getPacketLength();
size_t dumpLen = 0;
if((len != 0) && (len < length)) {
// user requested less data than we got, only return what was requested
dumpLen = length - len;
length = len;
}
// check address filtering
@ -361,6 +364,11 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
// read packet data
_mod->SPIreadRegisterBurst(RADIOLIB_RF69_REG_FIFO, length, data);
// dump the bytes that weren't requested
if(dumpLen != 0) {
clearFIFO(dumpLen);
}
// clear internal flag so getPacketLength can return the new packet length
_packetLengthQueried = false;
@ -935,4 +943,11 @@ void RF69::clearIRQFlags() {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, 0b11111111);
}
void RF69::clearFIFO(size_t count) {
while(count) {
_mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO);
count--;
}
}
#endif

View file

@ -616,7 +616,8 @@ class RF69: public PhysicalLayer {
\param data Pointer to array to save the received binary data.
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
\param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically.
When more bytes than received are requested, only the number of bytes requested will be returned.
\returns \ref status_codes
*/
@ -950,6 +951,7 @@ class RF69: public PhysicalLayer {
#endif
int16_t setMode(uint8_t mode);
void clearIRQFlags();
void clearFIFO(size_t count);
};
#endif