From adfc7e798b9cbdd022bf8df971843436912a0fe5 Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期日, 20 七月 2025 16:58:30 +0800
Subject: [PATCH] 成功移植g_com_map表逻辑,初步测试能读能写,并且TDOA效果和官方一致

---
 keil/include/components/app/src/uwb_test.c |   46 ++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/keil/include/components/app/src/uwb_test.c b/keil/include/components/app/src/uwb_test.c
index 5cbd453..ea035f7 100644
--- a/keil/include/components/app/src/uwb_test.c
+++ b/keil/include/components/app/src/uwb_test.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019-2023 Beijing Hanwei Innovation Technology Ltd. Co. and
+ * Copyright (c) 2019-2025 Beijing Hanwei Innovation Technology Ltd. Co. and
  * its subsidiaries and affiliates (collectly called MKSEMI).
  *
  * All rights reserved.
@@ -92,7 +92,7 @@
 static void uwb_test_tx_done_ind(struct MAC_HW_REPORT_T *tx)
 {
     struct UWB_TEST_TX_DONE_IND_T *ind;
-    uint8_t fcs_len = (uwb_app_config.ppdu_params.fcs_type == FCS_CRC_16 ? 2 : 4);
+    uint8_t fcs_len = (uwb_app_config.ppdu_params->fcs_type == FCS_CRC_16 ? 2 : 4);
 
     if ((ind = WsfMsgAlloc(sizeof(struct UWB_TEST_TX_DONE_IND_T) + tx->pkt_len + fcs_len)) != NULL)
     {
@@ -107,7 +107,7 @@
             ind->tx.timestamp_int = (uint32_t)(timestamp >> 9);
         }
 
-        if (uwb_app_config.ppdu_params.sts_pkt_cfg == SP3)
+        if (uwb_app_config.ppdu_params->sts_pkt_cfg == SP3)
         {
             ind->tx.length = tx->pkt_len;
             ind->tx.data = NULL;
@@ -121,7 +121,7 @@
                 memcpy(ind->tx.data, tx->pkt_data, tx->pkt_len);
             }
 
-            if (uwb_app_config.ppdu_params.fcs_type == FCS_CRC_16)
+            if (uwb_app_config.ppdu_params->fcs_type == FCS_CRC_16)
             {
                 uint16_t fcs = fcs_crc_16(tx->pkt_data, tx->pkt_len);
                 ind->tx.data[tx->pkt_len] = fcs & 0xff;
@@ -150,7 +150,7 @@
 {
     // send an indication to application
     struct UWB_TEST_RX_DONE_IND_T *ind;
-    uint8_t fcs_len = (uwb_app_config.ppdu_params.fcs_type == FCS_CRC_16 ? 2 : 4);
+    uint8_t fcs_len = (uwb_app_config.ppdu_params->fcs_type == FCS_CRC_16 ? 2 : 4);
 
     if ((ind = WsfMsgAlloc(sizeof(struct UWB_TEST_RX_DONE_IND_T) + rx->pkt_len + fcs_len)) != NULL)
     {
@@ -158,8 +158,17 @@
         ind->rx.phy_timer_count = rx->timestamp;
         ind->rx.phr_bits = (uint16_t)rx->phy_header;
         ind->rx.status = rx->err_code;
-        ind->rx.rssi = rx->rssi;
-        ind->rx.snr = rx->snr;
+        // ind->rx.rssi = rx->rssi;
+        // ind->rx.snr = rx->snr;
+        ind->rx.rssi = correct_rssi(rx->rssi);
+        ind->rx.snr = correct_snr(rx->snr);
+
+#if CSI_EN
+        if (ranging_debug_csi_en_get() == 0)
+        {
+            ranging_debug_csi_en_set(1);
+        }
+#endif
 
         if (rx->err_code == UWB_RX_OK)
         {
@@ -189,7 +198,7 @@
                         memcpy(ind->rx.data, rx->pkt_data, rx->pkt_len);
                     }
 
-                    if (uwb_app_config.ppdu_params.fcs_type == FCS_CRC_16)
+                    if (uwb_app_config.ppdu_params->fcs_type == FCS_CRC_16)
                     {
                         uint16_t fcs = fcs_crc_16(rx->pkt_data, rx->pkt_len);
                         ind->rx.data[rx->pkt_len] = fcs & 0xff;
@@ -205,6 +214,27 @@
                     }
                 }
             }
+#if CSI_EN
+            if (ranging_debug_csi_en_get())
+            {
+                uint8_t frame_idx = 0;
+                debug_csi.frame_idx = frame_idx;
+
+                uint32_t val = REG_READ(0x40003050);
+                debug_csi.frame[frame_idx].rf_gain = (val & 0x07);
+                debug_csi.frame[frame_idx].bb_gain = ((val >> 3) & 0x1f);
+                debug_csi.frame[frame_idx].bd_cnt = phy_bd_cnt_get();
+                debug_csi.frame[frame_idx].sfd_cnt = phy_sfd_cnt_get();
+                debug_csi.frame[frame_idx].error_code = ind->rx.status;
+                if (rx->err_code != 0x0830)
+                {
+                    debug_csi.frame[frame_idx].rssi = ind->rx.rssi;
+                    debug_csi.frame[frame_idx].snr = ind->rx.snr;
+                    debug_csi.frame[frame_idx].channel_power = REG_READ(0x40002064);
+                    debug_csi.frame[frame_idx].noise_power = REG_READ(0x40002078);
+                }
+            }
+#endif
         }
 
         // Send the message

--
Gitblit v1.9.3