Ground Altitude

gita1111
Posts: 3
Joined: Thu May 07, 2015 2:22 am

Postby gita1111 » Wed May 06, 2015 10:31 pm

I'm using a simconnect client that worked flawlessly and reliably with FSX. I rebuilt this client against p3d simconnect lib and it sorta works as good. Sometimes p3d hangs when my client is running and takes several starts to get it working.

Biggest issue however is when I request "Ground Altitude" I get the ground alt of where I first start, and this never changes as I fly around hilly terrain. This worked fine with fsx. So then I thought to compute my own height of terrain by taking baro alt and subtracting height above terrain. This basically results in gives me only the starting point ground alt. My guess is the height above terrain value is somehow seeded with that initial ground alt that doesn't change as I fly around.

I need a reliable way to fetch ground alt of my ownship at any point in space. Does anyone have any ideas or experience this?

User avatar
ronh991
Posts: 713
Joined: Sat Jan 19, 2013 1:46 am
Location: Ontario, Canada

Postby ronh991 » Thu May 07, 2015 10:16 am

Do you really need to compile with P3D version of simconnect? My FSX version works. Using VS2010 C++ Request Data example code.
Ron

Aspiring Prepar3d beta tester

gita1111
Posts: 3
Joined: Thu May 07, 2015 2:22 am

Postby gita1111 » Thu May 07, 2015 2:15 pm

I just tried using the old simconnect client I had from FSX and still no Ground Alt change. It just always gives the the ground alt of the point I start from

gita1111
Posts: 3
Joined: Thu May 07, 2015 2:22 am

Postby gita1111 » Thu May 07, 2015 2:17 pm

where can I get this request data example code at? Or could you just do a cut-and-paste job and show me the code here in the forum. thanks much

User avatar
ronh991
Posts: 713
Joined: Sat Jan 19, 2013 1:46 am
Location: Ontario, Canada

Postby ronh991 » Thu May 07, 2015 3:44 pm

in the prepar3d site - look in the menu

Community
Prepare3D SDK
click on the link open SDK online documentation
Prepar3d SDK
Utilities section
Simconnect then select simconnect again
goto the bottom where all the samples are listed

select the Request Data sample - copy the code

here is my update

//------------------------------------------------------------------------------
//
// SimConnect Data Request Sample
//
// Description:
// After a flight has loaded, request the lat/lon/alt of the user
// aircraft
//------------------------------------------------------------------------------

#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>

#include "SimConnect.h"

int quit = 0;
HANDLE hSimConnect = NULL;

struct Struct1
{
char ATCID[32];
double GrndAlt;
double altitude;
};

static enum EVENT_ID{
EVENT_SIM_START,
EVENT_4SEC,
};

static enum DATA_DEFINE_ID {
DEFINITION_1,
};

static enum DATA_REQUEST_ID {
REQUEST_1,
};

void CALLBACK MyDispatchProcRD(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
HRESULT hr;

switch(pData->dwID)
{
case SIMCONNECT_RECV_ID_EVENT:
{
SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;

switch(evt->uEventID)
{
case EVENT_SIM_START:

// Now the sim is running, request information on the user aircraft
hr = SimConnect_RequestDataOnSimObjectType(hSimConnect, REQUEST_1, DEFINITION_1, 0, SIMCONNECT_SIMOBJECT_TYPE_USER);

break;
case EVENT_4SEC:
hr = SimConnect_RequestDataOnSimObjectType(hSimConnect, REQUEST_1, DEFINITION_1, 0, SIMCONNECT_SIMOBJECT_TYPE_USER);

default:
break;
}
break;
}

case SIMCONNECT_RECV_ID_SIMOBJECT_DATA_BYTYPE:
{
SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*)pData;

switch(pObjData->dwRequestID)
{
case REQUEST_1:
{
DWORD ObjectID = pObjData->dwObjectID;
Struct1 *pS = (Struct1*)&pObjData->dwData;
if (SUCCEEDED(StringCbLengthA(&pS->ATCID[0], sizeof(pS->ATCID), NULL))) // security check
{
printf("\nATCID=%s\nGndAlt=%f Alt=%f", pS->ATCID, pS->GrndAlt, pS->altitude );
}
break;
}

default:
break;
}
break;
}

case SIMCONNECT_RECV_ID_QUIT:
{
quit = 1;
break;
}

default:
printf("\nReceived:%d",pData->dwID);
break;
}
}

void testDataRequest()
{
HRESULT hr;

if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Request Data", NULL, 0, 0, 0)))
{
printf("\nConnected to Flight Simulator!");

// Set up the data definition, but do not yet do anything with it
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "ATC ID", NULL, SIMCONNECT_DATATYPE_STRING32);
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Indicated Altitude", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "GROUND ALTITUDE", "feet");

// Request an event when the simulation starts
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_4SEC, "4Sec");

while( 0 == quit )
{
SimConnect_CallDispatch(hSimConnect, MyDispatchProcRD, NULL);
Sleep(1);
}

hr = SimConnect_Close(hSimConnect);
}
}

int __cdecl _tmain(int argc, _TCHAR* argv[])
{

testDataRequest();

return 0;
}

Ron

Aspiring Prepar3d beta tester


Return to “SimConnect Interface Questions”

Who is online

Users browsing this forum: No registered users and 2 guests