Fix record label typo: lat_west -> lon_west
[erlang-x-plane-data.git] / README.md
CommitLineData
3549a33a
SK
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
3X-Plane UDP data parser
4=======================
d014d93e 5
64c0d81f
SK
6Example
7-------
8
9```erlang
10-include_lib("include/x_plane_data.hrl").
11
12main(Port) ->
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),
16
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.
22
8892b9af
SK
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
29 , vind_mph = VindMph
30 , vtrue_mphas = VtrueMphas
31 , vtrue_mphgs = VtrueMphgs
32 },
33 } = hope_kv_list:get(XPlaneData, speeds),
34
35 {some, #x_plane_datum_pitch_roll_heading
36 { pitch_deg = PitchDeg
37 , roll_deg = RollDeg
38 , hding_true = HdingTrue
39 , hding_mag = HdingMag
40 },
41 } = hope_kv_list:get(XPlaneData, pitch_roll_heading),
42
43 {some, #x_plane_datum_lat_lon_alt
44 { lat_deg = LatDeg
45 , lon_deg = LonDeg
46 , alt_ftmsl = AltFtmsl
47 , alt_ftagl = AltFtagl
48 , on_runwy = OnRunwy
49 , alt_ind = AltInd
50 , lat_south = LatSouth
9101c998 51 , lon_west = LatWest
8892b9af
SK
52 },
53 } = hope_kv_list:get(XPlaneData, lat_lon_alt),
64c0d81f
SK
54
55 % Find an unlabled data type
56 {some, {10, V1, V2, V3, V4, V5, V6, V7, V8}} = hope_kv_list:get(XPlaneData, 10),
57
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),
61
62 ...
63```
64
65Note: 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.
69
d014d93e
SK
70
71Data format references
72----------------------
73
74- http://b58.svglobe.com/data.html
75- http://www.nuclearprojects.com/xplane/xplaneref.html
This page took 0.023993 seconds and 4 git commands to generate.