Skip to content

Commit

Permalink
Fix for available()
Browse files Browse the repository at this point in the history
Found that if available() is called, but a packet is not read, the system will halt, with no more payloads coming in. This make available() always return true if there is a packet in the radios buffer
  • Loading branch information
TMRh20 committed Oct 1, 2023
1 parent 3a158f8 commit 24b1cdd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ nrf_to_nrf::nrf_to_nrf()
ARC = 0;
addressWidth = 5;
ackTimeout = ACK_TIMEOUT_1MBPS;
payloadAvailable = false;

#if defined CCM_ENCRYPTION_ENABLED
NRF_CCM->INPTR = (uint32_t)inBuffer;
Expand Down Expand Up @@ -163,7 +164,11 @@ bool nrf_to_nrf::available()

bool nrf_to_nrf::available(uint8_t* pipe_num)
{


if(payloadAvailable){
return true;
}

if (!inRxMode) {
if (ackPayloadAvailable) {
*pipe_num = ackAvailablePipeNo;
Expand Down Expand Up @@ -293,6 +298,7 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
#endif
lastPacketCounter = packetCtr;
lastData = packetData;
payloadAvailable = true;
return 1;
}
if (NRF_RADIO->EVENTS_CRCERROR) {
Expand All @@ -312,6 +318,7 @@ void nrf_to_nrf::read(void* buf, uint8_t len)
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
payloadAvailable = false;
}

/**********************************************************************************************************/
Expand Down Expand Up @@ -1339,4 +1346,4 @@ void nrf_to_nrf::setIV(uint8_t IV[CCM_IV_SIZE]){
}


#endif // defined CCM_ENCRYPTION_ENABLED
#endif // defined CCM_ENCRYPTION_ENABLED
1 change: 1 addition & 0 deletions src/nrf_to_nrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ class nrf_to_nrf
uint8_t ARC;
uint8_t addressWidth;
uint16_t ackTimeout;
bool payloadAvailable;
#if defined CCM_ENCRYPTION_ENABLED
uint8_t inBuffer[MAX_PACKET_SIZE + CCM_MIC_SIZE + CCM_START_SIZE];
uint8_t scratchPTR[MAX_PACKET_SIZE + CCM_MODE_LENGTH_EXTENDED];
Expand Down

0 comments on commit 24b1cdd

Please sign in to comment.