CLI example for NNN50

Dependencies:   NNN50_WIFI_API

Fork of NNN50_WiFi_HelloWorld by Delta

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers command-interpreter.h Source File

command-interpreter.h

Go to the documentation of this file.
00001 /** @file command-interpreter.h
00002 * @brief Processes commands coming from the serial port.
00003 * See @ref commands for documentation.
00004 *
00005 * Copyright 2014 by DELTA Corporation.  All rights reserved.
00006 */
00007 
00008 #ifndef COMMAND_INTERPRETER_H
00009 #define COMMAND_INTERPRETER_H
00010 
00011 #include <stdbool.h>
00012 #include <stdint.h>
00013 #include "mbed.h"
00014 //#inlcude "nordic/boards.h"
00015 
00016 //#define DELTA_BLE_ON 1
00017 #define DELTA_WIFI_ON 1
00018 
00019 #ifndef CYNTEC_COMMAND_BUFFER_LENGTH
00020 #define CYNTEC_COMMAND_BUFFER_LENGTH 255
00021 #endif
00022 
00023 #ifndef MAX_TOKEN_COUNT
00024 #define MAX_TOKEN_COUNT 16
00025 #endif
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif 
00030 
00031 enum {
00032   CYNTEC_CMD_SUCCESS,                 
00033   CYNTEC_CMD_ERR_NO_SUCH_COMMAND,
00034     CYNTEC_CMD_ERR_WRONG_NUMBER_OF_ARGUMENTS,
00035   CYNTEC_CMD_ERR_ARGUMENT_OUT_OF_RANGE,        
00036   CYNTEC_CMD_ERR_ARGUMENT_SYNTAX_ERROR, 
00037   CYNTEC_CMD_ERR_NO_MATCHED_ARGUMENT,
00038     CYNTEC_CMD_ERR_WRONG_CMD_ORDER,
00039     CYNTEC_CMD_ERR_INVALID_STATE_TO_PERFORM_OPERATION,
00040   CYNTEC_CMD_ERR_CALL_FAIL
00041 };
00042 
00043 typedef void (*CommandAction)(void);
00044 
00045 typedef const struct {
00046   /** Use letters, digits, and underscores, '_', for the command name.
00047    * Command names are case-sensitive.
00048    */
00049   const char *name;
00050   /** A reference to a function in the application that implements the 
00051    *  command.
00052    *  If this entry refers to a nested command, then action field
00053    *  has to be set to NULL.
00054    */
00055   CommandAction action;
00056     /*
00057    *  In case of a nested command (action is NULL), then this field
00058    *  contains a pointer to the nested CyntecCommandEntry array.
00059      */
00060     const char *subMenu;
00061   /** A description of the command.
00062    */
00063   const char *description;
00064 } CyntecCommandEntry;
00065 
00066 extern CyntecCommandEntry cyntecCommandTable[];
00067 
00068 uint8_t cyntecAtoi(uint8_t *str, uint8_t len);
00069 int cyntecAtoInt(uint8_t *str);
00070 uint8_t cyntecArgToUint8(uint8_t *str, uint8_t len);
00071 uint16_t cyntecAtoiUint16(uint8_t *str, uint8_t len);
00072 uint16_t cyntecArgToUint16(uint8_t *str, uint8_t len);
00073 uint32_t cyntecHexToUint32(uint8_t *str, uint8_t len);
00074 uint8_t cyntecStrCmp(uint8_t *src, uint8_t *dst, uint8_t len);
00075 
00076 /**
00077  * @brief Process the given char as a command.
00078  **/
00079 void cyntecProcessCommandInput(uint8_t input);
00080 
00081 /** @brief Initialize the command interpreter.
00082  */
00083 void cyntecCommandReaderInit(void);
00084 
00085 /** Retrieves unsigned integer arguments. */
00086 uint8_t *cyntecGetCommandArgument(uint8_t argNum, uint8_t *length);
00087 uint8_t *cyntecGetMinusArgument(uint8_t argNum, uint8_t *length);
00088 extern void clearBuffer(void);
00089 
00090 /** Retrieves the token count. */
00091 uint8_t cyntecGetCommandTokenCnt(void);
00092 
00093 //gill add for accept blank in name 20150904
00094 //uint8_t *cyntecGetCommandBuffer(void);
00095 uint8_t *cyntecGetCommandTotalBuffer(void);
00096 void cyntecWriteToTotalBuffer(uint8_t input);
00097 uint8_t cyntecGetTotalIndex(void);
00098 
00099 #ifdef __cplusplus
00100 }
00101 #endif
00102 #endif
00103 
00104