Jump to content
The simFlight Network Forums

How to read …


Recommended Posts

Hi

Sorry for my English I am French (and to understand the SDK with my English ....,I am 14 :cry: ...)

I am programming in C++ (with DEVC++).

And I want to read some data of Flight Simulator (altitude, speed ...).

But I can read some variable (with “expression”)

For example : for altitude (0570, S64) the expression is “#*3.28084/(65536*65536)” and with this :

int altint;
char alt[8],alting[8];
......  
if (!FSUIPC_Read(0x0840, 8, alt, &dwResult) || !FSUIPC_Process(&dwResult)) fTimeOk = FALSE;
wsprintf(alting, "%d", alt[0]);
altint=atoi(alting);
altint=altint*3.28084/(65536*65536);
wsprintf(alting, "%d", altint);

and I get : -2147483648 :(

Why ?

Other question :

How to know the nearest airport of the plane ? (ICAO)

Thanks in advance. :wink:

Link to comment
Share on other sites

":a24be]

int altint;
char alt[8],alting[8];
......  
if (!FSUIPC_Read(0x0840, 8, alt, &dwResult) || !FSUIPC_Process(&dwResult)) fTimeOk = FALSE;
wsprintf(alting, "%d", alt[0]);
altint=atoi(alting);
altint=altint*3.28084/(65536*65536);
wsprintf(alting, "%d", altint);

and I get : -2147483648 :(

Why ?

Well, there are several things wrong here.

First, offset 0x0840 is a 2-byte "Crashed" flag, not any altitude at all. Where are you looking for your offset values? The aircraft altitude is a 64 bit signed integer at offset 0x0570.

Second, you are reading it as if it is an 8 character string!? why? It is a signed 64-bit integer. If your compiler supports it, define it as an __int64.

In this line:

wsprintf(alting, "%d", alt[0]);

you appear to be converting the value in the first 8 bits (for "alt[0]" is a character, which is 8 bits) into character form, so evidently you did realise, somewhere, that you weren't reading a string. However, the first 8 bits of a 64-bit number won't be very useful.

Then in these lines:

altint=altint*3.28084/(65536*65536);

wsprintf(alting, "%d", altint);

you do the accurate conversion from metres and fractional metres to feet, but store the result back into an integer. If you want the altitude to the whole number of feet blow, I suppose that's okay, but if you want more accuracy consider using floating point.

Try:

__int64 alt;
double dAlt;
char alting[8];
......  
if (!FSUIPC_Read(0x0570, 8, &alt, &dwResult) || !FSUIPC_Process(&dwResult)) fTimeOk = FALSE;
dAlt=alt*3.28084/(65536.0*65536.0);
wsprintf(alting, "%.2f", dAlt);

If your compiler doesn't support 64-bit integers then it gets a bit more complicated. You'd have to read it into two 32-bit values and treat them separately, as integral and fractional parts.

How to know the nearest airport of the plane ? (ICAO)

You'd need to search an airport database, having obtained the aircraft's Latitude and Longitude. There *should* be a way to find it inside FS, but I don't know how.

Regards,

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.