[Si443x] Fixed known binary receive length

This commit is contained in:
jgromes 2021-11-21 21:16:37 +01:00
parent e4eec9c5bd
commit c99e79073f
2 changed files with 21 additions and 4 deletions

View file

@ -285,14 +285,22 @@ int16_t Si443x::readData(uint8_t* data, size_t len) {
clearIRQFlags(); clearIRQFlags();
// get packet length // get packet length
size_t length = len; size_t length = getPacketLength();
if(len == RADIOLIB_SI443X_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;
} }
// read packet data // read packet data
_mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, length, data); _mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, 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;
@ -647,6 +655,13 @@ void Si443x::clearIRQFlags() {
_mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_INTERRUPT_STATUS_1, 2, buff); _mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_INTERRUPT_STATUS_1, 2, buff);
} }
void Si443x::clearFIFO(size_t count) {
while(count) {
_mod->SPIreadRegister(RADIOLIB_SI443X_REG_FIFO_ACCESS);
count--;
}
}
int16_t Si443x::config() { int16_t Si443x::config() {
// set mode to standby // set mode to standby
int16_t state = standby(); int16_t state = standby();

View file

@ -695,7 +695,8 @@ class Si443x: 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
*/ */
@ -838,6 +839,7 @@ class Si443x: public PhysicalLayer {
#endif #endif
bool findChip(); bool findChip();
void clearIRQFlags(); void clearIRQFlags();
void clearFIFO(size_t count);
int16_t config(); int16_t config();
int16_t updateClockRecovery(); int16_t updateClockRecovery();
int16_t directMode(); int16_t directMode();