This repository has been archived on 2021-09-26. You can view files and clone it, but cannot push or open issues or pull requests.
IDG-A32X/Nasal/ECAM/ECAM-controller.nas

280 lines
8.7 KiB
Text
Raw Normal View History

# A3XX Electronic Centralised Aircraft Monitoring System
# Copyright (c) 2019 Jonathan Redpath (legoboyvdlp)
2019-02-12 19:18:55 +00:00
var leftmsgEnable = props.globals.initNode("/ECAM/show-left-msg", 1, "BOOL");
var rightmsgEnable = props.globals.initNode("/ECAM/show-right-msg", 1, "BOOL");
2019-02-11 20:58:05 +00:00
var lines = [props.globals.getNode("/ECAM/msg/line1", 1), props.globals.getNode("/ECAM/msg/line2", 1), props.globals.getNode("/ECAM/msg/line3", 1), props.globals.getNode("/ECAM/msg/line4", 1), props.globals.getNode("/ECAM/msg/line5", 1), props.globals.getNode("/ECAM/msg/line6", 1), props.globals.getNode("/ECAM/msg/line7", 1), props.globals.getNode("/ECAM/msg/line8", 1)];
var linesCol = [props.globals.getNode("/ECAM/msg/linec1", 1), props.globals.getNode("/ECAM/msg/linec2", 1), props.globals.getNode("/ECAM/msg/linec3", 1), props.globals.getNode("/ECAM/msg/linec4", 1), props.globals.getNode("/ECAM/msg/linec5", 1), props.globals.getNode("/ECAM/msg/linec6", 1), props.globals.getNode("/ECAM/msg/linec7", 1), props.globals.getNode("/ECAM/msg/linec8", 1)];
2019-02-12 19:18:55 +00:00
var rightLines = [props.globals.getNode("/ECAM/rightmsg/line1", 1), props.globals.getNode("/ECAM/rightmsg/line2", 1), props.globals.getNode("/ECAM/rightmsg/line3", 1), props.globals.getNode("/ECAM/rightmsg/line4", 1), props.globals.getNode("/ECAM/rightmsg/line5", 1), props.globals.getNode("/ECAM/rightmsg/line6", 1), props.globals.getNode("/ECAM/rightmsg/line7", 1), props.globals.getNode("/ECAM/rightmsg/line8", 1)];
var rightLinesCol = [props.globals.getNode("/ECAM/rightmsg/linec1", 1), props.globals.getNode("/ECAM/rightmsg/linec2", 1), props.globals.getNode("/ECAM/rightmsg/linec3", 1), props.globals.getNode("/ECAM/rightmsg/linec4", 1), props.globals.getNode("/ECAM/rightmsg/linec5", 1), props.globals.getNode("/ECAM/rightmsg/linec6", 1), props.globals.getNode("/ECAM/rightmsg/linec7", 1), props.globals.getNode("/ECAM/rightmsg/linec8", 1)];
var statusLines = [props.globals.getNode("/ECAM/status/line1", 1), props.globals.getNode("/ECAM/status/line2", 1), props.globals.getNode("/ECAM/status/line3", 1), props.globals.getNode("/ECAM/status/line4", 1), props.globals.getNode("/ECAM/status/line5", 1), props.globals.getNode("/ECAM/status/line6", 1), props.globals.getNode("/ECAM/status/line7", 1), props.globals.getNode("/ECAM/status/line8", 1)];
var statusLinesCol = [props.globals.getNode("/ECAM/status/linec1", 1), props.globals.getNode("/ECAM/status/linec2", 1), props.globals.getNode("/ECAM/status/linec3", 1), props.globals.getNode("/ECAM/status/linec4", 1), props.globals.getNode("/ECAM/status/linec5", 1), props.globals.getNode("/ECAM/status/linec6", 1), props.globals.getNode("/ECAM/status/linec7", 1), props.globals.getNode("/ECAM/status/linec8", 1)];
2019-02-12 12:20:19 +00:00
var leftOverflow = props.globals.initNode("/ECAM/warnings/overflow-left", 0, "BOOL");
var rightOverflow = props.globals.initNode("/ECAM/warnings/overflow-right", 0, "BOOL");
var overflow = props.globals.initNode("/ECAM/warnings/overflow", 0, "BOOL");
2019-02-11 20:58:05 +00:00
2019-02-12 19:18:55 +00:00
var dc_ess = props.globals.getNode("/systems/electrical/bus/dc-ess", 1);
2019-02-12 12:20:19 +00:00
var lights = [props.globals.initNode("/ECAM/warnings/master-warning-light", 0, "BOOL"), props.globals.initNode("/ECAM/warnings/master-caution-light", 0, "BOOL")];
var aural = [props.globals.initNode("/sim/sound/warnings/crc", 0, "BOOL"), props.globals.initNode("/sim/sound/warnings/chime", 0, "BOOL")];
2019-02-12 19:18:55 +00:00
var warningFlash = props.globals.initNode("/ECAM/warnings/master-warning-flash", 0, "BOOL");
var lineIndex = 0;
var rightLineIndex = 0;
var statusIndex = 0;
2019-03-16 10:43:52 +00:00
var flash = 0;
var warning = {
new: func(msg,colour = "g",aural = 9,light = 9,hasSubmsg = 0,lastSubmsg = 0) {
var t = {parents:[warning]};
t.msg = msg;
t.colour = colour;
t.aural = aural;
t.light = light;
t.hasSubmsg = hasSubmsg;
t.lastSubmsg = lastSubmsg;
t.active = 0;
t.noRepeat = 0;
t.clearFlag = 0;
return t
},
write: func() {
2019-02-11 20:58:05 +00:00
if (me.active == 0) {return;}
2019-02-12 12:20:19 +00:00
lineIndex = 0;
2019-02-19 18:14:58 +00:00
while (lineIndex < 7 and lines[lineIndex].getValue() != "") {
2019-02-12 12:20:19 +00:00
lineIndex = lineIndex + 1; # go to next line until empty line
}
2019-02-19 18:14:58 +00:00
if (lineIndex == 7) {
2019-02-11 20:58:05 +00:00
leftOverflow.setBoolValue(1);
2019-02-15 21:17:34 +00:00
} elsif (leftOverflow.getBoolValue()) {
2019-02-11 20:58:05 +00:00
leftOverflow.setBoolValue(0);
}
2019-02-12 12:20:19 +00:00
if (lines[lineIndex].getValue() == "" and me.msg != "" and lineIndex <= 7) { # at empty line. Also checks if message is not blank to allow for some warnings with no displayed msg, eg stall
lines[lineIndex].setValue(me.msg);
linesCol[lineIndex].setValue(me.colour);
}
},
warnlight: func() {
2019-03-16 10:43:52 +00:00
if (me.light >= 1 or me.noRepeat == 1 or me.active == 0) {return;}
lights[me.light].setBoolValue(1);
me.noRepeat = 1;
},
sound: func() {
2019-03-16 10:43:52 +00:00
if (me.aural > 1 or me.active == 0) {return;}
#if (!aural[me.aural].getBoolValue()) {
aural[me.aural].setBoolValue(1);
#}
},
};
var memo = {
new: func(msg,colour = "g") {
var t = {parents:[memo]};
t.msg = msg;
t.colour = colour;
t.active = 0;
return t
},
write: func() {
2019-02-11 20:58:05 +00:00
if (me.active == 1) {
2019-02-12 19:18:55 +00:00
rightLineIndex = 0;
while (rightLines[rightLineIndex].getValue() != "" and rightLineIndex <= 7) {
rightLineIndex = rightLineIndex + 1; # go to next line until empty line
2019-02-11 20:58:05 +00:00
}
2019-02-12 19:18:55 +00:00
if (rightLineIndex > 7) {
rightOverflow.setBoolValue(1);
2019-02-15 21:17:34 +00:00
} elsif (rightOverflow.getBoolValue()) {
2019-02-12 19:18:55 +00:00
rightOverflow.setBoolValue(0);
2019-02-11 20:58:05 +00:00
}
2019-02-14 01:29:40 +00:00
if (rightLines[rightLineIndex].getValue() == "" and rightLineIndex <= 7) { # at empty line
2019-02-12 19:18:55 +00:00
rightLines[rightLineIndex].setValue(me.msg);
rightLinesCol[rightLineIndex].setValue(me.colour);
2019-02-11 20:58:05 +00:00
}
}
},
};
2018-11-26 13:00:28 +00:00
var status = {
2019-02-20 16:53:28 +00:00
new: func(msg,colour) {
2018-11-26 13:00:28 +00:00
var t = {parents:[status]};
t.msg = msg;
t.colour = colour;
t.active = 0;
2018-11-26 13:00:28 +00:00
return t
},
write: func() {
2019-02-11 20:58:05 +00:00
if (me.active == 1) {
2019-02-12 19:18:55 +00:00
statusIndex = 0;
while (statusLines[statusIndex].getValue() != "" and statusIndex <= 7) {
statusIndex = statusIndex + 1; # go to next line until empty line
2019-02-11 20:58:05 +00:00
}
2019-02-12 19:18:55 +00:00
if (statusLines[statusIndex].getValue() == "" and statusIndex <= 7) { # at empty line
statusLines[rightLineIndex].setValue(me.msg);
statusLinesCol[rightLineIndex].setValue(me.colour);
2019-02-11 20:58:05 +00:00
}
2018-11-26 13:00:28 +00:00
}
},
};
var ECAM_controller = {
init: func() {
ECAMloopTimer.start();
2018-12-29 17:41:26 +00:00
me.reset();
},
loop: func() {
# check active messages
2019-02-08 19:57:48 +00:00
messages_priority_3();
messages_priority_2();
2019-02-08 19:57:48 +00:00
messages_priority_1();
messages_priority_0();
messages_memo();
messages_right_memo();
# clear display momentarily
2019-02-12 19:18:55 +00:00
for(var n = 0; n <= 7; n += 1) {
lines[n].setValue("");
}
2019-02-12 19:18:55 +00:00
for(var n = 0; n <= 7; n += 1) {
rightLines[n].setValue("");
}
# write to ECAM
foreach (var w; warnings.vector) {
w.write();
}
2019-03-16 10:43:52 +00:00
foreach (var w2; warnings.vector) {
if (w2.active == 1) {
if (w2.noRepeat == 0) {
w2.warnlight();
}
w2.sound();
break
}
}
if (lines[0].getValue() == "" and flash == 0) { # disable left memos if a warning exists. Warnings are processed first, so this stops leftmemos if line1 is not empty
foreach (var l; leftmemos.vector) {
l.write();
}
}
foreach (var sL; specialLines.vector) {
sL.write();
}
foreach (var sF; secondaryFailures.vector) {
sF.write();
}
foreach (var m; memos.vector) {
m.write();
}
2018-11-22 12:56:28 +00:00
2019-02-12 19:18:55 +00:00
if (leftOverflow.getBoolValue() == 1 or leftOverflow.getBoolValue() == 1) {
overflow.setBoolValue(1);
} elsif (leftOverflow.getBoolValue() == 0 and leftOverflow.getBoolValue() == 0) {
overflow.setBoolValue(0);
2018-11-22 12:56:28 +00:00
}
},
2018-12-29 13:17:00 +00:00
reset: func() {
foreach (var w; warnings.vector) {
if (w.active == 1) {
w.active = 0;
}
}
foreach (var l; leftmemos.vector) {
if (l.active == 1) {
l.active = 0;
}
}
foreach (var sL; specialLines.vector) {
if (sL.active == 1) {
sL.active = 0;
}
}
foreach (var sF; secondaryFailures.vector) {
if (sF.active == 1) {
sF.active = 0;
}
}
foreach (var m; memos.vector) {
if (m.active == 1) {
m.active = 0;
}
}
},
2019-02-08 19:57:48 +00:00
clear: func() {
2019-02-08 20:05:54 +00:00
foreach (var w; warnings.vector) {
if (w.active == 1) {
if (w.hasSubmsg == 1) { continue; }
2019-02-11 20:58:05 +00:00
w.clearFlag = 1;
break;
}
}
},
recall: func() {
foreach (var w; warnings.vector) {
if (w.clearFlag == 1) {
2019-02-12 19:18:55 +00:00
w.noRepeat = 0;
2019-02-11 20:58:05 +00:00
w.clearFlag = 0;
2019-02-08 20:05:54 +00:00
break;
}
}
2019-02-08 19:57:48 +00:00
},
};
setlistener("/systems/electrical/bus/dc-ess", func {
2019-02-12 19:18:55 +00:00
if (dc_ess.getValue() < 25) {
2018-12-29 17:41:26 +00:00
ECAM_controller.reset();
}
}, 0, 0);
var ECAMloopTimer = maketimer(0.2, func {
ECAM_controller.loop();
});
# Flash Master Warning Light
2019-01-12 17:27:40 +00:00
var warnTimer = maketimer(0.25, func {
2019-02-15 21:17:34 +00:00
if (!lights[0].getBoolValue()) {
warnTimer.stop();
2019-02-12 19:18:55 +00:00
warningFlash.setBoolValue(0);
2019-02-15 21:17:34 +00:00
} else if (!warningFlash.getBoolValue()) {
2019-02-12 19:18:55 +00:00
warningFlash.setBoolValue(1);
} else {
2019-02-12 19:18:55 +00:00
warningFlash.setBoolValue(0);
}
});
setlistener("/ECAM/warnings/master-warning-light", func {
2019-02-15 21:17:34 +00:00
if (lights[0].getBoolValue()) {
2019-02-12 19:18:55 +00:00
warningFlash.setBoolValue(0);
warnTimer.start();
} else {
warnTimer.stop();
2019-02-12 19:18:55 +00:00
warningFlash.setBoolValue(0);
}
}, 0, 0);