Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    75+ Posting Member
    Join Date
    Oct 2008
    Location
    Germany
    Posts
    83
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    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_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?

  2. #2
    Heli Builder fweinrebe's Avatar
    Join Date
    May 2008
    Location
    Namibia
    Posts
    325
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    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 | C# Avionics | CNC)

  3. #3
    75+ Posting Member
    Join Date
    Apr 2008
    Location
    Frankford, Ontario
    Posts
    76
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: no result when reading FSUIPC aircraft longitude or latitude

    Quote Originally Posted by SimStar001 View Post
    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. #4
    Heli Builder fweinrebe's Avatar
    Join Date
    May 2008
    Location
    Namibia
    Posts
    325
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    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 | C# Avionics | CNC)

  5. #5
    2000+ Poster - Never Leaves the Sim
    Join Date
    Mar 2008
    Location
    France,Nice
    Posts
    2,426
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

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

  6. #6
    75+ Posting Member
    Join Date
    Apr 2008
    Location
    Frankford, Ontario
    Posts
    76
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: no result when reading FSUIPC aircraft longitude or latitude

    Quote Originally Posted by jeehell View Post
    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...
    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. #7
    Heli Builder fweinrebe's Avatar
    Join Date
    May 2008
    Location
    Namibia
    Posts
    325
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    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 | C# Avionics | CNC)

  8. #8
    75+ Posting Member
    Join Date
    Apr 2008
    Location
    Frankford, Ontario
    Posts
    76
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: no result when reading FSUIPC aircraft longitude or latitude

    Quote Originally Posted by fweinrebe View Post
    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. #9
    500+ This must be a daytime job
    Join Date
    Jan 2007
    Posts
    564
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: no result when reading FSUIPC aircraft longitude or latitude

    Quote Originally Posted by SimStar001 View Post
    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

  10. #10
    75+ Posting Member
    Join Date
    Apr 2008
    Location
    Frankford, Ontario
    Posts
    76
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    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…

Page 1 of 2 12 LastLast

Similar Threads

  1. Code help for ColdandDark and TestOvhd for Latitude and Longitude script
    By mick_LD767 in forum lekseecon Q&A and Discussions
    Replies: 5
    Last Post: 07-16-2010, 12:40 PM
  2. Latitude/Longidude type WPT is not accepted
    By dl4saw in forum PM Boeing FMC/CDU
    Replies: 4
    Last Post: 01-03-2010, 08:01 AM
  3. 747, 757, 767 Reading Light
    By mascot in forum Off Site Articles For Sale
    Replies: 0
    Last Post: 10-29-2009, 06:03 AM
  4. recommended reading
    By Jackpilot in forum General Builder Questions All Aircraft Types
    Replies: 1
    Last Post: 10-17-2008, 10:59 AM
  5. Interesting reading
    By bindook in forum MyCockpit Crew Rest (Off topic chat forum)
    Replies: 0
    Last Post: 01-23-2007, 05:18 AM