1 -module(x_plane_data_raw).
16 -type parsing_error() ::
21 -type group_index() ::
24 -type group_values() ::
36 {group_index(), group_values()}.
38 % Packet index byte. Essentially a schema version.
48 -define(BYTE_SIZE_OF_EACH_BLOCK, 36).
49 -define(PACKET_HEADER, "DATA").
51 -spec of_bin(binary()) ->
53 | {error, parsing_error()}
55 of_bin(<<?PACKET_HEADER, _:8/integer, ContiguousBlocks/binary>>)
56 when byte_size(ContiguousBlocks) rem ?BYTE_SIZE_OF_EACH_BLOCK =/= 0 ->
57 {error, packet_bad_length};
58 of_bin(<<?PACKET_HEADER, Index:8/integer, ContiguousBlocks/binary>>) ->
59 Groups = [group_of_bin(B) || B <- blocks_split(ContiguousBlocks)],
60 {ok, {Index, Groups}};
61 of_bin(<<_/binary>>) ->
62 {error, packet_bad_header}.
64 -spec blocks_split(binary()) ->
68 blocks_split(<<Block:?BYTE_SIZE_OF_EACH_BLOCK/bytes, Blocks/binary>>) ->
69 [Block | blocks_split(Blocks)].
71 -spec group_of_bin(binary()) ->
74 << Index:32/little-integer
85 Values = {V1, V2, V3, V4, V5, V6, V7, V8},