Board index FlightGear Development Nasal

FSEconomy support?

Nasal is the scripting language of FlightGear.

FSEconomy support?

Postby gurka » Fri Oct 19, 2012 7:29 pm

Hi. I am one of the developers behind FSEconomy and I'm interested in doing a 'client' or investigating at least the requirements to do a client.

I'll describe how the FSE client works for FS9, X and X-plane:

Client ONLY does 2 things:
1 - start a flight
2 - end a flight

for both, the following is required:
- logged in session
- start/end flights: current lat/long position, fuel information on the plane, start time/end time, some other plane/flight metrics

Starting Flights:
calls FSE server on HTTP with: current lat/long, fuel levels, and other stats from the plane, logged in session token
returns from server to client: 'success' or 'failure' code
can be called in the air, so if you forget to start the flight, you can still be in the area (remember, it uses lat/long to calculate your position) and start the flight - currently all external clients so quite common to 'forget' to start the client

Ending Flights:
calls FSE server on HTTP with: current lat/long, fuel levels, and other stats from the plane, logged in session token
returns from server to client: 'success' or 'failure' code
can only be called when the parking brake is set

That's basically it.

All the 'logic' and operations for those calls take place on the server. The FSX client let's you do a lot more 'things' by embedding an ActiveX control/DLL that is basically your IE browser and let's you navigate the site just like you could with any browser - so to me this useless for the client and not something I would look to add to the FG client.

The FG client would just need to start flights, and end flights. Pretty simple.

I know nothing of FG, so looking for you guys to tell me:
- can this start/end flight actions be programmed into FG so it's right 'in' the FG sim itself, not as a separate client program you run like the 9/x/X-plane clients work now. The clients right now are external programs that use FSUIPC for FS9 and the FSX SDK for FSX - X-Plane uses an external Python written system but let's not get into that now :-)
- If this is possible, can the NASAL scripting language be used to execute the HTTP commands I described above?

Thanks for your help.

cheers
gurka
 
Posts: 5
Joined: Fri Oct 19, 2012 7:20 pm

Re: FSEconomy support?

Postby Hooray » Fri Oct 19, 2012 7:35 pm

Hi & welcome to the FG community, most of this is directly possible in FG, even without modifying the C++ source code.
So without responding directly to your questions, I suggest to do a forum search, because we actually had some FSEconomy related threads here, including some people who started working on related features/ideas:

viewtopic.php?f=38&t=10932&p=163540&hilit=FSEconomy#p113079
viewtopic.php?f=6&t=17150&p=163414&hilit=FSEconomy#p163402

If this is possible, can the NASAL scripting language be used to execute the HTTP commands I described above?

Yes, sort of: Nasal itself doesn't currently include socket support for security reasons.
However, Nasal is able to execute so called "fgcommands", these are internal FlightGear commands implemented in C++
FlightGear >= 2.8 includes support for an "xmlhttprequest" fgcommand that can be used to execute a HTTP request.
This can be used to implement AJAX-like server/client exchanges.

You can pass any FG property tree data (lat,lon,alt,groundspeed etc) via conventional GET requests - see example code below(1st URL).
The only "restriction" is that the server-side response must be a PropertyList-encoded XML file, namely:

Code: Select all
<?xml version="1.0"?>
<PropertyList>
<!-- -->
</PropertyList>


For reference:
viewtopic.php?f=18&t=17476&p=166016&hilit=xmlhttprequest#p165973
https://code.google.com/p/flightgear-bu ... id=450#c22
https://gitorious.org/fg/flightgear/blo ... x#line1183
Last edited by Hooray on Fri Oct 19, 2012 7:44 pm, edited 2 times in total.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11885
Joined: Tue Mar 25, 2008 8:40 am

Re: FSEconomy support?

Postby gurka » Fri Oct 19, 2012 7:44 pm

Hello Hooray. I have read those posts and there was nothing on them really related to actually interfacing with FSE - a wishlist item and someone else doing something non-related basically.

Would one of you experienced NASAL devs be interested in working with me to define the http calls required out of FG into FSE and the return data?

Or, would someone be interested in giving me a high level explanation as a starter on how you would go about developing this? How would I initiate the calls to send the start event, and when the parking break is applied, how to send the http event there? With this info I might be able to figure it out.

thanks
gurka
 
Posts: 5
Joined: Fri Oct 19, 2012 7:20 pm

Re: FSEconomy support?

Postby gurka » Fri Oct 19, 2012 7:46 pm

Adding a PropertyList-encoded XML would be no problem for me to add to the server side on FSE to support FG.
gurka
 
Posts: 5
Joined: Fri Oct 19, 2012 7:20 pm

Re: FSEconomy support?

Postby Hooray » Fri Oct 19, 2012 7:51 pm

I am sure we can walk you through the basics pretty quickly - assuming that you have downloaded FG and are able to run it:


For testing purposes, you could modify your server-side script such that it echoes an empty XML response in the form of:
Code: Select all
<?xml version="1.0"?>
<PropertyList>
</PropertyList>


The server-side response will be directly written into the FlightGear property tree, so that it can be further processed.

How would I initiate the calls to send the start event, and when the parking break is applied, how to send the http event there? With this info I might be able to figure it out.


FlightGear uses the concept of a property tree: http://wiki.flightgear.org/Property_tree
This is global variable tree that contains numbers, strings etc
You can register so called "listeners" that are function callbacks which are automatically executed when a property is modified: http://wiki.flightgear.org/Using_listen ... with_Nasal
So, you only need to add a listener for the parking brake property (i.e. from the 777) and the callback will be executed automatically
In turn, the callback could be using the xmlhttprequest command to send a request to your server.

