1 -module(x_plane_datum).
3 -include("x_plane_datum_defaults.hrl").
4 -include("include/x_plane_data.hrl").
15 [ of_bin/1 % Use default max index
16 , of_bin/2 % Specify max index
19 -type parsing_error() ::
20 {block_structure_invalid, binary()}
21 | {block_index_byte_out_of_range, anonymous()}
43 #x_plane_datum_speeds{}
44 | #x_plane_datum_pitch_roll_heading{}
45 | #x_plane_datum_lat_lon_alt{}
49 {non_neg_integer() , anonymous()}
50 | {label() , identified()}
53 -spec of_bin(binary()) ->
54 hope_result:t(t(), parsing_error()).
55 of_bin(<<Block/binary>>) ->
56 of_bin(Block, ?DEFAULT_MAX_INDEX).
58 -spec of_bin(binary(), non_neg_integer()) ->
59 hope_result:t(t(), parsing_error()).
60 of_bin(<<Block/binary>>, MaxIndex) ->
61 case anonymous_of_bin(Block, MaxIndex)
63 IdentifiedOrIndexed = identify_or_index(Anonymous),
64 {ok, IdentifiedOrIndexed}
69 -spec anonymous_of_bin(binary(), non_neg_integer()) ->
70 hope_result:t(anonymous(), parsing_error()).
72 << Index:32/little-integer
84 Anonymous = {Index, V1, V2, V3, V4, V5, V6, V7, V8},
85 if Index > 0 andalso Index =< MaxIndex ->
88 {error, {block_index_byte_out_of_range, Anonymous}}
90 anonymous_of_bin(<<Block/binary>>, _) ->
91 % This case shouldn't be possible with a correct packet length, but we want to
92 % allow for possibility of using this module independently of it's parent,
94 {error, {block_structure_invalid, Block}}.
96 -spec identify_or_index(anonymous()) ->
98 identify_or_index({3, V1, V2, V3, V4, _, V6, V7, V8}) ->
100 #x_plane_datum_speeds
111 identify_or_index({17, V1, V2, V3, V4, _, _, _, _}) ->
113 #x_plane_datum_pitch_roll_heading
119 {pitch_roll_heading, Datum};
120 identify_or_index({20, V1, V2, V3, V4, V5, V6, V7, V8}) ->
122 #x_plane_datum_lat_lon_alt
132 {lat_lon_alt, Datum};
133 identify_or_index({Index, _, _, _, _, _, _, _, _}=Anonymous) ->