EvenAR / node-simconnect

A cross platform SimConnect client library for Node.JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setDataOnSimObject with Waypoints Array

whakamolenz opened this issue · comments

When trying to send a set of (or even one) waypoints to a non-atc aircraft simobject (created with aICreateNonATCAircraft) - i get size mismatch exception.

Looking at setDataOnSimObject the array item size seems to be forced to 0 in all cases?

    if (data instanceof Array) {
          this._writeBuffer.writeInt(DataSetFlag.DEFAULT);
          this._writeBuffer.writeInt(data.length);
          this._writeBuffer.writeInt(0); // size
          data.forEach(simConnectData => {
              simConnectData.write(this._writeBuffer);
          });
          this._writeBuffer.writeInt(this._writeBuffer.getOffset() - 36, 32);

In my code i'm basically createing a single waypoint then sending it to a data definition that just includes AI Wapoint List. Example below:

let newWaypointValue: Waypoint = new Waypoint();
                  newWaypointValue.speed = 100;
                  newWaypointValue.altitude = 1000;
                  newWaypointValue.latitude = 34.03684;
                  newWaypointValue.longitude = -118.22659;
                  newWaypointValue.throttle = 90.0;
                  newWaypointValue.flags =  SimConnectConstants.WAYPOINT_SPEED_REQUESTED;

handle.setDataOnSimObject(
                    dataDefinitions.waypoints,
                    aircraft.objectid,
                    [newWaypointValue]
                  );

@whakamolenz thanks for the bug report.

Looks like I forgot to implement the write()-function in the Waypoint-class (.. and a few other classes). Could you give 3.2.1-beta.0 a try now?

It took some time until I realised/remembered that the 0 is just a placeholder for the array total size, which will be calculated after the array has been written. Really confusing.

Awesome - yep will check it out now.

@EvenAR - not getting the excpetion anymore which is great. Though waypoints themselves still don't work for me - i.e. the aircraft seems to ignore them. But this has been an ongoing battle with MSFS for sometime.

Does that example code look ok for sending the waypoint? From what i've seen people using the managed simconnect seem to be able to set waypoints ok but not without - but that seems rather odd!

let newWaypointValue: Waypoint = new Waypoint();
                  newWaypointValue.speed = 100;
                  newWaypointValue.altitude = 1000;
                  newWaypointValue.latitude = 34.03684;
                  newWaypointValue.longitude = -118.22659;
                  newWaypointValue.throttle = 90.0;
                  newWaypointValue.flags =  SimConnectConstants.WAYPOINT_SPEED_REQUESTED;

handle.setDataOnSimObject(
                    dataDefinitions.waypoints,
                    aircraft.objectid,
                    [newWaypointValue]
                  );

EDIT: Actually definitely yet another MSFS thing i think - if when i insert the non atc aircraft i makr on ground as true - then the assigned waypoint works - otherwise they just remain as zombies.

@whakamolenz I'm not sure if it's related but I noticed that setDataOnSimObject have been sending an incorrect cbUnitSize value when there are more than one element in the array. I just published 3.2.1-beta.1 which should fix this. Maybe that version works better? At least the packets from node-simconnect and the offical samples looks identicial now 😄

Thanks for the update @EvenAR - doesn't seem to have changed anything for me. Basically if the initial aircraf is insert with onground = true - then the waypoints get accepted - but if the aircraft is onground = false - then just ignored. So i think i just need to try and force some workarounds for this.

Ahh ok. It would be interesting to know whether this is a problem with the official SDK too. I have never used this feature myself, but I think your code looks right.