From 34f575a6cb201ca70e142de59f1e9750b863d7f2 Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期四, 21 十一月 2024 11:00:36 +0800
Subject: [PATCH] 基站稳定与标签测距测信号强度STS版本,一对一

---
 keil/uwb_app.c |   44 +++++++++++++++++++++++++++-----------------
 1 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/keil/uwb_app.c b/keil/uwb_app.c
index 2144422..e86e3ae 100644
--- a/keil/uwb_app.c
+++ b/keil/uwb_app.c
@@ -9,7 +9,7 @@
 #include "dw_app_anchor.h"
 #include "global_param.h"
 #include "board.h"
-
+#include "lib_aoa.h"
 
 extern int simple_main(void);
 extern int temp_main(void);
@@ -66,7 +66,7 @@
 #define RANGING_PERIOD_MS (1000)
 
 /* This is the delay from Frame RX POLL frame to send RESP Frame */
-#define POLL_RX_TO_RESP_TX_DLY_US 670U //yuan450
+#define POLL_RX_TO_RESP_TX_DLY_US 1000U //yuan670 with urt 3000success
 
 #define RESP_TX_TO_FINAL_RX_DLY_US 500U
 
@@ -104,17 +104,7 @@
     uint8_t phy_work_mode; /* PHY_TX / PHY_RX / PHT_TX|PHY_RX */
     struct UWB_CONFIG_T phy_cfg;
 };
-/* Use the default key and IV specified in the IEEE 802.15.4z attachment */
-static struct UWB_STS_KEY_CONFIG_T sts_iv_key = {
-    .sts_vcounter = 0x1F9A3DE4,
-    .sts_vupper0 = 0xD37EC3CA,
-    .sts_vupper1 = 0xC44FA8FB,
-    .sts_vupper2 = 0x362EEB34,
-    .sts_key0 = 0x14EB220F,
-    .sts_key1 = 0xF86050A8,
-    .sts_key2 = 0xD1D336AA,
-    .sts_key3 = 0x14148674,
-};
+
 ///* Default communication configuration. */
 //static struct mk_uwb_configure config = {//原来的基站非110k代码
 //    .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX),
@@ -164,6 +154,17 @@
     .phy_cfg.rx_ant_id = UWB_RX_ANT_3,        /* UWB RX antenna port                       */
 };
 #endif
+/* Use the default key and IV specified in the IEEE 802.15.4z attachment */
+static struct UWB_STS_KEY_CONFIG_T sts_iv_key = {
+    .sts_vcounter = 0x1F9A3DE4,
+    .sts_vupper0 = 0xD37EC3CA,
+    .sts_vupper1 = 0xC44FA8FB,
+    .sts_vupper2 = 0x362EEB34,
+    .sts_key0 = 0x14EB220F,
+    .sts_key1 = 0xF86050A8,
+    .sts_key2 = 0xD1D336AA,
+    .sts_key3 = 0x14148674,
+};
 /* Buffer to store received frame */
 
 /*     Frames used in the ranging process
@@ -418,7 +419,7 @@
     while(mac_is_busy());
     gpio_pin_clr(SCL_PIN);
 }
-uint32_t range_timeout_us = 5000;
+uint32_t range_timeout_us = 1000000;//yuan5000
 uint16_t uwb_searchcount;
 uint8_t flag_recsuccess;
 uint8_t flag_temp2,flag_temp1;
@@ -488,6 +489,7 @@
 		flag_recsuccess = 0;
     temp_count3=phy_timer_count_get();
     gpio_pin_set(SCL_PIN);
+		sts_lsp_store();
     flag_temp1=uwb_rx(0, 0, range_timeout_us);//开启接收
 	
    // while(mac_is_busy());
@@ -511,6 +513,8 @@
                     break;
             }
         }
+			sts_lsp_store_stop();
+			
 			
     if(receive_flag==1)//成功接收
     {
@@ -552,11 +556,12 @@
             }
 						recev_error_num=0;
            	range_timeout_us=5000;//恢复为5000进入range后
-           LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度ANT0:%d,信号强度ANT2:%d\r\n",g_com_map[BIND_DEV_ID],distance,sts_rssi[0],sts_rssi[2]);
+           LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度ANT0: %f,信号强度ANT2: %f\r\n",g_com_map[BIND_DEV_ID],distance,sts_rssi[0],sts_rssi[2]);
 						gpio_pin_clr(SCL_PIN);
         break;
 				}
     } 
+			sts_lsp_store();
 		//失败或者接受被高发射机打断都会再次开启接收
 			flag_temp1=uwb_rx(0, 0, range_timeout_us);
 	}
@@ -625,6 +630,7 @@
     receive_flag = 0;
     temp_count3=phy_timer_count_get();
     gpio_pin_set(SCL_PIN);
+		sts_lsp_store();
     flag_temp2=uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//开启接收
     start_receive_count=phy_timer_count_get();
     poll_timeout=US_TO_PHY_TIMER_COUNT(2000000);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss
@@ -645,7 +651,9 @@
                     break;
             }
         }
-
+				sts_lsp_store_stop();
+				
+				
         temp_count2=phy_timer_count_get();
         if(receive_flag==1)//成功接收
         {
@@ -688,15 +696,17 @@
                 }
                 
                 gpio_pin_clr(SCL_PIN);//测试
-								LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度ANT0:%d,信号强度ANT2:%d\r\n",g_com_map[BIND_DEV_ID],distance,sts_rssi[0],sts_rssi[2]);
+								LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度ANT0:%f,信号强度ANT2: %f\r\n",g_com_map[BIND_DEV_ID],distance,sts_rssi[0],sts_rssi[2]);
                 return 1;//返回发送成功标志
             }
 
         }
 				temp_count3=phy_timer_count_get();
+				sts_lsp_store();
         flag_temp2=uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收
     }
 		delay_us(2);
+		sts_lsp_store_stop();
 		uwb_rx_force_off(1);
     // LOG_INFO(TRACE_MODULE_APP,"超时定时器:%x,%x,%x\r\n",start_receive_count,end_receive_count,current_count);
     gpio_pin_clr(SCL_PIN);//测试

--
Gitblit v1.9.3