Francois Girard / Mbed 2 deprecated CommandParser

Dependencies:   Libs mbed

Files at this revision

API Documentation at this revision

Comitter:
fantasiiio
Date:
Wed May 27 22:47:33 2015 +0000
Commit message:
first commit

Changed in this revision

Libs.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Libs.lib	Wed May 27 22:47:33 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/fantasiiio/code/Libs/#9af11f13219c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 27 22:47:33 2015 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "Commands.h"
+
+#define COMMAND_MAX_SIZE 30
+
+char command[COMMAND_MAX_SIZE];
+int cmdIndex;
+int commandReady;
+
+CommandList commands;
+Serial pc(USBTX, USBRX);
+
+// This function is called when a character goes into the RX buffer.
+void rxCallback() {
+    char c;
+    c = pc.getc();
+    
+    if(c != '\n')
+    {
+        command[cmdIndex++] = c;
+        command[cmdIndex] = 0;
+    }
+    
+    if(cmdIndex == COMMAND_MAX_SIZE ||  c == '\r')
+    {
+        command[cmdIndex-1] = 0;
+        commandReady = 1;
+        cmdIndex = 0;
+    }
+}
+
+void parseServo(CommandArgs cmdArgs)
+{
+    if(cmdArgs.paramCount != 3)
+        printf("command %s: wrong parameters count\r\n", cmdArgs.params[0]);
+        
+    printf("servo: %s %s\r\n",cmdArgs.params[1], cmdArgs.params[2]);
+}
+
+void parseUnknown(CommandArgs cmdArgs)
+{
+    printf("Unknown command '%s'\r\n", cmdArgs.params[0]);
+}
+
+int main()
+{
+    cmdIndex = 0;
+    commandReady = 0;
+        
+    commands.add("unknown",parseUnknown);
+    commands.add("servo",parseServo);
+
+    pc.printf("Enter Command:\r\n");
+    pc.attach(&rxCallback, Serial::RxIrq);
+    
+    while(1)
+    {
+        if(commandReady)
+        {
+            commands.parseCommand(command);
+            commandReady = 0;
+        }    
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed May 27 22:47:33 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/dbbf35b96557
\ No newline at end of file