Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of frdm_echo by
Diff: shell.cpp
- Revision:
- 9:f9efd3a69c2d
- Parent:
- 8:b715912d684b
- Child:
- 10:85a8da3b7e5e
diff -r b715912d684b -r f9efd3a69c2d shell.cpp --- a/shell.cpp Mon Apr 14 16:41:57 2014 +0000 +++ b/shell.cpp Mon Apr 14 21:02:10 2014 +0000 @@ -32,34 +32,36 @@ { // check if there is something to read if(usbSerial->readable()) { - + // if so ... char character = usbSerial->getc(); - + // see if this is a semi colon or a carriage return // if so, give a new line cursor if((character == ';') || (character == 13)) { + finishCharacterBuffer(); + parseCommands(); usbSerial->printf("\n> "); - finishCharacterBuffer(); ledColors->flashWhite(10); } - + // if not, just print the character - else { - usbSerial->printf("%c", character); - addCharacterToBuffer(character); + else if(addCharacterToBuffer(character)) { + usbSerial->printf("%c", character); ledColors->flashGreen(10); } } } //----------------------------------------------------------------------------- - -void Shell::addCharacterToBuffer(char newCharacter) + +bool Shell::addCharacterToBuffer(char newCharacter) { - if(characterPointer < ItsInputBufferSize_) { + bool accept = (characterPointer < ItsInputBufferSize_); + if(accept) { inputBuffer[characterPointer++] = newCharacter; characterCount = characterPointer; } + return accept; } //----------------------------------------------------------------------------- @@ -67,4 +69,37 @@ { characterPointer = 0; } -//----------------------------------------------------------------------------- \ No newline at end of file +//----------------------------------------------------------------------------- + +bool Shell::findString(char *thisString, uint32_t stringLength) +{ + bool found = false; + uint32_t startPointer = 0, characterPointer; + char firstChar, secondChar; + + while(!found && (startPointer <= characterCount - stringLength)) { + + found = true; + characterPointer = 0; + while(found && (characterPointer < stringLength)) { + firstChar = inputBuffer[startPointer + characterPointer]; + secondChar = thisString[characterPointer]; + found = (firstChar == secondChar); + + // usbSerial->printf("(compare %c with %c)\n", firstChar, secondChar); + + characterPointer++; + } + startPointer++; + } + + return found; +} +//----------------------------------------------------------------------------- + +void Shell::parseCommands() +{ + if(findString("set", 3)) sendText(" -- \"set\" found!"); +} +//----------------------------------------------------------------------------- +