Jump to content
Sign in to follow this  
Guest

Time to release FS2002 AI Traffic code...

Recommended Posts

Guest JeanLuc_

Dear all, I'm glad to offer a code snipset that will allow you to directly read the AI Traffic information from FS2002. As is, it can read the all AI Traffic tables (up to ~100 aircrafts) 18 times a second, with little if no impact on the performances. At this speed, you can really think about doing a working TCAS such as in Reality XP Jet Line Avionics or Flight Line Avionics as speed does matter in this case.Hope this helps!=====================================================================////////////////////////////////////////////////////////////////////// AI AIRCRAFTS SUPPORT CODE for FS2002////////////////////////////////////////////////////////////////////// gauge own structurestypedef struct RXPAIData{ // individual info float lat; // AI Lat in degrees float lon; // AI Lon in degrees float alt; // AI Alt in feet MSL float vs; // AI Vertical Speed in ft/min float gs; // AI Ground Speed in KT float hdg; // AI Heading in Degrees True UINT32 ID; // unique ID for the AI Aircraft} RXPAIData, * PRXPAIData, ** PPRXPAIData;RXPAIData RXPAIACFT[256]; // should be enough!int RXPAIDataNum = 0;// FS2002 Structurestypedef struct RXPAIHeader{ PVOID AIGetText; UINT32 AIID; PCHAR Data;} RXPAIHeader, * PRXPAIHeader, ** PPRXPAIHeader;typedef PRXPAIHeader (CALLBACK *_RXPAICBCK) (unsigned long int); // msg suivi de 2 param si besoin ( sans compter param dans cmdtypedef PRXPAIHeader FSAPI RXPAICBK(int element);typedef RXPAICBK *PRXPAICBK;HMODULE RXPAI_SIM1;char RXPAI_SIM1NAME[]="sim1.dll";UINT32 RXPAI_SIM1PROC;PRXPAICBK RXPAI_SIM1PROC2 = NULL;PRXPAIHeader RXPAI_SIM1HDR;////////////////////////////////////////////////////////////////////////////////////////// some support functions and code#define DEG2RAD(d) (( 0.0174532925199432958) * (d)) // (pi/180) * angle_degrees__inline double DEG360(double a){ if (a < 0.0) a += 360.0; return(fmod(a,360.0));}////////////////////////////////////////////////////////////////////////////////////////// init the DLL function pointer - call from PANEL_SERVICE_PRE_INSTALLvoid RXPAIInit(void){ UINT32 tie; if (RXPAI_SIM1PROC2 == NULL) // only init if not already init { RXPAIDataNum = 0; // get the module handle base address for sim1.dll RXPAI_SIM1 = GetModuleHandle(RXPAI_SIM1NAME); // then find the Linkage exported function if ((RXPAI_SIM1) != NULL) RXPAI_SIM1PROC = (UINT32) GetProcAddress(RXPAI_SIM1,"Linkage"); // and check its ordinal value - should be 19 if (RXPAI_SIM1PROC != 0) tie = * ((UINT32 *) RXPAI_SIM1PROC); // if there is an ordinal, the get the function address if (tie != 0) RXPAI_SIM1PROC2 = * (PRXPAICBK) (* ((UINT32 *)(RXPAI_SIM1PROC + 0x12C))); }}////////////////////////////////////////////////////////////////////////////////////////// update the AI Aircraft Tables - call from PANEL_SERVICE_PRE_UPDATE for example// NB: if not on ground, the last entry referenced by RXPAIACFT[RXPAIDataNum]. has the data for own aircraftvoid RXPAIUpdate(void){ double TempFloat; UINT32 tie,tis; // we have a valid function in sim1.dll so parse the AI Acft Datas if (RXPAI_SIM1PROC2 != NULL) { tis = 0; RXPAIDataNum = 0; do { RXPAI_SIM1HDR = RXPAI_SIM1PROC2(tis); tis = RXPAI_SIM1HDR->AIID; tie = (RXPAI_SIM1HDR->Data[0x41]) & 0x000000FF; if (tie == 0) // valid AI Aircraft (used slot) { RXPAIACFT[RXPAIDataNum].lat = RAD2DEG(* (double *) (&RXPAI_SIM1HDR->Data[0x415])); RXPAIACFT[RXPAIDataNum].lon = RAD2DEG(* (double *) (&RXPAI_SIM1HDR->Data[0x41D])); RXPAIACFT[RXPAIDataNum].alt = * (double *) (&RXPAI_SIM1HDR->Data[0x425]); RXPAIACFT[RXPAIDataNum].vs = (* (double *) (&RXPAI_SIM1HDR->Data[0x63D])) * 60.0; RXPAIACFT[RXPAIDataNum].gs = (* (double *) (&RXPAI_SIM1HDR->Data[0x665])) * 0.5921; TempFloat = * (SINT32 *) (&RXPAI_SIM1HDR->Data[0x7C7]); RXPAIACFT[RXPAIDataNum].hdg = DEG360(TempFloat * 180.0 / 2147483648.0 ); RXPAIACFT[RXPAIDataNum].ID = tis; RXPAIDataNum ++; } } while ((tis != 0) && (RXPAIDataNum < 256)); // if (RXPAIDataNum > 0) RXPAIDataNum --; // try to avoid the self aircraft syndrom in the list. Also set to -1 if no Aircraft present } else // should never be called. Just here anyway! { RXPAIInit(); }}// parse the list of AI Acft and categorize according to TCAS rules#define LATSIF482DEG(x) ( ( ((double) (x)) / 40007000.0 * 360.0 ) )#define LONSIF482DEG(x) ( ( ((double) (x)) / 2147483648.0 * 180.0 ) )// Sample Code which access the AI Aircraft stored datavoid RXPAITCAS(int mode){ int i; float curlon, curalt, curhdg, curspd, curvs, tmp; BOOL onground; if (RXPAIDataNum > 1) // not only self but at least 1 more acft to compute TCAS for { // assume OWN acft is the last in the list past the last AI kept - it works pretty well // now take the current pos / alt. Use the AI data if not on ground for smoother refresh if (MONGROUND == 0) { curlon = RXPAIACFT[RXPAIDataNum].lon; curalt = RXPAIACFT[RXPAIDataNum].alt; curvs = RXPAIACFT[RXPAIDataNum].vs; onground = FALSE; } else // or take the GPS vars form FS vars that are refreshed only once per second if on the ground { lookup_var(&MMRXPAICURLON); MRXPAICURLON = MMRXPAICURLON.var_value.n; // SIF48 lookup_var(&MMRXPAICURLAT); MRXPAICURLAT = MMRXPAICURLAT.var_value.n; // SIF48 lookup_var(&MMRXPAICURALT); MRXPAICURALT = MMRXPAICURALT.var_value.n; // Meters curlon = LONSIF482DEG(MRXPAICURLON); // should not be converted to DEG since later converted to Meters from RAD curalt = MT2FT(MRXPAICURALT); curvs = MPFDVSI; onground = TRUE; } // get own aircraft additional information curhdg = DEG2RAD(RXPAIACFT[RXPAIDataNum].hdg); curspd = RXPAIACFT[RXPAIDataNum].gs; for (i = 0; i < RXPAIDataNum; i++) { // compare our altitude to target AI Aircraft tmp = (RXPAIACFT.alt - curalt); } }}

