Jump to content
The simFlight Network Forums

Recommended Posts

Posted

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:

Posted
":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

Posted
":4790c]

But with wsprintf(alting, "%.2f", dAlt); I get "f"

And with sprintf(alting, "%.2f", dAlt); it's okay

Thanks !

Ah, the Windows built-in version of printf obviously doesn't support all the formats. Sorry.

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.