X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=README.md;h=2de6895be7b3fee96d464b31c29d67016305e928;hb=10d6d4c7bd29e99c67024e8a08a2b35f8da1c4de;hp=16c0a3d046876610a65ded6011e251fe932b054e;hpb=8892b9afe9757950420b83fb56a8df1a5a30bf7f;p=erlang-x-plane-data.git diff --git a/README.md b/README.md index 16c0a3d..2de6895 100644 --- a/README.md +++ b/README.md @@ -3,70 +3,49 @@ X-Plane UDP data parser ======================= -Example -------- +Examples +-------- -```erlang --include_lib("include/x_plane_data.hrl"). - -main(Port) -> - {ok, Socket} = gen_udp:open(Port, [binary, {active, false}]), - {ok, {_, _, <>}} = gen_udp:recv(Socket, 0), - {ok, XPlaneData} = x_plane_data:of_bin(XPlaneDataPacket), - - % Currently there're 133 possible data types sent by X-Plane 10, of which - % I've identified and labeled only some of. See x_plane_datum:t() type for - % what is currently labeled. - % The types I've not yet labeled are in the format specified by - % x_plane_datum:anonymous() and can be looked-up by their index number. - - % Find labeled data types - {some, #x_plane_datum_speeds - { vind_kias = VindKias - , vind_keas = VindKeas - , vtrue_ktas = VtrueKtas - , vtrue_ktgs = VtrueKtgs - , vind_mph = VindMph - , vtrue_mphas = VtrueMphas - , vtrue_mphgs = VtrueMphgs - }, - } = hope_kv_list:get(XPlaneData, speeds), - - {some, #x_plane_datum_pitch_roll_heading - { pitch_deg = PitchDeg - , roll_deg = RollDeg - , hding_true = HdingTrue - , hding_mag = HdingMag - }, - } = hope_kv_list:get(XPlaneData, pitch_roll_heading), - - {some, #x_plane_datum_lat_lon_alt - { lat_deg = LatDeg - , lon_deg = LonDeg - , alt_ftmsl = AltFtmsl - , alt_ftagl = AltFtagl - , on_runwy = OnRunwy - , alt_ind = AltInd - , lat_south = LatSouth - , lat_west = LatWest - }, - } = hope_kv_list:get(XPlaneData, lat_lon_alt), +### Receive data packet - % Find an unlabled data type - {some, {10, V1, V2, V3, V4, V5, V6, V7, V8}} = hope_kv_list:get(XPlaneData, 10), +```erlang +{ok, Socket} = gen_udp:open(Port, [binary, {active, false}]), +{ok, {_, _, <>}} = gen_udp:recv(Socket, 0), +``` - % Attempt to find a data type that was not included in current packet - none = hope_kv_list:get(XPlaneData, 130), - none = hope_kv_list:get(XPlaneData, 67), +### Parse data packet - ... +```erlang +{ok, {Index, Groups}} = x_plane_data_raw:of_bin(XPlaneDataPacket), ``` -Note: you can, of course, use any other method to search a `[{K, V}]` list -(which is how `x_plane_data:t()` is structured), such as: -`proplists:get_value/2`, `lists:keyfind/3`, etc., but I prefer the API of -`hope_kv_list`, so I used that. +### Access parsed data +```erlang +% Speeds are in group 3 +{3, Speeds} = lists:keyfind(3, 1, Groups), +{ VindKias +, VindKeas +, VtrueKtas +, VtrueKtgs +, _ +, VindMph +, VtrueMphas +, VtrueMphgs +} = Speeds, + +% Pitch roll and headings values are in group 17 +{17, PitchRollHeadings} = lists:keyfind(17, 1, Groups), +{ PitchDeg +, RollDeg +, HdingTrue +, HdingMag +, _ +, _ +, _ +, _ +} = PitchRollHeadings, +``` Data format references ----------------------