Skip to content

Commit

Permalink
FGFS Addon: Basic rewrite to dynamically registering radios
Browse files Browse the repository at this point in the history
  • Loading branch information
hbeni committed Jun 1, 2023
1 parent 3e2f1fc commit 2b4a096
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 247 deletions.
228 changes: 11 additions & 217 deletions client/fgfs-addon/FGData/Protocol/fgcom-mumble.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,224 +36,20 @@
<output>
<line_separator>newline</line_separator>
<var_separator>,</var_separator>

<!-- ############### -->
<!-- # RADIOS # -->
<!-- ############### -->

<!-- COM 1 -->
<chunk>
<name>com1-frequency</name>
<type>string</type>
<format>COM1_FRQ=%s</format>
<node>/instrumentation/comm[0]/fgcom-mumble/selected-mhz</node>
</chunk>
<chunk>
<name>com1-channel-width-khz</name>
<type>string</type>
<format>COM1_CWKHZ=%s</format>
<node>/instrumentation/comm[0]/frequencies/selected-channel-width-khz</node>
</chunk>
<chunk>
<name>com1-powerbutton</name>
<type>string</type>
<format>COM1_PBT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/comm[0]/operable</node>
<!-- ^^ we use the operable property because it honors all conditions (powered, serviceable, turned on) -->
</chunk>
<chunk>
<name>com1-ptt</name>
<type>string</type>
<format>COM1_PTT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/comm[0]/fgcom-mumble/ptt</node>
</chunk>
<chunk>
<name>com1-vol</name>
<type>string</type>
<format>COM1_VOL=%s</format> <!-- 0.0=mute, <=1.0 full -->
<node>/instrumentation/comm[0]/fgcom-mumble/volume</node>
</chunk>
<chunk>
<name>com1-txpwr</name>
<type>string</type>
<format>COM1_PWR=%s</format> <!-- in watts; Bendix KX165A typical 10w and yields a range of about 50nm@1500ft altitude?? -->
<node>/instrumentation/comm[0]/tx-power</node>
</chunk>
<chunk>
<name>com1-squelch</name>
<type>string</type>
<format>COM1_SQC=%s</format> <!-- 0.0=cutoff nothing, 1.0=cutoff any -->
<node>/instrumentation/comm[0]/cutoff-signal-quality</node>
</chunk>

<!-- COM 2 -->
<chunk>
<name>com2-frequency</name>
<type>string</type>
<format>COM2_FRQ=%s</format>
<node>/instrumentation/comm[1]/fgcom-mumble/selected-mhz</node>
</chunk>
<chunk>
<name>com2-channel-width-khz</name>
<type>string</type>
<format>COM2_CWKHZ=%s</format>
<node>/instrumentation/comm[1]/frequencies/selected-channel-width-khz</node>
</chunk>
<chunk>
<name>com2-powerbutton</name>
<type>string</type>
<format>COM2_PBT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/comm[1]/operable</node>
<!-- ^^ we use the operable property because it honors all conditions (powered, serviceable, turned on) -->
</chunk>
<chunk>
<name>com2-ptt</name>
<type>string</type>
<format>COM2_PTT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/comm[1]/fgcom-mumble/ptt</node>
</chunk>
<chunk>
<name>com2-vol</name>
<type>string</type>
<format>COM2_VOL=%s</format> <!-- 0.0=mute, <=1.0 full -->
<node>/instrumentation/comm[1]/fgcom-mumble/volume</node>
</chunk>
<chunk>
<name>com2-txpwr</name>
<type>string</type>
<format>COM2_PWR=%s</format> <!-- in watts; Bendix KX165A typical 10w and yields a range of about 50nm@1500ft altitude?? -->
<node>/instrumentation/comm[1]/tx-power</node>
</chunk>
<chunk>
<name>com2-squelch</name>
<type>string</type>
<format>COM2_SQC=%s</format> <!-- 0.0=cutoff nothing, 1.0=cutoff any -->
<node>/instrumentation/comm[1]/cutoff-signal-quality</node>
</chunk>

