From 131562d2be6986fadc823df11e6c1f9f94d1fa1e Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Mon, 27 Dec 2021 13:36:18 +0000 Subject: [PATCH] Add tune VOR by ident --- Nasal/FMGC/FMGC.nas | 1 + Nasal/MCDU/RADNAV.nas | 158 +++++++++++++++++++++++++++++++++--------- 2 files changed, 128 insertions(+), 31 deletions(-) diff --git a/Nasal/FMGC/FMGC.nas b/Nasal/FMGC/FMGC.nas index f23d9af3..7ca79fe1 100644 --- a/Nasal/FMGC/FMGC.nas +++ b/Nasal/FMGC/FMGC.nas @@ -525,6 +525,7 @@ var updateFuel = func { ############################ # Flight Phase and Various # ############################ +# TODO - if no ID is found, should trigger a NOT IN DATA BASE message var freqnav0 = nil; var nav0 = func { freqnav0 = sprintf("%.2f", pts.Instrumentation.Nav.Frequencies.selectedMhz[0].getValue()); diff --git a/Nasal/MCDU/RADNAV.nas b/Nasal/MCDU/RADNAV.nas index f772799c..3b1f7275 100644 --- a/Nasal/MCDU/RADNAV.nas +++ b/Nasal/MCDU/RADNAV.nas @@ -4,6 +4,46 @@ var radNavScratchpad = nil; var radNavScratchpadSize = nil; +var parseFrequencyVOR = func(scratchpad, i, num) { + if (size(scratchpad) == 3 or size(scratchpad) == 5 or size(scratchpad) == 6) { + if (scratchpad >= 108.00 and scratchpad <= 111.95) { + if (scratchpad == 108.10 or scratchpad == 108.15 or scratchpad == 108.30 or scratchpad == 108.35 or scratchpad == 108.50 or scratchpad == 108.55 or scratchpad == 108.70 or scratchpad == 108.75 or scratchpad == 108.90 or scratchpad == 108.95 + or scratchpad == 109.10 or scratchpad == 109.15 or scratchpad == 109.30 or scratchpad == 109.35 or scratchpad == 109.50 or scratchpad == 109.55 or scratchpad == 109.70 or scratchpad == 109.75 or scratchpad == 109.90 or scratchpad == 109.95 + or scratchpad == 110.10 or scratchpad == 110.15 or scratchpad == 110.30 or scratchpad == 110.35 or scratchpad == 110.50 or scratchpad == 110.55 or scratchpad == 110.70 or scratchpad == 110.75 or scratchpad == 110.90 or scratchpad == 110.95 + or scratchpad == 111.10 or scratchpad == 111.15 or scratchpad == 111.30 or scratchpad == 111.35 or scratchpad == 111.50 or scratchpad == 111.55 or scratchpad == 111.70 or scratchpad == 111.75 or scratchpad == 111.90 or scratchpad == 111.95) { + return 3; + } else { + pts.Instrumentation.Nav.Frequencies.selectedMhz[num].setValue(scratchpad); + return 4; + } + } else if (scratchpad >= 112.00 and scratchpad <= 117.95) { + pts.Instrumentation.Nav.Frequencies.selectedMhz[num].setValue(scratchpad); + return 4; + } else { + return 2; + } + } else { + return 1; + } +} + +var searchResult = nil; +var parseIdentVOR = func(scratchpad, i, num) { + # TODO - duplicate names + if (size(scratchpad) == 3) { + searchResult = findNavaidsByID(scratchpad); + if (size(searchResult) != 0) { + pts.Instrumentation.Nav.Frequencies.selectedMhz[num].setValue(searchResult[0].frequency / 100); + return 3; + } else { + return 2; + } + } else { + return 1; + } +}; + +var returny = nil; var radnavInput = func(key, i) { radNavScratchpad = mcdu_scratchpad.scratchpads[i].scratchpad; radNavScratchpadSize = size(radNavScratchpad); @@ -13,27 +53,55 @@ var radnavInput = func(key, i) { fmgc.FMGCInternal.VOR1.freqSet = 0; mcdu_scratchpad.scratchpads[i].empty(); } else { - if (radNavScratchpadSize == 3 or radNavScratchpadSize == 5 or radNavScratchpadSize == 6) { - if (radNavScratchpad >= 108.00 and radNavScratchpad <= 111.95) { - if (radNavScratchpad == 108.10 or radNavScratchpad == 108.15 or radNavScratchpad == 108.30 or radNavScratchpad == 108.35 or radNavScratchpad == 108.50 or radNavScratchpad == 108.55 or radNavScratchpad == 108.70 or radNavScratchpad == 108.75 or radNavScratchpad == 108.90 or radNavScratchpad == 108.95 - or radNavScratchpad == 109.10 or radNavScratchpad == 109.15 or radNavScratchpad == 109.30 or radNavScratchpad == 109.35 or radNavScratchpad == 109.50 or radNavScratchpad == 109.55 or radNavScratchpad == 109.70 or radNavScratchpad == 109.75 or radNavScratchpad == 109.90 or radNavScratchpad == 109.95 - or radNavScratchpad == 110.10 or radNavScratchpad == 110.15 or radNavScratchpad == 110.30 or radNavScratchpad == 110.35 or radNavScratchpad == 110.50 or radNavScratchpad == 110.55 or radNavScratchpad == 110.70 or radNavScratchpad == 110.75 or radNavScratchpad == 110.90 or radNavScratchpad == 110.95 - or radNavScratchpad == 111.10 or radNavScratchpad == 111.15 or radNavScratchpad == 111.30 or radNavScratchpad == 111.35 or radNavScratchpad == 111.50 or radNavScratchpad == 111.55 or radNavScratchpad == 111.70 or radNavScratchpad == 111.75 or radNavScratchpad == 111.90 or radNavScratchpad == 111.95) { - mcdu_message(i, "NOT ALLOWED"); + if (size(split("/", radNavScratchpad)) == 2) { + if (size(split("/", radNavScratchpad)[0]) != 0) { + mcdu_message(i, "FORMAT ERROR"); + return; + } else { + radNavScratchpad = split("/", radNavScratchpad)[1]; + if (num(radNavScratchpad) != radNavScratchpad) { + mcdu_message(i, "FORMAT ERROR"); } else { - pts.Instrumentation.Nav.Frequencies.selectedMhz[2].setValue(radNavScratchpad); + returny = parseFrequencyVOR(radNavScratchpad, i, 2); + if (returny == 1) { + mcdu_message(i, "FORMAT ERROR"); + } elsif (returny == 2) { + mcdu_message(i, "ENTRY OUT OF RANGE"); + } elsif (returny == 3) { + mcdu_message(i, "NOT ALLOWED"); + } elsif (returny == 4) { + fmgc.FMGCInternal.VOR1.freqSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } + } + } + } else if (size(split("/", radNavScratchpad)) == 1) { + if (num(radNavScratchpad) == radNavScratchpad) { + returny = parseFrequencyVOR(radNavScratchpad, i, 2); + if (returny == 1) { + mcdu_message(i, "FORMAT ERROR"); + } elsif (returny == 2) { + mcdu_message(i, "ENTRY OUT OF RANGE"); + } elsif (returny == 3) { + mcdu_message(i, "NOT ALLOWED"); + } elsif (returny == 4) { + fmgc.FMGCInternal.VOR1.freqSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } + } else if (isstr(radNavScratchpad)) { + returny = parseIdentVOR(radNavScratchpad, i, 2); + if (returny == 1) { + mcdu_message(i, "FORMAT ERROR"); + } elsif (returny == 2) { + # TODO - NEW NAVAID page + mcdu_message(i, "NOT IN DATA BASE"); + } elsif (returny == 3) { fmgc.FMGCInternal.VOR1.freqSet = 1; mcdu_scratchpad.scratchpads[i].empty(); } - } else if (radNavScratchpad >= 112.00 and radNavScratchpad <= 117.95) { - pts.Instrumentation.Nav.Frequencies.selectedMhz[2].setValue(radNavScratchpad); - fmgc.FMGCInternal.VOR1.freqSet = 1; - mcdu_scratchpad.scratchpads[i].empty(); - } else { - mcdu_message(i, "NOT ALLOWED"); } } else { - mcdu_message(i, "NOT ALLOWED"); + mcdu_message(i, "FORMAT ERROR"); } } } else if (key == "L2") { @@ -142,30 +210,58 @@ var radnavInput = func(key, i) { } } else if (key == "R1") { if (radNavScratchpad == "CLR") { - fmgc.FMGCInternal.VOR2.freqSet = 0; + fmgc.FMGCInternal.VOR1.freqSet = 0; mcdu_scratchpad.scratchpads[i].empty(); } else { - if (radNavScratchpadSize == 3 or radNavScratchpadSize == 5 or radNavScratchpadSize == 6) { - if (radNavScratchpad >= 108.10 and radNavScratchpad <= 111.95) { - if (radNavScratchpad == 108.10 or radNavScratchpad == 108.15 or radNavScratchpad == 108.30 or radNavScratchpad == 108.35 or radNavScratchpad == 108.50 or radNavScratchpad == 108.55 or radNavScratchpad == 108.70 or radNavScratchpad == 108.75 or radNavScratchpad == 108.90 or radNavScratchpad == 108.95 - or radNavScratchpad == 109.10 or radNavScratchpad == 109.15 or radNavScratchpad == 109.30 or radNavScratchpad == 109.35 or radNavScratchpad == 109.50 or radNavScratchpad == 109.55 or radNavScratchpad == 109.70 or radNavScratchpad == 109.75 or radNavScratchpad == 109.90 or radNavScratchpad == 109.95 - or radNavScratchpad == 110.10 or radNavScratchpad == 110.15 or radNavScratchpad == 110.30 or radNavScratchpad == 110.35 or radNavScratchpad == 110.50 or radNavScratchpad == 110.55 or radNavScratchpad == 110.70 or radNavScratchpad == 110.75 or radNavScratchpad == 110.90 or radNavScratchpad == 110.95 - or radNavScratchpad == 111.10 or radNavScratchpad == 111.15 or radNavScratchpad == 111.30 or radNavScratchpad == 111.35 or radNavScratchpad == 111.50 or radNavScratchpad == 111.55 or radNavScratchpad == 111.70 or radNavScratchpad == 111.75 or radNavScratchpad == 111.90 or radNavScratchpad == 111.95) { - mcdu_message(i, "NOT ALLOWED"); + if (size(split("/", radNavScratchpad)) == 2) { + if (size(split("/", radNavScratchpad)[1]) != 0) { + mcdu_message(i, "FORMAT ERROR"); + return; + } else { + radNavScratchpad = split("/", radNavScratchpad)[0]; + if (num(radNavScratchpad) != radNavScratchpad) { + mcdu_message(i, "FORMAT ERROR"); } else { - pts.Instrumentation.Nav.Frequencies.selectedMhz[3].setValue(radNavScratchpad); + returny = parseFrequencyVOR(radNavScratchpad, i, 3); + if (returny == 1) { + mcdu_message(i, "FORMAT ERROR"); + } elsif (returny == 2) { + mcdu_message(i, "ENTRY OUT OF RANGE"); + } elsif (returny == 3) { + mcdu_message(i, "NOT ALLOWED"); + } elsif (returny == 4) { + fmgc.FMGCInternal.VOR2.freqSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } + } + } + } else if (size(split("/", radNavScratchpad)) == 1) { + if (num(radNavScratchpad) == radNavScratchpad) { + returny = parseFrequencyVOR(radNavScratchpad, i, 3); + if (returny == 1) { + mcdu_message(i, "FORMAT ERROR"); + } elsif (returny == 2) { + mcdu_message(i, "ENTRY OUT OF RANGE"); + } elsif (returny == 3) { + mcdu_message(i, "NOT ALLOWED"); + } elsif (returny == 4) { + fmgc.FMGCInternal.VOR2.freqSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } + } else if (isstr(radNavScratchpad)) { + returny = parseIdentVOR(radNavScratchpad, i, 3); + if (returny == 1) { + mcdu_message(i, "FORMAT ERROR"); + } elsif (returny == 2) { + # TODO - NEW NAVAID page + mcdu_message(i, "NOT IN DATA BASE"); + } elsif (returny == 3) { fmgc.FMGCInternal.VOR2.freqSet = 1; mcdu_scratchpad.scratchpads[i].empty(); } - } else if (radNavScratchpad >= 112.00 and radNavScratchpad <= 117.95) { - pts.Instrumentation.Nav.Frequencies.selectedMhz[3].setValue(radNavScratchpad); - fmgc.FMGCInternal.VOR2.freqSet = 1; - mcdu_scratchpad.scratchpads[i].empty(); - } else { - mcdu_message(i, "NOT ALLOWED"); } } else { - mcdu_message(i, "NOT ALLOWED"); + mcdu_message(i, "FORMAT ERROR"); } } } else if (key == "R2") {