You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: BinaryProtocol-8bit.md
+7-148Lines changed: 7 additions & 148 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,158 +104,14 @@ This bit indicates whether the [`Payload`] represents fractional values. If the
104
104
105
105
If the bit is set, indicates that the [`Payload`] contains integers with signal.
106
106
107
-
> **Note**
108
-
>
109
-
> The bits [`IsFloat`] and [`IsSigned`] must never be set simultaneously.
110
-
111
-
### Payload (? bytes)
112
-
113
-
The content of the Harp Message.
114
-
115
-
If the [`HasTimestamp`] flag is set, the following optional fields are present at the beginning of the message payload:
116
-
117
-
#### Seconds (4 bytes)
118
107
119
-
Contains the number of seconds (`U32`) of the Harp Timestamp clock. This field is optional. In order to indicate that this field is available, the bit [`HasTimestamp`] in the field [`PayloadType`] needs to be set.
120
-
121
-
#### Microseconds (2 bytes)
122
-
123
-
It contains the fractional part of the Harp Timestamp clock in microseconds (`U16` containing the number of microseconds divided by 32).
108
+
### Commands
124
109
125
-
This field is optional. In order to indicate that this field is available, the bit [`HasTimestamp`] in the field [`PayloadType`] needs to be set.
110
+
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.
126
111
127
112
> **Note**
128
113
>
129
-
> The full timestamp information can thus be retrieved using the formula:
The sum of all bytes (`U8`) contained in the Harp Message.
135
-
The receiver of the message should calculate the checksum and compare it with the received. If they don’t match, the Harp Message should be discarded.
136
-
137
-
---
138
-
139
-
## Features and Code Examples
140
-
141
-
Some of the fields described on the previous chapter have special features. These are presented next.
142
-
143
-
### MessageType and ErrorFlag
144
-
145
-
The field [`Command`] has an Error flag on the 4th least significant bit. When this bit is set it means that an error has occured.
146
-
Examples of possible errors cane be:
147
-
148
-
1. The controller tries to read from a register that doesn’t exist;
149
-
2. The controller tries to write invalid data to a certain register;
150
-
3. The [`PayloadType`] doesn’t match the target register specification.
151
-
152
-
A simple code in C to check for error will be:
153
-
154
-
```C
155
-
int errorMask = 0x08;
156
-
157
-
if (Command & errorMask)
158
-
{
159
-
printf(“Error detected.\n”);
160
-
}
161
-
```
162
-
163
-
### Harp Message Length
164
-
165
-
If one byte is not enough to express the length of the Harp Message, use [`Length`] equal to 255 and add after an unsigned 16 bits word with the Harp Message length.
166
-
167
-
Replace the [`Length`] with:
168
-
[255] (1 byte) [`ExtendedLength`] (2 bytes)
169
-
170
-
### Parsing PayloadType
171
-
172
-
For the definition of the `PayloadType` types, a `C#` code snippet is presented.
173
-
174
-
Note that the time information can appear without an element Timestamp<>.
175
-
176
-
```C#
177
-
int isUnsigned = 0x00;
178
-
int isSigned = 0x80;
179
-
int isFloat = 0x40;
180
-
int hasTimestamp = 0x10;
181
-
182
-
enum PayloadType
183
-
{
184
-
U8 = (isUnsigned | 1),
185
-
S8 = (isSigned | 1),
186
-
U16 = (isUnsigned | 2),
187
-
S16 = (isSigned | 2),
188
-
U32 = (isUnsigned | 4),
189
-
S32 = (isSigned | 4),
190
-
U64 = (isUnsigned | 8),
191
-
S64 = (isSigned | 8),
192
-
Float = (isFloat | 4),
193
-
Timestamp = hasTimestamp,
194
-
TimestampedU8 = (hasTimestamp | U8),
195
-
TimestampedS8 = (hasTimestamp | S8),
196
-
TimestampedU16 = (hasTimestamp | U16),
197
-
TimestampedS16 = (hasTimestamp | S16),
198
-
TimestampedU32 = (hasTimestamp | U32),
199
-
TimestampedS32 = (hasTimestamp | S32),
200
-
TimestampedU64 = (hasTimestamp | U64),
201
-
TimestampedS64 = (hasTimestamp | S64),
202
-
TimestampedFloat = (hasTimestamp | Float)
203
-
}
204
-
```
205
-
206
-
The field `PayloadType` has a flag on the 5th least significant bit that indicates if the time information is available on the Harp Message. The existence of this flag is useful to know if the fields [`Seconds`] and [`Microseconds`] are present on the Harp Message.
207
-
In `C` one can check if the time information is avaible by using the following snippet:
208
-
209
-
```C
210
-
int hasTimestamp = 0x10;
211
-
212
-
if (PayloadType & hasTimestamp )
213
-
{
214
-
printf(“The time information is available on the Harp Message’s Payload.\n”);
215
-
}
216
-
```
217
-
218
-
### Using Checksum to validate communication integrity
219
-
220
-
The [`Checksum`] field is the sum of all bytes contained in the Harp Message. The receiver of the message should calculate the checksum and compare it with the received. If they don’t match, the Harp Message should be discarded.
221
-
Example on how to calculate the [`Checksum`] in C language:
222
-
223
-
```C
224
-
unsignedchar Checksum = 0;
225
-
int i = 0;
226
-
for (; i < Length + 1; i++ )
227
-
{
228
-
Checksum += HarpMessage(i);
229
-
}
230
-
```
231
-
232
-
### Parsing [Payload] with Arrays
233
-
234
-
The [`Payload`] element can contain a single, or an array of values of the same type. The first step to parse these payloads is to first find the number of values contained on the [`Payload`] element. This can be done using the following `C` code example:
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.
114
+
> 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.
259
115
260
116
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.
261
117
@@ -323,4 +179,7 @@ The timestamp information in [EVT] represents the time when the register with [A
323
179
- v1.4.1
324
180
* Remove table of contents to avoid redundancy with doc generators.
0 commit comments