Jump to content
Sign in to follow this  
Guest Patrick_Waugh

FLOAT64 to wstring

Recommended Posts

Guest Patrick_Waugh

When you use some code like this: FLOAT64 freq; execute_calculator_code("(A:ADF STANDBY FREQUENCY:1, KHz)", &freq, NULL, NULL);to read the ADF freq, what are you then doing to get it into text?If the ADF is tuned to say 315.0, what is in the FLOAT64?

Share this post


Link to post
Share on other sites

Patrick, the benefit of using this method to fetch the ADF frequency is that the return is in KHz, and therefore needs no BCD to DEC conversion... ;)Here is a code segment from my Honewell RTU, which features 2 ADF memory slots.fron the Honeywell_RTU.h file, the variables used://////////////////////////////////////////FLOAT64 adf1_frequency = 0;FLOAT64 ADF_MemA = 0;FLOAT64 ADF_MemB = 500; // defaults to 500 KHz???bool AdfFlag = false;int adf1_freq_high_carry = 0;//////////////////////////////////////////from the functions.cpp file:execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)",&adf1_frequency,NULL,NULL);if (AdfFlag == false) { ADF_MemA = adf1_frequency; }if (AdfFlag == true) { ADF_MemB = adf1_frequency; }char cString[8] = ""; sprintf(cString, "%07.2f", adf1_frequency); // since the character "0" is ascii code 48, // then subtracting 48 from the character code of // the desired character gives us the numeric equivalent. adf1_freq_high_carry = cString[2] - 48;//////////////////////////////////////////and, in case you're wondering what the devil the adf1_freq_high_carry is used for, here's a snip from the Honeywell_RTU_MouseFunctions.cpp file. This allows my "universal knob" to keep track of the decimal rollover:////////////////////////////////////////// if ( ( pagebutton == 1 && Pg1SelectCurs == 9 && dimbutton == 0 ) || ( pagebutton == 8 && Pg8SelectCurs == 7 && dimbutton == 0 ) ) { if (rtuthousandsknob == 1) { trigger_key_event (KEY_ADF_10_INC,0); if (adf1_freq_high_carry == 9) { trigger_key_event(KEY_ADF_100_INC,0); } rtuthousandsknob = 0; PageTimer = 0; } if (rtuthousandsknob == -1) { trigger_key_event (KEY_ADF_10_DEC,0); if (adf1_freq_high_carry == 0) { trigger_key_event(KEY_ADF_100_DEC,0); } rtuthousandsknob = 0; PageTimer = 0; } }


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Paradoxically, I don't mind the BCD stuff. =)But, I can't get at the ADF freq's without the XML vars, so I'm stuck trying to use that method.I'll try this:wstring RadioPage::GetAdf1Active(){ FLOAT64 freq; WCHAR freqStr[8] = {0}; execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz)", &freq, NULL, NULL); swprintf_s(freqStr, 8, L"%07.2f", freq); return freqStr;}For the COM freq's I'm using this:wstring RadioPage::GetCom1Active(){ lookup_var(&m_com_frequency); lookup_var(&m_com_radio_25_khz_tunable); UINT32 bcd = m_com_frequency.var_value.d; m_Com1Freq[0] = '1'; m_Com1Freq[1] = ((bcd >> 12) & 0xF) + 0x30; m_Com1Freq[2] = ((bcd >> 8) & 0xF) + 0x30; m_Com1Freq[3] = '.'; m_Com1Freq[4] = ((bcd >> 4) & 0xF) + 0x30; m_Com1Freq[5] = ((bcd) & 0xF) + 0x30; if(m_Com1Freq[5] == '2' || m_Com1Freq[5] == '7') { m_Com1Freq[6] = '5'; m_Com1Freq[7] = '0'; // NULL Terminator } else { m_Com1Freq[6] = '0'; // NULL Terminator } m_Com1Freq[7] = '0'; // NULL Terminator wstring wstr = m_Com1Freq; return wstr;}Which is fine. Sometime I'll profile the alternate method and see which is faster.

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