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

Dependencies:   MODSERIAL mbed

main.cpp

Committer:
Tomas
Date:
2014-04-08
Revision:
0:bada2c7bd577
Child:
1:f02249a6e8bb

File content as of revision 0:bada2c7bd577:

#include "mbed.h"
#include "pb.h"
#include "pb_encode.h"
#include "pb_decode.h"
#include "threeaxis.pb.h"
#include "MODSERIAL.h"

#include <iostream>
#include <string>
#include <fstream>
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 Gyro;
    
    pc.claim();
    uint8_t buffer[128];
    
    pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
    Status.Mode=1;
    Gyro.X=1.1;
    Gyro.Y=2.1;
    Gyro.Z=3.1;
    while(1){
        Gyro.X+=0.1;
        Gyro.Y+=0.2;
        Gyro.Z+=0.3;
        
        if (pb_encode(&stream, gyro_message_fields, &Gyro)) {
            pc.putc('$');
            //fwrite(buffer, 1, stream.bytes_written, stdout);
            pc.printf("%s", buffer);
            //pb_write(&stream, &buffer, 20);
            //memset(&buffer[0], 0, sizeof(buffer)); //empty buffer
            pc.putc('e');
            pc.putc('n');
            pc.putc('d');
            //stream*=0; //empty stream, not working as of now but creating error on mbed
        }
        
        else {
            pc.printf("Encoding failed: %s\n", PB_GET_ERROR(&stream));
            return 1;
        }        
        wait(1);
    }
}