From 1bcc40e28dba4831cf5e0690dbac328fedcb7c73 Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Fri, 29 Oct 2021 12:22:55 +0100 Subject: [PATCH 1/4] Improve resilience of ATIS parsing code --- Nasal/Systems/Comm/Notification.nas | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Nasal/Systems/Comm/Notification.nas b/Nasal/Systems/Comm/Notification.nas index d2510cc8..f0daa91d 100644 --- a/Nasal/Systems/Comm/Notification.nas +++ b/Nasal/Systems/Comm/Notification.nas @@ -390,6 +390,10 @@ var ATIS = { code = split(".", code)[0]; } + if (find(",", code) != -1) { + code = split(",", code)[0]; + } + me.receivedCode = code; var time = ""; @@ -402,15 +406,27 @@ var ATIS = { } else if (find("TIME ", raw) != -1) { time = split("TIME ", raw)[1]; time = split(" ", time)[0]; + } else if (find(" UTC", raw) != -1) { + time = split(" UTC", raw)[0]; + time = right(time, 4); } else if (find("Z.", raw) != -1) { time = split("Z.", raw)[0]; time = right(time, 4); } else if (find("Z SPECIAL", raw) != -1) { time = split("Z SPECIAL", raw)[0]; time = right(time, 4); + } else if (find("Z EXPECT", raw) != -1) { + time = split("Z EXPECT", raw)[0]; + time = right(time, 4); } else if (find("metreport", raw) != -1) { time = split("metreport", raw)[0]; time = right(time, 4); + } else if (find("METREPORT ", raw) != -1) { + time = split("METREPORT ", raw)[1]; + time = left(time, 4); + } else if (find("INFORMATION " ~ code ~ " AT ", raw) != -1) { + time = split("INFORMATION " ~ code ~ " AT ", raw)[1]; + time = left(time, 4); } else if (find((code ~ " "), raw) != -1) { if (size(split(" ",split(code ~ " ", raw)[1])[0]) == 4) { time = split(" ",split(code ~ " ", raw)[1])[0]; @@ -420,8 +436,10 @@ var ATIS = { debug.dump(raw); } + # Handle UK airport issue + # Limitation: always ends in 0 if (size(time) == 3) { - time ~= " "; + time ~= "0"; } raw = string.uc(raw); From 3e1184a4dfffbdb471851d026410431e58cd6b8b Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Sat, 30 Oct 2021 15:06:40 +0100 Subject: [PATCH 2/4] Improve ATIS: handle more types of time; handle phonetically spelt-out codes --- Nasal/Systems/Comm/Notification.nas | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Nasal/Systems/Comm/Notification.nas b/Nasal/Systems/Comm/Notification.nas index f0daa91d..80d10af3 100644 --- a/Nasal/Systems/Comm/Notification.nas +++ b/Nasal/Systems/Comm/Notification.nas @@ -339,6 +339,7 @@ var ATIS = { print("Failed to parse ATIS for " ~ airport); debug.dump(r.response); debug.printerror(errs); + me.sent = 0; mcdu.mcdu_message(i, "BAD SERVER RESPONSE"); } }); @@ -394,6 +395,10 @@ var ATIS = { code = split(",", code)[0]; } + if (size(code) > 1) { + code = left(code, 1); + } + me.receivedCode = code; var time = ""; @@ -406,6 +411,9 @@ var ATIS = { } else if (find("TIME ", raw) != -1) { time = split("TIME ", raw)[1]; time = split(" ", time)[0]; + } else if (find("WEATHER AT ", raw) != -1) { + time = split("WEATHER AT ", raw)[1]; + time = left(split(" ", time)[0], 4); } else if (find(" UTC", raw) != -1) { time = split(" UTC", raw)[0]; time = right(time, 4); @@ -431,6 +439,8 @@ var ATIS = { if (size(split(" ",split(code ~ " ", raw)[1])[0]) == 4) { time = split(" ",split(code ~ " ", raw)[1])[0]; } + } else if (size(split(" ",split(code, raw)[1])[0]) == 4) { + time = split(" ",split(code, raw)[1])[0]; } else { print("Failed to find a valid ATIS time for " ~ me.station); debug.dump(raw); @@ -440,6 +450,8 @@ var ATIS = { # Limitation: always ends in 0 if (size(time) == 3) { time ~= "0"; + } else if (size(time) > 4) { + time = left(time, 4); } raw = string.uc(raw); From 4b02640e888b2e2c7702dbf810420810ebfa1de4 Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Sat, 30 Oct 2021 15:45:04 +0100 Subject: [PATCH 3/4] 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"); } From 7cf3684b5b83f84d5b16ea543591fa45e90bca44 Mon Sep 17 00:00:00 2001 From: Jonathan Redpath Date: Sat, 30 Oct 2021 15:45:52 +0100 Subject: [PATCH 4/4] Simbrief parser: round tropopause --- Nasal/FMGC/SimbriefParser.nas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nasal/FMGC/SimbriefParser.nas b/Nasal/FMGC/SimbriefParser.nas index 8fa4136f..6312b49c 100644 --- a/Nasal/FMGC/SimbriefParser.nas +++ b/Nasal/FMGC/SimbriefParser.nas @@ -270,7 +270,7 @@ var SimbriefParser = { fmgc.FMGCInternal.costIndex = me.OFP.getNode("general/costindex").getValue(); fmgc.FMGCInternal.costIndexSet = 1; fmgc.FMGCNodes.costIndex.setValue(fmgc.FMGCInternal.costIndex); - fmgc.FMGCInternal.tropo = me.OFP.getNode("general/avg_tropopause").getValue(); + fmgc.FMGCInternal.tropo = math.round(me.OFP.getNode("general/avg_tropopause").getValue(), 10); fmgc.FMGCInternal.tropoSet = 1; # Set cruise altitude