From 4b02640e888b2e2c7702dbf810420810ebfa1de4 Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Sat, 30 Oct 2021 15:45:04 +0100 Subject: [PATCH] Improve INIT A validation of tropopause and GND TEMP --- Nasal/MCDU/INITA.nas | 66 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/Nasal/MCDU/INITA.nas b/Nasal/MCDU/INITA.nas index 9dfae813..aab8ad53 100644 --- a/Nasal/MCDU/INITA.nas +++ b/Nasal/MCDU/INITA.nas @@ -310,27 +310,65 @@ var initInputA = func(key, i) { setprop("MCDU[" ~ i ~ "]/page", "WINDCLB"); } else if (key == "R5") { if (scratchpad == "CLR") { - fmgc.FMGCInternal.tropo = 36090; - fmgc.FMGCInternal.tropoSet = 0; - mcdu_scratchpad.scratchpads[i].empty(); - } else { - var tropo = size(scratchpad); - if (tropo == 5 and scratchpad <= 99990) { - fmgc.FMGCInternal.tropo = scratchpad; - fmgc.FMGCInternal.tropoSet = 1; + if (fmgc.FMGCInternal.tropoSet) { + fmgc.FMGCInternal.tropo = 36090; + fmgc.FMGCInternal.tropoSet = 0; mcdu_scratchpad.scratchpads[i].empty(); } else { mcdu_message(i, "NOT ALLOWED"); } + } else { + if (num(scratchpad) == nil) { + if (find("FL", scratchpad) != -1) { + var tropos = size(split("FL", scratchpad)[1]); + var tropon = num(split("FL", scratchpad)[1]); + if (tropon != nil) { + if ((tropos == 2 or tropos == 3) and tropon >= 10 and tropon <= 999) { + fmgc.FMGCInternal.tropo = tropon * 100; + fmgc.FMGCInternal.tropoSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } else { + mcdu_message(i, "ENTRY OUT OF RANGE"); + } + } else { + mcdu_message(i, "NOT ALLOWED"); + } + } else { + mcdu_message(i, "NOT ALLOWED"); + } + } else { + var tropos = size(scratchpad); + var tropon = num(scratchpad); + if ((tropos == 4 or tropos == 5) and tropon >= 1000 and tropon <= 99990) { + fmgc.FMGCInternal.tropo = math.round(tropon, 10); + fmgc.FMGCInternal.tropoSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } else if ((tropos == 2 or tropos == 3) and tropon >= 10 and tropon <= 999) { + fmgc.FMGCInternal.tropo = num(scratchpad) * 100; + fmgc.FMGCInternal.tropoSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } else { + mcdu_message(i, "ENTRY OUT OF RANGE"); + } + } } } else if (key == "R6") { if (scratchpad == "CLR") { - fmgc.FMGCInternal.gndTempSet = 0; - mcdu_scratchpad.scratchpads[i].empty(); - } else if (int(scratchpad) != nil and fmgc.FMGCInternal.phase == 0 and size(scratchpad) >= 1 and size(scratchpad) <= 3 and scratchpad >= -99 and scratchpad <= 99) { - fmgc.FMGCInternal.gndTemp = scratchpad; - fmgc.FMGCInternal.gndTempSet = 1; - mcdu_scratchpad.scratchpads[i].empty(); + if (fmgc.FMGCInternal.gndTempSet) { + fmgc.FMGCInternal.gndTempSet = 0; + fmgc.FMGCInternal.gndTemp = 15; + mcdu_scratchpad.scratchpads[i].empty(); + } else { + mcdu_message(i, "NOT ALLOWED"); + } + } else if (isnum(scratchpad) and fmgc.FMGCInternal.phase == 0) { + if (size(scratchpad) >= 1 and size(scratchpad) <= 3 and scratchpad >= -99 and scratchpad <= 99) { + fmgc.FMGCInternal.gndTemp = scratchpad; + fmgc.FMGCInternal.gndTempSet = 1; + mcdu_scratchpad.scratchpads[i].empty(); + } else { + mcdu_message(i, "ENTRY OUT OF RANGE"); + } } else { mcdu_message(i, "NOT ALLOWED"); }