Jump to content
The simFlight Network Forums

FSUIPC - Traffic Data, bstate - C#


Recommended Posts

Hello,

How can I using FSUIPC from C# read the bState value for a particular aircraft. I know there is mention of the table structures in the SDK but how do I read this information.

Thanks much for any help.

P.S. I'm looking for code samples not just RTFM.

Tom

Link to comment
Share on other sites

How can I using FSUIPC from C# read the bState value for a particular aircraft.

What is the "bState" value?

I'm not able to help with C# I'm afraid, so I hope someone else will jump in -- I assume the C# part of the SDK isn't sufficient?

However, I don't even understand the value you want. :?

Regards,

Pete

Link to comment
Share on other sites

Pete,

Thanks much for your reply. :D

I am referring to the TCAS_DATA structure mentioned in the "FS2002/4 A.I. Traffic Data (for TCAS applications and similar)" section of the SDK.

I am trying to figure out how to read whether the aircraft is in flight plan, pushback, taxi, etc. from C#. VB code would do as well.

Tom

typedef struct _TCAS_DATA

{ DWORD id; // 0 = empty, otherwise this is an FS-generated ID.

(Do not use this for anything other than checking if the slot is empty or used—it may be re-used for other things at a later date).

float lat; // 32-bit float, in degrees, –ve = South

float lon; // 32-bit float, in degrees, –ve = West

float alt; // 32-bit float, in feet

WORD hdg; // 16-bits. Heading. Usual 360 degrees == 65536 format.

// Note that this is degrees TRUE, not MAG

WORD gs; // 16-bits. Knots Ground Speed

short vs; // 16-bits, signed feet per minute V/S

char idATC[15]; // Zero terminated string identifying the aircraft. By default this is:

// Airline & Flight Number, or Tail number

// For Tail number, if more than 14 chars you get the *LAST* 14

// Airline name is truncated to allow whole flight number to be included

BYTE bState; // Zero in FS2002, a status indication in FS2004—see list below.

WORD com1; // the COM1 frequency set in the AI aircraft’s radio. (0Xaabb as in 1aa.bb)

} TCAS_DATA;

The “bState” value is new for FS2004. When non-zero it gives the current status of the AI aircraft, as follows:

0x80 128 Initialising

0x81 129 Sleeping

0x82 130 Filing flight plan

....

Link to comment
Share on other sites

I am referring to the TCAS_DATA structure mentioned in the "FS2002/4 A.I. Traffic Data (for TCAS applications and similar)" section of the SDK.

I am trying to figure out how to read whether the aircraft is in flight plan, pushback, taxi, etc. from C#. VB code would do as well.

Ah! rightsorry, I didn't see the "Traffic" part, which I now see was in your subject line but not in the message.

It's just a number. I assume you are managing to find the TCAS entry you want? Please, what is then the problem? It sounds like you've done most of it if you've got that far.

Regards,

Pete

Link to comment
Share on other sites

I'm not sure how to get at the aircraft's TCAS table.

According to the SDK, "There are four tables, two main ones at E000 to EFFF for ground aircraft and F000 to FFFF for airborne aircraft, plus two smaller additional ones for FS2004 only at D000 and D800 respectively."

If I have a FlightSim instance running with just 1 aircraft sitting on the ground, how do I access it's TCAS table.

Do I first call FSUIPC_Read and pass in F000? Then, if that is successful, how do I access the bState value?

Thanks so much for your help.

Tom

Link to comment
Share on other sites

I'm not sure how to get at the aircraft's TCAS table.

There are basically two ways -- the easy sledgehammer way (which actually my own TrafficLook uses) and the "correct way".

The correct way is by reading the table size data and calculating which bits to read and which not. Then reading them, but only when flagged as changed. This is difficult and loong-winded to program, but very efficient at run time because you are causing minimum work.

However, the brute-force method seems to work pretty well (try TrafficLook and see). This is simple declaring arrays of enough TCAS_DATA structures for all the aircraft, and reading them all, in one read per table.

If you are only interested in the "bState" you are only interested in the two main tables, the traffic entries only, from E080 for ground and F080 for airborne traffic.

So, your "pseudo code" (C to me, sorry) would be (omitting error checks for now:

TCAS_DATA ground[96];
TCAS_DATA airborne[96];

DWORD dwResult;

FSUIPC_Read (0xE080, 96 * sizeof(TCAS_DATA), (BYTE *) ground, &result);

FSUIPC_Read (0xF080, 96 * sizeof(TCAS_DATA), (BYTE *) airborne, &result);

FSUIPC_Process ...

Now you have all the data in nice local tables in your memory and can access them as and how you like. This is exactly what TrafficLook does.

Regards,

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.