None of this requires any C++ work
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11885
Joined: Tue Mar 25, 2008 8:40 am

Re: FSEconomy support?

Postby Hooray » Fri Oct 19, 2012 7:55 pm

gurka wrote in Fri Oct 19, 2012 7:46 pm:Adding a PropertyList-encoded XML would be no problem for me to add to the server side on FSE to support FG.


You'll probably want to use a separate script or a specific parameter, in the form of ?client_type=flightgear&version=2.6
In the same way, other FG data can be appended to the GET url:

Code: Select all
var url = "http://www.example.com/script.php?foo=1&bar=2";
var req_params = props.Node.new( {"url": url, "targetnode": "/fse-response"} );
fgcommand("xmlhttprequest", params);


You can paste this into the Nasal console and customize it as required.

For example, to get the latitude, use:

Code: Select all
var lat=getprop("/position/latitude-deg");
var lon=getprop("/position/longitude-deg");
var url = "http://www.example.com/script.php?lat="~lat~"&lon="~lon;
var req_params = props.Node.new( {"url": url, "targetnode": "/fse-response"} );
fgcommand("xmlhttprequest", params);




Would one of you experienced NASAL devs be interested in working with me to define the http calls required out of FG into FSE and the return data?


You can use the internal "variable browser" to see what data is readily available in FG: http://wiki.flightgear.org/Property_browser
Note that some of it may be aircraft-specific
Last edited by Hooray on Fri Oct 19, 2012 8:02 pm, edited 1 time in total.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11885
Joined: Tue Mar 25, 2008 8:40 am

Re: FSEconomy support?

Postby gurka » Fri Oct 19, 2012 8:01 pm

Thanks Hooray that is a nice overview which will get me going...

FYI - FSE is all Java on the backend, so i'm more comfortable with C++ then I would be with javascript :-) But I'd like to avoid any C++ coding if this can all be done through the NASAL language - cause at the end of the day this just requires some information from the sim to send to the server, and then process some simple XML on the callback.

How would you handle setting up the login information? Can NASAL handle a 'setup' or config dialog to allow the user to enter in their FSE user id and password and then when logging an event can check to see if logged in or not and then execute a login http call (again, another simple call to the backend just like all the other events - everything is a Servlet on the backend for FSE to handle these User Events as they're called).

thanks for all the info I'll work on setting up FG this weekend and running some tests on my test FSE server.
gurka
 
Posts: 5
Joined: Fri Oct 19, 2012 7:20 pm

Re: FSEconomy support?

Postby Hooray » Fri Oct 19, 2012 8:07 pm

gurka wrote in Fri Oct 19, 2012 8:01 pm:Thanks Hooray that is a nice overview which will get me going...

for your info, I have edited my responses to add more snippets and links - so you may want to have another look.


FYI - FSE is all Java on the backend, so i'm more comfortable with C++ then I would be with javascript :-)

Which is fine, nobody is suggesting that you shouldn't touch the C++ code - it's all open source after all: http://wiki.flightgear.org/Howto:Start_core_development
However, it's all C++ - and NOT Java, so there's a steep learning curve, and lots of dependencies ...building FG from source can be tedious.

But I'd like to avoid any C++ coding if this can all be done through the NASAL language - cause at the end of the day this just requires some information from the sim to send to the server, and then process some simple XML on the callback.

That's definitely all possible. You should be able to get it working within 5 minutes by looking at the snippets that I posted.


How would you handle setting up the login information? Can NASAL handle a 'setup' or config dialog to allow the user to enter in their FSE user id and password and then when logging an event can check to see if logged in or not and then execute a login http call (again, another simple call to the backend just like all the other events - everything is a Servlet on the backend for FSE to handle these User Events as they're called).

Yes, the whole GUI is fully scriptable. All the GUI dialogs are written in XML with embedded Nasal script. One of the simplest examples is in fact our "exit" dialog: https://gitorious.org/fg/fgdata/blobs/m ... s/exit.xml

The GUI dialogs are all stored in $FG_ROOT/gui/dialogs
There are tons of examples to be found there.
The GUI system is documented in $FG_ROOT/Docs/README.gui: https://gitorious.org/fg/fgdata/blobs/m ... README.gui


Let us know if you hit any problems - none if this should take you very long, it's all definitely supported by FG.
I suggest to start playing around with FG a little, and the Nasal console.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11885
Joined: Tue Mar 25, 2008 8:40 am

Re: FSEconomy support?

Postby Hooray » Fri Oct 19, 2012 8:39 pm

I have started writing a little tutorial: http://wiki.flightgear.org/Howto:Making ... from_Nasal

Please let us know if anything is missing, or directly contribute to the wiki.
Thanks!
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11885
Joined: Tue Mar 25, 2008 8:40 am

Re: FSEconomy support?

Postby wjzijderveld » Sat Jan 02, 2016 1:58 pm

Sorry for commenting on such an old topic, but this made more sense then opening yet another topic :-)

Has there been any update on this? Or maybe even just a prototype, I'd like to help where possible if needed.
wjzijderveld
 
Posts: 1
Joined: Sat Jan 02, 2016 1:55 pm

Re: FSEconomy support?

Postby Hooray » Sat Jan 02, 2016 2:16 pm

Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11885
Joined: Tue Mar 25, 2008 8:40 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest