b417370d307e93e9da7e108ead2dc5a761feed72
[erlang-x-plane-data.git] / README.md
1 [![Build Status](https://travis-ci.org/ibnfirnas/erlang-x_plane_data.svg?branch=master)](https://travis-ci.org/ibnfirnas/erlang-x_plane_data)
2
3 X-Plane UDP data parser
4 =======================
5
6 Examples
7 --------
8
9 ### Receive data packet
10
11 ```erlang
12 {ok, Socket} = gen_udp:open(Port, [binary, {active, false}]),
13 {ok, {_, _, <<XPlaneDataPacket/binary>>}} = gen_udp:recv(Socket, 0),
14 ```
15
16 ### Parse data packet
17
18 ```erlang
19 {ok, {64=Index, GroupsRaw}=DataRaw} = x_plane_data_raw:of_bin(XPlaneDataPacket),
20 ```
21
22 ### Access parsed data
23
24 #### Raw
25
26 At this stage, only the structure of the packet was parsed. No attempt at
27 interpreting the values have been made:
28
29 ```erlang
30 % Speeds are in group 3
31 {3, Speeds} = lists:keyfind(3, 1, GroupsRaw),
32 { VindKias
33 , VindKeas
34 , VtrueKtas
35 , VtrueKtgs
36 , _
37 , VindMph
38 , VtrueMphas
39 , VtrueMphgs
40 } = Speeds,
41
42 % Pitch roll and headings values are in group 17
43 {17, PitchRollHeadings} = lists:keyfind(17, 1, GroupsRaw),
44 { PitchDeg
45 , RollDeg
46 , HdingTrue
47 , HdingMag
48 , _
49 , _
50 , _
51 , _
52 } = PitchRollHeadings,
53 ```
54
55 #### Named
56
57 Here we identify what each of the numbered groups mean in a given X-Plane
58 version. Right now only X-Plane 10 is supported and I only identified 3 groups
59 so far:
60
61 - index: `3` , name: `speeds`
62 - index: `17`, name: `pitch_roll_heading`
63 - index: `20`, name: `lat_lon_alt`
64
65 Unidentified groups (with index other than what is listed above) will be
66 absent from the list of named groups (think of `x_plane_data_named:of_raw/1` as
67 a filter), so you'll have to access their raw version, if needed.
68
69 ##### Identify
70 ```erlang
71 {ok, {x_plane_data_v10, GroupsNamed}} = x_plane_data_named:of_raw(DataRaw),
72 ```
73
74 ##### Access
75 ```erlang
76 -include_lib("x_plane_data_group_lat_lon_alt.hrl").
77 -include_lib("x_plane_data_group_pitch_roll_heading.hrl").
78 -include_lib("x_plane_data_group_speeds.hrl").
79
80 ...
81
82 {speeds, #x_plane_data_group_speeds
83 { vind_kias = VindKias
84 , vind_keas = VindKeas
85 , vtrue_ktas = VtrueKtas
86 , vtrue_ktgs = VtrueKtgs
87 , vind_mph = VindMph
88 , vtrue_mphas = VtrueMphas
89 , vtrue_mphgs = VtrueMphgs
90 }
91 } = lists:keyfind(speeds, 1, GroupsNamed),
92
93 {pitch_roll_heading, #x_plane_data_group_pitch_roll_heading
94 { pitch_deg = PitchDeg
95 , roll_deg = RollDeg
96 , hding_true = HdingTrue
97 , hding_mag = HdingMag
98 }
99 } = lists:keyfind(pitch_roll_heading, 1, GroupsNamed),
100 ```
101
102 Data format references
103 ----------------------
104
105 - http://b58.svglobe.com/data.html
106 - http://www.nuclearprojects.com/xplane/xplaneref.html
This page took 0.046904 seconds and 4 git commands to generate.