• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FS2004 GPS VOR frequency to tuned radio?

Messages
206
Country
unitedkingdom
Hi,

Another GPS question: is there a neat way to use the NearestVorCurrentFrequency data for a GPS search to directly tune a NAV radio? As far as I can see there is some kind of conversion needed before it can work?

Cheers,
Geoff
 
Messages
440
Country
us-wisconsin
Geoff,

It's referred to as the "Horner" (Base16) scheme. This scheme can be used for nav/comm radios, the transponder, but NOT the ADF. It must be a whole number so a multiplication is needed to get rid of the decimal point. Get the GPS output as a string then do the following -

The scheme itself -
Code:
10000 % int d 10 % r 10 / int d 10 % r 10 / int d 10 % r 10 / int 16 * + 16 * + 16 * +

An example -
Code:
115.50 100 *
10000 % int d 10 % r 10 / int d 10 % r 10 / int d 10 % r 10 / int 16 * + 16 * + 16 * + 
(>K:NAV1_RADIO_SET)

Roman
 
Last edited:
Messages
206
Country
unitedkingdom
Great stuff! Thanks very much for those - I'll have a play with them later... The idea is to have auto-tuning to nearest radios during cruise flight (if no user intervention has happened for X minutes and no station is tuned)...

Geoff
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
Note that the @Dec2BCD macro multiplies the base freq by 100.001 instead of just 100.0...

...this prevents some occasional rounding errors that will otherwise occur for certain decimal frequencies.
 
Messages
206
Country
unitedkingdom
Got it all working, after a few frustrating issues. Just thought I'd share a couple of things I discovered:

Setting the NAV1/2 radios is easier than using the macro, since the GPS search can generate the output in the desired format like this:
Code:
(@c:NearestVorCurrentFrequency, Frequency BCD16) (>K:NAV1_RADIO_SET)
This is then my working script for nearest VOR or VORDME within 150nM:
Code:
(L:Nav1Autotune, bool) if{ 
(A:PLANE LATITUDE, degrees) (>@c:NearestVorCurrentLatitude, degrees) 
(A:PLANE LONGITUDE, degrees) (>@c:NearestVorCurrentLongitude, degrees) 
100 (>@c:NearestVorMaximumItems, enum) 
150 (>@c:NearestVorMaximumDistance, nmiles) 
3 (>@c:NearestVorRemoveVorType) 
(@c:NearestVorItemsNumber) 0 != if{ 
0 (>@c:NearestVorCurrentLine) (@c:NearestVorCurrentFrequency, Frequency BCD16) (>K:NAV1_RADIO_SET) 0 (>L:Nav1Autotune, bool) 
} }

My ADF setting script seemed to not work, but then I realised that actually a large number of ADF beacons come up in the GPS database as having a frequence of zero! The following search script with an incrementing index finds the nearest type 3 (or greater) NDB with a nonzero frequency:
Code:
(L:ADFAutotune, bool) if{ 
(A:PLANE LATITUDE, degrees) (>@c:NearestNdbCurrentLatitude, degrees) 
(A:PLANE LONGITUDE, degrees) (>@c:NearestNdbCurrentLongitude, degrees) 
100 (>@c:NearestNdbMaximumItems, enum) 
100 (>@c:NearestNdbMaximumDistance, nmiles) 
(@c:NearestNdbItemsNumber) 0 != if{ 
(L:ADFindex,enum) (>@c:NearestNdbCurrentLine)
(@c:NearestNdbCurrentType, enum) 3 >= (@c:NearestNdbCurrentFrequency, khz) 0 > && if{ 
@SetADF((@c:NearestNdbCurrentFrequency, khz)) 0 (>L:ADFAutotune, bool) 0 (>L:ADFindex,enum)  
} els{ 
(L:ADFindex,enum) ++ (@c:NearestNdbItemsNumber) min (>L:ADFindex,enum) 
} } }

A note about the @SetADF macro in the wiki. I could not get this to work until I added the @1 reference as shown in red (actually, I could not get the BCD one to work either but found the workaround above)... Is that an error in the wiki or me doing something wrong?
Code:
<Macro Name="SetADF">
       (* UPDATE ADF FREQUENCY *)
       [COLOR="Red"][B]@1 [/B][/COLOR]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 (>K:ADF_COMPLETE_SET)
</Macro>

Cheers,
Geoff
 
Messages
1,564
Country
thailand
Geoff,

Code:
(@c:NearestVorCurrentFrequency, Frequency BCD16) (>K:NAV1_RADIO_SET)

Good thinking! Maybe that idea can be added to the wiki! In fact, it reminds me that a good wiki would be a short tut on how FS stores numbers and applies conversions based on units. Any takers?

Concerning the VOR type filter, you are safe using 3 (>@c:NearestVorRemoveVorType) in FS9 and probably also in FSX. However, I never scanned the FSX database for VOR types - only FS9. So, I couldn't be sure that FSX has no Type 4+ VORs.

You could always try 0xF8 (>@c:NearestVorRemoveVorType) (8 bit) or 0x38 (>@c:NearestVorRemoveVorType) (6 bit) to cover VOR 4+, although it probably isn't necessary.

Hope you have fun with the gps!

Bob
 
Messages
495
Country
austria
For ADF i'm doing it this way.


Code:
  (C:FS9GPS:NearestNdbCurrentFrequency,Frequency ADF BCD32) (&gt;L:NavM_NDB_save,Frequency ADF BCD32)

Code:
      (L:NavM_NDB_save,Frequency ADF BCD32) (&gt;K:ADF_COMPLETE_SET)

Edi
 
Messages
206
Country
unitedkingdom
For ADF i'm doing it this way.


Code:
  (C:FS9GPS:NearestNdbCurrentFrequency,Frequency ADF BCD32) (&gt;L:NavM_NDB_save,Frequency ADF BCD32)

Code:
      (L:NavM_NDB_save,Frequency ADF BCD32) (&gt;K:ADF_COMPLETE_SET)

Edi

Cool, even easier. I think I'll just do that as well since I never actually need to 'see' the frequency in a normal format...

Geoff
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
A note about the @SetADF macro in the wiki. I could not get this to work until I added the @1 reference as shown in red (actually, I could not get the BCD one to work either but found the workaround above)... Is that an error in the wiki or me doing something wrong?
I honestly don't know what to say, Geoff. I've been using both as written in the Wiki for years without problems...

I suppose adding an @1 to them cannot hurt; and if it helps why not do so? :confused:
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
The wiki is indeed bad, lacks the @1 parameter as geoffco noticed. This parameter is passed from the code in red :

@SetADF((L:ADF1 Frequency,Khz))

Anyway, the macro will work as it is written in the wiki if the script is like

(L:ADF1 Frequency,Khz) @SetADF((L:ADF1 Frequency,Khz))

The parameter is ignored, but the last stack's value is used instead.

Tom

EDIT: Actually I wouldn't bother to make any conversion at all, and instead use a Local var to do the job:

114.40 (>L:LazyNav,Mhz) (L:LazyNav, Frequency BCD 16) (>K:NAV1_RADIO_SET)

285.0 (>L:LazyADF,Khz) (L:LazyADF,Frequency ADF BCD32) (>K:ADF_COMPLETE_SET)
 
Last edited:

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
The wiki is indeed bad, lacks the @1 parameter as geoffco noticed. This parameter is passed from the code in red :

@SetADF((L:ADF1 Frequency,Khz))

Anyway, the macro will work as it is written in the wiki if the script is like

(L:ADF1 Frequency,Khz) @SetADF((L:ADF1 Frequency,Khz))

The parameter is ignored, but the last stack's value is used instead.
Wiki for both NAV and ADF @Macros now edited.

Actually, I note now that I have indeed been using the method above in past projects, where I call the @Macro after declaring the L:variable:

Code:
(L:ADF1 Frequency,Khz) @SetADF
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
Actually, I note now that I have indeed been using the method above in past projects, where I call the @Macro after declaring the L:variable:

Code:
(L:ADF1 Frequency,Khz) @SetADF

I guessed it Bill, so the reason I posted that example :)

Tom
 
G

gr8guitar

Guest
Great Information. Can this be done with VOR's in FS9? I'm trying to at least get the next VOR frequency that is in a flightplan (*.pln) but so far to no avail.
 
Messages
1,564
Country
thailand
Can this be done with VOR's in FS9? I'm trying to at least get the next VOR frequency that is in a flightplan (*.pln) but so far to no avail.
Yes, although it requires a couple of more lines of XML in FS9 than in later sims because the gps variable, FlightPlanWaypointFrequency, doesn't work in FS9.

Here's a way to do it in FS9:
Code:
<Update>
    (C:fs9gps:FlightPlanActiveWaypoint) (>C:fs9gps:FlightPlanWaypointIndex)
    (C:fs9gps:FlightPlanWaypointICAO) (>C:fs9gps:WaypointVorICAO)
</Update>
 
<Element Name="VOR IDENT AND FREQUENCY">
    <Position X="5" Y="60"/>
        <FormattedText X="90" Y="9" Font="courier new" FontSize="10" LineSpacing="10" Color="#101010" Bright="Yes">
            <String>%((C:fs9gps:WaypointVorIdent))%!5s!% %((C:fs9gps:WaypointVorFrequency, MHz))%!7.3f!% MHz</String>
        </FormattedText>
</Element>

This assumes that you want the frequency of the active waypoint. If you want the frequency of the waypoint after that, then use:

(C:fs9gps:FlightPlanActiveWaypoint) 1 + (>C:fs9gps:FlightPlanWaypointIndex)

Also, note that the line

(C:fs9gps:FlightPlanWaypointICAO) (>C:fs9gps:WaypointVorICAO)

is an ICAO Transfer. Often, ICAO Transfers require a cycle counting technique to delay execution of subsequent code until the gps engine completes the transfer. If all you're doing is displaying the frequency, then the cycle counting step can be omitted. However, if you use the VOR frequency to automatically tune the radio using (>K:NAV1_RADIO_SET) as discussed in the earlier responses, above, then you'll need to include cycle counting to delay the radio tuning.

If the active waypoint is not a VOR, the frequency displayed will be 000.00

It's all discussed in the gps Guidebook.

Cheers,

Bob
 
Last edited:
G

gr8guitar

Guest
WOW! Thanks! I tried (in part):

(A:GPS WP NEXT LAT, Radians) (>@c:NearestVORCurrentLatitude, Radians)
(A:GPS WP NEXT LON, Radians) (>@c:NearestVORCurrentLongitude, Radians)

but it only worked while I was at the departure airport....

A little history why I got on this path. I primarily use FS9. FS9 default GPS is great but it doesn't display the missed approach's holding altitude. I asked about this in another thread on this website and ADE was recommended. I got a UFMC from avsim.ru. The UFMC, as well as HoneywellFMC (best with FSX as its map doesn't show in FS9), works with FS9's GPS map. I also have some generic ND's that work. Also, the UFMC is not complete. The DTO doesn't work or the HOLD. Anyways, I'm attempting to make modest changes. I did get it to show the missed approach's holding altitude (as I progress through the approach) but now want the flightplan's VOR frequency. Again, thanks for all your help!
 
Messages
1,564
Country
thailand
(A:GPS WP NEXT LAT, Radians) (>@c:NearestVORCurrentLatitude, Radians)
(A:GPS WP NEXT LON, Radians) (>@c:NearestVORCurrentLongitude, Radians)
If you want to get information about a flight plan waypoint, such as VOR frequency, then don't introduce Nearest Search vars like NearestVORCurrentLatitude. A Nearest search is quite a different thing.

Suggest you try the script I show in #15 above.

If you want to know the missed approach holding alt, you might take a look at gps variable FlightPlanWaypointApproachTarget. It's the Missed Approach climb-out altitude which is sometimes, but not always, the designated holding pattern altitude.

Bob
 
Last edited:
G

gr8guitar

Guest
Well, I got it working!!! I could not have done it without your assistance. It's so nice to see the VOR's frequency update as I pass them. Yes, I will delve more into that FSMap Guidebook. So then this leads me to wonder, how did one learn so much about the internals of FS and also, how to write xml with all its options? I downloaded the SDK's (FS2004SDK) but I never gleaned all this information I learned today. I keep seeing information related to ESP but I never did find it. And I have had Internet help with some xml programming but where did "they" learn it? Again, thank you very much for your time and information.
 
Messages
1,564
Country
thailand
how did one learn so much about the internals of FS and also, how to write xml with all its options?
There are some Flight Sim XML tutorials out there, but not a lot. Search "Tutorial" in this forum. I think Nick Pike's tuts at fs2X.com are the best I've seen, so take a look at those.

The bottom line is that learning XML gauge coding is largely a trial and error process for most people. You need patience and curiosity and definitely the willingness to test, test, test, and re-test. Keep reading this forum and you will regularly pick up good tips - one of which is, stick to FS9 XML schema rather than the more verbose FSX variety. Might be best to get your feet wet learning to make some 2D gauges before tackling 3D. And, it's going to take some time. I'll hazard a guess that it takes casual Flight Sim hobbyists like me a few years to feel competent making gauges.

Bob
 
G

gr8guitar

Guest
Thanks for your reply. I do know about fs2x.com and I did find some other and good XML gauge information. I was just wondering if there was a particular text book for XML. The one's I've seen on the Internet so far, seem to mostly deal with, I guess, website design or other textual applications (i.e.: w3schools.com). Do you know where a person could obtain this ESP? It must stand only for Especially Smart People because I cannot find it. Is it its own flight simulator separate from FS2004, FSX? And you are correct about FSX's verbose xml schema. I have made some attempts to convert FSX to FS9 xml and it's a lot of work. I again, don't understand the reason behind the new schema. I have FSX but I don't have a powerful enough computer to make FSX run smoothly and thus more realistically like I can with FS9. In addition, though so many years, I have aircraft and gauges accumulated that I like. Again, thank you for your help.
 
Top