|
moddef-c
|
Embedded C runtime for ModDef (spec v0.4) — declarative Modbus device definitions. C99, no allocation, no dependencies (string.h + math.h), builds for Cortex-M.
The runtime parses binary .moddef documents in place: md_doc_t is a zero-copy view over the serialized bytes wherever they live — memory-mapped flash, a RAM buffer, or an array baked into the firmware. YAML/JSON stay host-side (convert with any other ModDef implementation).
md_transport_t is six blocking function pointers over your Modbus stack.
tools/moddef_c_gen.py embeds the binary document and emits point-index constants (byte offsets precomputed — no name lookups at runtime), C enums, and typed inline accessors. Runtime-loaded and generated documents share every code path.
Full codec lockstep with the Go/TS/Rust/Python implementations (shared vector suite): exact scaling, SunSpec scale factors and discovery (ID-relative model offsets, §7.3), selector cases, sentinels (MD_VAL_UNAVAILABLE / MD_ERR_UNAVAILABLE), strings, BCD, flags, packed fields, composed values, §11.4-validated writes. The decimal surface is double; md_decode_raw is the exact escape hatch and FPU-less targets can stay on the raw/integer path.
Vendor include/ + src/ (five .c files) into your firmware tree — there is nothing to configure. Tunables: -DMD_MAX_DISCOVERY=n (SunSpec base cache slots, default 4), -DMD_MAX_POINT_WORDS=n (stack window, default 64).
Tests need sibling checkouts of moddef (fixtures), devices (registry), and moddef-py with a .venv (host-side yaml→binary conversion and the generator).
Code generated from a ModDef document (for example by moddef gen) is not a derivative work of the ModDef tooling or runtime. You may license the generated output under any terms you choose. The runtime it imports (this library) is Apache-2.0 licensed; see the LICENSE file for its terms, which apply only to the runtime, not to your generated code.
Apache-2.0. See [LICENSE](LICENSE), [NOTICE](NOTICE), and CONTRIBUTING.md.