Protocol

The section Station-Pod Communication Protocol below establishes the Station-Pod link as a request-response protocol with the Station as sole initiator, and names three conceptual message categories: commands, status queries, and events. This page defines the wire-level realization of that model: the frame layout, how a request is correlated with its response, and the concrete communication patterns built on top of that correlation. The decision for the request-response model and the decision to generate the protocol code with commsdsl are recorded in ADRs. See SYS-003 and SYS-006.

The protocol is defined as a single schema shared by the Station and every Pod, so both sides agree on the same frame layout, message set, and field encoding by construction. Schema: cocktail-maker-protocol.

Station-Pod Communication Protocol

The Station and every Pod communicate through a request-response protocol. The Station is the sole initiator of communication. A Pod never sends unsolicited commands. Every Pod is addressed by a unique identifier assigned at connection time, allowing the Station to route commands to a specific Pod and to attribute status and events back to their origin. This request-response model, including the Station’s role as sole initiator, is decided in SYS-003.

The protocol distinguishes three conceptual message categories:

  • Commands: issued by the Station to trigger an action on a Pod, e.g. dispense a given volume.

  • Status queries: issued by the Station to poll a Pod’s current state, e.g. connected, idle, dispensing, fault.

  • Events: emitted by a Pod in response to a command or an internal condition, e.g. dispensing completed, calibration done, error raised.

This section defines the protocol’s role and message categories at a conceptual level. The exact wire format, framing, and versioning strategy are defined in Framing and Versioning.

Physical Transport

The Station and Pods are physically connected via USB, using the USB CDC class to carry the protocol described above. The USB data link is hot-pluggable, so the USB cable of a Pod can be replugged while the machine runs. The Pod supply is not, so an Operator switches the machine off before connecting or disconnecting the supply of a Pod (IF-03).

The detailed rationale, trade-offs, and alternatives considered (CAN, Ethernet) behind this interface choice are out of scope for this page and are captured separately in SYS-002, since the Station/Pod split (SYS-001) was decided independently of the transport used to realize it.

Framing

Every exchange between the Station and a Pod is carried in a single frame:

Field Type Purpose

Sync

uint16 (0xabcd)

Fixed marker that lets a receiver find the start of the next frame on the raw USB CDC byte stream.

Size

uint16

Number of bytes from MsgId through Payload, used to know when a full frame has been received.

MsgId

uint16

Identifies which message the payload contains (e.g. Dispense, Ack).

TransactionId

uint16

Correlates this frame with the request it belongs to. See Transaction Correlation.

Payload

message-specific

The fields of the message identified by MsgId.

Checksum

uint16 (CRC-16)

Computed over Size through Payload. Protects the frame’s integrity on the wire.

There is no byte-stuffing or escaping layer. Framing relies on Sync, Size, and the CRC alone.

Transaction Correlation

TransactionId is not a field of any individual message. It is a transport-level field carried by every frame, regardless of which message it holds. The Station generates a TransactionId for each request it sends and reuses it for every frame that belongs to the same exchange. This includes an immediate Ack/Nak, a dedicated response, and any event that concludes a longer-running action later on. A Pod must echo the TransactionId of the request it is reacting to on every frame it sends back for that exchange. Because a TransactionId is only required to be unique among requests that are currently pending, the Station is free to reuse a value once its exchange has concluded.

Correlation by TransactionId
Figure 1. Correlation by TransactionId

How does the Station match a frame from a Pod to its request?

This is the only correlation mechanism the protocol has. There is no separate request or session identifier. TransactionId scopes exactly one request/response exchange. It does not identify any higher-level operation a caller of the protocol may be carrying out, and such an operation may itself require several such exchanges.

Communication Patterns

Every message exchange follows one of three patterns, distinguished by how many frames a Pod sends back for a single request and how far apart in time they arrive.

Request / Response

The simplest pattern: a request is answered by exactly one dedicated response message, carrying the same TransactionId. Used by Ping/Pong (keep-alive), DeviceInfoRequest/DeviceInfoResponse, and LoadCellWeightRequest/LoadCellWeightResponse. A LoadCellWeightRequest is answered by a Nak instead if the load cell can’t be read.

Request and response
Figure 2. Request and response

