2 bit Bridge Driver

Committer:
jm
Date:
Sat Feb 19 01:30:54 2011 +0000
Revision:
0:bfa30f27fe9d
jmBridge Module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jm 0:bfa30f27fe9d 1 /*************************************************************************
jm 0:bfa30f27fe9d 2 * @file jmInterpreter.c
jm 0:bfa30f27fe9d 3 * @brief Command Line Interpreter
jm 0:bfa30f27fe9d 4 *
jm 0:bfa30f27fe9d 5 * @date December 27,2010
jm 0:bfa30f27fe9d 6 */
jm 0:bfa30f27fe9d 7
jm 0:bfa30f27fe9d 8 #include "jmInterpreter.h"
jm 0:bfa30f27fe9d 9 #include "jmRingBuffer.h"
jm 0:bfa30f27fe9d 10 #include "jmCommands.h"
jm 0:bfa30f27fe9d 11
jm 0:bfa30f27fe9d 12 /** @brief Interpret a command line.
jm 0:bfa30f27fe9d 13 * Interpreter uses Command Line Buffer to fecth command name
jm 0:bfa30f27fe9d 14 * and redirects execution to associated function.
jm 0:bfa30f27fe9d 15 * @param none
jm 0:bfa30f27fe9d 16 * @returns none
jm 0:bfa30f27fe9d 17 */
jm 0:bfa30f27fe9d 18 void Interpret(void){
jm 0:bfa30f27fe9d 19 unsigned int i,k;
jm 0:bfa30f27fe9d 20 unsigned char Command, found;
jm 0:bfa30f27fe9d 21 char Word[WordMaxSize];
jm 0:bfa30f27fe9d 22 Command =0;
jm 0:bfa30f27fe9d 23 found = 0;
jm 0:bfa30f27fe9d 24
jm 0:bfa30f27fe9d 25 if(NotEmpty(pLine)){
jm 0:bfa30f27fe9d 26 ExtractWord(pLine,Word); // Command name extraction
jm 0:bfa30f27fe9d 27 for(i=0, k=0;i<sizeof(cmdNames);i++){ // lookup in names array
jm 0:bfa30f27fe9d 28 if(cmdNames[i]!=Word[k]){ // if different
jm 0:bfa30f27fe9d 29 while(cmdNames[i]!=0)i++; // next entry in names array
jm 0:bfa30f27fe9d 30 Command++; // update command index
jm 0:bfa30f27fe9d 31 k=0;
jm 0:bfa30f27fe9d 32 }
jm 0:bfa30f27fe9d 33 else{
jm 0:bfa30f27fe9d 34 if(Word[k]==0){
jm 0:bfa30f27fe9d 35 found=1;
jm 0:bfa30f27fe9d 36 }
jm 0:bfa30f27fe9d 37 else k++;
jm 0:bfa30f27fe9d 38 } //else
jm 0:bfa30f27fe9d 39
jm 0:bfa30f27fe9d 40 if(found)break;
jm 0:bfa30f27fe9d 41 } //for
jm 0:bfa30f27fe9d 42 }
jm 0:bfa30f27fe9d 43
jm 0:bfa30f27fe9d 44 // Command execution
jm 0:bfa30f27fe9d 45 Action(Command);
jm 0:bfa30f27fe9d 46 }