From bf685e699dac374e7536cb81ed7ca972d01e5861 Mon Sep 17 00:00:00 2001 From: guanjiao <sqrgj@163.com> Date: 星期六, 15 九月 2018 18:16:51 +0800 Subject: [PATCH] AT指令发送写ID指令 --- 源码/核心板/Src/application/global_param.c | 12 ++++++++++-- 源码/核心板/Src/application/serial_at_cmd_app.c | 23 +++++++++++++++++++++++ 源码/核心板/Src/application/global_param.h | 1 + 源码/核心板/Src/OnChipDevices/Usart.c | 9 +++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Usart.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Usart.c" index 6ed2bf7..7ed8dde 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Usart.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/OnChipDevices/Usart.c" @@ -1,5 +1,6 @@ #include "Usart.h" #include <string.h> +#include <stdio.h> //数据发送队列变量 EUART_Frame m_EUART_TxFrames[EUART_TX_FRM_SIZE]; //数据发送帧队列 @@ -288,3 +289,11 @@ m_EUART_TxFrm_FreeFrmLen++; } +int fputc(int ch, FILE *f) +{ + + USART_SendData(USART1, (unsigned char) ch);// USART1 ???? USART2 ? + while (!(USART1->SR & USART_FLAG_TXE)); + return (ch); +} + diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" index 609adcd..6c64f8f 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.c" @@ -1,6 +1,7 @@ #include "global_param.h" #include "Flash.h" #include "dw_app.h" +#include <string.h> uint16_t g_com_map[COM_MAP_SIZE]; @@ -21,8 +22,15 @@ { FLASH_Read(FLASH_IAP_CTRL_MAP, (uint8_t*)&g_com_map, (COM_MAP_SIZE<<1)); - g_com_map[ALARM_DISTANCE] = 200; //默认报警距离200cm - g_com_map[ALARM_DEV] = 0; + if(g_com_map[0] != 0x55AA) + { + g_com_map[0] = 0x55AA; + g_com_map[ALARM_DISTANCE] = 200; //默认报警距离200cm + g_com_map[ALARM_DEV] = 0; + g_com_map[DEV_ID] = DEFAULT_DEV_ID; //默认设备ID + save_com_map_to_flash(); + } + dis_after_filter = 1000; //默认距离 p_Dis_Filter = New_LP_Frac(0.7); diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h" index ca85222..5f39377 100644 --- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h" +++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/global_param.h" @@ -5,6 +5,7 @@ #define COM_MAP_SIZE 1024 //MAP表的最大空间 #define DEFAULT_DISTANCE 1000 //初始测距距离为10米 +#define DEFAULT_DEV_ID 5555 //默认设备ID是5555 /*---------------Map Definition-------------------*/ #define DEV_ROLE 0x10 //该设备是anchor还是tag 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..e9f99cf 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,6 +1,7 @@ #include "serial_at_cmd_app.h" #include "global_param.h" #include <string.h> +#include <stdio.h> uint8_t m_frame_data[MAX_FRAME_LEN] = {0}; uint8_t m_frame_data_len = 0; @@ -10,10 +11,32 @@ if(!memcmp(m_frame_data, "SET", 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'); + printf("When distance < %d cm, alarm is on.\n", g_com_map[ALARM_DISTANCE]); + save_com_map_to_flash(); } else if(!memcmp(m_frame_data, "DEV", 3)) { g_com_map[ALARM_DEV] = m_frame_data[3]-'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)) + { + g_com_map[DEV_ID] = 0; + for(uint8_t i=2; i < m_frame_data_len; i++) + { + if(m_frame_data[i]<58 && m_frame_data[i]>47) + { + g_com_map[DEV_ID] = g_com_map[DEV_ID]*10 + m_frame_data[i]- '0'; + } + else + { + printf("Error: Wrong ID.\r\n"); + break; + } + } + printf("set dev id = %d. \r\n", g_com_map[DEV_ID]); + save_com_map_to_flash(); } } -- Gitblit v1.9.3