From 96ca4b1952c1c4bf85704208f53c97b45a875b04 Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期一, 01 十月 2018 12:25:53 +0800
Subject: [PATCH] 更改距离设置格式

---
 源码/核心板/Src/application/dw_app.h            |    1 +
 源码/核心板/Src/main.c                          |    4 ++--
 源码/核心板/Src/application/serial_at_cmd_app.c |   14 +++++++++++++-
 源码/核心板/Src/application/dw_app.c            |   22 +++++++++++++---------
 4 files changed, 29 insertions(+), 12 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 731f7e8..ef8d58c 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"
@@ -263,7 +263,7 @@
 }
 void Dw1000_App_Init(void)
 {
-	g_com_map[DEV_ID]=0x03;
+	g_com_map[DEV_ID]=0x00;
 	tx_poll_msg[MESSAGE_TYPE_IDX]=POLL;
 	tx_resp_msg[MESSAGE_TYPE_IDX]=RESPONSE;
 	tx_final_msg[MESSAGE_TYPE_IDX]=FINAL;
@@ -277,14 +277,14 @@
 	dwt_configuresleep(0x940, 0x7);
 	dwt_entersleep();
 }
-
+uint8_t result;
 void Tag_App(void)//发送模式(TAG标签)
 {
 	uint32_t frame_len;
 	uint32_t final_tx_time;
 	
 	GPIO_ResetBits(SPIx_GPIO, SPIx_CS);
-	delay_us(2000);
+	delay_us(250);
 	GPIO_SetBits(SPIx_GPIO, SPIx_CS);
 	
 	/* Write frame data to DW1000 and prepare transmission. See NOTE 7 below. */
@@ -341,12 +341,14 @@
 			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);//设定为延迟发送
+			result=dwt_starttx(DWT_START_TX_DELAYED);//设定为延迟发送
+			
 			
 			/* Poll DW1000 until TX frame sent event set. See NOTE 8 below. */
-			while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成
+			if(result==0)
+			{while (!(dwt_read32bitreg(SYS_STATUS_ID) & SYS_STATUS_TXFRS))//不断查询芯片状态直到发送完成
 			{ };
-
+		}
 			/* Clear TXFRS event. */
 			dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_TXFRS);//清除标志位
 
@@ -427,13 +429,15 @@
 			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);//延迟发送,等待接收
+			result = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);//延迟发送,等待接收
 
 			/* We assume that the transmission is achieved correctly, now poll for reception of expected "final" frame or error/timeout.
 			 * See NOTE 7 below. */
-			while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))///不断查询芯片状态直到接收成功或者出现错误
+			if(result==0)
+			{
+				while (!((status_reg = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))///不断查询芯片状态直到接收成功或者出现错误
 			{ };
-
+		}
 			/* Increment frame sequence number after transmission of the response message (modulo 256). */
 			frame_seq_nb++;
 
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h"
index c232afa..7f107f8 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/dw_app.h"
@@ -20,4 +20,5 @@
 extern uint16_t g_Tagdist[256];
 extern uint8_t g_flag_Taggetdist[256];
 extern void TagDistClear(void);
+void Dw1000_App_Init(void);
 #endif
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c"
index b3d7257..da57aa0 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c"
@@ -10,7 +10,19 @@
 {
 	if(!memcmp(m_frame_data, "DIS", 3))
 	{
-		g_com_map[ALARM_DISTANCE] = (m_frame_data[3]-'0')*1000 + (m_frame_data[4]-'0')*100 +  (m_frame_data[5]-'0')*10 + (m_frame_data[6]-'0');
+		g_com_map[ALARM_DISTANCE] =0;
+		for(uint8_t i=3; i < m_frame_data_len; i++)
+		{
+			if(m_frame_data[i]<58 && m_frame_data[i]>47)
+			{
+				g_com_map[ALARM_DISTANCE] = g_com_map[ALARM_DISTANCE]*10 + m_frame_data[i]- '0';
+			}
+			else
+			{
+				printf("Error: Wrong DISTANCE.\r\n");
+				break;
+			}
+		}
 		printf("When distance < %d cm, alarm is on.\n", g_com_map[ALARM_DISTANCE]);
 		save_com_map_to_flash();
 	}
diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
index 4d5adbc..917fef0 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/main.c"
@@ -10,8 +10,8 @@
 #include "serial_at_cmd_app.h"
 #include "global_param.h"
 
-//#define WORK_MODE_TAG
-#define WORK_MODE_ANCHOR
+#define WORK_MODE_TAG
+//#define WORK_MODE_ANCHOR
 
 void Device_Init(void)
 {

--
Gitblit v1.9.3