Breadcrumbs

Custom binary protocol

The custom binary protocol is a flexible format designed to store binary data of varying lengths within a defined limit.

Data:

  • Custom data

Format:

<q><N><T><var0><var1>…<varN><cs>

Custom binary protocol description

FIELD N.

FIELD

DESCRIPTION

UNIT

TYPE

NOTE

Byte 0

q

message header ('q' or 'Q')

-

string

If data is invalid or unstable (MAIN_OK = 0 in health monitoring system ), the header is replaced with 'Q', while the rest of the message remains unchanged.

Byte 1

N

length of message

-

U8

The number of bytes in the frame after length: T,var0,var1,…,varN,cs.

Byte 2

T

token

-

U8

A user adjustable number that helps identify or label the message format. Range: [10,100].

Byte 3-N

varN

data message N

-

U8 / U32 / I32 / Single / Double

Selected data from output variable list .

Big-endian: Data variables consisting of multiple bytes are transmitted with MSB first.

Byte N+1

cs

checksum

-

U8

XOR of all bytes between token and checksum.

Example:

A custom binary frame with example data, including roll, pitch, and heading (in that order), is shown below in hexedecimal format.

<71><0D><18> <3D><8F><EA><E4> <BE><D4><A1><E9> <43><97><F6><0F> <AD>

Byte 0

Byte 1

Byte 2

Byte 3-6

Byte 7-10

Byte 11-14

Byte 15

71

0D

18

3D 8F EA E4

BE D4 A1 E9

43 97 F6 0F

AD

Decoded values:

By using hex-to-decimal conversion and the IEEE 754 formula, we can decode the values.

  • Byte 0

    • Raw value: 71, decoded value: q (stable data).

  • Byte 1

    • Raw value: 0D, decoded value: 3 x number of bytes (per data message) + 1 (token) = 3 x 4 + 1 = 13 = 0D (hexadecimal).

  • Byte 2

    • Raw value: 18, decoded value: 18 (hexadecimal) = 24 (decimal). User selected token associated with this configuration.

  • Byte 3-6 (roll)

    • Hex to binary: 3D 8F EA E4 = 0011 1101 1000 1111 1110 1010 1110 0100.

    • Roll value = (-1)s x 1.M x 2(E-127) = (-1)0 x 1.000111111101010111001002 x 2(123−127) = 1.124225616 x 2-4 = 0.0702641.

    • Due to rounding errors, the final roll angle is 0.07 degrees.

Bit position

Component

Extracted bits

Bit 1

Sign (S)

0 (positive)

Bits 2-9

Exponent (E)

01111011 (decimal: 123)

Bits 10-32

Mantissa (M)

00011111110101011100100

  • Byte 7-10 (pitch)

    • Hex to binary: BE D4 A1 E9 = 1011 1110 1101 0100 1000 0001 1110 1001.

    • Pitch value = (-1)s x 1.M x 2(E-127) = (-1)1 x 1.101010010000001111010012 x 2(125−127) = -1.64006 x 2-2 = −0.410015.

    • Due to rounding errors, the final pitch angle is -0.41 degrees.

Bit position

Component

Extracted bits

Bit 1

Sign (S)

1 (negative)

Bits 2-9

Exponent (E)

01111101 (decimal: 125)

Bits 10-32

Mantissa (M)

10101001000000111101001

  • Byte 11-14 (heading)

    • Hex to binary: 43 97 F6 0F = 0100 0011 1001 0111 1111 0110 0000 1111.

    • Heading value = (-1)s x 1.M x 2(E-127) = (-1)0 x 1.001011111110110000011112 x 2(135−127) = 1.18629 x 28 = 303.69024.

    • Due to rounding errors, the final heading angle is 303.69 degrees.

Bit position

Component

Extracted bits

Bit 1

Sign (S)

0 (positive)

Bits 2-9

Exponent (E)

10000111 (decimal: 125)

Bits 10-32

Mantissa (M)

00101111111011000001111

  • Byte 15 (checksum)

    • Raw value: AD, hexadecimal value created from XOR operations of all bytes between token and checksum.


Note

The custom binary protocol follows big-endian format: MSB is stored at the lowest memory address, followed by the LSB.