This repository contains protobufs leveraging nanopb intended for device communication and settings storage
The source files for the protobufs are intended to be generated using the nanopb_generator.py Python script found in the nanopb Github repository.
This repository contains a script proto_gen.py that can be used to generate the output as a pre-build step for a project to keep the output in sync with the proto definitions.
protos/settings/device/v1/device_settings.options.base ignores all DeviceSettings / nested-group fields.
device_settings.options is not committed. scripts/merge_device_settings_options.cmake writes it from .base
plus an explicit opt-in: -DPORT= for port/<device>/settings_options/device_settings.options, or
-DTEMPLATE= for device_settings.options.template. Neither path is implied.
With no -DPORT and no -DTEMPLATE, the merge writes deny-all .base only, so a device that forgot its
options file fails at compile instead of enabling every field.
Unit tests pass the all-in template as -DPORT (or -DTEMPLATE) on purpose.
scripts/apply_device_settings_options.cmake does the same when NANOPB_DEVICE_SETTINGS_OPTIONS_PORT is set,
and leaves the merge deny-all when that variable is unset.
- Define the field in the relevant
.protounderprotos/settings/device/v1/(or add a new message and wire it intodevice_settings.proto). - Pick the field number — use an unused tag in that message (gaps are fine if you plan to fill them later). Use
reservedonly when retiring a number for good (e.g. after deleting a field that may still appear on the wire), so it cannot be reused accidentally. - Opt in for all-in / unit-test builds — add a line to
device_settings.options.templatewithtype:FT_DEFAULT(andmax_count/fixed_countfor repeated fields).max_countalone does not clearFT_IGNORE. - Opt in per device when ready — add the same style of line as in template to that product’s
port/<device>/settings_options/device_settings.options(max_count/fixed_countmight be different). Until then, deny-by-default keeps the field out of that device’s generatedDeviceSettingsstruct. - Regenerate nanopb outputs (device build or bare
nanopb_generator) and update migration / firmware that consume the new field.
Notes:
- New top-level
DeviceSettings.*members and fields under deny-listed groups (DeviceSettingsCANGroup.*,DeviceSettingsEthernetGroup.*,DeviceSettingsLINGroup.*,DeviceSettingsSerdesGroup.*) need explicit opt-ins in steps 3–4. - Fields added inside an already opted-in nested message (for example a new member of
DeviceSettingsEthernet) appear automatically once that parent is enabled; they do not need a separateDeviceSettings.*options line unless you introduce a new group message covered by the deny wildcards.
The protobuf parser must know how many bytes to process in order to correctly deserialize the message. This is how each protobuf should be packaged
- varint encoded byte length of the following header
- SettingsHeader message
- Protobuf described in the SettingsHeader
Show your appreciation to those who have contributed to the project.
protobuf license: https://github.com/protocolbuffers/protobuf/blob/main/LICENSE nanopb license: https://github.com/nanopb/nanopb/blob/master/LICENSE.txt