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 :
Here is the class where I store informations :
And finally here is what I get within my application debug window :
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
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