diff --git a/SerialCommand.cpp b/SerialCommand.cpp index fa9043d..6add976 100644 --- a/SerialCommand.cpp +++ b/SerialCommand.cpp @@ -80,6 +80,14 @@ char *SerialCommand::next() return nextToken; } +// Retrieve the actual token ("word" or "argument") from the Command buffer. +char *SerialCommand::dies() +{ + char *token; + token = strtok_r(buffer,delim,&last); // Search for command at start of buffer + return token; +} + // This checks the Serial stream for characters, and assembles them into a buffer. // When the terminator character (default '\r') is seen, it starts parsing the // buffer for a prefix command, and calls handlers setup by addCommand() member @@ -183,4 +191,4 @@ void SerialCommand::addCommand(const char *command, void (*function)()) void SerialCommand::addDefaultHandler(void (*function)()) { defaultHandler = function; -} \ No newline at end of file +} diff --git a/SerialCommand.h b/SerialCommand.h index bcfdc9f..39f3e88 100644 --- a/SerialCommand.h +++ b/SerialCommand.h @@ -80,6 +80,7 @@ class SerialCommand void clearBuffer(); // Sets the command buffer to all '\0' (nulls) char *next(); // returns pointer to next token found in command buffer (for getting arguments to commands) + char *dies(); // returns pointer to actual token found in command buffer (for getting arguments to commands) void readSerial(); // Main entry point. void addCommand(const char *, void(*)()); // Add commands to processing dictionary void addDefaultHandler(void (*function)()); // A handler to call when no valid command received. @@ -105,4 +106,4 @@ class SerialCommand #endif }; -#endif //SerialCommand_h \ No newline at end of file +#endif //SerialCommand_h