1
0
Fork 0
A320-family/Nasal/Systems/Comm/HF.nas

107 lines
2.4 KiB
Text
Raw Normal View History

# A3XX High Frequency Radio
# Jonathan Redpath
# Copyright (c) 2020 Josh Davidson (Octal450)
var toneControl = props.globals.getNode("/systems/comm/hf/tone1000hz");
var reception = props.globals.getNode("/systems/comm/hf/reception");
var _toneTime = nil;
var highFrequencyRadio = {
2020-04-21 13:24:05 +00:00
selectedChannelKhz: int(rand() * 10) ~ int(rand() * 10) ~ int(rand() * 10) ~ int(rand() * 10),
transmit: 0,
tuned: 0,
overrideDataLink: 0,
datalinkConnected: 0,
_transmitTime: nil,
2020-04-21 13:24:05 +00:00
new: func(powerNode, num) {
var a = { parents:[highFrequencyRadio] };
a.powerNode = powerNode;
2020-04-21 13:24:05 +00:00
a.num = num;
return a;
},
selectChannel: func(selectedKhz) {
if (selectedKhz < 2000 or selectedKhz > 29999) { return; }
if (selectedKhz - int(selectedKhz) != 0) { return; }
me.selectedChannelKhz = selectedKhz;
me.tuned = 0;
2020-04-21 13:24:05 +00:00
rmp.update_active_vhf(me.num + 4);
},
pttToggle: func() {
if (me.powerNode.getValue() < 110) {
me.transmit = 0;
return;
}
if (me.transmit) {
me.transmit = 0;
reception.setValue(1);
} else {
me.transmit = 1;
reception.setValue(0);
}
if (me.transmit) {
_transmitTime = pts.Sim.Time.elapsedSec.getValue();
2020-04-21 13:24:05 +00:00
transmitTimer.start();
if (me.selectedChannelKhz < 2800 or me.selectedChannelKhz > 23999) {
me.generate1000Hz();
return;
}
if (!me.tuned) {
me.generate1000Hz(5);
me.tuned = 1;
}
} else {
2020-04-21 13:24:05 +00:00
transmitTimer.stop();
ecam.transmitFlag = 0;
if (_toneTime == nil) {
toneControl.setValue(0);
}
_transmitTime = nil;
}
},
monitorPTT: func() {
2020-04-21 13:24:05 +00:00
if (me.transmit) {
if (pts.Sim.Time.elapsedSec.getValue() > _transmitTime + 60) {
ecam.transmitFlag = 1;
}
}
},
generate1000Hz: func(timeSec = 0) {
if (timeSec == 0) {
toneControl.setValue(1);
} else {
toneControl.setValue(1);
_toneTime = pts.Sim.Time.elapsedSec.getValue() + timeSec;
toneTimer.start();
}
},
datalink: func() {
if (me.powerNode.getValue() < 115) {
me.datalinkConnected = 0;
return;
}
if (overrideConnected or !pts.Gear.wow[0].getValue()) {
datalinkConnected = 1;
} else {
datalinkConnected = 0;
}
},
};
2020-04-21 13:24:05 +00:00
var HFS = [highFrequencyRadio.new(systems.ELEC.Bus.acEssShed, 0), highFrequencyRadio.new(systems.ELEC.Bus.ac2, 1)];
var toneTimer = maketimer(1, func() {
if (pts.Sim.Time.elapsedSec.getValue() > _toneTime) {
toneControl.setValue(0);
_toneTime = nil;
toneTimer.stop();
}
2020-04-21 13:24:05 +00:00
});
var transmitTimer = maketimer(1, func() {
HFS[0].monitorPTT();
});