Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ADR 0024 — Server kinds in the driver framework (Modbus slave)

Status: accepted · 2026-10-30 (Modbus DSA parity plan, ruling 15; master writes as ruling P4; values and master requests as rulings P24–P27). Replaces the “Slave/server mode” row (ServerKind) of ADR 0004.

Context

DSA’s Modbus link can also be a slave: it serves values from its tree to Modbus masters (SCADA, PLCs) and takes their writes. ADR 0004 sketched an optional ServerKind trait with a shared listener per port and a process image per unit, but nothing was built. The framework knew only connections that poll devices: an owner task per connection holds the transport, tickers send polls and pings, a ~set is a device write followed by a read-back.

A server has the same shape seen from the other side: a listener (or a serial port) instead of a socket to a device, unit ids instead of devices, and points that a master reads instead of points the link reads. What differs is where values come from and that they flow both ways.

Decision

  • A server is a connection kind. Driver::is_server(conn) -> bool (default false) marks it; the Modbus link adds the kinds ip_slave {listen_host, listen_port} and serial_slave {serial params} beside ip_connection and serial_connection. Its devices are the units it serves, its points are what it serves. The tree keeps its shape and its actions: add_*, edit, remove, start/stop, folders, copy, export and import work as for any connection (a copy or import starts stopped, so two servers never fight for a port). What is new: the two connection kinds, the point param writable_by_master (Modbus) and attr.warning on a connection’s status leaf (below). open returns the running server; dropping the transport closes it.
  • Not polled, not pinged. A server connection gets no tickers. Its devices are Connected while it runs, except those the server refuses (Driver::serve returns them with why; they show Failed: Modbus refuses unit 0 under serial_slave, the RTU broadcast address).
  • Values from the tree. Every point of a server takes ~set at level write, whatever the driver’s point_meta says (Modbus: input registers and discrete inputs too, which a master cannot write). Driver::write puts the value into what the server serves; there is no device read-back: the framework publishes what the driver now serves (Driver::take_changed), which is the value a master reads (after its encoding: an f32, a scale). The framework hands each plan to the server (Driver::serve; at once: a re-plan wakes the owner), then writes the tree’s last value of every point that is new to the server or whose params or device params changed (after open: every point). So a restarted or edited connection, a device started again and a point edited to another scale serve the tree’s value; a point that stays as it was keeps what it serves (a master may have written it). Amended 2026-10-30 (ruling P29, O1): a tree value the server does not take (it does not fit the point’s new data type, or the write is cut) is logged at warn (the point, never the value) and published again as bad/config_error with the old value kept, also when the point is bad already (bad/disconnected while the server was down), until a value is served.
  • A point the tree never set has no value (ruling P24). Nothing is published for it, so a link that starts afresh does not overwrite the broker’s stored ~val with an invented 0, and a new point never takes over the words of a removed or changed one. Modbus answers a master read that touches such a point with exception 4 (server device failure). Modbus knows the bits of a register one by one (ruling P28): a bit point has a value once its bit is known, a word view once all its bits are, and a master read (or FC22) of a register needs the bits its points read; setting one flag of a register leaves its sibling flags without a value.
  • Values from the remote side, in one order. A master’s request goes through a channel to the connection’s owner task, the same task that applies the tree’s sets: Driver::remote takes it (cancel-safe: it awaits only the receipt), Driver::apply_remote answers it under the plan’s read lock once the server has the plan in force. The framework passes since, when that plan began; by the hook’s contract the driver answers busy, changing nothing, to a request received before it (a re-plan came while it waited), like a tree set planned before a re-plan (P19). Modbus also drops a request whose master stopped waiting (it got busy), so it is never applied late. So the last writer wins, and the value published is what the next master read returns. The remote side gets its answer only after the framework published what the request changed. A master write is logged at info by point (never the value) and counted in the device’s and the connection’s diagnostics; there is no sys/audit record (no WYRM caller).
  • Listener on loopback by default (listen_host = "127.0.0.1"). Modbus has no authentication: anyone who reaches the port reads every served value and writes those a master may write. Another address is allowed (adding a connection is already a config action). The server listens on every address the host name resolves to (localhost: ::1 and 127.0.0.1), and the bound addresses are checked: one that is not loopback is logged at warn when the server opens and shown as attr.warning on the connection’s status leaf (Driver::status_note; an attribute, not a new leaf, so no new reserved name).
  • Driver actions of their own. A server connection and its devices offer Driver::server_actions instead of Driver::actions (Modbus: none; the commissioning actions are a master’s).

Modbus rules (the driver’s, in links/modbus/src/slave.rs): points are views on the served registers and bits of their unit, so devices with the same unit and overlapping points share them. An address no point covers answers exception 2; a write touching a point without writable_by_master exception 3, and so does a write that a point it touches cannot decode (invalid BCD, text, m10k) or that makes a float NaN or infinite (ruling P25); a tree set that would do that to an overlapping point of another type is refused the same way; a refused request changes nothing. ip_slave leaves out an address the host does not have, and (ruling P29, R1) one whose address family it lacks (EAFNOSUPPORT: an IPv6-disabled host binding ::1 for localhost); any other bind error (the port in use, no permission) fails the connection. A unit not served gets no reply on RTU and exception 0x0B on TCP. An RTU broadcast (unit 0) write goes to every served unit that takes it, with no reply, and counts as one request of the connection; a broadcast read is ignored (ruling P26).

Consequences

  • Every hook has a default; drivers without server kinds compile and behave as before.
  • One request at a time per server connection: a master’s reads wait behind the tree’s sets. The owner does no device I/O for a server, but each publish is a Zenoh put on the owner task, so a burst of changes delays the next master request by those puts.
  • A stored point loads unchanged: writable_by_master defaults to false; it does nothing under a master connection, and poll_s and the device’s ping and batch params do nothing under a slave.
  • The served values live in memory: a restart of the connection serves the tree’s values it has; a fresh link process serves nothing until the tree sets values (masters get exception 4 meanwhile).
  • serial_slave is supported only as the only slave on its line (point to point to one master, ruling P27). The tokio-modbus 0.17 RTU server decodes every frame on the line as a request: other slaves’ replies on a shared RS485 bus make its decoder drop bytes, and after 20 tries in one decode it gives up, which ends the server; the connection then fails and reopens after backoff, losing the masters’ requests meanwhile. Framing by the 3.5-character gap of our own is a separate task.

Alternatives

  • A ServerKind trait beside Driver, one listener per port shared by connections (the ADR 0004 sketch): a second registration path, ref-counting and overlap rules across connections, for a case (two connections on one port) that a second device under one connection already covers.
  • Answering reads in the server task from a shared image (a mutex): faster reads, but tree sets and master writes would be ordered in two places, and the diagnostics would miss the reads.
  • Showing the warning in the error leaf: that leaf means the node failed; a running server is not failed.
  • Serving 0 for a point never set: what many slaves do, but it invents a value at good quality and, published, overwrites the broker’s stored one.