• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Simulator variables handling

Messages
20
Country
france
Hello,

I am writing a C++ WIN32 add-on which reads every 5 seconds the following data from P3D :

- Aircraft altitude
- Ambient wind direction
- Ambient wind velocity
- Ambient OAT

My add-on connects and receive data every 5 seconds, but I have a problem when I try to read the variables when I stored the values. Here is my code :

Code:
void simConnectEventThread(void *pArg)
{
    hSimConnectEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

    if(SUCCEEDED(SimConnect_Open(&hSimConnect, "PSXAloft", NULL, 0, hSimConnectEvent, 0)))
    {
        pSimConnectStatusText->print("Connected", 1, TRUE);           
       
        SimConnect_AddToDataDefinition(hSimConnect, DEFINTION_OAW, "PLANE ALTITUDE", "Feet");
        SimConnect_AddToDataDefinition(hSimConnect, DEFINTION_OAW, "AMBIENT TEMPERATURE", "Celcius");
        SimConnect_AddToDataDefinition(hSimConnect, DEFINTION_OAW, "AMBIENT WIND VELOCITY", "Knots");
        SimConnect_AddToDataDefinition(hSimConnect, DEFINTION_OAW, "AMBIENT WIND DIRECTION", "Degrees");       

        SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_OAW, DEFINTION_OAW, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND, 0, 0, 5, 0);       

        while((!quit) && (WaitForSingleObject(hSimConnectEvent, INFINITE) == WAIT_OBJECT_0))
        {
            SimConnect_CallDispatch(hSimConnect, dispatchProc, NULL);
        }

        CloseHandle(hSimConnectEvent);
        SimConnect_Close(hSimConnect);
    }
    pSimConnectStatusText->print("Disconnected from simconnect", 2, TRUE);
    quit = FALSE;
}

void CALLBACK dispatchProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext)
{
    switch(pData->dwID)
    {
        case SIMCONNECT_RECV_ID_OPEN:
        {
            pDebug->print("SIMCONNECT CHANEL OPEN\n", "", "");
            break;
        }

        case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
        {
            SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;        

            switch(pObjData->dwRequestID)
            {
                case REQUEST_OAW:
                {               
                    pIncDataSim = (DataIncSim*)&pObjData->dwData;                    

                    stringstream ss;
                    string sstring;
                    ss.str(string());
                    ss.clear();                   
                    ss << "OAT : " << pIncDataSim->oat << "\n";
                    sstring = ss.str();
                    pDebug->print(sstring, "\n", "");
                    ss.str(string());
                    ss.clear();
                    ss << "Altitude : " << pIncDataSim->altitude << "\n";
                    sstring = ss.str();
                    pDebug->print(sstring, "\n", "");
                    ss.str(string());
                    ss.clear();
                    ss << "Wind dir : " << pIncDataSim->windDir << "\n";
                    sstring = ss.str();
                    pDebug->print(sstring, "\n", "");
                    ss.str(string());
                    ss.clear();
                    ss << "Wind vel : " << pIncDataSim->windVel << "\n";
                    sstring = ss.str();
                    pDebug->print(sstring, "\n", "");               
                   
                    break;
                }               
            }
            break;
        }

        case SIMCONNECT_RECV_ID_QUIT:
        {
            quit = TRUE;
            break;
        }
    }
}

Here is the class where I store informations :

Code:
#ifndef CLASS_DATA_INC_SIM_HEADER
#define CLASS_DATA_INC_SIM_HEADER

using namespace std;

class DataIncSim
{
    public:

    double altitude; // Aircraft current altitude
    double oat; // Current ambient OAT   
    double windVel; // Current ambient wind velocity
    double windDir; // Current ambient wind direction
   

    private:

};
#endif

And finally here is what I get within my application debug window :

Code:
SIMCONNECT CHANEL OPEN

OAT : 0.997356

Altitude : 37709.8

Wind dir : -2.53017e-098

Wind vel : 0

What am I doing wrong with data ? I tried many tips but nothing is working. Thank you in advance for your help.

Regards,
Jean-philippe
 
Top