Auto: s7-d2 — UDT / STRUCT / nested-DB fan-out

Closes #300
This commit is contained in:
Joseph Doherty
2026-04-26 06:50:26 -04:00
parent 7e62a1158f
commit 5f8d84db43
13 changed files with 1139 additions and 16 deletions

View File

@@ -45,10 +45,39 @@ def seed_buffer(buf: bytearray, seeds: list[dict]) -> None:
"""Poke seed values into the area buffer at declared byte offsets.
Each seed is {"offset": int, "type": str, "value": int|float|bool|str}
where type ∈ {u8, i8, u16, i16, u32, i32, f32, bool, ascii}. Endianness is
big-endian (Siemens wire format).
where type ∈ {u8, i8, u16, i16, u32, i32, f32, bool, ascii, udt_layout}.
Endianness is big-endian (Siemens wire format).
PR-S7-D2: ``udt_layout`` is a meta-seed-type that flattens an ordered list
of UDT members into per-member primitive seeds at member-byte offsets
relative to the parent's ``offset``. Shape:
{
"offset": 400, "type": "udt_layout",
"members": [
{"name": "Pressure", "offset": 0, "type": "f32", "value": 12.5},
{"name": "Status", "offset": 4, "type": "i16", "value": 7},
{"name": "Enabled", "offset": 6, "type": "bool", "value": true, "bit": 0}
]
}
Members reuse the same primitive seed types so the simulator stays
one-pass — ``udt_layout`` is sugar that lets the JSON profile read like
the UDT layout the .NET driver fan-outs into.
"""
for seed in seeds:
# PR-S7-D2: expand udt_layout meta-seeds inline before the per-type
# dispatch so members hit the same primitive paths as a flat seed list.
if seed.get("type") == "udt_layout":
base = int(seed["offset"])
members = seed.get("members", [])
expanded = []
for m in members:
child = dict(m)
child["offset"] = base + int(m.get("offset", 0))
expanded.append(child)
seed_buffer(buf, expanded)
continue
off = int(seed["offset"])
t = seed["type"]
v = seed["value"]