eebus

Home / Docs / SPINE: the model and the protocol

SPINE: the model and the protocol

The SPINE device model, addressing, NodeManagement discovery, bindings and subscriptions, acknowledgements, and Restricted Function Exchange with its merge rule.

SPINE defines what a device says it is and how peers read, write and subscribe to it.

The model

flowchart TB
  dev["<b>Device</b><br><small>d:_i:46925_HeatPump-1</small>"]
  e0["<b>Entity [0]</b> DeviceInformation<br><small>always present</small>"]
  e1["<b>Entity [1]</b> HeatPumpAppliance"]
  nm["<b>Feature 0</b> NodeManagement<br><small>the entry point for every peer</small>"]
  lc["<b>Feature 1</b> LoadControl<br><small>the limit lives here</small>"]
  dd["<b>Feature 2</b> DeviceDiagnosis<br><small>the heartbeat lives here</small>"]

  dev --> e0 --> nm
  dev --> e1
  e1 --> lc
  e1 --> dd

  classDef d fill:#0b8f63,stroke:#0b8f63,color:#fff;
  classDef e fill:#e6f5ef,stroke:#0b8f63,color:#101620;
  classDef f fill:transparent,stroke:#7b8595,color:#101620;
  class dev d
  class e0,e1 e
  class nm,lc,dd f

An entity path is a list, so entities nest. A feature address is the triple device / entity / feature, and it is what every message carries as source and destination.

A feature declares a role — server (holds the data) or client (asks for it) — and, per function, which operations are possible: read, write, and whether partial forms are supported. The crate announces a partial read in possibleOperations only for functions it can actually restrict.

Discovery

Every conversation begins at NodeManagement on entity 0.

  • Detailed discovery (§7.1) — "what are you?" Returns the whole tree: entities, features, roles, functions, operations.
  • Use-case discovery (§7.3) — "what do you do?" Returns nodeManagementUseCaseData: the use cases played, the actor played in each, and which numbered scenarios are supported.

Guessing use cases from feature types fails on a device that has a LoadControl feature for an unrelated reason.

A read names its function in either of two spellings — the function element, or an empty instance of the data element. spine-go uses only the second, and answers a read carrying only the first with errorNumber 6. The specification's example reads carry both, and so does this crate; it understands either.

A feature is identified by its type and its role. An entity may hold a DeviceDiagnosis server and client at once — evcc and the Porsche Mobile Charger Connect both do — and a Controllable System must, because it serves its own heartbeat and subscribes to the Energy Guard's. A subscription runs client → server, so its near end is the client feature.

When the tree changes underneath you

§7.1.5 and §7.5.4 let a device add, remove or modify its entities and use cases while a peer is connected — a car plugged in and driven away. Both changes are a notify carrying only what changed.

engine.subscribe_to_discovery(&peer_device, now);  // `Hub` does this for you
engine.add_entity(LocalEntity::new([2], EntityType::Compressor), now)?;
let gone = engine.remove_entity(&[1, 1], now)?;    // and everything beneath it

A removal also releases the bindings and subscriptions that named the entity's features, and drops the use cases it announced.

  • Subscribe, or hear nothing. §7.5.4: "a device that uses use case discovery should always subscribe to use case discovery". An arrival shows up in any re-read; a departure does not, because a discovery document merges. Only lastStateChange: removed on a notify reports it — EVCC scenario 8, the car that left, is that message. One subscription covers both functions, since §7.4.1 permits only whole-feature ones.
  • Neither discovery function is a list the generic merge can address. Detailed discovery is three parallel lists inside one value; a useCaseInformation entry is keyed by an optional address and an actor, which is not an identifier type. Merged the ordinary way, an update naming one new entity would replace the list, so both are merged by their own sections' rules.

Bindings and subscriptions

Two distinct grants, easily confused:

  • A binding grants the right to write to a feature that requires one.
  • A subscription asks to be notified when data changes.

LPC requires both, in that order, and requires the Energy Guard to have subscribed to the heartbeat before it writes a limit. A single-writer policy applies: a feature accepts a binding from one client, and the group lock the LPC implementation guide §3.5 describes is enforced here rather than left to the application.

"…that requires one"

§7.3 puts the requirement on the feature: "please note that some feature types define requirements for binding!" TC_SPINE_BIND_002 has the device under test reject an unbound write "if the target feature requires a binding (e.g. LoadControl)".

The use cases disagree on which features those are — LPC/LPP and their relatives require one, every HVAC use case says "Binding SHOULD NOT be used for this Scenario" — so WriteBinding is per feature:

