1 [![Build Status](https://travis-ci.org/ibnfirnas/erlang-x_plane_data.svg?branch=master)](https://travis-ci.org/ibnfirnas/erlang-x_plane_data)
3 X-Plane UDP data parser
4 =======================
9 ### Receive data packet
12 {ok, Socket} = gen_udp:open(Port, [binary, {active, false}]),
13 {ok, {_, _, <<XPlaneDataPacket/binary>>}} = gen_udp:recv(Socket, 0),
19 {ok, {64=Index, GroupsRaw}=DataRaw} = x_plane_data_raw:of_bin(XPlaneDataPacket),
22 ### Access parsed data
26 At this stage, only the structure of the packet was parsed. No attempt at
27 interpreting the values have been made:
30 % Speeds are in group 3
31 {3, Speeds} = lists:keyfind(3, 1, GroupsRaw),
42 % Pitch roll and headings values are in group 17
43 {17, PitchRollHeadings} = lists:keyfind(17, 1, GroupsRaw),
52 } = PitchRollHeadings,
57 Here we identify what each of the numbered groups mean in a given X-Plane
58 version. Right now only X-Plane 10 (packet index 64) is supported and I only
59 identified 3 groups so far:
61 | packet index | group index | group name |
62 |--------------|-------------|----------------------|
64 | 64 | 17 | `pitch_roll_heading` |
65 | 64 | 20 | `lat_lon_alt` |
67 Unidentified groups (with index other than what is listed above) will be
68 absent from the list of named groups (think of `x_plane_data_named:of_raw/1` as
69 a filter), so you'll have to access their raw version, if needed.
73 {ok, {x_plane_data_v10, GroupsNamed}} = x_plane_data_named:of_raw(DataRaw),
78 -include_lib("x_plane_data_group_lat_lon_alt.hrl").
79 -include_lib("x_plane_data_group_pitch_roll_heading.hrl").
80 -include_lib("x_plane_data_group_speeds.hrl").
84 {speeds, #x_plane_data_group_speeds
85 { vind_kias = VindKias
86 , vind_keas = VindKeas
87 , vtrue_ktas = VtrueKtas
88 , vtrue_ktgs = VtrueKtgs
90 , vtrue_mphas = VtrueMphas
91 , vtrue_mphgs = VtrueMphgs
93 } = lists:keyfind(speeds, 1, GroupsNamed),
95 {pitch_roll_heading, #x_plane_data_group_pitch_roll_heading
96 { pitch_deg = PitchDeg
98 , hding_true = HdingTrue
99 , hding_mag = HdingMag
101 } = lists:keyfind(pitch_roll_heading, 1, GroupsNamed),
104 Data format references
105 ----------------------
107 - http://b58.svglobe.com/data.html
108 - http://www.nuclearprojects.com/xplane/xplaneref.html