====== Habpack Binary Protocol ====== This page details the [[https://msgpack.org/|msgpack]] based binary protocol. Habpack uses msgpack to encode the binary data, and defines how msgpack is used to encode telemetry, and defines IDs for telemetry fields. Encoders should pick the smallest type within the correct family. eg. '112' can be encoded as an unsigned int using the 'positive fixnum' type, for an encoded size of 1 byte. Unsigned integers are always assumed to be positive. This means that using integers can scale the storage required to the value being transmitted, while floats maintain a constant size (5 bytes for 32b float). See the msgpack spec for more details: [[https://github.com/msgpack/msgpack/blob/master/spec.md#type-system|msgpack spec -> type system]] ===== Basic Structure ===== A single telemetry string is a msgpack map. Each telemetry field then consists of a key which defines what that field is, and a value field. For efficiency reasons, each key is usually a 7bit unsigned int, and the list of keys is defined in the section below. An example packet is as follows: { 0:”CALLSIGN”, 2:12:56:14, 3:[52.33, -0.3543, 12320], 20:8, … } * { .... } means msgpack map array * 0:123 means a map entry with key 0 and data 123 * [..., ..., ...] means an array It should be noted that the datatype (eg string, integer etc) is handled by msgpack. As a result, the decoder should see what datatype has been sent, and handle the data accordingly. ===== Telemetry field IDs ===== A list of reserved Map IDs is suggested below to standardise parsing of commonly used telemetry fields without requirement of a payload-doc, eg. for embedded & offline receivers. This list is intended to be expanded over time as new requirements develop. Core: * 0: callsign (string or unsigned integer) (integer converted to string representation for habitat upload) * 1: sentence id (unsigned integer) * 2: time (unsigned integer seconds past midnight UTC, or unsigned integer unix epoch seconds) * 3: position (2 or 3 element array of signed integers: [lat, long, ]. 1e-7 of a degree; meters) * 4: number of gnss satellites (unsigned integer) * 5: gnss lock [0: none, 1: time, 2: 2D, 3: 3D, 4: 3D+SBAS] (unsigned integer) * 6: voltage (float as Volts or signed integer as milli-volts) Environmental: * 10: Internal temperature (float as degrees C or signed integer as milli-degrees C) * 11: External temperature (float as degrees C or signed integer as milli-degrees C) * 12: pressure (float as bar, or unsigned integer as milli-bar) * 13: relative humidity (float or unsigned integer as relative humidity percentage) * 14: absolute humidity (float as g/m^3, or unsigned integer as milligrams/m^3) Calling Beacon: * 20: downlink frequency, for use in calling channel (unsigned integer as Hz) * 21: ID of common downlink LoRa Mode (unsigned integer) * 22: custom downlink LoRa: Implicit (unsigned integer) * 23: custom downlink LoRa: Error Coding (unsigned integer) * 24: custom downlink LoRa: Bandwidth (unsigned integer) * 25: custom downlink LoRa: Spreading Factor (unsigned integer) * 26: custom downlink LoRa: Low Datarate Optimise (unsigned integer) Uplink: * 30: total uplinked messages (unsigned integer) Landing/Flight Predictions: * 40: predicted time (unsigned integer seconds past midnight UTC, or unsigned integer unix epoch seconds) * 41: predicted position (2 or 3 element array of signed integers: [lat, long, ]. 1e-7 degree; meters) Multi-position: * 60: Multi-position position-diff scaling factor (unsigned integer) * 61: Multi-position altitude-diff scaling factor (unsigned integer) * 62: Multi-position array of positions (each: 2 or 3 element array of signed integers: [lat, long, ]. 1e-7 degree; meters) As msgpack handles datatypes, arrays can be used to send multiple entries for one field. For example, if there are two external temperature sensors, this can be sent as 11:[-40.5,-39,1] Types 6,10,11,12,13,14 can be an array of legal values to represent more than one field. ==== Current RPi Decoder Implementation ==== For bodging habitat upload compatibility, values are re-encoded into a UKHAS-compatible RTTY string ($$...*), with fields ordered by map ID ascending, and array index ascending when multiple values exist. eg. "$$,,