limitation::load_control_feature(1);   // WriteBinding::Required — the default
cdt::setpoint_feature(1);              // WriteBinding::NotRequired — CDT §3.4.1.1

The default is Required, the safe way round: a wrongly closed feature refuses a write, where a wrongly open one accepts writes from anybody. See Who may write, and who may not for the split by use case.

Unchanged data is not notified (SPINE IG §2.4), so the age of a subscribed value says nothing about the peer: a room holding its temperature sends nothing. What silence means is a property of the use case, carried by the descriptors — see Who has to subscribe, and what silence means.

Both tables are readable — nodeManagementBindingData and nodeManagementSubscriptionData (§7.3.2, §7.4.2) — and both are answered from the relations actually held.

A relation belongs to both partners. §7.4.1 rule 4: "Subscription information SHALL be kept persistently by both subscription partners", and §7.4.3 has each entry describe "the relation of an own feature to one feature of a subscription partner" — either direction. The two directions are separate questions:

relations.is_bound(&their_client, &our_server);      // may this peer write to us?
relations.holds_binding(&our_client, &their_server); // did a peer grant us one?

A relation this device holds carries no identifier: Table 18 makes subscriptionId optional and says the value is "a server's unique ID", which is the peer's to assign.

The table is tailored to who is reading it. §7.4.3: "no subscription entries of a third device C are exchanged between A and B", so a peer does not learn which other peers this device talks to. Where nothing concerns the recipient the element is absent rather than empty, as Table 18 distinguishes.

A request or a release is honoured only in the sender's own name. The call names its client address in the payload, and the engine accepts it only when that address belongs to the device SHIP authenticated as the sender — a peer that leaves the device part out has it filled in from the header, which is how spine-go phrases it; a peer that names another device is answered errorNumber 7. Nothing in §7.3 gives a binding's client authority over anybody else's.

A peer's relations are bounded. Each device may hold at most MAX_RELATIONS_PER_PEER bindings and as many subscriptions; a request past that is answered errorNumber 3. A peer chooses its client addresses freely, so without a bound the tables would grow without limit.

Deciding a write

A feature may hand its writes to the application instead of storing them, which LPC needs: the acknowledgement records that the limit was applied, so only the appliance can produce it. The engine reports SpineEvent::WriteRequested and waits. It carries two payloads:

  • data — what arrived, exactly. It says which entries the write addresses, and it is the record of what was asked for.
  • resolved — what the function would hold if the write were accepted: data merged into what is stored.

Decide on resolved. A partial write carries only what changed, so an absent isLimitActive means "unchanged", not "deactivate".

accept_write returns whether the engine could store what was accepted: a merged list that would exceed the bound reaches the peer as errorNumber 3, not an acknowledgement. The limitation actors handle this, so a §14a record says what the peer was told and the state machine ends where a refused write leaves it.

A write is refused with errorNumber 7 when an entry arrives without its primary and sub identifiers, which use-case IG §3.1 requires in every message: such an entry names nothing stored, so it can neither update nor delete.

A partial write cannot grow a list without end. An entry whose identifier matches nothing stored is appended, so one function holds at most 128 entries and a write that would exceed that is refused whole.

The queue of undecided writes is bounded. At most sixteen deferred writes may wait; beyond that a peer is answered errorNumber 3, overload. One undecided past §5.2.5's maximum response delay is abandoned and reported as SpineEvent::WriteAbandoned.

A write whose result the application owns is stored as the application says. accept_write stores what the peer sent, merged into what was there — correct wherever SPINE gives entries identifiers. For a function that is one value rather than a list it is not: OHPCF's partial write is mandatory, and merging its two-field fragment would replace everything the compressor announced, and notify that to every subscriber (§7.4.1). accept_write_with stores the application's value instead.

match compressor.apply(&write.resolved) {
    Ok(_)        => engine.accept_write_with(write.token, compressor.data(), now)?,
    Err(refused) => { engine.reject_write(write.token, refused.error_number(), now); }
}

Acknowledgements and errors

A message may request an acknowledgement, and whether one is owed depends on the classifier, the outcome and the request together (§5.2.5.1). A successful read is answered by the reply itself, never by a separate result; a failed one still owes an error. A result is never answered by a result.

owes_ack(CmdClassifier::Read,  true,  ErrorNumber::None);                 // false
owes_ack(CmdClassifier::Read,  true,  ErrorNumber::CommandNotSupported);  // true
owes_ack(CmdClassifier::Write, true,  ErrorNumber::None);                 // true
owes_ack(CmdClassifier::Write, false, ErrorNumber::None);                 // false

