Ground Altitude

Discuss on the SimConnect SDK can be used by programmers to write add-on components for Prepar3D
Locked
gita1111
Posts: 3
Joined: Thu May 07, 2015 2:22 am

Post by gita1111 »

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: 724
Joined: Sat Jan 19, 2013 1:46 am
Location: Ontario, Canada

Post by ronh991 »

Do you really need to compile with P3D version of simconnect? My FSX version works. Using VS2010 C++ Request Data example code.
Ron
gita1111
Posts: 3
Joined: Thu May 07, 2015 2:22 am

Post by gita1111 »

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

Post by gita1111 »

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: 724
Joined: Sat Jan 19, 2013 1:46 am
Location: Ontario, Canada

Post by ronh991 »

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
Locked