Jump to content
The simFlight Network Forums

Detecting low visibility (fs2004)


Recommended Posts

Hi guys,

I'm writing a simply DLL in order to detect visibility distance and condition an object in my scenery. Here's the code:

#include "fsmodule.h"
#include 
#include "FSUIPC_User.h"


LINKAGE Linkage =
{
    //0x000002d9,
    0x00000000,
    module_init,
    module_deinit,
    0,
    0,
    0x900,
    NULL
};

IMPORTTABLE ImportTable =
{
    {
        0x00000000, NULL
    }
};

WORD      LowVis=1;
UINT_PTR   TimerFSUIPC, VisibilityTimer;
BYTE      FSUIPCMemory[500];

VOID CALLBACK Visibility(HWND hwnd, UINT uMsg,UINT_PTR idEvent, DWORD dwTime)
{
   DWORD      dwResult;
   BYTE      IsLowVisibility;

    FSUIPC_Write(0x8001, 12, "IKB3BI67TCHEtest.dll", &dwResult);
    FSUIPC_Process(&dwResult);

   FSUIPC_Read(0x0E8A, 2, (BYTE*)&IsLowVisibility, &dwResult);
   FSUIPC_Process(&dwResult);

   //visibility is lower than 3 miles
   if (IsLowVisibility<=3.0) {
      FSUIPC_Write(0x0DDE, 2, &LowVis, &dwResult);
      FSUIPC_Process(&dwResult);
   }
}

VOID CALLBACK InitFSUIPC(HWND hwnd, UINT uMsg,UINT_PTR idEvent, DWORD dwTime)
{
   DWORD dwResult;
   if (FSUIPC_Open2(SIM_ANY, &dwResult, (BYTE*)FSUIPCMemory, 500)) {
      KillTimer(NULL,TimerFSUIPC);
      VisibilityTimer=SetTimer(NULL,1,2000,Visibility);
   }

}
void FSAPI module_init ()
{
   TimerFSUIPC=SetTimer (NULL,0,2000,InitFSUIPC);   
} 

void FSAPI module_deinit ()
{
   KillTimer (NULL,VisibilityTimer);
   FSUIPC_Close ();
}

Basically nothing happens, the DLL should be ok, what's wrong?

tx!

Link to comment
Share on other sites

I'm writing a simply DLL in order to detect visibility distance and condition an object in my scenery. Here's the code

...Basically nothing happens, the DLL should be ok, what's wrong?

Don't you think you should be doing some debugging?

I can immediately see two things wrong just with a casual glance:

1. You are reading a two-byte (16bit) value into a single byte variable. That alone is going to corrupt something.

2. You are comparing that (one byte!) value, which would, if it were possible in one byte, be in units of 100 x statute miles, as documented, with a floating point double (0.3) -- it will of course NEVER be less than 0 as it is unsigned!

You also seem to be using a Key, IKB3BI67TCHE, which I don't think is a valid application key and which certainly hasn't been issued to a "test.dll" as far as my records show.

You shouldn't really be writing to offset 8001 on every cycle. If you want to do one-off things like that, do it after the Open2() call, just the once. However, with any reasonably recent version of FSUIPC you do not need to write any key anywhere.

Why not try using your debugger? Also make use of FSUIPC's logging facilities -- you can log your IPC reads and writes.

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.