Jump to content
Sign in to follow this  
kiek

How to get the active NAV1 frequency in C++?

Recommended Posts

Hi,I'm having a difficulty in C++ obtaining the NAV1 active frequency (in a native Win32 application). In my panel the frequency reads 107.20I call a SimConnect_AddToDataDefinition with the following parameters "Nav active frequency:1", "MHz" and SIMCONNECT_DATATYPE_FLOAT64 When the value returns I try to interpret pObjData->dwData as double, but I do not know how to convert that to integer?????If I convert to int (to get the whole value) I get a strange result.Note that if I use SIMCONNECT_DATATYPE_INT32 and I interpret the pObjData->dwData as int, I get the correct whole value 107, but then I miss the decimal part .20Any help would be appreciated.Nicohttp://www.nicokaan.nl

Share this post


Link to post
Share on other sites

>I call a SimConnect_AddToDataDefinition with the following>parameters "Nav active frequency:1", "MHz" and>SIMCONNECT_DATATYPE_FLOAT64I've always found it best to read it as "frequency BCD16", not MHz, with type INT32. This is the native format in FS. You'll get 0x0720 for a frequency of 107.20. The inital 1 is assumed (it is always 1).>When the value returns I try to interpret pObjData->dwData as>double, but I do not know how to convert that to integer?A DOWRD value is only 4 bytes in any case. The double is 8 bytes. If you've definitely read the 8 bytes just read is using a cast:double dFrequency = *((double *) &pObjData->dwData);RegardsPete


Win10: 22H2 19045.2728
CPU: 9900KS at 5.5GHz
Memory: 32Gb at 3800 MHz.
GPU:  RTX 24Gb Titan
2 x 2160p projectors at 25Hz onto 200 FOV curved screen

Share this post


Link to post
Share on other sites

Hi Pete,Thank you for your help. Your cast works perfectly! I was under the impression that a DWORD was 8 bytes too, but you have opened my eyes.I also did not know that we have the freedom to choose BCD16 instead of MHz; the Simconnect documentation is not very eleborate on that. But good to know.Thanks again.Nicohttp://www.nicokaan.nl

Share this post


Link to post
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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...