Jump to content

Recommended Posts

This time I'm sure I'm not blind, but I'd like the (negative) confirmation from someone else. Is there an ADF2 equivalent of KEY_ADF_EXTENDED_SET, 'coz I can't see it and I suspect it's not there.... and if not, can someone give me a hint as to how to achieve the extended decimals for ADF2?Ta!! -Dai

Share this post


Link to post
Share on other sites

Confirm that there is no ADF2 variant of KEY_ADF_EXTENDED... and other ADF problems too, like KEY_ADF_COMPLETE_SET does not work (KEY_ADF_SET does work) and KEY_ADF2_COMPLETE_SET does not appear to work either ('appear' because I haven't hammered this as hard as KEY_ADF_COMPLETE_SET).Given that, would someone be kind enough to tell me what the problem is with the following code? It compiles but doesn't do anything. adf_freq contains the new frequency in decimal (e.g. 346):execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz) (>K:adf_freq)", NULL, NULL, NULL);-Dai

Share this post


Link to post
Share on other sites

Dai, Donot know if this will help but here goes,, ADF COMPLETE 1 & 2 do work but it does not take decimal input.. IIRC it is some sort of base 16/32/64 or something, here is my conversion code from decimal to it's proper format. Sorry just in XML.

10000 * s0 10 % s2 l0 10 / flr 10 % 16 * l2 + s2 l0 100 / flr 10 % 256 * l2 + s2 l0 1000 / flr 10 % 4096 * l2 + s2 l0 10000 / flr 10 % 65536 * l2 + s2 l0 100000 / flr 10 % 1048576 * l2 + s2 l0 1000000 / flr 10 % 16777216 * l2 + s2 l0 10000000 / flr 10 % 268435456 * l2 + s2

Roman


20AUG21_Avsim_Sig.png?dl=1  FS RTWR   SHRS F-111   JoinFS   Little Navmap 
 

 

Share this post


Link to post
Share on other sites

(>K:adf_freq)Er, there is no such XML key_event, Dai! You may use only one of the XML key_events listed in the center column of the EventIDs SDK document...Your code:

execute_calculator_code("(A:ADF ACTIVE FREQUENCY:1, KHz) (>K:adf_freq)", NULL, NULL, NULL);

is attempting to shove (>) the value from the read-only (A:ADF ACTIVE FREQUENCY:1,KHz) XML token variable into a non-existent XML Key_event you've misnamed (K:adf_freq)......which I'm fairly certain is not what you're actually wanting to do! :(


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

Ok, I'm going to offer up one of my own personal secrets. I know exactly how to set the freqency for both ADF 1 and ADF 2, accurately... every time.

		// for ADF_1		UINT32 bcdMainFreq;		bcdMainFreq = Dec2Bcd((UINT32)(freq*10000));		trigger_key_event(KEY_ADF_COMPLETE_SET, bcdMainFreq);		// for ADF_2		UINT32 bcdMainFreq;		bcdMainFreq = Dec2Bcd((UINT32)(freq*10000));		trigger_key_event(KEY_ADF2_COMPLETE_SET, bcdMainFreq);

Dec2Bcd is just a macro using HornerScheme conversion. "freq" is a value (>99.5 && <1800) || (>2178.5 && <2185.5)

  • Upvote 1

Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites

Okay Ed -you did give me the clue I needed. ADF_SET will accept ((hun*256)+(ten*16)+unit) e.g.

trigger_key_event(KEY_ADF_SET,((hun*256)+(ten*16)+unit);

because there is no extended (0.1KHz) for ADF_SET. That is loaded separately in ADF_EXTENDED. ADF_COMPLETE_SET requires the decimal figure even if it is not being used. The clue lay in this line here:-

bcdMainFreq = Dec2Bcd((UINT32)(freq*10000));

*10000 - that includes the decimal figure in the final figure presented to ADF_COMPLETE. So, the bottom line is that KEY_ADF_SET and KEY_ADF_COMPLETE_SET work in two different ways. That's why I couldn't get it to work - I was presenting a BCD figure that did not contain a final decimal.-DaiNOTE: Was being edited as Ed replied, hence what appears to be a non-sequiteur from Ed. It also means I can apologise for thinking you were being slightly sarcastic and my comment has been removed.

Share this post


Link to post
Share on other sites

Does it matter?I've shown you exactly how to set the frequency correctly for both ADFs. I'm pretty certain that's something that no one's been able to do before (I know, I searched long and hard).I don't spend my time trying to figure out why Microsoft's code doesn't work as expected... I really don't have the time for it.As for sarcasm... not sure why that's even in the discussion. I developed the Citation X v2 and it has dual working ADF tuners, it is the first aircraft I'm aware of with dual functioning ADFs for FS. (yes, I could easily be wrong there but I know of none other).


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites

See edited reply above.... As it happens I had twin ADFs in the FS98/FS2000 SD360 but you don't want to know the code bodge that was!-Dai

Share this post


Link to post
Share on other sites

Hi,I have dual functioning ADF's in my 767.Edited the code of the DC3 radio.<Macro Name="ADF">10000 * s0 10 % s2 l0 10 / flr 10 % 16 * l2 + s2 l0 100 / flr 10 % 256 * l2 + s2 l0 1000 / flr 10 % 4096 * l2 + s2 l0 10000 / flr 10 % 65536 * l2 + s2 l0 100000 / flr 10 % 1048576 * l2 + s2 l0 1000000 / flr 10 % 16777216 * l2 + s2 l0 10000000 / flr 10 % 268435456 * l2 + s2 </Macro>L:Var's for the numbers:(L:adf 0.1,number) 10 / (L:adf 1,number) + (L:adf 10,number) 10 * + (L:adf 100,number) 100 * + (>L:adf,number)(L:adf2 0.1,number) 10 / (L:adf2 1,number) + (L:adf2 10,number) 10 * + (L:adf2 100,number) 100 * + (>L:adf 2,number)And the commands to set the Freq:(L:adf,number) @ADF (>K:ADF_COMPLETE_SET) (L:adf 2,number) @ADF (>K:ADF2_COMPLETE_SET) May be useful for others,Jan

Share this post


Link to post
Share on other sites

As a working alternative to Arne's Dec2Bcd function, here's a somewhat more efficient method to achieve the goal:First, without the comments, the function is extremely simple:

int DoubleToSimFreq(double dblFreq){
	int  bcdValue;
	char cString[6];
	sprintf(cString, "%02d", (int)dblFreq-100);
	bcdValue = (cString[0]-48)*16 + (cString[1]-48);
	bcdValue *= 256;
	sprintf(cString, "%02.3f", (dblFreq-(int)dblFreq));
	bcdValue += (cString[2]-48)*16 + (cString[3]-48);
	return bcdValue;}
 

Once again, this time with full comments! ;)

int DoubleToSimFreq(double dblFreq){
	// The simulator stores frequences in a modified BCD format.
  	// It's not true BCD, so a special encoding is required.
	// To encode a numeric frequency into something the simulator will recognize,
 	// you drop the hundreds digit from the numeric frequency, then encode the
 	// remaining digits into a 2 byte integer (4 hex digits).  The first two hex digits
	// (i.e. the first byte of the 2-byte integer) represents the whole
 	// number portion of the frequency. The 3rd and 4th hex digits
 	// (i.e. the 2nd byte of the 2-byte integer) represent the decimal portion
 	// of the frequency.
	// When the 4 hex digits are grouped together as a 2-byte integer, the
	// resulting integer is what the simulator recognizes as a frequency.
	// NOTE: 48 is the ASCII code for the character "0".
	// So you'll see below that we subtract 48 from the ascii code for a particular character
    // which results in the numeric equivalent of the character digit.
	int  bcdValue;	char cString[6];
	// first, get rid of the hundreds, then isolate the remaining whole number portion of the frequency.
	sprintf(cString, "%02d", (int)dblFreq-100);
	// Convert the two hex digits into a decimal number which represents the whole number portion of the frequency
	bcdValue = (cString[0]-48)*16 + (cString[1]-48);
	// Since the above two hex digits will be the high-order digits of a 4-hex-digit number, the
	// result needs to be further scaled up by a factor of 256.
	bcdValue *= 256;
	// now, isolate the decimal portion of the frequency, and scale it up to a whole number by
	// multiplying by 100.  Use a float format string to avoid rounding errors that can occur.
    sprintf(cString, "%02.3f", (dblFreq-(int)dblFreq));
	// Convert the two hex digits (that represent the fractional part of the frequency) into a decimal number.
	// Since these two hex digits will be the low-order digits of a 4-digit hex number,
 	// no further scaling is required.
    bcdValue += (cString[2]-48)*16 + (cString[3]-48);
	// Return an integer that the sim will recognize as a frequency.
	return bcdValue;}
 

Usage is equally straightforward:

dblNumber = DoubleToSimFreq(NAV1freq);trigger_key_event(KEY_NAV1_RADIO_SET,dblNumber)
 
Edited by n4gix
Cleaned up comments/code for better legibility.

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

I chose to not use Bill's function because it didn't work correctly for this.But, thanks for reminding me as to why I never post. :(


Ed Wilson

Mindstar Aviation
My Playland - I69

Share this post


Link to post
Share on other sites
I chose to not use Bill's function because it didn't work correctly for this.But, thanks for reminding me as to why I never post. :(
Just realized my post didn't really make sense. I usually don't post because everyone always takes it the wrong way. :(

Ed Wilson

Mindstar Aviation
My Playland - I69

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