Jump to content
The simFlight Network Forums

Fractional Altitude


Recommended Posts

Im having trouble getting the fractional part of the altitude at offset 0570. I can read the unit part at 0574, however im unsure of how to convert the fractional part at 0570. At the moment ive tried dividing by 10^9 then adding to the unit part. This gives an approximate value. But when I write to the fractional value and try to multiply by 10^9 I get an overflow (VB.NET).

How do I handle the fractional part?

Link to comment
Share on other sites

Im having trouble getting the fractional part of the altitude at offset 0570. I can read the unit part at 0574, however im unsure of how to convert the fractional part at 0570. At the moment ive tried dividing by 10^9 then adding to the unit part. This gives an approximate value. But when I write to the fractional value and try to multiply by 10^9 I get an overflow (VB.NET).

How do I handle the fractional part?

Where do you get 10^9 from? The values aren't decimal! The fractional part is a value ranging from 0 to 2^32-1 and represents the number of 1/2^32 parts of a metre (i.e. 2^-32).

Think about it. It is a fixed point binary number with the "binary point" at the 32:32 bit boundary. The whole number is 64 bits in length, with the high 32-bits representing the number of whole metres and the lower 32-bits the fractions. A value there of 0x80000000 would represent exactly half a metre, as the bit just below the binary point is the only one set, representing 2^-1, or a half. And so on. Each bit down represents half again, exactly as they should in binary.

Regards,

Pete

Link to comment
Share on other sites

Ok i got it working finally. As you said the value is unsigned, and represents the number of 2^32 parts. Anyway was continually reading negative numbers, and soon found out that the VB.NET SDK does not have the capability to handle unsigned numbers. Anyway I added some code which I wil post here for anyone else who ever runs into such a problem.

Overloads Function FSUIPC_Get(ByRef Token As Integer, ByRef Result As UInt32) As Boolean
        Dim Size As Integer = 8    ' 8 bytes in a Double
        Dim InBuf(8) As Byte
        Dim i As Integer
        If (Token < 0) Or (Token > IPC_BUFFER_SIZE - (4 + Size)) Then 'Token out of range
            Result = Convert.ToUInt32(0) 'This line changed
            FSUIPC_Get = False
            Exit Function
        End If
        Result = BitConverter.ToUInt32(IPC, Token + 4)
        If IPCdr(Token) Then
            IPCdr(Token) = False
            FSUIPC_Get = True
        Else    ' If data ready flag not set, function returns FALSE and value found
            FSUIPC_Get = False
        End If
End Function

The change is:

Result = BitConverter.ToUInt32(IPC, Token + 4)

Which converts to unsigned 32bit integer. You may have to do a conversion back to double or signed integer in your code to perform any calculations.

Hope this helps someone.

Link to comment
Share on other sites

the VB.NET SDK does not have the capability to handle unsigned numbers.

Ouch! What sort of programing language restricts you so? That's awful. I've always thought VB was pretty terrible in any case (string handling problems, difficulties handling pointer-using interfaces which are very common in Windows, and the daft way it converts hexadecimal 0FFFF to FFFFFFFF with no warning unless you know some magic like postpending an & or something).

I'm please you sorted it out though.

Regards,

Pete

Link to comment
Share on other sites

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.