From 24b1cdd36e8e03709f1503c11ccaebff3da8d8d4 Mon Sep 17 00:00:00 2001 From: TMRh20 Date: Sat, 30 Sep 2023 23:02:27 -0600 Subject: [PATCH] Fix for available() 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 --- src/nrf_to_nrf.cpp | 11 +++++++++-- src/nrf_to_nrf.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/nrf_to_nrf.cpp b/src/nrf_to_nrf.cpp index f1b1988..d8da709 100644 --- a/src/nrf_to_nrf.cpp +++ b/src/nrf_to_nrf.cpp @@ -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; @@ -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; @@ -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) { @@ -312,6 +318,7 @@ void nrf_to_nrf::read(void* buf, uint8_t len) if (inRxMode) { NRF_RADIO->TASKS_START = 1; } + payloadAvailable = false; } /**********************************************************************************************************/ @@ -1339,4 +1346,4 @@ void nrf_to_nrf::setIV(uint8_t IV[CCM_IV_SIZE]){ } -#endif // defined CCM_ENCRYPTION_ENABLED \ No newline at end of file +#endif // defined CCM_ENCRYPTION_ENABLED diff --git a/src/nrf_to_nrf.h b/src/nrf_to_nrf.h index d9104da..d1ad6f4 100644 --- a/src/nrf_to_nrf.h +++ b/src/nrf_to_nrf.h @@ -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];