All in one solution demonstrating how to use nanopb Protocol Buffers library from within mbed environment. Test case is very simple. It works.
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.
source/protocol/command.pb.h@0:fbdd0d307c19, 2017-07-12 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgnezdov | 0:fbdd0d307c19 | 1 | /* Automatically generated nanopb header */ |
sgnezdov | 0:fbdd0d307c19 | 2 | /* Generated by nanopb-0.3.8 at Wed Jul 12 11:04:33 2017. */ |
sgnezdov | 0:fbdd0d307c19 | 3 | |
sgnezdov | 0:fbdd0d307c19 | 4 | #ifndef PB_PROTOCOL_COMMAND_PB_H_INCLUDED |
sgnezdov | 0:fbdd0d307c19 | 5 | #define PB_PROTOCOL_COMMAND_PB_H_INCLUDED |
sgnezdov | 0:fbdd0d307c19 | 6 | #include <pb.h> |
sgnezdov | 0:fbdd0d307c19 | 7 | |
sgnezdov | 0:fbdd0d307c19 | 8 | #include "google/protobuf/timestamp.pb.h" |
sgnezdov | 0:fbdd0d307c19 | 9 | |
sgnezdov | 0:fbdd0d307c19 | 10 | /* @@protoc_insertion_point(includes) */ |
sgnezdov | 0:fbdd0d307c19 | 11 | #if PB_PROTO_HEADER_VERSION != 30 |
sgnezdov | 0:fbdd0d307c19 | 12 | #error Regenerate this file with the current version of nanopb generator. |
sgnezdov | 0:fbdd0d307c19 | 13 | #endif |
sgnezdov | 0:fbdd0d307c19 | 14 | |
sgnezdov | 0:fbdd0d307c19 | 15 | #ifdef __cplusplus |
sgnezdov | 0:fbdd0d307c19 | 16 | extern "C" { |
sgnezdov | 0:fbdd0d307c19 | 17 | #endif |
sgnezdov | 0:fbdd0d307c19 | 18 | |
sgnezdov | 0:fbdd0d307c19 | 19 | /* Enum definitions */ |
sgnezdov | 0:fbdd0d307c19 | 20 | typedef enum _protocol_CommandStatus { |
sgnezdov | 0:fbdd0d307c19 | 21 | protocol_CommandStatus_Success = 0 |
sgnezdov | 0:fbdd0d307c19 | 22 | } protocol_CommandStatus; |
sgnezdov | 0:fbdd0d307c19 | 23 | #define _protocol_CommandStatus_MIN protocol_CommandStatus_Success |
sgnezdov | 0:fbdd0d307c19 | 24 | #define _protocol_CommandStatus_MAX protocol_CommandStatus_Success |
sgnezdov | 0:fbdd0d307c19 | 25 | #define _protocol_CommandStatus_ARRAYSIZE ((protocol_CommandStatus)(protocol_CommandStatus_Success+1)) |
sgnezdov | 0:fbdd0d307c19 | 26 | |
sgnezdov | 0:fbdd0d307c19 | 27 | /* Struct definitions */ |
sgnezdov | 0:fbdd0d307c19 | 28 | typedef struct _protocol_CommandBatch { |
sgnezdov | 0:fbdd0d307c19 | 29 | pb_callback_t sn; |
sgnezdov | 0:fbdd0d307c19 | 30 | pb_callback_t items; |
sgnezdov | 0:fbdd0d307c19 | 31 | /* @@protoc_insertion_point(struct:protocol_CommandBatch) */ |
sgnezdov | 0:fbdd0d307c19 | 32 | } protocol_CommandBatch; |
sgnezdov | 0:fbdd0d307c19 | 33 | |
sgnezdov | 0:fbdd0d307c19 | 34 | typedef struct _protocol_CommandResponseBatch { |
sgnezdov | 0:fbdd0d307c19 | 35 | pb_callback_t sn; |
sgnezdov | 0:fbdd0d307c19 | 36 | pb_callback_t items; |
sgnezdov | 0:fbdd0d307c19 | 37 | /* @@protoc_insertion_point(struct:protocol_CommandResponseBatch) */ |
sgnezdov | 0:fbdd0d307c19 | 38 | } protocol_CommandResponseBatch; |
sgnezdov | 0:fbdd0d307c19 | 39 | |
sgnezdov | 0:fbdd0d307c19 | 40 | typedef struct _protocol_SecureCommandBatch { |
sgnezdov | 0:fbdd0d307c19 | 41 | pb_callback_t signature; |
sgnezdov | 0:fbdd0d307c19 | 42 | pb_callback_t content; |
sgnezdov | 0:fbdd0d307c19 | 43 | /* @@protoc_insertion_point(struct:protocol_SecureCommandBatch) */ |
sgnezdov | 0:fbdd0d307c19 | 44 | } protocol_SecureCommandBatch; |
sgnezdov | 0:fbdd0d307c19 | 45 | |
sgnezdov | 0:fbdd0d307c19 | 46 | typedef struct _protocol_Command { |
sgnezdov | 0:fbdd0d307c19 | 47 | google_protobuf_Timestamp issuedDT; |
sgnezdov | 0:fbdd0d307c19 | 48 | uint32_t commandType; |
sgnezdov | 0:fbdd0d307c19 | 49 | pb_callback_t payload; |
sgnezdov | 0:fbdd0d307c19 | 50 | /* @@protoc_insertion_point(struct:protocol_Command) */ |
sgnezdov | 0:fbdd0d307c19 | 51 | } protocol_Command; |
sgnezdov | 0:fbdd0d307c19 | 52 | |
sgnezdov | 0:fbdd0d307c19 | 53 | typedef struct _protocol_CommandResponse { |
sgnezdov | 0:fbdd0d307c19 | 54 | google_protobuf_Timestamp issuedDT; |
sgnezdov | 0:fbdd0d307c19 | 55 | protocol_CommandStatus status; |
sgnezdov | 0:fbdd0d307c19 | 56 | /* @@protoc_insertion_point(struct:protocol_CommandResponse) */ |
sgnezdov | 0:fbdd0d307c19 | 57 | } protocol_CommandResponse; |
sgnezdov | 0:fbdd0d307c19 | 58 | |
sgnezdov | 0:fbdd0d307c19 | 59 | /* Default values for struct fields */ |
sgnezdov | 0:fbdd0d307c19 | 60 | |
sgnezdov | 0:fbdd0d307c19 | 61 | /* Initializer values for message structs */ |
sgnezdov | 0:fbdd0d307c19 | 62 | #define protocol_Command_init_default {google_protobuf_Timestamp_init_default, 0, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 63 | #define protocol_CommandBatch_init_default {{{NULL}, NULL}, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 64 | #define protocol_SecureCommandBatch_init_default {{{NULL}, NULL}, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 65 | #define protocol_CommandResponse_init_default {google_protobuf_Timestamp_init_default, (protocol_CommandStatus)0} |
sgnezdov | 0:fbdd0d307c19 | 66 | #define protocol_CommandResponseBatch_init_default {{{NULL}, NULL}, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 67 | #define protocol_Command_init_zero {google_protobuf_Timestamp_init_zero, 0, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 68 | #define protocol_CommandBatch_init_zero {{{NULL}, NULL}, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 69 | #define protocol_SecureCommandBatch_init_zero {{{NULL}, NULL}, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 70 | #define protocol_CommandResponse_init_zero {google_protobuf_Timestamp_init_zero, (protocol_CommandStatus)0} |
sgnezdov | 0:fbdd0d307c19 | 71 | #define protocol_CommandResponseBatch_init_zero {{{NULL}, NULL}, {{NULL}, NULL}} |
sgnezdov | 0:fbdd0d307c19 | 72 | |
sgnezdov | 0:fbdd0d307c19 | 73 | /* Field tags (for use in manual encoding/decoding) */ |
sgnezdov | 0:fbdd0d307c19 | 74 | #define protocol_CommandBatch_sn_tag 1 |
sgnezdov | 0:fbdd0d307c19 | 75 | #define protocol_CommandBatch_items_tag 10 |
sgnezdov | 0:fbdd0d307c19 | 76 | #define protocol_CommandResponseBatch_sn_tag 1 |
sgnezdov | 0:fbdd0d307c19 | 77 | #define protocol_CommandResponseBatch_items_tag 2 |
sgnezdov | 0:fbdd0d307c19 | 78 | #define protocol_SecureCommandBatch_signature_tag 1 |
sgnezdov | 0:fbdd0d307c19 | 79 | #define protocol_SecureCommandBatch_content_tag 2 |
sgnezdov | 0:fbdd0d307c19 | 80 | #define protocol_Command_issuedDT_tag 1 |
sgnezdov | 0:fbdd0d307c19 | 81 | #define protocol_Command_commandType_tag 2 |
sgnezdov | 0:fbdd0d307c19 | 82 | #define protocol_Command_payload_tag 10 |
sgnezdov | 0:fbdd0d307c19 | 83 | #define protocol_CommandResponse_issuedDT_tag 1 |
sgnezdov | 0:fbdd0d307c19 | 84 | #define protocol_CommandResponse_status_tag 2 |
sgnezdov | 0:fbdd0d307c19 | 85 | |
sgnezdov | 0:fbdd0d307c19 | 86 | /* Struct field encoding specification for nanopb */ |
sgnezdov | 0:fbdd0d307c19 | 87 | extern const pb_field_t protocol_Command_fields[4]; |
sgnezdov | 0:fbdd0d307c19 | 88 | extern const pb_field_t protocol_CommandBatch_fields[3]; |
sgnezdov | 0:fbdd0d307c19 | 89 | extern const pb_field_t protocol_SecureCommandBatch_fields[3]; |
sgnezdov | 0:fbdd0d307c19 | 90 | extern const pb_field_t protocol_CommandResponse_fields[3]; |
sgnezdov | 0:fbdd0d307c19 | 91 | extern const pb_field_t protocol_CommandResponseBatch_fields[3]; |
sgnezdov | 0:fbdd0d307c19 | 92 | |
sgnezdov | 0:fbdd0d307c19 | 93 | /* Maximum encoded size of messages (where known) */ |
sgnezdov | 0:fbdd0d307c19 | 94 | /* protocol_Command_size depends on runtime parameters */ |
sgnezdov | 0:fbdd0d307c19 | 95 | /* protocol_CommandBatch_size depends on runtime parameters */ |
sgnezdov | 0:fbdd0d307c19 | 96 | /* protocol_SecureCommandBatch_size depends on runtime parameters */ |
sgnezdov | 0:fbdd0d307c19 | 97 | #define protocol_CommandResponse_size 26 |
sgnezdov | 0:fbdd0d307c19 | 98 | /* protocol_CommandResponseBatch_size depends on runtime parameters */ |
sgnezdov | 0:fbdd0d307c19 | 99 | |
sgnezdov | 0:fbdd0d307c19 | 100 | /* Message IDs (where set with "msgid" option) */ |
sgnezdov | 0:fbdd0d307c19 | 101 | #ifdef PB_MSGID |
sgnezdov | 0:fbdd0d307c19 | 102 | |
sgnezdov | 0:fbdd0d307c19 | 103 | #define COMMAND_MESSAGES \ |
sgnezdov | 0:fbdd0d307c19 | 104 | |
sgnezdov | 0:fbdd0d307c19 | 105 | |
sgnezdov | 0:fbdd0d307c19 | 106 | #endif |
sgnezdov | 0:fbdd0d307c19 | 107 | |
sgnezdov | 0:fbdd0d307c19 | 108 | #ifdef __cplusplus |
sgnezdov | 0:fbdd0d307c19 | 109 | } /* extern "C" */ |
sgnezdov | 0:fbdd0d307c19 | 110 | #endif |
sgnezdov | 0:fbdd0d307c19 | 111 | /* @@protoc_insertion_point(eof) */ |
sgnezdov | 0:fbdd0d307c19 | 112 | |
sgnezdov | 0:fbdd0d307c19 | 113 | #endif |