Results 1 to 10 of 13
-
08-17-2009, 01:59 PM #1
- Join Date
- Oct 2008
- Location
- Germany
- Posts
- 86
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 056to 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_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;
-
08-17-2009, 02:11 PM #2
- Join Date
- May 2008
- Location
- Earth
- Posts
- 288
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)"; }
Fritz -> Helicopter Cockpit Builder
(FSX | TH2Go | Arduino | Air Manager Avionics | CNC)
-
08-17-2009, 02:18 PM #3
- Join Date
- Apr 2008
- Location
- Frankford, Ontario
- Posts
- 59
-
08-17-2009, 02:34 PM #4
- Join Date
- May 2008
- Location
- Earth
- Posts
- 288
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.Fritz -> Helicopter Cockpit Builder
(FSX | TH2Go | Arduino | Air Manager Avionics | CNC)
-
08-17-2009, 04:55 PM #5
- Join Date
- Mar 2008
- Location
- France,Nice
- Posts
- 2,652
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_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...
-
08-17-2009, 05:12 PM #6
- Join Date
- Apr 2008
- Location
- Frankford, Ontario
- Posts
- 59
-
08-17-2009, 05:25 PM #7
- Join Date
- May 2008
- Location
- Earth
- Posts
- 288
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?Fritz -> Helicopter Cockpit Builder
(FSX | TH2Go | Arduino | Air Manager Avionics | CNC)
-
08-17-2009, 05:54 PM #8
- Join Date
- Apr 2008
- Location
- Frankford, Ontario
- Posts
- 59
-
08-17-2009, 07:58 PM #9
- Join Date
- Jan 2007
- Posts
- 496
Re: no result when reading FSUIPC aircraft longitude or latitude
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)
Please use the Forum and please use the documentation supplied for programming to the FSUIPC interface.
Regards
Pete
-
08-17-2009, 09:11 PM #10
- Join Date
- Apr 2008
- Location
- Frankford, Ontario
- Posts
- 59
Re: no result when reading FSUIPC aircraft longitude or latitude
Well said, as always, Pete! You picked up what I didn't about the offset requirement. No surprise there…
Similar Threads
-
Latitude/Longidude type WPT is not accepted
By dl4saw in forum PM Boeing FMC/CDUReplies: 4Last Post: 01-03-2010, 08:01 AM -
747, 757, 767 Reading Light
By mascot in forum Off Site Articles For SaleReplies: 0Last Post: 10-29-2009, 05:03 AM -
recommended reading
By Jackpilot in forum General Builder Questions All Aircraft TypesReplies: 1Last Post: 10-17-2008, 09:59 AM