zhyinch
2018-10-13 be9861e4fc5ac9984218975f3d5594f1db848224
源码/核心板/Src/application/serial_at_cmd_app.c
@@ -2,20 +2,21 @@
#include "global_param.h"
#include <string.h>
#include <stdio.h>
#include "dw_app.h"
uint8_t m_frame_data[MAX_FRAME_LEN] = {0};
uint8_t m_frame_data_len = 0;
void ParseFrame(void)
{
   if(!memcmp(m_frame_data, "DIS", 3))
   if(!memcmp(m_frame_data, "DIS1", 4))
   {
      g_com_map[ALARM_DISTANCE] =0;
      for(uint8_t i=3; i < m_frame_data_len; i++)
      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_DISTANCE] = g_com_map[ALARM_DISTANCE]*10 + m_frame_data[i]- '0';
            g_com_map[ALARM_DISTANCE1] = g_com_map[ALARM_DISTANCE1]*10 + m_frame_data[i]- '0';
         }
         else
         {
@@ -23,19 +24,55 @@
            break;
         }
      }
      printf("When distance < %d cm, alarm is on.\n", g_com_map[ALARM_DISTANCE]);
      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))
   {
      g_com_map[DEV_ID] = 0;
      for(uint8_t i=2; i < m_frame_data_len; i++)
      for(uint8_t i=3; i < m_frame_data_len; i++)
      {
         if(m_frame_data[i]<58 && m_frame_data[i]>47)
         {
@@ -47,6 +84,7 @@
            break;
         }
      }
      Dw1000_App_Init();
      printf("set dev id = %d. \r\n", g_com_map[DEV_ID]);
      save_com_map_to_flash();
   }