diff --git a/src/deck/drivers/interface/lpsTdoaTag.h b/src/deck/drivers/interface/lpsTdoaTag.h index bd69b6f418..23c45b16e6 100644 --- a/src/deck/drivers/interface/lpsTdoaTag.h +++ b/src/deck/drivers/interface/lpsTdoaTag.h @@ -26,5 +26,7 @@ typedef struct rangePacket_s { #define LPS_TDOA2_TYPE 0 #define LPS_TDOA2_SEND_LPP_PAYLOAD 1 +#define TDOA2_LPP_PACKET_SEND_TIMEOUT (LOCODECK_NR_OF_ANCHORS * 5) + #endif // __LPS_TDOA_TAG_H__ diff --git a/src/deck/drivers/src/lpsTdoaTag.c b/src/deck/drivers/src/lpsTdoaTag.c index 53b9a74fd3..557102a70a 100644 --- a/src/deck/drivers/src/lpsTdoaTag.c +++ b/src/deck/drivers/src/lpsTdoaTag.c @@ -57,6 +57,7 @@ static uint32_t anchorStatusTimeout[LOCODECK_NR_OF_TDOA2_ANCHORS]; // LPP packet handling lpsLppShortPacket_t lppPacket; bool lppPacketToSend; +int lppPacketSendTryCounter; // Log data static float logUwbTdoaDistDiff[LOCODECK_NR_OF_TDOA2_ANCHORS]; @@ -288,11 +289,17 @@ static uint32_t onEvent(dwDevice_t *dev, uwbEvent_t event) { lppPacketToSend = false; } else { setRadioInReceiveMode(dev); + + // Discard lpp packet if we cannot send it for too long + if (++lppPacketSendTryCounter >= TDOA2_LPP_PACKET_SEND_TIMEOUT) { + lppPacketToSend = false; + } } if (!lppPacketToSend) { // Get next lpp packet lppPacketToSend = lpsGetLppShort(&lppPacket); + lppPacketSendTryCounter = 0; } break; case eventTimeout: @@ -347,6 +354,8 @@ static void Initialize(dwDevice_t *dev, lpsAlgoOptions_t* algoOptions) { previousAnchor = 0; + lppPacketToSend = false; + memset(logUwbTdoaDistDiff, 0, sizeof(logUwbTdoaDistDiff)); options->rangingState = 0; diff --git a/test/deck/drivers/src/TestLpsTdoaTag.c b/test/deck/drivers/src/TestLpsTdoaTag.c index b2626dcef7..6176ca1981 100644 --- a/test/deck/drivers/src/TestLpsTdoaTag.c +++ b/test/deck/drivers/src/TestLpsTdoaTag.c @@ -83,6 +83,8 @@ static int lppShortPacketLength = 5; static int lppShortPacketDest = 3; static int lppShortPacketSource = 0xff; +static int lpsGetLppShort_numberOfCall; + // End stock test case #define SLOT_TIME 0.002 @@ -754,6 +756,10 @@ void testThatLppShortPacketIsNotSentToWrongAnchorWhenAvailable() { (uint8_t[]) {0, 0, 0, 0, 0, 0, 0, 0}, (uint64_t[]){NS, NS, NS, NS, NS, NS, NS, NS}, (uint64_t[]){NS, NS, NS, NS, NS, NS, NS, NS}); + mockMessageFromAnchor(lppShortPacketDest+1, NS, + (uint8_t[]) {0, 0, 0, 0, 0, 0, 0, 0}, + (uint64_t[]){NS, NS, NS, NS, NS, NS, NS, NS}, + (uint64_t[]){NS, NS, NS, NS, NS, NS, NS, NS}); ignoreKalmanEstimatorValidation(); @@ -761,15 +767,20 @@ void testThatLppShortPacketIsNotSentToWrongAnchorWhenAvailable() { populateLppPacket(&expectedTxPacket, lppShortPacketData, lppShortPacketLength, 0xbccf000000000000 | lppShortPacketDest, 0xbccf000000000000 | lppShortPacketSource); // Test - uint32_t actual = uwbTdoaTagAlgorithm.onEvent(&dev, eventPacketReceived); + uwbTdoaTagAlgorithm.onEvent(&dev, eventPacketReceived); + uwbTdoaTagAlgorithm.onEvent(&dev, eventPacketReceived); // Assert - TEST_ASSERT_EQUAL_UINT32(MAX_TIMEOUT, actual); + // Nothing here, verification in mocks } void testThatLppShortPacketIsSentToGoodAnchorWhenAvailable() { // Fixture // mockRadioSetToReceiveMode() called as part of mockMessageFromAnchor() + mockMessageFromAnchor(lppShortPacketDest, NS, + (uint8_t[]) {0, 0, 0, 0, 0, 0, 0, 0}, + (uint64_t[]){NS, NS, NS, NS, NS, NS, NS, NS}, + (uint64_t[]){NS, NS, NS, NS, NS, NS, NS, NS}); mockMessageFromAnchorNotComingBackToReceive(lppShortPacketDest, NS, (uint8_t[]) {0, 0, 0, 0, 0, 0, 0, 0}, (uint64_t[]){NS, NS, NS, NS, NS, NS, NS, NS}, @@ -783,10 +794,37 @@ void testThatLppShortPacketIsSentToGoodAnchorWhenAvailable() { mockSendLppShortHandling(&expectedTxPacket, lppShortPacketLength); // Test - uint32_t actual = uwbTdoaTagAlgorithm.onEvent(&dev, eventPacketReceived); + uwbTdoaTagAlgorithm.onEvent(&dev, eventPacketReceived); + uwbTdoaTagAlgorithm.onEvent(&dev, eventPacketReceived); // Assert - TEST_ASSERT_EQUAL_UINT32(MAX_TIMEOUT, actual); + // Nothing here, verification in mocks +} + +void testThatLppShortPacketIsDiscardedIfAnchorNotPresentForTooLong() { + // Fixture + // mockRadioSetToReceiveMode() called as part of mockMessageFromAnchor() + for (int i=0; i