From 1ebb084c4d5216f4e5e3e61a63c88f568caf779e Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期五, 28 九月 2018 11:27:10 +0800
Subject: [PATCH] 增加多标签测距功能,标签有bug,长时间会死机

---
 源码/核心板/Src/application/dw_app.c |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
index c5c6329..731f7e8 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.c"
@@ -138,6 +138,8 @@
 float dis_after_filter;				//当前距离值
 LPFilter_Frac* p_Dis_Filter;		//测距用的低通滤波器
 
+uint16_t g_Tagdist[256];
+uint8_t g_flag_Taggetdist[256];
 /*------------------------------------ Functions ------------------------------------------*/
 
 
@@ -219,7 +221,23 @@
         *ts += ts_field[i] << (i * 8);
     }
 }
-
+void TagDistClear(void)
+{
+	static uint16_t clear_judge_cnt;
+	uint16_t i;
+	if(clear_judge_cnt++>1000)  //设定1S分频,每秒进一次。判断标志位大于等于2,2s没收到数据就把数据变成0xffff,不触发警报。
+	{
+		clear_judge_cnt=0;
+		for(i=0;i<255;i++)
+		{
+			g_flag_Taggetdist[i]++;
+			if(g_flag_Taggetdist[i]>=2)
+			{
+				g_Tagdist[i]=0xffff;
+			}
+		}
+	}
+}
 void Dw1000_Init(void)
 {
 	/* Reset and initialise DW1000.
@@ -245,6 +263,7 @@
 }
 void Dw1000_App_Init(void)
 {
+	g_com_map[DEV_ID]=0x03;
 	tx_poll_msg[MESSAGE_TYPE_IDX]=POLL;
 	tx_resp_msg[MESSAGE_TYPE_IDX]=RESPONSE;
 	tx_final_msg[MESSAGE_TYPE_IDX]=FINAL;
@@ -269,7 +288,7 @@
 	GPIO_SetBits(SPIx_GPIO, SPIx_CS);
 	
 	/* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
-
+	tx_poll_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
 	dwt_writetxdata(sizeof(tx_poll_msg), tx_poll_msg, 0);//将Poll包数据传给DW1000,将在开启发送时传出去
 	dwt_writetxfctrl(sizeof(tx_poll_msg), 0);//设置超宽带发送数据长度
 
@@ -297,7 +316,7 @@
 
 		/* Check that the frame is the expected response from the companion "DS TWR responder" example.
 		 * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */
-
+		rx_buffer[ALL_MSG_SN_IDX] = 0;
 		if (rx_buffer[MESSAGE_TYPE_IDX] == RESPONSE) //判断接收到的数据是否是response数据
 		{
 			/* Retrieve poll transmission and response reception timestamp. */
@@ -319,7 +338,7 @@
 			final_msg_set_ts(&tx_final_msg[FINAL_MSG_FINAL_TX_TS_IDX], final_tx_ts);
 
 			/* Write and send final message. See NOTE 7 below. */
-		
+			tx_final_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
 			dwt_writetxdata(sizeof(tx_final_msg), tx_final_msg, 0);//将发送数据写入DW1000
 			dwt_writetxfctrl(sizeof(tx_final_msg), 0);//设定发送数据长度
 			dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送
@@ -383,7 +402,7 @@
 
 		/* Check that the frame is a poll sent by "DS TWR initiator" example.
 		 * As the sequence number field of the frame is not relevant, it is cleared to simplify the validation of the frame. */
-	
+		rx_buffer[ALL_MSG_SN_IDX] = 0;
 		
 		//将收到的tag_id分别写入各次通讯的包中,为多标签通讯服务,防止一次通讯中接收到不同ID标签的数据
 		tag_id_recv = rx_buffer[TAG_ID_IDX];
@@ -405,7 +424,7 @@
 
 			/* Write and send the response message. See NOTE 9 below.*/
 			memcpy(&tx_resp_msg[DIST_IDX], &anchor_dist_last_frm[tag_id_recv], 2);
-			
+			tx_resp_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
 			dwt_writetxdata(sizeof(tx_resp_msg), tx_resp_msg, 0);//写入发送数据
 			dwt_writetxfctrl(sizeof(tx_resp_msg), 0);//设定发送长度
 			dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//延迟发送,等待接收
@@ -431,6 +450,7 @@
 
 				/* Check that the frame is a final message sent by "DS TWR initiator" example.
 				 * As the sequence number field of the frame is not used in this example, it can be zeroed to ease the validation of the frame. */
+				rx_buffer[ALL_MSG_SN_IDX] = 0;
 				if (rx_buffer[MESSAGE_TYPE_IDX] == FINAL&&rx_buffer[TAG_ID_IDX]==tag_id_recv&&rx_buffer[ANCHOR_ID_IDX]==g_com_map[DEV_ID]) //判断是否为Final包
 				{
 					uint32_t poll_tx_ts, resp_rx_ts, final_tx_ts;
@@ -468,6 +488,8 @@
 					LED0_BLINK; //每成功一次通讯则闪烁一次
 					g_UWB_com_interval = 0;
 					dis_after_filter=dist_cm;
+					g_Tagdist[tag_id_recv]=dist_cm;
+					g_flag_Taggetdist[tag_id_recv]=0;
 					//dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm);
 
 				}

--
Gitblit v1.9.3