2021-07-27 10:18:05 +00:00
|
|
|
# A3XX CPDLC - Jonathan Redpath
|
2022-01-11 02:17:41 +00:00
|
|
|
# Copyright (c) 2022 Josh Davidson (Octal450)
|
2020-12-30 17:52:48 +00:00
|
|
|
var A320CPDLCMessageHandler = cpdlc.CPDLCMessageHandler.new();
|
|
|
|
|
2020-08-03 16:50:08 +00:00
|
|
|
var CPDLCmessage = {
|
2020-12-30 17:52:48 +00:00
|
|
|
new: func(text,responses) {
|
2020-08-03 16:50:08 +00:00
|
|
|
var cpdlcMessage = {parents: [CPDLCmessage] };
|
|
|
|
cpdlcMessage.text = text;
|
2020-12-30 17:52:48 +00:00
|
|
|
cpdlcMessage.responses = responses;
|
2020-12-28 16:01:09 +00:00
|
|
|
cpdlcMessage._receivedTime = left(getprop("/sim/time/gmt-string"), 5);
|
|
|
|
cpdlcMessage.receivedTime = split(":", cpdlcMessage._receivedTime)[0] ~ "." ~ split(":", cpdlcMessage._receivedTime)[1] ~ "Z";
|
2020-08-03 16:50:08 +00:00
|
|
|
return cpdlcMessage;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-12-28 16:01:09 +00:00
|
|
|
var DCDUBuffer = {
|
|
|
|
buffer: std.Vector.new(),
|
|
|
|
insertMessage: func(message) {
|
|
|
|
me.buffer.append(message);
|
|
|
|
},
|
|
|
|
popMessage: func() {
|
|
|
|
return me.buffer.pop(0);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-11-29 21:41:52 +00:00
|
|
|
var CPDLCnewMsgFlag = props.globals.getNode("/network/cpdlc/rx/new-message");
|
2020-11-30 16:53:10 +00:00
|
|
|
var CPDLCnewMsgAlert = props.globals.initNode("/network/cpdlc/new-message-ringtone", 0, "BOOL");
|
|
|
|
var CPDLCnewMsgLight = props.globals.initNode("/network/cpdlc/new-message-light", 0, "BOOL");
|
2020-11-29 16:58:38 +00:00
|
|
|
|
2020-12-30 17:52:48 +00:00
|
|
|
var ATCMSGRingCancel = 0;
|
|
|
|
var ATCMsgFlashCancel = 0;
|
|
|
|
|
2020-11-29 21:41:52 +00:00
|
|
|
setlistener("/network/cpdlc/rx/new-message", func() {
|
2020-11-30 16:53:10 +00:00
|
|
|
if (CPDLCnewMsgFlag.getBoolValue()) {
|
2020-12-02 20:29:03 +00:00
|
|
|
fgcommand("cpdlc-next-message");
|
2020-11-30 16:53:10 +00:00
|
|
|
# add to DCDU message buffer to display
|
2020-12-30 17:52:48 +00:00
|
|
|
var message = CPDLCmessage.new(A320CPDLCMessageHandler.getMessage(),A320CPDLCMessageHandler.getReplyOptions());
|
2020-12-28 16:01:09 +00:00
|
|
|
DCDUBuffer.insertMessage(message);
|
|
|
|
if (!canvas_dcdu.DCDU.showingMessage) {
|
|
|
|
canvas_dcdu.DCDU.showNextMessage();
|
|
|
|
}
|
|
|
|
|
2020-12-30 17:52:48 +00:00
|
|
|
ATCMSGRingCancel = 1;
|
2020-11-30 19:17:32 +00:00
|
|
|
var messageType = 0; # urgent or normal
|
|
|
|
ATCMSGRing(messageType);
|
2020-12-30 17:52:48 +00:00
|
|
|
ATCMSGRingCancel = 0;
|
|
|
|
ATCMsgFlashCancel = 1;
|
2020-11-30 16:53:10 +00:00
|
|
|
ATCMSGFlash();
|
2020-12-30 17:52:48 +00:00
|
|
|
ATCMsgFlashCancel = 0;
|
|
|
|
|
2020-11-30 16:53:10 +00:00
|
|
|
# ATC MSG pushbutton: flashes, ringtone after 15 secs, therafter every 15 secs
|
|
|
|
# add DCDU prompts (wilco, etc) associated to message --> so the CPDLC message object must store the correct response for the actual message
|
2020-11-29 21:41:52 +00:00
|
|
|
}
|
2020-11-30 19:17:32 +00:00
|
|
|
}, 0, 1);
|
2020-11-29 16:58:38 +00:00
|
|
|
|
2020-11-30 19:17:32 +00:00
|
|
|
var ATCMSGRing = func(messageType) {
|
2020-11-30 16:53:10 +00:00
|
|
|
settimer(func() {
|
|
|
|
if (!ATCMSGRingCancel) {
|
2020-11-30 19:17:32 +00:00
|
|
|
CPDLCnewMsgAlert.setBoolValue(0);
|
|
|
|
settimer(func() {
|
|
|
|
CPDLCnewMsgAlert.setBoolValue(1);
|
|
|
|
ATCMSGRing(messageType);
|
|
|
|
}, 0.1);
|
2020-11-30 16:53:10 +00:00
|
|
|
}
|
2020-11-30 19:17:32 +00:00
|
|
|
}, (messageType == 0 ? 15 : 5));
|
2020-11-30 16:53:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var ATCMSGFlash = func() {
|
|
|
|
CPDLCnewMsgLight.setBoolValue(!CPDLCnewMsgLight.getBoolValue());
|
|
|
|
settimer(func() {
|
|
|
|
if (!ATCMsgFlashCancel) {
|
|
|
|
ATCMSGFlash();
|
|
|
|
}
|
|
|
|
}, 0.2);
|
|
|
|
};
|
|
|
|
|
2020-11-29 21:41:52 +00:00
|
|
|
# issue fgcommand with cpdlc message to send
|
2020-11-29 16:58:38 +00:00
|
|
|
|
2020-11-30 16:53:10 +00:00
|
|
|
var prefixes = {
|
|
|
|
acPerf: "DUE TO A/C PERFORMANCE",
|
|
|
|
weather: "DUE TO WEATHER",
|
|
|
|
turbulence: "DUE TO TURBULENCE",
|
|
|
|
medical: "DUE TO MEDICAL",
|
|
|
|
technical: "DUE TO TECHNICAL",
|
|
|
|
discretion: "AT PILOTS DISCRETION",
|
|
|
|
};
|
|
|
|
|
|
|
|
var responses = {
|
|
|
|
w: "WILCO",
|
|
|
|
u: "UNABLE",
|
|
|
|
a: "AFFIRM",
|
|
|
|
n: "NEGATIVE",
|
|
|
|
r: "ROGER",
|
|
|
|
s: "STBY",
|
|
|
|
#o: "none?",
|
|
|
|
#y: "any?",
|
|
|
|
};
|
|
|
|
|
2020-11-29 16:58:38 +00:00
|
|
|
var freeText = {
|
2020-11-30 16:53:10 +00:00
|
|
|
new: func() {
|
|
|
|
return {parents: [freeText]};
|
2020-11-29 16:58:38 +00:00
|
|
|
},
|
|
|
|
selection: 9,
|
|
|
|
changed: 0,
|
2020-11-29 21:41:52 +00:00
|
|
|
getText: func() {
|
|
|
|
if (me.selection == 0) {
|
2020-11-30 16:53:10 +00:00
|
|
|
return prefixes["acPerf"];
|
2020-11-29 21:41:52 +00:00
|
|
|
} elsif (me.selection == 1) {
|
2020-11-30 16:53:10 +00:00
|
|
|
return prefixes["weather"];
|
2020-11-29 21:41:52 +00:00
|
|
|
} elsif (me.selection == 2) {
|
2020-11-30 16:53:10 +00:00
|
|
|
return prefixes["turbulence"];
|
2020-11-29 21:41:52 +00:00
|
|
|
} elsif (me.selection == 3) {
|
2020-11-30 16:53:10 +00:00
|
|
|
return prefixes["medical"];
|
2020-11-29 21:41:52 +00:00
|
|
|
} elsif (me.selection == 4) {
|
2020-11-30 16:53:10 +00:00
|
|
|
return prefixes["technical"];
|
2020-11-29 21:41:52 +00:00
|
|
|
} elsif (me.selection == 5) {
|
2020-11-30 16:53:10 +00:00
|
|
|
return prefixes["discretion"];
|
2020-11-29 21:41:52 +00:00
|
|
|
} else {
|
2020-11-30 16:53:10 +00:00
|
|
|
return "";
|
2020-11-29 21:41:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-29 16:58:38 +00:00
|
|
|
};
|
|
|
|
|
2020-11-30 16:53:10 +00:00
|
|
|
var freeTexts = [freeText.new(), freeText.new()];
|