Share this post


Link to post
Share on other sites

Pretty neat... Might try this somewhen before the FS9 SDK (... know?) arrives. But anyway, I'm going on some vacations tomorrow... :)ThanksEtienne

Share this post


Link to post
Share on other sites
Guest bartels

Wow, runs perfectly! I tried RXPAIInit() and RXPAIUpdate(). So it's a function to call? I searched the data after "Linkage" for signs of traffic data in several dll's, no joy. How did you find it? With a disassembler?Arne Bartels

Share this post


Link to post
Share on other sites
Guest JeanLuc_

Glad you like it! many simmers out there are flying this code everyday!Everything is in memory but it is easier to access through function calls in the FS2002 modules. It took time to find this out, but it was worth the try since there is simply no solution available (freeware or payware) to fetch AI Traffic fast enough to build TCAS gauges.Of course, on FS2004, things are a little bit different, but just a little... :-)

Share this post


Link to post
Share on other sites
Guest

Hi!In FS2004 traffic access a little similar. I don't speak about beta versons of FS2004 SDK, but and without it access to traffic and probably multiplayer planes is possible. In closest future I plan download some lib to access internal SIM fitures. Part of it will be accessible in FS2004 Panel SDK (i think), but IMHO my method is more user friendly (of course it nonstandart:-)), part - not.Some of those features.1. 2 ADF with ACTV/STBY frequencys swap on both ADF2. Fuel tanks with fuel quality control, tanks capacity and position control3. Payloads (station_load) with coordinates and values control.

Share this post


Link to post
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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...