From f56dde7abad991a2c810708e80bf6da5f7a9fc88 Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期五, 15 八月 2025 16:29:47 +0800
Subject: [PATCH] 适配最新ss定位标签固件

---
 keil/uwb_app.c |   54 ++++++++++++++++++++----------------------------------
 1 files changed, 20 insertions(+), 34 deletions(-)

diff --git a/keil/uwb_app.c b/keil/uwb_app.c
index d6a5764..9378f01 100644
--- a/keil/uwb_app.c
+++ b/keil/uwb_app.c
@@ -78,7 +78,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 550U //yuan600 success 并且不卡busy
+#define POLL_RX_TO_RESP_TX_DLY_US 1000U //yuan600 success 并且不卡busy
 
 #define RESP_TX_TO_FINAL_RX_DLY_US 500U
 
@@ -254,7 +254,7 @@
         receive_flag=1;
 //        uart_send(UART_ID0, rx_buf,rx_length, NULL);
         gpio_pin_toggle(IO_PIN_4);
-        if(rx_buf[MESSAGE_TYPE_IDX]==MBX_POLL&&!shengji_flag)
+        if((rx_buf[MESSAGE_TYPE_IDX]==MBX_POLL||rx_buf[MESSAGE_TYPE_IDX]==DISCOVERPOLL2)&&!shengji_flag)
         {
         Anchor_App();
         }
@@ -482,6 +482,7 @@
 //    }
 //    anchordata_num=j;
 //}
