1. no result when reading FSUIPC aircraft longitude or latitude

Hello guys,

I programming with delphi...

on the project magneta website there is this posted:

Longitude of aircraft in FS format.

To convert to Degrees:

If your compiler supports long long (64-bit) integers then use such a variable to simply copy this 64-bit value into a double floating point variable and multiply by 360.0/(65536.0 * 65536.0 * 65536.0 * 65536.0).

Otherwise you will have to handle the high 32-bits and the low 32-bits separately, combining them into one double floating point value (say dHi). To do, copy the high part (the 32-bit int at 056C) to one double and the low part (the 32-bit unsigned int at 056 to another (say dLo). Remember that the low part is only part of a bigger number, so doesn’t have a sign of its own. Divide dLo by (65536.0 * 65536.0) to give it its proper magnitude compared to the high part, then either add it to or subtract it from dHi according to whether dHi is positive or negative. This preserves the integrity of the original positive or negative number. Finally multiply the result by 360.0/(65536.0 * 65536.0) to get degrees.

Either way, a negative result is West, positive East. If you did it all unsigned then values over 180.0 represent West longitudes of (360.0 – the value).

[Can be written to move aircraft: in FS2002 only in slew or pause states]

here is my source code:

Code:
```var dwresult : dword;
Longitude : integer;
wert : uint64;
Latitude : int64;
lon : extended;
temp : string;
begin
//FSUIPC_Open(SIM_ANY, dwResult) ;

if FSUIPC_Process(dwResult) then
begin
latitude := latitude * 90;
showmessage(floattostr(57.296 * (latitude /(10001750*65536.0*65536.0))));
end;
end;```
but there are no usefull result! who can help me?

2. Re: no result when reading FSUIPC aircraft longitude or latitude

Here is the C# code from the FSPUIC SDK: You can use the same teqnique:

Code:
```double latHi = 0;
double latLo = 0;
double latitude = 0;

double longHi = 0;
double longLo = 0;
double longitude = 0;

....

// Get latitude
result = fsuipc.FSUIPC_Read(0x0564, 4, ref token, ref dwResult);
result = fsuipc.FSUIPC_Process(ref dwResult);
result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
latHi = dwResult;

result = fsuipc.FSUIPC_Read(0x0560, 4, ref token, ref dwResult);
result = fsuipc.FSUIPC_Process(ref dwResult);
result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
latLo = dwResult;

if (latLo != 0)
{
latLo = latLo / (65536.0 * 65536.0);
}
if (latHi > 0)
{
latitude = latHi + latLo;
}
else
{
latitude = latHi - latLo;
}

if (result)
{
txtFullCycle.Text = "Result = true (Successful)";
txtResults1.Text = dwResult + " lat (FS units)";
}
else
{
txtFullCycle.Text = "Result = false (Unsuccessful)";
}

// Get longitude
result = fsuipc.FSUIPC_Read(0x056C, 4, ref token, ref dwResult);
result = fsuipc.FSUIPC_Process(ref dwResult);
result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
longHi = dwResult;

result = fsuipc.FSUIPC_Read(0x0568, 4, ref token, ref dwResult);
result = fsuipc.FSUIPC_Process(ref dwResult);
result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
longLo = dwResult;

if (longLo != 0)
{
longLo = longLo / (65536.0 * 65536.0);
}
if (longHi > 0)
{
longitude = longHi + longLo;
}
else
{
longitude = longHi - longLo;
}

if (result)
{
txtFullCycle.Text = "Result = true (Successful)";
txtResults1.Text = latitude + " lat (FS units)";
txtResults2.Text = longitude + " long (FS units)";
}
else
{
txtFullCycle.Text = "Result = false (Unsuccessful)";
}```

3. Re: no result when reading FSUIPC aircraft longitude or latitude

Originally Posted by SimStar001
latitude := latitude * 90;
showmessage(floattostr(57.296 * (latitude /(10001750*65536.0*65536.0))));
Excuse my ignorance, but can you say why you multiplied by 90? And why you didn't use the formula as posted in the PM site? So where does 57.296 and 10001750 come from? Just trying to understand

4. Re: no result when reading FSUIPC aircraft longitude or latitude

I assume the multification with 90 is because there are 90 degrees of latitude in each hemisphere and the variable "latitude" is a fraction. e.g. 0.9.

Pete Downson is the guy who is the guy behind FSPUIC and on his website is a downloadable SDK for FSPUIC. I am using that as a reference.

I used the C# example before and it works.

Hope it helps.

5. Re: no result when reading FSUIPC aircraft longitude or latitude

Hello,

Since I code with delphi as well, here are my two cents.

(by the way, offset 0560 and 0568 are 8 bytes long)
Code:
```var dwresult : dword;
Longitude : integer;
Latitude,longitude  : int64;
begin

if FSUIPC_Process(dwResult) then
begin
latitude := latitude / 10001750;
latitude := latitude /65536 ;
latitude := latitude /65536 ;
latitude := latitude *90;  //I separate those lines as sometimes it causes stack overflow on my system)
longitude := longitude / 65536 ;
longitude := longitude /65536 ;
longitude := longitude /65536 ;
longitude := longitude /65536 ;
longitude := longitude *360;
showmessage(floattostr(latitude+'  /  '+longitude ));
end;```

What I don't get though is the 57.296 factor?
If you're trying to write the data in FS (and not read from FS) then you'll need to use FSUIPC_Write procedure instead.

Hope that helps...

6. Re: no result when reading FSUIPC aircraft longitude or latitude

Originally Posted by jeehell
Hello,

Since I code with delphi as well, here are my two cents.

(by the way, offset 0560 and 0568 are 8 bytes long)
Code:
```var dwresult : dword;
Longitude : integer;
Latitude,longitude  : int64;
begin

if FSUIPC_Process(dwResult) then
begin
latitude := latitude / 10001750;
latitude := latitude /65536 ;
latitude := latitude /65536 ;
latitude := latitude *90;  //I separate those lines as sometimes it causes stack overflow on my system)
longitude := longitude / 65536 ;
longitude := longitude /65536 ;
longitude := longitude /65536 ;
longitude := longitude /65536 ;
longitude := longitude *360;
showmessage(floattostr(latitude+'  /  '+longitude ));
end;```

What I don't get though is the 57.296 factor?
If you're trying to write the data in FS (and not read from FS) then you'll need to use FSUIPC_Write procedure instead.

Hope that helps...
I thought there might be issues with stack over/underflow when I saw the formula implementation in the OP's post. Maybe doing the calcs one line at a time would work better - except for error accumulation.

7. Re: no result when reading FSUIPC aircraft longitude or latitude

P1IC, out of curiosity, why the "latitude / 10001750" statement?

Also can't see the purpose of the 57.296 factor?

8. Re: no result when reading FSUIPC aircraft longitude or latitude

Originally Posted by fweinrebe
P1IC, out of curiosity, why the "latitude / 10001750" statement?

Also can't see the purpose of the 57.296 factor?
These are my questions to the OP. The OP declared these in his original post.

9. Re: no result when reading FSUIPC aircraft longitude or latitude

Originally Posted by SimStar001
on the project magneta website there is this posted
Two points:

1. Best to come to the published Support Forum for FSUIPC questions. I won't normally answer them here.

2. You should be using the materials in the FSUIPC SDK, not out of date offset documentation posted on some other site.