From b5e55c30c551c17426b864327b92b20d437d35d7 Mon Sep 17 00:00:00 2001
From: chen <15335560115@163.com>
Date: 星期五, 20 九月 2024 18:17:29 +0800
Subject: [PATCH] 对应手环V1.12非车载,删除部分socket.c的外包代码

---
 keil/uwb_app.c |   64 +++++++++++++++++++++-----------
 1 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/keil/uwb_app.c b/keil/uwb_app.c
index def6e7f..16e516b 100644
--- a/keil/uwb_app.c
+++ b/keil/uwb_app.c
@@ -102,7 +102,7 @@
 /* Default communication configuration. */
 static struct mk_uwb_configure config = {
     .phy_work_mode = (uint8_t)(PHY_TX | PHY_RX),
-    .phy_cfg.ch_num = 9,                      /* Channel number.                           */
+    .phy_cfg.ch_num = 5,                      /* Channel number.                           */
     .phy_cfg.code_index = 9,                  /* TX preamble code.                         */
     .phy_cfg.mean_prf = MEAN_PRF_64M,         /* Data rate 6.8M                            */
     .phy_cfg.data_bit_rate = DATA_BR_6M8,     /* data rate 6.8M.                           */
@@ -216,7 +216,7 @@
         poll_rx_num++;
         rssi = rx_report->rssi;
         receive_flag=1;
-        recev_error_num=0;
+        
     }
     else
     {
@@ -226,6 +226,7 @@
         /* UWB_BD_ERR      Preamble detection error  */
         /* UWB_TO_ERR      Receive timeout           */
         /* UWB_STS_ERR     STS error                 */
+			        temp_count= phy_timer_count_get();
         memcpy(&rx_rpt, rx_report, sizeof(struct MAC_HW_REPORT_T));
         rx_length = 0;
 
@@ -275,7 +276,7 @@
     anchordata_dist[i] = dist;
     anchordata_bat[i] = battary;
     tagofflinetime[i]=0;//不断更新当前TAG对应离线时间
-    if(dist>0)
+//    if(dist>0)
     distance=dist*0.5+distance*0.5;
 }
 uint16_t CmpTagInList(uint16_t tagid)
@@ -346,7 +347,8 @@
     while(mac_is_busy());
     gpio_pin_clr(SCL_PIN);
 }
-uint16_t uwb_searchcount;
+uint16_t uwb_searchcount,range_timeout_us = 5000;
+uint8_t flag_recsuccess;
 extern uint8_t g_start_send_flag,search_open_flag = 1,link_success_flag;
 int UwbRange(void)
 {
@@ -377,24 +379,36 @@
     mac_register_process_handler(tx_int_callback, rx_int_callback);
 
     receive_flag = 0;
+		flag_recsuccess = 0;
     temp_count3=phy_timer_count_get();
     gpio_pin_set(SCL_PIN);
-    uwb_rx(0, 0, RX_SYNC_WIN_US);//开启接收
-    while(mac_is_busy());
-    temp_count2=phy_timer_count_get();
-//		start_receive_count=phy_timer_count_get();
-//	poll_timeout=rec_nearbase_num*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS)+US_TO_PHY_TIMER_COUNT(DELAY_DEFAULT);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss
-//	end_receive_count=start_receive_count+poll_timeout;
-//	if(end_receive_count>=UINT32_MAX)
-//	{end_receive_count-=UINT32_MAX;}
-//	current_count=phy_timer_count_get();
-//		while(current_count<end_receive_count||current_count>end_receive_count+HALF_SECOND_TIME)//循环接受包体,若为124.8K则是+62400000
-//		{
+    uwb_rx(0, 0, range_timeout_us);//开启接收
+  //  while(mac_is_busy());
+  //  temp_count2=phy_timer_count_get();
+		start_receive_count=phy_timer_count_get();
+	poll_timeout=US_TO_PHY_TIMER_COUNT(range_timeout_us);//多一个多0.4ms默认0.4ms计算为0.125*4*100000,默认开启1mss
+	end_receive_count=start_receive_count+poll_timeout;
+	if(end_receive_count>=UINT32_MAX)
+	{end_receive_count-=UINT32_MAX;}
+	current_count=phy_timer_count_get();
+		while(current_count<end_receive_count||current_count>end_receive_count+HALF_SECOND_TIME)//循环接受包体,若为124.8K则是+62400000
+		{
+			current_count=phy_timer_count_get();
+			while(mac_is_busy())
+        {
+            IdleTask();
+            current_count=phy_timer_count_get();
+            if(current_count>end_receive_count&&current_count<end_receive_count+HALF_SECOND_TIME)
+            {
+                    break;
+            }
+        }
     if(receive_flag==1)//成功接收
     {
 
         if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL&&!memcmp(&rx_buf[TAG_ID_IDX],&g_com_map[BIND_DEV_ID],2))//判断是否是和自己是同一组通讯的且为poll包
-        {   temp_count2=phy_timer_count_get();
+        {   flag_recsuccess = 1;
+					  temp_count2=phy_timer_count_get();
             frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序
             battary = rx_buf[BATTARY_IDX];
             rec_nearbase_num=rx_buf[FZ_NEARBASENUM_INDEX];  //标签传过来的他与基站交互的基站id数目
@@ -427,11 +441,18 @@
                 Anchor_RecNearPoll(i);
 
             }
+						recev_error_num=0;
             sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试
             LOG_INFO(TRACE_MODULE_APP,"标签ID:%X,距离: %d 信号强度:%d.\r\n",g_com_map[BIND_DEV_ID],distance,rssi);
-        }
+        break;
+				}
     } else {
-        sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US));//测试
+			uwb_rx(0, 0, range_timeout_us);
+    }
+	}
+		if(!flag_recsuccess)
+		{
+			sleep_timer_start(__MS_TO_32K_CNT(UWB_DELAY_TIME_US-3));//测试
         LOG_INFO(TRACE_MODULE_APP,"测距失败,计数:%d\r\n",recev_error_num);
         if(recev_error_num++>5)
         {
@@ -440,8 +461,7 @@
             uwb_searchcount = 0;
             search_open_flag = 1;
         }
-    }
-   
+			}
     gpio_pin_clr(SCL_PIN);
 }
 
@@ -540,7 +560,7 @@
             }
 
         }
-
+				temp_count3=phy_timer_count_get();
         uwb_rx(0, 0, RX_SYNC_WIN_US_TEMP);//再次开启接收
 
     }
@@ -550,7 +570,7 @@
 }
 //}
 
-#define SEARCH_TIMESTEMP 120
+#define SEARCH_TIMESTEMP 20
 void UWBPoll(void)
 {
     switch(UWB_work_state)

--
Gitblit v1.9.3