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

Dependencies:   MODSERIAL mbed

Committer:
Tomas
Date:
Tue Apr 08 10:28:49 2014 +0000
Revision:
0:bada2c7bd577
Child:
1:f02249a6e8bb
nanopb test, not working yet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Tomas 0:bada2c7bd577 1 #include "mbed.h"
Tomas 0:bada2c7bd577 2 #include "pb.h"
Tomas 0:bada2c7bd577 3 #include "pb_encode.h"
Tomas 0:bada2c7bd577 4 #include "pb_decode.h"
Tomas 0:bada2c7bd577 5 #include "threeaxis.pb.h"
Tomas 0:bada2c7bd577 6 #include "MODSERIAL.h"
Tomas 0:bada2c7bd577 7
Tomas 0:bada2c7bd577 8 #include <iostream>
Tomas 0:bada2c7bd577 9 #include <string>
Tomas 0:bada2c7bd577 10 #include <fstream>
Tomas 0:bada2c7bd577 11 DigitalOut myled(LED1);
Tomas 0:bada2c7bd577 12 MODSERIAL pc(USBTX, USBRX, "modser"); //modified modser lib to be able to input custom stream
Tomas 0:bada2c7bd577 13
Tomas 0:bada2c7bd577 14
Tomas 0:bada2c7bd577 15 using namespace std;
Tomas 0:bada2c7bd577 16
Tomas 0:bada2c7bd577 17 int main() {
Tomas 0:bada2c7bd577 18 pc.baud(115200);
Tomas 0:bada2c7bd577 19 status_message Status;
Tomas 0:bada2c7bd577 20 gyro_message Gyro;
Tomas 0:bada2c7bd577 21
Tomas 0:bada2c7bd577 22 pc.claim();
Tomas 0:bada2c7bd577 23 uint8_t buffer[128];
Tomas 0:bada2c7bd577 24
Tomas 0:bada2c7bd577 25 pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
Tomas 0:bada2c7bd577 26 Status.Mode=1;
Tomas 0:bada2c7bd577 27 Gyro.X=1.1;
Tomas 0:bada2c7bd577 28 Gyro.Y=2.1;
Tomas 0:bada2c7bd577 29 Gyro.Z=3.1;
Tomas 0:bada2c7bd577 30 while(1){
Tomas 0:bada2c7bd577 31 Gyro.X+=0.1;
Tomas 0:bada2c7bd577 32 Gyro.Y+=0.2;
Tomas 0:bada2c7bd577 33 Gyro.Z+=0.3;
Tomas 0:bada2c7bd577 34
Tomas 0:bada2c7bd577 35 if (pb_encode(&stream, gyro_message_fields, &Gyro)) {
Tomas 0:bada2c7bd577 36 pc.putc('$');
Tomas 0:bada2c7bd577 37 //fwrite(buffer, 1, stream.bytes_written, stdout);
Tomas 0:bada2c7bd577 38 pc.printf("%s", buffer);
Tomas 0:bada2c7bd577 39 //pb_write(&stream, &buffer, 20);
Tomas 0:bada2c7bd577 40 //memset(&buffer[0], 0, sizeof(buffer)); //empty buffer
Tomas 0:bada2c7bd577 41 pc.putc('e');
Tomas 0:bada2c7bd577 42 pc.putc('n');
Tomas 0:bada2c7bd577 43 pc.putc('d');
Tomas 0:bada2c7bd577 44 //stream*=0; //empty stream, not working as of now but creating error on mbed
Tomas 0:bada2c7bd577 45 }
Tomas 0:bada2c7bd577 46
Tomas 0:bada2c7bd577 47 else {
Tomas 0:bada2c7bd577 48 pc.printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
Tomas 0:bada2c7bd577 49 return 1;
Tomas 0:bada2c7bd577 50 }
Tomas 0:bada2c7bd577 51 wait(1);
Tomas 0:bada2c7bd577 52 }
Tomas 0:bada2c7bd577 53 }