EvenAR / node-simconnect

A cross platform SimConnect client library for Node.JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MFS2020 : Aircraft management from node-simconnect

Oru-Bus opened this issue · comments

Hello,
I'd like to know if it's possible to manage the aircraft by sending it data, and if so, how?
For example, we can find out the altitude of the autopilot by doing :

handle.addToDataDefinition(
            ALTITUDE_DATA,
            AUTOPILOT ALTITUDE LOCK VAR,
            feet',
            SimConnectDataType.FLOAT64,
            0.0,
            SimConnectConstants.UNUSED
 ) ;

handle.requestDataOnSimObject(
            REQUEST_ID_ALTITUDE_DATA,
            ALTITUDE_DATA,
            SimConnectConstants.OBJECT_ID_USER,
            SimConnectPeriod.SECOND,
            0,
            0,
            0,
            0
) ;
....

But is it possible to increase the autopilot altitude from node-simconnect?

For example, I tried :

const altitudeIncrement = 1000 ;

handle.transmitClientEvent(
    SimConnectConstants.EVENT_ID_AP_ALT_VAR_INC,
    altitudeIncrement,
    0, // Additional parameter (0 by default)
    SimConnectConstants.OBJECT_ID_USER,
    SimConnectConstants.EVENT_FLAG_GROUPID_IS_PRIORITY
 ) ;

But here's the error I got:

Error: TypeError: Illegal value: undefined (not an integer)
    at module.exports.ByteBufferPrototype.writeInt32 (D:\game\MFS2020\HomeCockpit\node_modules\bytebuffer\dist\bytebuffer-node.js:856:23)
    at RawBuffer.writeInt32 (D:\game\MFS2020\HomeCockpit\node_modules\node-simconnect\dist\RawBuffer.js:66:21)
    at SimConnectPacketBuilder.putInt32 (D:\game\MFS2020\HomeCockpit\node_modules\node-simconnect\dist\SimConnectPacketBuilder.js:41:28)
    at SimConnectConnection.transmitClientEvent (D:\game\MFS2020\HomeCockpit\node_modules\node-simconnect\dist\SimConnectConnection.js:124:14)

Hi! SimConnectConstants.EVENT_ID_AP_ALT_VAR_INC does not exist in node-simconnect so that is probably why get that error.

You need to bind the SimConnect event names to your own ID which you will use when calling transmitClientEvent. The available event names can be found here.

Example:

const INCREMENT = 0
const DECREMENT = 1

handle.mapClientEventToSimEvent(INCREMENT, "AP_ALT_VAR_INC");
handle.mapClientEventToSimEvent(DECREMENT, "AP_ALT_VAR_DEC");
// more events
// ...


// Usage
handle.transmitClientEvent(
    SimConnectConstants.OBJECT_ID_USER, 
    INCREMENT, 
    0, // The input value is not relevant for this event
    1, 
    EventFlag.EVENT_FLAG_GROUPID_IS_PRIORITY
);

handle.transmitClientEvent(
    SimConnectConstants.OBJECT_ID_USER, 
    DECREMENT, 
    0, // The input value is not relevant for this event
    1, 
    EventFlag.EVENT_FLAG_GROUPID_IS_PRIORITY
);

EDIT: I have added a sample here.