Incorrect Data Returned in *Leg When Using Facility API

When using the WASM facility API to request airport data, I am running into issues causing, only part of, the *Leg data (all types of LEG data) to return incorrect numbers. I am not sure if there’s some inherent limitation I am running into, if there’s a bug in the API, or if this is just a documentation issue.

Here’s the data struct I am using to capture the LEG data (basically all the data available). Note the 2 lines marked deliberately do not match the SDK because this is how I can get the “most” correct data.

struct LegRaw {
// Final approach legs, approach legs, missed approach legs
int Type;
char FixICAO[8];
char FixRegion[8];
int FixType;
double FixLat;
double FixLon;
double FixAltitude;
int IsFlyOver;
int DistanceInMinutes;
int IsTrueDegree;
int TurnDirection;
char OriginICAO[8];
char OriginRegion[8];
int OriginType;
double OriginLat;
double OriginLon;
float OriginAltitude;    //<--!!! SDK SAYS FLOAT64
float Theta;
float Rho;
float Course;
float RouteDistance;
int ApproachAltDesc;
float Alt1;
float Alt2;
float SpeedLimit;
float VertAngle;
char ArcCenterICAO[8];
char ArcCenterRegion[8];
int ArcCenterType;
double ArcCenterLat;
double ArcCenterLon;
float ArcCenterAltitude;     //<--!!! SDK SAYS FLOAT64
int IsIAF;
int IsIF;
int IsFAF;
int IsMAP;
};

I’ve set up the corresponding SimConnect_AddToFacilityDefinition that corresponds to all the data above. No SimConnect error is reported. When receiving the dispatch message, I am reading the data with const auto leg = *reinterpret_cast<LegRaw*>(&p->Data);
With this struct, I’ve been able to almost all data correctly (e.g. ICAO string all reads correctly, Course, Rho, Theta all reads correctly, etc.), except

  • FixAltitude always returns 0. Same for OriginAltitude and ArcCenterAltitude
  • The in the 2 lines marked, OriginAltitude and ArcCenterAltitude, if double is used. The data afterward will be wrong.
    • If double is used for OriginAltitude, Rho, Theta, Alt1, etc. will all be wrong.
    • If double is used for ArcCenterAltitude, IsIAF, IsIF, etc. will be wrong.
  • I can never get OriginLat and OriginLon to return the right data. They are always something like 1.0565893152556172e+270.

You’d also need to include the code setting up the facility data definition that goes along with your struct to make sense of it.

Hello

You can use the “SimConnect Inspector” to debug your facilityDataDefinition.
With this tool can see if some simconnect calls sent an exception and more interesting in your situation, you can inspect the layout of your facilityDataDefinition (server side) and the type/size of each field, and compare it to your code. Your code must respect this layout!

If they are the same, it might be a padding issue. So you can add some pragma around your struct to respect the alignment.

#pragma pack(push, 1)

struct SomeStructName
{
   ...
};

#pragma pack(pop)

Best Regards
Maxime / Asobo

1 Like

Thank you! Yep, it is a padding issue. Adding pragma pack solved the lat/long problem. All altitudes still return 0 but I am assuming that’s expected.