1 The generic communication protocol for FlightGear provides a powerful way
2 of adding a simple ASCII based or binary input/output protocol, just by
3 defining an XML encoded configuration file and placing it in the
4 $FG_ROOT/Protocol/ directory.
9 == file layout ================================================================
11 A protocol file can contain either or both of <input> and <output>
12 definition blocks. Which one is used depends on how the protocol
13 is called (e.g. --generic=file,out,1,/tmp/data.xml,myproto would
14 only use the <output> definitions block).
21 <binary_mode>false</binary_mode>
22 <line_separator></line_separator>
23 <var_separator></var_separator>
25 <postamble></postamble>
28 ... first chunk spec ...
32 ... another chunk etc. ...
37 <line_separator></line_separator>
38 <var_separator></var_separator>
51 == input/output parameters ====================================================
53 Both <output> and <input> blocks can contain information about
54 the data mode (ascii/binary) and about separators between fields
55 and data sets, as well as a list of <chunk>s. Each <chunk> defines
56 a property that should be written (and how), or a variable and which
57 property it should be written to.
60 <binary_mode> BOOL default: false (= ASCII mode)
61 <preamble> STRING default: "" file header put on top of the file
62 <postamble> STRING default: "" file footer put at the end of the file
65 <var_separator> STRING default: "" field separator
66 <line_separator> STRING default: "" separator between data sets
69 <var_separator> are put between every two output properties, while
70 <line_separator> is put at the end of each data set. Both can contain
71 arbitrary strings or one of the following keywords:
84 <var_separator>tab</var_separator>
85 <line_separator>newline</var_separator>
89 <var_separator>\t</var_separator>
90 <line_separator>\r\n</line_separator>
94 To enable binary mode, simply include a <binary_mode>true</binary_mode> tag in
95 your XML file. The format of the binary output is tightly packed, with 1 byte
96 for bool, 4 bytes for int, and 8 bytes for double. At this time, strings are not
97 supported. A configurable footer at the end of each "line" or packet of binary
98 output can be added using the <binary_footer> tag. Options include the length
99 of the packet, a magic number to simplify decoding. Examples:
101 <binary_footer>magic,0x12345678</binary_footer>
102 <binary_footer>length</binary_footer>
103 <binary_footer>none</binary_footer> <!-- default -->
108 == variable parameters (chunk spec) ===========================================
110 Both <input> and <output> block can contain a list of <chunk> specs,
111 each of which describes the properties of on variable to write/read.
114 <name> for ease of use (not tranferred)
115 <node> the property tree node which provides the data
116 <type> the value type (needed for formatting)
117 one of string, float, bool, int (default: int)
118 <format> defines the actual piece of text which should be sent.
119 it can include "printf" style formatting options like:
124 (not used or needed in binary mode)
126 <factor> an optional multiplication factor which can be used for
127 unit conversion. (for example, radians to degrees).
128 <offset> an optional offset which can be used for unit conversion.
129 (for example, degrees to radians).
132 Chunks can also consist of a single constant <format>, like in:
137 == examples ===================================================================
139 Writes log of this form:
150 <?xml version="1.0"?>
156 <line_separator>newline</line_separator>
157 <var_separator>newline</var_separator>
158 <binary_mode>false</binary_mode>
162 <format>V=%d</format>
163 <node>/velocities/airspeed-kt</node>
167 <name>heading (rad)</name>
168 <format>H=%.6f</format>
170 <node>/orientation/heading-deg</node>
171 <factor>0.0174532925199433</factor> <!-- degrees to radians -->
175 <name>pitch angle (deg)</name>
176 <format>P=%03.2f</format>
177 <node>/orientation/pitch-deg</node>
187 -- writing data in XML syntax -------------------------------------------------
189 Assuming the file is called $FG_ROOT/Protocol/xmltest.xml, then it could be
190 used as $ fgfs --generic=file,out,1,/tmp/data.xml,xmltest
193 <?xml version="1.0"?>
198 <binary_mode>false</binary_mode>
199 <var_separator>\n</var_separator>
200 <line_separator>\n</line_separator>
201 <preamble><?xml version="1.0"?>\n\n<data>\n</preamble>
202 <postamble></data>\n</postamble>
205 <format>\t<set></format>
209 <node>/position/altitude-ft</node>
211 <format>\t\t<altitude-ft>%.8f</altitude-ft></format>
215 <node>/velocities/airspeed-kt</node>
217 <format>\t\t<airspeed-kt>%.8f</airspeed-kt></format>
221 <format>\t</set></format>