Jump to content
The simFlight Network Forums

Reading TCAS data in gauge (stupid question ?)


Recommended Posts

Hi Pete,

Hope my question isn't to stupid but I've been trying to read the TCAS data and always come up with... nothing. This simple code counts to number of traffic found in the air (tested in FS2002).

//variables

TCAS_DATA TCAS_ARR[96] ;

DWORD tid ;

DWORD dwResult;

BYTE FsuipcMem[4096];

//In connect to window

FSUIPC_Open2(SIM_ANY, &dwResult, &FsuipcMem[0], 3008);

FSUIPC_Process(&dwResult);

FSUIPC_CONNECTION = dwResult ;

//if connected, perfomed in PRE_UPDATE section

FSUIPC_Read(0xF080, sizeof(TCAS_ARR), &TCAS_ARR, &dwResult);

FSUIPC_Process(&dwResult) ;

for (i=0; i < 96; i++)

{

tid = TCAS_ARR.id ;

if (tid != 0 ){ counter++ ; }

}

=> the counter always stays 0 so I presume no data is read.

Any idea what's wrong here ?

Thx for the help,

Björn

Link to comment
Share on other sites

Björn

Have a look at the log, but I suspect that when you specify the size of the block of memory to be read, thus: sizeof(TCAS_ARR), what you are getting is the size of the pointer itself, not the size of the block of memory it points to.

Also, if you read in the entire TCAS block on every gauge update, you will likely notice a bit of a frame rate hit. FSUIPC provides an array of byte elements at 0xf008 which get incremented when the relevant TCAS slot is updated. You can use these counters to determine if you need to re-read the data for a particular slot. This approach greatly reduces the amount of data that you need to request from FSUIPC. I did it like this:

int j;

_TCAS_DATA airborne[100];

_TCAS_DATA2 airborne2[100];

BYTE Mem[4100];

BYTE slots_changed[100];

BYTE slots_now[100];

BYTE slots_then[100];

CopyMemory( &slots_then[0], &slots_now[0], 96 );

FSUIPC_Read ( 0xf008, 96, &slots_now[0], &Result );

FSUIPC_Process(&Result);

j = 0;

while ( j < 96 )

{

slots_changed[j] = slots_now[j] - slots_then[j];

if ( slots_changed[j] != 0 )

{

FSUIPC_Read ( 0xf080 + (j * 40), 40, &airborne[j], &Result );

FSUIPC_Read ( 0xd840 + (j * 20), 20, &airborne2[j], &Result );

FSUIPC_Process(&Result);

}

j++;

}

Doug

Link to comment
Share on other sites

TCAS_DATA TCAS_ARR[96] ;

...

BYTE FsuipcMem[4096];

...

FSUIPC_Open2(SIM_ANY, &dwResult, &FsuipcMem[0], 3008);

FSUIPC_Process(&dwResult);

First question: what is the "Process" call for immediately after the Open, with no reads/writes to do? I don't think that will be valid.

FSUIPC_Read(0xF080, sizeof(TCAS_ARR), &TCAS_ARR, &dwResult);

...

Any idea what's wrong here ?

Did you try using FSUIPC's IPC read/write Logging, to see exactly the end result of your work? These facilities are included to make development and testing a lot easier, you know. Please use them.

Where did you arrive at the size of 3008 bytes to tell the Open2 call the size of your buffer? Why define it as 4096 and not use the last 1088 bytes of it?

Have you checked the arithmetic at all? The TCAS_DATA structure is 40 bytes long. You want to read 96 of them96 x 40 = 3840. You also need to allow 16 bytes per read/write and 4 for the terminator, so just for that one read the buffer needs to be 3860 minimum.

If you checked the dwResult of your FSUIPC_Read attempt, the error number would have told you. It is quite useful to look at error returns, especially when something doesn't work as expected! ;-)

Regards,

Pete

Link to comment
Share on other sites

Thx Doug and Pete, like I said.... stupid question I only increased the size of the FsuipcMem BYTE array and forget to do the same with the buffer.

I have also decreased the update frequency to approx 5 times per second, maybe I'll reduce even further, I'll see how it works out.

Got it working now !

Björn

Link to comment
Share on other sites

I have also decreased the update frequency to approx 5 times per second, maybe I'll reduce even further, I'll see how it works out.

If it is for a TCAS instrument display then you could probably reduce it a lot more. I don't think they are supposed to be quite that quick, are they?

Pete

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.