How does a Pod answer a request with one dedicated response?

Request / Acknowledgement

A request that only needs to confirm it was carried out is answered by the generic Ack, or Nak if it could not be executed. Nak carries an ErrorCode explaining the reason, rather than each command defining its own failure message. Used by EmergencyStop, LoadCellCalibrateWithRefWeight, LoadCellTare, and HighlightDispenser.

LoadCellTare and LoadCellCalibrateWithRefWeight take a little over a second. The Pod samples the load first, then waits until the load cell’s weight shows the result, and only then replies.

Request and acknowledgement
Figure 3. Request and acknowledgement

How does a Pod confirm a command, or refuse it?

Table 1. ErrorCode values
Value Meaning

InvalidParameter

A field of the command has a value the Pod can’t use.

DispenserNotFound

This Pod has no dispenser with the given DispenserId.

UnsupportedInCurrentState

The Pod can’t do this in its current state.

HardwareFault

An actuator or sensor failed or didn’t answer, or an EmergencyStop interrupted the action.

Busy

The dispenser is already running another action. Retry once that has ended.

NotCalibrated

The action needs a calibration that hasn’t been done yet.

InternalError

An unexpected error inside the Pod.

DispenserEmpty

Next to nothing came out of the dispenser, most likely because its bottle is empty.

NoLoadCell

This dispenser has no load cell, which is normal for some dispensers. Everything that weighs gets this, including Dispense and DispenserStartCalibration.

LoadNotSteady

The load moved while the load cell measured it. Keep the scale still and retry.

TareTooOld

A load cell calibration needs a tare of the empty scale shortly before. Tare and retry.

ImplausibleReference

The reference weight gave an implausible reading, most likely because it wasn’t on the scale.

Request / Acknowledgement / Event

Some requests trigger a physical action whose duration cannot be bounded tightly enough to hold a single response open. Dispensing a liquid and running a dispenser calibration are both examples of this. These are acknowledged immediately with Ack/Nak, and once the underlying action completes, the Pod sends a dedicated event carrying the same TransactionId as the original request. This is the mechanism that lets the Station attribute an event arriving seconds later back to the exact request that caused it, even though other exchanges may have started and finished with different transaction ids in the meantime. Used by Dispense (followed by DispenseFinished) and DispenserStartCalibration (followed by DispenserFinishedCalibrationResponse). The completion event must reuse the TransactionId of the request that triggered it.

While the action runs, the Pod sends a DispenseProgress about four times a second under the same TransactionId. It only comes between the Ack and the final reply, and it is only for display. The final reply alone holds the real amount. The Station drops it for now, so that it can’t crowd out the final reply.

Request, acknowledgement and event
Figure 4. Request, acknowledgement and event

How does a Pod report the end of a long action under the TransactionId of its request?

A Nak can still arrive in place of the event if the action fails after having been accepted, so a caller of this pattern must be prepared to receive either outcome under the same TransactionId.

DispenseFinished says how the pour ended:

Table 2. DispenseResult values
Value Meaning

Completed

The requested amount came out, within the Pod’s tolerance.

BottleEmpty

The weight stopped falling while the dispenser ran, most likely because the bottle is empty. A blocked hose looks the same.

TimedOut

The pour hit its time limit of 30 s (provisional, to be confirmed on the assembled machine) while the weight was still falling.

StillShort

All trims are used up and the amount is still below the target.

Only Completed reaches the requested amount. None of them is an error, so a pour that came up short still ends with DispenseFinished and not with a Nak.

Reply Times

The Station’s timeouts must be longer than the Pod’s worst case for each of these:

Request Allow Why

LoadCellTare, LoadCellCalibrateWithRefWeight

2 s

The Pod replies once it has finished, after a little over a second.

Dispense

35 s

The Pod stops a pour after 30 s at the latest (provisional, to be confirmed on the assembled machine) and then measures it at rest.

DispenserStartCalibration

Run time plus 3 s

The dispenser has to stop first, then the Pod measures at rest.

Ack on Dispense and DispenserStartCalibration

500 ms

The Pod reads the load cell before it starts. The longest reply measured is 2.7 ms.

LoadCellWeightRequest

500 ms

