Jean Mercier
/
jmMotor
Control up to 4 DC Motors from a serial port
jmInterpreter.c@0:dedab08b24ea, 2011-02-12 (annotated)
- Committer:
- jm
- Date:
- Sat Feb 12 16:39:20 2011 +0000
- Revision:
- 0:dedab08b24ea
jmMotor Command Line Interface Module
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jm | 0:dedab08b24ea | 1 | /************************************************************************* |
jm | 0:dedab08b24ea | 2 | * @file jmInterpreter.c |
jm | 0:dedab08b24ea | 3 | * @brief Command Line Interpreter |
jm | 0:dedab08b24ea | 4 | * |
jm | 0:dedab08b24ea | 5 | * @date December 27,2010 |
jm | 0:dedab08b24ea | 6 | */ |
jm | 0:dedab08b24ea | 7 | |
jm | 0:dedab08b24ea | 8 | #include "jmInterpreter.h" |
jm | 0:dedab08b24ea | 9 | #include "jmRingBuffer.h" |
jm | 0:dedab08b24ea | 10 | #include "jmCommands.h" |
jm | 0:dedab08b24ea | 11 | |
jm | 0:dedab08b24ea | 12 | /** @brief Interpret a command line. |
jm | 0:dedab08b24ea | 13 | * Interpreter uses Command Line Buffer to fecth command name |
jm | 0:dedab08b24ea | 14 | * and redirects execution to associated function. |
jm | 0:dedab08b24ea | 15 | * @param none |
jm | 0:dedab08b24ea | 16 | * @returns none |
jm | 0:dedab08b24ea | 17 | */ |
jm | 0:dedab08b24ea | 18 | void Interpret(void){ |
jm | 0:dedab08b24ea | 19 | unsigned int i,k; |
jm | 0:dedab08b24ea | 20 | unsigned char Command, found; |
jm | 0:dedab08b24ea | 21 | char Word[WordMaxSize]; |
jm | 0:dedab08b24ea | 22 | Command =0; |
jm | 0:dedab08b24ea | 23 | found = 0; |
jm | 0:dedab08b24ea | 24 | |
jm | 0:dedab08b24ea | 25 | if(NotEmpty(pLine)){ |
jm | 0:dedab08b24ea | 26 | ExtractWord(pLine,Word); // Command name extraction |
jm | 0:dedab08b24ea | 27 | for(i=0, k=0;i<sizeof(cmdNames);i++){ // lookup in names array |
jm | 0:dedab08b24ea | 28 | if(cmdNames[i]!=Word[k]){ // if different |
jm | 0:dedab08b24ea | 29 | while(cmdNames[i]!=0)i++; // next entry in names array |
jm | 0:dedab08b24ea | 30 | Command++; // update command index |
jm | 0:dedab08b24ea | 31 | k=0; |
jm | 0:dedab08b24ea | 32 | } |
jm | 0:dedab08b24ea | 33 | else{ |
jm | 0:dedab08b24ea | 34 | if(Word[k]==0){ |
jm | 0:dedab08b24ea | 35 | found=1; |
jm | 0:dedab08b24ea | 36 | } |
jm | 0:dedab08b24ea | 37 | else k++; |
jm | 0:dedab08b24ea | 38 | } //else |
jm | 0:dedab08b24ea | 39 | |
jm | 0:dedab08b24ea | 40 | if(found)break; |
jm | 0:dedab08b24ea | 41 | } //for |
jm | 0:dedab08b24ea | 42 | } |
jm | 0:dedab08b24ea | 43 | |
jm | 0:dedab08b24ea | 44 | // Command execution |
jm | 0:dedab08b24ea | 45 | Action(Command); |
jm | 0:dedab08b24ea | 46 | } |