scadaver is four layers stacked bottom to top: casket, an external pinned crate that owns every
wire format; src/ops/, one module per protocol, which turns a request into bytes, sends them,
parses the answer and returns typed values or an error that names the operation; src/model.rs and
src/protocol.rs, the shared records and the single registry of protocol names and default ports;
and the three surfaces, src/cli.rs, src/tui.rs and src/web/, which parse arguments, call ops
and render. src/main.rs is 83 lines and does nothing except call into the library.
casket(external, tagv0.1.1): frame codecs and the socket calls that carry them. Nothing in this repo should call it exceptsrc/ops/.src/ops/: 18 files. Sixteen are one protocol each (bacnet,beckhoff,dnp3,enip,iec104,mitsubishi,modbus,mqtt,omron,opcua,phoenix,rockwell,schneider,siemens,snmp, plus the shared dispatch inmod.rs), andranges.rsholds the Modbus and SLMP address tables and chunkers.src/model.rs:EndpointRecord,Outcome,Message,Level. These are what a surface prints and what the database layer stores.src/protocol.rs: theProtocolenum andALL, sixteen entries. One place knows that eWON defaults to 1507 and Modbus to 502.- Surfaces:
src/cli.rs(5358 lines),src/tui.rs(6714),src/web/(routes.rs5539 plus three static assets inlined withinclude_str!). They share the library throughsrc/lib.rs, and the CLI-side modules sit behind aclifeature that is on by default. src/safety.rs: safe mode, fragile-host refusal, and the table of verbs that mutate a device.
The hard rule: a surface may not call casket directly. scripts/check-parity.sh greps each
surface for casket:: and fails on any hit. The current counts, which are the backlog rather than
a pass, are 109 in cli.rs, 53 in tui.rs, 142 in routes.rs. Every one of those is a protocol
behaviour that still lives in a surface, so a fix there reaches one interface instead of three.
scadaver get register --protocol ewon -i 10.0.0.5 --type int16 --address 100
src/cli.rsparsesVerb::Get { noun: GetNoun::Register { .. } }, resolves the target, and askssrc/protocol.rsfor the default port ofProtocol::Ewon, which is 1507, the IPCONF discovery port.- The CLI passes the user's port, or 0 when the user gave none, into
src/ops/ewon.rs.ewon::modbus_portmaps 0 to 502 by delegating tocasket::core::modbus::effective_port, so a tag read never inherits the discovery port. An explicit 1507 is honoured, because the user may really mean it. ops::ewon::read_registervalidates the unit id (1 through 247), encodes the request, callscasket, and decodes the reply withdecode_register, which reports how many words came back when the reply is short.outcome.recordand the formatted value go back tocli.rs, which prints them and writes the row throughsrc/db.rs.
Nothing above the ops line knows a byte offset. Nothing below it knows about terminals or HTML.
opsreturns and never prints. A protocol function's return type is its contract, and the error variant names the operation and the value that failed.- One registry.
src/protocol.rsis the only place that maps a protocol to a default port. The three private copies this replaced are why eWON was on 80 in the CLI and 1507 everywhere else. - CLI output is pinned.
tests/golden/holds fixtures for nine cases, three in "simulators down" mode and six in "simulators up" mode, andscripts/golden.shdiffs both. The harness normalises the version token in the banner so a release does not rewrite every fixture. - No surface reaches past
ops.scripts/check-parity.shenforces it and its count is reported, not ignored.
Before, there was no protocol layer at all. Each surface carried its own socket code and its own copy of the protocol table:
| File | v1.7.2 lines | now |
|---|---|---|
src/cli.rs |
3405 | 5358 |
src/tui.rs |
9057 | 6714 |
src/web/routes.rs |
2540 | 5539 |
New files that did not exist at v1.7.2: src/model.rs (69), src/protocol.rs (166),
src/safety.rs (257), and all of src/ops/ (18 files, of which mod.rs 3356, ranges.rs 660,
ewon.rs 599 and omron.rs 333 are the large ones; the sixteen protocol modules are mostly 35 to
97 lines).
Three things the split fixed, each of which was a user-visible defect rather than tidiness:
- The CLI had its own default-port table, so
--protocol ewonwithout a port went to 80 while the rest of the tool said 1507. - Web
cpu_runsent Monitor (0x02) where the CLI sent Run (0x01), so two interfaces left the same controller in different states. - Web
read_dmclamped the requested word count to 100 and reported success, hiding a wrong read.
One thing it fixed that was not a defect in the tool: src/main.rs and src/lib.rs both declared
every module, so each module compiled twice and 46 of 361 test runs were the same test in two
binaries. main.rs is a consumer now, and the suite is 315 runs with the same unique tests.
src/ops/mod.rsis 3356 lines and mixes the verticals with shared dispatch. The sixteen protocol modules are thin; the shared file is where the growth went.cli.rsgrew by about 2000 lines androutes.rsby about 3000. The socket code left, the argument parsing, rendering and state did not, and the web routes in particular still carry handler logic that belongs inops.- The parity count is red at 109 / 53 / 142. Until it is zero, "fix it once and all surfaces get it" is a goal rather than a property.
- 35 tests are
#[ignore]d. They are the ones that need a live simulator or a server, so a green run does not cover them. scripts/sim_*.pyandsim/*_sim.pyare two generations of simulators. They are documented insim/README.md, not merged, because eight call sites name the exact paths.
- Behaviour:
src/ops/<protocol>.rs. If the change is about bytes, addresses or error text, it belongs there and nowhere else. - Ports and names:
src/protocol.rs. - Output that must not drift:
tests/golden/plusscripts/golden.sh; re-capture only with--updateand only when the change is intended. - Gates and the build environment:
docs/build.md. - Simulators and their provenance:
sim/README.md. - What a surface still does by hand:
scripts/check-parity.sh, and the numbers it prints.