Skip to content

Commit b5f8a05

Browse files
committed
radio control fixes, tune button now works with config, configuration is still buggy
1 parent f2f0356 commit b5f8a05

File tree

9 files changed

+269
-121
lines changed

9 files changed

+269
-121
lines changed

blueprints/preferences.blp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ StringList modes_model {
2222

2323
/* Radio connection models */
2424
Gtk.StringList connection_types_model {
25-
strings: ["None", "Serial", "Network", "USB"];
25+
strings: ["None", "Serial/USB", "Network"];
2626
}
2727

2828
Gtk.StringList baud_rates_model {

data/com.k0vcz.Artemis.gschema.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,13 @@
7373

7474
<!-- Radio Settings -->
7575
<key name="radio-connection-type" type="s">
76-
<default>"none"</default>
76+
<default>"NONE"</default>
7777
<summary>Radio connection type</summary>
78-
<description>How to connect to the radio (none, serial, network, usb).</description>
78+
<description>How to connect to the radio (none, serial/USB, network).</description>
7979
<choices>
80-
<choice value="none"/>
81-
<choice value="serial"/>
82-
<choice value="network"/>
83-
<choice value="usb"/>
80+
<choice value="NONE"/>
81+
<choice value="SERIAL/USB"/>
82+
<choice value="NETWORK"/>
8483
</choices>
8584
</key>
8685

data/meson.build

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ appstream_file = i18n.merge_file(
2121
)
2222

2323
appstreamcli = find_program('appstreamcli', required: false, disabler: true)
24-
test('Validate appstream file', appstreamcli,
24+
if appstreamcli.found()
25+
test('Validate appstream file', appstreamcli,
2526
args: ['validate', '--no-net', '--explain', appstream_file])
27+
endif
2628

2729
install_data('com.k0vcz.Artemis.gschema.xml',
2830
install_dir: get_option('datadir') / 'glib-2.0' / 'schemas'
2931
)
3032

3133
compile_schemas = find_program('glib-compile-schemas', required: false, disabler: true)
32-
test('Validate schema file',
34+
if compile_schemas.found()
35+
test('Validate schema file',
3336
compile_schemas,
3437
args: ['--strict', '--dry-run', meson.current_source_dir()])
35-
38+
endif
3639

3740
service_conf = configuration_data()
3841
service_conf.set('bindir', get_option('prefix') / get_option('bindir'))

src/RadioControl.vapi

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[CCode (cname = "RadioMode")]
1+
[CCode (cname = "enum RadioMode")]
22
public enum RadioMode {
33
UNKNOWN,
44
AM,
@@ -37,14 +37,21 @@ public class RadioControl : GLib.Object {
3737
public RadioControl ();
3838

3939
// Async operations
40-
public Dex.Future connect_async (RadioConfiguration configuration);
41-
public Dex.Future disconnect_async ();
40+
[CCode (cname = "radio_control_connect_async")]
41+
public Dex.Future connect (RadioConfiguration configuration);
4242

43-
public Dex.Future get_vfo_async ();
44-
public Dex.Future set_vfo_async (int frequency);
43+
[CCode (cname = "radio_control_disconnect_async")]
44+
public Dex.Future disconnect ();
4545

46-
public Dex.Future get_mode_async ();
47-
public Dex.Future set_mode_async (RadioMode mode);
46+
[CCode (cname = "radio_control_get_vfo_async")]
47+
public Dex.Future get_vfo ();
48+
[CCode (cname = "radio_control_set_vfo_async")]
49+
public Dex.Future set_vfo (int frequency);
50+
51+
[CCode (cname = "radio_control_get_mode_async")]
52+
public Dex.Future get_mode ();
53+
[CCode (cname = "radio_control_set_mode_async")]
54+
public Dex.Future set_mode (RadioMode mode);
4855

4956
// Property
5057
public bool is_rig_connected { get; }

src/application.vala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020

2121
public sealed class Application : Adw.Application {
22+
public signal void radio_status (bool is_connected);
23+
2224
private static Quark _current_spot_hash = 0;
2325
public static Quark current_spot_hash {
2426
get {
@@ -41,6 +43,9 @@ public sealed class Application : Adw.Application {
4143
public static PotaClient pota_client { get; private set; }
4244
public static MapWindow? map_window { get; private set; default = null; }
4345

46+
public static RadioControl? radio_control { get; private set; default = null; }
47+
public static bool is_radio_connected { get; set; default = false; }
48+
4449
public static Application app;
4550
public static Gtk.Window win;
4651

@@ -124,6 +129,17 @@ public sealed class Application : Adw.Application {
124129
pota_client = new PotaClient ();
125130
spot_database = new SpotDb ();
126131
callsign_cache = new CallsignCache (3600);
132+
133+
radio_control = new RadioControl ();
134+
radio_control.radio_connected.connect (() => {
135+
radio_status (true);
136+
});
137+
radio_control.radio_disconnected.connect (() => {
138+
radio_status (false);
139+
});
140+
radio_control.radio_status.connect ((frequency, radio_mode) => {
141+
radio_status (Application.radio_control.is_rig_connected);
142+
});
127143
}
128144

129145
public override void activate () {

src/preferences.vala

Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
using Gee;
2222
using GUdev;
2323

24+
static string _strip_quotes (string s) {
25+
if (s.has_prefix ("\"") && s.has_suffix ("\"") && (s.length >= 2))
26+
return s.substring (1, s.length - 2);
27+
return s;
28+
}
29+
2430
public sealed class PreferencesDialog : Object {
2531
private Adw.PreferencesDialog dialog;
2632
private Adw.EntryRow row_callsign;
@@ -58,6 +64,8 @@ public sealed class PreferencesDialog : Object {
5864
private File? logbook_csv = null;
5965
private GUdev.Client udev_client;
6066

67+
private Dex.Future connect_future;
68+
6169
public PreferencesDialog () {
6270
Object ();
6371
}
@@ -97,6 +105,10 @@ public sealed class PreferencesDialog : Object {
97105
row_radio_model.model = radio_model_list;
98106
row_radio_model.enable_search = true;
99107
row_radio_model.search_match_mode = Gtk.StringFilterMatchMode.SUBSTRING;
108+
row_radio_model.notify ["selected"].connect (() => {
109+
var model = radio_models[row_radio_model.selected - 1];
110+
print ("radio model selected %s".printf (model.display_name));
111+
});
100112

101113
row_device_path = builder.get_object ("row_device_path") as Adw.ComboRow;
102114
row_device_path.model = get_serial_devices ();
@@ -286,15 +298,14 @@ public sealed class PreferencesDialog : Object {
286298

287299
var selected_type = model.get_string (row_connection_type.selected);
288300

289-
switch (selected_type.down ()) {
290-
case "serial" :
291-
case "usb":
301+
switch (selected_type.up ()) {
302+
case "SERIAL/USB" :
292303
serial_settings_group.visible = true;
293304
network_settings_group.visible = false;
294305
row_radio_model.visible = true;
295306
radio_test_group.visible = true;
296307
break;
297-
case "network":
308+
case "NETWORK":
298309
row_radio_model.visible = true;
299310
row_radio_model.selected = 1;
300311
row_radio_model.selectable = false;
@@ -317,22 +328,66 @@ public sealed class PreferencesDialog : Object {
317328
connection_status_icon.icon_name = "content-loading-symbolic";
318329
connection_status_label.label = _ ("Testing…");
319330

320-
test_radio_connection.begin ((obj, res) => {
321-
bool success = test_radio_connection.end (res);
331+
test_radio_connection ();
332+
}
322333

323-
test_connection_button.sensitive = true;
324-
if (success) {
325-
connection_status_icon.icon_name = "network-idle-symbolic";
326-
connection_status_label.label = _ ("Connected");
327-
} else {
328-
connection_status_icon.icon_name = "network-offline-symbolic";
329-
connection_status_label.label = _ ("Failed");
334+
void test_radio_connection () {
335+
if (Application.radio_control == null || row_radio_model.selected == 0) return;
336+
var radio_models = RadioControl.get_radio_models ();
337+
var radio_model = radio_models[row_radio_model.selected - 1]; // padded for "None" selection
338+
339+
var connection_type = row_connection_type.model.get_item (row_connection_type.selected) as Gtk.StringObject;
340+
var device_path = row_device_path.model.get_item (row_device_path.selected) as Gtk.StringObject;
341+
var baud_rate = row_baud_rate.model.get_item (row_baud_rate.selected) as Gtk.StringObject;
342+
343+
var config = RadioConfiguration () {
344+
model_id = radio_model.model_id,
345+
connection_type = connection_type.get_string ().down () ?? "",
346+
device_path = device_path.get_string (),
347+
network_host = row_network_host.text,
348+
network_port = int.parse (row_network_port.text),
349+
baud_rate = int.parse (baud_rate.get_string ())
350+
};
351+
debug ("""Testing radio connection with:
352+
\tModel ID: %s\n
353+
\tConnection type: %s\n
354+
\tDevice path: %s\n
355+
\tNetwork host: %s\n
356+
\tNetwork port: %d\n
357+
\tBaud rate: %d\n
358+
""".printf (
359+
radio_model.display_name,
360+
config.connection_type,
361+
config.device_path,
362+
config.network_host,
363+
config.network_port,
364+
config.baud_rate
365+
));
366+
367+
var is_connected = Application.radio_control.connect (config);
368+
new Dex.Future.then (is_connected, (result) => {
369+
bool success = false;
370+
try {
371+
success = result.await_boolean ();
372+
} catch (Error err) {
373+
error (err.message);
330374
}
331-
});
332-
}
333375

334-
async bool test_radio_connection () {
335-
return false;
376+
Dex.Scheduler.get_default ().spawn (0, () => {
377+
test_connection_button.sensitive = true;
378+
if (success) {
379+
connection_status_icon.icon_name = "network-idle-symbolic";
380+
connection_status_label.label = _("Connected");
381+
} else {
382+
connection_status_icon.icon_name = "network-offline-symbolic";
383+
connection_status_label.label = _("Failed");
384+
}
385+
386+
return null;
387+
}).disown ();
388+
389+
return null;
390+
}).disown ();
336391
}
337392

338393
void do_import_file () {
@@ -386,12 +441,6 @@ public sealed class PreferencesDialog : Object {
386441
alert.present (dialog.get_root ());
387442
} /* do_import_file */
388443

389-
string _strip_quotes (string s) {
390-
if (s.has_prefix ("\"") && s.has_suffix ("\"") && (s.length >= 2))
391-
return s.substring (1, s.length - 2);
392-
return s;
393-
}
394-
395444
void on_import_file () {
396445
var file_dialog = new Gtk.FileDialog ();
397446

0 commit comments

Comments
 (0)