Message counters are per-source and tracked over a window rather than as a high-water mark: §5.2.4 makes msgCounter a sender-unique name, and a peer may send counters out of order. A high-water mark would drop the overtaken message as a duplicate. A datagram addressed to another device is answered DestinationUnreachable.

A payload carries exactly one command (§5.3.2); one with none or two is answered errorNumber 1 and refused whole, since a single result cannot report two outcomes. Several filters in one command are supported.

specificationVersion is checked, and a malformed one is refused — TC_SPINE_COMP_006 calls that the recommended behaviour — while tolerating the one deviation it permits, a leading v.

What a peer's address has to be

A device address is a routing key and a stored identity: the hub binds a connection to it, the engine allocates a peer record per distinct one, and every § 14a audit record names it. Two different rules apply.

What this node builds goes through the full §7.1.1.2 pattern, d:_(i:<IANA PEN>|n:<vendor>)_<unique>.

What a peer sends is checked only for what protects this node: bounded length, no control or whitespace characters, not empty. A datagram whose source fails that is discarded in silence, because there is nowhere to send an error to.

Enforcing conformance on reception would refuse evcc, which announces d:_i:EVCC_HEMS-… — the i: marker without an IANA Private Enterprise Number. A test names the non-conformant addresses in the device corpus, so a new one fails the suite.

How long a peer is given to answer

Ten seconds (§5.2.5.3), unless the feature announced longer in its detailed discovery. A client that ignored the announcement would retry against a conformant peer.

LocalFeature::with_max_response_delay declares this node's own figure. Discovery publishes it, and it is how long the engine holds a deferred write on that feature open.

When a peer says nothing at all

A resultData carrying an error is a completed exchange, and §2.6.1 forbids retrying it. For no answer at all, §2.6.2 gives the escalation path: retry after 30 seconds, then 5 minutes, then 15, then give up. RETRY_SCHEDULE holds those numbers, and the engine walks them.

Each retry goes out under a new msgCounter, since a repeated one is a duplicate a receiver drops — but the acknowledgement still arrives under the counter you were handed. SpineEvent::RequestRetried reports each retry; SpineEvent::RequestTimedOut fires only at the end, meaning an unresponsive peer, and an actor can then release what it held for that request.

The engine does not close the connection — §2.6.2's fourth step — because it owns none, and §2.6.4 says one unresponsive use case is not a reason to drop a connection carrying others. Hub passes the event up to the application.

Restricted Function Exchange

RFE is how SPINE reads and writes part of a function: a selector says which entries, an elements filter says which fields of them.

data.restrict(selectors, elements)?;                     // what a partial read answers with
rfe::apply_partial(&mut stored, update);                 // merge by identifier, element by element
data.delete_restricted(&update, selectors, elements)?;   // what a delete filter addresses

The merge rule is the part to get right. An omitted element means unchanged, all the way down the tree. A scaledNumber arriving with a bare number must keep its stored scale, or a 4.2 kW limit becomes 42 MW.

It applies to what a peer notifies, not only to what it writes. A server may notify a partial update, the ordinary shape of a subscribed measurement (IG §3.2.2). The engine keeps the merged state of every function a peer has sent, and SpineEvent::DataNotified and ReplyReceived carry data for what arrived and resolved for the merged result, as a deferred write does. The is_partial field identifies a partial update or a delete. For commissioning, wait for a complete snapshot of each required function in the current session before relying on subsequent merged updates.

A delete is filtered too, and a command may carry more than one filter. selectors choose the entries a delete addresses; elements choose the parts of them, and the entries survive. LPC UC TS §3.4.1.4's worked example is one command with two filters — the first withdraws a limit's timePeriod.endTime, the second writes its new value as a partial update — so a command's filters are applied in order. Answering only the delete removes the limit instead of making it open-ended.

Engine::write_filtered sends that shape, and the Energy Guard uses it automatically: a limit with no duration always carries the delete that withdraws the old endTime, since omitting the timePeriod would leave the previous end time in force.

Reads go the same way. Engine::read_filtered asks for part of a function, which §7.1.3 and §7.5.3 both describe: "where is your LoadControl feature?" costs a few hundred bytes instead of a whole device tree. The peer answers with a subset marked partial, and the merge keeps a narrow answer from discarding a wide one.

The XML Schemas link a data type to its selectors and elements filters only by naming convention, so the generator resolves it into a table covering 141 functions, and merge, delete and partial read are written once against that table. Which elements identify an entry is answered from the specification's own table rather than from a pattern.

A filtered request for a function the table does not cover is refused with errorNumber 8 rather than answered approximately. The table is published: which functions can be exchanged in part, generated from the same source the compiler reads.