From 0bacd86148a75c0342bd881ebebc80e306514dd9 Mon Sep 17 00:00:00 2001 From: Wolfgang Hoenig Date: Fri, 19 Jan 2024 12:00:39 +0100 Subject: [PATCH] radiolink: add log variables for statistics * radio.numRxBc counts the number of broadcasts received * radio.numRxUc counts the number of unicasts received --- src/hal/src/radiolink.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/hal/src/radiolink.c b/src/hal/src/radiolink.c index 9145fcd423..a21bf8a811 100644 --- a/src/hal/src/radiolink.c +++ b/src/hal/src/radiolink.c @@ -67,6 +67,8 @@ static int radiolinkReceiveCRTPPacket(CRTPPacket *p); static uint8_t rssi; static bool isConnected; static uint32_t lastPacketTick; +static uint16_t count_rx_broadcast; +static uint16_t count_rx_unicast; static volatile P2PCallback p2p_callback; @@ -162,6 +164,7 @@ void radiolinkSyslinkDispatch(SyslinkPacket *slp) slp->length--; // Decrease to get CRTP size. // Assert that we are not dropping any packets ASSERT(xQueueSend(crtpPacketDelivery, &slp->length, 0) == pdPASS); + ++count_rx_unicast; ledseqRun(&seq_linkUp); // If a radio packet is received, one can be sent if (xQueueReceive(txQueue, &txPacket, 0) == pdTRUE) @@ -173,7 +176,11 @@ void radiolinkSyslinkDispatch(SyslinkPacket *slp) { slp->length--; // Decrease to get CRTP size. // broadcasts are best effort, so no need to handle the case where the queue is full - xQueueSend(crtpPacketDelivery, &slp->length, 0); + BaseType_t result = xQueueSend(crtpPacketDelivery, &slp->length, 0); + // only increment the received counter, if we were able to put it in the queue + if (result == pdPASS) { + ++count_rx_broadcast; + } ledseqRun(&seq_linkUp); // no ack for broadcasts } else if (slp->type == SYSLINK_RADIO_RSSI) @@ -259,7 +266,28 @@ static int radiolinkSetEnable(bool enable) return 0; } +/** + * Radio link log variables. + */ LOG_GROUP_START(radio) +/** + * @brief Radio Signal Strength Indicator [dBm] + */ LOG_ADD_CORE(LOG_UINT8, rssi, &rssi) +/** + * @brief Indicator if a packet was received from the radio within the last RADIO_ACTIVITY_TIMEOUT_MS. + */ LOG_ADD_CORE(LOG_UINT8, isConnected, &isConnected) +/** + * @brief Number of broadcast packets received. + * + * Note that this is only 16 bits and overflows. Use overflow correction on the client side. + */ +LOG_ADD_CORE(LOG_UINT16, numRxBc, &count_rx_broadcast) +/** + * @brief Number of unicast packets received. + * + * Note that this is only 16 bits and overflows. Use overflow correction on the client side. + */ +LOG_ADD_CORE(LOG_UINT16, numRxUc, &count_rx_unicast) LOG_GROUP_STOP(radio)