| 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 | Example |
| 7 | ------- |
| 8 | |
| 9 | ```erlang |
| 10 | -include_lib("include/x_plane_data.hrl"). |
| 11 | |
| 12 | main(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 | |
| 38 | Note: 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 | |
| 43 | |
| 44 | Data format references |
| 45 | ---------------------- |
| 46 | |
| 47 | - http://b58.svglobe.com/data.html |
| 48 | - http://www.nuclearprojects.com/xplane/xplaneref.html |