2020-05-22 19:58:15 +00:00
# A3XX FMGC MCDU Message Generator and Control
2022-12-31 17:56:08 +00:00
# Copyright (c) 2023 Josh Davidson (Octal450) and Jonathan Redpath (legoboyvdlp)
2020-05-22 19:58:15 +00:00
var TypeIMessage = {
2020-05-25 17:56:13 +00:00
new: func(msgText, isInhibit = 0) {
2020-05-22 19:58:15 +00:00
var msg = { parents: [TypeIMessage] };
msg.msgText = msgText;
2020-05-23 11:16:20 +00:00
msg.colour = "wht";
2020-05-25 17:56:13 +00:00
msg.inhibitable = isInhibit;
2020-05-22 19:58:15 +00:00
return msg;
},
};
var TypeIIMessage = {
2020-05-23 11:16:20 +00:00
new: func(msgText, colour = "wht", isInhibit = 0) {
2020-05-22 19:58:15 +00:00
var msg = { parents: [TypeIIMessage] };
msg.msgText = msgText;
msg.colour = colour;
2020-05-22 23:47:43 +00:00
msg.inhibitable = isInhibit;
2020-05-22 19:58:15 +00:00
return msg;
},
};
var MessageQueueController = {
2020-05-25 17:56:13 +00:00
new: func(computer) {
2020-05-22 23:47:43 +00:00
var msgC = { parents: [MessageQueueController] };
2020-05-25 17:56:13 +00:00
msgC.computer = computer;
msgC.messages = std.Vector.new(); # show left to right
2020-05-22 23:47:43 +00:00
return msgC;
},
2020-05-22 19:58:15 +00:00
# first in first out
addNewMsg: func(msg) {
if (me.messages.size() < 5) {
if (!me.messages.contains(msg)) {
2020-05-25 17:56:13 +00:00
me.messages.append(msg);
2020-05-22 19:58:15 +00:00
}
}
},
getNextMsg: func() {
if (me.messages.size() >= 1) {
2020-05-25 17:56:13 +00:00
return me.messages.vector[0];
}
return nil;
},
deleteAtIndex: func(index) {
if (num(me.messages.size()) >= (index + 1)) {
me.messages.pop(index);
2020-05-22 19:58:15 +00:00
}
},
2021-07-30 11:30:34 +00:00
deleteWithText: func(text) {
foreach (var message; me.messages.vector) {
if (message.msgText == text) {
me.messages.remove(message);
}
}
},
2020-05-22 19:58:15 +00:00
clearQueue: func() {
me.messages.clear();
},
2020-05-25 17:56:13 +00:00
loop: func() {
if (me.getNextMsg() != nil) {
if (!scratchpads[me.computer].showTypeIIMsg) {
if (scratchpads[me.computer].showTypeII(me.getNextMsg())) {
me.deleteAtIndex(me.getNextMsg());
}
}
}
},
2020-05-22 19:58:15 +00:00
};
var scratchpadController = {
2020-05-23 00:40:01 +00:00
new: func(mcdu) {
2020-05-22 23:47:43 +00:00
var sp = { parents: [scratchpadController] };
sp.scratchpad = "";
sp.scratchpadSave = "";
2020-05-23 11:16:20 +00:00
sp.scratchpadColour = "wht";
sp.showTypeIMsg = 0;
sp.showTypeIIMsg = 0;
2020-12-31 20:03:47 +00:00
sp.clrmode = 0; # 1 = CLR mode
2020-05-23 00:40:01 +00:00
sp.mcdu = mcdu;
2020-05-22 23:47:43 +00:00
return sp;
},
2020-05-22 19:58:15 +00:00
2020-05-23 00:40:01 +00:00
addChar: func(character) {
2020-05-22 19:58:15 +00:00
if (size(me.scratchpad) >= 22) {
return;
}
# any shown type ii is hidden
2020-05-23 11:16:20 +00:00
if (me.showTypeIIMsg) {
me.clearTypeII();
2020-05-22 19:58:15 +00:00
}
# any shown type i is hidden
2020-05-23 11:16:20 +00:00
if (me.showTypeIMsg) {
me.clearTypeI();
2020-05-22 19:58:15 +00:00
}
2020-12-31 20:03:47 +00:00
if (me.clrmode == 1) { # prevent add chars in CLR mode
me.clear();
}
else if (character == "CLR") me.clrmode = 1;
2020-05-22 19:58:15 +00:00
me.scratchpad = me.scratchpad ~ character;
2020-05-25 17:56:13 +00:00
me.scratchpadColour = "wht";
2020-05-23 00:40:01 +00:00
me.update();
2020-05-22 19:58:15 +00:00
},
2020-05-23 00:40:01 +00:00
showTypeI: func(msg) {
2020-05-22 19:58:15 +00:00
# any shown type ii is hidden
2020-05-23 11:16:20 +00:00
if (me.showTypeIIMsg) {
me.clearTypeII();
2020-05-22 19:58:15 +00:00
}
2020-05-25 17:56:13 +00:00
if (!me.showTypeIMsg) {
me.showTypeIMsg = 1;
# save any data entered
me.scratchpadSave = me.scratchpad;
}
2020-05-23 11:16:20 +00:00
me.scratchpad = msg.msgText;
me.scratchpadColour = msg.colour;
2020-05-23 00:40:01 +00:00
me.update();
2020-05-22 19:58:15 +00:00
},
2020-05-23 00:40:01 +00:00
showTypeII: func(msg) {
2020-05-22 19:58:15 +00:00
# only show if scratchpad empty
2020-05-25 17:56:13 +00:00
if (me.scratchpad == "") {
2020-05-23 11:16:20 +00:00
me.showTypeIIMsg = 1;
me.scratchpad = msg.msgText;
me.scratchpadColour = msg.colour;
2020-05-25 17:56:13 +00:00
me.update();
return 1;
2020-05-22 19:58:15 +00:00
}
2020-05-23 00:40:01 +00:00
me.update();
2020-05-25 17:56:13 +00:00
return 0;
2020-05-22 19:58:15 +00:00
},
2020-05-23 00:40:01 +00:00
clearTypeI: func() {
2020-05-22 19:58:15 +00:00
me.scratchpad = me.scratchpadSave;
me.scratchpadSave = nil;
2020-05-23 11:16:20 +00:00
me.showTypeIMsg = 0;
2020-05-23 00:40:01 +00:00
me.update();
2020-05-22 19:58:15 +00:00
},
2020-05-23 00:40:01 +00:00
clearTypeII: func() {
2020-05-23 11:16:20 +00:00
me.showTypeIIMsg = 0;
2020-05-22 19:58:15 +00:00
me.empty();
2020-05-23 00:40:01 +00:00
me.update();
2020-05-22 19:58:15 +00:00
},
2020-05-23 11:37:22 +00:00
override: func(str) {
if (me.scratchpad == "USING COST INDEX N") {
me.scratchpad = "USING COST INDEX " ~ str;
me.update();
}
},
2020-05-22 19:58:15 +00:00
empty: func() {
me.scratchpad = "";
2020-12-31 20:03:47 +00:00
me.clrmode = 0;
2020-05-23 00:40:01 +00:00
me.update();
2020-05-22 19:58:15 +00:00
},
clear: func() {
2020-05-23 11:16:20 +00:00
if (me.scratchpad == "CLR") {
me.empty();
} elsif (me.showTypeIMsg) {
me.clearTypeI();
2020-05-22 19:58:15 +00:00
} elsif (!me.showTypeIIMsg) {
me.scratchpad = left(me.scratchpad, size(me.scratchpad) - 1);
} else {
2020-05-23 11:16:20 +00:00
me.clearTypeII();
2020-05-22 19:58:15 +00:00
}
2020-05-23 00:40:01 +00:00
me.update();
},
update: func() {
if (me.mcdu == 1) {
canvas_mcdu.MCDU_1.updateScratchpadCall();
} else {
canvas_mcdu.MCDU_2.updateScratchpadCall();
}
2020-05-22 19:58:15 +00:00
},
};
var MessageController = {
typeIMessages: std.Vector.new([
2020-05-23 11:37:22 +00:00
TypeIMessage.new("AOC DISABLED"),TypeIMessage.new("AWY/WPT MISMATCH"),TypeIMessage.new("DIR TO IN PROGRESS"),
TypeIMessage.new("ENTRY OUT OF RANGE"),TypeIMessage.new("FORMAT ERROR"),TypeIMessage.new("INSERT/ERASE TMPY FIRST"),
TypeIMessage.new("LIST OF 20 IN USE"),TypeIMessage.new("PILOT ELEMENT RETAINED"),TypeIMessage.new("NOT ALLOWED"),
TypeIMessage.new("NOT IN DATA BASE"),TypeIMessage.new("ONLY SPD ENTRY ALLOWED"),TypeIMessage.new("REVISION IN PROGRESS"),
2020-05-25 17:56:13 +00:00
TypeIMessage.new("TMPY F-PLN EXISTS", 1),TypeIMessage.new("SELECT DESIRED SYSTEM"),TypeIMessage.new("SELECT HDG/TRK FIRST"),
2020-06-27 22:26:36 +00:00
TypeIMessage.new("USING COST INDEX N", 1),TypeIMessage.new("WAIT FOR SYSTEM RESPONSE"),TypeIMessage.new("RWY/LS MISMATCH"),
2020-07-30 18:36:00 +00:00
TypeIMessage.new("VHF3 VOICE MSG NOT GEN"),TypeIMessage.new("NO COMM MSG NOT GEN"),TypeIMessage.new("WX UPLINK"),
2020-08-07 10:44:03 +00:00
TypeIMessage.new("SIMBRIEF DOWNLOAD FAILED"),TypeIMessage.new("MISSING USERNAME"),TypeIMessage.new("AOC ACT F-PLN UPLINK"),
2021-01-20 14:51:36 +00:00
TypeIMessage.new("NO ANSWER TO REQUEST"),TypeIMessage.new("NO D-ATIS AVAILABLE"),TypeIMessage.new("NO METAR AVAILABLE"),TypeIMessage.new("BAD SERVER RESPONSE"),
2021-01-14 14:22:12 +00:00
TypeIMessage.new("WIND DATA UPLINK"),TypeIMessage.new("CHECK ALT WIND"),TypeIMessage.new("INVALID WIND UPLINK"),TypeIMessage.new("WIND UPLINK EXISTS"), #p.533
TypeIMessage.new("FM DATALINK UNAVAIL"),TypeIMessage.new("NOT XMITTED TO ACARS"), #p.559
TypeIMessage.new("PRINTER NOT AVAILABLE"),
2020-05-22 19:58:15 +00:00
]),
typeIIMessages: std.Vector.new([
2020-05-25 17:56:13 +00:00
TypeIIMessage.new("LAT DISCONT AHEAD", "amb", 0),TypeIIMessage.new("MORE DRAG"),TypeIIMessage.new("RWY/LS MISMATCH", "amb", 0),TypeIIMessage.new("STEP DELETED"),
2020-06-03 13:20:39 +00:00
TypeIIMessage.new("STEP NOW"),TypeIIMessage.new("TIME TO EXIT", "amb", 0),TypeIIMessage.new("V1/VR/V2 DISAGREE", "amb", 0),
2022-01-25 12:30:35 +00:00
TypeIIMessage.new("T.O SPEEDS TOO LOW", "amb", 0),TypeIIMessage.new("CHECK TAKE OFF DATA", "amb", 0),
2021-01-14 14:22:12 +00:00
TypeIIMessage.new("CHECK DEST DATA", "amb", 0), #p.533
2021-07-29 22:40:38 +00:00
TypeIIMessage.new("GPS PRIMARY"),TypeIIMessage.new("GPS PRIMARY LOST", "amb", 0),
2020-05-22 19:58:15 +00:00
]),
2020-06-03 13:20:39 +00:00
# to speed to low - new on a320, margin against vmcg / vs1g
2020-05-22 19:58:15 +00:00
getTypeIMsgByText: func(text) {
2020-05-22 23:47:43 +00:00
return me.getMsgByText(text, me.typeIMessages.vector);
2020-05-22 19:58:15 +00:00
},
getTypeIIMsgByText: func(text) {
2020-05-22 23:47:43 +00:00
return me.getMsgByText(text, me.typeIIMessages.vector);
2020-05-22 19:58:15 +00:00
},
getMsgByText: func(text, theVector) {
foreach (var message; theVector) {
2021-07-29 22:40:38 +00:00
if (message.msgText == text) {
2020-05-22 19:58:15 +00:00
return message;
}
}
return nil;
},
2020-05-22 23:47:43 +00:00
};
2020-05-25 17:56:13 +00:00
var scratchpads = [scratchpadController.new(1), scratchpadController.new(2)];
var messageQueues = [MessageQueueController.new(0), MessageQueueController.new(1)];
var loop1MsgTimer = func() {
if (messageQueues[0].getNextMsg() != nil) {
if (!scratchpads[messageQueues[0].computer].showTypeIIMsg) {
if (scratchpads[messageQueues[0].computer].showTypeII(messageQueues[0].getNextMsg())) {
messageQueues[0].deleteAtIndex(0);
}
}
}
}
var loop2MsgTimer = func() {
if (messageQueues[1].getNextMsg() != nil) {
if (!scratchpads[messageQueues[1].computer].showTypeIIMsg) {
if (scratchpads[messageQueues[1].computer].showTypeII(messageQueues[1].getNextMsg())) {
messageQueues[1].deleteAtIndex(0);
}
}
}
}
var mcduMsgtimer1 = maketimer(1, loop1MsgTimer);
var mcduMsgtimer2 = maketimer(1, loop2MsgTimer);