Jump to content
The simFlight Network Forums

Plane's Current Mass - FSUIPC OffSet 0x30C8 (FLOAT64) ???


Recommended Posts

Hi,

I've been trying to get the plane current mass based on the "FSUIPC for Programers" document.

Unfortunately, I can't understand how this FLOAT64 value is coded. I can see all the 8 bytes of this offset decreasing while the plane is flying, but I can't understand how can I use them to get the plane's current mass value. I tried several aproaches, including IEEE-754 floating-point recomendation, but it simply doesn't fit on this.

My main question is:

- How to get the plane's current mass from the 8 bit value on offset 0x30C8???

Thank you,

Kind Regards

J. Sequeira

Link to comment
Share on other sites

You need to say what programmng languge you are using to get specific help for how to handle them in that specific language.

However, in general you need to cast the 8-byte value directly to a 64 bit floating point type, (it's not an an 8byte Integer). The name of this type varies from language to language, as does the method of casting. In many languages the type you need is called a 'Double.

Paul

Link to comment
Share on other sites

Hi Paul,

I'm using VB6. I based the code on a Peter Dowson's VB sample. Then I built some additional procedures and functions to handle each value.

I'll try to follow your indication. However, I think I've tried to do exactly what you said. May be the implementation was not the correct one...

The base sample I use to return integer values, is like this:

Private Function Read_Value(v As Long, n As Long) As Double

Dim dwResult As Long

Dim r() As Byte

Dim res As Double

ReDim r(n)

If FSUIPC_Read(v, n, VarPtr(r(1)), dwResult) Then

If FSUIPC_Process(dwResult) Then

res = 0#

f = 1#

For i = 1 To n

res = res + f * r(i)

f = f * 256#

Next i

Else

' Can't process

End If

Else

' Can't read

End If

Read_Value = res

End Function

How could I change this function to get a correct return to FLOAT64 value type?

Thanks in advance,

Kind regards,

Joao Sequeira

Link to comment
Share on other sites

Hi Paul (again),

Based on the previous message I wrote you, I'm going to try this and tell you later if it works:

------------------------------------------------------------------------

Private Function Read_Value(v As Long, n As Long) As Double

Dim dwResult As Long

Dim r() As Double

Dim res As Double

ReDim r(1)

If FSUIPC_Read(v, n, VarPtr(r(1)), dwResult) Then

If FSUIPC_Process(dwResult) Then

res = r(i)

Else

' Can't process

End If

Else

' Can't read

End If

Read_Value = res

End Function

------------------------------------------------------------------------

Kind regards,

Joao Sequeira

Link to comment
Share on other sites

Hi Joao,

Your code looks like it will work (except you need to change the res = r(i) to res = r(1) )

However, it's a bit more compilcated than it need be - you don't need to use an array of doubles:

This should be all you need to do, but I don't have VB6 on my machine anymore so I can't test it:

------------------------------------------------------------------------

Private Function Read_Value(v As Long, n As Long) As Double 

Dim dwResult As Long 
Dim res As Double 
If FSUIPC_Read(v, n, VarPtr(res), dwResult) Then 
   If FSUIPC_Process(dwResult) Then 
       Read_Value = res
    Else 
     ' Can't process 
   End If 
Else 
   ' Can't read 
End If 

End Function 

------------------------------------------------------------------------

Give that a try. If it doesn't work I'm sure a proper VB6 programmer will stop by and help you out. :-)

Paul

Link to comment
Share on other sites

Hi Paul, :D

Thank you for your first comment.

I tried the things I posted on the previous replies, and as I told you, I didn't succed on the first try.

However, I was doing a mistake: the "n" parameter must still be "8", and not "1", as I put it, despite the fact that we are not getting separate bytes but a single value.

So, putting the type as double, as you suggested, and putting n=8 on the function argument, the result is perfect!

Then we just have to convert from slug's to pounds, and the value is exactly what we get from the Flight Simulator interface.

Thanks a lot, :D

Kind regards,

Joao Sequeira

Lisbon, Portugal

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

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