Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi All,

I’m looking for an example Lua script that will read the TCAS table at offset 0xD000. I’ve written a fair amount of Lua in the past, so I’m sure I can cobble it together. However, I’m a big fan of module reuse and why reinvent the wing?

 

Can anyone direct me to such an example?

 

Thanks in anvance.

 

SeattleSleeper

  • 2 weeks later...
Posted

Hi Pete,

 

After a little more research, I've determined this is something much more suited to C/C++.  Also, it seems the information I want from TCAS is better collected from offet 0xF080. Something like this (without the open, close and error checking);

 

 struct TCAS {   // TCAS_Table Structure
   DWORD ID;
   float lat;  
   float lon;  
   float alt;  
   WORD hdg;
   WORD gs;
   short vs;
   char idATC[15];
   BYTE bState;
   WORD com1;
} MyTable[96];

 

    unsigned int tcas_len = 96;

    unsigned int tcas_base = 0xF080;
    unsigned int tcas_offset = 0x0028;
    unsigned int tcas_ID = 0x0000;
    unsigned int tcas_lat = 0x0004;
    unsigned int tcas_lon = 0x0008;
    unsigned int tcas_alt = 0x000C;
    unsigned int tcas_hdg = 0x0010;
    unsigned int tcas_gs = 0x0012;
    unsigned int tcas_vs = 0x0014;
    unsigned int tcas_idATC = 0x0016;
    unsigned int tcas_bState = 0x0025;
    unsigned int tcas_com1 = 0x0026;
    unsigned int i;
  

 

for(i = 0; i <= tcas_len; i++)
    {
        FSUIPC_Read(tcas_base+(i * tcas_offset), sizeof(DWORD), (void*)&MyTable.ID, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_lat, sizeof(float), (void*)&MyTable.lat, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_lon, sizeof(float), (void*)&MyTable.lon, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_alt, sizeof(float), (void*)&MyTable.alt, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_hdg, sizeof(WORD), (void*)&MyTable.hdg, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_gs, sizeof(WORD), (void*)&MyTable.gs, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_vs, sizeof(short), (void*)&MyTable.vs, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_idATC, 15, MyTable.idATC, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_bState, sizeof(byte), (void*)&MyTable.bState, &dwResult);
        FSUIPC_Read(tcas_base+(i * tcas_offset)+ tcas_com1, sizeof(WORD), (void*)&MyTable.com1, &dwResult);
    }
    FSUIPC_Process(&dwResult);

 

QUESTION#1 Should I put the "FSUIPC_Process" inside the loop? (too many reads to do at once with it outside the loop?)

QUESTION#2 If i use an external Win32 exe, will this also have less impact on the FSX VAS?

 

Thanks,

 

Terry

Posted

After a little more research, I've determined this is something much more suited to C/C++.  Also, it seems the information I want from TCAS is better collected from offet 0xF080. Something like this (without the open, close and error checking);

 

Why separate reads? Just read the whole structure as one item. In fact read ALL of the table, every entry, in one go, into your array of TCAS structures. i.e. just one read, no loop, like this:

 

 FSUIPC_Read(tcas_base, sizeof(MyTable), (BYTE*) &MyTable);

 

QUESTION#1 Should I put the "FSUIPC_Process" inside the loop? (too many reads to do at once with it outside the loop?)
 
Only one Process for all the reads you want to do in one cycle. Each process call means a change of process, twice -- back and forth. it is very inefficient to do more Process calls than needed. Up to 30,000 bytes of assorted data can be transferred in one Process, almost as fast as one byte if on the same PC as FS, because it's all done by shared memory.
 

QUESTION#2 If i use an external Win32 exe, will this also have less impact on the FSX VAS?

 

Yes, far better for any FSUIPC client to be external to FS. Why would you want the hassle of trying to make it work inside FS? It's not easy. Were you thinking of using the Gauge SDK?

 

Pete

 

Posted (edited)

Hi Pete,

 

Thank you for your prompt and helpfull reply!

 

 

Why separate reads? Just read the whole structure as one item. In fact read ALL of the table, every entry, in one go, into your array of TCAS structures. i.e. just one read, no loop, like this:

 

 FSUIPC_Read(tcas_base, sizeof(MyTable), (BYTE*) &MyTable);

 


 

 

Lack of practice in C/C++. It's been 15-20 years since I've had the need to code any C.

I'm not planning on using the Gauge SDK. This is the ground work for a rather unusual application. It will be used in Multiplayer in conjunction with B17 bomber missions with a few "aggressor" aircraft thrown into the mix. Right now I'm calling it the "Boge Module." The application will be timer event driven to;

1. Collect the TCAS data of all multi-player aircraft

2. Search the idATC for a string subset, (FW, Bf, ME, Do, etc…)

3. Compute convergence/divergence with the bomber stream

4. Trigger B17 crew voice over for converging "Bogies"

5. Detect close proximity of the "Bogies" to your aircraft (gun run)

6. Trigger audio of B17 guns defending against the "Boge", more crew voice over and shell strikes on the B17 airframe.

7. Compute a random chance of damage to the B17 and inflict damage using a write to local panel variables.

 

I've been able to do a similar module for FLAK for the B17 using Lua, Lvars and a table of lat,lon where our FLAK controllers are placed. It works quiet well. We call it the "Pucker Module." It randomly inflicts anything from a few cylinder failures to engine fires and total system failures. The guys never look at FLAK the same way after one flight with the "Pucker."

 

QUESTION: What method can I use to read/write local panel variables from this WIN32 application?

 

Thanks,

 

Terry

 

Terry

Edited by SeattleSleeper
Posted

QUESTION: What method can I use to read/write local panel variables from this WIN32 application?

 

Without using Lua (to read), or Lua or button/key macros (to write), you cannot. It can only be done from an internal module or gauge.

 

Pete

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.