Jump to content
The simFlight Network Forums

Recommended Posts

Posted (edited)

Hello guys,

first of all, i am totally new to the fsuipc developing side, so please bear with me, when it comes to the way i can interact with fsuipc.

I am currently experimenting within an electron-framework app, which ultimatly (in faaaaar time) shall become a tracker. In my research on interacting with fsuipc via javascript, i found the fsuipc-module on node-js. This module gives me the ability to poll data from fsuipc in certain intervalls. In functions great, i already built a simple polling stream which gets data like longtitude and latitude for P3D and MSFS at a certain intervall.

But i soon realised, that for certain tracker-behaviors i need a event-driven-script. For example the touchdown. 

Things like engine start or takeoff, i could simply detect via my current polling rate. But for the landing, i need a event listener which listens to the altitude (like pegasus for the last 50ft) or the touchdown itself, as i do not want to poll in milliseconds for the last 100ft or the approach.

I already looked at the sdk, but as i am still a little new to the whole programming world, i did not find a good approach to my problem.

I know, that the event-driven-script may be complicated to explain, but i hope that somebody has the time to do so or to provide me with sources where i could learn more about it. 🙂

My current simple polling script looks like this:
 

const fsuipc = require('fsuipc');
let fetchingInterval;

const startFsuipcHandler = async (event, args) => {
  try {
    if (fetchingInterval) {
      //Stop fetching if its already started
      clearInterval(fetchingInterval);
      fetchingInterval = null;
      console.log('fetching stopped');
      return;
    }

    //Start fetching every 5 seconds
    fetchingInterval = setInterval(async () => {
      const obj = new fsuipc.FSUIPC();
      await obj.open();
  
      obj.add('gpsGS', 0x6030, fsuipc.Type.Double); //speed in meter per second from GPS
      obj.add('gpsLAT', 0x6010, fsuipc.Type.Double); //LAT in DD Coord from GPS
      obj.add('gpsLON', 0x6018, fsuipc.Type.Double); //LON in dd Coord from GPS
      obj.add('gpsALT', 0x6020, fsuipc.Type.Double); //gpsALT in meter from GPS
      //obj.add('groundALT', 0x0020, fsuipc.Type.Int32); //ground ALT in meter (muss convertiert werden /256)
      obj.add('planeBank', 0x057C, fsuipc.Type.Int32); //bank (muss convertiert werden bank*360/65536^2, - = right bank)
      obj.add('planePitch', 0x578, fsuipc.Type.Int32); //pitch (muss convertiert werden pitch*360/65536^2, - = pitch up)
      obj.add('vs', 0x2C8, fsuipc.Type.Int32); //vertical speed (muss konvertiert werden vs *60*3,28084/256)
      obj.add('gForce', 0x1140, fsuipc.Type.Double);
      obj.add('aircraftType', 0x3D00, fsuipc.Type.String, 256);
      //obj.add('lights', 0x0D0C, fsuipc.Type.BitArray, 2);
      //obj.add('clockHour', 0x238, fsuipc.Type.Byte);
      obj.add('eng1fuelUsedSinceStart', 0x90C, fsuipc.Type.Single); //in lb
      obj.add('eng1N1', 0x898, fsuipc.Type.Int16);//konveriterung: value/16384 * 100
  
      const result = await obj.process();
  
      result.planeBank = ((result.planeBank * 360) / Math.pow(65536, 2)).toFixed(2);
      result.planePitch = ((result.planePitch * 360) / Math.pow(65536, 2)).toFixed(2);
      result.vs = Math.floor(result.vs * 60 * 3.28084 / 256);
      result.gForce = (result.gForce).toFixed(2);
      result.gpsALT = Math.round(result.gpsALT * 3.28084);
      result.gpsGS = (result.gpsGS * 1.94384).toFixed(1);
      result.gpsLAT = (result.gpsLAT).toFixed(9);
      result.gpsLON = (result.gpsLON).toFixed(9);
      result.eng1N1 = (result.eng1N1)/16384 *100;
  
      console.log(result);
      // Send the result to the renderer process
      event.sender.send('fsuipc-data', result);
  
      await obj.close();
    }, 5000);

    console.log('Fetching started')
    

  } catch (err) {
    console.error(err);
  }
};

module.exports = { startFsuipcHandler };

 

Thank you very much in advance and merry christmas 🙂

Edited by Benl112
  • 2 weeks later...
Posted

You would have to implement your own event-driven wrapper on top of the provided SDK. Basically you would need to request  the data/offsets that you are monitoring in one thread, and when the value changed you can signal this as events to other threads. I don't remember much about node-js, so cannot really help you with this.

More advanced wrappers, such as Paul Henty's dll for C#, may provide an event-driven interface. And there is also the websocket server.

Posted
Quote

 as i do not want to poll in milliseconds for the last 100ft or the approach.

Polling can't be avoided with FSUIPC because the protocol is based on polling. Applications that use FSUIPC are meant to constantly poll for look for changes.

As John says, my Websocket Server does have an event-driven model, but it has to use polling in the background to monitor for changed values. The developer can choose the polling rate.

My C# DLL does not have an event model for offsets (only LVars which uses John's LVar WAPI server and not FSUIPC).

If you're comfortable using the Node.JS SDK for FSUIPC then you should probably stick with that and just use polling. FSUIPC can comfortably handle requests every 40ms, maybe faster on modern hardware.

The only reason I can see to use another SDK is if the Node.JS wrapper is too slow to manage this rate of polling for some reason.

Paul

  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.