FlightGear Generic IO

external: index
internal: preamble generic IO images downloads end

C# Application, feeding on FG generic IO

While trolling the FG wiki, I came across an interesting Microsoft C# implementation feeding on FlightGear 'generic' IO stream, over a socket connection, manipulating a physical model connected to the COM1 port, and got quite interested ;=))

See - http://linkslink.wordpress.com/takeoff/ - I copied what bits I could of the code from there, and put together a C# application using Microsoft Visual Studio 2005 (MSV#8).

Like the site uses, I called the application FgfsSharp, and added some more features that I wanted ... The complete source, and runtime is given below. This is a view of the window -


It has a Log file output, of the messages received, if checked. The output to the COM1 port has not been tried, since I do not seem to have a COM1 port on that machine. The original application used this COM1 output to run a 'model' - see web site for details.

And, in XP, you ***MAY*** have downloaded and installed Microsoft Speech SDK (SAPI), from :-
*** OR ***MAYBE***Microsoft Speech Application Software Development Kit 1.1 ***
then you can ask it to speak the ATC messages that arrive. It seems this SAPI is already available in the full Vista Ultimate? and maybe other Vista versions? And maybe XP also, but I also wanted to compile, and try some C++ samples provided ...

Also this application was developed, and tested in XP using, Microsoft Visual Studio 2005 - Version 8.0.50727.762 (SP.050727-7600), Microsoft .NET Framework - Version 2.0.50727 SP1, Installed Edition: C# Express - Microsoft Visual C# 2005 (MSV#8).

When re-compiled in Vista, using MSV#9 (2008), it showed some 57 warnings, but NO errors, and seemed to run fine, and I did NOT install the Microsoft Speech Application Software Development Kit 1.1, since the System Requirements, Supported Operating Systems did NOT include Vista, but this may be just an oversight .... but in Vista, the speech worked without any 'SDK' installation ...

Selecting IP, and port 5555 and 'Start Server', sets it up ready to receive messages from FlightGear ... In Vista, this IP dropdown also showed a number of 'strange' entries like 'fe80::18c4:ab4:3f57.fe96%9' - not sure what these are all about - but all worked on, the 'localhost' IP address ...


Configure FG Output

More details can be found in README.IO, in the <data>/docs directory. But I am interested here only in the 'generic' IO, so it can be received by the above FgfsSharp 'server', written in Microsoft C# ...

[frequency(int)-cycles per second-Hz],

The parameters I used were -


The last Parameter is the name of a .xml-file located in the /Protocols folder of your FlightGear- install. An example fgfsSharp.xml is included with the runtime below, but to describe just the first part of it :-


These establish the basic format of the IO message sent to the socket at the requested frequency, or on each FG update if the frame rate is less than the requested frequency. Then each 'chunk' of the message, separated by the 'separator' chosen, is established like :-


The name is just that, a name! The <type> in this case is an 'int', and how to <format> the value, in this case a simple '%d', and what value to output from the FlightGear Property Tree. When running FG you can open a property tree viewer, to get all the possible path names - there are MANY ...

Or, as the web site advises, you can run FG with an --httpd=5555 parameter, and when it is up and running - the console window will show :-

Httpd server started on port 5555

Then open a browser and enter, in the address line, and GO, and voila, you will be shown a Property Tree list. You can 'navigate' down into the list, double clicking on an entry, just like normal folder browsing in the windows browser, and you must continually refresh the browser if you want to see any changes in the 'property' value ...

Any 'property' can be the subject of a 'chunk', but you would need to adjust FgfsSharp to 'read' that value from the message string, and do something with it ...

The factor, which defaults to 1 anyway, would allow you to apply a conversion, like from 'knot' to say feet-per-second, etc, by applying an 'factor'. See simgear/constants.h for say /** Knots to Feet per second */
#define SG_KT_TO_FPS 1.6878098571011956874
or any other 'factor' desired ... Of course, for more accuracy, the <type> should be a float, and the <format> is not required, or the <format> can add a 'marker' with 'precision', like <format>Speed=%05.1f</format> ...

But when I first tried FG I got - in the console

Unable to load the protocol configuration file,

BUT that was because I made an XML coding error! I wrote a simple chkxml.pl script, and found some problems ... now fixed!

Then -

Error: connect() failed in make_client_socket()
SG_IO_OUT socket creation failed
Error opening channel communication layer.
I/O Channel config failed.

BUT that was because you MUST run the 'server' FIRST ... FG MUST have a tcp 'server' to connect to ... But initially, still NO messages arrived ...

So I wrote a fgio.exe to do a SIMPLE sockets test, and it worked fine using :-

   string host = "";
   string port = "5555";
   string style = "tcp";

It uses the SAME SimGear IO, which is actually PLIB net.lib IO, as FlightGear, so fgio should work ... AND IT DID ;=)) AND NOW SO DID FlightGear ;=))

Originally I had set the 'speed' to 1000, like the site, expecting one message per second, but they arrived a LOT faster than that ... I guess the Hz means exactly that - cycles per second - so later I settled on 5 per second, as sufficient for my display. Certainly NOT 1000, since each message can only be sent on each FG update, and that is per the frames per second, and I usually get around 30 to 100, but NEVER 1000 fps!

So, when FLYING in FG, I can see the speed, height, roll and pitch changes reflected in my FgfsSharp application window - ABSOLUTELY GREAT STUFF !!!


Some Images

As can be seen, although I am in a steep left bank, the slider is only slightly to the left, even though the roll 'R', is -76 degrees ... this is why I would like to apply a log type scale, if I had the time ...


All the output is to a log file ... here is a sample of the contents -

14:58:40|67|4|5|0|Golf Foxtrot Sierra Cleared to land
14:58:41|70|7|6|0|Golf Foxtrot Sierra Cleared to land
14:58:42|72|13|7|-1|Golf Foxtrot Sierra Cleared to land
14:58:43|72|23|9|2|Golf Foxtrot Sierra Cleared to land
14:58:44|73|37|11|7|Golf Foxtrot Sierra Cleared to land
14:58:47|72|67|13|6|Golf Foxtrot Sierra Cleared to land
14:58:47|72|74|13|8|Golf Foxtrot Sierra Cleared to land
14:58:48|71|96|14|11|Golf Foxtrot Sierra Cleared to land
14:58:49|71|118|15|6|Golf Foxtrot Sierra Cleared to land
14:58:50|68|141|14|1|Golf Foxtrot Sierra Cleared to land

FgfsSharp added the 'time' to the front of the message, and this was using just 1Hz - i.e. 1 message a second, which may be sufficient for most purposes. And although the ATC message is repeated, I only 'speak' the message when it is a NEW, different message ...

A simple SUCCESSFUL test of FG generic IO, and receiving those messages on a socket, and show the change ... THE POSSIBILITIES ARE ENDLESS ;=))



The FgfsSharpe01.zip contains a runtime executable, FgfsSharp.exe, AND the 'interop' DLL for the MS Speech library, if required, and including the fgfsSharp.xml file, to be placed in <data>/Protocol folder, plus fgio.exe (in fgioe01.zip) for quick testing ...

And FgfsSharp-01.zip contains the full source, of both the FgfsSharp C# application source, AND my simple testing application, in fgio-01.zip. Like FG itself, fgio.exe requires FgfsSharp running, with the 'server' running, and sends messages about each second to FG ...

Date Link Size MD5









Enjoy the endless options of FlightGear ;=)).

Tuesday, November 18, 2008.


EOF - fgfsSharp-01.doc

checked by tidy  Valid HTML 4.01 Transitional