+int8_t test22,test33;
 void TagListUpdate(void)
 {
 uint16_t i,j=0,k=0;
@@ -539,11 +540,11 @@
     if(cmd_flag==0)
     {
     temp_count2=poll_rx_en_start_u32;
-
+    group_id=0xff;
     memcpy(&send_buffer[GROUP_ID_IDX],&group_id,1);//组id
     memcpy(&send_buffer[ANCHOR_ID_IDX],&dev_id,2);//自身id
     memcpy(&send_buffer[TAG_ID_IDX],&tag_id_recv,2);//接受者id
-    send_buffer[MESSAGE_TYPE_IDX]=MBX_RESPONSE;
+    send_buffer[MESSAGE_TYPE_IDX]=POS_RESPONSE;
 
 //    if(rec_nearbase_num == ancrec_nearbasepos)//抢占模式自己为新基站
 //    {
@@ -558,7 +559,7 @@
 //				//这里应该有问题问一下钟工
 //		}//此处设置绝对时间将poll u32改为phy_timer_count_get()
 		position=ancrec_nearbasepos;
-		resp_tx_en_start_u32 = poll_rx_en_start_u32+US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US)+ancrec_nearbasepos*US_TO_PHY_TIMER_COUNT(DELAY_BETWEEN_TWO_FRAME_UUS);//加入帧间隔
+		resp_tx_en_start_u32 = poll_rx_en_start_u32+US_TO_PHY_TIMER_COUNT(POLL_RX_TO_RESP_TX_DLY_US);//加入帧间隔
     resp_tx_ts_i64 = ranging_tx_time_correct(resp_tx_en_start_u32 + phy_shr_duration());//修正时间戳
     /* Write all timestamps in the final message. See NOTE 8 below. */
     resp_msg_set_ts(&send_buffer[RESP_MSG_POLL_RX_TS_IDX], poll_rx_ts_i64);
@@ -568,6 +569,7 @@
     temp_count3= phy_timer_count_get();
     flag_temp2=uwb_tx(send_buffer, 40,1 ,resp_tx_en_start_u32);//立即发送测试size大小
 		tagofflinetime[taglist_pos] = 0;//更新标签通信
+        test33++;
 //    temp_count1=phy_timer_count_get();
     //while(mac_is_busy());
     //gpio_pin_clr(SCL_PIN);
@@ -706,11 +708,11 @@
 {
 	 UWBIdleTask();
 }
+int32_t u32_rec_ancdistlist[TAG_NUM_IN_SYS];
 int Anchor_App(void)
 {
 								uint8_t i;
 				uint16_t tempid;
-			if(group_id==rx_buf[GROUP_ID_IDX]&&rx_buf[MESSAGE_TYPE_IDX] == MBX_POLL)//判断是否是和自己是同一组通讯的且为poll包
         {    flag_recsuccess = 1;
 						wltag_state=RANGE;//成功后从search切换为range
 						memcpy(&g_com_receive_id,&rx_buf[TAG_ID_IDX],2);
@@ -718,41 +720,25 @@
 						uwb_losttimer=0;//成功测距清0 lost时间
             frame_seq_nb2 = rx_buf[SEQUENCE_IDX];//获取包序
             battary = rx_buf[BATTARY_IDX];
-            rec_nearbase_num=rx_buf[FZ_NEARBASENUM_INDEX];  //标签传过来的他与基站交互的基站id数目
+            rec_nearbase_num=rx_buf[18];  //标签传过来的他与基站交互的基站id数目
             memcpy(&tag_id_recv,&rx_buf[TAG_ID_IDX],2);
-            memcpy(rec_ancidlist,&rx_buf[FZ_NEARBASEID_INDEX],2*rec_nearbase_num);
-            memcpy(rec_ancdistlist,&rx_buf[FZ_NEARBASEID_INDEX+2*rec_nearbase_num],2*rec_nearbase_num);
-            memcpy(&rec_antdelay,&rx_buf[FZ_NEARBASEID_INDEX+rec_nearbase_num*4],2);
-//            for(i=0; i<rec_nearbase_num; i++)
-//            {
-//                if(rec_ancidlist[i] == dev_id)
-//                {		temp_recdist_before_offset=rec_ancdistlist[i];
-//                    rec_ancdistlist[i]+=(int16_t)g_com_map[DIST_OFFSET];
-//                    PushAnchorDataArray(tag_id_recv,rec_ancdistlist[i],battary);
-//                }
-//            }
-//            for(i=0; i<rec_nearbase_num; i++)
-//            {
-//                memcpy(&tempid,&rx_buf[FZ_NEARBASEID_INDEX+i*2],2);
-//                if(tempid==dev_id)//也是比id如果有就更新没有就抢占
-//                {
-//                    seize_anchor=0;  //非抢占。已存在列表中
-//                    Anchor_RecNearPoll(i);
-//                    break;
-//                }
-//            }
+            memcpy(rec_ancidlist,&rx_buf[19+2],2*rec_nearbase_num);
 
-//            if(i==rec_nearbase_num)
-//            {
-//                seize_anchor=1;   //抢占anchor
-//                Anchor_RecNearPoll(i);
-//            }
+            memcpy(u32_rec_ancdistlist,&rx_buf[19+4+2*rec_nearbase_num],4*rec_nearbase_num);
+            for (int i = 0; i < rec_nearbase_num+1; i++) 
+            {
+            rec_ancdistlist[i] = (int16_t)(u32_rec_ancdistlist[i] & 0xFFFF);
+            }
+            test22++;
+//            memcpy(rec_ancdistlist,&rx_buf[FZ_NEARBASEID_INDEX+2*rec_nearbase_num],2*rec_nearbase_num);
+//            memcpy(&rec_antdelay,&rx_buf[FZ_NEARBASEID_INDEX+rec_nearbase_num*4],2);
+
 								taglist_pos=CmpTagInList(tag_id_recv);
                 if(taglist_num>=ANC_MAX_NUM)
 										return 0;
 								 for(i=0; i<rec_nearbase_num; i++)
 								{
-										memcpy(&tempid,&rx_buf[FZ_NEARBASEID_INDEX+i*2],2);
+										memcpy(&tempid,&rx_buf[19+2+i*2],2);
 										if(tempid==dev_id)
 										{
 												Anchor_RecNearPoll(i);

--
Gitblit v1.9.3