Commit 8b8e62f6 authored by Eric Duminil's avatar Eric Duminil
Browse files

Slowly getting there

parent c6e6f831
......@@ -27,15 +27,44 @@ namespace sensor_commands {
}
bool startsWith(const char *a, const char *b) {
if (strncmp(a, b, strlen(b)) == 0)
return 1;
return !strncmp(a, b, strlen(b));
}
bool parseCommand(const char *c, char *fname, long *param) {
return 0;
}
void run(const char *command) {
Serial.print(F("Received command : '"));
void run(const char *c) {
char command[30];
char *function_name;
long parameter;
parseCommand(c, function_name, &parameter);
strlcpy(command, c, 30);
Serial.print(F("Received : '"));
Serial.print(command);
Serial.println("'");
char *arg;
function_name = strtok(command, " ");
if (!function_name) {
// Empty string
return;
}
arg = strtok(NULL, " ");
if (arg) {
char *end;
parameter = strtol(arg, &end, 10);
if (*end) {
// Second argument isn't a number
parameter = -9999;
}
} else {
parameter = -9999;
}
Serial.print("Command : '");
Serial.print(function_name);
Serial.print("'. Parameter : ");
Serial.println(parameter);
// Test all the callbacks.
for (uint8_t i = 0; i < callbacks_count; i++) {
if (startsWith(command, callbacks[i].name)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment