Auxiliaries I use for CreaBot
Embed:
(wiki syntax)
Show/hide line numbers
CMD_Interpreter.h
00001 00002 #ifndef CMD_Interpreter_H 00003 #define CMD_Interpreter_H 00004 00005 #include "mbed.h" 00006 #include <string> 00007 00008 const int BuffLen = 512; 00009 00010 // define commands to be handled! 00011 typedef void (*caseHandler)(int param); 00012 00013 typedef struct EXE_CMD_TYPE{ 00014 char cmd; // THe single command character 00015 char Npar; // The number of parameters needed by the command, only for help text. All command Hanlders must have a Parameter 00016 caseHandler Handler; // Command Handlers 00017 string help; // Help Text for that command 00018 }EXE_CMD_TYPE; 00019 00020 // Define States of the interpreter 00021 enum InterpretState { isStartNew, isLineFilling, isOverflow, isWaitNewLine}; 00022 00023 typedef struct RD_CMD_TYPE { 00024 char Command; // Holds the next read command character 00025 int Parameter ; // Holds one int Parameter 00026 int NumParam ; // Indicates how many parameters where found 00027 } RD_CMD_TYPE; 00028 00029 // Uses a Ring buffer to buffer incomiing characters 00030 // Uses a parsing function to extract lines containing a command each 00031 class Interpreter{ 00032 public: 00033 // Interpreter Class Creation 00034 Interpreter( void ); 00035 void Reinit( void ); 00036 void FillCommands(int aNumCommands, const EXE_CMD_TYPE *ACommands ); 00037 public: // the writing mechanics 00038 void AddChar ( char aChar ); // Barebone function, assumes that checks havee been performed by writeBuf! 00039 void writeBuf( char c ) ; // High level method to add a Char to the buffer, 00040 char RingBuf[BuffLen]; 00041 InterpretState MyState;// Indicates if buffer overflow, line ended etc. 00042 int WriteIndex ; // points to next index to write to 00043 int BufAvail ; // indicates how much of the buffer is still available 00044 int LinesComplete; // Indicates how many complete lines are available 00045 bool ProcessPresentCommands( void ); 00046 RD_CMD_TYPE ParseCommand( void ); 00047 bool executeCommand(RD_CMD_TYPE cmd); 00048 void PrtCmdHelp ( Serial *aSerial ); // Display list of Commands 00049 // void GetLastMessage( string LastMsg); // not possible to implement at the moment 00050 public: // the reading mechanics 00051 int ScanIndex; // points to next index to read from to 00052 char actC ; // holds the actual character 00053 private: 00054 char GetAChar ( void ); 00055 void SkipBlanks( void ); 00056 int ReadAnInt ( void ); 00057 char actPP ( void ); 00058 EXE_CMD_TYPE* AllCommands; // Defines an array of all commands to be filled by the user. 00059 int NumCommands; // Holds the actual number of commands that are stored in the array 00060 /* 00061 char buff[100]; // Intermediate buffer to hold messages for datalogging 00062 string LastMessage; 00063 void DataLog( char *DebugMessage ); 00064 void CmdInval( int param ); // Feedback that the command is invalid 00065 */ 00066 }; // class Interpreter 00067 00068 #endif // CMD_Interpreter_H
Generated on Mon Jul 18 2022 17:02:22 by
