All in one solution demonstrating how to use nanopb Protocol Buffers library from within mbed environment. Test case is very simple. It works.

Dependencies:   nanopb protocol

Original import was an all-in-one solution that only depends on mbed.

Current implementation extracted 2 librarires:

1) nanopb contains code required to use nanopb and Timestamp dependency. 2) protocol is a specific research protocol used by LCE at Itron at the moment of commit.

The application decodes Protocol Buffers message generated with GO application using the same 'protocol'. This test level application decodes message and validates that it matches expected.

It is simply a proof that nanopb library can be used.

Committer:
sgnezdov
Date:
Wed Jul 12 22:40:29 2017 +0000
Revision:
0:fbdd0d307c19
initial import demonstrates how to decode Sample protocol buffers message.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sgnezdov 0:fbdd0d307c19 1 #include "mbed.h"
sgnezdov 0:fbdd0d307c19 2
sgnezdov 0:fbdd0d307c19 3 #include "pb_decode.h"
sgnezdov 0:fbdd0d307c19 4 #include "sample.pb.h"
sgnezdov 0:fbdd0d307c19 5
sgnezdov 0:fbdd0d307c19 6 int main()
sgnezdov 0:fbdd0d307c19 7 {
sgnezdov 0:fbdd0d307c19 8 printf("\nProtoBufTest\n");
sgnezdov 0:fbdd0d307c19 9
sgnezdov 0:fbdd0d307c19 10 uint8_t buffer[2] = { 0x10, 0x05 };
sgnezdov 0:fbdd0d307c19 11 size_t message_length = 2;
sgnezdov 0:fbdd0d307c19 12
sgnezdov 0:fbdd0d307c19 13 protocol_Sample message = protocol_Sample_init_zero;
sgnezdov 0:fbdd0d307c19 14 pb_istream_t stream = pb_istream_from_buffer(buffer, message_length);
sgnezdov 0:fbdd0d307c19 15 bool status = pb_decode(&stream, protocol_Sample_fields, &message);
sgnezdov 0:fbdd0d307c19 16 if (!status) {
sgnezdov 0:fbdd0d307c19 17 printf("Decoding failed: %s\n", PB_GET_ERROR(&stream));
sgnezdov 0:fbdd0d307c19 18 exit(1);
sgnezdov 0:fbdd0d307c19 19 }
sgnezdov 0:fbdd0d307c19 20 printf("Alarm: %d\n", message.alarm);
sgnezdov 0:fbdd0d307c19 21
sgnezdov 0:fbdd0d307c19 22 exit(0);
sgnezdov 0:fbdd0d307c19 23 }