Generic protocol: Difference between revisions

Jump to navigation Jump to search
→‎External links: add category {{PropertyTree}}
(→‎External links: add category {{PropertyTree}})
Line 217: Line 217:
total package size: 17 bytes
total package size: 17 bytes
</pre>
</pre>
{{PropertyTree}}
== Generic Protocol ==
FlightGear has an inbuilt "generic" protocol to push and pull data. (todo)
To interface with FlightGear on a socket for example, the following steps need to be taken.
# Establish which "properties" you want to appear "on the wire"
# Create a my_protocol.xml file containing those properties
# Start flight gear on a socket using my_protocol.
For this simple example say were interested in heading and altitude, and we want to "listen" ie output to a socket at port 6789, udp and receiving 10 times a second in the format:
alt\thead\n
// ie altitude - tab - heading - newline
The first step is establishing the nodes, in this example
/position/altitude-agl-ft  eg (22.4713923)
/orientation/heading-deg  eg (297.966325)
Next create a file '''my_protocol.xml'''. This needs to be located at
[[$FG_ROOT]]/Protocol/my_protocol.xml
The XML looks like this:
<?xml version="1.0"?>
<PropertyList>
<generic>
    <output>
        <line_separator>newline</line_separator>
        <var_separator>tab</var_separator>
        <chunk>
          <node>/position/altitude-agl-ft</node>
          <name>altitude to go</name>
          <type>float</type>
          <format>%03.2f</format>
        </chunk>
        <chunk>
          <node>/orientation/heading-deg</node>
          <name>Heading</name>
          <type>float</type>
          <format>%03.3f</format>
        </chunk>
    </output>
  </generic>
</PropertyList>
* The '''output''' tag indicates the protocol for output. The same "protocol" file can contain an "input" section, absent in this example (more later).
* '''line_seperator''' - the end of line (todo ? is this \r\n??)
* '''var_seperator''' - the delimiter for the properties, this could be "|", "###", any string.
* The two '''chunk''' blocks contain our data. Note that these appear in the order presented within the xml file.
** '''node''' - the node of data we want
** '''name''' - it there for a reference, its not transmitted and note necessary (like a note)
** '''type''' - the way this xml is to interpret the value. This is quite important tag. For example if its not there or a string, then "floats" go wild and end up being a string of 32 characters with two decimal places!
** '''format''' - same syntax as printf
** There's more that can be done {todo - link to a full blown example/reference}
We can now start FlightGear and listen with:
fgfs --generic=socket,out,10,localhost,6789,udp,my_protocol
[todo] - link here to the tutorial


== External links ==
== External links ==
Line 225: Line 289:
[[Category:Software]]
[[Category:Software]]
[[Category:XML]]
[[Category:XML]]
[[Category:Property Tree]]

Navigation menu