2020-04-30 19:26:36 +00:00
# A3XX mCDU by Joshua Davidson (Octal450), Jonathan Redpath, and Matthew Maring (mattmaring)
2020-03-23 13:48:01 +00:00
2020-04-30 19:26:36 +00:00
# Copyright (c) 2020 Matthew Maring (mattmaring)
2020-03-23 13:48:01 +00:00
# From INIT-B
2020-04-14 22:12:38 +00:00
var zfwcg = props.globals.getNode("FMGC/internal/zfwcg", 1);
var zfwcgSet = props.globals.getNode("FMGC/internal/zfwcg-set", 1);
2020-03-23 13:48:01 +00:00
var zfw = props.globals.getNode("FMGC/internal/zfw", 1);
2020-04-14 22:12:38 +00:00
var zfwSet = props.globals.getNode("FMGC/internal/zfw-set", 1);
2020-04-11 11:01:37 +00:00
var block = props.globals.getNode("FMGC/internal/block", 1);
2020-04-14 22:12:38 +00:00
var blockSet = props.globals.getNode("FMGC/internal/block-set", 1);
2020-03-23 13:48:01 +00:00
var taxi_fuel = props.globals.getNode("FMGC/internal/taxi-fuel", 1);
var trip_fuel = props.globals.getNode("FMGC/internal/trip-fuel", 1);
var trip_time = props.globals.getNode("FMGC/internal/trip-time", 1);
var rte_rsv = props.globals.getNode("FMGC/internal/rte-rsv", 1);
var rte_percent = props.globals.getNode("FMGC/internal/rte-percent", 1);
var alt_fuel = props.globals.getNode("FMGC/internal/alt-fuel", 1);
var alt_time = props.globals.getNode("FMGC/internal/alt-time", 1);
var final_fuel = props.globals.getNode("FMGC/internal/final-fuel", 1);
var final_time = props.globals.getNode("FMGC/internal/final-time", 1);
var min_dest_fob = props.globals.getNode("FMGC/internal/min-dest-fob", 1);
var tow = props.globals.getNode("FMGC/internal/tow", 1);
var lw = props.globals.getNode("FMGC/internal/lw", 1);
var trip_wind = props.globals.getNode("FMGC/internal/trip-wind", 1);
2020-05-03 17:29:46 +00:00
var trip_wind_value = props.globals.getNode("FMGC/internal/trip-wind", 1);
2020-04-14 22:12:38 +00:00
var fob = props.globals.getNode("FMGC/internal/fob", 1);
var fffq_sensor = props.globals.getNode("FMGC/internal/fffq-sensor", 1);
2020-03-23 13:48:01 +00:00
var extra_fuel = props.globals.getNode("FMGC/internal/extra-fuel", 1);
var extra_time = props.globals.getNode("FMGC/internal/extra-time", 1);
var fuelPredInput = func(key, i) {
var scratchpad = getprop("MCDU[" ~ i ~ "]/scratchpad");
2020-05-02 01:21:57 +00:00
if (key == "L3" and getprop("/FMGC/internal/block-confirmed") and !getprop("/FMGC/internal/fuel-calculating")) {
2020-03-28 20:40:02 +00:00
if (scratchpad == "CLR") {
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/rte-rsv", 0.05 * num(getprop("/FMGC/internal/trip-fuel")));
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/rte-percent", 5.0);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad-msg", 0);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-05-02 00:26:05 +00:00
} else if (getprop("/FMGC/internal/trip-fuel") != 0) {
2020-04-14 22:12:38 +00:00
var tf = num(scratchpad);
2020-03-23 13:48:01 +00:00
var tfs = size(scratchpad);
if (tfs >= 2 and tfs <= 5 and find("/", scratchpad) == 0) {
2020-03-30 01:27:18 +00:00
var perc = num(split("/", scratchpad)[1]);
2020-04-14 22:12:38 +00:00
if (perc != nil and perc >= 0.0 and perc <= 15.0) {
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/rte-rsv", num(perc) / 100 * num(getprop("/FMGC/internal/trip-fuel")));
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/rte-percent", perc);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-03-23 13:48:01 +00:00
}
2020-05-05 13:52:11 +00:00
} else if (tfs >= 1 and tfs <= 4 and tf != nil and tf >= 0 and tf <= 21.7) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/rte-rsv", scratchpad);
2020-05-05 13:52:11 +00:00
if (scratchpad / num(getprop("/FMGC/internal/trip-fuel")) * 100 <= 15.0) {
setprop("/FMGC/internal/rte-percent", scratchpad / num(getprop("/FMGC/internal/trip-fuel")) * 100);
} else {
setprop("/FMGC/internal/rte-percent", 15.0); # need reasearch on this value
}
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-03-23 13:48:01 +00:00
} else {
notAllowed(i);
}
} else {
2020-03-28 20:40:02 +00:00
notAllowed(i);
}
2020-05-05 13:52:11 +00:00
} else if (key == "L4" and getprop("/FMGC/internal/block-confirmed") and !getprop("/FMGC/internal/fuel-calculating") and getprop("/FMGC/internal/alt-set")s) {
2020-03-28 20:40:02 +00:00
if (scratchpad == "CLR") {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/alt-fuel", 0.0);
setprop("/FMGC/internal/alt-time", "0000");
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/alt-fuel-set", 0);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad-msg", 0);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-04-14 22:12:38 +00:00
} else if (find(".", scratchpad) != -1) {
var tf = num(scratchpad);
var tfs = size(scratchpad);
2020-05-02 01:21:57 +00:00
if (tfs >= 3 and tfs <= 4 and tf != nil and tf >= 0 and tf <= 10.0) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/alt-fuel", tf);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/alt-time", "0000");
setprop("/FMGC/internal/alt-fuel-set", 1);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-04-14 22:12:38 +00:00
} else {
notAllowed(i);
}
2020-03-28 20:40:02 +00:00
} else {
2020-05-02 01:21:57 +00:00
notAllowed(i);
2020-03-28 20:40:02 +00:00
}
2020-05-02 01:21:57 +00:00
} else if (key == "L5" and getprop("/FMGC/internal/block-confirmed") and !getprop("/FMGC/internal/fuel-calculating")) {
2020-03-28 20:40:02 +00:00
if (scratchpad == "CLR") {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/final-fuel", 0.0);
setprop("/FMGC/internal/final-time", "0030");
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/final-fuel-set", 0);
setprop("/FMGC/internal/final-time-set", 0);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad-msg", 0);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-04-14 22:12:38 +00:00
} else if (find(".", scratchpad) != -1) {
var tf = num(scratchpad);
var tfs = size(scratchpad);
2020-05-02 01:21:57 +00:00
if (tfs >= 3 and tfs <= 4 and tf != nil and tf >= 0 and tf <= 10.0) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/final-fuel", tf);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/final-fuel-set", 1);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-04-14 22:12:38 +00:00
} else {
notAllowed(i);
}
2020-03-28 20:40:02 +00:00
} else {
2020-04-14 22:12:38 +00:00
var tf = num(scratchpad);
2020-03-28 20:40:02 +00:00
var tfs = size(scratchpad);
2020-04-14 22:12:38 +00:00
if (tfs == 4 and tf != nil and ((tf >= 0 and tf <= 59) or (tf >= 100 and tf <= 130))) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/final-time", scratchpad);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/final-time-set", 1);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
2020-03-28 20:40:02 +00:00
} else {
notAllowed(i);
}
}
2020-05-02 01:21:57 +00:00
} else if (key == "L6" and getprop("/FMGC/internal/block-confirmed") and !getprop("/FMGC/internal/fuel-calculating")) {
if (scratchpad == "CLR") {
setprop("/FMGC/internal/min-dest-fob", 0);
setprop("/FMGC/internal/min-dest-fob-set", 0);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad-msg", 0);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
} else if (find(".", scratchpad) != -1) {
var tf = num(scratchpad);
var tfs = size(scratchpad);
if (tfs >= 3 and tfs <= 5 and tf != nil and tf >= 0 and tf <= 80.0) {
setprop("/FMGC/internal/min-dest-fob", tf);
setprop("/FMGC/internal/min-dest-fob-set", 1);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/MCDU[" ~ i ~ "]/scratchpad", "");
if (num(getprop("/FMGC/internal/min-dest-fob")) < num(getprop("/FMGC/internal/final-fuel") + getprop("/FMGC/internal/alt-fuel"))) {
genericMessage(i, "CHECK MIN DEST FOB", "wht");
}
} else {
notAllowed(i);
}
} else {
notAllowed(i);
}
} else if (key == "R3" and !getprop("/FMGC/internal/fuel-calculating")) {
2020-03-23 13:48:01 +00:00
if (scratchpad == "CLR") {
notAllowed(i);
} else {
var tfs = size(scratchpad);
if (tfs == 0) {
var zfw = getprop("fdm/jsbsim/inertia/weight-lbs") - getprop("consumables/fuel/total-fuel-lbs");
setprop("MCDU[" ~ i ~ "]/scratchpad", "/" ~ sprintf("%3.1f", math.round(zfw / 1000, 0.1)));
} else if (tfs >= 2 and tfs <= 11 and find("/", scratchpad) != -1) {
var zfwi = split("/", scratchpad);
2020-03-30 01:27:18 +00:00
var zfwcg = num(zfwi[0]);
var zfw = num(zfwi[1]);
var zfwcgs = size(zfwi[0]);
var zfws = size(zfwi[1]);
if (zfwcg != nil and zfwcgs >= 1 and zfwcgs <= 5 and zfwcg > 0 and zfwcg <= 99.9) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/zfwcg", zfwcg);
setprop("/FMGC/internal/zfwcg-set", 1);
if (getprop("/FMGC/internal/block-set") != 1) {
setprop("/FMGC/internal/block", num(getprop("consumables/fuel/total-fuel-lbs") / 1000));
setprop("/FMGC/internal/block-set", 1);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/fuel-request-set", 1);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/FMGC/internal/block-calculating", 0);
setprop("/FMGC/internal/block-confirmed", 1);
2020-03-23 13:48:01 +00:00
}
}
2020-03-30 01:27:18 +00:00
if (zfw != nil and zfws >= 1 and zfws <= 5 and zfw > 0 and zfw <= 999.9) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/zfw", zfw);
setprop("/FMGC/internal/zfw-set", 1);
if (getprop("/FMGC/internal/block-set") != 1) {
setprop("/FMGC/internal/block", num(getprop("consumables/fuel/total-fuel-lbs") / 1000));
setprop("/FMGC/internal/block-set", 1);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/fuel-request-set", 1);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/FMGC/internal/block-calculating", 0);
setprop("/FMGC/internal/block-confirmed", 1);
}
if (getprop("/FMGC/internal/block-confirmed")) {
setprop("/FMGC/internal/fuel-calculating", 1);
2020-03-23 13:48:01 +00:00
}
}
2020-03-30 01:27:18 +00:00
if ((zfwcg != nil and zfwcgs >= 1 and zfwcgs <= 5 and zfwcg > 0 and zfwcg <= 99.9) or (zfw != nil and zfws >= 1 and zfws <= 5 and zfw > 0 and zfw <= 999.9)) {
2020-03-23 13:48:01 +00:00
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
} else {
notAllowed(i);
}
} else if (tfs >= 1 and tfs <= 5) {
var zfwcg = size(scratchpad);
2020-03-30 01:27:18 +00:00
if (num(scratchpad) != nil and zfwcg >= 1 and zfwcg <= 5 and scratchpad > 0 and scratchpad <= 99.9) {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/zfwcg", scratchpad);
setprop("/FMGC/internal/zfwcg-set", 1);
if (getprop("/FMGC/internal/block-set") != 1) {
setprop("/FMGC/internal/block", num(getprop("consumables/fuel/total-fuel-lbs") / 1000));
setprop("/FMGC/internal/block-set", 1);
2020-05-02 01:21:57 +00:00
setprop("/FMGC/internal/fuel-request-set", 1);
setprop("/FMGC/internal/fuel-calculating", 1);
setprop("/FMGC/internal/block-calculating", 0);
setprop("/FMGC/internal/block-confirmed", 1);
2020-03-23 13:48:01 +00:00
}
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
} else {
notAllowed(i);
}
} else {
notAllowed(i);
}
}
2020-04-14 22:12:38 +00:00
} else if (key == "R4") {
if (scratchpad == "CLR") {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/fffq-sensor", "FF+FQ");
2020-04-20 02:08:42 +00:00
setprop("MCDU[" ~ i ~ "]/scratchpad-msg", 0);
2020-04-14 22:12:38 +00:00
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
} else if (find("/", scratchpad) == 0) {
var sensor = substr(scratchpad, 1);
if (sensor == "FF+FQ" or sensor == "FQ+FF" or sensor == "FF" or sensor == "FQ") {
2020-05-02 00:26:05 +00:00
setprop("/FMGC/internal/fffq-sensor", sensor);
2020-04-14 22:12:38 +00:00
setprop("MCDU[" ~ i ~ "]/scratchpad", "");
} else {
notAllowed(i);
}
} else {
notAllowed(i);
}
} else {
notAllowed(i);
2020-03-23 13:48:01 +00:00
}
}