I like the simplicity of how this code works and it is really reliable, the problem is i dont understand enough about the code itself inorder to modify how it works...
in short the code manages serial commands, in the format cmd:val i would like to know how to modify it to work with cmd:val:val:val:msg
i tried over a month ago a few times to get a hold of the original author but to no avail. like i say the code is really reliable for what i need it for anyway but it doesnt pass enough information.
// Arduino RBD Serial Manager Library v1.0.0-alpha.3 - A simple interface for serial communication.
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2016 Alex Taujenis
// MIT License
#include <Arduino.h>
#include <RBD_SerialManager.h> // https://github.com/alextaujenis/RBD_SerialManager
namespace RBD {
SerialManager::SerialManager() {}
void SerialManager::start() {
Serial.begin(115200);
}
bool SerialManager::onReceive() {
if(Serial.available()) {
_char = char(Serial.read());
if(_char == _flag) {
_value = _buffer;
_buffer = "";
return true;
}
else {
_buffer += _char;
return false;
}
}
else {
return false;
}
}
String SerialManager::getValue() {
return _value;
}
void SerialManager::setFlag(char value) {
_flag = value;
}
void SerialManager::setDelimiter(char value) {
_delimiter = value;
}
String SerialManager::getCmd() {
_position = getValue().indexOf(_delimiter);
if(_position > -1) {
return _value.substring(0, _position);
}
else {
return getValue();
}
}
String SerialManager::getParam() {
_position = getValue().indexOf(_delimiter);
if(_position > -1) {
return _value.substring(_position + 1, _value.length());
}
else {
return "";
}
}
bool SerialManager::isCmd(String value) {
return getCmd() == value;
}
bool SerialManager::isParam(String value) {
return getParam() == value;
}
}
// Arduino RBD Serial Manager Library v1.0.0-alpha.3 - A simple interface for serial communication.
// https://github.com/alextaujenis/RBD_SerialManager
// Copyright 2016 Alex Taujenis
// MIT License
#ifndef RBD_SERIAL_MANAGER
#define RBD_SERIAL_MANAGER
#include <Arduino.h>
namespace RBD {
class SerialManager {
public:
SerialManager();
void start();
void setFlag(char value);
void setDelimiter(char value);
bool onReceive();
String getValue();
String getCmd();
String getParam();
bool isCmd(String value);
bool isParam(String value);
template <typename T> void print(T value){Serial.print(value);}
template <typename T> void println(T value){Serial.println(value);}
private:
int _position;
char _char;
char _flag = '\n'; // you must set the serial monitor to include a newline with each command
char _delimiter = ':';
String _buffer = "";
String _value = "";
};
}
#endif
i have code that i cobbled together that does what i need it to do but it is not as consistent or reliable.. ill post below.