December 7, 201411 yr Hello, I'm trying to read theses variables : - AIRSPEED TRUE and PLANE HEADING DEGREES TRUE. So , to do this I wrote this king of code : struct Struct1 { double altitude; double altitudeAboveGround; double latitude; double longitude; double heading; double trueAirSpeed; }; and SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Altitude","feet"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Alt Above Ground","feet"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Latitude","degrees"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Longitude","degrees"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Heading Degrees Magnetic","radians"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Airspeed True","knots"); like the RequestData sample from SimConnect SDK. When I run FSX, Altitude, Latitude and Longitude datas are correct, but heading and speed give me some funny values. Are my definitions wrong ? Or do I need to convert the heading and speed values ? Thank you for help... Davy
December 7, 201411 yr Did you want heading in radians? You'd have to convert it to degrees by multiplying it by 180/PI if I remember. Gregg Gregg Seipp "A good landing is when you can walk away from the airplane. A great landing is when you can reuse it." i9 64GB RAM, GTX-5090
December 7, 201411 yr Author For funny values, this is what I've got : 2014-12-07 15:27:05.849 L [iNFO]: Log file, "LiveTiles.log", has been opened.2014-12-07 15:27:05.849 L [iNFO]: DLLstart...2014-12-07 15:27:07.887 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_OPEN...2014-12-07 15:27:07.887 L [iNFO]: OnRecvOpen : create menu entry...2014-12-07 15:27:10.840 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_EVENT...2014-12-07 15:27:10.840 L [iNFO]: OnRecvEvent : SIM_START... [#0]2014-12-07 15:27:31.369 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_EVENT...2014-12-07 15:27:31.369 L [iNFO]: OnRecvEvent : SIM_START... [#1]2014-12-07 15:27:32.247 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA...2014-12-07 15:27:32.248 L [iNFO]: Aircraft latitude : 0.003000 longitude : -0.007197 altitude : 1724.999996 heading : -1731497640 speed : 10739101912014-12-07 15:27:37.218 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA...2014-12-07 15:27:37.218 L [iNFO]: Aircraft latitude : 0.002343 longitude : -0.006309 altitude : 1737.872894 heading : -741805454 speed : 10738764762014-12-07 15:27:42.248 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA...2014-12-07 15:27:42.248 L [iNFO]: Aircraft latitude : 0.002337 longitude : -0.005052 altitude : 1613.741970 heading : -1273069681 speed : 10730533042014-12-07 15:27:47.208 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA...2014-12-07 15:27:47.208 L [iNFO]: Aircraft latitude : 0.003036 longitude : -0.003702 altitude : 1476.562808 heading : -1305919448 speed : 10729616602014-12-07 15:27:52.224 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA...2014-12-07 15:27:52.225 L [iNFO]: Aircraft latitude : 0.003785 longitude : -0.002346 altitude : 1341.971656 heading : -887307242 speed : 10728037692014-12-07 15:27:57.244 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA...2014-12-07 15:27:57.244 L [iNFO]: Aircraft latitude : 0.004799 longitude : -0.001117 altitude : 1160.765933 heading : 1249950545 speed : 10725652812014-12-07 15:28:02.194 L [iNFO]: DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA...2014-12-07 15:28:02.194 L [iNFO]: Aircraft latitude : 0.005956 longitude : -0.000031 altitude : 1058.595231 heading : -1447998764 speed : 10723255532014-12-07 15:28:07.523 L [iNFO]: DLLStop...====[ END OF CURRENT LOG ]==== Even if I convert from rad to deg or deg to rad the heading value, I still have wrong heading ... When I run FSX, I'm using a low speed aircraft...
December 7, 201411 yr Can you provide a snippet of where you're storing the variable and the line you're using for logging? Gregg Seipp "A good landing is when you can walk away from the airplane. A great landing is when you can reuse it." i9 64GB RAM, GTX-5090
December 7, 201411 yr Author Here it is , all my code: I use for my logging this library : CppLogLib_0_3_1 #include "stdafx.h" #include <iostream> #include <SimConnect\SimConnect.h> #include "CppLogLib_0_3_1\LogFile\Log.h" using namespace std; // Logger LogFile_t mLogger; // Inner int SimStartCounter; // Menu // Données à recueiller struct Struct1 { double altitude; double altitudeAboveGround; double latitude; double longitude; double heading; double trueAirSpeed; }; // Simconnect datas HANDLE hSimConnect; enum EVENT_ID { MAIN_MENU = 1, SIM_START } ; enum REQUEST_ID { SHOW_WINDOW, } ; enum DATA_DEFINE_ID { DEFINITION_1 } ; enum DATA_REQUEST_ID { REQUEST_1 } ; void SetupStructDefinitions() { SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Altitude","feet"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Alt Above Ground","feet"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Latitude","degrees"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Longitude","degrees"); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Plane Heading Degrees Magnetic","radians", SIMCONNECT_DATATYPE::SIMCONNECT_DATATYPE_FLOAT64, 0.0f, SIMCONNECT_UNUSED); SimConnect_AddToDataDefinition(hSimConnect,DEFINITION_1,"Airspeed True","knots"); } void onRecvOpen(SIMCONNECT_RECV_OPEN *pOpen) { mLogger->Info("OnRecvOpen : create menu entry..."); SimConnect_MenuAddItem(hSimConnect, "Live Tiles",MAIN_MENU,0); } void onRecvEvent(SIMCONNECT_RECV_EVENT *pEvent) { switch(pEvent->uEventID) { case MAIN_MENU : { mLogger->Info("OnRecvEvent : MAIN_MENU..."); break; } case SIM_START: { mLogger->Info("OnRecvEvent : SIM_START... [#%d]",SimStartCounter); if (SimStartCounter > 0) SimConnect_RequestDataOnSimObject(hSimConnect,REQUEST_1,DEFINITION_1,SIMCONNECT_OBJECT_ID_USER,SIMCONNECT_PERIOD_SECOND,0,0,5,0); SimStartCounter++; break; } } } void onRecvSimObjectData(SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData) { switch (pObjData->dwRequestID) { case REQUEST_1: { Struct1 * pstruct1 = (Struct1*) &pObjData->dwData; mLogger->Info("Aircraft latitude : %f longitude : %f altitude : %f heading : %d speed : %d",pstruct1->latitude, pstruct1->longitude, pstruct1->altitude, pstruct1->heading, pstruct1->trueAirSpeed); break; } } } void CALLBACK DispatchProcedure(SIMCONNECT_RECV *pData, DWORD chData,void *pContext) { switch(pData->dwID) { case SIMCONNECT_RECV_ID_OPEN: { mLogger->Info("DispatchProcadure call : SIMCONNECT_RECV_ID_OPEN..."); onRecvOpen((SIMCONNECT_RECV_OPEN *) pData); break; } case SIMCONNECT_RECV_ID_EVENT: { mLogger->Info("DispatchProcadure call : SIMCONNECT_RECV_ID_EVENT..."); onRecvEvent((SIMCONNECT_RECV_EVENT *) pData); break; } case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: { mLogger->Info("DispatchProcadure call : SIMCONNECT_RECV_ID_SIMOBJECTDATA..."); onRecvSimObjectData((SIMCONNECT_RECV_SIMOBJECT_DATA *) pData); break; } } } void __stdcall DLLStart(void) { SimStartCounter = 0; // BOOST_LOG_TRIVIAL(info) << "DLLStart"; const string LogName = "f:\\LiveTiles.log"; Logger::Init(LogName.c_str(), true, false); // this file (no path included) gets created in the current working directory. mLogger = Logger::GetLog(); // get the pointer through which logging takes place. if ( mLogger.get() == NULL || mLogger->IsProblem() ) // one can check for error conditions in the logger. { if ( mLogger.get() == NULL ) cout << "\n" << "Failed to initialize (open/create) the log file, " << LogName << endl; else cout << "\n" << mLogger->GetErrorMessage() << endl; } else { mLogger->Info("Log file, \"%s\", has been opened.", "LiveTiles.log"); mLogger->Info("DLLstart..."); } if (SUCCEEDED(SimConnect_Open(&hSimConnect,"LiveTiles_DLL",NULL,0,NULL,SIMCONNECT_OPEN_CONFIGINDEX_LOCAL))) { SetupStructDefinitions(); SimConnect_SubscribeToSystemEvent(hSimConnect, SIM_START, "SimStart"); SimConnect_CallDispatch(hSimConnect,DispatchProcedure,NULL); } } void __stdcall DLLStop(void) { // BOOST_LOG_TRIVIAL(info) << "DLLStop"; mLogger->Info("DLLStop..."); SimConnect_Close(hSimConnect); } Still looking for the problem...
December 7, 201411 yr Try changing those %d in your log line to %f and see what happens. Gregg Gregg Seipp "A good landing is when you can walk away from the airplane. A great landing is when you can reuse it." i9 64GB RAM, GTX-5090
December 7, 201411 yr Author Ok, I found my errors .... :rolleyes: mLogger->Info("Aircraft latitude : %f longitude : %f altitude : %f heading : %d speed : %d",pstruct1->latitude, pstruct1->longitude, pstruct1->altitude, pstruct1->heading, pstruct1->trueAirSpeed); It should be : mLogger->Info("Aircraft latitude : %f longitude : %f altitude : %f heading : %f speed : %f",pstruct1->latitude, pstruct1->longitude, pstruct1->altitude, pstruct1->heading, pstruct1->trueAirSpeed); Anyway, thank's a lot for you help Gregg_Seip... Ahhh, you answered when I was writting my post... Thank you
Create an account or sign in to comment