<!-- COM 3 -->
<chunk>
<name>com3-frequency</name>
<type>string</type>
<format>COM3_FRQ=%s</format>
<node>/instrumentation/comm[2]/fgcom-mumble/selected-mhz</node>
</chunk>
<chunk>
<name>com3-channel-width-khz</name>
<type>string</type>
<format>COM3_CWKHZ=%s</format>
<node>/instrumentation/comm[2]/frequencies/selected-channel-width-khz</node>
</chunk>
<chunk>
<name>com3-powerbutton</name>
<type>string</type>
<format>COM3_PBT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/comm[2]/operable</node>
<!-- ^^ we use the operable property because it honors all conditions (powered, serviceable, turned on) -->
</chunk>
<chunk>
<name>com3-ptt</name>
<type>string</type>
<format>COM3_PTT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/comm[2]/fgcom-mumble/ptt</node>
</chunk>
<chunk>
<name>com3-vol</name>
<type>string</type>
<format>COM3_VOL=%s</format> <!-- 0.0=mute, <=1.0 full -->
<node>/instrumentation/comm[2]/fgcom-mumble/volume</node>
</chunk>
<chunk>
<name>com3-txpwr</name>
<type>string</type>
<format>COM3_PWR=%s</format> <!-- in watts; Bendix KX165A typical 10w and yields a range of about 50nm@1500ft altitude?? -->
<node>/instrumentation/comm[2]/tx-power</node>
</chunk>
<chunk>
<name>com3-squelch</name>
<type>string</type>
<format>COM3_SQC=%s</format> <!-- 0.0=cutoff nothing, 1.0=cutoff any -->
<node>/instrumentation/comm[2]/cutoff-signal-quality</node>
</chunk>

<!-- INFO: add more radios here. The plugin ignores not present radios automatically. -->
<!-- Remember that you need to adjust the variables n_COM and COM_offset (and the ADF ones) -->
<!-- in radios.nas, and also don't forget to push the following ADF indexes up. -->


<!-- ADF radio / RDF -->
<chunk>
<!-- UDP RDF client port overwrite: This is needed, because FGFS currently
cannot assign the sending client port, but chooses a random one -->
<name>fgcom-udp-client-port</name>
<type>string</type>
<format>UDP_TGT_PORT=19991</format>
</chunk>

<chunk>
<name>adf1-local-only</name>
<type>string</type>
<format>COM4_PUBLISH=%s</format>
<node>/instrumentation/adf[0]/fgcom-mumble/publish</node>
</chunk>
<chunk>
<name>adf1-operable</name>
<type>string</type>
<format>COM4_PBT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/adf[0]/operable</node>
<!-- ^^ we use the operable property because it honors all conditions (powered, serviceable, turned on) -->
</chunk>
<chunk>
<name>adf1-volume</name>
<type>string</type>
<format>COM4_VOL=%s</format> <!-- 0.0=mute, <=1.0 full -->
<node>/instrumentation/adf[0]/fgcom-mumble/volume</node>
</chunk>
<chunk>
<name>adf1-frequency</name>
<type>string</type>
<format>COM4_FRQ=%s</format>
<node>/instrumentation/adf[0]/fgcom-mumble/selected-mhz</node>
</chunk>
<chunk>
<name>adf1-enableRDF</name>
<type>string</type>
<format>COM4_RDF=%s</format>
<node>/instrumentation/adf[0]/fgcom-mumble/rdf-enabled</node>
</chunk>

<chunk>
<name>adf2-local-only</name>
<type>string</type>
<format>COM5_PUBLISH=%s</format>
<node>/instrumentation/adf[1]/fgcom-mumble/publish</node>
</chunk>
<chunk>
<name>adf2-operable</name>
<type>string</type>
<format>COM5_PBT=%s</format> <!-- 0=inactive, 1=active -->
<node>/instrumentation/adf[1]/operable</node>
<!-- ^^ we use the operable property because it honors all conditions (powered, serviceable, turned on) -->
</chunk>
<chunk>
<name>adf2-volume</name>
<type>string</type>
<format>COM5_VOL=%s</format> <!-- 0.0=mute, <=1.0 full -->
<node>/instrumentation/adf[1]/fgcom-mumble/volume</node>
</chunk>
<chunk>
<name>adf2-frequency</name>
<type>string</type>
<format>COM5_FRQ=%s</format>
<node>/instrumentation/adf[1]/fgcom-mumble/selected-mhz</node>
</chunk>


<!-- ##################### -->
<!-- # RADIO DATA # -->
<!-- ##################### -->
<!-- This is dynamically created from the nasal addon code -->
<chunk>
<name>adf2-enableRDF</name>
<name>radios_data</name>
<type>string</type>
<format>COM5_RDF=%s</format>
<node>/instrumentation/adf[1]/fgcom-mumble/rdf-enabled</node>
<format>%s</format>
<node>/addons/by-id/org.hallinger.flightgear.FGCom-mumble/output/udp</node>
</chunk>



<!-- FGCom 3.0 compatibility: /instrumentation/com[n]/ptt is never set from any aircraft except
c182s or the combar-gui. The old FGCom protocol seems outdated and transmit an old property.
To get compatibility out-of-the-box, we transmit the FGCom PTT property here.
Expand Down Expand Up @@ -318,8 +114,6 @@
<format>AUDIO_HEAR_ALL=%d</format>
<node>/addons/by-id/org.hallinger.flightgear.FGCom-mumble/audio-hear-all</node>
</chunk>


</output>