One read of the load cell. The longest reply measured is 2.6 ms.

Ack on EmergencyStop

500 ms

It can wait behind a read of the load cell. The longest reply measured is 2.6 ms.

HighlightDispenser, Ping, DeviceInfoRequest

100 ms

The longest reply measured is 4.6 ms. Ping and DeviceInfoRequest are repeated with a longer timeout.

The measured times come from a Pod’s hardware test with three other dispensers running. They include USB and the host, and the Station keeps the rest as a margin. The Station doesn’t repeat a tare, a load cell calibration, a Dispense or a DispenserStartCalibration on its own.

Load Cell Weights

LoadCellWeightResponse reports the weight relative to the load cell’s zero point, so it can be negative. LoadCellTare sets that zero point, and so does every power up of the load cell. The reading therefore says how far the weight has moved, not how full a bottle is. The Station keeps the fill level. See the Station runtime view and SYS-007.

Versioning

The schema is released with semantic version numbers. Its version attribute carries the same number as 0xMMmmpp, so 0x020100 is release 2.1.0. DeviceInfoResponse starts with ProtocolVersion in that form, and it stays the first field in every release.

The Station accepts exactly the release it was built against. A Pod on another release stays unused, and the Station names both releases. A Pod on 2.0.0 has no ProtocolVersion yet, so its DeviceInfoResponse doesn’t decode at all. The Station then only sees no answer and logs a hint that the Pod may speak another release.

Messages

Message Direction Category Purpose

Ping

Station → Pod

Request / Response

Checks that the Pod is alive.

Pong

Pod → Station

Request / Response

The Pod’s reply to a Ping.

Ack

Pod → Station

Request / Acknowledgement

The Pod accepted a command. For a command that reports its end with a message of its own, this only says that the action has started. For any other command it says that the command has been carried out.

Nak

Pod → Station

Request / Acknowledgement

The Pod refused a command or couldn’t finish it, with an ErrorCode as the reason.

DeviceInfoRequest

Station → Pod

Request / Response

Asks a Pod to describe itself.

DeviceInfoResponse

Pod → Station

Request / Response

Protocol release, hardware revision, firmware version, number of pumps and valves, and the Pod’s name.

EmergencyStop

Station → Pod

Request / Acknowledgement

Stops every pump and valve of the Pod at once. Every Dispense and DispenserStartCalibration still running ends with a Nak. A running tare or load cell calibration carries on.

LoadCellCalibrateWithRefWeight

Station → Pod

Request / Acknowledgement

Calibrates a dispenser’s load cell with a known weight resting on the scale. The empty scale must have had a LoadCellTare shortly before. The calibration stays on the load cell across power cycles.

LoadCellTare

Station → Pod

Request / Acknowledgement

Makes the current load the zero point of a dispenser’s load cell. The load must stay still meanwhile.

LoadCellWeightRequest

Station → Pod

Request / Response

Asks for the current weight on a dispenser’s load cell.

LoadCellWeightResponse

Pod → Station

Request / Response

The current weight relative to the zero point, which can be negative.

DispenserStartCalibration

Station → Pod

Request / Acknowledgement / Event

Runs a dispenser for a set time and measures what came out with its load cell. The run time must be greater than 0 and at most 30 s (provisional, to be confirmed on the assembled machine). The load cell must already be calibrated, and real liquid comes out. After a Nak the previous calibration stays in place.

DispenserFinishedCalibrationResponse

Pod → Station

Request / Acknowledgement / Event

Reports the amount that came out, measured at rest. The Pod uses the new calibration from now on and keeps it across power cycles.

HighlightDispenser

Station → Pod

Request / Acknowledgement

Shows a light effect on a dispenser’s LEDs. A duration of 0 keeps it on until the next HighlightDispenser for this dispenser.

Dispense

Station → Pod

Request / Acknowledgement / Event

Pours a given amount of liquid from a dispenser. The amount must be greater than 0.

DispenseFinished

Pod → Station

Request / Acknowledgement / Event

Reports the amount poured, measured at rest, and how the pour ended as a DispenseResult.

DispenseProgress

Pod → Station

Request / Acknowledgement / Event

The amount so far during a pour or a calibration run. Never negative and only for display.