Serial Packet Handler

Dependencies:   MbedJSONValue mbed

Files at this revision

API Documentation at this revision

Comitter:
Arkadi
Date:
Mon Feb 26 13:23:48 2018 +0000
Parent:
3:632a7590a341
Commit message:
Example How to work with json packets

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 632a7590a341 -r 7d1077d2a30b main.cpp
--- a/main.cpp	Mon Jan 15 12:46:23 2018 +0000
+++ b/main.cpp	Mon Feb 26 13:23:48 2018 +0000
@@ -6,7 +6,7 @@
     Construct packet from uart and parse with json format
     json:<PACKET>\r\n
     test with
-    json:{"my_array": ["demo_string", 10], "my_boolean": true}
+    json:{"my_array": ["demo_string", 10], "my_boolean": true}\r\n
 */
 
 /*
@@ -26,7 +26,7 @@
 ///////////////
 #include "mbed.h"
 #include "MbedJSONValue.h"
-#include <string>
+//#include <string>
 
 //#include "BufferedSerial.h" // uart handler library
 ///////////////
@@ -221,7 +221,7 @@
 #ifdef DEBUG_MOD1
     // write buffer to screen
     //pc.printf("%d, %.*s", packetMSG.bufferIndex ,packetMSG.bufferIndex, packetMSG.buffer );
-    pc.printf("%s", json);
+    //pc.printf("%s", json);
 #endif
 
     MbedJSONValue demo;
@@ -231,16 +231,16 @@
     //parse the previous string and fill the object demo
     parse(demo, json);
 
-    std::string my_str;
-    int my_int;
-    bool my_bool;
-
-    my_str = demo["my_array"][0].get<std::string>();
-    my_int = demo["my_array"][1].get<int>();
-    my_bool = demo["my_boolean"].get<bool>();
-
-    printf("my_str: %s\r\n", my_str.c_str());
-    printf("my_int: %d\r\n", my_int);
-    printf("my_bool: %s\r\n", my_bool ? "true" : "false");
+//    string my_str;
+//    int my_int;
+//    bool my_bool;
+//
+//    my_str = demo["my_array"][0].get<std::string>();
+//    my_int = demo["my_array"][1].get<int>();
+//    my_bool = demo["my_boolean"].get<bool>();
+//
+//    printf("my_str: %s\r\n", my_str.c_str());
+//    printf("my_int: %d\r\n", my_int);
+//    printf("my_bool: %s\r\n", my_bool ? "true" : "false");
 
 }
\ No newline at end of file