Fix FGCOM (fully supported only >=2019.2!)

parent d3a98155
......@@ -189,3 +189,11 @@ Control-Shift-Пробел КВ2
Большинство систем уже работают на значительно меньшей частоте.
6. Автокоординация FlightGear принудительно отключена, т.к. АБСУ
обеспечивает координирование разворотов.
7. FGCOM не работает с положениями переключателя "Просл." на пульте
СПУ, только "Радио". Это связано с тем, что FGCOM рассчитан только
на одну радиостанцию.
ПРИМЕЧАНИЕ. В версиях FlightGear до 2019.2.0 FGCOM имеет следующие
ограничения:
- работает только для первого полукомплекта УКВ;
- не регулируется громкость от СПУ.
......@@ -1038,3 +1038,69 @@ if(io.stat(mpclash_nas) != nil){
print("Load MPClash: " ~ mpclash_nas);
globals.io.load_nasal(mpclash_nas, "mpclash");
}
# FGCOM interface.
# FGCOM logic is listener-based, so connecting JSBSim directly would not work.
var _fgcom_timer = maketimer(0.1, func{
# Comm selection: 2: UKW1, 3: UKW2.
var tu144_select = getprop("/fdm/jsbsim/systems/comm/SPU/SPU[0]/panel/switch/radio") or 0;
var select = math.max(0, tu144_select - 1);
if(select){
select *= getprop("/fdm/jsbsim/systems/comm/Landysh/UKW[" ~ (select - 1) ~ "]/status/on") or 0;
}
if(select != getprop("/controls/radios/comm-radio-selected")){
setprop("/controls/radios/comm-radio-selected", select);
_fgcom_select = select;
}
for(var ii = 0; ii < 2; ii = ii + 1){
var ptt = getprop("/instrumentation/comm[" ~ ii ~ "]/ptt_jsbsim") or 0;
var ptt_diff = ptt - getprop("/instrumentation/comm[" ~ ii ~ "]/ptt");
if(ptt_diff > 0.5){
setprop("/instrumentation/comm[" ~ ii ~ "]/ptt", 1);
} else if(ptt_diff < -0.0001) {
setprop("/instrumentation/comm[" ~ ii ~ "]/ptt", 0);
}
var freq = getprop("/instrumentation/comm[" ~ ii ~ "]/frequencies/selected-mhz_jsbsim") or 0.0;
var freq_diff = freq - getprop("/instrumentation/comm[" ~ ii ~ "]/frequencies/selected-mhz");
if(math.abs(freq_diff) > 0.0000001){
setprop("/instrumentation/comm[" ~ ii ~ "]/frequencies/selected-mhz", freq);
}
var vol = getprop("/instrumentation/comm[" ~ ii ~ "]/volume_jsbsim") or 0.0;
var vol_diff = vol - (getprop("/instrumentation/comm[" ~ ii ~ "]/volume"));
if(math.abs(vol_diff) > 0.001){
setprop("/instrumentation/comm[" ~ ii ~ "]/volume", vol);
}
}
});
# FGBUG FGCOM becomes inaudible if frequency is changed without restart.
var _fgcom_restart = func(){
if(getprop("/sim/fgcom/enabled")){
setprop("/sim/fgcom/enabled", 0);
settimer(func {
setprop("/sim/fgcom/enabled", 1);
}, 0.1);
}
}
var _fgcom_selected = 0;
setlistener("/controls/radios/comm-radio-selected", func(p) {
var selected = p.getValue();
if(selected != _fgcom_selected){
_fgcom_restart();
}
_fgcom_selected = selected;
});
setlistener("/instrumentation/comm[0]/frequencies/selected-mhz", func(p) {
if(getprop("/controls/radios/comm-radio-selected") == 1){
_fgcom_restart();
}
});
setlistener("/instrumentation/comm[1]/frequencies/selected-mhz", func(p) {
if(getprop("/controls/radios/comm-radio-selected") == 2){
_fgcom_restart();
}
});
_fgcom_timer.start();
......@@ -9,7 +9,7 @@
<property>systems/comm/SPU/SPU[0]/panel/button/ptt</property><!-- On the yoke -->
<property>systems/comm/SPU/SPU[0]/panel/switch/unknown</property><!-- RV-5? -->
<property>systems/comm/SPU/SPU[0]/panel/switch/backup</property>
<property>systems/comm/SPU/SPU[0]/panel/switch/SPU</property><!-- 0: cockpit, 1: kitchen, 2: cabin -->
<property value="0.5">systems/comm/SPU/SPU[0]/panel/pot/SPU</property>
<property value="2">systems/comm/SPU/SPU[0]/panel/switch/radio</property><!-- 0: KW1, 1: KW2, 2: UKW1, 3: UKW2 -->
......
......@@ -357,20 +357,21 @@
<volume-norm alias="/fdm/jsbsim/fcs/NPK/KURS-MP/ARK/backend/volume-norm"/>
</adf>
<!-- SIC The properties postfixed with "_jsbsim" would break FG'S listeners for FGCOM. See Nasal/Tu-144.nas for the interfacing code. -->
<comm n="0">
<ptt alias="/fdm/jsbsim/systems/comm/Landysh/UKW[0]/backend/ptt"/>
<ptt_jsbsim alias="/fdm/jsbsim/systems/comm/Landysh/UKW[0]/backend/ptt"/>
<frequencies>
<selected-mhz alias="/fdm/jsbsim/systems/comm/Landysh/UKW[0]/backend/selected-mhz"/>
<selected-mhz_jsbsim alias="/fdm/jsbsim/systems/comm/Landysh/UKW[0]/backend/selected-mhz"/>
</frequencies>
<volume alias="/fdm/jsbsim/systems/comm/Landysh/UKW[0]/backend/volume"/>
<volume_jsbsim alias="/fdm/jsbsim/systems/comm/Landysh/UKW[0]/backend/volume"/>
<cutoff-signal-quality alias="/fdm/jsbsim/systems/comm/Landysh/UKW[0]/backend/cutoff-signal-quality"/>
</comm>
<comm n="1">
<ptt alias="/fdm/jsbsim/systems/comm/Landysh/UKW[1]/backend/ptt"/>
<ptt_jsbsim alias="/fdm/jsbsim/systems/comm/Landysh/UKW[1]/backend/ptt"/>
<frequencies>
<selected-mhz alias="/fdm/jsbsim/systems/comm/Landysh/UKW[1]/backend/selected-mhz"/>
<selected-mhz_jsbsim alias="/fdm/jsbsim/systems/comm/Landysh/UKW[1]/backend/selected-mhz"/>
</frequencies>
<volume alias="/fdm/jsbsim/systems/comm/Landysh/UKW[1]/backend/volume"/>
<volume_jsbsim alias="/fdm/jsbsim/systems/comm/Landysh/UKW[1]/backend/volume"/>
<cutoff-signal-quality alias="/fdm/jsbsim/systems/comm/Landysh/UKW[1]/backend/cutoff-signal-quality"/>
</comm>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment