Log in

View Full Version : no result when reading FSUIPC aircraft longitude or latitude



SimStar001
08-17-2009, 01:59 PM
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 0568) 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:


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

if FSUIPC_Read($0560,3, @latitude, dwResult) then
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?

fweinrebe
08-17-2009, 02:11 PM
Here is the C# code from the FSPUIC SDK: You can use the same teqnique:




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)";
}

P1IC
08-17-2009, 02:18 PM
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 :shock:

fweinrebe
08-17-2009, 02:34 PM
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. :-)

jeehell
08-17-2009, 04:55 PM
Hello,

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



(by the way, offset 0560 and 0568 are 8 bytes long)


var dwresult : dword;
Longitude : integer;
Latitude,longitude : int64;
begin

if (FSUIPC_Read($0560,8, @latitude, dwResult))and(FSUIPC_Read($0568,8, @longitude, dwResult)) then
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...

P1IC
08-17-2009, 05:12 PM
Hello,

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



(by the way, offset 0560 and 0568 are 8 bytes long)


var dwresult : dword;
Longitude : integer;
Latitude,longitude : int64;
begin

if (FSUIPC_Read($0560,8, @latitude, dwResult))and(FSUIPC_Read($0568,8, @longitude, dwResult)) then
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.

fweinrebe
08-17-2009, 05:25 PM
P1IC, out of curiosity, why the "latitude / 10001750" statement?

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

P1IC
08-17-2009, 05:54 PM
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. :D

Peter Dowson
08-17-2009, 07:58 PM
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.


if FSUIPC_Read($0560,3, @latitude, dwResult)

Why are you only reading the first 3 bytes of the 8-byte (i.e. 64 bit) latitude value? What result do you think you will get? Those represent the least significant 24 bits of a 64 bit number. They probably will be zero.

Please use the Forum and please use the documentation supplied for programming to the FSUIPC interface.

Regards

Pete

P1IC
08-17-2009, 09:11 PM
Well said, as always, Pete! You picked up what I didn't about the offset requirement. No surprise there…

SimStar001
08-18-2009, 12:30 AM
Thanks for the good help...
Iwill try it today...
@pete... Where is the public forum loceted? so that i can use it next time?

Peter Dowson
08-18-2009, 05:41 AM
Thanks for the good help...
Iwill try it today...
@pete... Where is the public forum loceted? so that i can use it next time?

It is the one pointed to from the Schiratti download page, where you downloaded FSUIPC. It is also the one with a link to it on the first TAB in the FSUIPC options screen in FS. It is also the one linked to in the purchase pages on SimMarket where you buy FSUIPC and WideFS. It is also the one with links published in the FSUIPC documentation.

In fact it is one which it should be really difficult to miss. So how did you?

To save you all the bother of looking in any of these important places, I repeat the link here, but I am really saddened by the fact that you even have to ask such a question. I really don't know what else to do, where else to publish the link. :-(

http://forums.simflight.com/viewforum.php?f=54

Whilst you are there, please note the first Announcement, the one at the top. There you will often find new versions and other useful things.

Pete

SimStar001
08-18-2009, 10:52 AM
ok I have solved the problem with the latitude. this is now correct, but I also have a problem with the longitude....

pleas have a look to this link: http://forums.simflight.com/viewtopic.php?f=54&t=77285