Merge pull request #928 from plietar/master

[CC1101] Correctly wait for packet end on blocking receive.
This commit is contained in:
Jan Gromeš 2024-01-13 19:20:04 +01:00 committed by GitHub
commit d1d6e04f2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -139,7 +139,7 @@ int16_t CC1101::receive(uint8_t* data, size_t len) {
int16_t state = startReceive(); int16_t state = startReceive();
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// wait for packet or timeout // wait for packet start or timeout
uint32_t start = this->mod->hal->micros(); uint32_t start = this->mod->hal->micros();
while(this->mod->hal->digitalRead(this->mod->getIrq())) { while(this->mod->hal->digitalRead(this->mod->getIrq())) {
this->mod->hal->yield(); this->mod->hal->yield();
@ -151,11 +151,16 @@ int16_t CC1101::receive(uint8_t* data, size_t len) {
} }
} }
// for some reason, blocking receive will sometimes return impossible packet lengths // wait for packet end or timeout
// reading packet length again in readData seems to resolve this start = this->mod->hal->micros();
size_t length = getPacketLength(); while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
if((length == 0) || (length > RADIOLIB_CC1101_MAX_PACKET_LENGTH)) { this->mod->hal->yield();
this->packetLengthQueried = false;
if(this->mod->hal->micros() - start > timeout) {
standby();
SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_RX);
return(RADIOLIB_ERR_RX_TIMEOUT);
}
} }
// read packet data // read packet data