From 743f4f1291c555b1facc0c34bcbb3cea3cfd41c4 Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期一, 29 七月 2019 16:54:22 +0800
Subject: [PATCH] 标签输出

---
 源码/核心板/Src/application/dw_app.c |   59 ++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 42 insertions(+), 17 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 9b4c5fa..2a1e753 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"
@@ -46,9 +46,9 @@
 #define POLL_TX_TO_RESP_RX_DLY_UUS 150
 /* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the
  * frame length of approximately 2.66 ms with above configuration. */
-#define RESP_RX_TO_FINAL_TX_DLY_UUS 1500
+#define RESP_RX_TO_FINAL_TX_DLY_UUS 400
 /* Receive response timeout. See NOTE 5 below. */
-#define RESP_RX_TIMEOUT_UUS 2700
+#define RESP_RX_TIMEOUT_UUS 600
 
 #define POLL_RX_TO_RESP_TX_DLY_UUS 420
 /* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */
@@ -93,7 +93,7 @@
 };
 
 /* Frames used in the ranging process. See NOTE 2 below. */
-static uint8_t tx_poll_msg[18] = {0};
+static uint8_t tx_poll_msg[19] = {0};
 //static uint8_t rx_resp_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'V', 'E', 'W', 'A', 0x10, 0x02, 0, 0, 0, 0};
 static uint8_t tx_final_msg[] = {0x41, 0x88, 0, 0xCA, 0xDE, 'W', 'A', 'V', 'E', 0x23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 	
@@ -256,8 +256,7 @@
 
     /* 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. */
-    dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);			//设置发送后开启接收,并设定延迟时间
-    dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);						//设置接收超时时间
+				//设置接收超时时间
 }
 void Dw1000_App_Init(void)
 {
@@ -300,12 +299,15 @@
 	uint32_t final_tx_time;
 	u32 start_poll;
 	u8 i;
-	
+	//LED0_ON;
+	dwt_forcetrxoff();
 	g_Resttimer=0;
-	GPIO_ResetBits(SPIx_GPIO, SPIx_CS);
-	delay_us(2500);
-	GPIO_SetBits(SPIx_GPIO, SPIx_CS);
+    dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS);			//设置发送后开启接收,并设定延迟时间
+    dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);		
 	tag_succ_times = 0;
+	tx_poll_msg[BATTARY_IDX] = Get_Battary();
+	tx_poll_msg[BUTTON_IDX] = !READ_KEY0;
+
 	for(i=0;i<REPOET_ANC_NUM;i++)
 	{
 	/* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
@@ -323,7 +325,7 @@
 	{ if(time32_incr - start_poll>20)
 		NVIC_SystemReset();
 		UART_CheckReceive();
-		UART_CheckSend();
+		
 	};
 
 	/* Increment frame sequence number after transmission of the poll message (modulo 256). */
@@ -352,7 +354,7 @@
 			poll_tx_ts = get_tx_timestamp_u64();										//获得POLL发送时间T1
 			resp_rx_ts = get_rx_timestamp_u64();										//获得RESPONSE接收时间T4
 			
-			memcpy(&anchor_dist_last_frm[tag_id], &rx_buffer[DIST_IDX], 4);
+			memcpy(&anchor_dist_last_frm[0], &rx_buffer[DIST_IDX], 4);
 			memcpy(&tx_final_msg[ANCHOR_ID_IDX], &rx_buffer[ANCHOR_ID_IDX], 4);
 			/* Compute final message transmission time. See NOTE 9 below. */
 			final_tx_time = (resp_rx_ts + (RESP_RX_TO_FINAL_TX_DLY_UUS * UUS_TO_DWT_TIME)) >> 8;//计算final包发送时间,T5=T4+Treply2
@@ -373,7 +375,25 @@
 			result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送
 			
 			tag_succ_times++;
-			
+			#ifdef WORK_MODE_TAG
+				LED0_BLINK;
+			#endif
+				#ifdef HEX_OUTPUT
+					usart_send[2] = frame_seq_nb++;
+					//usart_send[6] = tag_id_recv;
+					//usart_send[8] = g_com_map[DEV_ID];
+					memcpy(&usart_send[3],&dev_id,4);
+					memcpy(&usart_send[7],&rx_buffer[ANCHOR_ID_IDX],4);
+					hex_dist = anchor_dist_last_frm[0];
+					memcpy(&usart_send[11],&hex_dist,4);
+					usart_send[15] = battary;
+					usart_send[16] = button;
+					checksum = Checksum_u16(&usart_send[2],19);
+					memcpy(&usart_send[21],&checksum,2);
+					UART_PushFrame(usart_send,23);
+					#else
+					printf("Anchor ID: %d, Tag ID: %d, Dist = %d cm\n", g_com_map[DEV_ID_L]|g_com_map[DEV_ID_L]<<8, tag_id_recv, (uint16_t)dist_cm);
+					#endif
 			/* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */
 			if(result==0)
 			{while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成
@@ -399,18 +419,18 @@
 	}
 //	deca_sleep(10);
 }
