/*! ***************************************************************************** @file: UARTCmd.c @author: $Author: nxu2 $ @brief: UART Command process @version: $Revision: 766 $ @date: $Date: 2017-08-21 14:09:35 +0100 (Mon, 21 Aug 2017) $ ----------------------------------------------------------------------------- Copyright (c) 2017-2019 Analog Devices, Inc. All Rights Reserved. This software is proprietary to Analog Devices, Inc. and its licensors. By using this software you agree to the terms of the associated Analog Devices Software License Agreement. *****************************************************************************/ #include "stdint.h" #include "string.h" #include "stdio.h" #include #define LINEBUFF_SIZE 128 #define CMDTABLE_SIZE 8 uint32_t help(uint32_t para1, uint32_t para2); uint32_t say_hello(uint32_t para1, uint32_t para2); uint32_t rst_eda_base(uint32_t para1, uint32_t para2); uint32_t set_eda_base(uint32_t para1, uint32_t para2); uint32_t get_average_imp(uint32_t para1, uint32_t para2); uint32_t eda_start(uint32_t para1, uint32_t para2); uint32_t eda_stop(uint32_t para1, uint32_t para2); struct __uartcmd_table { void *pObj; const char *cmd_name; const char *pDesc; }uart_cmd_table[CMDTABLE_SIZE]= { {(void*)help, "help", "print supported commands"}, {(void*)help, "?", "print supported commands"}, {(void*)say_hello, "hello", "print parameteres and say hello"}, {(void*)eda_start, "edastart", "Start EDA measurement"}, {(void*)eda_stop, "edastop", "Stop EDA measurement immediately"}, {(void*)rst_eda_base, "rstbase", "Reset EDA baseline impedance"}, {(void*)set_eda_base, "setbase", "Set EDA impedance baseline with current averaged impedance result"}, {(void*)get_average_imp, "getavr", "get average impedance of all result"}, }; uint32_t help(uint32_t para1, uint32_t para2) { int i = 0; printf("*****help menu*****\nbelow are supported commands:\n"); for(;i= LINEBUFF_SIZE-1) line_buffer_index = 0; /* Error: buffer overflow */ if( (c == '\r') || (c == '\n')) { uint32_t res; line_buffer[line_buffer_index] = '\0'; /* Start to process command */ if(line_buffer_index == 0) { line_buffer_index = 0; /* Reset buffer */ return; /* No command inputs, return */ } /* Step1, remove space */ UARTCmd_RemoveSpaces(); if(token_count == 0) { line_buffer_index = 0; /* Reset buffer */ return; /* No valid input */ } /* Step2, match commands */ UARTCmd_MatchCommand(); if(pObjFound == 0) { line_buffer_index = 0; /* Reset buffer */ return; /* Command not support */ } if(token_count > 1) /* There is parameters */ { UARTCmd_TranslateParas(); } /* Step3, call function */ res = ((uint32_t (*)(uint32_t, uint32_t))(pObjFound))(parameter1, parameter2); printf("res:0x%08x\n", res); line_buffer_index = 0; /* Reset buffer */ } else { line_buffer[line_buffer_index++] = c; } }