From: Siraaj Khandkar Date: Sun, 4 Oct 2015 23:24:00 +0000 (-0400) Subject: Organize and annotate examples X-Git-Url: https://git.xandkar.net/?p=erlang-x-plane-data.git;a=commitdiff_plain;h=25c95554d442f93258a20e5d3e27c2733a20fd6d Organize and annotate examples --- diff --git a/README.md b/README.md index 027e94c..2de6895 100644 --- a/README.md +++ b/README.md @@ -3,40 +3,48 @@ X-Plane UDP data parser ======================= -Example -------- +Examples +-------- + +### Receive data packet + +```erlang +{ok, Socket} = gen_udp:open(Port, [binary, {active, false}]), +{ok, {_, _, <>}} = gen_udp:recv(Socket, 0), +``` + +### Parse data packet + +```erlang +{ok, {Index, Groups}} = x_plane_data_raw:of_bin(XPlaneDataPacket), +``` + +### Access parsed data ```erlang -main(Port) -> - {ok, Socket} = gen_udp:open(Port, [binary, {active, false}]), - {ok, {_, _, <>}} = gen_udp:recv(Socket, 0), - {ok, {Index, Groups}} = x_plane_data_raw:of_bin(XPlaneDataPacket), - - % 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, - - ... +% 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