[RF69] Fixed known binary receive length (#408)
This commit is contained in:
parent
90b9bd02fb
commit
1d4295feed
2 changed files with 21 additions and 4 deletions
|
@ -347,9 +347,12 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
// get packet length
|
// get packet length
|
||||||
size_t length = len;
|
size_t length = getPacketLength();
|
||||||
if(len == RADIOLIB_RF69_MAX_PACKET_LENGTH) {
|
size_t dumpLen = 0;
|
||||||
length = getPacketLength();
|
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
|
// check address filtering
|
||||||
|
@ -361,6 +364,11 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
|
||||||
// read packet data
|
// read packet data
|
||||||
_mod->SPIreadRegisterBurst(RADIOLIB_RF69_REG_FIFO, length, 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
|
// clear internal flag so getPacketLength can return the new packet length
|
||||||
_packetLengthQueried = false;
|
_packetLengthQueried = false;
|
||||||
|
|
||||||
|
@ -935,4 +943,11 @@ void RF69::clearIRQFlags() {
|
||||||
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, 0b11111111);
|
_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
|
#endif
|
||||||
|
|
|
@ -616,7 +616,8 @@ class RF69: public PhysicalLayer {
|
||||||
|
|
||||||
\param data Pointer to array to save the received binary data.
|
\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
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
|
@ -950,6 +951,7 @@ class RF69: public PhysicalLayer {
|
||||||
#endif
|
#endif
|
||||||
int16_t setMode(uint8_t mode);
|
int16_t setMode(uint8_t mode);
|
||||||
void clearIRQFlags();
|
void clearIRQFlags();
|
||||||
|
void clearFIFO(size_t count);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue