From 81edf652590d7813cc3c218032f03bb957493afa Mon Sep 17 00:00:00 2001 From: Matthew Maring <56924612+hayden2000@users.noreply.github.com> Date: Sun, 26 Apr 2020 14:59:32 -0400 Subject: [PATCH] Clean up ils logic --- Models/Instruments/MCDU/MCDU.nas | 2 +- Nasal/FMGC/FMGC.nas | 49 +++++++++++++------------------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/Models/Instruments/MCDU/MCDU.nas b/Models/Instruments/MCDU/MCDU.nas index 24cd44cb..b7f28c7a 100644 --- a/Models/Instruments/MCDU/MCDU.nas +++ b/Models/Instruments/MCDU/MCDU.nas @@ -2615,7 +2615,7 @@ var canvas_MCDU_base = { me["Simple_R1S"].setText("FINAL"); if (fmgc.flightPlanController.flightplans[2].approach != nil) { - me["Simple_R1"].setText(sprintf("%s",fmgc.flightPlanController.flightplans[2].approach.id)); + me["Simple_R1"].setText(sprintf("%s",fmgc.flightPlanController.flightplans[2].approach.id)); # should exclude ILS/LDA/RNAV etc in future me["Simple_R1"].setColor(GREEN); } else { me["Simple_R1"].setText("--- "); diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index 828842a5..3245ad87 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -479,42 +479,33 @@ var masterFMGC = maketimer(0.2, func { if (fmgc.flightPlanController.flightplans[2].approach != nil and phase >= 2) { var airport = airportinfo(getprop("FMGC/internal/arr-arpt")); setprop("FMGC/internal/ldg-elev", airport.elevation * M2FT); - var runways = airportinfo(airport.id).runways; - var rwy = string.replace(fmgc.flightPlanController.flightplans[2].approach.id, "ILS", ""); - if (runways[rwy] != nil) { - var r = runways[rwy]; - #print(r.lat); - #print(r.lon); - #print(r.length); - #print(r.width); - #print(r.heading); - #print(r.stopway); - #print(r.threshold); - magnetic_hdg = geo.normdeg(r.heading - getprop("environment/magnetic-variation-deg")); - if (r.ils_frequency_mhz != nil and !getprop("FMGC/internal/ils1freq-set") and !getprop("FMGC/internal/ils1crs-set")) { - setprop("FMGC/internal/ils1freq-calculated", r.ils_frequency_mhz); - setprop("instrumentation/nav[0]/frequencies/selected-mhz", r.ils_frequency_mhz); + var rwy = fmgc.flightPlanController.flightplans[2].destination_runway; + if (rwy != nil) { + magnetic_hdg = geo.normdeg(rwy.heading - getprop("environment/magnetic-variation-deg")); + runway_ils = rwy.ils_frequency_mhz; + if (runway_ils != nil and !getprop("FMGC/internal/ils1freq-set") and !getprop("FMGC/internal/ils1crs-set")) { + setprop("FMGC/internal/ils1freq-calculated", runway_ils); + setprop("instrumentation/nav[0]/frequencies/selected-mhz", runway_ils); setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); - } else if (r.ils_frequency_mhz != nil and !getprop("FMGC/internal/ils1freq-set")) { - setprop("FMGC/internal/ils1freq-calculated", r.ils_frequency_mhz); - setprop("instrumentation/nav[0]/frequencies/selected-mhz", r.ils_frequency_mhz); + } else if (runway_ils != nil and !getprop("FMGC/internal/ils1freq-set")) { + setprop("FMGC/internal/ils1freq-calculated", runway_ils); + setprop("instrumentation/nav[0]/frequencies/selected-mhz", runway_ils); } else if (!getprop("FMGC/internal/ils1crs-set")) { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); } } } else if (fmgc.flightPlanController.flightplans[2].departure_runway != nil and phase <= 1) { - var runways = airportinfo(airportinfo(getprop("FMGC/internal/dep-arpt")).id).runways; - var rwy = fmgc.flightPlanController.flightplans[2].departure_runway.id; - if (runways[rwy] != nil) { - var r = runways[rwy]; - magnetic_hdg = geo.normdeg(r.heading - getprop("environment/magnetic-variation-deg")); - if (r.ils_frequency_mhz != nil and !getprop("FMGC/internal/ils1freq-set") and !getprop("FMGC/internal/ils1crs-set")) { - setprop("FMGC/internal/ils1freq-calculated", r.ils_frequency_mhz); - setprop("instrumentation/nav[0]/frequencies/selected-mhz", r.ils_frequency_mhz); + var rwy = fmgc.flightPlanController.flightplans[2].departure_runway; + if (rwy != nil) { + magnetic_hdg = geo.normdeg(rwy.heading - getprop("environment/magnetic-variation-deg")); + runway_ils = rwy.ils_frequency_mhz; + if (runway_ils != nil and !getprop("FMGC/internal/ils1freq-set") and !getprop("FMGC/internal/ils1crs-set")) { + setprop("FMGC/internal/ils1freq-calculated", runway_ils); + setprop("instrumentation/nav[0]/frequencies/selected-mhz", runway_ils); setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); - } else if (r.ils_frequency_mhz != nil and !getprop("FMGC/internal/ils1freq-set")) { - setprop("FMGC/internal/ils1freq-calculated", r.ils_frequency_mhz); - setprop("instrumentation/nav[0]/frequencies/selected-mhz", r.ils_frequency_mhz); + } else if (runway_ils != nil and !getprop("FMGC/internal/ils1freq-set")) { + setprop("FMGC/internal/ils1freq-calculated", runway_ils); + setprop("instrumentation/nav[0]/frequencies/selected-mhz", runway_ils); } else if (!getprop("FMGC/internal/ils1crs-set")) { setprop("instrumentation/nav[0]/radials/selected-deg", magnetic_hdg); }