Nanopb (lightweight version of googles protobuf) test. It is not working as it should yet.

Dependencies:   MODSERIAL mbed

Revision:
2:487359a1a439
Parent:
1:f02249a6e8bb
Child:
3:fd0e1bc80f78
--- a/main.cpp	Wed Apr 09 11:31:53 2014 +0000
+++ b/main.cpp	Wed Apr 09 11:37:05 2014 +0000
@@ -10,16 +10,10 @@
 #include <fstream>
 #include <algorithm>
 
-
-DigitalOut myled(LED1);
 MODSERIAL pc(USBTX, USBRX, "modser"); //modified modser lib to be able to input custom stream
 
-
-using namespace std;
-
 int main() {
     pc.baud(115200);
-    status_message Status;
     gyro_message GyroOut, GyroIn;
     
     pc.claim();
@@ -27,8 +21,7 @@
     uint8_t bufferin[150];
     
     pb_ostream_t streamout = pb_ostream_from_buffer(bufferout, sizeof(bufferout));
-    
-    Status.Mode=1;
+
     GyroOut.X=1.1;
     GyroOut.Y=2.1;
     GyroOut.Z=3.1;
@@ -38,7 +31,9 @@
         GyroOut.Y+=0.2;
         GyroOut.Z+=0.3;
         
-        if (pb_encode(&streamout, gyro_message_fields, &GyroOut)) {
+        pc.printf("Raw values: x: %4.2f, y: %4.2f, z: %4.2f\r\n", GyroOut.X, GyroOut.Y, GyroOut.Z); //print values before encoding
+        
+        if (pb_encode(&streamout, gyro_message_fields, &GyroOut)) { //encode message
             /*pc.putc('$');
             //fwrite(buffer, 1, stream.bytes_written, stdout);
             pc.printf("%s", buffer);
@@ -50,23 +45,24 @@
             //memset(&buffer[0], 0, sizeof(buffer)); //empty buffer*/
 
             //new test code:
-            pc.printf("Raw values: x: %4.2f, y: %4.2f, z: %4.2f\r\n", GyroOut.X, GyroOut.Y, GyroOut.Z);
+            
             pc.printf("%s\r\n", bufferout);
         }
         
-        else {
+        else { //print error message if encoding fails
             pc.printf("Encoding failed: %s\n", PB_GET_ERROR(&streamout));
             return 0;
         }
+        
         pc.printf("decoding...\r\n");
-        pb_istream_t streamin = pb_istream_from_buffer(bufferin, sizeof(bufferin));
+        pb_istream_t streamin = pb_istream_from_buffer(bufferin, sizeof(bufferin)); //create input stream
         for(int i=0;i<=streamout.bytes_written;i++) //copy output buffer to input buffer
             bufferin[i]=bufferout[i];
         if (pb_decode(&streamin, gyro_message_fields, &GyroIn)) { //decode message
-            pc.printf("Decoded values: x: %4.2f, y: %4.2f, z: %4.2f\r\n", GyroIn.X, GyroIn.Y, GyroIn.Z);
+            pc.printf("Decoded values: x: %4.2f, y: %4.2f, z: %4.2f\r\n", GyroIn.X, GyroIn.Y, GyroIn.Z); //print decoded values
         }
         
-        else {
+        else { //print error message if decoding fails
             pc.printf("Decoding failed: %s\n", PB_GET_ERROR(&streamin));
             return 0;
         }