Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otCommandParser Class Reference
[Command Parser - This library implements a command interpreter.Command Parser - This library implements a command interpreter.]

This library implements a command interpreter. Useful to manage a remote control or for a console function.

#include <otCommandParser.h>


Public Member Functions

 otCommandParser ()
bool init (U32 elements, otFILE *fs=0)
void close ()
S32 add (const char *commandText, const char *commandTextShort, _procCallback commandExe, bool disk=false, U8 minParams=0, U8 maxParams=0, const char *paramsList=0, const char *help=0)
S32 parse (char *cmdLine)
U32 count ()
void usage (int n, bool error=true)
const char * name (U32 i, bool Long=true)
const char * parameters (U32 i)
const char * help (U32 i)
bool parameters (U32 i, U8 &minp, U8 &maxp)
int findCommandIndex (const char *name)
bool isConsole ()
S32 retCode ()
void setEcho (bool ena)
void setRetCode (S32 v)


Constructor & Destructor Documentation

otCommandParser.otCommandParser  ) 
 

Library creation.


Member Function Documentation

S32 otCommandParser.add const char *  commandText,
const char *  commandTextShort,
_procCallback  commandExe,
bool  disk = false,
U8  minParams = 0,
U8  maxParams = 0,
const char *  paramsList = 0,
const char *  help = 0
 

Add a new command to the command parser
The aspected syntax is: COMMAND PAR1 PAR2 ... PARn

Parameters:
commandText Name of the command in the extended version. Tipically CLASS.NAME
commandTextShort Shortcut name
commandExe Callback to the command
disk True if a file sytem is required
minParams Minum number of parameters
maxParams Maximum number of parameters
paramsList Parameters specifier
help Help string
Returns:
Command index
 \\ Example
 cp->add("CORE.WATCHDOG","WD", __wd, false, 1, 2, "ON|OFF;1,30000", "ON|OFF [mS] ; Enable/Disable watch dog. Default is 1s different value can be specified as mS");

void otCommandParser.close  ) 
 

Close the library and free all allocated memories

U32 otCommandParser.count  ) 
 

Read the number of loaded command

Returns:
Number of commands

int otCommandParser.findCommandIndex const char *  name  ) 
 

From a string found the index of a command. All command are stored in UPPERCASE!

Parameters:
name Nome of the command
Returns:
If >= 0 the command index else not found

const char* otCommandParser.help U32  i  ) 
 

Return the help for a specified command

Parameters:
i Command index
Returns:
Realted help

bool otCommandParser.init U32  elements,
otFILE fs = 0
 

Init the library

Parameters:
elements Maximum number of allowed commands
fs File system library class pointer
Returns:
True on success

bool otCommandParser.isConsole  ) 
 

Read if the command parser is set for console mode or not. Console mode accept character correction like BACKSPACE.

Returns:
True if in console mode.

const char* otCommandParser.name U32  i,
bool  Long = true
 

Return the name of a command

Parameters:
i Command index
Long True to return the extended name
Returns:
Command name

bool otCommandParser.parameters U32  i,
U8 minp,
U8 maxp
 

Read the number of parameters for a specified command index

Parameters:
i Command index
minp Return minimum number of parameters
maxp Return maximum number of parameters
Returns:
True on success

const char* otCommandParser.parameters U32  i  ) 
 

Return requested parameters of a specified command

Parameters:
i Command index
Returns:
The parameters list

S32 otCommandParser.parse char *  cmdLine  ) 
 

It interprets the string that is passed to it, if a command is recognized it is executed. The parameters (if necessary) follow the command separated by a SPACE character.

Parameters:
cmdLine Command to be executed
Returns:
0: ok, 1: Batch exists but is empty, 2: Batch don't exists, 3: Unknown command

S32 otCommandParser.retCode  ) 
 

Read the return code of the latest execute command

Returns:
Ret code

void otCommandParser.setEcho bool  ena  ) 
 

Enable or disable string echo in batch execution

Parameters:
ena True to enable console mode

void otCommandParser.setRetCode S32  v  ) 
 

Force ret code to a specified value.

Parameters:
v Value for ret code

void otCommandParser.usage int  n,
bool  error = true
 

Display on standard output the command usage

Parameters:
n Command index
error If true display as an error message


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-23 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0