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 =======================
10 -include_lib("include/x_plane_data.hrl").
13 {ok, Socket} = gen_udp:open(Port, [binary, {active, false}]),
14 {ok, {_, _, <<XPlaneDataPacket/binary>>}} = gen_udp:recv(Socket, 0),
15 {ok, XPlaneData} = x_plane_data:of_bin(XPlaneDataPacket),
17 % Currently there're 133 possible data types sent by X-Plane 10, of which
18 % I've identified and labeled only some of. See x_plane_datum:t() type for
19 % what is currently labeled.
20 % The types I've not yet labeled are in the format specified by
21 % x_plane_datum:anonymous() and can be looked-up by their index number.
23 % Find labeled data types
24 {some, #x_plane_datum_speeds
25 { vind_kias = VindKias
26 , vind_keas = VindKeas
27 , vtrue_ktas = VtrueKtas
28 , vtrue_ktgs = VtrueKtgs
30 , vtrue_mphas = VtrueMphas
31 , vtrue_mphgs = VtrueMphgs
33 } = hope_kv_list:get(XPlaneData, speeds),
35 {some, #x_plane_datum_pitch_roll_heading
36 { pitch_deg = PitchDeg
38 , hding_true = HdingTrue
39 , hding_mag = HdingMag
41 } = hope_kv_list:get(XPlaneData, pitch_roll_heading),
43 {some, #x_plane_datum_lat_lon_alt
46 , alt_ftmsl = AltFtmsl
47 , alt_ftagl = AltFtagl
50 , lat_south = LatSouth
53 } = hope_kv_list:get(XPlaneData, lat_lon_alt),
55 % Find an unlabled data type
56 {some, {10, V1, V2, V3, V4, V5, V6, V7, V8}} = hope_kv_list:get(XPlaneData, 10),
58 % Attempt to find a data type that was not included in current packet
59 none = hope_kv_list:get(XPlaneData, 130),
60 none = hope_kv_list:get(XPlaneData, 67),
65 Note: you can, of course, use any other method to search a `[{K, V}]` list
66 (which is how `x_plane_data:t()` is structured), such as:
67 `proplists:get_value/2`, `lists:keyfind/3`, etc., but I prefer the API of
68 `hope_kv_list`, so I used that.
71 Data format references
72 ----------------------
74 - http://b58.svglobe.com/data.html
75 - http://www.nuclearprojects.com/xplane/xplaneref.html