Add some examples to README
[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
23 % Find a labeled data type
24 {some, #x_plane_datum_speeds{}} = hope_kv_list:get(XPlaneData, speeds),
25 {some, #x_plane_datum_pitch_roll_heading{}} = hope_kv_list:get(XPlaneData, pitch_roll_heading),
26 {some, #x_plane_datum_lat_lon_alt{}} = hope_kv_list:get(XPlaneData, lat_lon_alt),
27
28 % Find an unlabled data type
29 {some, {10, V1, V2, V3, V4, V5, V6, V7, V8}} = hope_kv_list:get(XPlaneData, 10),
30
31 % Attempt to find a data type that was not included in current packet
32 none = hope_kv_list:get(XPlaneData, 130),
33 none = hope_kv_list:get(XPlaneData, 67),
34
35 ...
36```
37
38Note: you can, of course, use any other method to search a `[{K, V}]` list
39(which is how `x_plane_data:t()` is structured), such as:
40`proplists:get_value/2`, `lists:keyfind/3`, etc., but I prefer the API of
41`hope_kv_list`, so I used that.
42
d014d93e
SK
43
44Data format references
45----------------------
46
47- http://b58.svglobe.com/data.html
48- http://www.nuclearprojects.com/xplane/xplaneref.html
This page took 0.026812 seconds and 4 git commands to generate.