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 🙂