• 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.

FSX Retrieving AI data

Messages
47
Country
belgium
Hi all,

I am having problems collecting AI data for my TCAS display from SimConnect:



Code:
void CALLBACK MyDispatchProcMI(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
   HRESULT hr;
   DWORD dwData;

    switch(pData->dwID)
    {
        
		////////////////////////////////////////////////
		// AI Traffic
		////////////////////////////////////////////////
		case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
        {
            SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE *evt = (SIMCONNECT_RECV_EVENT_OBJECT_ADDREMOVE*)pData;
            
            switch(evt->uEventID)
            {
                case EVENT_ADDED_AIRCRAFT:
			if ( evt->eObjType == SIMCONNECT_SIMOBJECT_TYPE_AIRCRAFT )
			{
				hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_AIAIRCRAFT_DATA, DEFINITION_AI,
                        evt->dwData, SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED );
				AddTCASData(evt->dwData);
			}
                    break;

                case EVENT_REMOVED_AIRCRAFT:
			if ( evt->eObjType == SIMCONNECT_SIMOBJECT_TYPE_AIRCRAFT )
			{
				hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_AIAIRCRAFT_DATA, DEFINITION_AI,
                        evt->dwData, SIMCONNECT_PERIOD_NEVER, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED );
				RemoveTCASData(evt->dwData);
			}
			break;
            }
            break;
        }

	case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
        {
            SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*)pData;
            
            switch(pObjData->dwRequestID)
            {
                case REQUEST_AIAIRCRAFT_DATA:
                {
                    DWORD ObjectID = pObjData->dwObjectID;
                    PositionData *pS = (PositionData*)&pObjData->dwData;
					UpdateTCASData(ObjectID, *pS);
                    break;
                }

                default:
                   break;
            }
            break;
        }

        case SIMCONNECT_RECV_ID_QUIT:
        {
            SimConnectQuit = 1;
            break;
        }

        default:
        break;
    }
}

void OpenSimConnect()
{
    HRESULT hr;

    if (SUCCEEDED(SimConnect_Open(&hSimConnect, "SimConnect", NULL, 0, 0, 0)))
    {
        hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_ADDED_AIRCRAFT, "ObjectAdded");
        hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_REMOVED_AIRCRAFT, "ObjectRemoved");	
		
 	SimConnect_CallDispatch(hSimConnect, MyDispatchProcMI, NULL);
    }
}

The ObjectAdded and ObjectRemoved work fine but the SIMCONNECT_RECV_ID_SIMOBJECT_DATA event is called a few times for the last aircraft added by FSX and then simply stops working.

I am probably missing something but I can't find what !

Any ideas anyone ?

Thx,
Björn
 
Last edited:
Not sure what fix you found, but I can tell you why I think your sample above doesn't work:

Your calls to RequestClientData() need unique request ids, so that as each aircraft is added, your request doesn't overwrite the previous request for the previous aircraft. You can reuse the id if the calls are few and far between and you only want to do a PERIOD_ONCE call, but to continue to receive updates, you can't.

What I do is set up my request enums like this:

Code:
enum REQUEST_ID
{
  REQUEST_SOMETHING = 0,
..
blah, blah
..
  REQUEST_AI_DATA = 10000,
  REQUEST_MO_SOMETHINGS = 20000,
..
..

That when I call the RequestDataOnSimObject, for the request id I use REQUEST_ID_DATA+objectId.

It means you have to use if-then-else in the callback instead of switch-case for the request ids, but it works. To get the object id that the callback data is relevent to, just subtract REQUEST_AI_DATA from the request id.

Si
 
Back
Top