-	dwt_entersleep();
+//	dwt_entersleep();
 	if(tag_succ_times<REPOET_ANC_NUM_MIN)
 	{
 	random_delay_tim =time32_incr&0x8f+7;
 	deca_sleep(random_delay_tim);
 	}
-	LED0_BLINK;
+	//LED0_BLINK;
 	RTC_SET_ALARM(1);
 	/* Execute a delay between ranging exchanges. */
 	
 }
-
+extern uint8_t g_start_send_flag;
 void Anchor_App(void)
 {
 	uint32_t frame_len;
@@ -423,7 +443,7 @@
 	dwt_rxenable(0);//打开接收
 
 	/* Poll for reception of a frame or error/timeout. See NOTE 7 below. */
-	while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到接收成功或者出现错误
+	while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR))&&!g_start_send_flag)//不断查询芯片状态直到接收成功或者出现错误
 	{ 
 		UART_CheckReceive();
 		UART_CheckSend();
@@ -477,6 +497,8 @@
 			dwt_writetxfctrl(sizeof(tx_resp_msg), 0);//设定发送长度
 			result = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//延迟发送,等待接收
 
+			battary = rx_buffer[BATTARY_IDX];
+			button = rx_buffer[BUTTON_IDX];
 			/* We assume that the transmission is achieved correctly, now poll for reception of expected "final" frame or error/timeout.
 			 * See NOTE 7 below. */
 			if(result==0)
@@ -548,8 +570,11 @@
 //						printf("Pair Finish PairID: %d. \r\n",g_com_map[PAIR_ID]);
 //					}
 					// tag_time_recv[tag_id_recv] = tag_recv_timer;
+						if(tag_id_recv-TAG_ID_START<=TOTAL_TAG_NUM)
+						{
 					g_flag_Taggetdist[tag_id_recv-TAG_ID_START]=0;
 					anchor_dist_last_frm[tag_id_recv-TAG_ID_START] = dist_cm;
+						}
 					#ifdef HEX_OUTPUT
 					usart_send[2] = frame_seq_nb++;
 					//usart_send[6] = tag_id_recv;
@@ -564,7 +589,7 @@
 					memcpy(&usart_send[21],&checksum,2);
 					UART_PushFrame(usart_send,23);
 					#else
-					printf("Anchor ID: %d, Tag ID: %d, Dist = %d cm\n", g_com_map[DEV_ID], tag_id_recv, (uint16_t)dis_after_filter);
+					printf("Anchor ID: %d, Tag ID: %d, Dist = %d cm\n", g_com_map[DEV_ID_L]|g_com_map[DEV_ID_L]<<8, tag_id_recv, (uint16_t)dist_cm);
 					#endif
 					
 					//dis_after_filter = LP_Frac_Update(p_Dis_Filter, dist_cm);

--
Gitblit v1.9.3