E:/Ablage_Gerhard/10_Hobby/Elektronik/30_Atmel/20_Prog/AVR_CMD_INTERFACE/cmd_interface.c File Reference

Simple implementation of an command-interface. More...

#include "cmd_interface.h"

Functions

int8_t execute_command ()
 internal function which executes the commands
int8_t split_command_line ()
 internal function which splits the act. command line into separated components, which are separated by split signs.
void cmd_interface_init ()
 initialisation routine for command interface variables
uint8_t cmd_interface_add_cmd (char(*cmd_string), uint8_t(*cmd_func_ptr)(int8_t argc, char *argval[]))
 adding a command to internal command - table
int8_t execute_cmd_interface (char *string)
 routine called to execute command interface

Variables

char c_ptr_cmd_line [_CMD_INTERFACE_MAX_LENGTH+1]
cmd_interface_command_table_t cmd_interface_table [_CMD_INTERFACE_NO_OF_COMMANDS]

Detailed Description

Simple implementation of an command-interface.

Target/Compiler: AVR_MEGA / GCC(WinAVR)

Author:
Gerhard Bruenner
Version:
V2.03
Date:
2009.12.29 - GB created new function split_command_line() - now using own version of strtok. This reduced the operating-time of this function to the half of the previous version. Although changed the function-parameter interface of the user-function to uint8_t cmd_func (int8_t argc, char *argval[])
2009.11.15 - added function cmd_interface_add_cmd and Backspace-Function - GB
2009.10.31 - changed the way how commandline is interpret - GB
2009.10.21 - small updates - GB
2009.02.01 - Created - GB
Bug:
none that I am aware so far

\


Function Documentation

uint8_t cmd_interface_add_cmd ( char *  cmd_string,
uint8_t(*)(int8_t argc, char *argval[])  cmd_func_ptr 
)

adding a command to internal command - table

Parameters:
char *cmd_string - String representing the command
uint8_t (*cmd_func_ptr) - pointer to function which shall be executed if the command has been found
Returns:
0 - all fine -1 - command-table is full

This function shall add a given string and function-pointer to the internal command-table. The string in the command-table is used by the internal functions to determine whether a command is known or not. The function where the function-pointer is pointing to is called in the case the entered command matches to the given string. The function MUST have the following interface-declaration.... uint8_t cmd_func (int8_t argc, char *argval[])

void cmd_interface_init (  ) 

initialisation routine for command interface variables

Parameters:
none 
Returns:
void
int8_t execute_cmd_interface ( char *  string  ) 

routine called to execute command interface

Parameters:
*string - to attach at the actual command_line buffer
Returns:
The content of the return-value have been split into two parts
The three lowest bits are used as counter for executed commands
The remaining "upper" bits represent bit-coded errors,
due to the possibilitiy of multiple errors per call.
<0 - error occured
#1001 0XXX - #84 - not used
#1001 0XXX - #90 - too many operands in the command-line
#1010 0XXX - A0 - no valid command found
#1100 0XXX - B0 - too many signs in comand-line
0 - no end of command-line detects
0> - number of commands which have been executed

This routine has to be called to execute the command-interface It attaches the forwarded string to the internal command-line buffer and its sub-functions interprets the line before it executes the corresponding command-function given by the user

int8_t execute_command (  ) 

internal function which executes the commands

Parameters:
none 
Returns:
<0 - error
-1 - too many operands in the command-line (ret_val of split_command_line)
0 - no valid command
1 - a command hast been successfully executed.

this functions checks whether the given command exists in the command-table if it exists it executes the function referenced in the function-pointer which belongs the specific command.

int8_t split_command_line (  ) 

internal function which splits the act. command line into separated components, which are separated by split signs.

Parameters:
none 
Returns:
<0 - error
-1 - too many operands in the command-line
>0 - number of strings/operands which have been found, means separated by split-signs.

Variable Documentation

cmd_interface_command_table_t cmd_interface_table[_CMD_INTERFACE_NO_OF_COMMANDS]

internal table used to store the differen combinations of commands and functions


Generated on Fri Jan 1 18:18:57 2010 for AVR_CMD_INTERFACE by  doxygen 1.6.1