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