Board index FlightGear Support Interfacing

is it possible to know if flightgear is paused with telnet?

Connecting two computers, using generic protocol, connecting with Matlab?

is it possible to know if flightgear is paused with telnet?

Postby starvi » Mon Jun 21, 2021 1:10 pm

hi everyone,

as i am interfacing flightgear through telnet, i would like to know the current status of flightgear such as if the system is currently on pause, etc.

from Telnet Usage, i am able to pause/play flightgear with "run pause" but what about knowing its current status? what commands do i need to run/get?
starvi
 
Posts: 12
Joined: Fri May 21, 2021 5:13 am

Re: is it possible to know if flightgear is paused with teln

Postby wkitty42 » Mon Jun 21, 2021 1:59 pm

tracing through the code, i see
1. --enable-freeze and --disable-freeze are the two options to start the sim frozen (paused) or not...
2. those point to fgOptEnableFreeze and fgOptDisableFreeze in flightgear/src/Main/options.cxx...
3. searching for those turns up two subroutines that set/unset boolean properties /sim/freeze/master and /sim/freeze/clock...
4. when the sim is frozen/paused, these two boolean properties are both set to true otherwise they are set to false...
5. when actually running the sim and having the property tree opened and located on the /sim/freeze branch, hitting the 'p' key in-sim to toggle paused does indeed toggle both of those properties between true and false...

with that information, you should be able to figure out how to check at least one of those properties in your process to see if said property is true or false and react accordingly...
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: is it possible to know if flightgear is paused with teln

Postby Hooray » Mon Jun 21, 2021 6:40 pm

exactly.

Apart from that, you can also register a listener (subscription) to receive a notification when the property is updated (see the subscribe/unsubscribe telnet commands).
That way, you won't have to use polling.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: is it possible to know if flightgear is paused with teln

Postby starvi » Tue Jun 22, 2021 9:01 am

hey @wkitty42 and @Hooray

thanks for the help!
starvi
 
Posts: 12
Joined: Fri May 21, 2021 5:13 am

Re: is it possible to know if flightgear is paused with teln

Postby wkitty42 » Tue Jun 22, 2021 1:12 pm

Image
"You get more air close to the ground," said Angalo. "I read that in a book. You get lots of air low down, and not much when you go up."
"Why not?" said Gurder.
"Dunno. It's frightened of heights, I guess."
User avatar
wkitty42
 
Posts: 9148
Joined: Fri Feb 20, 2015 4:46 pm
Location: central NC, USA
Callsign: wk42
Version: git next
OS: Kubuntu 20.04

Re: is it possible to know if flightgear is paused with teln

Postby ludomotico » Tue Jun 22, 2021 3:05 pm

Hooray wrote in Mon Jun 21, 2021 6:40 pm:You can also register a listener (subscription) to receive a notification when the property is updated (...) That way, you won't have to use polling.


Except if you don't want to miss any change and, in the case of the "pause/unpause event", you don't.

If you decide to use "subscribe", you must increase the frequency of the internal update to prevent missing any change. Alternatively, do the polling yourself. Check: viewtopic.php?f=18&t=39161

EDIT: checking again, I think my message applies to the websocket interface and maybe not telnet. Anyway, I leave this here just in case.
User avatar
ludomotico
 
Posts: 1269
Joined: Tue Apr 24, 2012 2:01 pm
Version: nightly
OS: Windows 10

Re: is it possible to know if flightgear is paused with teln

Postby Hooray » Tue Jun 22, 2021 4:10 pm

We implemented telnet subscription support using the existing Plib Netchat object and a standard SGPropertyChangeListener specifically to avoid polling - thus, the whole thing will be executed inside the main loop and should "just work" for most people.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: is it possible to know if flightgear is paused with teln

Postby starvi » Wed Jun 23, 2021 9:19 am

I managed to have a get and set with unity through telnet but how can I use the subscribe? I would like to use it for a simple on-off button where I don't have to check for changes in value constantly.

the only details I get from the wiki are:

unlike the 'get'/set commands, the 'subscribe' command needs its argument to be an absolute path from the root, for example:
subscribe /sim/time/real/seconds


For each changed property, the notification response will be in the form of: /some/property=value (terminator)


this is my code for the getter:
Code: Select all
public async Task<string> AsyncGet (string command)
{
   this.callType = "get";

   try
   {
      if (this.netStream != null && this.netStream.CanWrite)
      {
         this.strmWriter.WriteLine($"get {command}");
         this.strmWriter.Flush();

         while(!this.netStream.DataAvailable)
            await Task.Delay(1);

         //readline return result <fg command>='<value>'
         return this.SubStrResult(this.strmReader.ReadLine(), '\'', '\'');
      }
   }

   catch (Exception ex)
   {
      Debug.LogError($"{this.LogHeader} unable to get. {ex.Message}");
   }

   return default;
}


what it does is after it sends the command with StreamWriter, it just waits for the stream to update and return what is in the StreamReader.
and for example, when I press a key on the keyboard I can get a return just with
Code: Select all
 string visable = await this.AsyncGet("sim/yokes-visible");


with the code above, I don't see how I can use subscribe like an event when the return is a string.

I'm a baby in the concept of interfacing and network, so will be great if detailed explanations can be given in c#/unity.

thanks in advance
starvi
 
Posts: 12
Joined: Fri May 21, 2021 5:13 am

Re: is it possible to know if flightgear is paused with teln

Postby Hooray » Wed Jun 23, 2021 5:29 pm

a subscription sets up a listener and whenever the property is updated/written to, a corresponding line will be echoed to the telnet client - i.e. in the form of /some/property=value

Thus, when you are parsing the recv buffer, you can look property=value responses and then process the result accordingly.
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: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 2 guests