parser.h File Reference

serial protocol parser and commands. More...

#include <cpu/types.h>

Go to the source code of this file.


Data Structures

union  parms
 union that contains parameters passed to and from commands More...
struct  CmdTemplate
 Define a command that can be tokenized by the parser. More...

Defines

#define PARSER_MAX_ARGS   8
 Max number of arguments and results for each command.

Typedefs

typedef ResultCode(* CmdFuncPtr )(parms args_results[])
 pointer to commands

Enumerations

enum  ResultCode { RC_ERROR = -1, RC_OK = 0, RC_REPLY = 1, RC_SKIP = 2 }
 Error generated by the commands through the return code. More...

Functions

void parser_init (void)
 Initialize the parser module.
void parser_register_cmd (const struct CmdTemplate *cmd)
 Register a new command into the parser.
const char * parser_rl_match (void *dummy, const char *word, int word_len)
 Hook for readline to provide completion support for the commands registered in the parser.
bool parser_process_line (const char *line)
 Command input handler.
bool parser_execute_cmd (const struct CmdTemplate *templ, parms args[PARSER_MAX_ARGS])
 Execute a command with its arguments, and fetch its results.
struct CmdTemplateparser_get_cmd_template (const char *line)
 Find the template for the command contained in the text line.
bool parser_get_cmd_arguments (const char *line, const struct CmdTemplate *templ, parms args[PARSER_MAX_ARGS])
 Extract the arguments for the command contained in the text line.
bool parser_get_cmd_id (const char *line, unsigned long *ID)
 Extract the ID from the command text line.

Detailed Description

serial protocol parser and commands.

Version:
Id
parser.h 2506 2009-04-15 08:29:07Z duplo

Author:
Bernie Innocenti <bernie@codewiz.org>

Stefano Fedrigo <aleph@develer.com>

Giovanni Bajo <rasky@develer.com>

Definition in file parser.h.


Enumeration Type Documentation

enum ResultCode

Error generated by the commands through the return code.

Enumerator:
RC_ERROR  Reply with error.
RC_OK  No reply (ignore reply arguments).
RC_REPLY  Reply command arguments.
RC_SKIP  Skip following commands.

Definition at line 54 of file parser.h.


Function Documentation

bool parser_execute_cmd ( const struct CmdTemplate templ,
parms  args[PARSER_MAX_ARGS] 
) [inline]

Execute a command with its arguments, and fetch its results.

Parameters:
templ Template of the command to be executed
args Arguments for the command, and will contain the results
Returns:
False if the command returned an error, true otherwise

Definition at line 137 of file parser.h.

bool parser_get_cmd_arguments ( const char *  line,
const struct CmdTemplate templ,
parms  args[PARSER_MAX_ARGS] 
)

Extract the arguments for the command contained in the text line.

Parameters:
line Text line to be processed (ASCIIZ)
templ Command template for this line
args Will contain the extracted parameters
Returns:
True if everything OK, false in case of parsing error.

Definition at line 317 of file parser.c.

bool parser_get_cmd_id ( const char *  line,
unsigned long *  ID 
)

Extract the ID from the command text line.

Parameters:
line Text line to be processed (ASCIIZ)
ID Will contain the ID extracted.
Returns:
True if everything ok, false if there is no ID

Definition at line 270 of file parser.c.

struct CmdTemplate* parser_get_cmd_template ( const char *  line  )  [read]

Find the template for the command contained in the text line.

The template can be used to tokenize the command and interpret it.

This function can be used to find out which command is contained in a given text line without parsing all the parameters and executing it.

Parameters:
line Text line to be processed (ASCIIZ)
Returns:
The command template associated with the command contained in the line, or NULL if the command is invalid.

Definition at line 286 of file parser.c.

void parser_init ( void   ) 

Initialize the parser module.

Note:
This function must be called before any other function in this module

Definition at line 389 of file parser.c.

bool parser_process_line ( const char *  line  ) 

Command input handler.

Process the input, calling the requested command (if found) and calling printResult() to give out the result (on device specified with parameter fd).

Parameters:
line Text line to be processed (ASCIIZ)
Returns:
true if everything is OK, false in case of errors

Definition at line 337 of file parser.c.

void parser_register_cmd ( const struct CmdTemplate cmd  ) 

Register a new command into the parser.

Parameters:
cmd Command template describing the command

Definition at line 355 of file parser.c.

const char* parser_rl_match ( void *  dummy,
const char *  word,
int  word_len 
)

Hook for readline to provide completion support for the commands registered in the parser.

Note:
This is meant to be used with mware/readline.c. See the documentation there for a description of this hook.