Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to return actual token #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion SerialCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,4 +191,4 @@ void SerialCommand::addCommand(const char *command, void (*function)())
void SerialCommand::addDefaultHandler(void (*function)())
{
defaultHandler = function;
}
}
3 changes: 2 additions & 1 deletion SerialCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -105,4 +106,4 @@ class SerialCommand
#endif
};

#endif //SerialCommand_h
#endif //SerialCommand_h