Skip to content

Commit ae0a721

Browse files
committed
Clarify request-reply contract
1 parent 7eb1aa5 commit ae0a721

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

BinaryProtocol-8bit.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ else
255255

256256
### Commands
257257

258-
The device that implements this Harp Protocol receives `Write` and `Read` commands from the controller, and replies with a copy of the message, timestamped with the hardware time at which the command was applied.
258+
The device that implements this Harp Protocol receives `Write` and `Read` commands from the controller, and replies with a copy of the message, timestamped with the hardware time at which the command was applied. This behavior is core to the protocol and is expected to be implemented by all devices that use it. As a rule of thumb, for each `Write` or `Read` command, a single reply message should be returned from the device. The message should be emitted from the same register that the command was issued to. It should be noted that the payload of the returned value might be different from the one issued by the command, as the device can operate/transform the issued `Write` command. ([see "Register Polymorphism" section below](#register-polymorphism)).
259+
260+
> Exceptions to the previous contract are possible but should be avoided. The single supported exception is the `R_OPERATION_CTRL` (via **DUMP [Bit 3]**) that allows the controller to request a dump of all registers in the device. In this case, the device should reply with a single `Write` message from `R_OPERATION_CTRL`, honoring the previous contract, but will it also emit a volley of `Read` messages, one for each register in the device.
259261
260262
Some Harp Messages are shown below to demonstrate the typical usage of the protocol between a device and a controller. Note that timestamp information is usually omitted in messages sent from the controller to the device, since actions are expected to run as soon as possible.
261263

@@ -273,20 +275,52 @@ We will use the following abbreviations:
273275

274276
The timestamp information in the [RPL] represents the time when the register with [Address] was updated.
275277

276-
### Read Message
278+
#### Read Message
277279

278280
- [CMD] **Controller**: `1` `4` `Address` `Port` `PayloadType` `Checksum`
279281
- [RPL] **Device**: `1` `Length` `Address` `Port` `PayloadType` `Timestamp<T>` `Checksum` OK
280282
- [RPL] **Device**: `9` `10` `Address` `Port` `PayloadType` `Timestamp<T>` `Checksum` ERROR
281283

282284
The timestamp information in the [RPL] represents the time when the register with [Address] was read.
283285

284-
### Event message
286+
#### Event message
285287

286288
- [EVT] **Device**: `3` `Length` `Address` `Port` `PayloadType` `Timestamp<T>` `Checksum` OK
287289

288290
The timestamp information in [EVT] represents the time when the register with [Address] was read.
289291

292+
### Intended Usage
293+
294+
#### Register polymorphism
295+
296+
297+
While it is possible to have different types of data in the same register, we **STRONGLY** discourage this practice. The protocol was designed to be as simple as possible, and having different types of data in the same register would make the parsing of the messages unnecessary more complex. As a rule, each register should: (1) have a single data type (e.g. `U8`) for all message types (`Read`, `Write`, `Event`), (2) the payload should have the same "function"/"meaning" regardless of the message type (see examples below), and (3) the payload data should be of the same size for all message types.
298+
It should be noted that this guide doesnt necessarly mean that the payload issued by a `Write` message should be the same as the one issued by a `Read` message, as the device can operate/transform the issued `Write`.
299+
300+
301+
> **Examples**
302+
>
303+
> Consider the following register:
304+
>
305+
>```
306+
> CameraFrequency:
307+
> - Address: 32
308+
> - Type: U8
309+
> - Access: Raad, Write
310+
> - Description: Sets the frequency of the camera in Hz.
311+
>```
312+
>
313+
> DO NOT ❌
314+
>
315+
> - Return the frequency in U16 for a `Read` command and the frequency in U8 for a `Write` command. (i.e. Share the same data type.)
316+
> - Return the frequency in Hz for a `Read` command and the period in seconds for a `Write` command. (i.e. share the same function/meaning.)
317+
>
318+
> DO ✅
319+
>
320+
> - Return the frequency in U8 for both a `Read` and `Write` command.
321+
> - Return the frequency in Hz for both a `Read` and a `Write` command.
322+
> - `Write` a value of `101` to set the frequency, but both `Read` and `Write` return the frequency of 100Hz. This behavior is perfectly acceptable as the device might not be able to set the frequency to the exact value requested by the controller, and instead returns the value that was set.
323+
290324
---
291325
292326
## Release notes:
@@ -323,4 +357,8 @@ The timestamp information in [EVT] represents the time when the register with [A
323357
- v1.4.1
324358
* Remove table of contents to avoid redundancy with doc generators.
325359
* Avoid using verbatim literals in titles.
326-
* Change device naming to Controller and Device.
360+
* Change device naming to Controller and Device.
361+
362+
- v1.4.2
363+
* Clarify request-reply contract.
364+
* Discourage the use of polymorphic register behavior.

0 commit comments

Comments
 (0)