Expand Down
21 changes: 20 additions & 1 deletion client/fgfs-addon/addon-main.nas
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var main = func( addon ) {
var myAddonId = addon.id;
var mySettingsRootPath = "/addons/by-id/" ~ myAddonId;
var protocolInitialized = 0;
var fgcom_timers = {};

print("Addon FGCom-mumble loading...");

Expand Down Expand Up @@ -60,12 +61,23 @@ var main = func( addon ) {
print("Addon FGCom-mumble loading radios...");
io.load_nasal(root~"/radios.nas", "FGComMumble_radios");
var rdfinputNode = props.globals.getNode(mySettingsRootPath ~ "/rdfinput/",1);
FGComMumble_radios.GenericRadio.setOutputRoot(props.globals.getNode(mySettingsRootPath ~ "/output", 1));
FGComMumble_radios.create_radios();
FGComMumble_radios.start_rdf(rdfinputNode);

# Load the FGCom-mumble combar
print("Addon FGCom-mumble loading combar...");
io.load_nasal(root~"/gui/combar.nas", "FGComMumble_combar");

var update_udp_output = func() {
FGComMumble_radios.update_radios();
var out_prop = props.globals.getNode(mySettingsRootPath ~ "/output/udp",1);
var str_v = [];
foreach (r_out; FGComMumble_radios.GenericRadio.outputRootNode.getChildren("COM")) {
append(str_v, r_out.getValue());
}
out_prop.setValue(string.join(",", str_v));
}

var initProtocol = func() {
if (protocolInitialized == 0) {
Expand Down Expand Up @@ -93,6 +105,10 @@ var main = func( addon ) {
foreach(var p; rdfinputNode.getChildren()) {
p.setValue("");
}

fgcom_timers.udploop = maketimer(1/refresh, nil, update_udp_output);
fgcom_timers.udploop.start();

protocolInitialized = 1;
}
}
Expand All @@ -106,6 +122,10 @@ var main = func( addon ) {
"name" : "fgcom-mumble"
})
);

foreach (var t; keys(fgcom_timers.timers)) fgcom_timers.timers[t].stop();
fgcom_timers.timers = {};

protocolInitialized = 0;
}
}
Expand Down Expand Up @@ -142,7 +162,6 @@ var main = func( addon ) {
var reinit_hostChange = setlistener(mySettingsRootPath ~ "/host", reinitProtocol, 0, 0);
var reinit_portChange = setlistener(mySettingsRootPath ~ "/port", reinitProtocol, 0, 0);


# Check for upates at init time
checkUpdate(mySettingsRootPath);
}
Expand Down
25 changes: 11 additions & 14 deletions client/fgfs-addon/gui/combar.nas
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ canvas.gui.widgets.SpringButton.setDown = func(down = 1)

var combar = {

# Generate buttons for this much COM radios;
# /!\ must be the same as the defined/transmitted radios in the protocol file!
num_radios: FGComMumble_radios.n_COM,

comPTTButton_size: [65,25],
dialogOpened: 0,
show: func() {
Expand All @@ -64,22 +60,21 @@ var combar = {


# Generate PTT buttons for the configured radios
for (var i=0; i<me.num_radios; i=i+1) {
var radio_p = "/instrumentation/comm["~i~"]";
var radio_used = getprop(radio_p~"/fgcom-mumble/is-used");
if (!radio_used) {
print("Addon FGCom-mumble: combar skipping "~radio_p);
var r_num = 1;
foreach (var ridx; keys(FGComMumble_radios.COM_radios)) {
var r = FGComMumble_radios.COM_radios[ridx];
if (!r.is_used) {
print("Addon FGCom-mumble: combar skipping "~r.root.getPath());
continue;
}

var comid = i+1;
print("Addon FGCom-mumble: combar adding "~radio_p~" (COM"~comid~")");
print("Addon FGCom-mumble: combar adding "~r.root.getPath()~" (COM"~r.fgcomPacketStr.getIndex()~")");

var newSizeWidth = math.round((i+1)*me.comPTTButton_size[0] + me.comPTTButton_size[0]/4);
var newSizeWidth = math.round((r_num)*me.comPTTButton_size[0] + me.comPTTButton_size[0]/4);
dlgWindow.setSize([newSizeWidth, me.comPTTButton_size[1]+4]);

var button = canvas.gui.widgets.SpringButton.new(root, canvas.style, {})
.setText("COM" ~ comid)
.setText("COM" ~ r.fgcomPacketStr.getIndex())
.setFixedSize(me.comPTTButton_size[0], me.comPTTButton_size[1]);
var init_button = func(b,rp,ci) {
b.ptt_prop = rp~"/ptt";
Expand All @@ -102,9 +97,11 @@ var combar = {
});
update_button_timer.start();
};
init_button(button, radio_p, comid);
init_button(button, r.root.getPath(), r.fgcomPacketStr.getIndex());

myLayout.addItem(button);

r_num = r_num + 1;
}

me.dialogOpened = 1;
Expand Down
Loading

0 comments on commit 2b4a096

Please sign in to comment.