From 0b4231514c82930d7800628f5598e0426e5a000c Mon Sep 17 00:00:00 2001 From: oenne Date: Fri, 6 Feb 2015 21:49:24 +0100 Subject: [PATCH 1/2] Added possibility to return actual token --- SerialCommand.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 +} From cfa1525c5f2797ed3189286607c9f25b3b4a8459 Mon Sep 17 00:00:00 2001 From: oenne Date: Fri, 6 Feb 2015 21:52:35 +0100 Subject: [PATCH 2/2] Update SerialCommand.h --- SerialCommand.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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