The CommandProcessor is the interface to install a run-time menu into an embedded system.

Dependents:   A_CANAdapter USB2I2C

Embed: (wiki syntax)

« Back to documentation index

CMDP_T Struct Reference

CMDP_T Struct Reference

This is the CommandProcessor interface from the user application. More...

#include <CommandProcessor.h>

Data Fields

INITRESULT_T(* Init )(CMD_T *SignOnBanner, CONFIG_T config, int maxCmdLen, int historyLen, int(*kbhit)(void), int(*getch)(void), int(*putch)(int ch), int(*puts)(const char *s))
 Init is the first function to call to configure the CommandProcessor.
ADDRESULT_T(* Add )(CMD_T *m)
 Add is called to add an item to the CommandProcessor menu.
RUNRESULT_T(* Run )(void)
 Run is the primary runtime entry point for the CommandProcessor.
RUNRESULT_T(* Echo )(int echo)
 Echo command permits turning the echo on and off.
RUNRESULT_T(* End )(void)
 End if the function to be called when you want to gracefully end the CommandProcessor.

Detailed Description

This is the CommandProcessor interface from the user application.

The user aquires a handle to this set of functions with the GetCommandProcessor command. After this, the user may then initialize the CommandProcessor, add items to the menu, cause the CommandProcessor to run periodically, and if need be the application can end the CommandProcessor.

Definition at line 221 of file CommandProcessor.h.


Field Documentation

Add is called to add an item to the CommandProcessor menu.

This passes in a reference to a user provided CMD_T item, which is added to the menu system.

Parameters:
mis a pointer to the user provided menu
Returns:
ADDRESULT_T to indicate if the add was successful or failed

Definition at line 263 of file CommandProcessor.h.

RUNRESULT_T(* Echo)(int echo)

Echo command permits turning the echo on and off.

When interactive with the user, it is best to have echo on, so they can see the prompt, but if this is simply slaved to another program, then the echo might need to be off to best manage the stream.

Parameters:
echoturns the echo on (non-zero) or off (zero)
Returns:
RUNRESULT_T to indicate if the CommandProcessor should remain active or if the command that was executed is requesting the CommandProcessor to exit.

Definition at line 289 of file CommandProcessor.h.

RUNRESULT_T(* End)(void)

End if the function to be called when you want to gracefully end the CommandProcessor.

Calling this function causes the CommandProcessor to free any memory that was previously allocated by the Init and Add functions. Called to shutdown the processor

Definition at line 295 of file CommandProcessor.h.

INITRESULT_T(* Init)(CMD_T *SignOnBanner, CONFIG_T config, int maxCmdLen, int historyLen, int(*kbhit)(void), int(*getch)(void), int(*putch)(int ch), int(*puts)(const char *s))

Init is the first function to call to configure the CommandProcessor.

This function has a number of parameters, which make the CommandProcessor quite flexible.

Parameters:
SignOnBannerfunction, which is used as a signon banner
configenables various default menu items, based on the bit values, combine the following:

  • CFG_ENABLE_TERMINATE - enables the Exit command
  • CFG_ENABLE_SYSTEM - enables system commands Echo, Help, etc.
  • CFG_ECHO_ON - initialize with echo on
  • CFG_CASE_INSENSITIVE - Command Parser is case insensitive
maxCmdLensizes the buffer, and is the maximum number of characters in a single command, including all command arguments
historyLensets the number of items that can be recalled from history
kbhitis a user provided function to detect if a character is available for the CommandProcessor, and when using standard io, you can typically use kbhit, or _kbhit as your system provides.
getchis a user provided function that provides a single character to the CommandProcessor
putchis a user provided function that permits the CommandProcessor to output a character
putsis a user provided function that permits the CommandProcessor to output a string to which is automatically appended a \n
Returns:
INITRESULT_T to indicate if the init was successful or failed

Definition at line 244 of file CommandProcessor.h.

RUNRESULT_T(* Run)(void)

Run is the primary runtime entry point for the CommandProcessor.

This function should be called periodically - fast enough not to miss user input. This function always returns, so if not character is available for the CommandProcessor it will return very fast. If there is a character (as detected by the kbhit callback), then it will process that character and determine what to do. It may then execute one of the menu functions. In this case, CPU cycles spent are based on the function being executed.

Returns:
RUNRESULT_T to indicate if the CommandProcessor should remain active or if the command that was executed is requesting the CommandProcessor to exit.

Definition at line 277 of file CommandProcessor.h.