Fixposition SDK 0.0.0-heads/main-0-gd0a6ce2
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
Parser FP_B routines and types

API: fpsdk_common/parser/fpb.hpp and fpsdk::common::parser::fpb

Framing:

The structure of a FP_B message (frame) is:

Offs Size Type Content
0 1 uint8_t Sync 1: f = 102 = 0x66 = 0b0110'0110
1 1 uint8_t Sync 1: ! = 33 = 0x21 = 0b0010'0001
2 2 uint16_t Message ID (message_id), 1...65534
4 2 uint16_t Payload size (payload_size)
6 2 uint16_t Monotonic time [ms] (message_time), overflows/wraps around at ~65s
8… Payload
8 + payload_size 4 uint32_t Checksum

The checksum is a 32 bit cyclic redundancy check (CRC) with the polynomial 0x32c00699. See Koopman's CRC polynomial zoo at http://users.ece.cmu.edu/~koopman/crc/crc32.html for details.

Payload:

The payload encoding can be:

  • Fixed structure (for example, FP_B-MEASUREMENTS) using little-endian signed and unsigned integers of 8, 16, 32 or 64 bits, as well as IEEE 754 single (32 bits) or double (64 bits) precision.
  • Serialised data of a t.b.d. interface description language (e.g. Protobuf, Capn' Proto, Flatbuffers, ....)

Example:

A short FP_B frame with the bytes in order they appear on the wire:

First byte                                   Last byte
|                                            |
66 21 34 12 04 00 21 43 01 02 03 04 61 c4 c5 9c
^^ ^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^ ^^^^^^^^^^^
|  |  |     |     |     |           |
|  |  |     |     |     |           CRC (= 0x9cc5c461)
|  |  |     |     |     Payload (= [ 0x01, 0x02, 0x03, 0x04 ])
|  |  |     |     Message time (= 0x4321 = 17185 = 17.185s)
|  |  |     Payload size = (=x0004 = 4)
|  |  Message ID (= 0x1234)
|  Sync 2
Sync 1

Fixed payload definition:

A short and incomplete guideline:

  • All fields must be aligned
  • Padding must be explicitly added as reserved fields: e.g. uint8_t reserved[3] //!< Reserved for future use. Set to 0.
  • Fields can only be basic types (no enums!)
  • Decoding must be doable with a single pass. I.e. repeated parts must follow static parts.
  • Repeated parts of the payload mus have a num_foo field in the static part.
  • For enums the value 0 must always be "unspecified" or "unknown"
  • Don't use bitfields. Waste some space (e.g. uint8_t for a bool, instead of a bit in a bitfield)
  • Values that may or may not be valid must be accompanied by a foo_valid flag field.
  • No strings! Not ever. With some exceptions, probably... :-)
  • ...and more...