I'm trying to output the airplane coordinates using serial Generic Protocol to an embedded device. The values that are being sent are position/latitude-deg and position/longitude-deg. The longitude value is being correctly converted into binary, but I'm still having trouble with the latitude value. Below you will find images that will better explain the problem.
The command I'm using to run FGFS with Serial Generic Protocol is:
- Code: Select all
fgfs --generic=serial,out,1,\\.\COM9,115200,f5serial
The XML file f5serial:
- Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
<output>
<line_separator></line_separator>
<var_separator></var_separator>
<binary_mode>true</binary_mode>
<byte_order>network</byte_order>
<chunk>
<name>Lat</name>
<node>/position/latitude-deg</node>
<format>%.6f</format>
<type>float</type>
</chunk>
<chunk>
<name>Lon</name>
<node>/position/longitude-deg</node>
<format>%.6f</format>
<type>float</type>
</chunk>
</output>
</generic>
</PropertyList>
I can see the coordinates of the airplane on the Internal Property Browser as follows. You can see that the value for Latitude-Degrees is 63.991 and the value for Longitude-Degrees is -22.605:
Reading the serial output sent by FG using a serial terminal program such as CoolTerm (https://freeware.the-meiers.org/) I get the following:
The hexadecimal binary value in RED is the Latitude and hexadecimal binary value in BLUE is the Longitude.
When I convert these two values into a decimal float using the online converter at https://gregstoll.com/~gregstoll/floattohex/ I get the following:
You can see then that the Latitude converted from the binary value to a decimal float is not the same as the value shown in the Internal Property Browser.
Now the funny thing is when I configure the Generic Protocol to write to a text file, it will write the values exactly as shown in the Internal Property Browser:
which were generated using the following command and XML file:
- Code: Select all
fgfs --generic=file,out,1,data.txt,f6serial
- Code: Select all
<?xml version="1.0"?>
<PropertyList>
<generic>
<output>
<binary_mode>false</binary_mode>
<line_separator>newline</line_separator>
<var_separator>newline</var_separator>
<preamble></preamble>
<postamble></postamble>
<chunk>
<name>Lat</name>
<format>LAT: %.6f</format>
<node>/position/latitude-deg</node>
<type>float</type>
</chunk>
<chunk>
<name>Lon</name>
<format>LON: %.6f</format>
<node>/position/longitude-deg</node>
<type>float</type>
</chunk>
</output>
</generic>
</PropertyList>
I decided to investigate the code found on GitHub a little bit and I found that at least for the Socket output (I couldn't see where the code for Serial output was) the Latitude value is treated differently then the Longitude value.
Link to the GitHub repository: https://github.com/FlightGear
Link to the source file shown in the image above: https://github.com/FlightGear/flightgear/blob/next/src/FDM/JSBSim/input_output/FGOutputFG.cpp
I'm not sure if this applies, but at least as per the code one can see why the the values when received from serial Generic Protocol would be different. Any and all help is very welcome.
Thanks in advance.