... | ... | @@ -37,6 +37,26 @@ Follow the [instructions here](ihttps://github.com/nanopb/nanopb#generating-the- |
|
|
|
|
|
# Implementation and Examples
|
|
|
|
|
|
## Protofiles:
|
|
|
Let's say you want to transmit a Can message in a serialized protobuf format. Then we need to define the can message and its contents inside a proto file as follows:
|
|
|
|
|
|
```
|
|
|
//can.proto
|
|
|
message can_message {
|
|
|
required int64 timestamp_ms = 1;
|
|
|
|
|
|
required int32 bus_id = 2; // The bus number which received the CAN message
|
|
|
required int32 message_id = 3; // Standard 11-bit
|
|
|
required int32 data_byte = 4; // Usually 8 bytes but modified for simplified example
|
|
|
}
|
|
|
```
|
|
|
In this file a message to be transmitted is defined using `message` keyword, followed by message name. There are 3 members inside the message with int64 and int32 datatypes respectively. The member of the message has to be initialized if `required` keyword is used. Alternatively `option` keyword can also be used. The `required int64 timestamp_ms = 1` the number after equality operator is the tag of the message member, which are used to match fields when serializing and deserializing the data.
|
|
|
For more information about `proto` message, visit the [documentation.](https://developers.google.com/protocol-buffers/docs/overview).
|
|
|
|
|
|
On running the python script to generate header and source files from proto file, we get structures:
|
|
|
```
|
|
|
i
|
|
|
```
|
|
|
|
|
|
## Simple Getting started Example
|
|
|
Todo
|
... | ... | |