From 9ff25be6f85a1dc8a04470437d6597399a45d11f Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期五, 15 九月 2023 17:08:29 +0800
Subject: [PATCH] 1

---
 Src/application/dw_app.c |   64 +++++++++++++++++++++++++++++--
 1 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c
index ef8207f..b994d8b 100644
--- a/Src/application/dw_app.c
+++ b/Src/application/dw_app.c
@@ -70,8 +70,15 @@
 #define FINAL_MSG_RESP_RX_TS_IDX 14
 #define FINAL_MSG_FINAL_TX_TS_IDX 18
 #define FINAL_MSG_TS_LEN 4
+
+//#define _UWB_4G
+
 static dwt_config_t config = {
-	5,               /* Channel number. */
+#ifdef _UWB_4G
+	2,               /* Channel number. */
+#else
+    5,
+#endif
 	DWT_PRF_64M,     /* Pulse repetition frequency. */
 	DWT_PLEN_64,    /* Preamble length. */
 	DWT_PAC8,        /* Preamble acquisition chunk size. Used in RX only. */
@@ -175,7 +182,6 @@
     /* Apply default antenna delay value. See NOTE 1 below. */
     dwt_setrxantennadelay(RX_ANT_DLY);		//设置接收天线延迟
     dwt_settxantennadelay(TX_ANT_DLY);		//设置发射天线延迟
-
     /* Set expected response's delay and timeout. See NOTE 4 and 5 below.
      * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */
 				//设置接收超时时间
@@ -338,7 +344,11 @@
       {
 
          // exsistbase_list[i]--;
-          clockOffsetRatio = anc_clockoffset[i] * (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ;
+#ifdef _UWB_4G
+            clockOffsetRatio = anc_clockoffset[i] * (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_2 / 1.0e6) ;
+#else
+            clockOffsetRatio = anc_clockoffset[i] * (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ;
+#endif
           rtd_init = tag_resprx[i] - poll_tx_ts;
           rtd_resp = anc_resptx[i] - anc_pollrx[i];
           tof = ((rtd_init - rtd_resp * (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS;
@@ -350,6 +360,35 @@
       }
     
     }
+}
+extern uint8_t module_power,imu_enable,motor_enable;
+void Registor_Poll(void)
+{
+	static u8 regpoll_count=0;
+    u8 timeout;
+		
+		tx_near_msg[MESSAGE_TYPE_IDX] = MBX_REG;
+        tx_near_msg[REGP_TAGSTATE_INDEX] = !GET_USERKEY<<2|imu_enable<<1|motor_enable;
+		tx_near_msg[REGP_FREQUENCY_INDEX] = bat_percent;
+		tx_near_msg[REGP_POWER_INDEX] = module_power;
+		memcpy(&tx_near_msg[REGP_VERSION_INDEX],&g_com_map[VERSION],2);	
+		memcpy(&tx_near_msg[REGP_IMUTHRES_INDEX],&g_com_map[GROUP_ID],2);
+		memcpy(&tx_near_msg[REGP_NOMOVESLEEPTIME_INDEX],&g_com_map[DIST_OFFSET],2);
+        memcpy(&tx_near_msg[REGP_HEIGHTOFFSET_INDEX],&g_com_map[MAX_REPORT_ANC_NUM],2);
+		dwt_writetxdata(23, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
+		dwt_writetxfctrl(23, 0);//设置超宽带发送数据长度
+		dwt_starttx(DWT_START_TX_IMMEDIATE);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置
+        start_count=HAL_LPTIM_ReadCounter(&hlptim1);
+        timeout=50;
+        end_count=start_count+(timeout<<2);
+        while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_TXFRS)))//不断查询芯片状态直到成功接收或者发生错误
+        { 
+            current_count=HAL_LPTIM_ReadCounter(&hlptim1);
+           if(current_count>=end_count&&current_count<end_count+15000)
+								break;
+            
+        };	
+               
 }
 float range_lost_time = 0;
 u16 rec_nearbaseid,rec_nearbasepos;
@@ -395,7 +434,7 @@
 	flag_getresponse=0;
 	start_count=HAL_LPTIM_ReadCounter(&hlptim1);
 	recbase_num=0;
-	timeout=nearbase_num*SLOT_SCALE+10;
+	timeout=nearbase_num*SLOT_SCALE+50;
 	end_count=start_count+(timeout<<2);
 	if(end_count>=32768)
 	{end_count-=32768;}
@@ -403,6 +442,7 @@
 	mainbase_lost_count++;
 	current_count=HAL_LPTIM_ReadCounter(&hlptim1);
 			while(current_count<end_count||current_count>end_count+15000)
+//            while(1)
 			{
 				current_count=HAL_LPTIM_ReadCounter(&hlptim1);
 					while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误
@@ -640,7 +680,7 @@
         }
     }
 }
-
+u8 regpoll_count;
 u32 id;
 void Tag_App(void)//发送模式(TAG标签)
 {
@@ -659,6 +699,20 @@
     }
     delay_us(100);
 	g_Resttimer=0;
+    if(freqlost_count>FREQ_LOST_TIME)
+    {
+        if(regpoll_count++>11) //待机状态1分钟上传一次基站状态
+        {
+            regpoll_count = 0;
+            Registor_Poll();
+        }
+    }else{
+        if(regpoll_count++>59)//测距状态1分钟上传一次基站状态
+        {
+            regpoll_count = 0;
+            Registor_Poll();
+        }
+    }
 	NearPoll();
 	dwt_entersleep();
     bat_percent=Get_VDDVlotage();

--
Gitblit v1.9.3