From 643829caa98867a769a95a25a7d6e93042f7b2bc Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期三, 10 七月 2019 14:58:28 +0800
Subject: [PATCH] 去掉标签输出,标签探索6-4响应模式

---
 源码/核心板/Src/application/serial_at_cmd_app.c |  132 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 127 insertions(+), 5 deletions(-)

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 913b7c5..fe9b6d4 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"
@@ -1,19 +1,141 @@
 #include "serial_at_cmd_app.h"
 #include "global_param.h"
 #include <string.h>
-
+#include <stdio.h>
+#include "dw_app.h"
+#include "RTC.h"
 uint8_t m_frame_data[MAX_FRAME_LEN] = {0};
 uint8_t m_frame_data_len = 0;
-
+uint8_t g_pairstart=0;
 void ParseFrame(void)
 {
-	if(!memcmp(m_frame_data, "SET", 3))
+	if(!memcmp(m_frame_data, "DIS1", 4))
 	{
-		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_DISTANCE1] =0;
+		for(uint8_t i=5; i < m_frame_data_len; i++)
+		{
+			if(m_frame_data[i]<58 && m_frame_data[i]>47)
+			{
+				g_com_map[ALARM_DISTANCE1] = g_com_map[ALARM_DISTANCE1]*10 + m_frame_data[i]- '0';
+			}
+			else
+			{
+				printf("Error: Wrong DISTANCE.\r\n");
+				break;
+			}
+		}
+		printf("When distance1 < %d cm, alarm1 is on.\n", g_com_map[ALARM_DISTANCE1]);
+		save_com_map_to_flash();
+	}
+	else if(!memcmp(m_frame_data, "DIS2", 4))
+	{
+		g_com_map[ALARM_DISTANCE2] =0;
+		for(uint8_t i=5; i < m_frame_data_len; i++)
+		{
+			if(m_frame_data[i]<58 && m_frame_data[i]>47)
+			{
+				g_com_map[ALARM_DISTANCE2] = g_com_map[ALARM_DISTANCE2]*10 + m_frame_data[i]- '0';
+			}
+			else
+			{
+				printf("Error: Wrong DISTANCE.\r\n");
+				break;
+			}
+		}
+		printf("When distance2 < %d cm, alarm2 is on.\n", g_com_map[ALARM_DISTANCE2]);
+		save_com_map_to_flash();
+	}
+	else if(!memcmp(m_frame_data, "DIS3", 4))
+	{
+		g_com_map[ALARM_DISTANCE3] =0;
+		for(uint8_t i=5; i < m_frame_data_len; i++)
+		{
+			if(m_frame_data[i]<58 && m_frame_data[i]>47)
+			{
+				g_com_map[ALARM_DISTANCE3] = g_com_map[ALARM_DISTANCE3]*10 + m_frame_data[i]- '0';
+			}
+			else
+			{
+				printf("Error: Wrong DISTANCE.\r\n");
+				break;
+			}
+		}
+		printf("When distance3 < %d cm, alarm3 is on.\n", g_com_map[ALARM_DISTANCE3]);
+		save_com_map_to_flash();
 	}
 	else if(!memcmp(m_frame_data, "DEV", 3))
 	{
-		g_com_map[ALARM_DEV] = m_frame_data[3]-'0';
+		g_com_map[ALARM_DEV] = m_frame_data[4]-'0';
+		printf("Alarm device is %d. \n", g_com_map[ALARM_DEV]);
+		save_com_map_to_flash();
+	}
+	else if(!memcmp(m_frame_data, "ID", 2))
+	{
+	dev_id = 0;
+		for(uint8_t i=3; i < m_frame_data_len; i++)
+		{
+			if(m_frame_data[i]<='9' && m_frame_data[i]>='0')
+			{
+				dev_id = (dev_id<<4)|(m_frame_data[i]- '0');
+			}else if(m_frame_data[i]<='f' && m_frame_data[i]>='a')
+			{
+				dev_id = (dev_id<<4)|(m_frame_data[i]- 'a'+10);
+			}else if(m_frame_data[i]<='F' && m_frame_data[i]>='A')
+			{
+				dev_id = (dev_id<<4)|(m_frame_data[i]- 'A'+10);
+			}
+			else
+			{
+				printf("Error: Wrong ID.\r\n");
+				break;
+			}
+		}
+		g_com_map[DEV_ID_L] = dev_id;
+		g_com_map[DEV_ID_H] = dev_id>>16;
+		Dw1000_App_Init();
+		printf("set dev id = %x. \r\n", dev_id);
+		save_com_map_to_flash();
+	}else if(!memcmp(m_frame_data, "INT", 3))
+	{
+		g_com_map[COM_INTERVAL] = 0;
+		for(uint8_t i=4; i < m_frame_data_len; i++)
+		{
+			if(m_frame_data[i]<58 && m_frame_data[i]>47)
+			{
+				g_com_map[COM_INTERVAL] = g_com_map[COM_INTERVAL]*10 + m_frame_data[i]- '0';
+			}
+			else
+			{
+				printf("Error: Wrong COM_INTERVAL.\r\n");
+				break;
+			}
+		}
+		printf("set dev interval = %d ms. \r\n", g_com_map[COM_INTERVAL]);
+		RTC_Configuration(g_com_map[COM_INTERVAL]*20);
+		save_com_map_to_flash();
+	}else if(!memcmp(m_frame_data, "PAIRID", 6))
+	{
+		g_com_map[PAIR_ID] = 0;
+		for(uint8_t i=7; i < m_frame_data_len; i++)
+		{
+			if(m_frame_data[i]<58 && m_frame_data[i]>47)
+			{
+				g_com_map[PAIR_ID] = g_com_map[PAIR_ID]*10 + m_frame_data[i]- '0';
+			}
+			else
+			{
+				printf("Error: Wrong PAIR_ID.\r\n");
+				break;
+			}
+		}
+		printf("set dev PAIR_ID = %d . \r\n", g_com_map[PAIR_ID]);
+		save_com_map_to_flash();
+	}else if(!memcmp(m_frame_data, "STARTPAIR", 9))
+	{
+		g_pairstart=1;
+		printf("Start Pair Mode. \r\n");
+	}else{
+		printf("Error: Wrong Command.\r\n");
 	}
 }
 

--
Gitblit v1.9.3