From da6d7e68ec3d303e78e83a1adf17f638a0d49269 Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期二, 26 十二月 2023 15:45:30 +0800
Subject: [PATCH] 1

---
 Src/application/dw_app.c |  111 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 66 insertions(+), 45 deletions(-)

diff --git a/Src/application/dw_app.c b/Src/application/dw_app.c
index 4b11118..339297e 100644
--- a/Src/application/dw_app.c
+++ b/Src/application/dw_app.c
@@ -113,7 +113,7 @@
 uint32_t g_UWB_com_interval = 0; 
 float dis_after_filter;				//当前距离值
 LPFilter_Frac* p_Dis_Filter;		//测距用的低通滤波器
-
+float range_lost_time = 0;
 
 
 static uint64_t get_tx_timestamp_u64(void)
@@ -182,6 +182,13 @@
     /* Apply default antenna delay value. See NOTE 1 below. */
     dwt_setrxantennadelay(RX_ANT_DLY);		//设置接收天线延迟
     dwt_settxantennadelay(TX_ANT_DLY);		//设置发射天线延迟
+//            dwt_configcontinuousframemode(12480);
+//    dwt_writetxdata(13, usart_send, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
+//	dwt_writetxfctrl(13, 0);//设置超宽带发送数据长度
+//	dwt_starttx(DWT_START_TX_IMMEDIATE);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置
+
+//while(1)
+//{}
     /* 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. */
 				//设置接收超时时间
@@ -355,6 +362,7 @@
           distance = tof * SPEED_OF_LIGHT;
           if(distance>-10&&distance<1000)
             nearbase_distlist[i] = distance*100+anc_distoffset[i];
+          range_lost_time=0;
       }else{
          // nearbase_distlist[i] = 0x1ffff;
       }
@@ -391,8 +399,8 @@
                
 }
 u16 numceshi;
-float range_lost_time = 0;
 u16 rec_nearbaseid,rec_nearbasepos;
+extern  u16 poll_startcount;
 void NearPoll(void)
 {
 	
@@ -425,7 +433,18 @@
 	memcpy(&tx_near_msg[ANCHOR_ID_IDX],&mainbase_id,2);	
 	dwt_writetxdata(13+4*nearbase_num, tx_near_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
 	dwt_writetxfctrl(13+4*nearbase_num, 0);//设置超宽带发送数据长度
+    current_count=HAL_LPTIM_ReadCounter(&hlptim1);
+		while(current_count<poll_startcount||current_count>poll_startcount+16384)
+		{
+			current_count=HAL_LPTIM_ReadCounter(&hlptim1);
+			if(current_count<poll_startcount-300)
+			{
+				break;
+			}
+		}
+        
 	dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//开启发送,发送完成后等待一段时间开启接收,等待时间在dwt_setrxaftertxdelay中设置
+    HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);
 	numceshi++;
 	tx_near_msg[TAGCONFIGSUCCESS_INDEX] =0;
 	para_update = 0;
@@ -435,7 +454,7 @@
 	flag_getresponse=0;
 	start_count=HAL_LPTIM_ReadCounter(&hlptim1);
 	recbase_num=0;
-	timeout=nearbase_num*SLOT_SCALE+20; //单位0.1ms
+	timeout=nearbase_num*SLOT_SCALE+100; //单位0.1ms
 	end_count=start_count+(timeout<<2);
 	if(end_count>=32768)
 	{end_count-=32768;}
@@ -448,31 +467,31 @@
 				current_count=HAL_LPTIM_ReadCounter(&hlptim1);
 					while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误
 					{
-						if(flag_finalsend&&flag_ancreadpara)
-						{
-							dw_systime=dwt_readsystimestamphi32();
-							if(dw_systime>temp1&&dw_systime<temp2)
-							{
-								
-								dwt_forcetrxoff();
-								flag_rxon=0;
-                                if(flag_ancreadpara)   //只有在读取参数的时候需要回复
-                                {
-                                    u16 calCRC;
-                                  tx_near_msg[MESSAGE_TYPE_IDX] = MBX_PRAAREPLY;  
-                                  memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX],g_com_map,SENDANCPARA_LEN);
-                                  calCRC = CRC_Compute((uint8_t*)g_com_map,SENDANCPARA_LEN);
-                                  memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX+SENDANCPARA_LEN],&calCRC,2);
-                                  dwt_writetxdata(14+SENDANCPARA_LEN, tx_near_msg, 0);//将发送数据写入DW1000
-                                  dwt_writetxfctrl(14+SENDANCPARA_LEN, 0);//设定发送数据长度
-                                
-								dwt_setdelayedtrxtime(final_tx_time);
-								result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送	
-                                }
-								flag_finalsend=0;
-								break;
-							}
-						}
+//						if(flag_finalsend&&flag_ancreadpara)
+//						{
+//							dw_systime=dwt_readsystimestamphi32();
+//							if(dw_systime>temp1&&dw_systime<temp2)
+//							{
+//								
+//								dwt_forcetrxoff();
+//								flag_rxon=0;
+//                                if(flag_ancreadpara)   //只有在读取参数的时候需要回复
+//                                {
+//                                    u16 calCRC;
+//                                  tx_near_msg[MESSAGE_TYPE_IDX] = MBX_PRAAREPLY;  
+//                                  memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX],g_com_map,SENDANCPARA_LEN);
+//                                  calCRC = CRC_Compute((uint8_t*)g_com_map,SENDANCPARA_LEN);
+//                                  memcpy(&tx_near_msg[MESSAGE_PARAREPLY_IDX+SENDANCPARA_LEN],&calCRC,2);
+//                                  dwt_writetxdata(14+SENDANCPARA_LEN, tx_near_msg, 0);//将发送数据写入DW1000
+//                                  dwt_writetxfctrl(14+SENDANCPARA_LEN, 0);//设定发送数据长度
+//                                
+//								dwt_setdelayedtrxtime(final_tx_time);
+//								result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送	
+//                                }
+//								flag_finalsend=0;
+//								break;
+//							}
+//						}
 							current_count=HAL_LPTIM_ReadCounter(&hlptim1);
 						 if(current_count>=end_count&&current_count<end_count+15000)
 								break;
@@ -498,7 +517,9 @@
 								recbase_num++;
 								memcpy(&rec_nearbaseid,&rx_buffer[ANCHOR_ID_IDX],2);
                                 rec_remotepara_state = rx_buffer[MOTORSTATE_INDEX]>>4;
-                                TagFreqProcess(rx_buffer[TAGFREQ_IDX]);
+//                                TagFreqProcess(rx_buffer[TAGFREQ_IDX]);
+//                                if(rec_nearbaseid==0x9002)
+//                                {rec_remotepara_state = rx_buffer[MOTORSTATE_INDEX]>>4;}
                                 if(rec_remotepara_state != 0)
                                 {   
                                     para_update = rec_remotepara_state;
@@ -609,9 +630,9 @@
 				}
 			}
             nearbase_num = next_nearbase_num;
-            if(mainbase_lost_count>1&&exsistbase_list[0] != 0)
+            if(mainbase_lost_count>1)//&&exsistbase_list[0] != 0)
 			{
-                last_lpcount+= HAL_LPTIM_ReadCounter(&hlptim1)%(g_com_map[COM_INTERVAL]*16);
+                last_lpcount-= HAL_LPTIM_ReadCounter(&hlptim1)%(g_com_map[COM_INTERVAL]*16);
 			}
             last_nearbase_num = next_nearbase_num;
 			for(i=0;i<last_nearbase_num-1;i++)
@@ -702,20 +723,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();
-        }
-    }
+//    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