You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(57) |
Nov
(27) |
Dec
(25) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(41) |
Feb
(101) |
Mar
(60) |
Apr
(32) |
May
(32) |
Jun
(198) |
Jul
(95) |
Aug
(60) |
Sep
(48) |
Oct
(96) |
Nov
(27) |
Dec
(222) |
| 2002 |
Jan
(180) |
Feb
(46) |
Mar
(68) |
Apr
(11) |
May
(36) |
Jun
(34) |
Jul
(113) |
Aug
(42) |
Sep
(71) |
Oct
(65) |
Nov
(116) |
Dec
(40) |
| 2003 |
Jan
(32) |
Feb
(92) |
Mar
(29) |
Apr
(102) |
May
(21) |
Jun
(34) |
Jul
(3) |
Aug
(60) |
Sep
(30) |
Oct
(62) |
Nov
(57) |
Dec
(33) |
| 2004 |
Jan
(28) |
Feb
(46) |
Mar
(16) |
Apr
(14) |
May
(31) |
Jun
(21) |
Jul
(10) |
Aug
(80) |
Sep
(42) |
Oct
(11) |
Nov
(28) |
Dec
(13) |
| 2005 |
Jan
(35) |
Feb
(26) |
Mar
(20) |
Apr
(118) |
May
(2) |
Jun
(5) |
Jul
|
Aug
|
Sep
(5) |
Oct
(1) |
Nov
(13) |
Dec
(1) |
| 2006 |
Jan
(9) |
Feb
(25) |
Mar
(22) |
Apr
(6) |
May
|
Jun
|
Jul
(2) |
Aug
(1) |
Sep
(3) |
Oct
(46) |
Nov
(13) |
Dec
(7) |
| 2007 |
Jan
(9) |
Feb
(14) |
Mar
(3) |
Apr
|
May
(6) |
Jun
(1) |
Jul
|
Aug
(11) |
Sep
(7) |
Oct
(8) |
Nov
(41) |
Dec
(3) |
| 2008 |
Jan
(27) |
Feb
(16) |
Mar
(13) |
Apr
(23) |
May
(39) |
Jun
(4) |
Jul
(7) |
Aug
(1) |
Sep
(13) |
Oct
(52) |
Nov
(44) |
Dec
(55) |
| 2009 |
Jan
(72) |
Feb
(69) |
Mar
|
Apr
|
May
|
Jun
(13) |
Jul
(1) |
Aug
(6) |
Sep
(15) |
Oct
(11) |
Nov
(31) |
Dec
(20) |
| 2010 |
Jan
(24) |
Feb
(21) |
Mar
(22) |
Apr
(40) |
May
(38) |
Jun
(4) |
Jul
(2) |
Aug
(22) |
Sep
(19) |
Oct
(14) |
Nov
(5) |
Dec
(8) |
| 2011 |
Jan
(14) |
Feb
(36) |
Mar
(6) |
Apr
|
May
|
Jun
(23) |
Jul
(13) |
Aug
(8) |
Sep
(7) |
Oct
|
Nov
(3) |
Dec
(9) |
| 2012 |
Jan
(17) |
Feb
(13) |
Mar
(10) |
Apr
|
May
(1) |
Jun
(14) |
Jul
(4) |
Aug
(12) |
Sep
(2) |
Oct
(24) |
Nov
(14) |
Dec
(2) |
| 2013 |
Jan
(4) |
Feb
(3) |
Mar
(3) |
Apr
(3) |
May
(10) |
Jun
(4) |
Jul
(7) |
Aug
|
Sep
(15) |
Oct
(5) |
Nov
(1) |
Dec
(2) |
| 2014 |
Jan
|
Feb
(8) |
Mar
(1) |
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
(3) |
Oct
(7) |
Nov
(6) |
Dec
(3) |
| 2015 |
Jan
(4) |
Feb
(5) |
Mar
(8) |
Apr
(8) |
May
(2) |
Jun
|
Jul
(4) |
Aug
(7) |
Sep
(8) |
Oct
|
Nov
(6) |
Dec
(4) |
| 2016 |
Jan
(6) |
Feb
(26) |
Mar
(3) |
Apr
(10) |
May
(6) |
Jun
(5) |
Jul
(1) |
Aug
(4) |
Sep
(3) |
Oct
(4) |
Nov
(3) |
Dec
(10) |
| 2017 |
Jan
(11) |
Feb
(11) |
Mar
(2) |
Apr
(1) |
May
(7) |
Jun
(2) |
Jul
(11) |
Aug
(9) |
Sep
(5) |
Oct
(5) |
Nov
(1) |
Dec
(2) |
| 2018 |
Jan
(5) |
Feb
(2) |
Mar
(19) |
Apr
(7) |
May
(11) |
Jun
(3) |
Jul
(4) |
Aug
(10) |
Sep
(2) |
Oct
(8) |
Nov
(6) |
Dec
(9) |
| 2019 |
Jan
(9) |
Feb
(6) |
Mar
(2) |
Apr
(4) |
May
(6) |
Jun
(9) |
Jul
(6) |
Aug
(3) |
Sep
(5) |
Oct
(2) |
Nov
(8) |
Dec
(9) |
| 2020 |
Jan
(15) |
Feb
(1) |
Mar
(18) |
Apr
(33) |
May
(43) |
Jun
(87) |
Jul
(45) |
Aug
(8) |
Sep
(43) |
Oct
(3) |
Nov
(5) |
Dec
(42) |
| 2021 |
Jan
(116) |
Feb
(40) |
Mar
(58) |
Apr
(48) |
May
(29) |
Jun
(2) |
Jul
|
Aug
(22) |
Sep
(18) |
Oct
(1) |
Nov
|
Dec
(3) |
| 2022 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(2) |
Jun
(1) |
Jul
|
Aug
(1) |
Sep
|
Oct
(6) |
Nov
(2) |
Dec
(9) |
| 2023 |
Jan
(10) |
Feb
|
Mar
|
Apr
(10) |
May
(3) |
Jun
(1) |
Jul
(2) |
Aug
(4) |
Sep
(1) |
Oct
|
Nov
(2) |
Dec
(3) |
| 2024 |
Jan
(4) |
Feb
(1) |
Mar
(2) |
Apr
(2) |
May
(5) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(9) |
| 2025 |
Jan
(5) |
Feb
(5) |
Mar
|
Apr
(10) |
May
(20) |
Jun
(43) |
Jul
(24) |
Aug
(47) |
Sep
(38) |
Oct
(5) |
Nov
(3) |
Dec
(18) |
| 2026 |
Jan
(17) |
Feb
(13) |
Mar
(17) |
Apr
(30) |
May
(19) |
Jun
(11) |
Jul
(24) |
Aug
(30) |
Sep
(26) |
Oct
(12) |
Nov
(3) |
Dec
|
|
From: n0nb <n0...@us...> - 2026-11-11 13:40:56
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via 214bf9d275f218fd40169785c27e819c0f355d4a (commit)
via 5fe815e3adebb47aef1b11acc5117466460ce9f9 (commit)
via 22a76334da288b68d6643f4fd737334aaee188ba (commit)
via 913df25602dcca0fe543516bce0a057ab20c82a1 (commit)
via c552b56f2d3195a924f49cdfef670d500db73847 (commit)
via 690ecb3eb95ff3d1d8797b56a5e15b1aa2d0d89f (commit)
via eab0a2147c2a575002c53088d974382b9efcec2b (commit)
via f8d35a9f73e5bcd61745cf21f213ae5bffb1f5ec (commit)
via 995753e34befda4a26b70ac2419323eaafbf7a52 (commit)
via d2b1b546bcc7d484154b0fb6a4c3cced429e7e4c (commit)
via 607fb82ba9952723fdcfb3a73c2cff15ea94be57 (commit)
via 388df04c790822fde5b4e7b92221e03b3f6b4cc4 (commit)
via e5a2ba48f8d0c13f3ffa410d144d882f6baafda4 (commit)
via 83ca2ae8a1cfa605ae8009ee4d89cd495766f22f (commit)
via 251d68c3b537c3fbb723246de80247ec98b2ff51 (commit)
via 0b79b33a8425df16e6924243d7342878cd549fbd (commit)
from 78f5b78f25ee0ad58f8d79a57e2c046a6a1c638f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 214bf9d275f218fd40169785c27e819c0f355d4a
Author: David Christle <dch...@us...>
Date: Mon Sep 21 23:18:45 2026 +0200
fix(newcat): reject invalid narrow filter values
NewCAT narrow status is boolean, but the parser accepts up to three
digits. Reject values other than zero or one before bandwidth selection
so malformed replies cannot be treated as a narrow-filter state.
Add an FT-950 protocol test covering both valid default widths and an
invalid narrow reply, adapted to the 4.7 test layout.
(cherry picked from commit 1c1e2aabf707e78a8bf36de059b2bc4592df9042)
diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c
index 385f7a024..3e9c65e58 100644
--- a/rigs/yaesu/newcat.c
+++ b/rigs/yaesu/newcat.c
@@ -8723,6 +8723,13 @@ static int get_narrow(RIG *rig, vfo_t vfo)
RETURNFUNC(-RIG_EPROTO);
}
+ if (narrow != 0 && narrow != 1)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: invalid narrow value %d from '%s'\n",
+ __func__, narrow, priv->ret_data);
+ RETURNFUNC(-RIG_EPROTO);
+ }
+
RETURNFUNC(narrow);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 82f2e88fb..f7d263f7c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -34,6 +34,7 @@ DIRECT_TESTS = \
testgs100 \
testicomts \
testnewcatset \
+ testnewcatwidth \
testsendraw \
testmodecompat \
testmorse \
@@ -131,6 +132,7 @@ testctlparser_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgeministatus_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgs100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testnewcatset_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testnewcatwidth_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testelecraft_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testts990s_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testicomts_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
@@ -180,6 +182,8 @@ testts990s_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood/libh
testftx1parsers_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testft991idmeter_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testnewcatset_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
+testnewcatwidth_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) \
+ $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testnetrigctl_SOURCES = testnetrigctl.c $(top_srcdir)/rigs/dummy/dummy_common.c
testnetrigctl_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testsmartsdrstatus_LDADD = $(top_builddir)/rigs/flexradio/libhamlib-flexradio.la $(LDADD)
diff --git a/tests/testnewcatwidth.c b/tests/testnewcatwidth.c
new file mode 100644
index 000000000..acaf46d8b
--- /dev/null
+++ b/tests/testnewcatwidth.c
@@ -0,0 +1,230 @@
+/*
+ * Hamlib Yaesu NewCAT legacy bandwidth tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#ifdef _WIN32
+
+#include <stdio.h>
+
+int main(void)
+{
+ printf("testnewcatwidth: skipped, requires socketpair()\n");
+ return 77;
+}
+
+#else
+
+#include <poll.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/port.h"
+#include "hamlib/rig_state.h"
+
+extern struct rig_caps ft950_caps;
+
+struct peer_case
+{
+ int fd;
+ const char *mode_command;
+ const char *mode_response;
+ const char *width_command;
+ const char *width_response;
+ const char *narrow_command;
+ const char *narrow_response;
+ int status;
+};
+
+static int read_frame(int fd, char *buffer, size_t capacity)
+{
+ size_t used = 0;
+
+ while (used + 1 < capacity)
+ {
+ struct pollfd descriptor = { .fd = fd, .events = POLLIN };
+ ssize_t count;
+
+ if (poll(&descriptor, 1, 2000) != 1)
+ {
+ return -1;
+ }
+
+ count = read(fd, buffer + used, 1);
+
+ if (count != 1)
+ {
+ return -1;
+ }
+
+ if (buffer[used++] == ';')
+ {
+ buffer[used] = '\0';
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+static int write_all(int fd, const char *buffer)
+{
+ size_t length = strlen(buffer);
+ size_t written = 0;
+
+ while (written < length)
+ {
+ ssize_t count = write(fd, buffer + written, length - written);
+
+ if (count <= 0)
+ {
+ return -1;
+ }
+
+ written += (size_t)count;
+ }
+
+ return 0;
+}
+
+static int exchange(int fd, const char *expected, const char *response)
+{
+ char command[32];
+
+ if (read_frame(fd, command, sizeof(command)) != 0
+ || strcmp(command, expected) != 0)
+ {
+ return -1;
+ }
+
+ if (response != NULL && write_all(fd, response) != 0)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+static void *run_peer(void *arg)
+{
+ struct peer_case *test = arg;
+
+ test->status = -1;
+
+ if (exchange(test->fd, test->mode_command,
+ test->mode_response) != 0
+ || exchange(test->fd, test->width_command,
+ test->width_response) != 0)
+ {
+ return NULL;
+ }
+
+ if (test->narrow_command != NULL
+ && exchange(test->fd, test->narrow_command,
+ test->narrow_response) != 0)
+ {
+ return NULL;
+ }
+
+ test->status = 0;
+ return NULL;
+}
+
+static int run_narrow_case(const char *name, const char *narrow_response,
+ int expected_retval, pbwidth_t expected_width)
+{
+ int sockets[2];
+ pthread_t thread;
+ struct peer_case peer =
+ {
+ .fd = -1,
+ .mode_command = "MD0;",
+ .mode_response = "MD02;",
+ .width_command = "SH0;",
+ .width_response = "SH000;",
+ .narrow_command = "NA0;",
+ .narrow_response = narrow_response,
+ .status = -1
+ };
+ RIG *rig;
+ rmode_t mode = RIG_MODE_NONE;
+ pbwidth_t width = RIG_PASSBAND_NORMAL;
+ int retval;
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0)
+ {
+ perror("socketpair");
+ return 1;
+ }
+
+ rig = rig_init(RIG_MODEL_FT950);
+
+ if (rig == NULL)
+ {
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->timeout = 100;
+ RIGPORT(rig)->retry = 0;
+ STATE(rig)->powerstat = RIG_POWER_ON;
+ peer.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &peer) != 0)
+ {
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ retval = rig->caps->get_mode(rig, RIG_VFO_A, &mode, &width);
+ pthread_join(thread, NULL);
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+
+ if (peer.status != 0 || retval != expected_retval
+ || (retval == RIG_OK
+ && (mode != RIG_MODE_USB || width != expected_width)))
+ {
+ fprintf(stderr,
+ "%s: expected %d/USB/%d, got %d/%s/%d (peer %d)\n",
+ name, expected_retval, (int)expected_width, retval,
+ rig_strrmode(mode), (int)width, peer.status);
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ rig_set_debug(RIG_DEBUG_NONE);
+ rig_register(&ft950_caps);
+
+ if (run_narrow_case("wide default", "NA00;", RIG_OK, 2400) != 0
+ || run_narrow_case("narrow default", "NA01;", RIG_OK, 1800) != 0
+ || run_narrow_case("invalid narrow", "NA02;", -RIG_EPROTO,
+ RIG_PASSBAND_NORMAL) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+#endif /* !_WIN32 */
commit 5fe815e3adebb47aef1b11acc5117466460ce9f9
Author: Wahaj18 <484...@us...>
Date: Wed Nov 4 12:54:35 2026 +0500
fix(icom): reject non-BCD G90 SWR meter replies
The G90 sometimes answers the SWR meter query with a byte whose low
nibble is not a BCD digit (e.g. 02 2c). from_bcd_be() decoded it anyway,
so RIG_LEVEL_SWR reported values up to the 6.0 ceiling of the default
calibration table while the rig showed a normal match.
Validate the reply in g90_get_level() and return -RIG_EPROTO for
non-BCD bytes while preserving calibration of valid readings. Adapt the
test registration and VFO state setup for Hamlib 4.7.
Fixes #2257
(cherry picked from commit bdec04b0264f6db7aad20d4e160ed6db1274e3aa)
diff --git a/rigs/icom/icom.h b/rigs/icom/icom.h
index 310f22824..e55403bbd 100644
--- a/rigs/icom/icom.h
+++ b/rigs/icom/icom.h
@@ -452,6 +452,7 @@ extern const struct confparams icom_ext_levels[];
extern const struct confparams icom_ext_funcs[];
extern const struct confparams icom_ext_parms[];
extern const struct cmdparams icom_ext_cmds[];
+extern const cal_table_float_t icom_default_swr_cal;
extern struct rig_caps ic703_caps;
extern struct rig_caps ic705_caps;
diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c
index 7d2f7aba8..4fc209107 100644
--- a/rigs/icom/xiegu.c
+++ b/rigs/icom/xiegu.c
@@ -1385,6 +1385,44 @@ static int g90_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
return RIG_OK;
}
+/*
+ * G90 firmware sometimes answers the SWR meter query with a byte whose
+ * low nibble is not a BCD digit (e.g. 0x02 0x2c), which from_bcd_be()
+ * turns into a much higher SWR than the rig shows. Reject such replies.
+ */
+static int g90_get_swr(RIG *rig, value_t *val)
+{
+ unsigned char response[MAXFRAMELEN];
+ int length = sizeof(response), retval, raw;
+
+ retval = icom_transaction(rig, C_RD_SQSM, S_SWR, NULL, 0,
+ response, &length);
+
+ if (retval != RIG_OK)
+ {
+ return retval;
+ }
+
+ if (length == 1 && response[0] == NAK)
+ {
+ return -RIG_ERJCTED;
+ }
+
+ if (length != 4 || response[0] != C_RD_SQSM || response[1] != S_SWR
+ || response[2] > 0x09 || (response[3] >> 4) > 9
+ || (response[3] & 0x0f) > 9)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: invalid SWR response, len=%d\n",
+ __func__, length);
+ return -RIG_EPROTO;
+ }
+
+ raw = from_bcd_be(response + 2, 4);
+ val->f = rig_raw2val_float(raw, rig->caps->swr_cal.size != 0
+ ? &rig->caps->swr_cal : &icom_default_swr_cal);
+ return RIG_OK;
+}
+
/*
* g90_get_level
* Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL
@@ -1398,6 +1436,11 @@ static int g90_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
int retval, state;
+ if (level == RIG_LEVEL_SWR)
+ {
+ return g90_get_swr(rig, val);
+ }
+
if (level == RIG_LEVEL_RFPOWER)
{
retval = icom_get_level(rig, vfo, level, val);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7b60dc9ed..82f2e88fb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@ DIRECT_TESTS = \
testft991idmeter \
testelecraft \
testftx1parsers \
+ testg90swr \
testgeministatus \
testgs100 \
testicomts \
@@ -121,6 +122,8 @@ testmorse_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testnetrigctl_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testsendraw_CFLAGS = $(AM_CFLAGS)
testdaemonclient_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testg90swr_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testg90swr_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testid5100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testid5100_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testicomfallback_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
@@ -157,6 +160,9 @@ testasyncio_LDADD = $(PTHREAD_LIBS) $(LDADD)
testmorse_LDADD = $(PTHREAD_LIBS) $(LDADD)
# Exercise internal FIFO helpers without adding them to the DLL exports.
testmorse_SOURCES = testmorse.c $(top_srcdir)/src/fifo.c
+testg90swr_SOURCES = testg90swr.c testicomsock.c testicomsock.h
+testg90swr_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) \
+ $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testid5100_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testicomfallback_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testsendraw_SOURCES = testsendraw.c
diff --git a/tests/testg90swr.c b/tests/testg90swr.c
new file mode 100644
index 000000000..fc326c608
--- /dev/null
+++ b/tests/testg90swr.c
@@ -0,0 +1,164 @@
+/*
+ * Hamlib Xiegu G90 SWR meter tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+/*
+ * The G90 sometimes answers the SWR meter query (15 12) with a byte
+ * that is not BCD, e.g. 02 2c. Decoding it anyway reports an SWR near
+ * the top of the calibration table, so such a reply must be rejected
+ * while valid readings still go through the calibration table.
+ */
+
+#include <math.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/port.h"
+#include "hamlib/rig_state.h"
+#include "icom.h"
+#include "frame.h"
+#include "misc.h"
+#include "testicomsock.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+extern struct rig_caps g90_caps;
+
+struct swr_case
+{
+ unsigned char hi, lo;
+ int expected_retval;
+ float expected_swr;
+};
+
+static const struct swr_case cases[] =
+{
+ { 0x00, 0x00, RIG_OK, 1.0f },
+ { 0x01, 0x84, RIG_OK, 4.6f },
+ { 0x02, 0x2c, -RIG_EPROTO, 0 }, /* low nibble 0xc, seen in #2257 */
+ { 0x01, 0xa0, -RIG_EPROTO, 0 },
+ { 0x0a, 0x00, -RIG_EPROTO, 0 }
+};
+
+struct peer_case
+{
+ int fd;
+ int bad_request;
+};
+
+static void *run_peer(void *arg)
+{
+ static const unsigned char query[] =
+ {
+ 0xfe, 0xfe, 0x88, 0xe0, 0x15, 0x12, 0xfd
+ };
+ struct peer_case *test = arg;
+ unsigned char frame[MAXFRAMELEN];
+ size_t i, length;
+
+ for (i = 0; i < ARRAY_SIZE(cases); i++)
+ {
+ unsigned char reply[] =
+ {
+ 0xfe, 0xfe, 0xe0, 0x88, 0x15, 0x12, cases[i].hi, cases[i].lo, 0xfd
+ };
+
+ if (read_frame(test->fd, frame, sizeof(frame), &length) != 0)
+ {
+ break;
+ }
+
+ if (length != sizeof(query) || memcmp(frame, query, length) != 0)
+ {
+ test->bad_request = 1;
+ }
+
+ if (write_all(test->fd, reply, sizeof(reply)) != 0) { break; }
+ }
+
+ return NULL;
+}
+
+int main(void)
+{
+ int sockets[2];
+ pthread_t thread;
+ struct peer_case test = { -1, 0 };
+ RIG *rig;
+ size_t i;
+ int failed = 0;
+
+#ifdef _WIN32
+ WSADATA wsa_data;
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0) { return 1; }
+
+#endif
+
+ rig_register(&g90_caps);
+ rig = rig_init(RIG_MODEL_G90);
+
+ if (rig == NULL || open_test_connection(sockets) != 0)
+ {
+ fprintf(stderr, "test setup failed\n");
+ return 1;
+ }
+
+ test.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &test) != 0)
+ {
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->type.rig = RIG_PORT_NETWORK;
+ RIGPORT(rig)->timeout = 250;
+ RIGPORT(rig)->retry = 0;
+ ((struct icom_priv_data *) STATE(rig)->priv)->serial_USB_echo_off = 1;
+ STATE(rig)->comm_state = 1;
+ STATE(rig)->current_vfo = RIG_VFO_A;
+
+ for (i = 0; i < ARRAY_SIZE(cases); i++)
+ {
+ value_t val = { .f = -1.0f };
+ int retval = rig->caps->get_level(rig, RIG_VFO_CURR, RIG_LEVEL_SWR,
+ &val);
+
+ if (retval != cases[i].expected_retval
+ || (retval == RIG_OK
+ && fabsf(val.f - cases[i].expected_swr) > 0.001f))
+ {
+ fprintf(stderr, "SWR reply %02x %02x: expected %d/%.2f, got %d/%.2f\n",
+ cases[i].hi, cases[i].lo, cases[i].expected_retval,
+ cases[i].expected_swr, retval, val.f);
+ failed = 1;
+ }
+ }
+
+ stop_test_peer(sockets, thread);
+
+ if (test.bad_request)
+ {
+ fprintf(stderr, "unexpected SWR query frame\n");
+ failed = 1;
+ }
+
+ STATE(rig)->comm_state = 0;
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+
+#ifdef _WIN32
+ WSACleanup();
+#endif
+
+ return failed;
+}
diff --git a/tests/testicomsock.c b/tests/testicomsock.c
new file mode 100644
index 000000000..f4b41dbca
--- /dev/null
+++ b/tests/testicomsock.c
@@ -0,0 +1,159 @@
+/*
+ * Socket-pair plumbing shared by the Icom CI-V tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <string.h>
+
+#include "testicomsock.h"
+
+int close_test_socket(int fd)
+{
+#ifdef _WIN32
+ return closesocket(fd);
+#else
+ return close(fd);
+#endif
+}
+
+void stop_test_peer(int sockets[2], pthread_t thread)
+{
+ close_test_socket(sockets[0]);
+ pthread_join(thread, NULL);
+ close_test_socket(sockets[1]);
+}
+
+int read_test_socket(int fd, void *buffer, size_t length)
+{
+#ifdef _WIN32
+ return recv(fd, buffer, (int) length, 0);
+#else
+ return (int) read(fd, buffer, length);
+#endif
+}
+
+int write_test_socket(int fd, const void *buffer, size_t length)
+{
+#ifdef _WIN32
+ return send(fd, buffer, (int) length, 0);
+#else
+ return (int) write(fd, buffer, length);
+#endif
+}
+
+void set_read_timeout(int fd, int ms)
+{
+#ifdef _WIN32
+ DWORD timeout = (DWORD) ms;
+
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char *) &timeout,
+ sizeof(timeout));
+#else
+ struct timeval timeout;
+
+ timeout.tv_sec = ms / 1000;
+ timeout.tv_usec = (ms % 1000) * 1000;
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
+#endif
+}
+
+int open_test_connection(int sockets[2])
+{
+#ifdef _WIN32
+ SOCKET listener;
+ SOCKET client;
+ SOCKET peer;
+ struct sockaddr_in address;
+ int address_length = sizeof(address);
+
+ listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ if (listener == INVALID_SOCKET) { return -1; }
+
+ memset(&address, 0, sizeof(address));
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ address.sin_port = 0;
+
+ if (bind(listener, (struct sockaddr *) &address, sizeof(address)) != 0
+ || listen(listener, 1) != 0
+ || getsockname(listener, (struct sockaddr *) &address,
+ &address_length) != 0)
+ {
+ closesocket(listener);
+ return -1;
+ }
+
+ client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ if (client == INVALID_SOCKET)
+ {
+ closesocket(listener);
+ return -1;
+ }
+
+ if (connect(client, (struct sockaddr *) &address, address_length) != 0)
+ {
+ closesocket(client);
+ closesocket(listener);
+ return -1;
+ }
+
+ peer = accept(listener, NULL, NULL);
+ closesocket(listener);
+
+ if (peer == INVALID_SOCKET)
+ {
+ closesocket(client);
+ return -1;
+ }
+
+ sockets[0] = (int) client;
+ sockets[1] = (int) peer;
+ return 0;
+#else
+ return socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
+#endif
+}
+
+int read_frame(int fd, unsigned char *buffer, size_t capacity,
+ size_t *length)
+{
+ size_t used = 0;
+
+ while (used < capacity)
+ {
+ int count = read_test_socket(fd, buffer + used, 1);
+
+ if (count != 1) { return -1; }
+
+ if (buffer[used++] == 0xfd)
+ {
+ *length = used;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int write_all(int fd, const unsigned char *buffer, size_t length)
+{
+ size_t written = 0;
+
+ while (written < length)
+ {
+ int count = write_test_socket(fd, buffer + written, length - written);
+
+ if (count <= 0) { return -1; }
+
+ written += (size_t) count;
+ }
+
+ return 0;
+}
diff --git a/tests/testicomsock.h b/tests/testicomsock.h
new file mode 100644
index 000000000..b1ce02567
--- /dev/null
+++ b/tests/testicomsock.h
@@ -0,0 +1,47 @@
+/*
+ * Socket-pair plumbing shared by the Icom CI-V tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+/*
+ * A test drives a backend over one end of a local socket connection
+ * while a fake rig answers on the other. On POSIX that is a socket
+ * pair; on Windows, where socketpair() does not exist, a loopback TCP
+ * connection stands in for it.
+ */
+
+#ifndef TESTICOMSOCK_H
+#define TESTICOMSOCK_H
+
+#include <pthread.h>
+#include <stddef.h>
+
+#ifdef _WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
+
+int close_test_socket(int fd);
+int read_test_socket(int fd, void *buffer, size_t length);
+int write_test_socket(int fd, const void *buffer, size_t length);
+void set_read_timeout(int fd, int ms);
+int open_test_connection(int sockets[2]);
+
+/* Stops the fake rig reading sockets[1]: closing the backend's end,
+ sockets[0], ends its read; its own end is closed after the join */
+void stop_test_peer(int sockets[2], pthread_t thread);
+
+/* Reads one CI-V frame, i.e. everything up to and including an FD byte */
+int read_frame(int fd, unsigned char *buffer, size_t capacity,
+ size_t *length);
+int write_all(int fd, const unsigned char *buffer, size_t length);
+
+#endif /* TESTICOMSOCK_H */
commit 22a76334da288b68d6643f4fd737334aaee188ba
Author: David Christle <dch...@us...>
Date: Tue Nov 10 16:41:09 2026 -0800
fix(elecraft): read K4 power in a single transaction
The TM forward-power field uses tenths of a watt in low range and
whole watts in high range. Interpreting both as watts can report
20 W for 2 W of output.
Read PO for both power meters. Its fixed tenths-of-a-watt units make
the reading independent of a separate range query. Keep the 100 W
reference for the normalized meter and use TM for SWR and ALC.
Support PO in the K4 simulator and extend the Elecraft socket suite
to cover metering. Rename the suite and its executable ignore entry
to reflect its broader scope.
(cherry picked from commit b7a9bfab7227b803458b97dea5cc58a0f12b8362)
diff --git a/rigs/kenwood/k3.c b/rigs/kenwood/k3.c
index 068ff597b..8722f0a44 100644
--- a/rigs/kenwood/k3.c
+++ b/rigs/kenwood/k3.c
@@ -177,8 +177,7 @@ static int k3_set_nb_level(RIG *rig, float dsp_nb, float if_nb);
static int k3_get_nb_level(RIG *rig, float *dsp_nb, float *if_nb);
static int k3_get_bar_graph_level(RIG *rig, float *smeter, float *pwr, float *alc,
int *mode_tx);
-static int k4_get_bar_graph_level(RIG *rig, float *swr, float *pwr, float *alc,
- int *mode_tx);
+static int k4_get_bar_graph_level(RIG *rig, float *swr, float *alc);
/* K4 functions */
static int k4_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt);
@@ -2101,7 +2100,7 @@ static int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
if (RIG_IS_K4)
{
- retval = k4_get_bar_graph_level(rig, NULL, NULL, &alc, &tx_mode);
+ retval = k4_get_bar_graph_level(rig, NULL, &alc);
tx_mode = 1; // Assume ALC is zero when in Tx so we don't care about ptt status
}
else
@@ -2137,14 +2136,27 @@ static int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
if (RIG_IS_K4)
{
- retval = k4_get_bar_graph_level(rig, NULL, &pwr, NULL, &tx_mode);
- tx_mode = 1; // Does K4 return pwr=0 when in Rx? Hope so.
- }
- else
- {
- retval = k3_get_bar_graph_level(rig, NULL, &pwr, NULL, &tx_mode);
+ retval = kenwood_safe_transaction(rig, "PO", levelbuf,
+ sizeof(levelbuf), 6);
+
+ if (retval != RIG_OK)
+ {
+ return retval;
+ }
+
+ if (strspn(levelbuf + 2, "0123456789") != 4)
+ {
+ return -RIG_EPROTO;
+ }
+
+ // PO reports tenths of a watt in both power ranges.
+ val->f = atoi(levelbuf + 2) /
+ (level == RIG_LEVEL_RFPOWER_METER_WATTS ? 10.0f : 1000.0f);
+ return RIG_OK;
}
+ retval = k3_get_bar_graph_level(rig, NULL, &pwr, NULL, &tx_mode);
+
if (retval != RIG_OK)
{
return retval;
@@ -2350,7 +2362,7 @@ static int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
case RIG_LEVEL_SWR:
if (RIG_IS_K4)
{
- return k4_get_bar_graph_level(rig, &val->f, NULL, NULL, NULL);
+ return k4_get_bar_graph_level(rig, &val->f, NULL);
}
else
{
@@ -2735,8 +2747,7 @@ static int k3_get_nb_level(RIG *rig, float *dsp_nb, float *if_nb)
return RIG_OK;
}
-int k4_get_bar_graph_level(RIG *rig, float *swr, float *pwr, float *alc,
- int *mode_tx)
+static int k4_get_bar_graph_level(RIG *rig, float *swr, float *alc)
{
int retval;
int ialc, icmp, ifwd, iswr;
@@ -2758,8 +2769,6 @@ int k4_get_bar_graph_level(RIG *rig, float *swr, float *pwr, float *alc,
if (swr) { *swr = iswr / 10.0; }
- if (pwr) { *pwr = ifwd / 100.0; } // pwr is returned in 0-1 sscale
-
if (alc) { *alc = ialc; }
return RIG_OK;
diff --git a/simulators/simelecraftk4.c b/simulators/simelecraftk4.c
index 43d28aab0..4b2d4fb83 100644
--- a/simulators/simelecraftk4.c
+++ b/simulators/simelecraftk4.c
@@ -297,6 +297,11 @@ int main(int argc, char *argv[])
SNPRINTF(buf, sizeof(buf), "PC0980;");
WRITE(fd, buf, strlen(buf));
}
+ else if (strncmp(buf, "PO;", 3) == 0)
+ {
+ SNPRINTF(buf, sizeof(buf), "PO0003;");
+ WRITE(fd, buf, strlen(buf));
+ }
else if (strncmp(buf, "PA;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "PA%d;", preampA);
diff --git a/tests/.gitignore b/tests/.gitignore
index affc6964a..f45c41dd9 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -34,7 +34,7 @@ testcache.sh
testcookie
testcookie.sh
testctlparser
-testelecraftvfo
+testelecraft
testfreq
testfreq.sh
testftx1parsers
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b10e8d438..7b60dc9ed 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,7 +27,7 @@ DIRECT_TESTS = \
testid5100 \
testicomfallback \
testft991idmeter \
- testelecraftvfo \
+ testelecraft \
testftx1parsers \
testgeministatus \
testgs100 \
@@ -128,7 +128,7 @@ testctlparser_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgeministatus_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgs100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testnewcatset_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
-testelecraftvfo_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testelecraft_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testts990s_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testicomts_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testgeministatus_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/amplifiers/gemini
@@ -169,7 +169,7 @@ testmodecompat_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testicomts_LDADD = $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testgeministatus_LDADD = $(PTHREAD_LIBS) $(top_builddir)/amplifiers/gemini/libhamlib-gemini.la $(LDADD)
testgs100_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/gomspace/libhamlib-gomspace.la $(LDADD)
-testelecraftvfo_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood/libhamlib-kenwood.la $(LDADD)
+testelecraft_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood/libhamlib-kenwood.la $(LDADD)
testts990s_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood/libhamlib-kenwood.la $(LDADD)
testftx1parsers_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testft991idmeter_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
diff --git a/tests/testelecraftvfo.c b/tests/testelecraft.c
similarity index 64%
rename from tests/testelecraftvfo.c
rename to tests/testelecraft.c
index e71bc6d81..fdf85b75e 100644
--- a/tests/testelecraftvfo.c
+++ b/tests/testelecraft.c
@@ -1,5 +1,5 @@
/*
- * Hamlib Elecraft K4 VFO response tests
+ * Hamlib Elecraft response tests
* Copyright (c) 2026 by Hamlib Team
*
* This library is free software; you can redistribute it and/or
@@ -8,6 +8,7 @@
* version 2.1 of the License, or (at your option) any later version.
*/
+#include <math.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
@@ -28,7 +29,9 @@ extern struct rig_caps k4_caps;
struct peer_case
{
int fd;
- const char *responses[3];
+ const char *const *commands;
+ const char *const *responses;
+ size_t count;
int status;
};
@@ -153,25 +156,23 @@ static int write_all(int fd, const char *buffer, size_t length)
static void *run_peer(void *arg)
{
- static const char *commands[] = { "FR;", "FT;", "TQ;" };
struct peer_case *test = arg;
- char command[8];
+ char command[32];
size_t i;
test->status = -1;
- for (i = 0; i < sizeof(commands) / sizeof(commands[0]); i++)
+ for (i = 0; i < test->count; i++)
{
- if (test->responses[i] == NULL) { break; }
-
if (read_command(test->fd, command, sizeof(command)) != 0
- || strcmp(command, commands[i]) != 0)
+ || strcmp(command, test->commands[i]) != 0)
{
return NULL;
}
- if (write_all(test->fd, test->responses[i],
- strlen(test->responses[i])) != 0)
+ if (test->responses[i] != NULL
+ && write_all(test->fd, test->responses[i],
+ strlen(test->responses[i])) != 0)
{
return NULL;
}
@@ -186,6 +187,8 @@ static int run_case(const char *name, const char *fr, const char *ft,
vfo_t expected_vfo, vfo_t expected_rx_vfo,
vfo_t expected_tx_vfo)
{
+ static const char *commands[] = { "FR;", "FT;", "TQ;" };
+ const char *responses[] = { fr, ft, tq };
const vfo_t initial_vfo = RIG_VFO_MEM;
const vfo_t initial_rx_vfo = RIG_VFO_MAIN;
const vfo_t initial_tx_vfo = RIG_VFO_SUB;
@@ -194,7 +197,9 @@ static int run_case(const char *name, const char *fr, const char *ft,
struct peer_case test =
{
.fd = -1,
- .responses = { fr, ft, tq },
+ .commands = commands,
+ .responses = responses,
+ .count = tq != NULL ? 3 : ft != NULL ? 2 : 1,
.status = -1
};
RIG *rig;
@@ -267,6 +272,151 @@ static int run_case(const char *name, const char *fr, const char *ft,
return 0;
}
+static int run_meter_case(const char *name, setting_t level,
+ const char *command,
+ const char *response, int expected_retval,
+ float expected_value)
+{
+ struct peer_case test =
+ {
+ .fd = -1,
+ .commands = &command,
+ .responses = &response,
+ .count = 1,
+ .status = -1
+ };
+ int sockets[2];
+ pthread_t thread;
+ RIG *rig;
+ value_t value = { .f = -1.0f };
+ int retval;
+
+ if (open_test_connection(sockets) != 0) { return 1; }
+
+ test.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &test) != 0)
+ {
+ close_test_socket(sockets[0]);
+ close_test_socket(sockets[1]);
+ return 1;
+ }
+
+ rig = rig_init(RIG_MODEL_K4);
+
+ if (rig == NULL)
+ {
+ close_test_socket(sockets[0]);
+ close_test_socket(sockets[1]);
+ pthread_join(thread, NULL);
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->type.rig = RIG_PORT_NETWORK;
+ RIGPORT(rig)->timeout = 500;
+ RIGPORT(rig)->retry = 0;
+
+ retval = rig->caps->get_level(rig, RIG_VFO_CURR, level, &value);
+
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close_test_socket(sockets[0]);
+ pthread_join(thread, NULL);
+ close_test_socket(sockets[1]);
+
+ if (test.status != 0 || retval != expected_retval
+ || fabsf(value.f - (retval == RIG_OK ? expected_value : -1.0f))
+ > 0.00001f)
+ {
+ fprintf(stderr, "%s: expected %d/%.4f, got %d/%.4f (peer %d)\n",
+ name, expected_retval, expected_value, retval, value.f,
+ test.status);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int test_meters(void)
+{
+ static const struct
+ {
+ const char *name;
+ setting_t level;
+ const char *command;
+ const char *response;
+ int retval;
+ float value;
+ } cases[] =
+ {
+ {
+ "2w", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0020;", RIG_OK, 2.0f
+ },
+ {
+ "20w", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0200;", RIG_OK, 20.0f
+ },
+ {
+ "minimum-nonzero-output", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0001;", RIG_OK, 0.1f
+ },
+ {
+ "110w", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO1100;", RIG_OK, 110.0f
+ },
+ {
+ "zero-output", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0000;", RIG_OK, 0.0f
+ },
+ {
+ "2w-normalized", RIG_LEVEL_RFPOWER_METER,
+ "PO;", "PO0020;", RIG_OK, 0.02f
+ },
+ {
+ "20w-normalized", RIG_LEVEL_RFPOWER_METER,
+ "PO;", "PO0200;", RIG_OK, 0.2f
+ },
+ {
+ "swr", RIG_LEVEL_SWR,
+ "TM;", "TM003004020012;", RIG_OK, 1.2f
+ },
+ {
+ "alc", RIG_LEVEL_ALC,
+ "TM;", "TM003004020012;", RIG_OK, 3.0f
+ },
+ {
+ "malformed-power-response", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO00X0;", -RIG_EPROTO, 0.0f
+ },
+ {
+ "short-power-response", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO020;", -RIG_EPROTO, 0.0f
+ },
+ {
+ "power-query-unavailable", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "N;", -RIG_ENAVAIL, 0.0f
+ },
+ {
+ "malformed-tm-response", RIG_LEVEL_SWR,
+ "TM;", "TM00300402X012;", -RIG_EPROTO, 0.0f
+ }
+ };
+ size_t i;
+
+ for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ {
+ if (run_meter_case(cases[i].name, cases[i].level, cases[i].command,
+ cases[i].response, cases[i].retval, cases[i].value))
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
int main(void)
{
int failed = 0;
@@ -351,6 +501,8 @@ int main(void)
-RIG_EPROTO, RIG_VFO_NONE, RIG_VFO_NONE,
RIG_VFO_NONE);
+ if (!failed) { failed = test_meters(); }
+
cleanup:
#ifdef _WIN32
WSACleanup();
commit 913df25602dcca0fe543516bce0a057ab20c82a1
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Tue Nov 3 09:54:42 2026 +0100
fix(rig): skip the settling wait in rig_open() when there is no rig port
rig_open() waits 100 ms after opening the ports "to give some serial
ports time" (ece6a7ae1, "allow serial port settling"). It also waits for
RIG_PORT_NONE, for which port_open() opens nothing: the dummy rig, and
the WiNRADiO, DWT, Elektor 507 (without libusb) and USRP backends, which
open their device afterwards in their own rig_open().
Skip the wait for RIG_PORT_NONE. Serial, network, USB and all other port
types wait as before. A separate serial PTT or DCD port on a
RIG_PORT_NONE rig also loses this shared 100 ms wait.
(cherry picked from commit 316d514a57ccdf58d0677ba746b1eb922fa00a65)
Co-authored-by: David Christle <dch...@us...>
diff --git a/src/rig.c b/src/rig.c
index 95f563f03..02a24488c 100644
--- a/src/rig.c
+++ b/src/rig.c
@@ -1500,8 +1500,13 @@ int HAMLIB_API rig_open(RIG *rig)
rig_debug(RIG_DEBUG_VERBOSE, "%s: %p rs->comm_state==1?=%d\n", __func__,
&rs->comm_state,
rs->comm_state);
- hl_usleep(100 *
- 1000); // wait a bit after opening to give some serial ports time
+
+ // The wait is for the rig port, which port_open() does not open for RIG_PORT_NONE
+ if (rp->type.rig != RIG_PORT_NONE)
+ {
+ hl_usleep(100 *
+ 1000); // wait a bit after opening to give some serial ports time
+ }
/*
commit c552b56f2d3195a924f49cdfef670d500db73847
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Tue Nov 3 22:19:20 2026 +0100
fix(rig): send nothing of a Morse text emptied before it is taken
The Morse thread looks at the queue with hl_peek() and then takes each
character with hl_pop(). Both tested for an empty queue before taking
the queue's mutex, and resetFIFO(), which rig_stop_morse() calls to
empty the queue, did not take it at all. When the queue was emptied
after the thread had seen text in it, hl_peek() returned a stale
character and hl_pop() returned -1, which the thread stored as 0xFF and
sent to the rig. A reset that landed inside hl_pop() could also be
undone, or leave the read position one past the write position, so the
queue looked full of old text.
resetFIFO(), hl_peek() and hl_pop() now test and change the queue only
under its mutex, and the thread stops taking characters when hl_pop()
finds the queue empty, which covers a reset between the two calls.
tests/testmorse holds the queue's mutex while rig_stop_morse() runs on
another thread, and checks that the queue is emptied only after the
mutex is released. It also holds the mutex while the thread waits to
look at text in the queue, empties the queue, and checks that nothing is
sent. That test fails only with both the locked tests in hl_peek() and
hl_pop() and the thread's check reverted: a reset between the two calls,
or between a test and the lock, cannot be timed from a test.
(cherry picked from commit 96331d93a082bc6d73d91e7d19d34039d90636c5)
Co-authored-by: David Christle <dch...@us...>
diff --git a/src/fifo.c b/src/fifo.c
index b3cf28415..f6b1944af 100644
--- a/src/fifo.c
+++ b/src/fifo.c
@@ -39,8 +39,10 @@ void initFIFO(FIFO_RIG *fifo)
void resetFIFO(FIFO_RIG *fifo)
{
rig_debug(RIG_DEBUG_TRACE, "%s: fifo flushed\n", __func__);
+ pthread_mutex_lock(&fifo->mutex);
fifo->head = fifo->tail;
fifo->flush = 1;
+ pthread_mutex_unlock(&fifo->mutex);
}
// returns RIG_OK if added
@@ -98,9 +100,14 @@ int hl_peek(FIFO_RIG *fifo)
if (fifo->tail > 1023 || fifo->head > 1023) { return -1; }
- if (fifo->tail == fifo->head) { return -1; }
-
pthread_mutex_lock(&fifo->mutex);
+
+ if (fifo->tail == fifo->head)
+ {
+ pthread_mutex_unlock(&fifo->mutex);
+ return -1;
+ }
+
char c = fifo->data[fifo->head];
#if 0
@@ -120,9 +127,14 @@ int hl_peek(FIFO_RIG *fifo)
int hl_pop(FIFO_RIG *fifo)
{
- if (fifo->tail == fifo->head) { return -1; }
-
pthread_mutex_lock(&fifo->mutex);
+
+ if (fifo->tail == fifo->head)
+ {
+ pthread_mutex_unlock(&fifo->mutex);
+ return -1;
+ }
+
char c = fifo->data[fifo->head];
#if 0
diff --git a/src/rig.c b/src/rig.c
index 5111ab1f5..95f563f03 100644
--- a/src/rig.c
+++ b/src/rig.c
@@ -8869,6 +8869,13 @@ static void *morse_data_handler(void *arg)
}
d = hl_pop(rs->fifo_morse);
+
+ // rig_stop_morse() may have emptied the queue since the peek
+ if (d < 0)
+ {
+ break;
+ }
+
c[n] = (char) d;
}
diff --git a/tests/testmorse.c b/tests/testmorse.c
index 3133cdbcf..003388c08 100644
--- a/tests/testmorse.c
+++ b/tests/testmorse.c
@@ -69,6 +69,7 @@ static void run_test(const char *name, void (*test)(void))
static pthread_mutex_t sent_lock = PTHREAD_MUTEX_INITIALIZER;
static char sent[2 * HAMLIB_FIFO_SIZE + 1];
+static int sent_invalid;
static int stub_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
{
@@ -90,6 +91,7 @@ static int stub_send_morse(RIG *rig, vfo_t vfo, const char *msg)
used = strlen(sent);
CHECK(length < sizeof(sent) - used);
memcpy(sent + used, msg, length + 1);
+ sent_invalid |= memchr(msg, 0xff, length) != NULL;
CHECK(pthread_mutex_unlock(&sent_lock) == 0);
return RIG_OK;
}
@@ -125,6 +127,7 @@ static RIG *open_test_rig(void)
CHECK(pthread_mutex_lock(&sent_lock) == 0);
sent[0] = '\0';
+ sent_invalid = 0;
CHECK(pthread_mutex_unlock(&sent_lock) == 0);
rig = rig_init(TEST_MORSE_MODEL);
CHECK(rig != NULL);
@@ -138,7 +141,7 @@ static int sent_equals(const char *text)
int equal;
CHECK(pthread_mutex_lock(&sent_lock) == 0);
- equal = strcmp(sent, text) == 0;
+ equal = !sent_invalid && strcmp(sent, text) == 0;
CHECK(pthread_mutex_unlock(&sent_lock) == 0);
return equal;
}
@@ -344,6 +347,92 @@ static void test_queue_recovers_after_overflow(void)
CHECK(rig_cleanup(rig) == RIG_OK);
}
+static void test_reset_keeps_empty_sentinels(void)
+{
+ FIFO_RIG fifo = { 0 };
+
+ initFIFO(&fifo);
+ CHECK(hl_push(&fifo, "ET") == RIG_OK);
+ resetFIFO(&fifo);
+ CHECK(fifo.flush == 1);
+ CHECK(hl_peek(&fifo) == -1);
+ CHECK(hl_pop(&fifo) == -1);
+ CHECK(hl_pop(&fifo) == -1);
+ CHECK(fifo.head == fifo.tail);
+ CHECK(hl_push(&fifo, "A") == RIG_OK);
+ check_fifo_text(&fifo, "A");
+ CHECK(pthread_mutex_destroy(&fifo.mutex) == 0);
+}
+
+static void test_reset_before_dequeue_sends_nothing(void)
+{
+ RIG *rig = open_test_rig();
+ FIFO_RIG *fifo = STATE(rig)->fifo_morse;
+
+ CHECK(pthread_mutex_lock(&fifo->mutex) == 0);
+ fifo->data[fifo->tail] = 'E';
+ fifo->tail = (fifo->tail + 1) % HAMLIB_FIFO_SIZE;
+ /* Give the worker a chance to wait on the queue; this does not force
+ * every possible interleaving between its peek and pop. */
+ hl_usleep(300 * 1000);
+ fifo->head = fifo->tail;
+ CHECK(pthread_mutex_unlock(&fifo->mutex) == 0);
+ CHECK(rig_close(rig) == RIG_OK);
+ CHECK(sent_equals(""));
+ CHECK(rig_cleanup(rig) == RIG_OK);
+}
+
+struct stop_request
+{
+ RIG *rig;
+ int entered;
+ int done;
+ int result;
+};
+
+static void *stop_morse(void *arg)
+{
+ struct stop_request *request = arg;
+
+ __atomic_store_n(&request->entered, 1, __ATOMIC_RELEASE);
+ request->result = rig_stop_morse(request->rig, RIG_VFO_CURR);
+ __atomic_store_n(&request->done, 1, __ATOMIC_RELEASE);
+ return NULL;
+}
+
+static void test_stop_waits_for_queue_mutex(void)
+{
+ RIG *rig = open_held_rig();
+ FIFO_RIG *fifo = STATE(rig)->fifo_morse;
+ struct stop_request request = { rig, 0, 0, -RIG_EINTERNAL };
+ pthread_t thread;
+
+ CHECK(rig_send_morse(rig, RIG_VFO_CURR, "E") == RIG_OK);
+ CHECK(pthread_mutex_lock(&fifo->mutex) == 0);
+ CHECK(pthread_create(&thread, NULL, stop_morse, &request) == 0);
+
+ for (int i = 0;
+ i < 300 && !__atomic_load_n(&request.entered, __ATOMIC_ACQUIRE);
+ ++i)
+ {
+ hl_usleep(10 * 1000);
+ }
+
+ CHECK(__atomic_load_n(&request.entered, __ATOMIC_ACQUIRE));
+ hl_usleep(300 * 1000);
+ CHECK(!__atomic_load_n(&request.done, __ATOMIC_ACQUIRE));
+ CHECK(fifo->head != fifo->tail);
+ CHECK(pthread_mutex_unlock(&fifo->mutex) == 0);
+ CHECK(pthread_join(thread, NULL) == 0);
+ CHECK(request.result == RIG_OK);
+ CHECK(hl_peek(fifo) == -1);
+ CHECK(hl_pop(fifo) == -1);
+ release_worker();
+ CHECK(rig_close(rig) == RIG_OK);
+ CHECK(sent_equals(""));
+ CHECK(rig_cleanup(rig) == RIG_OK);
+}
+
int main(void)
{
rig_set_debug(RIG_DEBUG_NONE);
@@ -355,6 +444,10 @@ int main(void)
test_wraparound_rejection_preserves_text);
run_test("oversized fresh queue", test_oversized_fresh_queue);
run_test("queue recovers after overflow", test_queue_recovers_after_overflow);
+ run_test("reset keeps empty sentinels", test_reset_keeps_empty_sentinels);
+ run_test("reset before dequeue sends nothing",
+ test_reset_before_dequeue_sends_nothing);
+ run_test("stop waits for queue mutex", test_stop_waits_for_queue_mutex);
CHECK(rig_unregister(TEST_MORSE_MODEL) == RIG_OK);
puts("Morse queue tests passed");
return EXIT_SUCCESS;
commit 690ecb3eb95ff3d1d8797b56a5e15b1aa2d0d89f
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Tue Nov 3 21:32:51 2026 +0100
fix(rig): release the Morse queue when a text does not fit
hl_push() returned -RIG_EDOM for a text that did not fit in the Morse
queue with the queue's mutex still locked. The Morse thread then blocked
on it for good: nothing more was sent, rig_close() waited forever while
the queue held text, and the next rig_send_morse() hung.
The overflow check also missed a full queue whose read position was 0,
as on a fresh queue: the write position wrapped onto it and the queued
text was dropped, with RIG_OK returned.
hl_push() now checks for room before storing each character, unlocks
before it returns, and stores the new write position only once the whole
text fits, so a text that does not fit is refused whole.
tests/testmorse checks that a text longer than the queue is refused with
nothing sent, and that after a refused text the next one is sent and
rig_close() returns.
Cover exact capacity, filtering and wraparound with queued text. Build
the internal FIFO source into tests/testmorse so those helpers do not
need new DLL exports.
(cherry picked from commit c75e0dced289492bdadf672f2a7ab7ca0d2cb594)
Co-authored-by: David Christle <dch...@us...>
diff --git a/src/fifo.c b/src/fifo.c
index b7da0637c..b3cf28415 100644
--- a/src/fifo.c
+++ b/src/fifo.c
@@ -44,11 +44,13 @@ void resetFIFO(FIFO_RIG *fifo)
}
// returns RIG_OK if added
-// return -RIG error if overflow
+// returns -RIG_EDOM, adding nothing, if the text does not fit
int hl_push(FIFO_RIG *fifo, const char *msg)
{
pthread_mutex_lock(&fifo->mutex);
int len = strlen(msg);
+ // Readers see the text only once fifo->tail is stored
+ int tail = fifo->tail;
for (int i = 0; i < len; ++i)
{
@@ -63,20 +65,27 @@ int hl_push(FIFO_RIG *fifo, const char *msg)
continue;
}
- fifo->data[fifo->tail] = msg[i];
+ int next = (tail + 1) % HAMLIB_FIFO_SIZE;
+
+ if (next == fifo->head)
+ {
+ pthread_mutex_unlock(&fifo->mutex);
+ return -RIG_EDOM;
+ }
+
+ fifo->data[tail] = msg[i];
if (isalnum(msg[i]))
rig_debug(RIG_DEBUG_VERBOSE, "%s: push %c (%d,%d)\n", __func__, msg[i],
- fifo->head, fifo->tail);
+ fifo->head, tail);
else
rig_debug(RIG_DEBUG_VERBOSE, "%s: push 0x%02x (%d,%d)\n", __func__, msg[i],
- fifo->head, fifo->tail);
-
- if (fifo->tail + 1 == fifo->head) { return -RIG_EDOM; }
+ fifo->head, tail);
- fifo->tail = (fifo->tail + 1) % HAMLIB_FIFO_SIZE;
+ tail = next;
}
+ fifo->tail = tail;
pthread_mutex_unlock(&fifo->mutex);
return RIG_OK;
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0c0ea7143..b10e8d438 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -155,6 +155,8 @@ rigctlsync_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(LDADD) $(READLINE_LIBS)
testdebug_LDADD = $(PTHREAD_LIBS) $(LDADD)
testasyncio_LDADD = $(PTHREAD_LIBS) $(LDADD)
testmorse_LDADD = $(PTHREAD_LIBS) $(LDADD)
+# Exercise internal FIFO helpers without adding them to the DLL exports.
+testmorse_SOURCES = testmorse.c $(top_srcdir)/src/fifo.c
testid5100_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testicomfallback_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testsendraw_SOURCES = testsendraw.c
diff --git a/tests/testmorse.c b/tests/testmorse.c
index 9bef12149..3133cdbcf 100644
--- a/tests/testmorse.c
+++ b/tests/testmorse.c
@@ -246,11 +246,115 @@ static void test_queue_ready_before_worker(void)
CHECK(rig_cleanup(rig) == RIG_OK);
}
+static void check_fifo_text(FIFO_RIG *fifo, const char *text)
+{
+ for (size_t i = 0; text[i] != '\0'; ++i)
+ {
+ CHECK(hl_peek(fifo) == (unsigned char)text[i]);
+ CHECK(hl_pop(fifo) == (unsigned char)text[i]);
+ }
+
+ CHECK(hl_peek(fifo) == -1);
+ CHECK(hl_pop(fifo) == -1);
+}
+
+static void test_exact_capacity(void)
+{
+ FIFO_RIG fifo = { 0 };
+ char full[HAMLIB_FIFO_SIZE];
+
+ memset(full, 'E', sizeof(full) - 1);
+ full[sizeof(full) - 1] = '\0';
+ initFIFO(&fifo);
+ CHECK(hl_push(&fifo, full) == RIG_OK);
+ CHECK(hl_push(&fifo, "T") == -RIG_EDOM);
+ check_fifo_text(&fifo, full);
+ CHECK(hl_push(&fifo, "T") == RIG_OK);
+ check_fifo_text(&fifo, "T");
+ CHECK(pthread_mutex_destroy(&fifo.mutex) == 0);
+}
+
+static void test_filtered_capacity(void)
+{
+ FIFO_RIG fifo = { 0 };
+ char full[HAMLIB_FIFO_SIZE];
+
+ memset(full, 'E', sizeof(full) - 1);
+ full[sizeof(full) - 1] = '\0';
+ initFIFO(&fifo);
+ CHECK(hl_push(&fifo, "\rE\n\x80\xffT\r\n") == RIG_OK);
+ check_fifo_text(&fifo, "ET");
+ CHECK(hl_push(&fifo, full) == RIG_OK);
+ CHECK(hl_push(&fifo, "\r\n\x80\xff") == RIG_OK);
+ CHECK(hl_push(&fifo, "\r\nT\x80") == -RIG_EDOM);
+ check_fifo_text(&fifo, full);
+ CHECK(pthread_mutex_destroy(&fifo.mutex) == 0);
+}
+
+static void test_wraparound_rejection_preserves_text(void)
+{
+ FIFO_RIG fifo = { 0 };
+ char padding[HAMLIB_FIFO_SIZE - 3];
+ char too_long[HAMLIB_FIFO_SIZE];
+
+ memset(padding, 'E', sizeof(padding) - 1);
+ padding[sizeof(padding) - 1] = '\0';
+ memset(too_long, 'T', sizeof(too_long) - 1);
+ too_long[sizeof(too_long) - 1] = '\0';
+ initFIFO(&fifo);
+ CHECK(hl_push(&fifo, padding) == RIG_OK);
+ check_fifo_text(&fifo, padding);
+ CHECK(hl_push(&fifo, "ABCDEF") == RIG_OK);
+ CHECK(fifo.tail < fifo.head);
+ CHECK(hl_push(&fifo, too_long) == -RIG_EDOM);
+ CHECK(hl_push(&fifo, "G") == RIG_OK);
+ check_fifo_text(&fifo, "ABCDEFG");
+ CHECK(pthread_mutex_destroy(&fifo.mutex) == 0);
+}
+
+static void test_oversized_fresh_queue(void)
+{
+ char too_long[HAMLIB_FIFO_SIZE + 1];
+ RIG *rig = open_held_rig();
+
+ memset(too_long, 'E', sizeof(too_long) - 1);
+ too_long[sizeof(too_long) - 1] = '\0';
+ CHECK(rig_send_morse(rig, RIG_VFO_CURR, too_long) == -RIG_EDOM);
+ CHECK(hl_peek(STATE(rig)->fifo_morse) == -1);
+ release_worker();
+ CHECK(rig_close(rig) == RIG_OK);
+ CHECK(sent_equals(""));
+ CHECK(rig_cleanup(rig) == RIG_OK);
+}
+
+static void test_queue_recovers_after_overflow(void)
+{
+ char too_long[HAMLIB_FIFO_SIZE + 1];
+ RIG *rig = open_test_rig();
+
+ CHECK(rig_send_morse(rig, RIG_VFO_CURR, "E") == RIG_OK);
+ wait_until_sent("E");
+ memset(too_long, 'E', sizeof(too_long) - 1);
+ too_long[sizeof(too_long) - 1] = '\0';
+ CHECK(rig_send_morse(rig, RIG_VFO_CURR, too_long) == -RIG_EDOM);
+ CHECK(rig_send_morse(rig, RIG_VFO_CURR, "T") == RIG_OK);
+ wait_until_sent("ET");
+ CHECK(rig_close(rig) == RIG_OK);
+ CHECK(sent_equals("ET"));
+ CHECK(rig_cleanup(rig) == RIG_OK);
+}
+
int main(void)
{
rig_set_debug(RIG_DEBUG_NONE);
CHECK(rig_register(&morse_caps) == RIG_OK);
run_test("queue ready before worker", test_queue_ready_before_worker);
+ run_test("exact usable capacity", test_exact_capacity);
+ run_test("filtered capacity", test_filtered_capacity);
+ run_test("wraparound rejection preserves text",
+ test_wraparound_rejection_preserves_text);
+ run_test("oversized fresh queue", test_oversized_fresh_queue);
+ run_test("queue recovers after overflow", test_queue_recovers_after_overflow);
CHECK(rig_unregister(TEST_MORSE_MODEL) == RIG_OK);
puts("Morse queue tests passed");
return EXIT_SUCCESS;
commit eab0a2147c2a575002c53088d974382b9efcec2b
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Tue Nov 3 11:39:58 2026 +0100
fix(rig): create the Morse queue before its thread starts
rig_open() starts the Morse thread and may return before the thread has
run, and only the thread allocated and initialised the queue.
rig_send_morse() right after rig_open() could then find no queue and
dereference NULL in hl_push(), and rig_stop_morse() likewise in
resetFIFO(). In a stress run under lldb with a test backend, 19 of 40
processes started at once crashed in hl_push().
rig_morse_data_handler_start() now creates the queue before it starts
the thread, and frees it again if the thread cannot be started. The
thread still frees it when it ends. Rigs without a Morse thread do not
change.
tests/testmorse holds the worker behind a condition gate and checks that
text queued before it runs is sent; without the fix the queue does not
exist yet at that point. testasyncio checks that a failed start leaves
no queue behind.
(cherry picked from commit 547ab82f2b9a9c108db00db6e5a2538f7ed3882f)
Co-authored-by: David Christle <dch...@us...>
diff --git a/src/rig.c b/src/rig.c
index c131d3835..5111ab1f5 100644
--- a/src/rig.c
+++ b/src/rig.c
@@ -8605,6 +8605,21 @@ int rig_morse_data_handler_start(RIG *rig,
RETURNFUNC(-RIG_ENOMEM);
}
+ // The queue must be ready even if rig_open() returns before the worker runs.
+ if (rs->fifo_morse == NULL)
+ {
+ rs->fifo_morse = calloc(1, sizeof(FIFO_RIG));
+
+ if (rs->fifo_morse == NULL)
+ {
+ free(rs->morse_data_handler_priv_data);
+ rs->morse_data_handler_priv_data = NULL;
+ RETURNFUNC(-RIG_ENOMEM);
+ }
+ }
+
+ initFIFO(rs->fifo_morse);
+
morse_data_handler_priv = (morse_data_handler_priv_data *)
rs->morse_data_handler_priv_data;
morse_data_handler_priv->args.rig = rig;
@@ -8623,6 +8638,8 @@ int rig_morse_data_handler_start(RIG *rig,
rs->morse_data_handler_thread_run = 0;
free(rs->morse_data_handler_priv_data);
rs->morse_data_handler_priv_data = NULL;
+ free(rs->fifo_morse);
+ rs->fifo_morse = NULL;
rig_debug(RIG_DEBUG_ERR, "%s: pthread_create error: %s\n", __func__,
strerror(err));
RETURNFUNC(-RIG_EINTERNAL);
@@ -8830,14 +8847,6 @@ static void *morse_data_handler(void *arg)
rig_debug(RIG_DEBUG_VERBOSE, "%s: Starting morse data handler thread\n",
__func__);
- if (STATE(rig)->fifo_morse == NULL)
- {
- // Can't use rs-> 'cuz it's const
- STATE(rig)->fifo_morse = calloc(1, sizeof(FIFO_RIG));
- }
-
- initFIFO(rs->fifo_morse);
-
char *c;
int qsize = rig->caps->morse_qsize; // if backend overrides qsize
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 12bf38f51..0c0ea7143 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,6 +35,7 @@ DIRECT_TESTS = \
testnewcatset \
testsendraw \
testmodecompat \
+ testmorse \
testsmartsdrstatus \
testthd7x \
testthd75emu \
@@ -116,6 +117,7 @@ rigctltcp_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_builddir)/security
rigctlsync_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_builddir)/security
testdebug_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testasyncio_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testmorse_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testnetrigctl_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testsendraw_CFLAGS = $(AM_CFLAGS)
testdaemonclient_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
@@ -152,6 +154,7 @@ rigctltcp_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(LDADD) $(READLINE_LIBS)
rigctlsync_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(LDADD) $(READLINE_LIBS)
testdebug_LDADD = $(PTHREAD_LIBS) $(LDADD)
testasyncio_LDADD = $(PTHREAD_LIBS) $(LDADD)
+testmorse_LDADD = $(PTHREAD_LIBS) $(LDADD)
testid5100_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testicomfallback_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testsendraw_SOURCES = testsendraw.c
diff --git a/tests/testasyncio.c b/tests/testasyncio.c
index a104989d7..31ea3ea8a 100644
--- a/tests/testasyncio.c
+++ b/tests/testasyncio.c
@@ -437,6 +437,7 @@ static void test_failed_morse_start_rolls_back_state(void)
check_thread_error();
REQUIRE(!STATE(rig)->morse_data_handler_thread_run);
REQUIRE(STATE(rig)->morse_data_handler_priv_data == NULL);
+ REQUIRE(STATE(rig)->fifo_morse == NULL);
}
REQUIRE(rig_open(rig) == RIG_OK);
diff --git a/tests/testmorse.c b/tests/testmorse.c
new file mode 100644
index 000000000..9bef12149
--- /dev/null
+++ b/tests/testmorse.c
@@ -0,0 +1,257 @@
+/*
+ * Hamlib Morse queue tests, run without a radio.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "hamlib/config.h"
+
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/rig_state.h"
+#include "fifo.h"
+#include "misc.h"
+#include "rig_internal.h"
+
+#define TEST_MORSE_MODEL RIG_MAKE_MODEL(RIG_DUMMY, 998)
+
+#define CHECK(condition) \
+ do \
+ { \
+ if (!(condition)) \
+ { \
+ fprintf(stderr, "FAIL: %s:%d: %s\n", __FILE__, __LINE__, \
+ #condition); \
+ exit(EXIT_FAILURE); \
+ } \
+ } while (0)
+
+struct test_deadline
+{
+ const char *name;
+ int done;
+};
+
+static void *watchdog(void *arg)
+{
+ struct test_deadline *deadline = arg;
+
+ for (...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-11-11 13:40:16
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 1b3fb4a6a30652c37a45b38cd766f5de515231b3 (commit)
via f78a899fe0b8d5282a201485cbf9c679e08ae2f1 (commit)
via b7a9bfab7227b803458b97dea5cc58a0f12b8362 (commit)
via dba524fef82627a9a481de08d7600a9b589b1644 (commit)
via 9c1fd07b4e2f3d11331a5ba15c10376f90a8390b (commit)
via 9199f8a239aed26b5eb0ee9c1a73bf51580483ce (commit)
via 43b3585ea14dd52ebbfd018bcddc7c4a7630a24f (commit)
via 47657b4ba320e7ff03bdf5e14f821a77197d345c (commit)
via 6aa7852bd310126093869ee225123ccaadb2f847 (commit)
via ebda7335e0b189e2b9defcec7daed84cac19315b (commit)
via e724eae550cb6e6429608471bcf4497586d20d8a (commit)
via 7f20794ea259f764bed36a0769dc43a12689847b (commit)
via ef684a15e2122844c4eed8b62c50415faddc9e47 (commit)
via 96331d93a082bc6d73d91e7d19d34039d90636c5 (commit)
via c75e0dced289492bdadf672f2a7ab7ca0d2cb594 (commit)
via 547ab82f2b9a9c108db00db6e5a2538f7ed3882f (commit)
via 4cc853ea7ff47bb17c429c8cff16263a907c76d7 (commit)
via a31705698eded8509bcba90c44eaaf33b3c4e3ff (commit)
from 67e01fff9d4a710b92bea1f588e48efe0d558f27 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1b3fb4a6a30652c37a45b38cd766f5de515231b3
Author: David Christle <dch...@us...>
Date: Mon Sep 21 23:18:45 2026 +0200
fix(newcat): reject invalid narrow filter values
NewCAT narrow status is boolean, but the parser accepted up to three
digits and used the result as a two-element defaults index. Reject
values other than zero or one before bandwidth selection.
Extend the FT-950 socket test with both valid default-width mappings and
a malformed narrow reply.
diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c
index 9581c2ea4..be8eb294d 100644
--- a/rigs/yaesu/newcat.c
+++ b/rigs/yaesu/newcat.c
@@ -8757,6 +8757,13 @@ static int get_narrow(RIG *rig, vfo_t vfo)
RETURNFUNC(-RIG_EPROTO);
}
+ if (narrow != 0 && narrow != 1)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: invalid narrow value %d from '%s'\n",
+ __func__, narrow, priv->ret_data);
+ RETURNFUNC(-RIG_EPROTO);
+ }
+
RETURNFUNC(narrow);
}
diff --git a/tests/testnewcatwidth.c b/tests/testnewcatwidth.c
index 5c943cfa9..d5281e4c1 100644
--- a/tests/testnewcatwidth.c
+++ b/tests/testnewcatwidth.c
@@ -32,6 +32,7 @@ int main(void)
#include "hamlib/rig_state.h"
extern struct rig_caps ft450_caps;
+extern struct rig_caps ft950_caps;
extern struct rig_caps ft9000_caps;
enum test_operation
@@ -47,6 +48,8 @@ struct peer_case
const char *mode_response;
const char *width_command;
const char *width_response;
+ const char *narrow_command;
+ const char *narrow_response;
int status;
};
@@ -146,6 +149,13 @@ static void *run_peer(void *arg)
return NULL;
}
+ if (test->narrow_command != NULL
+ && exchange(test->fd, test->narrow_command,
+ test->narrow_response) != 0)
+ {
+ return NULL;
+ }
+
test->status = 0;
return NULL;
}
@@ -161,6 +171,8 @@ static int run_case(const struct width_case *test_case)
.mode_response = test_case->mode_response,
.width_command = test_case->width_command,
.width_response = test_case->width_response,
+ .narrow_command = NULL,
+ .narrow_response = NULL,
.status = -1
};
RIG *rig;
@@ -229,6 +241,78 @@ static int run_case(const struct width_case *test_case)
return 0;
}
+static int run_narrow_case(const char *name, const char *narrow_response,
+ int expected_retval, pbwidth_t expected_width)
+{
+ int sockets[2];
+ pthread_t thread;
+ struct peer_case peer =
+ {
+ .fd = -1,
+ .mode_command = "MD0;",
+ .mode_response = "MD02;",
+ .width_command = "SH0;",
+ .width_response = "SH000;",
+ .narrow_command = "NA0;",
+ .narrow_response = narrow_response,
+ .status = -1
+ };
+ RIG *rig;
+ rmode_t mode = RIG_MODE_NONE;
+ pbwidth_t width = RIG_PASSBAND_NORMAL;
+ int retval;
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0)
+ {
+ perror("socketpair");
+ return 1;
+ }
+
+ rig = rig_init(RIG_MODEL_FT950);
+
+ if (rig == NULL)
+ {
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->timeout = 100;
+ RIGPORT(rig)->retry = 0;
+ STATE(rig)->powerstat = RIG_POWER_ON;
+ peer.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &peer) != 0)
+ {
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ retval = rig->caps->get_mode(rig, RIG_VFO_A, &mode, &width);
+ pthread_join(thread, NULL);
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+
+ if (peer.status != 0 || retval != expected_retval
+ || (retval == RIG_OK
+ && (mode != RIG_MODE_USB || width != expected_width)))
+ {
+ fprintf(stderr,
+ "%s: expected %d/USB/%d, got %d/%s/%d (peer %d)\n",
+ name, expected_retval, (int)expected_width, retval,
+ rig_strrmode(mode), (int)width, peer.status);
+ return 1;
+ }
+
+ return 0;
+}
+
int main(void)
{
static const struct width_case cases[] =
@@ -270,6 +354,7 @@ int main(void)
rig_set_debug(RIG_DEBUG_NONE);
rig_register(&ft450_caps);
+ rig_register(&ft950_caps);
rig_register(&ft9000_caps);
for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
@@ -280,6 +365,14 @@ int main(void)
}
}
+ if (run_narrow_case("wide default", "NA00;", RIG_OK, 2400) != 0
+ || run_narrow_case("narrow default", "NA01;", RIG_OK, 1800) != 0
+ || run_narrow_case("invalid narrow", "NA02;", -RIG_EPROTO,
+ RIG_PASSBAND_NORMAL) != 0)
+ {
+ return 1;
+ }
+
return 0;
}
commit f78a899fe0b8d5282a201485cbf9c679e08ae2f1
Author: Wahaj18 <484...@us...>
Date: Wed Nov 4 12:54:35 2026 +0500
G90: reject non-BCD SWR meter replies
The G90 sometimes answers the SWR meter query with a byte whose low
nibble is not a BCD digit (e.g. 02 2c). from_bcd_be() decoded it anyway,
so RIG_LEVEL_SWR reported values up to the 6.0 ceiling of the default
calibration table while the rig showed a normal match.
Validate the reply in g90_get_level() and return -RIG_EPROTO for
non-BCD bytes, as is already done for the G90 AF quirk.
Fixes #2257
diff --git a/rigs/icom/icom.h b/rigs/icom/icom.h
index 6c039e4d2..992f7a36e 100644
--- a/rigs/icom/icom.h
+++ b/rigs/icom/icom.h
@@ -467,6 +467,7 @@ extern const struct confparams icom_ext_levels[];
extern const struct confparams icom_ext_funcs[];
extern const struct confparams icom_ext_parms[];
extern const struct cmdparams icom_ext_cmds[];
+extern const cal_table_float_t icom_default_swr_cal;
extern struct rig_caps ic703_caps;
extern struct rig_caps ic705_caps;
diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c
index 6a93919c3..a025830ad 100644
--- a/rigs/icom/xiegu.c
+++ b/rigs/icom/xiegu.c
@@ -1483,6 +1483,44 @@ static int g90_get_af_quirk(RIG *rig, value_t *val)
return RIG_OK;
}
+/*
+ * G90 firmware sometimes answers the SWR meter query with a byte whose
+ * low nibble is not a BCD digit (e.g. 0x02 0x2c), which from_bcd_be()
+ * turns into a much higher SWR than the rig shows. Reject such replies.
+ */
+static int g90_get_swr(RIG *rig, value_t *val)
+{
+ unsigned char response[MAXFRAMELEN];
+ int length = sizeof(response), retval, raw;
+
+ retval = icom_transaction(rig, C_RD_SQSM, S_SWR, NULL, 0,
+ response, &length);
+
+ if (retval != RIG_OK)
+ {
+ return retval;
+ }
+
+ if (length == 1 && response[0] == NAK)
+ {
+ return -RIG_ERJCTED;
+ }
+
+ if (length != 4 || response[0] != C_RD_SQSM || response[1] != S_SWR
+ || response[2] > 0x09 || (response[3] >> 4) > 9
+ || (response[3] & 0x0f) > 9)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: invalid SWR response, len=%d\n",
+ __func__, length);
+ return -RIG_EPROTO;
+ }
+
+ raw = from_bcd_be(response + 2, 4);
+ val->f = rig_raw2val_float(raw, rig->caps->swr_cal.size != 0
+ ? &rig->caps->swr_cal : &icom_default_swr_cal);
+ return RIG_OK;
+}
+
/*
* g90_get_level
* Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL
@@ -1502,6 +1540,11 @@ static int g90_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
return g90_get_af_quirk(rig, val);
}
+ if (level == RIG_LEVEL_SWR)
+ {
+ return g90_get_swr(rig, val);
+ }
+
if (level == RIG_LEVEL_RFPOWER)
{
retval = icom_get_level(rig, vfo, level, val);
diff --git a/tests/make/tests-icom.am b/tests/make/tests-icom.am
index d5aa92367..8121c3f14 100644
--- a/tests/make/tests-icom.am
+++ b/tests/make/tests-icom.am
@@ -12,6 +12,14 @@ testg90rit_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testg90rit_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) \
$(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
+check_PROGRAMS += testg90swr
+TESTS += testg90swr
+testg90swr_SOURCES = testg90swr.c testicomsock.c testicomsock.h
+testg90swr_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
+testg90swr_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testg90swr_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) \
+ $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
+
check_PROGRAMS += testic7760caps
TESTS += testic7760caps
testic7760caps_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
diff --git a/tests/testg90swr.c b/tests/testg90swr.c
new file mode 100644
index 000000000..8ae3f6a66
--- /dev/null
+++ b/tests/testg90swr.c
@@ -0,0 +1,164 @@
+/*
+ * Hamlib Xiegu G90 SWR meter tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+/*
+ * The G90 sometimes answers the SWR meter query (15 12) with a byte
+ * that is not BCD, e.g. 02 2c. Decoding it anyway reports an SWR near
+ * the top of the calibration table, so such a reply must be rejected
+ * while valid readings still go through the calibration table.
+ */
+
+#include <math.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/port.h"
+#include "hamlib/rig_state.h"
+#include "icom.h"
+#include "frame.h"
+#include "misc.h"
+#include "testicomsock.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+extern struct rig_caps g90_caps;
+
+struct swr_case
+{
+ unsigned char hi, lo;
+ int expected_retval;
+ float expected_swr;
+};
+
+static const struct swr_case cases[] =
+{
+ { 0x00, 0x00, RIG_OK, 1.0f },
+ { 0x01, 0x84, RIG_OK, 4.6f },
+ { 0x02, 0x2c, -RIG_EPROTO, 0 }, /* low nibble 0xc, seen in #2257 */
+ { 0x01, 0xa0, -RIG_EPROTO, 0 },
+ { 0x0a, 0x00, -RIG_EPROTO, 0 }
+};
+
+struct peer_case
+{
+ int fd;
+ int bad_request;
+};
+
+static void *run_peer(void *arg)
+{
+ static const unsigned char query[] =
+ {
+ 0xfe, 0xfe, 0x88, 0xe0, 0x15, 0x12, 0xfd
+ };
+ struct peer_case *test = arg;
+ unsigned char frame[MAXFRAMELEN];
+ size_t i, length;
+
+ for (i = 0; i < ARRAY_SIZE(cases); i++)
+ {
+ unsigned char reply[] =
+ {
+ 0xfe, 0xfe, 0xe0, 0x88, 0x15, 0x12, cases[i].hi, cases[i].lo, 0xfd
+ };
+
+ if (read_frame(test->fd, frame, sizeof(frame), &length) != 0)
+ {
+ break;
+ }
+
+ if (length != sizeof(query) || memcmp(frame, query, length) != 0)
+ {
+ test->bad_request = 1;
+ }
+
+ if (write_all(test->fd, reply, sizeof(reply)) != 0) { break; }
+ }
+
+ return NULL;
+}
+
+int main(void)
+{
+ int sockets[2];
+ pthread_t thread;
+ struct peer_case test = { -1, 0 };
+ RIG *rig;
+ size_t i;
+ int failed = 0;
+
+#ifdef _WIN32
+ WSADATA wsa_data;
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0) { return 1; }
+
+#endif
+
+ rig_register(&g90_caps);
+ rig = rig_init(RIG_MODEL_G90);
+
+ if (rig == NULL || open_test_connection(sockets) != 0)
+ {
+ fprintf(stderr, "test setup failed\n");
+ return 1;
+ }
+
+ test.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &test) != 0)
+ {
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->type.rig = RIG_PORT_NETWORK;
+ RIGPORT(rig)->timeout = 250;
+ RIGPORT(rig)->retry = 0;
+ ((struct icom_priv_data *) STATE(rig)->priv)->serial_USB_echo_off = 1;
+ STATE(rig)->comm_state = 1;
+ rig_set_current_vfo_state(rig, RIG_VFO_A);
+
+ for (i = 0; i < ARRAY_SIZE(cases); i++)
+ {
+ value_t val = { .f = -1.0f };
+ int retval = rig->caps->get_level(rig, RIG_VFO_CURR, RIG_LEVEL_SWR,
+ &val);
+
+ if (retval != cases[i].expected_retval
+ || (retval == RIG_OK
+ && fabsf(val.f - cases[i].expected_swr) > 0.001f))
+ {
+ fprintf(stderr, "SWR reply %02x %02x: expected %d/%.2f, got %d/%.2f\n",
+ cases[i].hi, cases[i].lo, cases[i].expected_retval,
+ cases[i].expected_swr, retval, val.f);
+ failed = 1;
+ }
+ }
+
+ stop_test_peer(sockets, thread);
+
+ if (test.bad_request)
+ {
+ fprintf(stderr, "unexpected SWR query frame\n");
+ failed = 1;
+ }
+
+ STATE(rig)->comm_state = 0;
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+
+#ifdef _WIN32
+ WSACleanup();
+#endif
+
+ return failed;
+}
commit b7a9bfab7227b803458b97dea5cc58a0f12b8362
Author: David Christle <dch...@us...>
Date: Tue Nov 10 16:41:09 2026 -0800
fix(elecraft): read K4 power in a single transaction
The TM forward-power field uses tenths of a watt in low range and
whole watts in high range. Interpreting both as watts can report
20 W for 2 W of output.
Read PO for both power meters. Its fixed tenths-of-a-watt units make
the reading independent of a separate range query. Keep the 100 W
reference for the normalized meter and use TM for SWR and ALC.
Support PO in the K4 simulator and extend the Elecraft socket suite
to cover metering. Rename the suite and its executable ignore entry
to reflect its broader scope.
diff --git a/rigs/kenwood/k3.c b/rigs/kenwood/k3.c
index 4f3bf2a31..6da99e99f 100644
--- a/rigs/kenwood/k3.c
+++ b/rigs/kenwood/k3.c
@@ -182,8 +182,7 @@ static int k3_get_nb_level(RIG *rig, float *dsp_nb, float *if_nb);
static int k3_get_bar_graph_level(RIG *rig, float *smeter, float *pwr,
float *alc,
int *mode_tx);
-static int k4_get_bar_graph_level(RIG *rig, float *swr, float *pwr, float *alc,
- int *mode_tx);
+static int k4_get_bar_graph_level(RIG *rig, float *swr, float *alc);
/* K4 functions */
static int k4_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt);
@@ -2125,7 +2124,7 @@ static int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
if (RIG_IS_K4)
{
- retval = k4_get_bar_graph_level(rig, NULL, NULL, &alc, &tx_mode);
+ retval = k4_get_bar_graph_level(rig, NULL, &alc);
tx_mode = 1; // Assume ALC is zero when in Tx so we don't care about ptt status
}
else
@@ -2161,14 +2160,27 @@ static int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
if (RIG_IS_K4)
{
- retval = k4_get_bar_graph_level(rig, NULL, &pwr, NULL, &tx_mode);
- tx_mode = 1; // Does K4 return pwr=0 when in Rx? Hope so.
- }
- else
- {
- retval = k3_get_bar_graph_level(rig, NULL, &pwr, NULL, &tx_mode);
+ retval = kenwood_safe_transaction(rig, "PO", levelbuf,
+ sizeof(levelbuf), 6);
+
+ if (retval != RIG_OK)
+ {
+ return retval;
+ }
+
+ if (strspn(levelbuf + 2, "0123456789") != 4)
+ {
+ return -RIG_EPROTO;
+ }
+
+ // PO reports tenths of a watt in both power ranges.
+ val->f = atoi(levelbuf + 2) /
+ (level == RIG_LEVEL_RFPOWER_METER_WATTS ? 10.0f : 1000.0f);
+ return RIG_OK;
}
+ retval = k3_get_bar_graph_level(rig, NULL, &pwr, NULL, &tx_mode);
+
if (retval != RIG_OK)
{
return retval;
@@ -2374,7 +2386,7 @@ static int k3_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
case RIG_LEVEL_SWR:
if (RIG_IS_K4)
{
- return k4_get_bar_graph_level(rig, &val->f, NULL, NULL, NULL);
+ return k4_get_bar_graph_level(rig, &val->f, NULL);
}
else
{
@@ -2759,8 +2771,7 @@ static int k3_get_nb_level(RIG *rig, float *dsp_nb, float *if_nb)
return RIG_OK;
}
-int k4_get_bar_graph_level(RIG *rig, float *swr, float *pwr, float *alc,
- int *mode_tx)
+static int k4_get_bar_graph_level(RIG *rig, float *swr, float *alc)
{
int retval;
int ialc, icmp, ifwd, iswr;
@@ -2782,8 +2793,6 @@ int k4_get_bar_graph_level(RIG *rig, float *swr, float *pwr, float *alc,
if (swr) { *swr = iswr / 10.0; }
- if (pwr) { *pwr = ifwd / 100.0; } // pwr is returned in 0-1 sscale
-
if (alc) { *alc = ialc; }
return RIG_OK;
diff --git a/simulators/simelecraftk4.c b/simulators/simelecraftk4.c
index 43d28aab0..4b2d4fb83 100644
--- a/simulators/simelecraftk4.c
+++ b/simulators/simelecraftk4.c
@@ -297,6 +297,11 @@ int main(int argc, char *argv[])
SNPRINTF(buf, sizeof(buf), "PC0980;");
WRITE(fd, buf, strlen(buf));
}
+ else if (strncmp(buf, "PO;", 3) == 0)
+ {
+ SNPRINTF(buf, sizeof(buf), "PO0003;");
+ WRITE(fd, buf, strlen(buf));
+ }
else if (strncmp(buf, "PA;", 3) == 0)
{
SNPRINTF(buf, sizeof(buf), "PA%d;", preampA);
diff --git a/tests/.gitignore b/tests/.gitignore
index ff491df0d..e4b38b846 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -37,7 +37,7 @@ testcookie.sh
testctlparser
testdebug
testdummyparm
-testelecraftvfo
+testelecraft
testfreq
testfreq.sh
testft991idmeter
diff --git a/tests/make/tests-kenwood.am b/tests/make/tests-kenwood.am
index 204be4170..c5d88a7aa 100644
--- a/tests/make/tests-kenwood.am
+++ b/tests/make/tests-kenwood.am
@@ -1,7 +1,7 @@
-check_PROGRAMS += testelecraftvfo
-TESTS += testelecraftvfo
-testelecraftvfo_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
-testelecraftvfo_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) \
+check_PROGRAMS += testelecraft
+TESTS += testelecraft
+testelecraft_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testelecraft_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) \
$(top_builddir)/rigs/kenwood/libhamlib-kenwood.la $(LDADD)
check_PROGRAMS += testthd75emu
diff --git a/tests/testelecraftvfo.c b/tests/testelecraft.c
similarity index 79%
rename from tests/testelecraftvfo.c
rename to tests/testelecraft.c
index ae4a7fc40..59c948938 100644
--- a/tests/testelecraftvfo.c
+++ b/tests/testelecraft.c
@@ -1,5 +1,5 @@
/*
- * Hamlib Elecraft K4 VFO and mode response tests
+ * Hamlib Elecraft response tests
* Copyright (c) 2026 by Hamlib Team
*
* This library is free software; you can redistribute it and/or
@@ -8,6 +8,7 @@
* version 2.1 of the License, or (at your option) any later version.
*/
+#include <math.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
@@ -468,6 +469,151 @@ static int run_split_mode_set_case(int is_k4, rmode_t mode)
return 0;
}
+static int run_meter_case(const char *name, setting_t level,
+ const char *command,
+ const char *response, int expected_retval,
+ float expected_value)
+{
+ struct peer_case test =
+ {
+ .fd = -1,
+ .commands = &command,
+ .responses = &response,
+ .count = 1,
+ .status = -1
+ };
+ int sockets[2];
+ pthread_t thread;
+ RIG *rig;
+ value_t value = { .f = -1.0f };
+ int retval;
+
+ if (open_test_connection(sockets) != 0) { return 1; }
+
+ test.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &test) != 0)
+ {
+ close_test_socket(sockets[0]);
+ close_test_socket(sockets[1]);
+ return 1;
+ }
+
+ rig = rig_init(RIG_MODEL_K4);
+
+ if (rig == NULL)
+ {
+ close_test_socket(sockets[0]);
+ close_test_socket(sockets[1]);
+ pthread_join(thread, NULL);
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->type.rig = RIG_PORT_NETWORK;
+ RIGPORT(rig)->timeout = 500;
+ RIGPORT(rig)->retry = 0;
+
+ retval = rig->caps->get_level(rig, RIG_VFO_CURR, level, &value);
+
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close_test_socket(sockets[0]);
+ pthread_join(thread, NULL);
+ close_test_socket(sockets[1]);
+
+ if (test.status != 0 || retval != expected_retval
+ || fabsf(value.f - (retval == RIG_OK ? expected_value : -1.0f))
+ > 0.00001f)
+ {
+ fprintf(stderr, "%s: expected %d/%.4f, got %d/%.4f (peer %d)\n",
+ name, expected_retval, expected_value, retval, value.f,
+ test.status);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int test_meters(void)
+{
+ static const struct
+ {
+ const char *name;
+ setting_t level;
+ const char *command;
+ const char *response;
+ int retval;
+ float value;
+ } cases[] =
+ {
+ {
+ "2w", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0020;", RIG_OK, 2.0f
+ },
+ {
+ "20w", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0200;", RIG_OK, 20.0f
+ },
+ {
+ "minimum-nonzero-output", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0001;", RIG_OK, 0.1f
+ },
+ {
+ "110w", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO1100;", RIG_OK, 110.0f
+ },
+ {
+ "zero-output", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO0000;", RIG_OK, 0.0f
+ },
+ {
+ "2w-normalized", RIG_LEVEL_RFPOWER_METER,
+ "PO;", "PO0020;", RIG_OK, 0.02f
+ },
+ {
+ "20w-normalized", RIG_LEVEL_RFPOWER_METER,
+ "PO;", "PO0200;", RIG_OK, 0.2f
+ },
+ {
+ "swr", RIG_LEVEL_SWR,
+ "TM;", "TM003004020012;", RIG_OK, 1.2f
+ },
+ {
+ "alc", RIG_LEVEL_ALC,
+ "TM;", "TM003004020012;", RIG_OK, 3.0f
+ },
+ {
+ "malformed-power-response", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO00X0;", -RIG_EPROTO, 0.0f
+ },
+ {
+ "short-power-response", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "PO020;", -RIG_EPROTO, 0.0f
+ },
+ {
+ "power-query-unavailable", RIG_LEVEL_RFPOWER_METER_WATTS,
+ "PO;", "N;", -RIG_ENAVAIL, 0.0f
+ },
+ {
+ "malformed-tm-response", RIG_LEVEL_SWR,
+ "TM;", "TM00300402X012;", -RIG_EPROTO, 0.0f
+ }
+ };
+ size_t i;
+
+ for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ {
+ if (run_meter_case(cases[i].name, cases[i].level, cases[i].command,
+ cases[i].response, cases[i].retval, cases[i].value))
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
int main(void)
{
int failed = 0;
@@ -633,6 +779,8 @@ int main(void)
failed = run_split_mode_set_case(1, RIG_MODE_RTTYR);
+ if (!failed) { failed = test_meters(); }
+
cleanup:
#ifdef _WIN32
WSACleanup();
commit dba524fef82627a9a481de08d7600a9b589b1644
Merge: 9199f8a23 9c1fd07b4
Author: Terrell Deppe <62b...@pr...>
Date: Sat Nov 7 16:05:24 2026 -0600
Merge pull request #2222 from mikaelnousiainen/daemon-client-socket-fixes
Fix: client socket closed more than once, and a client thread can abort the daemon
commit 9c1fd07b4e2f3d11331a5ba15c10376f90a8390b
Author: KJ5HST <kj...@de...>
Date: Sat Nov 7 15:39:05 2026 -0600
tests: retry daemon startup on a fresh port
pick_free_port() checks the port on 127.0.0.1, but the daemons bind
[::], so the port can already be in use on IPv6, or be taken before the
daemon binds it, and the daemon exits at startup. Retry on a fresh port,
as start_rigctld_opt() in test_netrigctl_stream.c does.
diff --git a/test/test_daemon_clients.c b/test/test_daemon_clients.c
index 090680e02..b852506ea 100644
--- a/test/test_daemon_clients.c
+++ b/test/test_daemon_clients.c
@@ -216,8 +216,8 @@ static void dump_log(const struct daemon_proc *proc)
}
-static int start_daemon(const struct daemon_spec *spec,
- struct daemon_proc *proc)
+static int start_daemon_once(const struct daemon_spec *spec,
+ struct daemon_proc *proc)
{
const char *path = daemon_path(spec->name);
char port_str[16];
@@ -314,6 +314,29 @@ static void stop_daemon(struct daemon_proc *proc)
}
+/* pick_free_port() checks the port on 127.0.0.1 and closes its socket before
+ * the daemon binds the port on [::], so the port can already be in use on IPv6,
+ * or be taken in between, and the daemon exits on the bind failure. Retry on a
+ * fresh port, as start_rigctld_opt() in test_netrigctl_stream.c does. */
+static int start_daemon(const struct daemon_spec *spec,
+ struct daemon_proc *proc)
+{
+ int attempt;
+
+ for (attempt = 0; attempt < 3; attempt++)
+ {
+ if (start_daemon_once(spec, proc) == 0)
+ {
+ return 0;
+ }
+
+ stop_daemon(proc);
+ }
+
+ return -1;
+}
+
+
enum session_result
{
SESSION_ANSWERED,
commit 9199f8a239aed26b5eb0ee9c1a73bf51580483ce
Author: Claude <no...@an...>
Date: Tue Nov 3 19:08:39 2026 +0100
prm80: return the error of the final prompt wait of a transaction
prm80_transaction() waited for the final ">" prompt but ignored a timeout,
so e.g. [N] in set_func(REV) looked successful and [E] and [T] followed.
The result of the wait is returned now; REV stops before [T] if selecting
the channel did not complete.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
Claude-Session: https://claude.ai/code/session_01WuSe41qryLsRRQJPkzmJyd
diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c
index aab297061..18246e5f3 100644
--- a/rigs/prm80/prm80.c
+++ b/rigs/prm80/prm80.c
@@ -296,7 +296,8 @@ static int prm80_transaction(RIG *rig, const char *cmd,
if (wait_prompt)
{
- prm80_wait_for_prompt(rp);
+ // e.g. [N]: without the prompt the command may not have completed
+ return prm80_wait_for_prompt(rp);
}
return RIG_OK;
commit 43b3585ea14dd52ebbfd018bcddc7c4a7630a24f
Author: Claude <no...@an...>
Date: Tue Nov 3 18:55:03 2026 +0100
prm80: keep the default shift when a channel is written several times
set_channel cleared default_offs[] after every write, so a channel read
once and written twice got a fixed shift with the second write. After a
successful write with the default shift kept, default_offs[] keeps the
effective offset; it is cleared only for a channel with its own shift or
none, and after a failed write.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
Claude-Session: https://claude.ai/code/session_01WuSe41qryLsRRQJPkzmJyd
diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c
index d15d24b51..aab297061 100644
--- a/rigs/prm80/prm80.c
+++ b/rigs/prm80/prm80.c
@@ -1258,12 +1258,21 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
// the channel memory has changed
priv->list_valid = 0;
- priv->default_offs[chan->channel_num] = 0;
if (ret != RIG_OK)
{
+ priv->default_offs[chan->channel_num] = 0;
return ret;
}
+
+ // Written with the default shift kept: the next write of the same
+ // channel_t must keep it as well (an application may save a channel
+ // several times without reading it again). Otherwise the channel
+ // has its own shift (or none) now.
+ if (shift != 0 || offs == 0)
+ {
+ priv->default_offs[chan->channel_num] = 0;
+ }
}
else
{
commit 47657b4ba320e7ff03bdf5e14f821a77197d345c
Author: Claude <no...@an...>
Date: Mon Nov 2 00:38:58 2026 +0100
prm80: REV only with firmware V5.1+, get_channel fails without the list
- set_func(REV) returns -RIG_ENAVAIL with firmware V5.0 before sending
anything: its [N] does not stop a running scan, so [E] could report
another channel than the one [T] writes to. V5.1 and newer keep the
sequence [E], [N], fresh [E], [T]; the channel list cache is
invalidated afterwards.
- get_channel of a memory channel with shift returns the error of the
channel list lookup ([C]) instead of RIG_OK: without the stored shift a
write-back could replace the default shift by a fixed one.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
Claude-Session: https://claude.ai/code/session_01WuSe41qryLsRRQJPkzmJyd
diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c
index a111ced57..d15d24b51 100644
--- a/rigs/prm80/prm80.c
+++ b/rigs/prm80/prm80.c
@@ -925,10 +925,21 @@ int prm80_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only)
if (chan->vfo == RIG_VFO_MEM && chan->channel_num >= CHAN_MIN
&& chan->channel_num <= CHAN_MAX)
{
+ if (chan->rptr_shift != RIG_RPT_SHIFT_NONE)
+ {
+ // Without the stored shift the read is incomplete: a write-back
+ // could replace the default shift by a fixed one.
+ ret = prm80_read_channel_list(rig, 0);
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+ }
+
priv->default_offs[chan->channel_num] = 0;
if (chan->rptr_shift != RIG_RPT_SHIFT_NONE
- && prm80_read_channel_list(rig, 0) == RIG_OK
&& chan->channel_num <= priv->last_chan
&& priv->stored_shift[chan->channel_num] == 0)
{
@@ -1315,12 +1326,24 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
// TODO "Read-Modify-Write" (or shadowing in priv area) of the lock bits
int prm80_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
{
+ struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
char buf[BUFSZ];
int ret, chanstate;
if (func & RIG_FUNC_REV)
{
- // Read-Modify-Write of the state of the current channel.
+ // V5.0: [N] does not stop a running scan, so [E] may report another
+ // channel than the one [T] writes to. The read-modify-write below
+ // could then store the state of one channel in another one.
+ if (priv->fw_major == 5 && priv->fw_minor < 1)
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: setting REV needs PRM80 firmware V5.1 or newer (found V%d.%d)\n",
+ __func__, priv->fw_major, priv->fw_minor);
+ return -RIG_ENAVAIL;
+ }
+
+ // Read-Modify-Write of the state of the current channel (V5.1+).
// While the rig scans, [E] (V5.1) reports the channel being
// received, but [T] writes to the channel the scan started on. So
// the channel reported by [E] is selected first with [N], which
@@ -1367,6 +1390,9 @@ int prm80_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
{
ret = prm80_wait_for_prompt(RIGPORT(rig));
}
+
+ // the stored state of the channel may have changed
+ priv->list_valid = 0;
}
else if (func & RIG_FUNC_LOCK)
{
commit 6aa7852bd310126093869ee225123ccaadb2f847
Author: Claude <no...@an...>
Date: Fri Oct 30 11:45:30 2026 +0100
prm80: REV acts on the channel reported by [E], refuse tiny offsets
Review of #2285:
- set_func(REV): while the rig scans, [E] (firmware V5.1) reports the
channel being received, but [T] writes to the channel the scan started
on. The channel reported by [E] is now selected first with [N], which
stops a running scan and makes [T] act on that channel; then the state
is read fresh and written back. Without a scan [N] selects the current
channel again.
- set_channel: an offset that rounds to 0 PLL steps would select the
default shift of the rig, and a shift above 0xffff steps can't be
stored; such offsets are refused with -RIG_EINVAL.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
Claude-Session: https://claude.ai/code/session_01WuSe41qryLsRRQJPkzmJyd
diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c
index 2007b3ee1..a111ced57 100644
--- a/rigs/prm80/prm80.c
+++ b/rigs/prm80/prm80.c
@@ -1154,6 +1154,16 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
offs = (chan->rptr_shift != RIG_RPT_SHIFT_NONE) ? labs(chan->rptr_offs) : 0;
shift = (unsigned)(offs / FREQ_DIV + 0.5);
+ // An offset that rounds to 0 would select the default shift of the
+ // rig, and the 4 hex digits limit the shift: refuse such offsets.
+ if ((offs != 0 && shift == 0) || shift > 0xffff)
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: offset %ld Hz can't be stored (steps of %.0f Hz, 0 = default shift)\n",
+ __func__, offs, FREQ_DIV);
+ return -RIG_EINVAL;
+ }
+
// A channel that uses the default shift is reported by get_channel()
// with the effective offset. Written back with that offset, it keeps
// the default shift (0), so a later change of the default still
@@ -1310,9 +1320,27 @@ int prm80_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
if (func & RIG_FUNC_REV)
{
- // Read-Modify-Write of the state of the current channel, with a
- // fresh state (not the cache), so that the state of the channel
- // selected right now is modified
+ // Read-Modify-Write of the state of the current channel.
+ // While the rig scans, [E] (V5.1) reports the channel being
+ // received, but [T] writes to the channel the scan started on. So
+ // the channel reported by [E] is selected first with [N], which
+ // stops a running scan (V5.1) and makes [T] act on that channel.
+ // Then the state is read fresh (not from the cache).
+ prm80_force_cache_timeout(rig);
+ ret = prm80_read_system_state(rig, buf);
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+
+ ret = prm80_set_mem(rig, vfo, (int)hhtoi(buf + 2));
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+
prm80_force_cache_timeout(rig);
ret = prm80_read_system_state(rig, buf);
commit ebda7335e0b189e2b9defcec7daed84cac19315b
Author: Claude <no...@an...>
Date: Tue Oct 27 11:40:18 2026 +0100
prm80: keep the default shift on a round trip, fresh state for REV
Review of #2285:
- get_channel/set_channel: a channel that uses the default shift of the
rig (shift 0 in the channel memory) is still reported with its
effective offset, but written back with that offset it keeps the
default shift, so a later change of the default still applies to it.
get_channel reads the stored shift from the channel list [C], which is
cached for 10 s and invalidated when a channel is written or the rig
is reset. The same list gives the last channel for new channels.
- set_func(REV): the read-modify-write of the channel state uses a fresh
[E] answer instead of the cached one (up to 200 ms old), so the state
of another channel is not written to the channel selected meanwhile.
- set_func(REV) and set_channel: the result of waiting for the prompt
is returned, so a timeout after the last digits is reported as error.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
Claude-Session: https://claude.ai/code/session_01WuSe41qryLsRRQJPkzmJyd
diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c
index e17291d6b..2007b3ee1 100644
--- a/rigs/prm80/prm80.c
+++ b/rigs/prm80/prm80.c
@@ -46,6 +46,9 @@
// "E" system state is cached for this time (ms)
#define PRM80_CACHE_TIMEOUT 200
+// The channel list "C" is cached for this time (ms)
+#define PRM80_LIST_CACHE_TIMEOUT 10000
+
// Length (in bytes) of the response to the "E" command
#define CMD_E_RSP_LEN 22
@@ -154,6 +157,8 @@ MessageAide: DB "H",0Dh,0Ah
* *********************************************************************
*/
+static int prm80_read_channel_list(RIG *rig, int force);
+
static void prm80_force_cache_timeout(RIG *rig)
{
struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
@@ -434,6 +439,7 @@ int prm80_reset(RIG *rig, reset_t reset)
return retval;
}
+ ((struct prm80_priv_data *)STATE(rig)->priv)->list_valid = 0;
prm80_force_cache_timeout(rig);
return RIG_OK;
@@ -831,7 +837,7 @@ static int prm80_read_system_state(RIG *rig, char *statebuf)
*/
int prm80_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only)
{
- const struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
+ struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
char statebuf[BUFSZ];
int ret, chanstate, mode_byte, lock_byte;
@@ -914,6 +920,22 @@ int prm80_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only)
chan->split = priv->split; // RIG_SPLIT_ON; ?
}
+ // For a memory channel, remember whether it uses the default shift, so
+ // that set_channel() keeps it when the channel is written back.
+ if (chan->vfo == RIG_VFO_MEM && chan->channel_num >= CHAN_MIN
+ && chan->channel_num <= CHAN_MAX)
+ {
+ priv->default_offs[chan->channel_num] = 0;
+
+ if (chan->rptr_shift != RIG_RPT_SHIFT_NONE
+ && prm80_read_channel_list(rig, 0) == RIG_OK
+ && chan->channel_num <= priv->last_chan
+ && priv->stored_shift[chan->channel_num] == 0)
+ {
+ priv->default_offs[chan->channel_num] = chan->rptr_offs;
+ }
+ }
+
if (!read_only)
{
// Set rig to channel values
@@ -928,16 +950,28 @@ int prm80_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only)
}
/*
- * Number of the last channel, from the channel list [C]:
+ * Read the channel list [C] into the cache (unless the cache is recent
+ * and force is not set):
* "Channel Frequency Shift State" CRLF
- * "0 2D80 0030 01" CRLF ... (one line per channel) CRLF '>'
+ * "00 2D80 0030 01" CRLF ... (one line per channel) CRLF '>'
+ * The shift column is the shift stored in the channel, 0000 meaning
+ * the default shift of the rig.
*/
-static int prm80_read_last_channel(RIG *rig, int *last)
+static int prm80_read_channel_list(RIG *rig, int force)
{
+ struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
hamlib_port_t *rp = RIGPORT(rig);
char list[2048];
const char *p;
- int ret;
+ int ret, last = -1;
+
+ if (!force && priv->list_valid
+ && !rig_check_cache_timeout(&priv->list_tv, PRM80_LIST_CACHE_TIMEOUT))
+ {
+ return RIG_OK;
+ }
+
+ priv->list_valid = 0;
ret = prm80_transaction(rig, "C", NULL, 0);
@@ -955,26 +989,51 @@ static int prm80_read_last_channel(RIG *rig, int *last)
list[(ret < (int)sizeof(list)) ? ret : ((int)sizeof(list) - 1)] = '\0';
- *last = -1;
-
- // the number of the last line starting with a digit
for (p = list; *p != '\0'; p++)
{
- if ((p == list || p[-1] == '\n') && isdigit((unsigned char)*p))
+ unsigned num, pll, shift, state;
+
+ // the lines starting with a channel number
+ if ((p == list || p[-1] == '\n') && isdigit((unsigned char)*p)
+ && sscanf(p, "%u %x %x %x", &num, &pll, &shift, &state) == 4
+ && num <= CHAN_MAX)
{
- *last = atoi(p);
+ priv->stored_shift[num] = shift;
+ last = (int)num;
}
}
- if (*last < 0)
+ if (last < 0)
{
rig_debug(RIG_DEBUG_ERR, "%s: no channel in the list '%s'\n", __func__, list);
return -RIG_EPROTO;
}
+ priv->last_chan = last;
+ priv->list_valid = 1;
+ gettimeofday(&priv->list_tv, NULL);
+
return RIG_OK;
}
+/*
+ * Number of the last channel, read fresh from the channel list [C].
+ */
+static int prm80_read_last_channel(RIG *rig, int *last)
+{
+ const struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
+ int ret;
+
+ ret = prm80_read_channel_list(rig, 1);
+
+ if (ret == RIG_OK)
+ {
+ *last = priv->last_chan;
+ }
+
+ return ret;
+}
+
/*
* Program a memory channel with [P] (firmware V5).
* Example
@@ -1065,7 +1124,7 @@ static int prm80_program_channel(RIG *rig, int channel_num, unsigned pll,
return ret;
}
- prm80_wait_for_prompt(rp);
+ return prm80_wait_for_prompt(rp);
}
return RIG_OK;
@@ -1079,6 +1138,7 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
int ret, chanstate, asked, last;
unsigned shift;
+ long offs;
freq_t tx_freq, nominal;
if (chan->vfo == RIG_VFO_MEM)
@@ -1091,11 +1151,19 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
}
// Size of the shift, 0 means the default shift of the rig.
- shift = 0;
-
- if (chan->rptr_shift != RIG_RPT_SHIFT_NONE)
+ offs = (chan->rptr_shift != RIG_RPT_SHIFT_NONE) ? labs(chan->rptr_offs) : 0;
+ shift = (unsigned)(offs / FREQ_DIV + 0.5);
+
+ // A channel that uses the default shift is reported by get_channel()
+ // with the effective offset. Written back with that offset, it keeps
+ // the default shift (0), so a later change of the default still
+ // applies to it.
+ if (shift != 0 && priv->default_offs[chan->channel_num] != 0
+ && labs(offs - priv->default_offs[chan->channel_num]) < FREQ_DIV / 2)
{
- shift = (unsigned)(labs(chan->rptr_offs) / FREQ_DIV + 0.5);
+ rig_debug(RIG_DEBUG_VERBOSE, "%s: channel %d keeps the default shift\n",
+ __func__, chan->channel_num);
+ shift = 0;
}
// The channel memory holds the nominal frequency (the rig adds or
@@ -1108,12 +1176,10 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
if ((chan->funcs & RIG_FUNC_REV) && chan->rptr_shift != RIG_RPT_SHIFT_NONE)
{
- if (shift != 0)
+ if (offs != 0)
{
- freq_t offs = (freq_t)shift * FREQ_DIV;
-
nominal = (chan->rptr_shift == RIG_RPT_SHIFT_PLUS) ?
- chan->freq - offs : chan->freq + offs;
+ chan->freq - (freq_t)offs : chan->freq + (freq_t)offs;
}
else if (chan->tx_freq != 0)
{
@@ -1169,6 +1235,10 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
(unsigned)(nominal / FREQ_DIV + 0.5), shift, chanstate, 1, &asked);
}
+ // the channel memory has changed
+ priv->list_valid = 0;
+ priv->default_offs[chan->channel_num] = 0;
+
if (ret != RIG_OK)
{
return ret;
@@ -1240,7 +1310,10 @@ int prm80_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
if (func & RIG_FUNC_REV)
{
- // Read-Modify-Write of the state of the current channel
+ // Read-Modify-Write of the state of the current channel, with a
+ // fresh state (not the cache), so that the state of the channel
+ // selected right now is modified
+ prm80_force_cache_timeout(rig);
ret = prm80_read_system_state(rig, buf);
if (ret != RIG_OK)
@@ -1264,7 +1337,7 @@ int prm80_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
if (ret == RIG_OK)
{
- prm80_wait_for_prompt(RIGPORT(rig));
+ ret = prm80_wait_for_prompt(RIGPORT(rig));
}
}
else if (func & RIG_FUNC_LOCK)
diff --git a/rigs/prm80/prm80.h b/rigs/prm80/prm80.h
index d51d2f3ac..6a8b4c860 100644
--- a/rigs/prm80/prm80.h
+++ b/rigs/prm80/prm80.h
@@ -44,6 +44,12 @@ struct prm80_priv_data
char cached_statebuf[32]; /* response of last "E" command */
int fw_major; /* firmware version, read by prm80_open() */
int fw_minor;
+ /* channel list [C], cached for get_channel() */
+ int list_valid;
+ struct timeval list_tv;
+ int last_chan;
+ unsigned stored_shift[100]; /* shift in the channel memory, 0 = default shift */
+ long default_offs[100]; /* offset reported for a channel with the default shift, 0 = none */
};
int prm80_init(RIG *rig);
commit e724eae550cb6e6429608471bcf4497586d20d8a
Author: Claude <no...@an...>
Date: Tue Oct 27 10:29:57 2026 +0100
prm80: keep the nominal frequency of reversed channels, refuse gaps
Review of #2285:
- set_channel: chan->freq is the RX frequency, as get_channel() reports
it. With reverse the rig receives on the shifted frequency and
transmits on the nominal one, so the nominal frequency is now
computed back from the RX frequency and the shift (or taken from
tx_freq for the default shift). A reversed channel read and written
back is no longer moved by the shift. Reverse with the default shift
and neither rptr_offs nor tx_freq is refused.
- set_channel: the firmware appends a new channel directly after the
last one, whatever number was requested. The query for a new channel
is now refused first; the last channel is read with [C], and the
channel is only created if it is the one directly after the last
one. Otherwise -RIG_EINVAL is returned and nothing is changed.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
Claude-Session: https://claude.ai/code/session_01WuSe41qryLsRRQJPkzmJyd
diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c
index 530893e30..e17291d6b 100644
--- a/rigs/prm80/prm80.c
+++ b/rigs/prm80/prm80.c
@@ -928,77 +928,204 @@ int prm80_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only)
}
/*
- * prm80_set_channel handles RIG_VFO_MEM and RIG_VFO_CURR
+ * Number of the last channel, from the channel list [C]:
+ * "Channel Frequency Shift State" CRLF
+ * "0 2D80 0030 01" CRLF ... (one line per channel) CRLF '>'
*/
-int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
+static int prm80_read_last_channel(RIG *rig, int *last)
{
- struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
hamlib_port_t *rp = RIGPORT(rig);
- char buf[BUFSZ];
- int ret, chanstate;
- unsigned shift;
- freq_t tx_freq;
+ char list[2048];
+ const char *p;
+ int ret;
- if (chan->vfo == RIG_VFO_MEM)
+ ret = prm80_transaction(rig, "C", NULL, 0);
+
+ if (ret != RIG_OK)
{
- // setting channel without calling set_mem()
+ return ret;
+ }
- if (chan->channel_num < CHAN_MIN || chan->channel_num > CHAN_MAX)
+ ret = read_string(rp, (unsigned char *) list, sizeof(list), ">", 1, 0, 1);
+
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ list[(ret < (int)sizeof(list)) ? ret : ((int)sizeof(list) - 1)] = '\0';
+
+ *last = -1;
+
+ // the number of the last line starting with a digit
+ for (p = list; *p != '\0'; p++)
+ {
+ if ((p == list || p[-1] == '\n') && isdigit((unsigned char)*p))
{
- return -RIG_EINVAL;
+ *last = atoi(p);
}
+ }
- /* [P] = Edit/Add channel (firmware V5) */
- /* Example
- Channel to set : 00
- PLL value to load : $2D80 (145.600 MHz)
- Shift value : $0030 (600 kHz)
- Channel state : $01 (shift enabled, negative)
+ if (*last < 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: no channel in the list '%s'\n", __func__, list);
+ return -RIG_EPROTO;
+ }
- Possibly:
- "This channel number doesn't exist. Add new channel (Y/N) ? "
- */
+ return RIG_OK;
+}
- SNPRINTF(buf, sizeof(buf), "%02u", (unsigned)chan->channel_num);
+/*
+ * Program a memory channel with [P] (firmware V5).
+ * Example
+ * Channel to set : 00
+ * PLL value to load : $2D80 (145.600 MHz)
+ * Shift value : $0030 (600 kHz)
+ * Channel state : $01 (shift enabled, negative)
+ * For a channel above the last one the rig asks
+ * "This channel number doesn't exist. Add new channel (Y/N) ? "
+ * and then appends the channel directly after the last one, whatever
+ * number was requested. The query is confirmed only if add_new is set,
+ * otherwise it is refused and *asked is set.
+ */
+static int prm80_program_channel(RIG *rig, int channel_num, unsigned pll,
+ unsigned shift, int chanstate, int add_new, int *asked)
+{
+ hamlib_port_t *rp = RIGPORT(rig);
+ char buf[BUFSZ];
+ int ret;
- ret = prm80_transaction(rig, "P", buf, 0);
+ *asked = 0;
- if (ret != RIG_OK)
+ SNPRINTF(buf, sizeof(buf), "%02u", (unsigned)channel_num);
+
+ ret = prm80_transaction(rig, "P", buf, 0);
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+
+ SNPRINTF(buf, sizeof(buf), "%04X", pll & 0xffff);
+
+ // "PLL value to load : $"
+ ret = read_dollar_prompt_and_send(rp, NULL, NULL, buf);
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+
+ SNPRINTF(buf, sizeof(buf), "%04X", shift & 0xffff);
+
+ // "Shift value : $"
+ ret = read_dollar_prompt_and_send(rp, NULL, NULL, buf);
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+
+ SNPRINTF(buf, sizeof(buf), "%02X", (unsigned)chanstate);
+
+ // "Channel state : $"
+ ret = read_dollar_prompt_and_send(rp, NULL, NULL, buf);
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+
+ // The rig echoes the state, then either the prompt comes back
+ // (CRLF'>') or the query for a new channel.
+ ret = read_string(rp, (unsigned char *) buf, sizeof(buf), ">?", 2, 0, 1);
+
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ if (ret > 0 && buf[ret - 1] == '?')
+ {
+ *asked = 1;
+
+ // Read extra space
+ ret = read_block(rp, (unsigned char *) buf, 1);
+
+ if (ret < 0)
{
return ret;
}
- // The channel memory holds the nominal frequency (the rig adds or
- // subtracts the IF itself), so no IF offset here, unlike [R].
- SNPRINTF(buf, sizeof(buf), "%04X",
- (unsigned)(chan->freq / FREQ_DIV + 0.5));
+ // Answer the query; with "N" nothing is changed
+ ret = write_block(rp, (unsigned char *)(add_new ? "Y" : "N"), 1);
- // "PLL value to load : $"
- ret = read_dollar_prompt_and_send(rp, NULL, NULL, buf);
-
- if (ret != RIG_OK)
+ if (ret < 0)
{
return ret;
}
- // Shift of this channel, in PLL steps. 0 means the default shift.
- if (chan->rptr_shift == RIG_RPT_SHIFT_NONE)
+ prm80_wait_for_prompt(rp);
+ }
+
+ return RIG_OK;
+}
+
+/*
+ * prm80_set_channel handles RIG_VFO_MEM and RIG_VFO_CURR
+ */
+int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
+{
+ struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
+ int ret, chanstate, asked, last;
+ unsigned shift;
+ freq_t tx_freq, nominal;
+
+ if (chan->vfo == RIG_VFO_MEM)
+ {
+ // setting channel without calling set_mem()
+
+ if (chan->channel_num < CHAN_MIN || chan->channel_num > CHAN_MAX)
{
- shift = 0;
+ return -RIG_EINVAL;
}
- else
+
+ // Size of the shift, 0 means the default shift of the rig.
+ shift = 0;
+
+ if (chan->rptr_shift != RIG_RPT_SHIFT_NONE)
{
shift = (unsigned)(labs(chan->rptr_offs) / FREQ_DIV + 0.5);
}
- SNPRINTF(buf, sizeof(buf), "%04X", shift & 0xffff);
-
- // "Shift value : $"
- ret = read_dollar_prompt_and_send(rp, NULL, NULL, buf);
+ // The channel memory holds the nominal frequency (the rig adds or
+ // subtracts the IF itself), so no IF offset here, unlike [R].
+ // chan->freq is the RX frequency, as get_channel() reports it.
+ // In reverse mode the rig transmits on the nominal frequency and
+ // receives on the shifted one, so the nominal frequency is the RX
+ // frequency minus the shift (or the TX frequency).
+ nominal = chan->freq;
- if (ret != RIG_OK)
+ if ((chan->funcs & RIG_FUNC_REV) && chan->rptr_shift != RIG_RPT_SHIFT_NONE)
{
- return ret;
+ if (shift != 0)
+ {
+ freq_t offs = (freq_t)shift * FREQ_DIV;
+
+ nominal = (chan->rptr_shift == RIG_RPT_SHIFT_PLUS) ?
+ chan->freq - offs : chan->freq + offs;
+ }
+ else if (chan->tx_freq != 0)
+ {
+ nominal = chan->tx_freq;
+ }
+ else
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: reverse with the default shift needs rptr_offs or tx_freq\n",
+ __func__);
+ return -RIG_EINVAL;
+ }
}
// the channel status byte.
@@ -1016,45 +1143,35 @@ int prm80_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
chanstate |= (chan->funcs & RIG_FUNC_REV) ? 0x02 : 0;
chanstate |= (chan->flags & RIG_CHFLAG_SKIP) ? 0x08 : 0;
- SNPRINTF(buf, sizeof(buf), "%02X", chanstate);
-
- // "Channel state : $"
- ret = read_dollar_prompt_and_send(rp, NULL, NULL, buf);
-
- if (ret != RIG_OK)
- {
- return ret;
- }
-
- // The rig echoes the state, then either the prompt comes back
- // (CRLF'>') or the query for a new channel:
- // "This channel number doesn't exist. Add new channel (Y/N) ? "
- ret = read_string(rp, (unsigned char *) buf, sizeof(buf), ">?", 2, 0, 1);
+ ret = prm80_program_channel(rig, chan->channel_num,
+ (unsigned)(nominal / FREQ_DIV + 0.5), shift, chanstate, 0, &asked);
- if (ret < 0)
+ if (ret == RIG_OK && asked)
{
- return ret;
- }
+ // A new channel: the rig would append it after the last one,
+ // so only the channel directly after the last one is created.
+ ret = prm80_read_last_channel(rig, &last);
- if (ret > 0 && buf[ret - 1] == '?')
- {
- // Read extra space
- ret = read_block(rp, (unsigned char *) buf, 1);
-
- if (ret < 0)
+ if (ret != RIG_OK)
{
return ret;
}
- // Send confirmation
- ret = write_block(rp, (unsigned char *) "Y", 1);
-
- if (ret < 0)
+ if (chan->channel_num != last + 1)
{
- return ret;
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: channel %d can't be created, the last channel is %d (only %d can be added)\n",
+ __func__, chan->channel_num, last, last + 1);
+ return -RIG_EINVAL;
}
- prm80_wait_for_prompt(rp);
+ ret = prm80_program_channel(rig, chan->channel_num,
+ (unsigned)(nominal / FREQ_DIV + 0.5), shift, chanstate, 1, &asked);
+ }
+
+ if (ret != RIG_OK)
+ {
+ return ret;
}
}
else
commit 7f20794ea259f764bed36a0769dc43a12689847b
Author: Claude <no...@an...>
Date: Mon Oct 26 21:15:20 2026 +0100
prm80: invalidate the frequency cache when the rig changes the frequency
set_mem, set_channel, set_func(REV) and reset change the frequency of
the rig without rig_set_freq(), so rig_get_freq() returned the old
frequency from the cache of the rig layer for a while.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
Claude-Session: https://claude.ai/code/session_01WuSe41qryLsRRQJPkzmJyd
diff --git a/rigs/prm80/prm80.c b/rigs/prm80/prm80.c
index c62302071..530893e30 100644
--- a/rigs/prm80/prm80.c
+++ b/rigs/prm80/prm80.c
@@ -30,6 +30,7 @@
#include "iofunc.h"
#include "register.h"
#include "idx_builtin.h"
+#include "cache.h"
#include "prm80.h"
@@ -158,6 +159,11 @@ static void prm80_force_cache_timeout(RIG *rig)
struct prm80_priv_data *priv = (struct prm80_priv_data *)STATE(rig)->priv;
rig_force_cache_timeout(&priv->status_tv);
+
+ // A new channel, reverse or channel state changes the frequency
+ // without rig_set_freq(), so the frequency cache of the rig
+ // layer has to be invalidated too.
+ rig_set_cache_freq(rig, RIG_VFO_ALL, (freq_t)0);
}
/*
commit ef684a15e2122844c4eed8b62c50415faddc9e47
Author: Claude <no...@an...>
Date: Mon Oct 26 19:01:18 2026 +0100
prm80: fix channel programming and shift handling for firmware V5
Tested against the PRM80 firmware V5.0/V5.1 protocol (inc_ser.a51):
- rig_open: read the firmware version with [V] and refuse firmware
older than V5.0 with a clear error message. The backend already
relied on V5 ([E] answer with RSSI), so older firmware failed later
with unclear protocol errors.
- set_channel [P]: answer the "Shift value : $" prompt of V5 (shift
per channel in 12.5 kHz steps, 0 = default shift of the rig).
Before, the channel state was sent as shift value and the command
hung.
- set_channel [P]: send the nominal frequency of the channel. The rig
adds/subtracts the IF itself; the RX PLL word with IF offset is only
used by [R].
- set_channel [P]: a negative shift is state 0x01 (shift enabled,
negative), not 0x03 which also set the reverse bit. Reverse is now
taken from RIG_FUNC_REV of the channel.
- set_channel [P]: the rig echoes the state digits, so the query for a
new channel ("Add new channel (Y/N) ?") was never detected. Now read
up to '>' or '?'.
- get_channel: decode the shift direction from b2 (b1 is reverse), so
a negative shift is no longer reported as none; rptr_offs is the
size of the shift.
- set_func RIG_FUNC_REV implemented with [T] (decimal state).
- pysimulprm80.py: simulate V5.1 with echo, shift prompt and a channel
m...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-11-03 18:45:56
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 67e01fff9d4a710b92bea1f588e48efe0d558f27 (commit)
via 316d514a57ccdf58d0677ba746b1eb922fa00a65 (commit)
via e859e24535c02e9d93443b9d41f4fad7fd3573eb (commit)
via 986585b1ad48d6caabe9e0df35100290c3a7a125 (commit)
via d56e548244c2ad409de718fa62f6543c521fca75 (commit)
via 1a3dcc2e68117001ca72006cebb719eb84c363ed (commit)
via 61292110953ca0c9d75677e74636ccf13397c040 (commit)
via ea260ab4cb29ff1b8fd503cd599238338834dd0c (commit)
via eb4f48f0f905f50d47e082cca543cd7a8f1f6b74 (commit)
via 7c58b74f00c792feedee5c2afce27f54310543f3 (commit)
via d91126247014608c75e7f61a388b042fa674337e (commit)
via cf3ed3f78fdaf5d6753b5b473c9943614e982f1c (commit)
via c2f2a49bdc691a91b5917bd35ee04a0778bdf295 (commit)
via ef0114cd9762087e4f27a2f6a916f67d63e09dcd (commit)
via 3150a922f12d0b1275258cd104a8b4fd038c8ca3 (commit)
via 8b35f3581c710fe7ce35211730cbd28d2f36c5c4 (commit)
via e5d05445622c0c05ee9afe383082be8e46b6ae01 (commit)
via 48c24e26b815b14fc7407292794df5a8bd5bc5b0 (commit)
via 04f897d405f00ee8a3c18cbe2d10f50e78dd8b94 (commit)
via 419711954c8213b768c110f16aa28fe83fdced89 (commit)
via 8ebb942321085d16816258b8bead5b2ed4e65297 (commit)
via d155e64d21c4cb578eabe9813cec4db5821068c6 (commit)
via d22bf90f5c1dc78c4062470efe47343e963f9755 (commit)
via 0c3ba5a35192482b419eb1868853b524e686bd8d (commit)
via dae8f61d8abdff06615fa977c7bea8e49fd001fd (commit)
via 471816e3e8bebedc7153a845928daec679490ec3 (commit)
via a2e053f82660f96004c6b6f623bb5671662fa9e8 (commit)
via 9e6f90b676a774bea7de4b9bcb396f8e32034cbe (commit)
via 4d40ba494669e849cea70763e1c02f3d8c7180bb (commit)
via 203532a95aaad2823fd86ac14871be195cd73f3f (commit)
via eceecc76f0cbee6fe46e9bca635a64e0e7eebf71 (commit)
via 0e3c8d9c38d6f0b41f49b47746326c4424fd3290 (commit)
via 43107cd6d499eec7ec1beb1086221bc3f3ae327c (commit)
via 720268fa63c0aab318897c30f9bc9c6bda5bc0e8 (commit)
via e0baf95110e1efe58e984112f5d86d2157862912 (commit)
via f27ddc813ddd327d7833b08331be7f6278e514a2 (commit)
via c2c6053bdf72eafe93528cfa361df9f4842b3bd3 (commit)
via c7cd431662224284c31e4636dfa0ea24f8db152b (commit)
via 21f27ea9e7f138fe9f4e431cf73b9ea22ef194fa (commit)
via fd17a556af367175eb1aa77f6cfe2220886cbe0f (commit)
via bba61a91be9296a5a94438e57bf8d2d611cc678d (commit)
via 45390a11a5e0e0616db3b578ab030318ec131dd4 (commit)
via 0b58218ad7548f0d14e1f5de191cc69e06fd25f4 (commit)
via 124609142db23c2d57a8494368a3dec81c06315d (commit)
via 5fb1ef9f9481e2ddba0a0a3cb8ba63271c1470ee (commit)
via 93b9061951517be5779121b4992c3c97a996b741 (commit)
via 919954b6f12374924950afbdf6bd9bb680f7f976 (commit)
via 43e9901582ad095d8486996b1ace1b27a0a3112e (commit)
via 797e14ec543c1740b06f9f6cb9a0937084520633 (commit)
via e39155d448bb9f742a42ab5fcb73568b75bad65b (commit)
via 4faec05e2bfea38d97f29ff04d364cdc69da9868 (commit)
via 107deadf8d2dd08570f58502882cc40c53e8f334 (commit)
via e7a08061ac6245f64894da91bb87b984f55f6cc6 (commit)
via 0b28a905907f764b8ef2192ddd1334c80a5f7963 (commit)
via 45d56a18457b63ff557c46c2a8de0c204ef923cd (commit)
via e10f4e92f3f7888151edc3313a3a3a9be4fe5115 (commit)
via 4a6c5fe453b4fd9bb802fe226b0f6df2a0c031ed (commit)
via 2bd15cd2550addbd5eecf8a1e8d39100a0cee6ab (commit)
via d7818b9f255e49dbeea086b7a5c2bfbadb5f1536 (commit)
via 73cc80ddae41bb58fd5348fa08d1b690c4709403 (commit)
via c64c8bc324bffc57ac730ffa1649a37cb072dbf4 (commit)
via 037c6ae2996808ce8a64b103f0369ae4fb47d70d (commit)
via 423bef8746f6de5f305c4b76210699aa02bd1f4f (commit)
via 2b184e6e3990b0ed539bce5c7e9ca0232a64e062 (commit)
via 73981d5101f571f7ee01461e7987a5ea6fce82f8 (commit)
via b5118f0d41894ad191296c9ee220a42ff59067b3 (commit)
via e31517e8a129c1b707bee67c861019f85e7f94c7 (commit)
via 74699267136311d47e9f381d61c51101c1fd8575 (commit)
via 19287a1fc517c5f33a99a2d665201be17961443b (commit)
via d15fba9cd7555da72f19dc0fc062c69439d58400 (commit)
via 700cdd1a42d7bdd814516a2156ffbe09350efa41 (commit)
via f3d4e6a3b90000e11415802b9edf1af080274e50 (commit)
from 94d984e72a9fef7b1d3a46fabf13987106278bad (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 67e01fff9d4a710b92bea1f588e48efe0d558f27
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Tue Nov 3 09:15:47 2026 +0100
fix(rigctld): close an unsubscribed stream in 100 ms, not 1 s
Before a client subscribes, the receive thread of a unicast stream
waits for SUBSCRIBE in select() with a 1 s timeout and checks between
waits whether the stream was closed. \stream_close, a client's
disconnect and rigctld's exit wait for that thread to end, so closing
a stream nobody had subscribed to took up to 1 s.
The timeout only sets how soon the thread notices the close: select()
returns as soon as a packet arrives, and the subscribe deadline is
checked against its own clock. Use 100 ms, as the transmit thread in
the same file does.
test_rigctld_commands closes such streams in many of its tests; on
macOS it now runs in 99 s instead of 148 s, and make -j14 check in
118 s instead of 167 s. Subscribed and multicast streams and the radio
backends are not affected.
diff --git a/tests/rigctld_stream.c b/tests/rigctld_stream.c
index ad1f83851..0cb27b819 100644
--- a/tests/rigctld_stream.c
+++ b/tests/rigctld_stream.c
@@ -993,8 +993,9 @@ static int wait_for_subscribe(struct rigctld_stream *stream)
FD_ZERO(&fds);
FD_SET(stream->udp_sock, &fds);
- tv.tv_sec = 1;
- tv.tv_usec = 0;
+ /* Closing the stream waits until this loop sees running == 0. */
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000;
int ready = select(stream->udp_sock + 1, &fds, NULL, NULL, &tv);
commit 316d514a57ccdf58d0677ba746b1eb922fa00a65
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Tue Nov 3 09:54:42 2026 +0100
fix(rig): skip the settling wait in rig_open() when there is no rig port
rig_open() waits 100 ms after opening the ports "to give some serial
ports time" (ece6a7ae1, "allow serial port settling"). It also waits
for RIG_PORT_NONE, for which port_open() opens nothing: the dummy rig,
and the WiNRADiO, DWT, Elektor 507 (without libusb) and USRP backends,
which open their device afterwards in their own rig_open().
Skip the wait for RIG_PORT_NONE. Serial, network, USB and all other
port types wait as before; traced on a pty, on netrigctl and on an
IC-7760's USB serial port.
Opening the dummy rig takes 100 ms less: `rigctl -m 1 f` runs in
0.36 s instead of 0.44 s, and test_rigctld_commands, which opens it in
each of its 115 subtests, in 134 s instead of 144-148 s (macOS).
diff --git a/src/rig.c b/src/rig.c
index 1142fd1bd..d6f68c383 100644
--- a/src/rig.c
+++ b/src/rig.c
@@ -1563,8 +1563,12 @@ int HAMLIB_API rig_open(RIG *rig)
rig_debug(RIG_DEBUG_VERBOSE, "%s: %p rs->comm_state==1?=%d\n", __func__,
&rs->comm_state,
rs->comm_state);
- hl_usleep(100 *
- 1000); // wait a bit after opening to give some serial ports time
+ // The wait is for the rig port, which port_open() does not open for RIG_PORT_NONE
+ if (rp->type.rig != RIG_PORT_NONE)
+ {
+ hl_usleep(100 *
+ 1000); // wait a bit after opening to give some serial ports time
+ }
/*
commit e859e24535c02e9d93443b9d41f4fad7fd3573eb
Author: David Christle <dch...@us...>
Date: Tue Nov 3 00:16:11 2026 -0800
test(icom): expect the liveness probe after a refused VFO query
The IC-9700 scope test expects only 07 D2 after a refused band query.
The shared Icom backend now follows a refusal with a frequency query
to distinguish standby from an unsupported command.
Assert 07 D2 followed by 03 for the refusal case, while retaining the
single-query expectation for a timeout. Both cases must preserve the
expected error and send no spectrum command to an unresolved receiver.
diff --git a/tests/testic9700civ.c b/tests/testic9700civ.c
index 018ad6e2b..a327165b8 100644
--- a/tests/testic9700civ.c
+++ b/tests/testic9700civ.c
@@ -133,6 +133,7 @@ int main(void)
size_t set_mark[4], read_mark[4];
static const unsigned char select_vfo_b[] = { 0x07, 0x01 };
static const unsigned char read_band[] = { 0x07, 0xd2 };
+ static const unsigned char read_frequency[] = { 0x03 };
size_t vfo_b_mark, split_set_mark, split_read_mark;
size_t sub_split_set_mark, sub_split_read_mark;
static const struct
@@ -336,27 +337,36 @@ int main(void)
for (i = 0; i < 2; i++)
{
+ size_t expected_frames = lookups[i].reply == BAND_REFUSE ? 2 : 1;
+ const char *sequence = expected_frames == 2 ? "07 D2, 03" : "07 D2";
+
if (lookup_set_ret[i] != lookups[i].error
- || lookup_read_mark[i] != lookup_set_mark[i] + 1
- || !frame_is(&test, lookup_set_mark[i], read_band, sizeof(read_band)))
+ || lookup_read_mark[i] != lookup_set_mark[i] + expected_frames
+ || !frame_is(&test, lookup_set_mark[i], read_band, sizeof(read_band))
+ || (expected_frames == 2
+ && !frame_is(&test, lookup_set_mark[i] + 1,
+ read_frequency, sizeof(read_frequency))))
{
fprintf(stderr, "set_level SPECTRUM_SPAN CURR with VFOB on Sub and"
- " 07 D2 %s returned %d after %d frames, not %d after 07 D2"
- " alone\n", lookups[i].name, lookup_set_ret[i],
+ " 07 D2 %s returned %d after %d frames, expected %d after"
+ " %s\n", lookups[i].name, lookup_set_ret[i],
(int)(lookup_read_mark[i] - lookup_set_mark[i]),
- lookups[i].error);
+ lookups[i].error, sequence);
failed = 1;
}
if (lookup_read_ret[i] != lookups[i].error
- || lookup_end_mark[i] != lookup_read_mark[i] + 1
- || !frame_is(&test, lookup_read_mark[i], read_band, sizeof(read_band)))
+ || lookup_end_mark[i] != lookup_read_mark[i] + expected_frames
+ || !frame_is(&test, lookup_read_mark[i], read_band, sizeof(read_band))
+ || (expected_frames == 2
+ && !frame_is(&test, lookup_read_mark[i] + 1,
+ read_frequency, sizeof(read_frequency))))
{
fprintf(stderr, "get_level SPECTRUM_SPAN CURR with VFOB on Sub and"
- " 07 D2 %s returned %d after %d frames, not %d after 07 D2"
- " alone\n", lookups[i].name, lookup_read_ret[i],
+ " 07 D2 %s returned %d after %d frames, expected %d after"
+ " %s\n", lookups[i].name, lookup_read_ret[i],
(int)(lookup_end_mark[i] - lookup_read_mark[i]),
- lookups[i].error);
+ lookups[i].error, sequence);
failed = 1;
}
}
commit 986585b1ad48d6caabe9e0df35100290c3a7a125
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sun Sep 20 20:55:01 2026 +0200
test(ic7760): send the scope span for CURR and TX to their receiver
"fix(icom): send scope settings for CURR to the selected receiver" and
"fix(icom): send scope settings for TX to the receiver selected for it"
made icom_get_spectrum_vfo() follow the receiver. The IC-7760 frame
test now checks it on this model: set and get of SPECTRUM_SPAN for CURR
go out as 27 15 00 with Main selected and 27 15 01 with Sub selected,
and setting it for TX with Main selected goes out as 07 D1, 27 15 01,
07 D0.
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index 1d0c470c7..3f1d01e26 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -30,7 +30,7 @@
#include "misc.h"
#include "testicomsock.h"
-#define MAX_RECORDED_FRAMES 32
+#define MAX_RECORDED_FRAMES 64
#define MAX_FRAME_LEN 32
struct peer_case
@@ -42,9 +42,12 @@ struct peer_case
atomic_size_t frame_count;
/* which band 07 D2 answers with, or -1 to reject it like the rest */
atomic_int band_sel_answer;
+ /* nonzero: accept 07 D0 and 07 D1, the Main and Sub selection */
+ atomic_int ack_band_select;
};
static const unsigned char nak[] = { 0xfe, 0xfe, 0xe0, 0xb2, 0xfa, 0xfd };
+static const unsigned char ack[] = { 0xfe, 0xfe, 0xe0, 0xb2, 0xfb, 0xfd };
/*
* Records the command byte of every frame and rejects it, so the backend
@@ -83,6 +86,14 @@ static void *run_peer(void *arg)
continue;
}
+ if (length == 7 && frame[4] == 0x07
+ && (frame[5] == 0xd0 || frame[5] == 0xd1) && test->ack_band_select)
+ {
+ if (write_all(test->fd, ack, sizeof(ack)) != 0) { break; }
+
+ continue;
+ }
+
if (write_all(test->fd, nak, sizeof(nak)) != 0) { break; }
}
@@ -165,7 +176,7 @@ int main(void)
pthread_t thread;
struct peer_case test =
{
- .fd = -1, .frame_count = 0, .band_sel_answer = -1
+ .fd = -1, .frame_count = 0, .band_sel_answer = -1, .ack_band_select = 0
};
unsigned char oversized_reply[MAXFRAMELEN];
size_t oversized_reply_len = 0;
@@ -184,9 +195,22 @@ int main(void)
static const unsigned char read_band_sel[] = { 0x07, 0xd2 };
static const unsigned char read_ovf[] = { 0x15, 0x07 };
static const unsigned char ip_plus_on[] = { 0x16, 0x65, 0x01 };
+ /* 27 15 <scope> <span/2 in BCD>: 50 kHz goes on the wire as 25 kHz */
+ static const unsigned char span_main_set[] =
+ { 0x27, 0x15, 0x00, 0x00, 0x50, 0x02, 0x00, 0x00 };
+ static const unsigned char span_sub_set[] =
+ { 0x27, 0x15, 0x01, 0x00, 0x50, 0x02, 0x00, 0x00 };
+ static const unsigned char span_main_read[] = { 0x27, 0x15, 0x00 };
+ static const unsigned char span_sub_read[] = { 0x27, 0x15, 0x01 };
powerstat_t status = RIG_POWER_OFF;
size_t main_freq_mark, sub_freq_mark, main_mode_mark, sub_mode_mark;
size_t band_sel_mark, ovf_mark, ip_plus_mark;
+ size_t span_main_set_mark, span_sub_set_mark;
+ size_t span_main_read_mark, span_sub_read_mark;
+ size_t span_tx_mark;
+ static const unsigned char select_main[] = { 0x07, 0xd0 };
+ static const unsigned char select_sub[] = { 0x07, 0xd1 };
+ value_t span;
vfo_t selected_main = RIG_VFO_NONE, selected_sub = RIG_VFO_NONE;
vfo_t selected_after_refusal = RIG_VFO_NONE;
int main_sel_retval, sub_sel_retval;
@@ -323,6 +347,36 @@ int main(void)
ip_plus_retval = rig_set_ext_func(rig, RIG_VFO_CURR,
rig_ext_token_lookup(rig, "IPP"), 1);
+ /*
+ * The scope commands name their scope outright, 00 for Main and 01
+ * for Sub, so RIG_VFO_CURR has to follow the selected band rather
+ * than always landing on Main.
+ */
+ span.i = 50000;
+ rig_set_current_vfo_state(rig, RIG_VFO_MAIN);
+ span_main_set_mark = test.frame_count;
+ rig_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_SPECTRUM_SPAN, span);
+ span_main_read_mark = test.frame_count;
+ rig_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_SPECTRUM_SPAN, &span);
+ rig_set_current_vfo_state(rig, RIG_VFO_SUB);
+ span_sub_set_mark = test.frame_count;
+ span.i = 50000;
+ rig_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_SPECTRUM_SPAN, span);
+ span_sub_read_mark = test.frame_count;
+ rig_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_SPECTRUM_SPAN, &span);
+
+ /*
+ * For RIG_VFO_TX rig_set_level() selects the receiver icom_set_vfo()
+ * picks for TX, Sub on this rig, and passes RIG_VFO_TX on: the scope
+ * byte has to name that same receiver.
+ */
+ test.ack_band_select = 1;
+ rig_set_current_vfo_state(rig, RIG_VFO_MAIN);
+ span.i = 50000;
+ span_tx_mark = test.frame_count;
+ rig_set_level(rig, RIG_VFO_TX, RIG_LEVEL_SPECTRUM_SPAN, span);
+ test.ack_band_select = 0;
+
/*
* A rig that refuses 07 D2 must cost this handle its get_vfo and no
* one else's. rig_caps is one static per model, shared by every rig
@@ -456,6 +510,44 @@ int main(void)
failed = 1;
}
+ /* 27 15 carries the scope as its first data byte: 00 Main, 01 Sub. */
+ if (!frame_is(&test, span_main_set_mark, span_main_set, sizeof(span_main_set)))
+ {
+ fprintf(stderr, "set_level SPECTRUM_SPAN CURR did not send 27 15 00"
+ " with Main selected\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, span_main_read_mark, span_main_read, sizeof(span_main_read)))
+ {
+ fprintf(stderr, "get_level SPECTRUM_SPAN CURR did not send 27 15 00"
+ " with Main selected\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, span_sub_set_mark, span_sub_set, sizeof(span_sub_set)))
+ {
+ fprintf(stderr, "set_level SPECTRUM_SPAN CURR did not send 27 15 01"
+ " with Sub selected\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, span_sub_read_mark, span_sub_read, sizeof(span_sub_read)))
+ {
+ fprintf(stderr, "get_level SPECTRUM_SPAN CURR did not send 27 15 01"
+ " with Sub selected\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, span_tx_mark, select_sub, sizeof(select_sub))
+ || !frame_is(&test, span_tx_mark + 1, span_sub_set, sizeof(span_sub_set))
+ || !frame_is(&test, span_tx_mark + 2, select_main, sizeof(select_main)))
+ {
+ fprintf(stderr, "set_level SPECTRUM_SPAN TX with Main selected did not"
+ " send 07 D1, 27 15 01, 07 D0\n");
+ failed = 1;
+ }
+
/*
* Without get_vfo wired up the backend cannot follow the front
* panel, and dumpcaps reports the rig cannot read its VFO at all.
commit d56e548244c2ad409de718fa62f6543c521fca75
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sun Sep 20 20:55:01 2026 +0200
test(ic7760): keep the shared caps intact after a refused 07 D2
"fix(rig): stop a refused get_vfo from erasing it for the whole model"
(#2289) stopped rig_get_vfo() from writing NULL into the model's
rig_caps when a rig refuses the read. The IC-7760 frame test now
covers it for this model: after the fake rig refuses 07 D2,
ic7760_caps must still carry get_vfo, and by the end of the run no
field of the shared caps may differ from a copy taken at the start.
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index c21f4bcc1..1d0c470c7 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -188,7 +188,9 @@ int main(void)
size_t main_freq_mark, sub_freq_mark, main_mode_mark, sub_mode_mark;
size_t band_sel_mark, ovf_mark, ip_plus_mark;
vfo_t selected_main = RIG_VFO_NONE, selected_sub = RIG_VFO_NONE;
+ vfo_t selected_after_refusal = RIG_VFO_NONE;
int main_sel_retval, sub_sel_retval;
+ int get_vfo_survived;
int ovf_retval, ip_plus_retval;
int ovf_status = 0;
rmode_t mode;
@@ -200,6 +202,8 @@ int main(void)
RIG *rig;
int parm_retval;
int failed = 0;
+ /* rig_caps is documented read-only; hold a copy to prove it stayed so */
+ static struct rig_caps caps_snapshot;
#ifdef _WIN32
WSADATA wsa_data;
@@ -212,6 +216,8 @@ int main(void)
#endif
+ memcpy(&caps_snapshot, &ic7760_caps, sizeof(caps_snapshot));
+
rig_register(&ic7760_caps);
rig = rig_init(RIG_MODEL_IC7760);
@@ -317,8 +323,24 @@ int main(void)
ip_plus_retval = rig_set_ext_func(rig, RIG_VFO_CURR,
rig_ext_token_lookup(rig, "IPP"), 1);
+ /*
+ * A rig that refuses 07 D2 must cost this handle its get_vfo and no
+ * one else's. rig_caps is one static per model, shared by every rig
+ * opened from it, so anything written there outlives this handle.
+ */
+ test.band_sel_answer = -1;
+ rig_get_vfo(rig, &selected_after_refusal);
+ get_vfo_survived = ic7760_caps.get_vfo != NULL;
+
stop_test_peer(sockets, thread);
+ if (!get_vfo_survived)
+ {
+ fprintf(stderr, "one refused 07 D2 cleared get_vfo in ic7760_caps,"
+ " which every IC-7760 in the process shares\n");
+ failed = 1;
+ }
+
if (!oversized_answered)
{
fprintf(stderr, "a frame of %d bytes stopped the peer, so nothing after"
@@ -493,6 +515,17 @@ int main(void)
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
+ /*
+ * Wider than the get_vfo case above: no field of the shared caps may
+ * change, whatever this test made the library do.
+ */
+ if (memcmp(&caps_snapshot, &ic7760_caps, sizeof(caps_snapshot)) != 0)
+ {
+ fprintf(stderr, "ic7760_caps changed while the test ran, but the"
+ " model's caps are shared by every handle in the process\n");
+ failed = 1;
+ }
+
#ifdef _WIN32
WSACleanup();
#endif
commit 1a3dcc2e68117001ca72006cebb719eb84c363ed
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 04:16:41 2026 +0200
test(icom): keep the fake rig reading frames it can be sent
The peer in the socket tests reads a command into a fixed buffer, and
read_frame() gives up once that buffer is full: the peer thread ends,
nothing answers the socket, and every later command in the test times
out. The buffers were 64 bytes while hamlib builds Icom frames of up
to MAXFRAMELEN, so a long enough command would have taken the whole
test down with a symptom that looks like a dozen unrelated failures.
The buffers are sized by MAXFRAMELEN with the tests that introduced
them. This adds the case that pins it: a full length frame sent before
anything else, and the peer's answer read back.
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index 38921e09b..c21f4bcc1 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -135,11 +135,41 @@ static int frame_is(const struct peer_case *test, size_t index,
&& memcmp(&test->frames[index][4], payload, len) == 0;
}
+/*
+ * Hamlib builds Icom frames of up to MAXFRAMELEN bytes, so the peer has
+ * to be able to read one that long. read_frame() gives up once its
+ * buffer is full, which ends the peer thread and leaves every command
+ * after it unanswered.
+ */
+static int send_oversized_frame(int fd)
+{
+ unsigned char frame[MAXFRAMELEN];
+ size_t i;
+
+ frame[0] = 0xfe;
+ frame[1] = 0xfe;
+ frame[2] = 0xb2;
+ frame[3] = 0xe0;
+ frame[4] = 0x17; /* send CW message */
+
+ for (i = 5; i < sizeof(frame) - 1; i++) { frame[i] = 0x20; }
+
+ frame[sizeof(frame) - 1] = 0xfd;
+
+ return write_all(fd, frame, sizeof(frame));
+}
+
int main(void)
{
int sockets[2];
pthread_t thread;
- struct peer_case test = { .fd = -1, .frame_count = 0, .band_sel_answer = -1 };
+ struct peer_case test =
+ {
+ .fd = -1, .frame_count = 0, .band_sel_answer = -1
+ };
+ unsigned char oversized_reply[MAXFRAMELEN];
+ size_t oversized_reply_len = 0;
+ int oversized_answered;
struct icom_priv_data *priv;
static const unsigned char backlight_full[] = { 0x14, 0x19, 0x02, 0x55 };
static const unsigned char dual_watch_on[] = { 0x07, 0xc1 };
@@ -226,6 +256,17 @@ int main(void)
STATE(rig)->comm_state = 1;
rig_set_current_vfo_state(rig, RIG_VFO_MAIN);
+ /*
+ * Before anything else, so that a peer which survived leaves the
+ * socket empty for the exchanges that follow.
+ */
+ send_oversized_frame(sockets[0]);
+ set_read_timeout(sockets[0], 1000);
+ oversized_answered = read_frame(sockets[0], oversized_reply,
+ sizeof(oversized_reply),
+ &oversized_reply_len) == 0;
+ set_read_timeout(sockets[0], 0);
+
rig_get_powerstat(rig, &status);
backlight.f = 1.0f;
@@ -278,6 +319,13 @@ int main(void)
stop_test_peer(sockets, thread);
+ if (!oversized_answered)
+ {
+ fprintf(stderr, "a frame of %d bytes stopped the peer, so nothing after"
+ " it was answered\n", MAXFRAMELEN);
+ failed = 1;
+ }
+
/*
* The command table defines 18 00 and 18 01 to switch the transceiver
* off and on; there is no form of 18 that reads the power state.
diff --git a/tests/testicomsock.c b/tests/testicomsock.c
index da32eb784..f4b41dbca 100644
--- a/tests/testicomsock.c
+++ b/tests/testicomsock.c
@@ -46,6 +46,22 @@ int write_test_socket(int fd, const void *buffer, size_t length)
#endif
}
+void set_read_timeout(int fd, int ms)
+{
+#ifdef _WIN32
+ DWORD timeout = (DWORD) ms;
+
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char *) &timeout,
+ sizeof(timeout));
+#else
+ struct timeval timeout;
+
+ timeout.tv_sec = ms / 1000;
+ timeout.tv_usec = (ms % 1000) * 1000;
+ setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
+#endif
+}
+
int open_test_connection(int sockets[2])
{
#ifdef _WIN32
diff --git a/tests/testicomsock.h b/tests/testicomsock.h
index 69df45e14..b1ce02567 100644
--- a/tests/testicomsock.h
+++ b/tests/testicomsock.h
@@ -32,6 +32,7 @@
int close_test_socket(int fd);
int read_test_socket(int fd, void *buffer, size_t length);
int write_test_socket(int fd, const void *buffer, size_t length);
+void set_read_timeout(int fd, int ms);
int open_test_connection(int sockets[2]);
/* Stops the fake rig reading sockets[1]: closing the backend's end,
commit 61292110953ca0c9d75677e74636ccf13397c040
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 04:02:27 2026 +0200
feat(ic7760): expose the OVF indicator and three more switches
The shared Icom code already speaks 15 07 for the OVF indicator and
16 65, 16 66 and 16 67 for IP Plus, TX Inhibit and DPD, and the rig
documents all four, but none of them were advertised, so no client
could reach them.
OVF is read only, there being no command to set it, so it goes in
has_get_func alone. ICPW2 is left out: the address the IC-7610 uses
for it, 1A 05 03 10, is the Count Up Trigger on this rig.
Tested on an IC-7760: all four read back, and IP Plus switched off and
on again.
diff --git a/rigs/icom/ic7760.c b/rigs/icom/ic7760.c
index a7f553134..98bf07044 100644
--- a/rigs/icom/ic7760.c
+++ b/rigs/icom/ic7760.c
@@ -115,7 +115,8 @@ static int ic7760_ext_tokens[] =
{
TOK_DRIVE_GAIN, TOK_DIGI_SEL_FUNC, TOK_DIGI_SEL_LEVEL,
TOK_SCOPE_MSS, TOK_SCOPE_SDS, TOK_SCOPE_STX, TOK_SCOPE_CFQ,
- TOK_SCOPE_EDG, TOK_SCOPE_VBW, TOK_SCOPE_RBW, TOK_BACKEND_NONE
+ TOK_SCOPE_EDG, TOK_SCOPE_VBW, TOK_SCOPE_RBW,
+ TOK_IPP_FUNC, TOK_TX_INHIBIT_FUNC, TOK_DPP_FUNC, TOK_BACKEND_NONE
};
static const struct icom_clock_cmds ic7760_clock_cmds =
@@ -260,7 +261,7 @@ struct rig_caps ic7760_caps =
.post_write_delay = 0,
.timeout = 1000,
.retry = 3,
- .has_get_func = IC7760_FUNCS,
+ .has_get_func = IC7760_FUNCS | RIG_FUNC_OVF_STATUS,
.has_set_func = IC7760_FUNCS,
.has_get_level = IC7760_LEVELS,
.has_set_level = RIG_LEVEL_SET(IC7760_LEVELS),
diff --git a/tests/testic7760caps.c b/tests/testic7760caps.c
index 2ca69b077..e26e72c35 100644
--- a/tests/testic7760caps.c
+++ b/tests/testic7760caps.c
@@ -882,6 +882,30 @@ static int match_name(RIG *rig, const struct confparams *cfp, rig_ptr_t data)
* rig has but the backend does not drive, so it has to stay filtered
* out - that is what keeps the whitelist honest.
*/
+/*
+ * The OVF indicator is read with 15 07. icom_set_func() has no case for
+ * it, so advertising it as settable would only ever answer EINVAL.
+ */
+static int test_overflow_status_is_read_only(void)
+{
+ int fail = 0;
+
+ if ((ic7760_caps.has_get_func & RIG_FUNC_OVF_STATUS) == 0)
+ {
+ fprintf(stderr, "OVF status (15 07) is readable but not advertised\n");
+ fail = 1;
+ }
+
+ if ((ic7760_caps.has_set_func & RIG_FUNC_OVF_STATUS) != 0)
+ {
+ fprintf(stderr, "OVF status is advertised as settable, but the rig has"
+ " no command to set it\n");
+ fail = 1;
+ }
+
+ return fail;
+}
+
/*
* 07 D2 reads which of Main and Sub is selected, so the backend can
* follow the front panel instead of trusting its own last set_vfo.
@@ -911,7 +935,11 @@ static int test_ext_tokens_are_enumerable(RIG *rig)
{ "digi_sel_level", 0, 1 },
{ "digi_sel", 1, 1 },
{ "SPECTRUM_SELECT", 0, 1 },
- { "TX_INHIBIT", 1, 0 },
+ { "IPP", 1, 1 },
+ { "TX_INHIBIT", 1, 1 },
+ { "DPP", 1, 1 },
+ /* 1A 05 03 10 is the Count Up Trigger on this rig, not PW2 */
+ { "ICPW2", 1, 0 },
};
size_t i;
int fail = 0;
@@ -974,6 +1002,7 @@ int main(void)
fail |= test_agc_levels();
fail |= test_spectrum_scope();
fail |= test_band_selection_is_readable();
+ fail |= test_overflow_status_is_read_only();
rig_register(&ic7760_caps);
rig = rig_init(RIG_MODEL_IC7760);
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index 3a48a4331..38921e09b 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -152,11 +152,15 @@ int main(void)
static const unsigned char read_main_mode[] = { 0x26, 0x00 };
static const unsigned char read_sub_mode[] = { 0x26, 0x01 };
static const unsigned char read_band_sel[] = { 0x07, 0xd2 };
+ static const unsigned char read_ovf[] = { 0x15, 0x07 };
+ static const unsigned char ip_plus_on[] = { 0x16, 0x65, 0x01 };
powerstat_t status = RIG_POWER_OFF;
size_t main_freq_mark, sub_freq_mark, main_mode_mark, sub_mode_mark;
- size_t band_sel_mark;
+ size_t band_sel_mark, ovf_mark, ip_plus_mark;
vfo_t selected_main = RIG_VFO_NONE, selected_sub = RIG_VFO_NONE;
int main_sel_retval, sub_sel_retval;
+ int ovf_retval, ip_plus_retval;
+ int ovf_status = 0;
rmode_t mode;
pbwidth_t width;
freq_t freq;
@@ -261,6 +265,17 @@ int main(void)
test.band_sel_answer = 0x01;
sub_sel_retval = rig_get_vfo(rig, &selected_sub);
+ /*
+ * The OVF indicator is read with 15 07, and IP Plus is switched with
+ * 16 65. Both are implemented by the shared Icom code, so all the
+ * rig has to do is advertise them.
+ */
+ ovf_mark = test.frame_count;
+ ovf_retval = rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_OVF_STATUS, &ovf_status);
+ ip_plus_mark = test.frame_count;
+ ip_plus_retval = rig_set_ext_func(rig, RIG_VFO_CURR,
+ rig_ext_token_lookup(rig, "IPP"), 1);
+
stop_test_peer(sockets, thread);
/*
@@ -402,6 +417,30 @@ int main(void)
failed = 1;
}
+ if (ovf_retval == -RIG_ENAVAIL)
+ {
+ fprintf(stderr, "get_func OVF_STATUS was rejected by the backend\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, ovf_mark, read_ovf, sizeof(read_ovf)))
+ {
+ fprintf(stderr, "get_func OVF_STATUS did not send 15 07\n");
+ failed = 1;
+ }
+
+ if (ip_plus_retval == -RIG_EINVAL)
+ {
+ fprintf(stderr, "set_ext_func IPP was rejected by the backend\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, ip_plus_mark, ip_plus_on, sizeof(ip_plus_on)))
+ {
+ fprintf(stderr, "set_ext_func IPP did not send 16 65 01\n");
+ failed = 1;
+ }
+
STATE(rig)->comm_state = 0;
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
commit ea260ab4cb29ff1b8fd503cd599238338834dd0c
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 03:55:54 2026 +0200
fix(ic7760): read back which of Main and Sub is selected
The rig reports its selected band with 07 D2 and icom_get_vfo() sends
that command, but get_vfo was left commented out. Hamlib could not
follow a change made at the front panel, and reported that the rig
cannot read its VFO at all.
get_vfo is left out for rigs that have A/B inside Main and Sub, which
07 D2 cannot describe. The IC-7760 has no A/B, so it now wires it the
way the IC-7600, IC-7610, IC-7800 and IC-785x do.
Tested on an IC-7760: 07 D2 answers 00 with Main selected and 01 with
Sub selected.
diff --git a/rigs/icom/ic7760.c b/rigs/icom/ic7760.c
index 0cd750f70..a7f553134 100644
--- a/rigs/icom/ic7760.c
+++ b/rigs/icom/ic7760.c
@@ -422,7 +422,7 @@ struct rig_caps ic7760_caps =
.set_mode = icom_set_mode,
.get_mode = icom_get_mode,
.set_vfo = icom_set_vfo,
-// .get_vfo = icom_get_vfo,
+ .get_vfo = icom_get_vfo,
.set_ant = icom_set_ant,
.get_ant = icom_get_ant,
diff --git a/tests/testic7760caps.c b/tests/testic7760caps.c
index 0d3f67721..2ca69b077 100644
--- a/tests/testic7760caps.c
+++ b/tests/testic7760caps.c
@@ -882,6 +882,22 @@ static int match_name(RIG *rig, const struct confparams *cfp, rig_ptr_t data)
* rig has but the backend does not drive, so it has to stay filtered
* out - that is what keeps the whitelist honest.
*/
+/*
+ * 07 D2 reads which of Main and Sub is selected, so the backend can
+ * follow the front panel instead of trusting its own last set_vfo.
+ */
+static int test_band_selection_is_readable(void)
+{
+ if (ic7760_caps.get_vfo == NULL)
+ {
+ fprintf(stderr, "the rig reads its Main/Sub selection with 07 D2, but"
+ " get_vfo is not wired up\n");
+ return 1;
+ }
+
+ return 0;
+}
+
static int test_ext_tokens_are_enumerable(RIG *rig)
{
static const struct
@@ -957,6 +973,7 @@ int main(void)
fail |= test_scan_operations();
fail |= test_agc_levels();
fail |= test_spectrum_scope();
+ fail |= test_band_selection_is_readable();
rig_register(&ic7760_caps);
rig = rig_init(RIG_MODEL_IC7760);
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index 2c79bf739..3a48a4331 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -40,6 +40,8 @@ struct peer_case
size_t frame_len[MAX_RECORDED_FRAMES];
/* the peer counts while the main thread takes marks, hence atomic */
atomic_size_t frame_count;
+ /* which band 07 D2 answers with, or -1 to reject it like the rest */
+ atomic_int band_sel_answer;
};
static const unsigned char nak[] = { 0xfe, 0xfe, 0xe0, 0xb2, 0xfa, 0xfd };
@@ -65,6 +67,22 @@ static void *run_peer(void *arg)
test->frame_count++;
}
+ /*
+ * 07 D2 reads the selected band, so it has to come back with a
+ * band rather than a rejection for the answer to be decoded.
+ */
+ if (length == 7 && frame[4] == 0x07 && frame[5] == 0xd2
+ && test->band_sel_answer >= 0)
+ {
+ unsigned char band[] = { 0xfe, 0xfe, 0xe0, 0xb2, 0x07, 0xd2, 0x00, 0xfd };
+
+ band[6] = (unsigned char) test->band_sel_answer;
+
+ if (write_all(test->fd, band, sizeof(band)) != 0) { break; }
+
+ continue;
+ }
+
if (write_all(test->fd, nak, sizeof(nak)) != 0) { break; }
}
@@ -121,7 +139,7 @@ int main(void)
{
int sockets[2];
pthread_t thread;
- struct peer_case test = { .fd = -1, .frame_count = 0 };
+ struct peer_case test = { .fd = -1, .frame_count = 0, .band_sel_answer = -1 };
struct icom_priv_data *priv;
static const unsigned char backlight_full[] = { 0x14, 0x19, 0x02, 0x55 };
static const unsigned char dual_watch_on[] = { 0x07, 0xc1 };
@@ -133,8 +151,12 @@ int main(void)
static const unsigned char read_sub_freq[] = { 0x25, 0x01 };
static const unsigned char read_main_mode[] = { 0x26, 0x00 };
static const unsigned char read_sub_mode[] = { 0x26, 0x01 };
+ static const unsigned char read_band_sel[] = { 0x07, 0xd2 };
powerstat_t status = RIG_POWER_OFF;
size_t main_freq_mark, sub_freq_mark, main_mode_mark, sub_mode_mark;
+ size_t band_sel_mark;
+ vfo_t selected_main = RIG_VFO_NONE, selected_sub = RIG_VFO_NONE;
+ int main_sel_retval, sub_sel_retval;
rmode_t mode;
pbwidth_t width;
freq_t freq;
@@ -227,6 +249,18 @@ int main(void)
sub_mode_mark = test.frame_count;
rig_get_mode(rig, RIG_VFO_SUB, &mode, &width);
+ /*
+ * 07 D2 reads which band the front panel has selected, answering 00
+ * for Main and 01 for Sub. rig_get_vfo() caches its answer, so both
+ * bands are only seen with the cache switched off.
+ */
+ rig_set_cache_timeout_ms(rig, HAMLIB_CACHE_ALL, 0);
+ band_sel_mark = test.frame_count;
+ test.band_sel_answer = 0x00;
+ main_sel_retval = rig_get_vfo(rig, &selected_main);
+ test.band_sel_answer = 0x01;
+ sub_sel_retval = rig_get_vfo(rig, &selected_sub);
+
stop_test_peer(sockets, thread);
/*
@@ -337,6 +371,37 @@ int main(void)
failed = 1;
}
+ /*
+ * Without get_vfo wired up the backend cannot follow the front
+ * panel, and dumpcaps reports the rig cannot read its VFO at all.
+ */
+ if (main_sel_retval == -RIG_ENAVAIL || sub_sel_retval == -RIG_ENAVAIL)
+ {
+ fprintf(stderr, "get_vfo is not wired up, so the Main/Sub selection"
+ " cannot be read\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, band_sel_mark, read_band_sel, sizeof(read_band_sel)))
+ {
+ fprintf(stderr, "get_vfo did not send 07 D2\n");
+ failed = 1;
+ }
+
+ if (selected_main != RIG_VFO_MAIN)
+ {
+ fprintf(stderr, "get_vfo read 07 D2 00 as %s, not Main\n",
+ rig_strvfo(selected_main));
+ failed = 1;
+ }
+
+ if (selected_sub != RIG_VFO_SUB)
+ {
+ fprintf(stderr, "get_vfo read 07 D2 01 as %s, not Sub\n",
+ rig_strvfo(selected_sub));
+ failed = 1;
+ }
+
STATE(rig)->comm_state = 0;
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
commit eb4f48f0f905f50d47e082cca543cd7a8f1f6b74
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 03:45:46 2026 +0200
fix(icom): address the IC-7760 Main and Sub bands by name
Commands 25 and 26 take 00 for Main and 01 for Sub on this rig, but it
was falling through to the branch that reads that byte as selected and
unselected instead. With Sub selected the two came out swapped, so a
targeted read or write of frequency or mode reached the other receiver.
Tested on an IC-7760 with Main on 14.1828 MHz and Sub on 14.0730 MHz:
reading Sub while Sub was selected sent 25 00 and returned 14.1828 MHz,
the Main frequency. It now sends 25 01 and returns 14.0730 MHz.
The branch is model gated, so no other rig changes behaviour.
diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c
index 10b00ae52..844d14841 100644
--- a/rigs/icom/icom.c
+++ b/rigs/icom/icom.c
@@ -10377,7 +10377,8 @@ static int icom_get_vfo_number_x25x26(RIG *rig, vfo_t vfo)
rig_get_cache_routing_snapshot(rig, &routing);
// Rigs with *only* Main/Sub VFOs can directly address VFOs: 0 = Main, 1 = Sub
- if (RIG_IS_IC7600 || RIG_IS_IC7610 || RIG_IS_IC7800 || RIG_IS_IC785X)
+ if (RIG_IS_IC7600 || RIG_IS_IC7610 || RIG_IS_IC7760 || RIG_IS_IC7800
+ || RIG_IS_IC785X)
{
vfo_t actual_vfo = vfo_fixup_from_snapshot(
rig, vfo, routing.split, &routing,
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index 8b2c238fd..2c79bf739 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -18,6 +18,7 @@
*/
#include <pthread.h>
+#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
@@ -37,7 +38,8 @@ struct peer_case
int fd;
unsigned char frames[MAX_RECORDED_FRAMES][MAX_FRAME_LEN];
size_t frame_len[MAX_RECORDED_FRAMES];
- size_t frame_count;
+ /* the peer counts while the main thread takes marks, hence atomic */
+ atomic_size_t frame_count;
};
static const unsigned char nak[] = { 0xfe, 0xfe, 0xe0, 0xb2, 0xfa, 0xfd };
@@ -102,6 +104,19 @@ static int saw_payload(const struct peer_case *test,
return 0;
}
+/*
+ * Each of the calls below sends exactly one frame, so the frame recorded
+ * at the mark taken before a call is that call's own and can be matched
+ * whole rather than searched for.
+ */
+static int frame_is(const struct peer_case *test, size_t index,
+ const unsigned char *payload, size_t len)
+{
+ return index < test->frame_count
+ && test->frame_len[index] == len + 5
+ && memcmp(&test->frames[index][4], payload, len) == 0;
+}
+
int main(void)
{
int sockets[2];
@@ -114,7 +129,15 @@ int main(void)
static const unsigned char ant1_rx_on[] = { 0x12, 0x00, 0x01 };
static const unsigned char voice_mem_3[] = { 0x28, 0x00, 0x03 };
static const unsigned char voice_mem_stop[] = { 0x28, 0x00, 0x00 };
+ static const unsigned char read_main_freq[] = { 0x25, 0x00 };
+ static const unsigned char read_sub_freq[] = { 0x25, 0x01 };
+ static const unsigned char read_main_mode[] = { 0x26, 0x00 };
+ static const unsigned char read_sub_mode[] = { 0x26, 0x01 };
powerstat_t status = RIG_POWER_OFF;
+ size_t main_freq_mark, sub_freq_mark, main_mode_mark, sub_mode_mark;
+ rmode_t mode;
+ pbwidth_t width;
+ freq_t freq;
int voice_retval;
value_t backlight;
value_t ant_option;
@@ -188,6 +211,22 @@ int main(void)
voice_retval = rig_send_voice_mem(rig, RIG_VFO_CURR, 3);
rig_stop_voice_mem(rig, RIG_VFO_CURR);
+ /*
+ * Commands 25 and 26 name the band outright, so the byte they carry
+ * does not depend on which band is selected. Ask for both bands
+ * with Sub selected, where reading that byte as selected and
+ * unselected instead comes out reversed.
+ */
+ rig_set_current_vfo_state(rig, RIG_VFO_SUB);
+ main_freq_mark = test.frame_count;
+ rig_get_freq(rig, RIG_VFO_MAIN, &freq);
+ sub_freq_mark = test.frame_count;
+ rig_get_freq(rig, RIG_VFO_SUB, &freq);
+ main_mode_mark = test.frame_count;
+ rig_get_mode(rig, RIG_VFO_MAIN, &mode, &width);
+ sub_mode_mark = test.frame_count;
+ rig_get_mode(rig, RIG_VFO_SUB, &mode, &width);
+
stop_test_peer(sockets, thread);
/*
@@ -273,6 +312,31 @@ int main(void)
failed = 1;
}
+ /* 25 and 26 take 00 for Main and 01 for Sub. */
+ if (!frame_is(&test, main_freq_mark, read_main_freq, sizeof(read_main_freq)))
+ {
+ fprintf(stderr, "get_freq MAIN did not send 25 00 with Sub selected\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, sub_freq_mark, read_sub_freq, sizeof(read_sub_freq)))
+ {
+ fprintf(stderr, "get_freq SUB did not send 25 01 with Sub selected\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, main_mode_mark, read_main_mode, sizeof(read_main_mode)))
+ {
+ fprintf(stderr, "get_mode MAIN did not send 26 00 with Sub selected\n");
+ failed = 1;
+ }
+
+ if (!frame_is(&test, sub_mode_mark, read_sub_mode, sizeof(read_sub_mode)))
+ {
+ fprintf(stderr, "get_mode SUB did not send 26 01 with Sub selected\n");
+ failed = 1;
+ }
+
STATE(rig)->comm_state = 0;
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
commit 7c58b74f00c792feedee5c2afce27f54310543f3
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 03:28:35 2026 +0200
build: initialise Winsock in the icom socket tests
testic7760civ, testicomant and testicomscan open a socket pair to stand
in for a rig, but on Windows their socket() calls run without
WSAStartup(), so they fail with WSANOTINITIALISED before testing
anything. testid5100.c already carries the pattern; the three now
follow it, cleaning up on each exit path.
Only the Windows path changes, and it is untested here, there being no
Windows machine or cross compiler to hand.
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index 5fe51adc8..8b2c238fd 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -122,12 +122,26 @@ int main(void)
int parm_retval;
int failed = 0;
+#ifdef _WIN32
+ WSADATA wsa_data;
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
+ {
+ fprintf(stderr, "WSAStartup failed\n");
+ return 1;
+ }
+
+#endif
+
rig_register(&ic7760_caps);
rig = rig_init(RIG_MODEL_IC7760);
if (rig == NULL)
{
fprintf(stderr, "rig_init failed\n");
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -135,6 +149,9 @@ int main(void)
{
fprintf(stderr, "test socket setup failed\n");
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -145,6 +162,9 @@ int main(void)
close_test_socket(sockets[0]);
close_test_socket(sockets[1]);
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -257,5 +277,9 @@ int main(void)
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
+
return failed;
}
diff --git a/tests/testicomant.c b/tests/testicomant.c
index 4e7171099..4c513b638 100644
--- a/tests/testicomant.c
+++ b/tests/testicomant.c
@@ -100,12 +100,26 @@ int main(void)
int bad_option_retval;
int failed = 0;
+#ifdef _WIN32
+ WSADATA wsa_data;
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
+ {
+ fprintf(stderr, "WSAStartup failed\n");
+ return 1;
+ }
+
+#endif
+
rig_register(&ic7600_caps);
rig = rig_init(RIG_MODEL_IC7600);
if (rig == NULL)
{
fprintf(stderr, "rig_init failed\n");
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -113,6 +127,9 @@ int main(void)
{
fprintf(stderr, "test socket setup failed\n");
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -123,6 +140,9 @@ int main(void)
close_test_socket(sockets[0]);
close_test_socket(sockets[1]);
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -175,5 +195,9 @@ int main(void)
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
+
return failed;
}
diff --git a/tests/testicomscan.c b/tests/testicomscan.c
index a823c1c91..4a4d8c503 100644
--- a/tests/testicomscan.c
+++ b/tests/testicomscan.c
@@ -116,12 +116,26 @@ int main(void)
int slct_retval;
int failed = 0;
+#ifdef _WIN32
+ WSADATA wsa_data;
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0)
+ {
+ fprintf(stderr, "WSAStartup failed\n");
+ return 1;
+ }
+
+#endif
+
rig_register(&ic7300_caps);
rig = rig_init(RIG_MODEL_IC7300);
if (rig == NULL)
{
fprintf(stderr, "rig_init failed\n");
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -129,6 +143,9 @@ int main(void)
{
fprintf(stderr, "test socket setup failed\n");
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -139,6 +156,9 @@ int main(void)
close_test_socket(sockets[0]);
close_test_socket(sockets[1]);
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
return 1;
}
@@ -180,5 +200,9 @@ int main(void)
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
+#ifdef _WIN32
+ WSACleanup();
+#endif
+
return failed;
}
commit d91126247014608c75e7f61a388b042fa674337e
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 03:23:30 2026 +0200
fix(ic7760): let the voice memories be transmitted
The backend advertises eight RIG_MTYPE_VOICE channels, but without
send_voice_mem and stop_voice_mem behind them rig_send_voice_mem()
returns ENAVAIL, so dumpcaps reported "Can send Voice: N" beside a list
of voice memories. Wired the way ic7610.c wires them. ic7300.c also
carries RIG_FUNC_SEND_VOICE_MEM, which nothing in the Icom backend
implements, so that is left out.
Checked against the radio: 28 00 01 is rejected while T1 is empty and
acknowledged once it holds a recording, keying the rig for the whole
11 s of it at minimum power; 28 00 00 sent two seconds in is
acknowledged and drops PTT a second later.
Source: IC-7760 CI-V reference guide, A7788-8EX-2 (May 2025), p. 16 for
command 28 00.
diff --git a/rigs/icom/ic7760.c b/rigs/icom/ic7760.c
index 14ded3bca..0cd750f70 100644
--- a/rigs/icom/ic7760.c
+++ b/rigs/icom/ic7760.c
@@ -465,6 +465,8 @@ struct rig_caps ic7760_caps =
.send_morse = icom_send_morse,
.stop_morse = icom_stop_morse,
.wait_morse = rig_wait_morse,
+ .send_voice_mem = icom_send_voice_mem,
+ .stop_voice_mem = icom_stop_voice_mem,
.set_clock = icom_set_clock,
.get_clock = icom_get_clock,
.hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
diff --git a/tests/testic7760civ.c b/tests/testic7760civ.c
index 5ed1c027b..5fe51adc8 100644
--- a/tests/testic7760civ.c
+++ b/tests/testic7760civ.c
@@ -112,7 +112,10 @@ int main(void)
static const unsigned char dual_watch_on[] = { 0x07, 0xc1 };
static const unsigned char transceive_on[] = { 0x1a, 0x05, 0x01, 0x50, 0x01 };
static const unsigned char ant1_rx_on[] = { 0x12, 0x00, 0x01 };
+ static const unsigned char voice_mem_3[] = { 0x28, 0x00, 0x03 };
+ static const unsigned char voice_mem_stop[] = { 0x28, 0x00, 0x00 };
powerstat_t status = RIG_POWER_OFF;
+ int voice_retval;
value_t backlight;
value_t ant_option;
RIG *rig;
@@ -162,6 +165,8 @@ int main(void)
rig_set_func(rig, RIG_VFO_CURR, RIG_FUNC_TRANSCEIVE, 1);
ant_option.i = 1;
rig_set_ant(rig, RIG_VFO_CURR, RIG_ANT_1, ant_option);
+ voice_retval = rig_send_voice_mem(rig, RIG_VFO_CURR, 3);
+ rig_stop_voice_mem(rig, RIG_VFO_CURR);
stop_test_peer(sockets, thread);
@@ -224,6 +229,30 @@ int main(void)
failed = 1;
}
+ /*
+ * The voice memories are advertised as eight channels, so a client
+ * has to be able to transmit them: 28 00 with the memory as its data
+ * byte, 01 through 08, and 28 00 00 to stop.
+ */
+ if (voice_retval == -RIG_ENAVAIL)
+ {
+ fprintf(stderr, "send_voice_mem is not wired up, so the advertised"
+ " voice memories cannot be transmitted\n");
+ failed = 1;
+ }
+
+ if (!saw_payload(&test, voice_mem_3, sizeof(voice_mem_3)))
+ {
+ fprintf(stderr, "send_voice_mem 3 did not send 28 00 03\n");
+ failed = 1;
+ }
+
+ if (!saw_payload(&test, voice_mem_stop, sizeof(voice_mem_stop)))
+ {
+ fprintf(stderr, "stop_voice_mem did not send 28 00 00\n");
+ failed = 1;
+ }
+
STATE(rig)->comm_state = 0;
RIGPORT(rig)->fd = -1;
rig_cleanup(rig);
commit cf3ed3f78fdaf5d6753b5b473c9943614e982f1c
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 02:18:27 2026 +0200
build: ignore test programs missing from tests/.gitignore
tests/.gitignore had fallen behind tests/Makefile.am. Six check_PROGRAMS
and one generated script were never listed, so a built tree always had
seven untracked files in git status:
testft991idmeter, testguohetec, testid5100, testrigctlprotocol,
testthd75emu, testthd7x and testnetrigctllocale.sh
The last of those is written by the Makefile itself, the same way as
testnetrigctl.sh and testrig.sh, which were already listed.
diff --git a/tests/.gitignore b/tests/.gitignore
index 46acb2cc3..ff491df0d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -40,11 +40,13 @@ testdummyparm
testelecraftvfo
testfreq
testfreq.sh
+testft991idmeter
testftx1parsers
testgeministatus
testgrid
testgrid.sh
testgs100
+testguohetec
testic7760caps
testic7760civ
testic9700civ
@@ -53,17 +55,22 @@ testicomgetvfo
testicomscan
testicomscope
testicomts
+testid5100
testlibusb
testloc
testloc.sh
testmW2power
testnetrigctl
testnetrigctl.sh
+testnetrigctllocale.sh
testrig
testrig.sh
testrigcaps
testrigcaps.sh
+testrigctlprotocol
testrigopen
+testthd75emu
+testthd7x
testtrn
testtunercontrol
testtunercontrol_marker
commit c2f2a49bdc691a91b5917bd35ee04a0778bdf295
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 01:05:47 2026 +0200
feat(ic7760): advertise more of the attenuator range
The rig attenuates in 3 dB steps from 3 to 45 dB. The caps listed
6, 12 and 18, inherited from the IC-7700, so dump_caps and any client
building its menu from the list showed three settings out of fifteen,
and never the strongest.
HAMLIB_MAXDBLSTSIZ holds seven entries, so the list stays a subset:
6, 12, 18, 24, 30, 36, 45 keeps everything that was there, adds a
regular 6 dB ladder and reaches the maximum. The values left out are
still reachable, as rig_set_level() does not check against the list.
Checked on the radio: 03 through 45 were all accepted, while 11 05,
11 10 and 11 50 were rejected.
Source: IC-7760 CI-V reference guide, A7788-8EX-2 (May 2025), p. 3.
diff --git a/rigs/icom/ic7760.c b/rigs/icom/ic7760.c
index 812ec45ee..14ded3bca 100644
--- a/rigs/icom/ic7760.c
+++ b/rigs/icom/ic7760.c
@@ -288,7 +288,8 @@ struct rig_caps ic7760_caps =
.ctcss_list = common_ctcss_list,
.dcs_list = NULL,
.preamp = { 12, 20, RIG_DBLST_END, },
- .attenuator = { 6, 12, 18, RIG_DBLST_END, },
+ // 3 to 45 dB in 3 dB steps; the list holds seven of the fifteen
+ .attenuator = { 6, 12, 18, 24, 30, 36, 45, RIG_DBLST_END, },
.max_rit = Hz(9999),
.max_xit = Hz(9999),
.max_ifshift = Hz(0),
diff --git a/tests/testic7760caps.c b/tests/testic7760caps.c
index 8cb0ab75f..0d3f67721 100644
--- a/tests/testic7760caps.c
+++ b/tests/testic7760caps.c
@@ -806,6 +806,55 @@ static int test_preamp_gains(void)
return 0;
}
+/*
+ * Command 11 carries the attenuation as BCD dB. The rig takes 3 to 45
+ * in steps of 3 and rejects anything else, which is fifteen settings,
+ * and HAMLIB_MAXDBLSTSIZ has room for seven of them. The list is a
+ * subset, then, but every entry has to be a setting the rig accepts and
+ * the strongest one has to be reachable.
+ */
+static int test_attenuator_steps(void)
+{
+ size_t i;
+ int previous = 0;
+ int fail = 0;
+
+ for (i = 0; i < HAMLIB_MAXDBLSTSIZ && ic7760_caps.attenuator[i] != 0; i++)
+ {
+ int att = ic7760_caps.attenuator[i];
+
+ if (att < 3 || att > 45 || att % 3 != 0)
+ {
+ fprintf(stderr, "attenuator %d dB is not a setting of command 11\n",
+ att);
+ fail = 1;
+ }
+
+ if (att <= previous)
+ {
+ fprintf(stderr, "attenuator list is not ascending at %d dB\n", att);
+ fail = 1;
+ }
+
+ previous = att;
+ }
+
+ if (i == HAMLIB_MAXDBLSTSIZ)
+ {
+ fprintf(stderr, "attenuator list is not terminated\n");
+ fail = 1;
+ }
+
+ if (previous != 45)
+ {
+ fprintf(stderr, "strongest attenuator advertised is %d dB, the rig"
+ " goes to 45 dB\n", previous);
+ fail = 1;
+ }
+
+ return fail;
+}
+
struct name_search
{
const char *wanted;
@@ -899,6 +948,7 @@ int main(void)
fail |= test_present_capabilities();
fail |= test_memory_channel_counts();
fail |= test_preamp_gains();
+ fail |= test_attenuator_steps();
fail |= test_serial_rates();
fail |= test_id_meter_calibration();
fail |= test_transmit_power_ranges();
commit ef0114cd9762087e4f27a2f6a916f67d63e09dcd
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 01:02:14 2026 +0200
feat(ic7760): advertise the select memory scan
The rig has one: 0E 23 starts it, and 0E B0 and 0E B1 clear and set
the select mark on a memory channel. IC7760_SCAN_OPS did not list
RIG_SCAN_SLCT, so rig_scan() turned the request away before any frame
was sent.
Checked on the radio. With two memories written and one of them
marked as select, 0E 23 was accepted, the display read SELECT MEMORY
SCAN, and the rig stayed on the marked channel, while the plain
memory scan moved to the other one.
Source: IC-7760 CI-V reference guide, A7788-8EX-2 (May 2025), p. 3.
diff --git a/rigs/icom/ic7760.c b/rigs/icom/ic7760.c
index af70d6b59..812ec45ee 100644
--- a/rigs/icom/ic7760.c
+++ b/rigs/icom/ic7760.c
@@ -44,7 +44,7 @@
#define IC7760_PARMS (RIG_PARM_ANN|RIG_PARM_BACKLIGHT)
#define IC7760_VFO_OPS (RIG_OP_CPY|RIG_OP_XCHG|RIG_OP_FROM_VFO|RIG_OP_TO_VFO|RIG_OP_MCL|RIG_OP_TUNE)
-#define IC7760_SCAN_OPS (RIG_SCAN_MEM|RIG_SCAN_VFO|RIG_SCAN_PROG|RIG_SCAN_DELTA)
+#define IC7760_SCAN_OPS (RIG_SCAN_MEM|RIG_SCAN_VFO|RIG_SCAN_PROG|RIG_SCAN_DELTA|RIG_SCAN_SLCT)
#define IC7760_ANTS (RIG_ANT_1|RIG_ANT_2|RIG_ANT_3|RIG_ANT_4)
diff --git a/tests/testic7760caps.c b/tests/testic7760caps.c
index 70739fb41..8cb0ab75f 100644
--- a/tests/testic7760caps.c
+++ b/tests/testic7760caps.c
@@ -564,7 +564,7 @@ static int test_agc_levels(void)
static int test_scan_operations(void)
{
scan_t expected = RIG_SCAN_MEM | RIG_SCAN_VFO | RIG_SCAN_PROG
- | RIG_SCAN_DELTA;
+ | RIG_SCAN_DELTA | RIG_SCAN_SLCT;
if (ic7760_caps.scan_ops == expected) { return 0; }
commit 3150a922f12d0b1275258cd104a8b4fd038c8ca3
Author: Arkadiusz Miśkiewicz <ar...@ma...>
Date: Sat Aug 29 00:18:01 2026 +0200
feat(ic7760): support the spectrum scope
The rig answers the whole 27 command set and hamlib can already drive
it, but the backend described none of it.
The waveform is 689 points ranging 0 to 200, arriving over USB in
fifteen pieces, the first carrying only the header, so 50 points to a
piece. Spans are held as the full width because the backend halves them
before sending, so the rig's 2.5 kHz to 500 kHz becomes 5 kHz to 1 MHz -
the same list ic7610.c carries.
Data only comes out while both the scope and its data output are on, so
27 10 is advertised as well as 27 11. It arrives unasked on 27 00, and
without async_data_supported rig_open() clears async_data_enabled,
leaving a client only the frames read_icom_frame() picks up while a
command is in flight. Both are declared the way ic7610.c declares them.
Checked against the radio: all 66 sweeps across two runs had the same
shape - 15 frames, the first the header, the next thirteen 50 points and
the last 39, so 689 points, on both scopes. Only amplitudes differed,
running 0 to 118, so the top of the guide's range is untested. 27 10
reads back on and takes off and on again, the span answers 25 kHz, the
reference level -10 dB and averaging on 1A 05 02 12. A client listening
for five seconds now gets 20 sweeps of 689 points, against none before.
Source: IC-7760 CI-V reference guide, A7788-8EX-2 (May 2025), p. 15 for
the two settings the output depends on, p. 16 for the command list and
pp. 23-25 for the formats.
Fixes #1794.
diff --git a/rigs/icom/ic7760.c b/rigs/icom/ic7760.c
index 15dbc5d14..af70d6b59 100644
--- a/rigs/icom/ic7760.c
+++ b/rigs/icom/ic7760.c
@@ -36,9 +36,9 @@
#define IC7760_AM_TX_MODES (RIG_MODE_AM|RIG_MODE_PKTAM)
#define IC7760_ALL_RX_MODES IC7760_OTHER_TX_MODES | IC7760_AM_TX_MODES
-#define IC7760_FUNCS (RIG_FUNC_NB|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_TONE|RIG_FUNC_TSQL|RIG_FUNC_SBKIN|RIG_FUNC_FBKIN|RIG_FUNC_NR|RIG_FUNC_MON|RIG_FUNC_MN|RIG_FUNC_ANF|RIG_FUNC_LOCK|RIG_FUNC_RIT|RIG_FUNC_XIT|RIG_FUNC_TUNER|RIG_FUNC...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-10-31 12:57:05
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 94d984e72a9fef7b1d3a46fabf13987106278bad (commit)
via c2840b4a36e10706d11985178f4c0177be9008d4 (commit)
via 91e7b973133cf373f991113703196bd44f054e33 (commit)
via 974c779f12765222c1908772f9322d3396cee997 (commit)
via 2e3e4a6add3bd806e828d035200777608d2bdbd5 (commit)
via ab51aeab1b047e4b438264898eabaaf67e9cb5f5 (commit)
via 73015ca009e4443e708dc14589a93b598374b50b (commit)
via a9c9848469c6d835c3acbbf29b7aed9a7ebfbf0b (commit)
via 7ff6ab89e4158e29342ac2e28f186e30cd612174 (commit)
via d38efff3d209c49e090f3a4a793f9a678c45d6d3 (commit)
via 59be194a6fe292b115dbf15281a438e9d891c81b (commit)
via f9190048a9e0804d17af23fae5f4698a334179b0 (commit)
via 5952c990c4a59e70efa36c0e961e81f5370f617a (commit)
via fbec996dc4a8433f8e619a39e726bda972f9dd35 (commit)
via cb39abd0fab3c72d66c645809f4451e0cf37ad6a (commit)
via 940c806c23c662aa802c1c48bd2dffe2b31ea8a6 (commit)
via 3b126ade0aa72fff2ff2d787e0e418d855142b02 (commit)
from add899a696ee3a664ac2c931b54852f98ee36093 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 94d984e72a9fef7b1d3a46fabf13987106278bad
Merge: 91e7b9731 c2840b4a3
Author: Terrell Deppe <62b...@pr...>
Date: Fri Oct 30 15:18:41 2026 -0500
Merge pull request #2178 from mikaelnousiainen/streaming-backend-icom-network-pr
commit c2840b4a36e10706d11985178f4c0177be9008d4
Merge: 974c779f1 91e7b9731
Author: Mikael Nousiainen <mik...@ik...>
Date: Fri Oct 30 21:16:52 2026 +0200
Merge branch 'master' into streaming-backend-icom-network-pr.
icom network: fix strncpy truncation and Winsock signedness warnings
- test_rigctld_commands.c: take this branch's version; #2224 made the
equivalent fix and WAIT_UNTIL is WAIT_UNTIL_MS here
- icom.h: keep both the network fields and g90_af_quirk (#2246)
- icom frame.c: only skip non-matching reply frames longer than an ACK,
so a garbled ACK to a set is still -RIG_EPROTO (fixes testg90rit)
- icom_network_open(): use SNPRINTF for the config strings and refuse
a radio address longer than the host buffer (-Wstringop-truncation)
- network_session.c, test mock: pass char buffers to send/recv/sendto/
recvfrom, which Winsock declares with char * (-Wpointer-sign on MinGW)
diff --cc rigs/icom/frame.c
index 453b5e116,8130a1465..dc3d1ae9a
--- a/rigs/icom/frame.c
+++ b/rigs/icom/frame.c
@@@ -437,19 -351,6 +437,22 @@@ again2
goto again2;
}
+ // The frame must be the response to the command we sent: a set replies
- // ACK/NAK/COL, a get echoes our cmd (and subcmd). Any other cmd byte is an
- // unsolicited or interleaved frame (e.g. on a shared or echoing CI-V bus),
- // so skip it and read the next frame.
- if (buf[4] != ACK && buf[4] != NAK && buf[4] != COL
++ // ACK/NAK/COL, a get echoes our cmd (and subcmd). A data frame carrying
++ // some other cmd is an unsolicited or interleaved reply (e.g. on a shared
++ // or echoing CI-V bus), so skip it and read the next frame. A frame no
++ // longer than an ACK is not skipped: it is a garbled ACK and is rejected
++ // below as a protocol error.
++ if (frm_len > ACKFRMLEN
++ && buf[4] != ACK && buf[4] != NAK && buf[4] != COL
+ && !icom_frame_matches_cmd(cmd, subcmd, buf, frm_len))
+ {
+ rig_debug(RIG_DEBUG_VERBOSE,
+ "%s: cmd x%02x subcmd x%x != buf x%02x x%02x so retry read\n",
+ __func__, cmd, subcmd, buf[4], buf[5]);
+ goto again2;
+ }
+
if (sendbuf[3] != buf[2])
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: unknown async? read again\n", __func__);
diff --cc rigs/icom/icom.h
index 3690b67d3,ba25adf2e..e5ac91762
--- a/rigs/icom/icom.h
+++ b/rigs/icom/icom.h
@@@ -316,27 -316,7 +316,28 @@@ struct icom_priv_dat
int filter_usb; /*!< Filter number to use for USB/LSB when setting mode */
int filter_cw; /*!< Filter number to use for CW/CWR when setting mode */
int filter_fm; /*!< Filter number to use for CW/CWR when setting mode */
+ void *netsession; /*!< Icom network session (network models only); when
+ set, CI-V frames are tunneled over the LAN protocol */
+ char net_username[24]; /*!< Network protocol login (network models only) */
+ char net_password[24]; /*!< Network protocol password (network models only) */
+ int net_control_port; /*!< Network protocol control port (0 = default) */
+ int net_iq_mode; /*!< Present stereo RX audio as an I/Q stream */
+ int net_rx_codec; /*!< RX audio codec wire byte (0 = model default) */
+ int net_tx_codec; /*!< TX audio codec wire byte (0 = model default) */
+ int net_sample_rate; /*!< Network audio sample rate in Hz (0 = default) */
+ int net_rx_latency; /*!< RX reorder window in ms (0 = in-order, no retransmits) */
+ int net_tx_latency; /*!< TX audio jitter-buffer length in ms (0 = default) */
+ int net_tx_enable; /*!< Open a TX audio session (0 = RX only) */
+ int net_tx_frame_ms; /*!< TX audio wire-frame duration in ms */
+ int net_radio_index; /*!< Radio to select from the advertised list,
+ -1 = select by name instead */
+ char net_radio_name[33]; /*!< Radio name to select, empty = use the
+ model's own name */
+ int net_liveness_timeout; /*!< Silence (ms) before the session is declared
+ lost; 0 disables the check */
+ int net_auto_reconnect; /*!< Re-establish a lost session in the background */
+ const void *net_model; /*!< Per-model icom_network_model descriptor */
+ int g90_af_quirk; /*!< Opt-in G90 AF reply encoding workaround */
};
extern const struct ts_sc_list r8500_ts_sc_list[];
diff --cc rigs/icom/icom_network.c
index 01f7fd135,000000000..567e794d2
mode 100644,000000..100644
--- a/rigs/icom/icom_network.c
+++ b/rigs/icom/icom_network.c
@@@ -1,1228 -1,0 +1,1238 @@@
+/*
+ * Hamlib Icom network backend
+ * Copyright (c) 2026 by Mikael Nousiainen OH3BHX
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+/* Generic Icom LAN (network-protocol) backend: controls a radio over the Icom */
+/* UDP protocol, reusing the CI-V backend with the network session as transport. */
+
+#include "hamlib/config.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <pthread.h>
+#include <time.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/port.h"
+#include "icom.h"
+#include "icom_defs.h"
+#include "network_session.h"
+#include "network_proto.h"
+#include "network_conf.h"
+#include "icom_network.h"
+#include "network_utils.h"
+#include "stream.h"
+#include "stream_ringbuf.h"
+#include "stream_codec.h"
+#include "stream_anchor.h"
+#include "stream_proto.h"
+#include "stream_time.h"
+
+/* The radio frames its own audio in 20 ms chunks for every codec; TX uses the
+ * same duration by default (net_tx_frame_ms overrides). */
+#define ICOM_NETWORK_TX_FRAME_MS 20
+
+/* One I/Q sample on the wire: a signed 16-bit I and Q pair. */
+#define ICOM_NETWORK_IQ_FRAME_BYTES 4
+
+/* The session queues audio payloads up to ICOM_NETWORK_SESSION_AUDIO_FRAME_MAX,
+ * which is larger than the buffer above; icom_network_audio_recv() clamps to
+ * the buffer it is given and drops the remainder, silently. That the radios do
+ * not send payloads that large is an observation, not a guarantee: measured
+ * across every codec and both stream types on an IC-7610 and an IC-9700, no
+ * payload has ever exceeded this maximum. Raise this constant, do not lower
+ * it, and if a radio ever appears that packetises differently the symptom will
+ * be audible dropouts with no counter moving. */
+
+static const struct icom_network_model *icom_network_find_model(
+ rig_model_t model);
+static int icom_network_publish_session_caps(RIG *rig,
+ const struct icom_network_session_config *scfg);
+
+/*
+ * Route inbound CI-V frames from the session's receive thread: handle
+ * unsolicited async frames (spectrum scope, transceive) here so the waterfall
+ * flows during and between transactions; leave command responses (return 0)
+ * for the transaction layer to read via the seam.
+ */
+static int icom_network_async_frame(void *ctx, const unsigned char *frame,
+ size_t length)
+{
+ RIG *rig = (RIG *)ctx;
+
+ if (icom_is_async_frame(rig, length, frame))
+ {
+ icom_process_async_frame(rig, length, frame);
+ return 1;
+ }
+
+ return 0;
+}
+
+/* ------------------------------------------------------------------ */
+/* rig open / close */
+/* ------------------------------------------------------------------ */
+
+/* Publish a change in the session's health where applications and the multicast
+ * snapshot can see it. The session layer reports both directions through this
+ * one callback: a reason names what went wrong, and RIG_COMM_REASON_NONE means
+ * the reconnect thread has the session back. Treating every call as a loss
+ * would leave a recovered rig looking disconnected for the rest of its life.
+ * Runs on a session thread, so it only touches rig_state fields that are plain
+ * scalars. */
+static void icom_network_session_state_changed(void *ctx, unsigned reason)
+{
+ RIG *rig = ctx;
+
+ STATE(rig)->comm_status = reason == RIG_COMM_REASON_NONE
+ ? RIG_COMM_STATUS_OK
+ : RIG_COMM_STATUS_DISCONNECTED;
+ STATE(rig)->comm_reason = reason;
+}
+
+static int icom_network_open(RIG *rig)
+{
+ struct icom_priv_data *priv = (struct icom_priv_data *)STATE(rig)->priv;
+ hamlib_port_t *rp = RIGPORT(rig);
+ struct icom_network_session_config config;
+ struct icom_network_session *sess;
+ char *colon;
+ int ret;
+
+ /* icom_rig_open() can re-enter this open on its internal retry; free any
+ * session from a prior attempt so we never orphan one whose threads keep
+ * the radio marked busy and refusing new connections. */
+ if (priv->netsession)
+ {
+ icom_network_session_free(priv->netsession);
+ priv->netsession = NULL;
+ }
+
+ memset(&config, 0, sizeof(config));
- /* the radio host comes from the -r/rig_pathname argument, host[:port] */
- strncpy(config.host, rp->pathname, sizeof(config.host) - 1);
++ /* the radio host comes from the -r/rig_pathname argument, host[:port];
++ * refuse one that does not fit rather than connect to a truncated name */
++ if (strlen(rp->pathname) >= sizeof(config.host))
++ {
++ rig_debug(RIG_DEBUG_ERR, "%s: radio address too long (max %d): %s\n",
++ __func__, (int)sizeof(config.host) - 1, rp->pathname);
++ return -RIG_EINVAL;
++ }
++
++ SNPRINTF(config.host, sizeof(config.host), "%s", rp->pathname);
+ colon = strchr(config.host, ':');
+
+ if (colon)
+ {
+ *colon = '\0';
+ config.control_port = (uint16_t)atoi(colon + 1);
+ }
+
+ if (priv->net_control_port)
+ {
+ config.control_port = (uint16_t)priv->net_control_port;
+ }
+
- strncpy(config.username, priv->net_username, sizeof(config.username) - 1);
- strncpy(config.password, priv->net_password, sizeof(config.password) - 1);
- strncpy(config.client_name, "hamlib", sizeof(config.client_name) - 1);
++ SNPRINTF(config.username, sizeof(config.username), "%s",
++ priv->net_username);
++ SNPRINTF(config.password, sizeof(config.password), "%s",
++ priv->net_password);
++ SNPRINTF(config.client_name, sizeof(config.client_name), "%s", "hamlib");
+
+ const struct icom_network_model *m =
+ icom_network_find_model(STATE(rig)->rig_model);
+
+ if (m == NULL)
+ {
+ return -RIG_EINVAL;
+ }
+
- strncpy(config.radio_name, m->radio_name, sizeof(config.radio_name) - 1);
++ SNPRINTF(config.radio_name, sizeof(config.radio_name), "%s", m->radio_name);
+ config.radio_index = priv->net_radio_index;
+ /* net_liveness_timeout defaults to 0 in a zeroed priv, which would mean
+ * "disabled"; an untouched token should get the built-in default instead. */
+ config.liveness_timeout_ms = priv->net_liveness_timeout;
+ config.auto_reconnect = priv->net_auto_reconnect;
- strncpy(config.radio_select_name, priv->net_radio_name,
- sizeof(config.radio_select_name) - 1);
++ SNPRINTF(config.radio_select_name, sizeof(config.radio_select_name), "%s",
++ priv->net_radio_name);
+ priv->net_model = m;
+ /* Audio formats come from the config tokens; I/Q mode forces a stereo
+ * LPCM16 RX stream (I=left, Q=right) unless an RX codec was set explicitly. */
+ config.rx_codec = priv->net_rx_codec ? (uint8_t)priv->net_rx_codec
+ : (priv->net_iq_mode ? ICOM_NETWORK_CODEC_LPCM16S
+ : ICOM_NETWORK_CODEC_LPCM16);
+ config.tx_codec = priv->net_tx_codec ? (uint8_t)priv->net_tx_codec
+ : ICOM_NETWORK_CODEC_LPCM16;
+ config.sample_rate = priv->net_sample_rate ? (uint32_t)priv->net_sample_rate
+ : 48000;
+ config.tx_buffer_ms = priv->net_tx_latency ? (uint32_t)priv->net_tx_latency :
+ ICOM_NETWORK_DEFAULT_LATENCY_MS;
+ /* 0, the default, is in-order delivery with no audio retransmits. */
+ config.rx_reorder_ms = (uint32_t)priv->net_rx_latency;
+ /* RX-only models (e.g. IC-R8600) never reserve a TX audio path; on TX
+ * capable models the radio must reserve it at connect for a TX stream to
+ * work later, so it defaults on (no audio transmits without PTT + a TX
+ * stream) and the net_tx_enable token can force it off. */
+ config.tx_enable = m->rx_only ? 0 : priv->net_tx_enable;
+
+ sess = icom_network_session_alloc(&config);
+
+ if (sess == NULL)
+ {
+ return -RIG_ENOMEM;
+ }
+
+ icom_network_session_set_async_cb(sess, icom_network_async_frame, rig);
+ icom_network_session_set_lost_cb(sess, icom_network_session_state_changed,
+ rig);
+
+ ret = icom_network_session_connect(sess);
+
+ if (ret != RIG_OK)
+ {
+ icom_network_session_free(sess);
+ return ret;
+ }
+
+ priv->netsession = sess;
+ /* The negotiated geometry is known only now, and no stream can open
+ * before this returns, so this is the moment to publish what the session
+ * can carry. Without it the frontend would resolve streams against the
+ * model declaration, which describes every configuration rather than this
+ * one -- and a stream opened on that basis reads the wire at the wrong
+ * width. Refuse the open rather than serve it wrongly. */
+ ret = icom_network_publish_session_caps(rig, &config);
+
+ if (ret != RIG_OK)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: could not publish session caps: %s\n",
+ __func__, rigerror(ret));
+ priv->netsession = NULL;
+ icom_network_session_free(sess);
+ return ret;
+ }
+
+ /* The session layer strips the radio's CI-V command echo, so the icom
+ * transaction layer must not expect an echo of its own frames. */
+ priv->serial_USB_echo_off = 1;
+
+ /* run the standard icom open sequence; CI-V now flows over the session */
+ ret = icom_rig_open(rig);
+
+ if (ret != RIG_OK)
+ {
+ /* free so the disconnect (token-remove + DISCONNECT) releases the
+ * radio's streams/slot instead of leaving them reserved */
+ icom_network_session_free(priv->netsession);
+ priv->netsession = NULL;
+ }
+
+ return ret;
+}
+
+static int icom_network_close(RIG *rig)
+{
+ struct icom_priv_data *priv = (struct icom_priv_data *)STATE(rig)->priv;
+
+ icom_rig_close(rig);
+
+ if (priv->netsession)
+ {
+ icom_network_session_free(priv->netsession);
+ priv->netsession = NULL;
+ }
+
+ return RIG_OK;
+}
+
+/* ------------------------------------------------------------------ */
+/* audio codecs and timing */
+/* ------------------------------------------------------------------ */
+
+struct icom_network_stream_state
+{
+ RIG *rig;
+ struct rig_stream *stream;
+ struct icom_network_session *sess;
+ struct rig_audio_codec_state *codec;
+ pthread_t thread;
+ HAMLIB_ATOMIC int running; /* thread stop flag; read by the stream thread */
+ unsigned tx_send_errors; /* failed wire sends; first one is logged */
+ int thread_started;
+ enum icom_network_audio_user audio_user;
+ unsigned generation; /* the session connection this stream runs on */
+ int wire_channels; /* negotiated wire codec channel count */
+ int passthrough; /* the wire payload already is this stream's own
+ bytes, so it crosses the ring untouched */
+ size_t wire_frame_bytes; /* one frame on the wire, all channels */
+ uint8_t silence_fill; /* the byte that means silence in this stream's
+ format: 0 signed, 0x80 for unsigned bytes */
+ uint32_t wire_rate; /* negotiated wire sample rate (Hz) */
+ uint8_t *pcm_buffer; /* the stream's own format (one frame / one
+ payload); unused on a passthrough stream */
+ uint8_t *encode_buffer; /* wire-encoded data */
+ size_t pcm_buffer_length;
+ size_t encode_buffer_length;
+ size_t frame_bytes; /* TX: bytes read per frame, in the stream's
+ own format */
+ size_t native_frame_bytes; /* RX: bytes per sample frame of what is
+ written to the ring (the backend format) */
+ uint64_t native_pos; /* RX: samples produced so far in the backend's
+ own domain, including concealed and marked
+ losses; the time-anchor index */
+ uint64_t decoded_samples; /* RX, codec streams: samples decoded ... */
+ uint64_t decoded_wire_bytes; /* ... from this many wire bytes, which sizes
+ losses in samples */
+};
+
+/* Map a negotiated Icom network codec id to a Hamlib device codec. */
+static rig_audio_codec_t icom_network_codec_map(uint8_t net_codec)
+{
+ switch (net_codec)
+ {
+ case ICOM_NETWORK_CODEC_PCMU:
+ case ICOM_NETWORK_CODEC_PCMUS:
+ return RIG_AUDIO_CODEC_MULAW;
+
+ case ICOM_NETWORK_CODEC_ADPCM:
+ return RIG_AUDIO_CODEC_ADPCM_IMA;
+
+ default: /* LPCM family: 16-bit PCM passthrough */
+ return RIG_AUDIO_CODEC_NONE;
+ }
+}
+
+/* Linear PCM on the wire, in any of its widths. These are the codecs whose
+ * payload already IS the stream's own bytes -- 8-bit unsigned or 16-bit
+ * signed -- so nothing has to be done to them in either direction. The
+ * companded and block codecs (uLaw, ADPCM) genuinely encode, and have to be
+ * run through the codec layer. */
+static int icom_network_codec_is_lpcm(uint8_t net_codec)
+{
+ switch (net_codec)
+ {
+ case ICOM_NETWORK_CODEC_LPCM:
+ case ICOM_NETWORK_CODEC_LPCM8:
+ case ICOM_NETWORK_CODEC_LPCM16:
+ case ICOM_NETWORK_CODEC_LPCM8S:
+ case ICOM_NETWORK_CODEC_LPCM16S:
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+/* The 8-bit LPCM codecs carry UNSIGNED samples biased at 128, while the 16-bit
+ * ones are signed -- so they are the wire's PCM_U8, not a narrower version of
+ * the same thing. The device-link codec layer has no linear-8 codec (its
+ * "none" passthrough is the S16 pivot itself), so these two go through the
+ * frontend's U8 converter instead. */
+static int icom_network_codec_is_linear8(uint8_t net_codec)
+{
+ return net_codec == ICOM_NETWORK_CODEC_LPCM8
+ || net_codec == ICOM_NETWORK_CODEC_LPCM8S;
+}
+
+/* The one sample format a session serves without touching the bytes.
+ *
+ * For the 8-bit LPCM codecs that is PCM_U8: their wire samples already are
+ * unsigned bytes, which is the point of choosing them -- half the network
+ * traffic, and nothing to do at either end. Every other codec decodes to the
+ * 16-bit pivot. Reaching any other format is the frontend's conversion, so
+ * exactly one format belongs here: naming a second would claim the backend
+ * serves it for free when it does not. uLaw is one byte on the wire too and
+ * saves as much traffic, but it is companded rather than linear and Hamlib
+ * has no uLaw sample format, so it only ever arrives through the pivot. */
+static rig_stream_format_t icom_network_session_formats(uint8_t net_codec)
+{
+ return icom_network_codec_is_linear8(net_codec)
+ ? RIG_STREAM_FORMAT_PCM_U8
+ : RIG_STREAM_FORMAT_PCM_S16;
+}
+
+/* ------------------------------------------------------------------ */
+/* audio stream threads */
+/* ------------------------------------------------------------------ */
+
+/* Turn one received payload into the bytes this stream carries, and say how
+ * many there are. Returns 0 when the payload yields nothing to write. */
+static size_t icom_network_rx_decode(struct icom_network_stream_state *st,
+ size_t received, const uint8_t **out)
+{
+ size_t pcm_bytes = 0;
+
+ /* The stereo LPCM16 payload {L,R,...} already is IQ_CS16 {I,Q,...}. Hand
+ * over whole complex frames only: a payload ending mid-frame would swap I
+ * and Q for everything after it, which no consumer can detect. */
+ if (stream_type_is_iq(st->stream->type))
+ {
+ *out = st->encode_buffer;
+ return received - (received % ICOM_NETWORK_IQ_FRAME_BYTES);
+ }
+
+ /* Linear PCM on the wire is already this stream's own bytes, whatever its
+ * width, so it goes to the ring as it arrived -- no codec, no copy. Hand
+ * over whole frames only: a payload ending mid-frame would put the
+ * channels out of phase for everything after it. */
+ if (st->passthrough)
+ {
+ *out = st->encode_buffer;
+ return received - (received % st->wire_frame_bytes);
+ }
+
+ /* The companded and block codecs genuinely decode, to the 16-bit pivot. */
+ *out = st->pcm_buffer;
+
+ if (rig_audio_convert_to_pcm(st->codec, st->encode_buffer, received,
+ RIG_STREAM_FORMAT_PCM_S16, st->pcm_buffer,
+ st->pcm_buffer_length, &pcm_bytes) != RIG_OK)
+ {
+ return 0;
+ }
+
+ return pcm_bytes;
+}
+
+/* A host-clock anchor about once a second, so a consumer can put the samples
+ * on a wall clock, and one right after every loss, flagged as a discontinuity.
+ * The index is the backend's own sample position: the frontend rescales it
+ * under rate conversion, which rig_stream_get_samples_written() would already
+ * have done once. */
+static void icom_network_rx_push_anchor(struct icom_network_stream_state *st,
+ uint8_t flags)
+{
+ struct rig_stream_time_anchor a;
+
+ memset(&a, 0, sizeof(a));
+ a.sample_index = st->native_pos;
+ stream_time_now(&a.seconds, &a.picoseconds);
+ a.source = RIG_STREAM_TIME_SRC_HOST;
+ a.accuracy = RIG_STREAM_TIME_ACC_MS;
+ a.flags = flags;
+ rig_stream_push_time_anchor(st->stream, &a);
+}
+
+/* Wire bytes of this stream's codec, in samples of what reaches the ring. */
+static uint64_t icom_network_rx_wire_samples(
+ const struct icom_network_stream_state *st, uint64_t wire_bytes)
+{
+ if (stream_type_is_iq(st->stream->type))
+ {
+ return wire_bytes / ICOM_NETWORK_IQ_FRAME_BYTES;
+ }
+
+ if (st->passthrough)
+ {
+ return wire_bytes / st->wire_frame_bytes;
+ }
+
+ /* Companded and block codecs: use the ratio actually decoded so far. */
+ if (st->decoded_wire_bytes > 0)
+ {
+ return wire_bytes * st->decoded_samples / st->decoded_wire_bytes;
+ }
+
+ return wire_bytes / (uint64_t)st->wire_channels;
+}
+
+/* Report what the session lost before this payload, in the terms the stream
+ * needs, before the payload itself is written. Audio is concealed with
+ * silence so playback stays continuous; I/Q is marked as an index hole,
+ * because invented samples would corrupt the phase a demodulator tracks. */
+static void icom_network_rx_account_loss(struct icom_network_stream_state *st,
+ const struct icom_network_audio_loss *loss)
+{
+ struct rig_stream *stream = st->stream;
+ int iq = stream_type_is_iq(stream->type);
+ uint64_t lost, overrun;
+
+ if (loss->lost_packets == 0 && !loss->lost_unsized
+ && loss->overrun_bytes == 0)
+ {
+ return;
+ }
+
+ lost = icom_network_rx_wire_samples(st, loss->lost_bytes);
+ overrun = icom_network_rx_wire_samples(st, loss->overrun_bytes);
+
+ rig_debug(RIG_DEBUG_VERBOSE,
+ "%s: lost %u packet(s) (~%llu samples)%s, queue overrun %llu "
+ "samples\n", __func__, loss->lost_packets,
+ (unsigned long long)lost, loss->lost_unsized ? " + unsized" : "",
+ (unsigned long long)overrun);
+
+ /* A stateful codec must not predict across the hole. */
+ rig_audio_codec_reset(st->codec);
+
+ if (overrun > 0)
+ {
+ if (iq)
+ {
+ stream_skip_samples(stream, overrun, STREAM_DROP_LOCAL_OVERRUN);
+ }
+ else
+ {
+ (void)stream_fill_gap(stream, overrun, RIG_STREAM_DROP_OVERRUN);
+ }
+
+ st->native_pos += overrun;
+ }
+
+ /* Lost packets whose size is not known yet count as an unsized loss. */
+ if (loss->lost_unsized || (loss->lost_packets > 0 && lost == 0))
+ {
+ if (iq) { (void)rig_stream_mark_gap(stream, 0); }
+ else { (void)stream_fill_gap(stream, 0, RIG_STREAM_DROP_GAP); }
+ }
+
+ if (lost > 0)
+ {
+ if (iq) { (void)rig_stream_mark_gap(stream, lost); }
+ else { (void)stream_fill_gap(stream, lost, RIG_STREAM_DROP_GAP); }
+
+ st->native_pos += lost;
+ }
+
+ icom_network_rx_push_anchor(st, RIG_STREAM_TIME_FLAG_DISCONTINUITY);
+}
+
+/* Has the connection this stream started on gone away -- lost, or replaced by
+ * a background reconnect? Then the stream is failed with the reason it ended:
+ * a stream is never carried over to a new connection, the application
+ * reopens it. */
+static int icom_network_stream_ended(struct icom_network_stream_state *st)
+{
+ unsigned reason;
+
+ if (icom_network_session_is_current(st->sess, st->generation, &reason))
+ {
+ return 0;
+ }
+
+ stream_mark_failed(st->stream, reason);
+ return 1;
+}
+
+static void *icom_network_rx_thread(void *arg)
+{
+ struct icom_network_stream_state *st = arg;
+ struct rig_stream *stream = st->stream;
+ struct icom_network_audio_loss loss;
+ int64_t last_anchor = 0;
+
+ while (st->running)
+ {
+ const uint8_t *out = NULL;
+ size_t length;
+ int64_t now;
+ int n;
+
+ if (icom_network_stream_ended(st))
+ {
+ /* A blocked reader wakes with -RIG_EIO: the samples are not
+ * merely late, the connection they came from is gone. */
+ break;
+ }
+
+ n = icom_network_audio_recv(st->sess, st->generation, st->encode_buffer,
+ st->encode_buffer_length, 100, &loss);
+
+ /* A timeout is ordinary: the anchor below still has to be pushed, so
+ * this only skips the decode. */
+ if (n > 0)
+ {
+ icom_network_rx_account_loss(st, &loss);
+ length = icom_network_rx_decode(st, (size_t)n, &out);
+
+ if (length > 0)
+ {
+ uint64_t samples = length / st->native_frame_bytes;
+
+ (void)stream_backend_write(stream, out, length);
+ st->native_pos += samples;
+
+ if (!st->passthrough && !stream_type_is_iq(stream->type))
+ {
+ st->decoded_samples += samples;
+ st->decoded_wire_bytes += (uint64_t)n;
+ }
+ }
+ }
+
+ now = icom_network_now_ms();
+
+ if (now - last_anchor >= 1000)
+ {
+ icom_network_rx_push_anchor(st, 0);
+ last_anchor = now;
+ }
+ }
+
+ return NULL;
+}
+
+/* Fill one wire frame from the ring, padding a genuine underrun with silence.
+ * Returns the bytes gathered, which is 0 when the producer had nothing at all. */
+static size_t icom_network_tx_fill_frame(struct icom_network_stream_state *st,
+ size_t frame_bytes)
+{
+ struct rig_stream *stream = st->stream;
+ size_t got = 0;
+
+ while (got < frame_bytes && st->running)
+ {
+ size_t n = stream_ringbuf_read(&stream->ringbuf, st->pcm_buffer + got,
+ frame_bytes - got, 100);
+
+ if (n == 0) { break; } /* underrun: no data within the timeout */
+
+ got += n;
+ }
+
+ /* A partial frame because the stream is closing is not an underrun: the
+ * producer did not stall, the loop was told to stop. Padding and warning
+ * about it would report a fault on every clean close. */
+ if (got == 0 || got >= frame_bytes || !st->running) { return got; }
+
+ rig_debug(RIG_DEBUG_WARN,
+ "%s: TX underrun, padded %zu of %zu bytes with silence\n",
+ __func__, frame_bytes - got, frame_bytes);
+ /* Silence is the midpoint of the sample range, which is zero for the
+ * signed pivot but 128 for unsigned bytes -- zero there is full-scale
+ * negative, i.e. a click at every underrun. */
+ memset(st->pcm_buffer + got, st->silence_fill, frame_bytes - got);
+
+ return frame_bytes;
+}
+
+/* Encode one frame into what goes on the wire. Returns the wire length and
+ * points *out at it; 0 means the frame produced nothing to send. */
+static size_t icom_network_tx_encode(struct icom_network_stream_state *st,
+ size_t frame_bytes, const uint8_t **out)
+{
+ size_t enc_bytes = 0;
+
+ /* A linear-PCM stream already holds the wire layout, so there is no
+ * encoding step at all: the frame goes out as it came off the ring. */
+ if (st->passthrough)
+ {
+ *out = st->pcm_buffer;
+ return frame_bytes;
+ }
+
+ *out = st->encode_buffer;
+
+ if (rig_audio_convert_from_pcm(st->codec, RIG_STREAM_FORMAT_PCM_S16,
+ st->pcm_buffer, frame_bytes,
+ st->encode_buffer, st->encode_buffer_length,
+ &enc_bytes) != RIG_OK)
+ {
+ return 0;
+ }
+
+ return enc_bytes;
+}
+
+/* Send one wire frame as max-payload packets (a 1920-byte LPCM16 frame travels
+ * as 1364 + 556). */
+static void icom_network_tx_send_fragments(struct icom_network_stream_state *st,
+ const uint8_t *wire, size_t length)
+{
+ size_t off = 0;
+
+ while (off < length)
+ {
+ size_t chunk = length - off;
+
+ if (chunk > ICOM_NETWORK_AUDIO_MAX_PAYLOAD)
+ {
+ chunk = ICOM_NETWORK_AUDIO_MAX_PAYLOAD;
+ }
+
+ if (icom_network_audio_send(st->sess, st->generation, wire + off,
+ chunk) < 0)
+ {
+ /* Logged once: this runs per wire frame, so a persistent fault
+ * would otherwise flood the log. The total is reported when the
+ * stream closes. */
+ if (st->tx_send_errors == 0)
+ {
+ rig_debug(RIG_DEBUG_WARN, "%s: TX audio send failed\n", __func__);
+ }
+
+ st->tx_send_errors++;
+ }
+
+ off += chunk;
+ }
+}
+
+/* TX thread: pull one frame from the ring, encode it, and put it on the wire.
+ * The application producer runs in real time, so a full frame becomes ready
+ * about once per frame duration and that paces the radio's receive framing. */
+static void *icom_network_tx_thread(void *arg)
+{
+ struct icom_network_stream_state *st = arg;
+ size_t frame_bytes = st->frame_bytes;
+
+ while (st->running)
+ {
+ const uint8_t *wire = NULL;
+ size_t got, enc_bytes;
+
+ if (icom_network_stream_ended(st))
+ {
+ /* Nothing to transmit to: the writer is told instead of being
+ * left to fill the ring for a connection that is gone. */
+ break;
+ }
+
+ got = icom_network_tx_fill_frame(st, frame_bytes);
+
+ if (!st->running) { break; }
+
+ if (got == 0) { continue; } /* nothing produced; the ping keeps it up */
+
+ enc_bytes = icom_network_tx_encode(st, frame_bytes, &wire);
+
+ if (enc_bytes > 0)
+ {
+ icom_network_tx_send_fragments(st, wire, enc_bytes);
+ }
+ }
+
+ return NULL;
+}
+
+/* Release everything a stream state owns. Every failure path in stream_open
+ * and the normal teardown in stream_close go through here, so the buffers
+ * cannot be forgotten on one path and freed on another. */
+/* ------------------------------------------------------------------ */
+/* stream open / close */
+/* ------------------------------------------------------------------ */
+
+static void icom_network_stream_state_free(struct icom_network_stream_state *st)
+{
+ if (st == NULL)
+ {
+ return;
+ }
+
+ rig_audio_codec_close(st->codec);
+ free(st->pcm_buffer);
+ free(st->encode_buffer);
+ free(st);
+}
+
+/* Can this session serve the stream at all? Checked before anything is
+ * allocated, so a refusal costs nothing. */
+static int icom_network_stream_check_openable(struct rig_stream *stream,
+ struct icom_network_session *sess)
+{
+ if (sess == NULL)
+ {
+ return -RIG_EIO;
+ }
+
+ if (!icom_network_session_is_valid(sess))
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: session is not connected\n", __func__);
+ return -RIG_EIO;
+ }
+
+ /* The model's stream capabilities are static, but whether a TX audio path
+ * exists is only known once the radio has answered the capabilities
+ * exchange, so the check belongs here rather than in the caps table. */
+ int tx_available = icom_network_session_tx_audio_available(sess);
+
+ if (!stream_type_is_rx(stream->type) && !tx_available)
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: radio advertises no TX audio at the negotiated rate\n",
+ __func__);
+ return -RIG_ENAVAIL;
+ }
+
+ return RIG_OK;
+}
+
+
+/* Resolve the wire geometry from the negotiated codec, open the codec and size
+ * the two working buffers. On failure st owns whatever was allocated and the
+ * caller frees it. */
+static int icom_network_stream_setup(RIG *rig, struct rig_stream *stream,
+ struct icom_network_stream_state *st)
+{
+ const struct icom_network_session_config *scfg =
+ icom_network_session_config(st->sess);
+ int is_rx = stream_type_is_rx(stream->type);
+ uint8_t net_codec = is_rx ? scfg->rx_codec : scfg->tx_codec;
+ int wire_sb = icom_network_codec_sample_bytes(net_codec);
+ int codec_channels = icom_network_codec_channels(net_codec);
+
+ /* backend_config is the configuration the frontend resolved this stream
+ * to, and the negotiated codec is what the wire can carry. They agree
+ * while the advertised caps describe the session, so a disagreement means
+ * the caps are wrong. Refuse it: running at a geometry the codec cannot
+ * represent produces audio at the wrong speed while every counter stays at
+ * zero. I/Q is exempt because it rides a stereo codec as a single complex
+ * channel. */
+ rig_stream_format_t session_format = icom_network_session_formats(net_codec);
+
+ if (!stream_type_is_iq(stream->type)
+ && (stream->backend_config.sample_rate != (int)scfg->sample_rate
+ || stream->backend_config.channels != codec_channels
+ || stream->backend_config.format != session_format))
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: stream resolved to %d Hz %d ch format 0x%x, but the "
+ "codec carries %u Hz %d ch format 0x%x\n", __func__,
+ stream->backend_config.sample_rate,
+ stream->backend_config.channels,
+ (unsigned)stream->backend_config.format,
+ (unsigned)scfg->sample_rate, codec_channels,
+ (unsigned)session_format);
+ return -RIG_ECONF;
+ }
+
+ st->wire_rate = (uint32_t)scfg->sample_rate;
+ st->wire_channels = codec_channels;
+ /* A session declares exactly one native format, so the frontend always
+ * resolves these streams to it and anything else the application wants is
+ * the frontend's conversion on the far side of the ring. Where that format
+ * is what the wire already carries -- the whole linear-PCM family -- the
+ * payload needs nothing done to it in either direction. */
+ st->passthrough = icom_network_codec_is_lpcm(net_codec);
+ st->wire_frame_bytes = (size_t)wire_sb * (size_t)st->wire_channels;
+ /* What an RX stream writes to the ring: the wire bytes as they are for
+ * I/Q and linear PCM, the decoded 16-bit pivot otherwise. */
+ st->native_frame_bytes = stream_type_is_iq(stream->type)
+ ? ICOM_NETWORK_IQ_FRAME_BYTES
+ : st->passthrough ? st->wire_frame_bytes
+ : 2u * (size_t)st->wire_channels;
+ st->silence_fill =
+ stream->backend_config.format == RIG_STREAM_FORMAT_PCM_U8 ? 0x80 : 0x00;
+
+ /* The codec runs at the wire channel count. */
+ st->codec = rig_audio_codec_open(icom_network_codec_map(net_codec),
+ st->wire_channels);
+
+ /* One unit of work each way, in this stream's own format: RX one packet
+ * payload, TX one wire frame. Both hold native data only; reaching the
+ * format, channel count and rate the application asked for belongs to the
+ * frontend, on the far side of the ring. */
+ if (is_rx)
+ {
+ st->encode_buffer_length = ICOM_NETWORK_AUDIO_MAX_PAYLOAD;
+ /* A one-byte codec doubles in width when decoded to the S16 pivot, so
+ * size for the widest case rather than the wire. */
+ st->pcm_buffer_length = ICOM_NETWORK_AUDIO_MAX_PAYLOAD
+ / (size_t)wire_sb * 2;
+ st->frame_bytes = 0;
+ }
+ else
+ {
+ int frame_ms = ((struct icom_priv_data *)STATE(rig)->priv)
+ ->net_tx_frame_ms;
+ size_t per_ch;
+
+ if (frame_ms <= 0)
+ {
+ frame_ms = ICOM_NETWORK_TX_FRAME_MS;
+ }
+
+ per_ch = (size_t)st->wire_rate * (size_t)frame_ms / 1000;
+
+ if (per_ch == 0)
+ {
+ per_ch = 1;
+ }
+
+ /* The ring is read in the stream's own format: the wire's width when
+ * nothing is converted, the 16-bit pivot otherwise. */
+ st->frame_bytes = per_ch * (size_t)st->wire_channels
+ * (size_t)(st->passthrough ? wire_sb : 2);
+ st->encode_buffer_length = per_ch * (size_t)st->wire_channels
+ * (size_t)wire_sb;
+ st->pcm_buffer_length = st->frame_bytes;
+ }
+
+ /* A passthrough stream works out of one buffer: receive fills the wire
+ * buffer and hands it straight over, transmit fills the ring buffer and
+ * sends it as it stands. Only a codec stream needs both, one for each side
+ * of the decode. */
+ if (st->passthrough)
+ {
+ if (is_rx) { st->pcm_buffer_length = 0; }
+ else { st->encode_buffer_length = 0; }
+ }
+
+ st->pcm_buffer = st->pcm_buffer_length
+ ? malloc(st->pcm_buffer_length) : NULL;
+ st->encode_buffer = st->encode_buffer_length
+ ? malloc(st->encode_buffer_length) : NULL;
+
+ if (st->codec == NULL
+ || (st->pcm_buffer_length && st->pcm_buffer == NULL)
+ || (st->encode_buffer_length && st->encode_buffer == NULL))
+ {
+ return st->codec == NULL ? -RIG_EINVAL : -RIG_ENOMEM;
+ }
+
+ return RIG_OK;
+}
+
+
+static int icom_network_stream_open(RIG *rig, struct rig_stream *stream)
+{
+ struct icom_priv_data *priv = (struct icom_priv_data *)STATE(rig)->priv;
+ struct icom_network_session *sess = priv->netsession;
+ struct icom_network_stream_state *st;
+ void *(*thread_fn)(void *);
+ int ret;
+
+ ret = icom_network_stream_check_openable(stream, sess);
+
+ if (ret != RIG_OK)
+ {
+ return ret;
+ }
+
+ st = calloc(1, sizeof(*st));
+
+ if (st == NULL)
+ {
+ return -RIG_ENOMEM;
+ }
+
+ st->rig = rig;
+ st->stream = stream;
+ st->sess = sess;
+
+ ret = icom_network_stream_setup(rig, stream, st);
+
+ if (ret != RIG_OK)
+ {
+ icom_network_stream_state_free(st);
+ return ret;
+ }
+
+ /* Join the session's audio flow, starting it if this is the first stream.
+ * AUDIO_RX and IQ_RX are two views of the same received flow, so the
+ * session takes one reader of either kind and refuses a second. */
+ st->audio_user = stream_type_is_rx(stream->type) ? ICOM_NETWORK_AUDIO_RX
+ : ICOM_NETWORK_AUDIO_TX;
+ ret = icom_network_audio_start(sess, st->audio_user, &st->generation);
+
+ if (ret != RIG_OK)
+ {
+ icom_network_stream_state_free(st);
+ return ret;
+ }
+
+ thread_fn = stream_type_is_rx(stream->type) ? icom_network_rx_thread
+ : icom_network_tx_thread;
+ st->running = 1;
+
+ if (pthread_create(&st->thread, NULL, thread_fn, st) != 0)
+ {
+ st->running = 0;
+ icom_network_audio_stop(sess, st->audio_user, st->generation);
+ icom_network_stream_state_free(st);
+ return -RIG_EIO;
+ }
+
+ st->thread_started = 1;
+ stream->backend_priv = st;
+
+ return RIG_OK;
+}
+
+static int icom_network_stream_close(RIG *rig, struct rig_stream *stream)
+{
+ struct icom_network_stream_state *st =
+ (struct icom_network_stream_state *)stream->backend_priv;
+
+ (void)rig;
+
+ if (st == NULL)
+ {
+ return RIG_OK;
+ }
+
+ st->running = 0;
+
+ if (st->thread_started)
+ {
+ pthread_join(st->thread, NULL);
+ }
+
+ if (st->tx_send_errors > 0)
+ {
+ rig_debug(RIG_DEBUG_WARN, "%s: %u TX audio send failure(s) on this stream\n",
+ __func__, st->tx_send_errors);
+ }
+
+ /* Leave the audio flow. It keeps running for another open stream and stops
+ * with the last one, so a later RX stream never reads audio that queued
+ * up while nothing was open. */
+ icom_network_audio_stop(st->sess, st->audio_user, st->generation);
+
+ stream->backend_priv = NULL;
+ icom_network_stream_state_free(st);
+
+ return RIG_OK;
+}
+
+#define ICOM_NETWORK_MAX_MODELS 16
+/* ------------------------------------------------------------------ */
+/* model registry and capabilities */
+/* ------------------------------------------------------------------ */
+
+static const struct icom_network_model
+ *icom_network_models[ICOM_NETWORK_MAX_MODELS];
+/* The stream-caps buffer each model owns, parallel to the array above.
+ * rig_caps hands it out as const, but this backend built it and narrows the
+ * rates it advertises once a session has settled on one. */
+static struct rig_stream_caps
+ *icom_network_model_caps[ICOM_NETWORK_MAX_MODELS];
+static int icom_network_model_count;
+
+static const struct icom_network_model *icom_network_find_model(
+ rig_model_t model)
+{
+ int i;
+
+ for (i = 0; i < icom_network_model_count; i++)
+ {
+ if (icom_network_models[i]->rig_model == model)
+ {
+ return icom_network_models[i];
+ }
+ }
+
+ return NULL;
+}
+
+
+/* A session settles on one audio rate and one codec per direction at connect,
+ * and changing either means reconnecting, so until then they are the only
+ * geometry this backend can produce or accept. Advertise exactly that and let
+ * the frontend convert for any application wanting something else. Leaving
+ * the hardware's whole range up would let the frontend resolve to a native
+ * configuration no stream could be served at -- and a channel count is worse
+ * than a rate, because handing stereo to a mono codec is not refused
+ * anywhere: the wire bytes are simply read as twice as many mono samples.
+ * The I/Q entry carries its own fixed geometry and is left alone.
+ *
+ * The buffer belongs to the model, not the rig, so two rigs of one model in a
+ * single process share it -- the second connection's settings win. */
+static int icom_network_publish_session_caps(RIG *rig,
+ const struct icom_network_session_config *scfg)
+{
+ const struct rig_stream_caps *model = NULL;
+ struct rig_stream_caps session[HAMLIB_MAX_STREAM_CAPS];
+ /* Slots per wire frame, which is the audio channel count but only the
+ * carrier for I/Q -- see the I/Q branch below. */
+ int rx_codec_slots = icom_network_codec_channels(scfg->rx_codec);
+ int tx_codec_slots = icom_network_codec_channels(scfg->tx_codec);
+ int n = 0;
+ int i;
+
+ for (i = 0; i < icom_network_model_count; i++)
+ {
+ if (icom_network_models[i]->rig_model == STATE(rig)->rig_model)
+ {
+ model = icom_network_model_caps[i];
+ break;
+ }
+ }
+
+ if (model == NULL)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: no stream caps registered for model %u\n",
+ __func__, (unsigned)STATE(rig)->rig_model);
+ return -RIG_EINTERNAL;
+ }
+
+ memset(session, 0, sizeof(session));
+
+ for (i = 0; model[i].formats != 0 && n < HAMLIB_MAX_STREAM_CAPS; i++)
+ {
+ struct rig_stream_caps e = model[i];
+ int channels;
+
+ if (e.type == RIG_STREAM_TYPE_AUDIO_RX)
+ {
+ channels = rx_codec_slots;
+ e.formats = icom_network_session_formats(scfg->rx_codec);
+ }
+ else if (e.type == RIG_STREAM_TYPE_AUDIO_TX)
+ {
+ channels = tx_codec_slots;
+ e.formats = icom_network_session_formats(scfg->tx_codec);
+ }
+ else
+ {
+ /* I/Q is the RX audio path carrying {I,Q} pairs as IQ_CS16, so it
+ * needs the two slots of a stereo codec AND those slots must be
+ * signed 16-bit samples. Only LPCM16S is: the other two-slot
+ * codecs carry companded or unsigned bytes, and advertising I/Q
+ * over one of those hands an application something it will read as
+ * complex samples and hear as noise. A mono session has nowhere to
+ * put Q at all. Those two slots are the components of ONE complex
+ * channel, not two channels. */
+ if (scfg->rx_codec != ICOM_NETWORK_CODEC_LPCM16S)
+ {
+ continue;
+ }
+
+ channels = 1;
+ }
+
+ memset(e.sample_rates, 0, sizeof(e.sample_rates));
+ e.sample_rates[0] = (int)scfg->sample_rate;
+ memset(e.channels, 0, sizeof(e.channels));
+ e.channels[0] = channels;
+ session[n++] = e;
+ }
+
+ return stream_set_session_caps(rig, session, n);
+}
+
+/* Initialize the icom private data, then set the network audio defaults that
+ * must be non-zero (TX path enabled; the open clears it for RX-only models). */
+static int icom_network_init(RIG *rig)
+{
+ int ret = icom_init(rig);
+
+ if (ret == RIG_OK)
+ {
+ struct icom_priv_data *priv = (struct icom_priv_data *)STATE(rig)->priv;
+ priv->net_tx_enable = 1;
+ priv->net_tx_frame_ms = ICOM_NETWORK_TX_FRAME_MS;
+ priv->net_radio_index = -1;
+ priv->net_liveness_timeout = ICOM_NETWORK_DEFAULT_LIVENESS_MS;
+ }
+
+ return ret;
+}
+
+void icom_network_build_caps(struct rig_caps *out,
+ struct rig_stream_caps *stream_caps,
+ const struct icom_network_model *m)
+{
+ *out = *m->base_caps;
+ out->rig_model = m->rig_model;
+ out->macro_name = m->macro_name;
+ out->model_name = m->model_name;
+ out->status = m->status;
+ out->version = m->version;
+ out->port_type = RIG_PORT_CUSTOM;
+ out->rig_init = icom_network_init;
+ out->rig_open = icom_network_open;
+ out->rig_close = icom_network_close;
+ out->cfgparams = icom_network_config_params;
+ out->set_conf = icom_network_set_conf;
+ out->get_conf = icom_network_get_conf;
+ out->stream_open = icom_network_stream_open;
+ out->stream_close = icom_network_stream_close;
+
+ {
+ /* rig_caps.stream_caps is a pointer; fill the caller's per-model buffer
+ * sequentially (0-terminated by the memset) and point at it. */
+ struct rig_stream_caps rx, tx, iq;
+ int n = 0;
+ memset(stream_caps, 0,
+ HAMLIB_MAX_STREAM_CAPS * sizeof(*stream_caps));
+ memset(&rx, 0, sizeof(rx));
+ rx.type = RIG_STREAM_TYPE_AUDIO_RX;
+ /* Most wire codecs this radio offers -- LPCM16, uLaw, ADPCM -- are
+ * decoded to a 16-bit pivot, so the codec chosen through net_rx_codec
+ * decides what crosses the network but not what this backend produces.
+ * The two 8-bit LPCM codecs are the exception: their wire samples are
+ * unsigned bytes, which is PCM_U8 exactly, so a session that has
+ * negotiated one can hand an application the network bytes with
+ * nothing done to them. Both are therefore reachable on this model;
+ * which one a given connection can serve is pinned once it has
+ * negotiated. Anything else an application asks for is the frontend's
+ * conversion to make. */
+ rx.formats = RIG_STREAM_FORMAT_PCM_S16 | RIG_STREAM_FORMAT_PCM_U8;
+ {
+ /* ICOM_NETWORK_SUPPORTED_RATES is in the radio's own preference
+ * order, highest first, and net_sample_rate is a combo whose value
+ * is an index into it, so that order is part of the public
+ * configuration and cannot be changed here. A caps rate list is an
+ * ascending set, so read the same single source of truth back to
+ * front. dump_caps checks the result, so a future edit that breaks
+ * this assumption surfaces as a warning rather than silently. */
+ static const int supported[] = ICOM_NETWORK_SUPPORTED_RATES;
+ int count = ICOM_NETWORK_SUPPORTED_RATE_COUNT;
+ int r;
+
+ if (count > HAMLIB_MAX_STREAM_RATES)
+ {
+ count = HAMLIB_MAX_STREAM_RATES;
+ }
+
+ for (r = 0; r < count; r++)
+ {
+ rx.sample_rates[r] = supported[count - 1 - r];
+ }
+ }
+ /* Both counts are reachable: the mono and stereo codecs are the same
+ * hardware, chosen by net_rx_codec. Which one this session can
+ * actually carry is pinned once it has negotiated. */
+ rx.channels[0] = 1;
+ rx.channels[1] = 2;
+ rx.max_streams = 1;
+ stream_caps[n++] = rx;
+
+ if (!m->rx_only)
+ {
+ tx = rx;
+ tx.type = RIG_STREAM_TYPE_AUDIO_TX;
+ stream_caps[n++] = tx;
+ }
+
+ if (m->iq_capable)
+ {
+ memset(&iq, 0, sizeof(iq));
+ iq.type = RIG_STREAM_TYPE_IQ_RX;
+ /* The stereo LPCM16 payload is already {I,Q,...}; CS16 is what
+ * comes off the wire and so all this backend natively has. */
+ iq.formats = RIG_STREAM_FORMAT_IQ_CS16;
+ iq.sample_rates[0] = 48000;
+ /* The stereo payload is one complex stream, not two channels. */
+ iq.channels[0] = 1;
+ iq.max_streams = 1;
+ stream_caps[n++] = iq;
+ }
+
+ out->stream_caps = stream_caps;
+ }
+
+ if (icom_network_model_count < ICOM_NETWORK_MAX_MODELS)
+ {
+ icom_network_model_caps[icom_network_model_count] = stream_caps;
+ icom_network_models[icom_network_model_count++] = m;
+ }
+}
diff --cc rigs/icom/network_session.c
index c2aa50bc6,000000000..7cd1f9c09
mode 100644,000000..100644
--- a/rigs/icom/network_session.c
+++ b/rigs/icom/network_session.c
@@@ -1,3102 -1,0 +1,3103 @@@
+/*
+ * Hamlib Icom network backend - session and state machine
+ * Copyright (c) 2026 by Mikael Nousiainen OH3BHX
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+/* Icom network protocol Layer 2: session/state machine over the 3 UDP sockets. */
+/* Runs the handshake, owns per-socket keepalive/retransmit threads, and bridges */
+/* complete CI-V frames to the icom transaction layer. */
+
+#include "hamlib/config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <pthread.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+/* Windows has no BSD socket headers; pull in winsock the same way src/network.c
+ * does, including the _WIN32_WINNT bump that inet_pton needs. */
+#if defined(HAVE_WS2TCPIP_H) && !defined(HAVE_SYS_SOCKET_H)
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0600
+#include <ws2tcpip.h>
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0502
+#endif
+#ifdef __MINGW32__
+#include <winsock2.h>
+#endif
+
+/* Sockets are closed with closesocket() on Windows and close() elsewhere;
+ * wrapped once so the three call sites stay readable. */
+static void icom_network_session_close_fd(int fd)
+{
+#ifdef __MINGW32__
+ closesocket(fd);
+#else
+ close(fd);
+#endif
+}
+
+#include "hamlib/rig.h"
+#include "network_proto.h"
+#include "network_seqbuf.h"
+#include "network_session.h"
+#include "network_utils.h"
+
+#define ICOM_NETWORK_SESSION_PACKET_MAX 2048
+#define ICOM_NETWORK_SESSION_CIV_FRAME_MAX 256
+#define ICOM_NETWORK_SESSION_CIV_QUEUE_LENGTH 32
+#define ICOM_NETWORK_SESSION_AUDIO_FRAME_MAX 1600
+#define ICOM_NETWORK_SESSION_AUDIO_QUEUE_LENGTH 64
+/* Audio reorder window geometry. The fastest audio flow is 16-bit stereo at
+ * 48 kHz, three packets per 20 ms frame, i.e. 150 packets a second, so 256
+ * positions cover the longest (1000 ms) window with room to spare. A forward
+ * jump of more than MAX_GAP packets is treated as a restart, not a loss. */
+#define ICOM_NETWORK_SESSION_AUDIO_REORDER_SLOTS 256
+#define ICOM_NETWORK_SESSION_AUDIO_MAX_GAP 256
+/* Packets per radio frame tracked for loss sizing (stereo LPCM16 needs 3). */
+#define ICOM_NETWORK_SESSION_AUDIO_PHASES_MAX 8
+/* Spacing of repeated audio retransmit requests: half the reorder window, so
+ * even a short window gets a second attempt when the first resend is lost,
+ * within these bounds. Measured on an IC-7610 over a LAN, resends mostly
+ * arrive within 20 ms, so asking again sooner than that only duplicates. */
+#define ICOM_NETWORK_SESSION_AUDIO_RETRANSMIT_MIN_MS 20
+
+/* The audio receive loop never blocks longer than this, so it notices a stop
+ * request and sends its pings without anything arriving. */
+#define ICOM_NETWORK_SESSION_AUDIO_POLL_MS 50
+
+#define ICOM_NETWORK_SESSION_IDLE_MS 100
+#define ICOM_NETWORK_SESSION_PING_MS 500
+/* audio stream pings fast, inside the TX freshness window */
+#define ICOM_NETWORK_SESSION_AUDIO_PING_MS 100
+
+/* CI-V stream-open drain: the radio flushes frames left undelivered by the
+ * previous client as soon as a new stream opens; connect() discards them
+ * until the response queue stays quiet for QUIET_MS (bounded by TOTAL_MS). */
+#define ICOM_NETWORK_SESSION_CIV_DRAIN_QUIET_MS 50
+#define ICOM_NETWORK_SESSION_CIV_DRAIN_TOTAL_MS 250
+#define ICOM_NETWORK_SESSION_TOKEN_RENEW_MS 60000
+#define ICOM_NETWORK_SESSION_RETRANSMIT_MS 100
+#define ICOM_NETWORK_SESSION_PURGE_MS 10000
+#define ICOM_NETWORK_SESSION_HANDSHAKE_TIMEOUT_MS 500
+/* How long disconnect() keeps the threads alive after sending the stream
+ * closes, so the radio's retransmit requests for those packets can still be
+ * answered. Chosen to comfortably cover the radio's own retransmit latency
+ * (observed well under 100 ms) without stalling rig_close(). */
+#define ICOM_NETWORK_SESSION_DISCONNECT_GRACE_MS 300
+/* Auto-reconnect backoff. The radio holds a lost session's slot for its own
+ * timeout, ...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-10-29 16:36:06
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via add899a696ee3a664ac2c931b54852f98ee36093 (commit)
via 479dce7fc7b4233c2ca6456f6a05e412721dc2c0 (commit)
via 0e77a496d44ebada6e499a0c2059fdbf342ebf6b (commit)
via ce558ecc5108461b01c02fb02357719280692b86 (commit)
via 6dfb56096e2d4117d80d47c0cc5e1e95d19c600d (commit)
via 436b22a75148ed36175dd9247c987e265c475fa3 (commit)
via 8d6965907cb48aeba4eb7c8c386ec1130c71be81 (commit)
via e2b67bce5f6593647ce7a60a823dc440000f7154 (commit)
via 0147d62cc4b213c30961f87252aba3dc7ff8675b (commit)
via a8576f2913a5fddb3975678140cccf72556dde2b (commit)
via 8e79c2613a542826b891f943290c3bfd65ae5a14 (commit)
via 85f3a62867166a21db80ece034af76ff9e1e015d (commit)
via 8c9defa260808f848f07406e82e9c86c9fceffb9 (commit)
via bb045cdc68ca5f99d05884ffd08d475ccbc0fb2d (commit)
via dbd3f7964ac8014745d55cd8fc71f1a4992146d6 (commit)
via 2e49bb4566262b0824bff6bc1bb8e6b5f4d65c52 (commit)
via 72dcdd28cf43f2d2e8cfa0d035583d25d6f690ff (commit)
via 22406fa71f5b138d7efa21f6404f82d277d60693 (commit)
via ed69537f887aa4d43936bfcf56245ac19645bcd0 (commit)
via 6e67889a82139421f54cdffe778a7877a2a4302e (commit)
via 45c242c5fef5d6428fb4947fbf16ed0e068b8acc (commit)
via 14c618fe541fad68c62a28a1b27579924deb443c (commit)
via af176c31e622a9600448d56d0459385e0f6f140d (commit)
via 72a200305e9904538f0661d29d5dad31ebfb4085 (commit)
via 06cb75951717f082f6913ea09ebd26b552e86de8 (commit)
via 9e09cb3153c53e5b1507020e8cbe05e96dcdfb73 (commit)
via 04aedf35f0699a4a78914c85b0e5d2ae3bcbe353 (commit)
via e4a12d374ca386e2a9351cfea4cb0825849361d4 (commit)
via 58af5b2dd73ed0fadce794b3a6c13cabbee9a5ed (commit)
from 075b78cb0560e892c81bc73890d633cc11f23f59 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit add899a696ee3a664ac2c931b54852f98ee36093
Author: David Christle <dch...@us...>
Date: Tue Oct 27 23:39:57 2026 -0700
fix(rigctl): recover from malformed long command names
Empty and overlong command names returned a fatal parser result and
ended interactive and daemon sessions. Discard only the malformed line
and continue, while keeping actual input failures fatal.
Cover recovery without executing trailing tokens or consuming the next
command, including a following password command.
diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c
index 0d986607e..4242e2419 100644
--- a/tests/rigctl_parse.c
+++ b/tests/rigctl_parse.c
@@ -667,7 +667,7 @@ static int read_long_command_name(FILE *fin, char *name, size_t name_size)
if (isspace((unsigned char)c))
{
- if (length > 0 && !too_long && ungetc(c, fin) == EOF)
+ if (ungetc(c, fin) == EOF)
{
return RIGCTL_PARSE_ERROR;
}
@@ -687,7 +687,7 @@ static int read_long_command_name(FILE *fin, char *name, size_t name_size)
name[length] = '\0';
- return length > 0 && !too_long ? RIG_OK : RIGCTL_PARSE_ERROR;
+ return length > 0 && !too_long ? RIG_OK : -RIG_EINVAL;
}
static int parse_protocol_freq(const char *token, freq_t *value)
@@ -1607,12 +1607,22 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc,
{
char cmd_name[MAXNAMSIZ + 1];
- if (read_long_command_name(fin, cmd_name,
- sizeof(cmd_name)) != RIG_OK)
+ retcode = read_long_command_name(fin, cmd_name,
+ sizeof(cmd_name));
+
+ if (retcode != RIG_OK)
{
rig_debug(RIG_DEBUG_WARN,
"%s: invalid long command name\n", __func__);
- return (RIGCTL_PARSE_ERROR);
+
+ if (retcode != -RIG_EINVAL)
+ {
+ return (RIGCTL_PARSE_ERROR);
+ }
+
+ while ((retcode = fgetc(fin)) != EOF && retcode != '\n');
+
+ return (ferror(fin) ? RIGCTL_PARSE_ERROR : RIG_OK);
}
cmd = parse_arg(cmd_name);
diff --git a/tests/testctlparser.c b/tests/testctlparser.c
index 8c5092646..ddb0a27c6 100644
--- a/tests/testctlparser.c
+++ b/tests/testctlparser.c
@@ -1749,7 +1749,7 @@ static int check_long_command_framing(RIG *rig)
ret = parse_interactive_text(rig, "\\\n\\password test-secret\n", 1,
NULL, 0, remaining, sizeof(remaining));
- if (ret != RIGCTL_PARSE_ERROR
+ if (ret != RIG_OK
|| strcmp(remaining, "\\password test-secret\n") != 0)
{
fprintf(stderr, "empty long command consumed next line: '%s'\n",
@@ -1757,6 +1757,40 @@ static int check_long_command_framing(RIG *rig)
return 1;
}
+ captured_freq = -1;
+ ret = parse_interactive_text(rig, "\\ set_freq 1\n\\set_freq 456\n", 2,
+ NULL, 0, NULL, 0);
+
+ if (ret != RIG_OK || captured_freq != 456)
+ {
+ fprintf(stderr, "empty long command name ended the session\n");
+ return 1;
+ }
+
+ captured_freq = -1;
+ ret = parse_interactive_text(rig,
+ "\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa set_freq 1\n"
+ "\\set_freq 789\n", 2, NULL, 0, NULL, 0);
+
+ if (ret != RIG_OK || captured_freq != 789)
+ {
+ fprintf(stderr, "overlong long command name ended the session\n");
+ return 1;
+ }
+
+ ret = parse_interactive_text(rig,
+ "\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
+ "\\password test-secret\n", 1, NULL, 0,
+ remaining, sizeof(remaining));
+
+ if (ret != RIG_OK
+ || strcmp(remaining, "\\password test-secret\n") != 0)
+ {
+ fprintf(stderr, "overlong long command consumed next line: '%s'\n",
+ remaining);
+ return 1;
+ }
+
return 0;
}
commit 479dce7fc7b4233c2ca6456f6a05e412721dc2c0
Author: David Christle <dch...@us...>
Date: Mon Oct 26 12:09:59 2026 -0700
fix(rigctl): keep long commands within one input line
Read command names without skipping line delimiters.
Reject empty and overlong names before dispatch.
Preserve complete commands at EOF and cover stale replay and cross-line
consumption.
diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c
index 52a1b692b..0d986607e 100644
--- a/tests/rigctl_parse.c
+++ b/tests/rigctl_parse.c
@@ -634,6 +634,62 @@ static int scanfc(FILE *fin, const char *format, void *p)
while (1);
}
+static int read_long_command_name(FILE *fin, char *name, size_t name_size)
+{
+ size_t length = 0;
+ int too_long = 0;
+ int c;
+
+ name[0] = '\0';
+
+ while (1)
+ {
+ errno = 0;
+ c = fgetc(fin);
+
+ if (c == EOF)
+ {
+ if (ferror(fin) && errno == EINTR)
+ {
+ clearerr(fin);
+ continue;
+ }
+
+ if (ferror(fin))
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: errno=%d, %s\n", __func__, errno,
+ strerror(errno));
+ return RIGCTL_PARSE_ERROR;
+ }
+
+ break;
+ }
+
+ if (isspace((unsigned char)c))
+ {
+ if (length > 0 && !too_long && ungetc(c, fin) == EOF)
+ {
+ return RIGCTL_PARSE_ERROR;
+ }
+
+ break;
+ }
+
+ if (length + 1 < name_size)
+ {
+ name[length++] = (char)c;
+ }
+ else
+ {
+ too_long = 1;
+ }
+ }
+
+ name[length] = '\0';
+
+ return length > 0 && !too_long ? RIG_OK : RIGCTL_PARSE_ERROR;
+}
+
static int parse_protocol_freq(const char *token, freq_t *value)
{
return rigctl_parse_double(token, RIGCTL_DECIMAL_DOT_OR_COMMA, value) == RIG_OK;
@@ -1442,7 +1498,6 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc,
char arg3[MAXARGSZ + 1], *p3 = NULL;
vfo_t vfo = RIG_VFO_CURR;
char client_version[32];
- char name_format[8];
char arg_format[8];
int open_retcode = RIG_OK;
int password_authenticated;
@@ -1455,7 +1510,6 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc,
rig_debug(RIG_DEBUG_TRACE, "%s: called, interactive=%d\n", __func__,
interactive);
- SNPRINTF(name_format, sizeof(name_format), "%%%ds", MAXNAMSIZ - 1);
SNPRINTF(arg_format, sizeof(arg_format), "%%%ds", MAXARGSZ - 1);
/* cmd, internal, rigctld */
@@ -1551,22 +1605,17 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc,
/* command by name */
if (cmd == '\\')
{
- char cmd_name[MAXNAMSIZ + 1], *pcmd = cmd_name;
+ char cmd_name[MAXNAMSIZ + 1];
- if (scanfc(fin, "%c", pcmd) < 1)
+ if (read_long_command_name(fin, cmd_name,
+ sizeof(cmd_name)) != RIG_OK)
{
- rig_debug(RIG_DEBUG_WARN, "%s: nothing to scan#4?\n", __func__);
+ rig_debug(RIG_DEBUG_WARN,
+ "%s: invalid long command name\n", __func__);
return (RIGCTL_PARSE_ERROR);
}
- retcode = fscanf(fin, name_format, ++pcmd); // Get the rest of the command
-
- if (retcode == 0 || retcode == EOF) { rig_debug(RIG_DEBUG_WARN, "%s: unable to scan %c\n", __func__, *(pcmd - 1)); }
-
- while (*++pcmd);
-
- *pcmd = '\0';
- cmd = parse_arg((char *)cmd_name);
+ cmd = parse_arg(cmd_name);
rig_debug(RIG_DEBUG_VERBOSE, "%s: cmd=%s handle=%d\n", __func__, cmd_name,
fileno(fin));
break;
diff --git a/tests/testctlparser.c b/tests/testctlparser.c
index 492caf8ca..8c5092646 100644
--- a/tests/testctlparser.c
+++ b/tests/testctlparser.c
@@ -1655,6 +1655,111 @@ done:
return result;
}
+static int parse_interactive_text(RIG *rig, const char *text, int parse_count,
+ char *response, size_t response_size,
+ char *remaining, size_t remaining_size)
+{
+ FILE *input = tmpfile();
+ FILE *output = tmpfile();
+ char *argv[] = { "testctlparser" };
+ int vfo_mode = 0;
+ int ext_resp = 0;
+ char resp_sep = '\n';
+ int ret = RIGCTL_PARSE_ERROR;
+
+ if (response != NULL && response_size > 0) { response[0] = '\0'; }
+
+ if (remaining != NULL && remaining_size > 0) { remaining[0] = '\0'; }
+
+ if (input == NULL || output == NULL)
+ {
+ if (input != NULL) { fclose(input); }
+
+ if (output != NULL) { fclose(output); }
+
+ return ret;
+ }
+
+ fputs(text, input);
+ rewind(input);
+
+ for (int i = 0; i < parse_count; i++)
+ {
+ ret = rigctl_parse(rig, input, output, argv, 1, NULL, 1, 0,
+ &vfo_mode, 0, &ext_resp, &resp_sep, 0);
+
+ if (ret != RIG_OK)
+ {
+ break;
+ }
+ }
+
+ if (response != NULL && response_size > 0)
+ {
+ fflush(output);
+ rewind(output);
+ response[fread(response, 1, response_size - 1, output)] = '\0';
+ }
+
+ if (remaining != NULL && remaining_size > 0)
+ {
+ remaining[fread(remaining, 1, remaining_size - 1, input)] = '\0';
+ }
+
+ fclose(input);
+ fclose(output);
+ return ret;
+}
+
+static int check_long_command_framing(RIG *rig)
+{
+ char response[64];
+ char remaining[64];
+ int ret;
+
+ ret = parse_interactive_text(rig, "\\chk_vfo\n\\c", 2, response,
+ sizeof(response), NULL, 0);
+
+ if (ret != RIG_OK || strcmp(response, "0\n") != 0)
+ {
+ fprintf(stderr, "truncated long command replayed prior command: '%s'\n",
+ response);
+ return 1;
+ }
+
+ captured_freq = -1;
+ ret = parse_interactive_text(rig, "\\f\n\\set_freq 123\n", 2, NULL, 0,
+ NULL, 0);
+
+ if (ret != RIG_OK || captured_freq != 123)
+ {
+ fprintf(stderr, "single-character long command consumed next line\n");
+ return 1;
+ }
+
+ ret = parse_interactive_text(rig, "\\chk_vfo", 1, response,
+ sizeof(response), NULL, 0);
+
+ if (ret != RIG_OK || strcmp(response, "0\n") != 0)
+ {
+ fprintf(stderr, "complete long command at EOF failed: '%s'\n", response);
+ return 1;
+ }
+
+ ret = parse_interactive_text(rig, "\\\n\\password test-secret\n", 1,
+ NULL, 0, remaining, sizeof(remaining));
+
+ if (ret != RIGCTL_PARSE_ERROR
+ || strcmp(remaining, "\\password test-secret\n") != 0)
+ {
+ fprintf(stderr, "empty long command consumed next line: '%s'\n",
+ remaining);
+ return 1;
+ }
+
+ return 0;
+}
+
static int check_send_command(RIG *rig, const char *command,
const unsigned char *expected,
size_t expected_length)
@@ -2074,7 +2179,8 @@ int main(void)
return 1;
}
- if (check_description(rig, maximum, maximum) != 0
+ if (check_long_command_framing(rig) != 0
+ || check_description(rig, maximum, maximum) != 0
|| check_description(rig, thirty, maximum) != 0
|| check_description(rig, thirty_one, maximum) != 0)
{
commit 0e77a496d44ebada6e499a0c2059fdbf342ebf6b
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:18:34 2026 -0700
fix(network): avoid stale payload logging during flush
Log queued byte counts before receiving and keep the bounded hex dump.
diff --git a/src/network.c b/src/network.c
index 958075b3d..44f122e62 100644
--- a/src/network.c
+++ b/src/network.c
@@ -453,9 +453,8 @@ void network_flush(hamlib_port_t *rp)
{
int len_read = 0;
rig_debug(RIG_DEBUG_WARN,
- "%s: network data clear d: ret=%d, len=%d, '%s'\n",
- __func__,
- ret, (int)len, buffer);
+ "%s: network data clear: ret=%d, len=%d\n",
+ __func__, ret, (int)len);
len_read = recv(rp->fd, buffer, len < NET_BUFFER_SIZE ? len : NET_BUFFER_SIZE,
0);
commit ce558ecc5108461b01c02fb02357719280692b86
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:18:03 2026 -0700
fix(stream): avoid shifting negative samples
Scale signed 8-bit samples in int, then narrow explicitly to int16_t.
diff --git a/src/stream_convert.c b/src/stream_convert.c
index 9d0e10544..e2f27027f 100644
--- a/src/stream_convert.c
+++ b/src/stream_convert.c
@@ -128,7 +128,7 @@ static inline long scale_round_clamp(float v, float scale, long lo, long hi)
/* Direct integer converters (fast path) */
/* ------------------------------------------------------------------ */
-/* S8 -> S16: sign-extend and shift left 8 */
+/* S8 -> S16: sign-extend and scale by 256 */
static void convert_s8_to_s16(const void *src, void *dst, size_t n)
{
const int8_t *s = src;
@@ -136,11 +136,11 @@ static void convert_s8_to_s16(const void *src, void *dst, size_t n)
for (size_t i = 0; i < n; i++)
{
- d[i] = (int16_t)s[i] << 8;
+ d[i] = (int16_t)((int)s[i] * 256);
}
}
-/* U8 -> S16: subtract 128 offset, shift left 8 */
+/* U8 -> S16: subtract 128 offset, scale by 256 */
static void convert_u8_to_s16(const void *src, void *dst, size_t n)
{
const uint8_t *s = src;
@@ -148,7 +148,7 @@ static void convert_u8_to_s16(const void *src, void *dst, size_t n)
for (size_t i = 0; i < n; i++)
{
- d[i] = (int16_t)((int)s[i] - 128) << 8;
+ d[i] = (int16_t)(((int)s[i] - 128) * 256);
}
}
@@ -200,7 +200,7 @@ static void convert_cs8_to_cu8(const void *src, void *dst, size_t n)
}
}
-/* CU8 -> CS16: subtract 128, shift left 8 per component */
+/* CU8 -> CS16: subtract 128, scale by 256 per component */
static void convert_cu8_to_cs16(const void *src, void *dst, size_t n)
{
const uint8_t *s = src;
@@ -208,11 +208,11 @@ static void convert_cu8_to_cs16(const void *src, void *dst, size_t n)
for (size_t i = 0; i < 2 * n; i++)
{
- d[i] = (int16_t)((int)s[i] - 128) << 8;
+ d[i] = (int16_t)(((int)s[i] - 128) * 256);
}
}
-/* CS8 -> CS16: sign-extend and shift left 8 per component */
+/* CS8 -> CS16: sign-extend and scale by 256 per component */
static void convert_cs8_to_cs16(const void *src, void *dst, size_t n)
{
const int8_t *s = src;
@@ -220,7 +220,7 @@ static void convert_cs8_to_cs16(const void *src, void *dst, size_t n)
for (size_t i = 0; i < 2 * n; i++)
{
- d[i] = (int16_t)s[i] << 8;
+ d[i] = (int16_t)((int)s[i] * 256);
}
}
commit 6dfb56096e2d4117d80d47c0cc5e1e95d19c600d
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:17:39 2026 -0700
fix(tools): iterate the full mode bit range
Use the unsigned mode-mask type for capability and protocol output.
Avoid signed-shift undefined behavior and enumerate upper mode bits.
diff --git a/tests/dumpcaps.c b/tests/dumpcaps.c
index b425f9d6c..f1b91613c 100644
--- a/tests/dumpcaps.c
+++ b/tests/dumpcaps.c
@@ -1015,9 +1015,9 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "Bandwidths:");
- for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1)
+ for (rmode_t mode = 1; mode < RIG_MODE_TESTS_MAX; mode <<= 1)
{
- pbwidth_t pbnorm = rig_passband_normal(rig, i);
+ pbwidth_t pbnorm = rig_passband_normal(rig, mode);
if (pbnorm == 0)
{
@@ -1025,12 +1025,12 @@ int dumpcaps(RIG *rig, FILE *fout)
}
sprintf_freq(freqbuf, sizeof(freqbuf), pbnorm);
- fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(i), freqbuf);
+ fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(mode), freqbuf);
- sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_narrow(rig, i));
+ sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_narrow(rig, mode));
fprintf(fout, "Narrow: %s,\t", freqbuf);
- sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_wide(rig, i));
+ sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_wide(rig, mode));
fprintf(fout, "Wide: %s", freqbuf);
}
diff --git a/tests/dumpstate.c b/tests/dumpstate.c
index e94a38c43..191ef8438 100644
--- a/tests/dumpstate.c
+++ b/tests/dumpstate.c
@@ -724,9 +724,9 @@ int dumpstate(RIG *rig, FILE *fout)
fprintf(fout, "Bandwidths:");
- for (i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1)
+ for (rmode_t mode = 1; mode < RIG_MODE_TESTS_MAX; mode <<= 1)
{
- pbwidth_t pbnorm = rig_passband_normal(rig, i);
+ pbwidth_t pbnorm = rig_passband_normal(rig, mode);
if (pbnorm == 0)
{
@@ -734,12 +734,12 @@ int dumpstate(RIG *rig, FILE *fout)
}
sprintf_freq(freqbuf, sizeof(freqbuf), pbnorm);
- fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(i), freqbuf);
+ fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(mode), freqbuf);
- sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_narrow(rig, i));
+ sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_narrow(rig, mode));
fprintf(fout, "Narrow: %s,\t", freqbuf);
- sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_wide(rig, i));
+ sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_wide(rig, mode));
fprintf(fout, "Wide: %s", freqbuf);
}
diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c
index 4d268f857..52a1b692b 100644
--- a/tests/rigctl_parse.c
+++ b/tests/rigctl_parse.c
@@ -3359,9 +3359,9 @@ declare_proto_rig(get_modes)
fprintf(fout, "\nBandwidths:");
- for (int i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1)
+ for (rmode_t mode = 1; mode < RIG_MODE_TESTS_MAX; mode <<= 1)
{
- pbwidth_t pbnorm = rig_passband_normal(rig, i);
+ pbwidth_t pbnorm = rig_passband_normal(rig, mode);
if (pbnorm == 0)
{
@@ -3369,12 +3369,12 @@ declare_proto_rig(get_modes)
}
sprintf_freq(freqbuf, sizeof(freqbuf), pbnorm);
- fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(i), freqbuf);
+ fprintf(fout, "\n\t%s\tNormal: %s,\t", rig_strrmode(mode), freqbuf);
- sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_narrow(rig, i));
+ sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_narrow(rig, mode));
fprintf(fout, "Narrow: %s,\t", freqbuf);
- sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_wide(rig, i));
+ sprintf_freq(freqbuf, sizeof(freqbuf), rig_passband_wide(rig, mode));
fprintf(fout, "Wide: %s", freqbuf);
}
@@ -3390,15 +3390,15 @@ declare_proto_rig(get_mode_bandwidths)
rmode_t mode = rig_parse_mode(arg1);
- for (int i = 1; i < RIG_MODE_TESTS_MAX; i <<= 1)
+ for (rmode_t mode_bit = 1; mode_bit < RIG_MODE_TESTS_MAX; mode_bit <<= 1)
{
- if (i != mode) { continue; }
+ if (mode_bit != mode) { continue; }
if (mode == RIG_MODE_CWR) { mode = RIG_MODE_CW; }
if (mode == RIG_MODE_RTTYR) { mode = RIG_MODE_RTTY; }
- pbwidth_t pbnorm = rig_passband_normal(rig, i);
+ pbwidth_t pbnorm = rig_passband_normal(rig, mode_bit);
if (pbnorm == 0)
{
@@ -3407,13 +3407,15 @@ declare_proto_rig(get_mode_bandwidths)
// sprintf_freq(freqbuf, sizeof(freqbuf), pbnorm);
SNPRINTF(freqbuf, sizeof(freqbuf), "%ldHz", pbnorm);
- fprintf(fout, "Mode=%s\n", rig_strrmode(i));
+ fprintf(fout, "Mode=%s\n", rig_strrmode(mode_bit));
fprintf(fout, "Normal=%s\n", freqbuf);
- SNPRINTF(freqbuf, sizeof(freqbuf), "%ldHz", rig_passband_narrow(rig, i));
+ SNPRINTF(freqbuf, sizeof(freqbuf), "%ldHz",
+ rig_passband_narrow(rig, mode_bit));
fprintf(fout, "Narrow=%s\n", freqbuf);
- SNPRINTF(freqbuf, sizeof(freqbuf), "%ldHz", rig_passband_wide(rig, i));
+ SNPRINTF(freqbuf, sizeof(freqbuf), "%ldHz",
+ rig_passband_wide(rig, mode_bit));
fprintf(fout, "Wide=%s", freqbuf);
}
commit 436b22a75148ed36175dd9247c987e265c475fa3
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:17:15 2026 -0700
fix(ctl): reserve terminators in stdin tokens
Limit scansets to the remaining token capacity after the first byte.
diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c
index fdfb86b66..4e9bb5d7a 100644
--- a/tests/ampctl_parse.c
+++ b/tests/ampctl_parse.c
@@ -79,9 +79,6 @@ extern int read_history();
static pthread_mutex_t amp_mutex = PTHREAD_MUTEX_INITIALIZER;
-#define STR1(S) #S
-#define STR(S) STR1(S)
-
#define MAXNAMSIZ 32
#define MAXNBOPT 100 /* max number of different options */
#define MAXARGSZ 127
@@ -403,11 +400,15 @@ static int next_word(char *buffer, int argc, char *argv[], int newline)
if (reading_stdin)
{
+ char stdin_format[32];
+ SNPRINTF(stdin_format, sizeof(stdin_format), " %%c%%%d[^ \t\n#]",
+ MAXARGSZ - 1);
+
do
{
do
{
- ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]);
+ ret = scanf(stdin_format, &c, &buffer[1]);
}
while (EINTR == ret);
diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c
index 234ce17e2..4d268f857 100644
--- a/tests/rigctl_parse.c
+++ b/tests/rigctl_parse.c
@@ -93,9 +93,6 @@ extern int read_history();
/* Hash table implementation See: http://uthash.sourceforge.net/ */
#include "uthash.h"
-#define STR1(S) #S
-#define STR(S) STR1(S)
-
#define MAXNAMSIZ 32
#define MAXNBOPT 100 /* max number of different options */
#define MAXARGSZ 511
@@ -892,12 +889,15 @@ static int next_word(char *buffer, int argc, char *argv[], int newline,
if (reading_stdin)
{
+ char stdin_format[32];
+ SNPRINTF(stdin_format, sizeof(stdin_format), " %%c%%%d[^ \t\n#]",
+ MAXARGSZ - 1);
+
do
{
do
{
- ret = fscanf(fin, " %c%" STR(MAXARGSZ) "[^ \t\n#]", &c,
- &buffer[1]);
+ ret = fscanf(fin, stdin_format, &c, &buffer[1]);
}
while (EINTR == ret);
diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c
index 82ee27f8e..bd1e7bf69 100644
--- a/tests/rotctl_parse.c
+++ b/tests/rotctl_parse.c
@@ -94,9 +94,6 @@ extern int read_history();
static pthread_mutex_t rot_mutex = PTHREAD_MUTEX_INITIALIZER;
-#define STR1(S) #S
-#define STR(S) STR1(S)
-
#define MAXNAMSIZ 32
#define MAXNBOPT 100 /* max number of different options */
#define MAXARGSZ 127
@@ -456,11 +453,15 @@ static int next_word(char *buffer, int argc, const char **argv, int newline)
if (reading_stdin)
{
+ char stdin_format[32];
+ SNPRINTF(stdin_format, sizeof(stdin_format), " %%c%%%d[^ \t\n#]",
+ MAXARGSZ - 1);
+
do
{
do
{
- ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]);
+ ret = scanf(stdin_format, &c, &buffer[1]);
}
while (EINTR == ret);
commit 8d6965907cb48aeba4eb7c8c386ec1130c71be81
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:16:30 2026 -0700
fix(conf): honor frontend string capacities
Terminate stored frontend paths and device identifiers after truncation.
Bound every frontend string getter by the caller-provided capacity.
diff --git a/src/amp_conf.c b/src/amp_conf.c
index 692deca70..6ae64d831 100644
--- a/src/amp_conf.c
+++ b/src/amp_conf.c
@@ -117,7 +117,7 @@ int frontamp_set_conf(AMP *amp, hamlib_token_t token, const char *val)
switch (token)
{
case TOK_PATHNAME:
- strncpy(ampp->pathname, val, HAMLIB_FILPATHLEN - 1);
+ SNPRINTF(ampp->pathname, sizeof(ampp->pathname), "%s", val);
break;
case TOK_WRITE_DELAY:
@@ -366,7 +366,7 @@ int frontamp_get_conf2(AMP *amp, hamlib_token_t token, char *val, int val_len)
switch (token)
{
case TOK_PATHNAME:
- strncpy(val, ampp->pathname, val_len - 1);
+ SNPRINTF(val, val_len, "%s", ampp->pathname);
break;
case TOK_WRITE_DELAY:
@@ -444,7 +444,7 @@ int frontamp_get_conf2(AMP *amp, hamlib_token_t token, char *val, int val_len)
return -RIG_EINVAL;
}
- strncpy(val, s, val_len - 1);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_HANDSHAKE:
@@ -471,7 +471,7 @@ int frontamp_get_conf2(AMP *amp, hamlib_token_t token, char *val, int val_len)
return -RIG_EINVAL;
}
- strncpy(val, s, val_len);
+ SNPRINTF(val, val_len, "%s", s);
break;
default:
diff --git a/src/conf.c b/src/conf.c
index a113fd623..a876fe990 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -330,22 +330,23 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
switch (token)
{
case TOK_PATHNAME:
- strncpy(rp->pathname, val, HAMLIB_FILPATHLEN - 1);
+ SNPRINTF(rp->pathname, sizeof(rp->pathname), "%s", val);
if (strstr(rig->caps->model_name, "SmartSDR Slice"))
{
char *val2 = strdup(val);
- char *p = strchr(val2, ':');
+ char *p;
if (val2 == NULL)
{
return -RIG_ENOMEM;
}
+ p = strchr(val2, ':');
+
if (p != NULL && p[1] != '\0')
{
- strncpy(rp->pathname, val, HAMLIB_FILPATHLEN - 1);
- rp->pathname[HAMLIB_FILPATHLEN - 1] = 0;
+ SNPRINTF(rp->pathname, sizeof(rp->pathname), "%s", val);
}
else
{
@@ -660,7 +661,7 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
break;
case TOK_PTT_PATHNAME:
- strncpy(pttp->pathname, val, HAMLIB_FILPATHLEN - 1);
+ SNPRINTF(pttp->pathname, sizeof(pttp->pathname), "%s", val);
break;
case TOK_PTT_BITNUM:
@@ -718,11 +719,11 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
break;
case TOK_DCD_PATHNAME:
- strncpy(dcdp->pathname, val, HAMLIB_FILPATHLEN - 1);
+ SNPRINTF(dcdp->pathname, sizeof(dcdp->pathname), "%s", val);
break;
case TOK_DEVICE_ID:
- strncpy(rs->device_id, val, HAMLIB_RIGNAMSIZ - 1);
+ SNPRINTF(rs->device_id, sizeof(rs->device_id), "%s", val);
break;
@@ -1151,7 +1152,7 @@ static int frontend_get_conf2(RIG *rig, hamlib_token_t token, char *val,
return -RIG_EINVAL;
}
- strcpy(val, s);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_HANDSHAKE:
@@ -1181,7 +1182,7 @@ static int frontend_get_conf2(RIG *rig, hamlib_token_t token, char *val,
return -RIG_EINVAL;
}
- strcpy(val, s);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_RTS_STATE:
@@ -1208,7 +1209,7 @@ static int frontend_get_conf2(RIG *rig, hamlib_token_t token, char *val,
return -RIG_EINVAL;
}
- strcpy(val, s);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_DTR_STATE:
@@ -1235,7 +1236,7 @@ static int frontend_get_conf2(RIG *rig, hamlib_token_t token, char *val,
return -RIG_EINVAL;
}
- strcpy(val, s);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_DEVICE_ID:
@@ -1293,11 +1294,11 @@ static int frontend_get_conf2(RIG *rig, hamlib_token_t token, char *val,
return -RIG_EINVAL;
}
- strcpy(val, s);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_PTT_PATHNAME:
- strcpy(val, pttp->pathname);
+ SNPRINTF(val, val_len, "%s", pttp->pathname);
break;
case TOK_PTT_BITNUM:
@@ -1347,11 +1348,11 @@ static int frontend_get_conf2(RIG *rig, hamlib_token_t token, char *val,
return -RIG_EINVAL;
}
- strcpy(val, s);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_DCD_PATHNAME:
- strcpy(val, dcdp->pathname);
+ SNPRINTF(val, val_len, "%s", dcdp->pathname);
break;
case TOK_LO_FREQ:
diff --git a/src/rot_conf.c b/src/rot_conf.c
index 59bcc5dcb..5213eb459 100644
--- a/src/rot_conf.c
+++ b/src/rot_conf.c
@@ -151,7 +151,7 @@ int frontrot_set_conf(ROT *rot, hamlib_token_t token, const char *val)
switch (token)
{
case TOK_PATHNAME:
- strncpy(rotp->pathname, val, HAMLIB_FILPATHLEN - 1);
+ SNPRINTF(rotp->pathname, sizeof(rotp->pathname), "%s", val);
break;
case TOK_WRITE_DELAY:
@@ -407,7 +407,7 @@ int frontrot_get_conf(ROT *rot, hamlib_token_t token, char *val, int val_len)
switch (token)
{
case TOK_PATHNAME:
- strncpy(val, rotp->pathname, val_len - 1);
+ SNPRINTF(val, val_len, "%s", rotp->pathname);
break;
case TOK_WRITE_DELAY:
@@ -485,7 +485,7 @@ int frontrot_get_conf(ROT *rot, hamlib_token_t token, char *val, int val_len)
return -RIG_EINVAL;
}
- strncpy(val, s, val_len);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_HANDSHAKE:
@@ -512,7 +512,7 @@ int frontrot_get_conf(ROT *rot, hamlib_token_t token, char *val, int val_len)
return -RIG_EINVAL;
}
- strcpy(val, s);
+ SNPRINTF(val, val_len, "%s", s);
break;
case TOK_MIN_AZ:
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8184be690..55f6455b1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,8 +27,9 @@ DIRECT_TESTS = \
testdaemonclients \
testdebug \
testdummyparm \
- testft991idmeter \
testelecraftvfo \
+ testfrontendconf \
+ testft991idmeter \
testftx1parsers \
testg90af \
testg90rit \
@@ -204,6 +205,7 @@ testcachevfo_LDADD = $(PTHREAD_LIBS) \
testctlparser_SOURCES = testctlparser.c $(RIGCOMMONSRC)
testctlparser_LDADD = $(PTHREAD_LIBS) $(READLINE_LIBS) $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testrigctlprotocol_LDADD = $(LDADD)
+testfrontendconf_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testmodecompat_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testicomts_LDADD = $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testid5100_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
diff --git a/tests/testfrontendconf.c b/tests/testfrontendconf.c
new file mode 100644
index 000000000..94ca212a2
--- /dev/null
+++ b/tests/testfrontendconf.c
@@ -0,0 +1,321 @@
+/*
+ * Hamlib frontend configuration buffer tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <hamlib/amplifier.h>
+#include <hamlib/amplist.h>
+#include <hamlib/port.h>
+#include <hamlib/rig.h>
+#include <hamlib/rig_state.h>
+#include <hamlib/riglist.h>
+#include <hamlib/rotator.h>
+#include <hamlib/rotlist.h>
+
+struct guarded_buffer
+{
+ char value[4];
+ unsigned char guard[4];
+};
+
+static void prepare_buffer(struct guarded_buffer *buffer)
+{
+ memset(buffer, 0xa5, sizeof(*buffer));
+}
+
+static int verify_buffer(const char *name, int result,
+ const struct guarded_buffer *buffer,
+ const char *expected)
+{
+ size_t i;
+
+ if (result != RIG_OK)
+ {
+ fprintf(stderr, "%s returned %s\n", name, rigerror(result));
+ return 1;
+ }
+
+ if (memcmp(buffer->value, expected, sizeof(buffer->value) - 1) != 0
+ || buffer->value[sizeof(buffer->value) - 1] != '\0')
+ {
+ fprintf(stderr, "%s did not truncate and terminate its output\n", name);
+ return 1;
+ }
+
+ for (i = 0; i < sizeof(buffer->guard); ++i)
+ {
+ if (buffer->guard[i] != 0xa5)
+ {
+ fprintf(stderr, "%s wrote beyond the output buffer\n", name);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static void make_long_value(char *value, size_t size)
+{
+ memset(value, 'x', size - 1);
+ value[size - 1] = '\0';
+}
+
+static int test_rig_frontend(void)
+{
+ char long_value[HAMLIB_FILPATHLEN + 32];
+ struct guarded_buffer output;
+ struct rig_state *state;
+ RIG *rig = rig_init(RIG_MODEL_DUMMY);
+ int result = 1;
+
+ if (rig == NULL)
+ {
+ fprintf(stderr, "unable to initialize dummy rig\n");
+ return 1;
+ }
+
+ make_long_value(long_value, sizeof(long_value));
+ state = HAMLIB_STATE(rig);
+
+ if (rig_set_conf(rig, rig_token_lookup(rig, "rig_pathname"),
+ long_value) != RIG_OK
+ || RIGPORT(rig)->pathname[HAMLIB_FILPATHLEN - 1] != '\0')
+ {
+ fprintf(stderr, "rig pathname setter did not terminate storage\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("rig pathname getter",
+ rig_get_conf2(rig,
+ rig_token_lookup(rig, "rig_pathname"),
+ output.value, sizeof(output.value)),
+ &output, "xxx"))
+ {
+ goto done;
+ }
+
+ if (rig_set_conf(rig, rig_token_lookup(rig, "ptt_pathname"),
+ long_value) != RIG_OK
+ || PTTPORT(rig)->pathname[HAMLIB_FILPATHLEN - 1] != '\0')
+ {
+ fprintf(stderr, "PTT pathname setter did not terminate storage\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("PTT pathname getter",
+ rig_get_conf2(rig,
+ rig_token_lookup(rig, "ptt_pathname"),
+ output.value, sizeof(output.value)),
+ &output, "xxx"))
+ {
+ goto done;
+ }
+
+ if (rig_set_conf(rig, rig_token_lookup(rig, "dcd_pathname"),
+ long_value) != RIG_OK
+ || DCDPORT(rig)->pathname[HAMLIB_FILPATHLEN - 1] != '\0')
+ {
+ fprintf(stderr, "DCD pathname setter did not terminate storage\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("DCD pathname getter",
+ rig_get_conf2(rig,
+ rig_token_lookup(rig, "dcd_pathname"),
+ output.value, sizeof(output.value)),
+ &output, "xxx"))
+ {
+ goto done;
+ }
+
+ if (rig_set_conf(rig, rig_token_lookup(rig, "device_id"),
+ long_value) != RIG_OK
+ || state->device_id[sizeof(state->device_id) - 1] != '\0')
+ {
+ fprintf(stderr, "device ID setter did not terminate storage\n");
+ goto done;
+ }
+
+ if (rig_set_conf(rig, rig_token_lookup(rig, "ptt_type"),
+ "Parallel") != RIG_OK)
+ {
+ fprintf(stderr, "unable to set PTT type\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("PTT type getter",
+ rig_get_conf2(rig, rig_token_lookup(rig, "ptt_type"),
+ output.value, sizeof(output.value)),
+ &output, "Par"))
+ {
+ goto done;
+ }
+
+ result = 0;
+
+done:
+ rig_cleanup(rig);
+ return result;
+}
+
+static int test_rotator_frontend(void)
+{
+ char long_value[HAMLIB_FILPATHLEN + 32];
+ struct guarded_buffer output;
+ struct rot_caps caps;
+ ROT *rot = rot_init(ROT_MODEL_DUMMY);
+ int result = 1;
+
+ if (rot == NULL)
+ {
+ fprintf(stderr, "unable to initialize dummy rotator\n");
+ return 1;
+ }
+
+ make_long_value(long_value, sizeof(long_value));
+ caps = *rot->caps;
+ caps.port_type = RIG_PORT_SERIAL;
+ rot->caps = ∩︀
+
+ if (rot_set_conf(rot, rot_token_lookup(rot, "rot_pathname"),
+ long_value) != RIG_OK
+ || ROTPORT(rot)->pathname[HAMLIB_FILPATHLEN - 1] != '\0')
+ {
+ fprintf(stderr, "rotator pathname setter did not terminate storage\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("rotator pathname getter",
+ rot_get_conf2(rot,
+ rot_token_lookup(rot, "rot_pathname"),
+ output.value, sizeof(output.value)),
+ &output, "xxx"))
+ {
+ goto done;
+ }
+
+ ROTPORT(rot)->type.rig = RIG_PORT_SERIAL;
+
+ if (rot_set_conf(rot, rot_token_lookup(rot, "serial_parity"),
+ "Space") != RIG_OK)
+ {
+ fprintf(stderr, "unable to set rotator parity\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("rotator parity getter",
+ rot_get_conf2(rot,
+ rot_token_lookup(rot, "serial_parity"),
+ output.value, sizeof(output.value)),
+ &output, "Spa"))
+ {
+ goto done;
+ }
+
+ result = 0;
+
+done:
+ rot_cleanup(rot);
+ return result;
+}
+
+static int test_amplifier_frontend(void)
+{
+ char long_value[HAMLIB_FILPATHLEN + 32];
+ struct guarded_buffer output;
+ struct amp_caps caps;
+ AMP *amp = amp_init(AMP_MODEL_DUMMY);
+ int result = 1;
+
+ if (amp == NULL)
+ {
+ fprintf(stderr, "unable to initialize dummy amplifier\n");
+ return 1;
+ }
+
+ make_long_value(long_value, sizeof(long_value));
+ caps = *amp->caps;
+ caps.port_type = RIG_PORT_SERIAL;
+ amp->caps = ∩︀
+
+ if (amp_set_conf(amp, amp_token_lookup(amp, "amp_pathname"),
+ long_value) != RIG_OK
+ || AMPPORT(amp)->pathname[HAMLIB_FILPATHLEN - 1] != '\0')
+ {
+ fprintf(stderr, "amplifier pathname setter did not terminate storage\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("amplifier pathname getter",
+ amp_get_conf2(amp,
+ amp_token_lookup(amp, "amp_pathname"),
+ output.value, sizeof(output.value)),
+ &output, "xxx"))
+ {
+ goto done;
+ }
+
+ AMPPORT(amp)->type.rig = RIG_PORT_SERIAL;
+
+ if (amp_set_conf(amp, amp_token_lookup(amp, "serial_parity"),
+ "Space") != RIG_OK)
+ {
+ fprintf(stderr, "unable to set amplifier parity\n");
+ goto done;
+ }
+
+ prepare_buffer(&output);
+
+ if (verify_buffer("amplifier parity getter",
+ amp_get_conf2(amp,
+ amp_token_lookup(amp, "serial_parity"),
+ output.value, sizeof(output.value)),
+ &output, "Spa"))
+ {
+ goto done;
+ }
+
+ result = 0;
+
+done:
+ amp_cleanup(amp);
+ return result;
+}
+
+int main(void)
+{
+ rig_load_backend("dummy");
+ rot_load_backend("dummy");
+ amp_load_backend("dummy");
+
+ if (test_rig_frontend() || test_rotator_frontend()
+ || test_amplifier_frontend())
+ {
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
commit e2b67bce5f6593647ce7a60a823dc440000f7154
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:12:21 2026 -0700
fix(rigctld): harden state and channel output
Read level and parameter granularities from their matching arrays.
Omit unset string parameters and print channel strings without staging.
diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c
index 01d319c3f..234ce17e2 100644
--- a/tests/rigctl_parse.c
+++ b/tests/rigctl_parse.c
@@ -5130,8 +5130,10 @@ int dump_chan(FILE *fout, RIG *rig, channel_t *chan)
switch (cfp->type)
{
case RIG_CONF_STRING:
- strcpy(lstr, chan->ext_levels[idx].val.s);
- break;
+ fprintf(fout, ",\t %s: %s", cfp->name,
+ chan->ext_levels[idx].val.s != NULL ?
+ chan->ext_levels[idx].val.s : "");
+ continue;
case RIG_CONF_COMBO:
SNPRINTF(lstr, sizeof(lstr), "%d", chan->ext_levels[idx].val.i);
@@ -5386,8 +5388,8 @@ declare_proto_rig(dump_state)
}
else
{
- fprintf(fout, "%d=%d,%d,%d;", i, rs->parm_gran[i].min.i,
- rs->parm_gran[i].max.i, rs->parm_gran[i].step.i);
+ fprintf(fout, "%d=%d,%d,%d;", i, rs->level_gran[i].min.i,
+ rs->level_gran[i].max.i, rs->level_gran[i].step.i);
}
}
@@ -5409,12 +5411,15 @@ declare_proto_rig(dump_state)
}
else if (RIG_PARM_IS_STRING(parm))
{
- fprintf(fout, "%d=%s;", i, rs->parm_gran[i].step.cs);
+ if (rs->parm_gran[i].step.cs != NULL)
+ {
+ fprintf(fout, "%d=%s;", i, rs->parm_gran[i].step.cs);
+ }
}
else
{
- fprintf(fout, "%d=%d,%d,%d;", i, rs->level_gran[i].min.i,
- rs->level_gran[i].max.i, rs->level_gran[i].step.i);
+ fprintf(fout, "%d=%d,%d,%d;", i, rs->parm_gran[i].min.i,
+ rs->parm_gran[i].max.i, rs->parm_gran[i].step.i);
}
}
diff --git a/tests/testctlparser.c b/tests/testctlparser.c
index d892ce2ca..492caf8ca 100644
--- a/tests/testctlparser.c
+++ b/tests/testctlparser.c
@@ -1911,6 +1911,109 @@ done:
return result;
}
+static int contains_between(const char *start, const char *end,
+ const char *needle)
+{
+ const char *match = strstr(start, needle);
+
+ return match != NULL && match < end;
+}
+
+static int check_state_granularity_output(RIG *rig)
+{
+ struct rig_state *state = HAMLIB_STATE(rig);
+ const int level_index = rig_setting2idx(RIG_LEVEL_ATT);
+ const int parm_index = rig_setting2idx(RIG_PARM_ANN);
+ const int band_index = rig_setting2idx(RIG_PARM_BANDSELECT);
+ const int keyer_index = rig_setting2idx(RIG_PARM_KEYERTYPE);
+ unsigned char output[32768];
+ char level_expected[64];
+ char level_wrong[64];
+ char parm_expected[64];
+ char parm_wrong[64];
+ char band_expected[64];
+ char keyer_entry[32];
+ char *level_start;
+ char *parm_start;
+ char *state_end;
+ FILE *input = tmpfile();
+ char *chk_vfo_argv[] = { "testctlparser", "chk_vfo" };
+ char *dump_state_argv[] = { "testctlparser", "dump_state" };
+ size_t output_length;
+ int ret;
+
+ if (input == NULL)
+ {
+ return 1;
+ }
+
+ state->level_gran[level_index].min.i = 101;
+ state->level_gran[level_index].max.i = 102;
+ state->level_gran[level_index].step.i = 103;
+ state->parm_gran[level_index].min.i = 201;
+ state->parm_gran[level_index].max.i = 202;
+ state->parm_gran[level_index].step.i = 203;
+ state->parm_gran[parm_index].min.i = 301;
+ state->parm_gran[parm_index].max.i = 302;
+ state->parm_gran[parm_index].step.i = 303;
+ state->level_gran[parm_index].min.i = 401;
+ state->level_gran[parm_index].max.i = 402;
+ state->level_gran[parm_index].step.i = 403;
+ state->parm_gran[band_index].step.cs = "BAND160M,BAND80M";
+ state->parm_gran[keyer_index].step.cs = NULL;
+
+ ret = parse_command_output(rig, input, chk_vfo_argv, 2, -1, output,
+ sizeof(output) - 1, &output_length);
+
+ if (ret == RIG_OK)
+ {
+ ret = parse_command_output(rig, input, dump_state_argv, 2, -1, output,
+ sizeof(output) - 1, &output_length);
+ }
+
+ fclose(input);
+
+ if (ret != RIG_OK || output_length >= sizeof(output) - 1)
+ {
+ fprintf(stderr, "unable to capture complete state output\n");
+ return 1;
+ }
+
+ output[output_length] = '\0';
+ level_start = strstr((char *)output, "level_gran=");
+ parm_start = strstr((char *)output, "\nparm_gran=");
+ state_end = parm_start == NULL ? NULL : strstr(parm_start, "\nrig_model=");
+
+ if (level_start == NULL || parm_start == NULL || state_end == NULL)
+ {
+ fprintf(stderr, "state output is missing granularity sections\n");
+ return 1;
+ }
+
+ SNPRINTF(level_expected, sizeof(level_expected), "%d=101,102,103;",
+ level_index);
+ SNPRINTF(level_wrong, sizeof(level_wrong), "%d=201,202,203;", level_index);
+ SNPRINTF(parm_expected, sizeof(parm_expected), "%d=301,302,303;",
+ parm_index);
+ SNPRINTF(parm_wrong, sizeof(parm_wrong), "%d=401,402,403;", parm_index);
+ SNPRINTF(band_expected, sizeof(band_expected), "%d=BAND160M,BAND80M;",
+ band_index);
+ SNPRINTF(keyer_entry, sizeof(keyer_entry), "%d=", keyer_index);
+
+ if (!contains_between(level_start, parm_start, level_expected)
+ || contains_between(level_start, parm_start, level_wrong)
+ || !contains_between(parm_start, state_end, parm_expected)
+ || contains_between(parm_start, state_end, parm_wrong)
+ || !contains_between(parm_start, state_end, band_expected)
+ || contains_between(parm_start, state_end, keyer_entry))
+ {
+ fprintf(stderr, "state output contains incorrect granularity data\n");
+ return 1;
+ }
+
+ return 0;
+}
+
int main(void)
{
static const char maximum[] = "12345678901234567890123456789";
@@ -2020,7 +2123,8 @@ int main(void)
|| check_receive_length(rig, "12junk", -RIG_EINVAL) != 0
|| check_receive_length(rig, "999999999999999999999999",
-RIG_EINVAL) != 0
- || check_bad_input_stream(rig) != 0)
+ || check_bad_input_stream(rig) != 0
+ || check_state_granularity_output(rig) != 0)
{
rig_cleanup(rig);
return 1;
commit 0147d62cc4b213c30961f87252aba3dc7ff8675b
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:11:11 2026 -0700
fix(events): handle short spectrum trace lines
Clamp spectrum aggregation for traces shorter than 120 samples.
Reserve a terminator even when an event carries no spectrum samples.
diff --git a/src/event.c b/src/event.c
index 1be2c8d0c..2226bedba 100644
--- a/src/event.c
+++ b/src/event.c
@@ -908,6 +908,11 @@ static int print_spectrum_line(char *str, size_t length,
int i, c;
int charlen = strlen("█");
+ if (aggregate_count < 1)
+ {
+ aggregate_count = 1;
+ }
+
str[0] = '\0';
for (i = 0, c = 0; i < line->spectrum_data_length; i++)
@@ -964,7 +969,7 @@ int rig_fire_spectrum_event(RIG *rig, struct rig_spectrum_line *line)
if (rig_need_debug(RIG_DEBUG_TRACE))
{
- char spectrum_debug[line->spectrum_data_length * 4];
+ char spectrum_debug[line->spectrum_data_length * 4 + 1];
print_spectrum_line(spectrum_debug, sizeof(spectrum_debug), line);
rig_debug(RIG_DEBUG_TRACE, "%s: ASCII Spectrum Scope: %s\n", __func__,
spectrum_debug);
diff --git a/tests/testdebug.c b/tests/testdebug.c
index 6b3891871..7a6ca9374 100644
--- a/tests/testdebug.c
+++ b/tests/testdebug.c
@@ -13,6 +13,9 @@
#include <string.h>
#include <hamlib/rig.h>
+#include <hamlib/rig_state.h>
+
+#include "event.h"
#define THREAD_COUNT 8
#define PADDING_SIZE 1536
@@ -68,10 +71,12 @@ static void *worker(void *arg)
}
pthread_mutex_lock(&context->gate->mutex);
+
while (!context->gate->open)
{
pthread_cond_wait(&context->gate->condition, &context->gate->mutex);
}
+
pthread_mutex_unlock(&context->gate->mutex);
rig_debug(RIG_DEBUG_TRACE, "%s", message);
@@ -80,7 +85,8 @@ static void *worker(void *arg)
static int test_concurrent_history(void)
{
- struct start_gate gate = {
+ struct start_gate gate =
+ {
PTHREAD_MUTEX_INITIALIZER,
PTHREAD_COND_INITIALIZER,
0
@@ -97,6 +103,7 @@ static int test_concurrent_history(void)
{
contexts[thread].gate = &gate;
contexts[thread].thread = thread;
+
if (pthread_create(&threads[thread], NULL, worker,
&contexts[thread]) != 0)
{
@@ -130,7 +137,9 @@ static int test_concurrent_history(void)
{
return 0;
}
+
expected_length += strlen(expected);
+
if (strstr(debugmsgsave, expected) == NULL)
{
fprintf(stderr,
@@ -169,6 +178,7 @@ static int test_rolling_history(void)
rig_set_debug(RIG_DEBUG_NONE);
history = debugmsgsave;
+
for (line = HISTORY_LINE_COUNT - RETAINED_LINE_COUNT;
line < HISTORY_LINE_COUNT; ++line)
{
@@ -182,6 +192,7 @@ static int test_rolling_history(void)
fprintf(stderr, "history did not retain line %u in order\n", line);
return 0;
}
+
history += written;
}
@@ -195,9 +206,45 @@ static int test_rolling_history(void)
return 1;
}
+static int test_short_spectrum_lines(void)
+{
+ static const size_t lengths[] = { 0, 1, 2, 119, 120 };
+ struct rig_state state = { 0 };
+ RIG rig = { 0 };
+ unsigned char data[120] = { 0 };
+ struct rig_spectrum_line line =
+ {
+ .data_level_max = 255,
+ .spectrum_data = data
+ };
+ size_t i;
+
+ rig.state_addr = &state;
+ rig_set_debug_callback(ignore_debug_output, NULL);
+ rig_set_debug(RIG_DEBUG_TRACE);
+
+ for (i = 0; i < sizeof(lengths) / sizeof(lengths[0]); ++i)
+ {
+ line.spectrum_data_length = lengths[i];
+
+ if (rig_fire_spectrum_event(&rig, &line) != RIG_OK)
+ {
+ fprintf(stderr, "spectrum event failed for length %zu\n", lengths[i]);
+ rig_set_debug_callback(NULL, NULL);
+ rig_set_debug(RIG_DEBUG_NONE);
+ return 0;
+ }
+ }
+
+ rig_set_debug_callback(NULL, NULL);
+ rig_set_debug(RIG_DEBUG_NONE);
+ return 1;
+}
+
int main(void)
{
- if (!test_concurrent_history() || !test_rolling_history())
+ if (!test_concurrent_history() || !test_rolling_history()
+ || !test_short_spectrum_lines())
{
return EXIT_FAILURE;
}
commit a8576f2913a5fddb3975678140cccf72556dde2b
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:10:26 2026 -0700
fix(io): compare length-delimited terminators safely
Match the FLRig XML marker by explicit length and byte content.
Use a terminated marker when searching the accumulated receive buffer.
diff --git a/src/iofunc.c b/src/iofunc.c
index 4d1a4809a..5acfd5312 100644
--- a/src/iofunc.c
+++ b/src/iofunc.c
@@ -1336,6 +1336,7 @@ static int read_string_generic(hamlib_port_t *p,
int expected_len,
int direct)
{
+ static const char flrig_terminator[] = "</methodResponse>";
struct timeval start_time, end_time, elapsed_time;
int total_count = 0;
int i = 0;
@@ -1457,9 +1458,12 @@ shortcut:
}
// special read for FLRig
- if (stopset != NULL && strcmp(stopset, "</methodResponse>") == 0)
+ if (stopset != NULL
+ && stopset_len == sizeof(flrig_terminator) - 1
+ && memcmp(stopset, flrig_terminator,
+ sizeof(flrig_terminator) - 1) == 0)
{
- if (strstr((char *)rxbuffer, stopset))
+ if (strstr((char *)rxbuffer, flrig_terminator))
{
HAMLIB_TRACE2;
}
commit 8e79c2613a542826b891f943290c3bfd65ae5a14
Author: David Christle <dch...@us...>
Date: Mon Oct 26 18:09:51 2026 -0700
fix(meade): bound transaction reply storage
Reserve the terminating NUL at every full-buffer reply call site.
Truncate oversized device metadata to the backend's fixed storage.
diff --git a/rotators/meade/meade.c b/rotators/meade/meade.c
index d282d6f3d..76ff750c5 100644
--- a/rotators/meade/meade.c
+++ b/rotators/meade/meade.c
@@ -87,8 +87,9 @@ struct meade_priv_data
* cmdstr - Command to be sent to the rig.
* data - Buffer for reply string. Can be NULL, indicating that no reply is
* is needed, but answer will still be read.
- * data_len - in: Size of buffer. It is the caller's responsibility to provide
- * a large enough buffer for all possible replies for a command.
+ * data_len - out: Number of reply bytes received.
+ * reply_content_len - Maximum reply content length, excluding the terminating
+ * NUL byte.
*
* returns:
* RIG_OK - if no error occurred.
@@ -96,7 +97,7 @@ struct meade_priv_data
* RIG_ETIMEOUT - if timeout expires without any characters received.
*/
static int meade_transaction(ROT *rot, const char *cmdstr,
- char *data, size_t *data_len, size_t expected_return_length)
+ char *data, size_t *data_len, size_t reply_content_len)
{
hamlib_port_t *rotp = ROTPORT(rot);
int return_value;
@@ -124,7 +125,7 @@ transaction:
if (data != NULL)
{
return_value = read_string(rotp, (unsigned char *) data,
- expected_return_length + 1,
+ reply_content_len + 1,
"\r\n", strlen("\r\n"), 0, 1);
if (return_value > 0)
@@ -214,13 +215,14 @@ static int meade_open(ROT *rot)
// Get our product name for any custom things we need to do
// The LX200 does not have :GVP# so no response will default to LX200
retval = meade_transaction(rot, ":GVP#", return_str, &return_str_size,
- sizeof(return_str));
+ sizeof(return_str) - 1);
if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: meade_transaction %s\n", __func__, rigerror(retval)); }
if (return_str_size > 0) { strtok(return_str, "#"); }
- strcpy(priv->product_name, return_str_size > 0 ? return_str : "LX200 Assumed");
+ SNPRINTF(priv->product_name, sizeof(priv->product_name), "%s",
+ return_str_size > 0 ? return_str : "LX200 Assumed");
rig_debug(RIG_DEBUG_VERBOSE, "%s product_name=%s\n", __func__,
priv->product_name);
@@ -285,7 +287,8 @@ static int meade_set_position(ROT *rot, azimuth_t az, elevation_t el)
/* Undesirable behavior if stopped can happen */
/* So we just ignore commands while moving */
/* Should we return RIG_OK or an error though? */
- meade_transaction(rot, ":D#", return_str, &return_str_size, sizeof(return_str));
+ meade_transaction(rot, ":D#", return_str, &return_str_size,
+ sizeof(return_str) - 1);
// LX200 return 0xff bytes and Autostart returns 0x7f
if (return_str_size > 0 && ((return_str[0] & 0x7f) == 0x7f))
@@ -329,7 +332,8 @@ static int meade_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
- meade_transaction(rot, ":GZ#:GA#", return_str, &return_str_size, BUFSIZE);
+ meade_transaction(rot, ":GZ#:GA#", return_str, &return_str_size,
+ sizeof(return_str) - 1);
rig_debug(RIG_DEBUG_VERBOSE, "%s: returned '%s'\n", __func__, return_str);
// GZ returns DDD*MM# or DDD*MM'SS#
// GA returns sDD*MM# or sDD*MM'SS#
commit 85f3a62867166a21db80ece034af76ff9e1e015d
Merge: 8c9defa26 6e67889a8
Author: Terrell Deppe <62b...@pr...>
Date: Wed Oct 28 19:10:06 2026 -0500
Merge pull request #2265 from KJ5HST/core-split-freq-always-set
rig_set_split_freq: always send the TX frequency
commit 8c9defa260808f848f07406e82e9c86c9fceffb9
Merge: bb045cdc6 2e49bb456
Author: Terrell Deppe <62b...@pr...>
Date: Wed Oct 28 19:09:48 2026 -0500
Merge pull request #2283 from dchristle/fix/rigctld-command-lock-scope
fix(rigctld): avoid waiting for clients under the daemon lock
commit bb045cdc68ca5f99d05884ffd08d475ccbc0fb2d
Merge: dbd3f7964 72dcdd28c
Author: Terrell Deppe <62b...@pr...>
Date: Wed Oct 28 19:09:30 2026 -0500
Merge pull request #2157 from dchristle/fix/rigctld-password-authz
fix(rigctld): enforce password authentication consistently
commit dbd3f7964ac8014745d55cd8fc71f1a4992146d6
Author: David Christle <dch...@us...>
Date: Tue Oct 20 23:59:09 2026 -0700
fix(build): export samplerate for static pkg-config consumers
Static Hamlib builds with libsamplerate enabl...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-10-29 12:04:38
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via 78f5b78f25ee0ad58f8d79a57e2c046a6a1c638f (commit)
via aa70d3275dcddcc2208958018ab78acb9b350ce3 (commit)
via 1670b83e90fa058bf4e9eb588a1aa7d45f46e531 (commit)
via aef8632f49c1d5b69715acf1c56588e03d059171 (commit)
via f7369e9667dd717bc0a693d64a4c54610e36e830 (commit)
via fd17791333bcc7bbdd2488d4894a6a293926d338 (commit)
via f2b4a6f26f3d3e3b6bda6340d834b5fab963db1f (commit)
via 16f5d9cf3c5c5ed7d8919fb53993d69d399e3aaa (commit)
via 851805d09091853af5135eb2d13235204c453a9f (commit)
via f186b1f090bef89f51509fec523c8e0a53c7a888 (commit)
via 72898934f45c5b6cc2a06d6bfaca90d116795701 (commit)
via 54782eb1ab44d6c7ad86855f7766bdac33e7b90a (commit)
via b0893dd95b7c22030b9e214e6bda6560cd846635 (commit)
from ddc0a3a14c1d6ef9d8e25cf269d99bd61f602cc2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 78f5b78f25ee0ad58f8d79a57e2c046a6a1c638f
Author: Jan Szumiec <jan...@gm...>
Date: Wed Oct 28 11:07:02 2026 -0400
simtrusdx: allow startup without a port argument on POSIX
On POSIX, openPort() ignores its argument and creates a pseudo-terminal,
so the previous simtrusdx (like the other Kenwood simulators) could be
started with no arguments. Only require the port argument on Windows,
where openPort() actually opens the named device.
Co-Authored-By: Claude Opus 5.5 <no...@an...>
diff --git a/simulators/simtrusdx.c b/simulators/simtrusdx.c
index 380ed2a45..700ef5cda 100644
--- a/simulators/simtrusdx.c
+++ b/simulators/simtrusdx.c
@@ -17,8 +17,11 @@ int main(int argc, char *argv[])
long freq = 14075000;
int mode = 2;
+#if defined(WIN32) || defined(_WIN32)
+ /* Only the Windows openPort() opens the named port. */
if (argc != 2) { return 1; }
- fd = openPort(argv[1]);
+#endif
+ fd = openPort(argc > 1 ? argv[1] : NULL);
if (fd < 0) { return 1; }
while (1)
commit aa70d3275dcddcc2208958018ab78acb9b350ce3
Author: Jan Szumiec <jan...@gm...>
Date: Sat Oct 3 10:39:52 2026 +0200
Restrict truSDX CAT support in a dedicated backend with corrected capabilities
Backport of #2243 to Hamlib-4.7.
rig_set_current_vfo_state() does not exist on this branch, so
trusdx_open() uses the branch's existing convention,
STATE(rig)->current_vfo = RIG_VFO_A, and no longer needs cache.h.
(cherry picked from commit 14c618fe541fad68c62a28a1b27579924deb443c)
Co-Authored-By: Claude Opus 5.5 <no...@an...>
diff --git a/rigs/kenwood/Makefile.am b/rigs/kenwood/Makefile.am
index 6d1f64651..fc3577400 100644
--- a/rigs/kenwood/Makefile.am
+++ b/rigs/kenwood/Makefile.am
@@ -2,7 +2,7 @@
TSSRC = ts850.c ts870s.c ts570.c ts450s.c ts950.c ts50s.c \
ts790.c ts2000.c k2.c k3.c xg3.c ts930.c \
ts680.c ts690.c ts140.c ts480.c trc80.c ts590.c ts890s.c \
- ts990s.c ts990s.h flex6xxx.c pihpsdr.c tx500.c
+ ts990s.c ts990s.h flex6xxx.c pihpsdr.c tx500.c trusdx.c
IC10SRC = ts440.c ts940.c ts711.c ts811.c r5000.c
diff --git a/rigs/kenwood/trusdx.c b/rigs/kenwood/trusdx.c
new file mode 100644
index 000000000..12437390b
--- /dev/null
+++ b/rigs/kenwood/trusdx.c
@@ -0,0 +1,211 @@
+/*
+ * Hamlib Kenwood backend - (tr)uSDX description
+ * Copyright (c) 2000-2004 by Stephane Fillod and Juergen Rinas
+ * Copyright (c) 2021 by Mikael Nousiainen
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <string.h>
+
+#include "hamlib/rig.h"
+#include "idx_builtin.h"
+#include "kenwood.h"
+
+/*
+ * The (tr)uSDX implements only the CAT subset documented at
+ * https://dl2man.de/5-trusdx-details/ . In particular, IF only documents
+ * frequency and mode; its other fields must not be used as rig status.
+ * Keep these callbacks separate from the full TS-480 capability set.
+ *
+ * Firmware history:
+ * https://dl2man.de/wp-content/uploads/2022/01/wp.php/releases.txt
+ * R2.00t disabled AM/FM; R2.00v re-enabled them. The mode list below
+ * describes firmware with AM/FM enabled, not every historical release.
+ * R2.00p beta notes introduce 115200 baud; the user manual requires it
+ * for R2.00t onward. Older firmware uses 38400 baud.
+ * R2.00u improves TX resolution to 1 Hz and changes FL handling; R2.00v
+ * enables a TX CAT meter. Neither entry defines the wire format, so this
+ * backend does not advertise filter control or meter queries.
+ * R2.00w enables semi-QSK by default; R2.00x defaults it back to OFF and
+ * removes a CAT display update that slowed FT8CN TX/RX transitions.
+ * Audio streaming extensions are not implemented by this backend.
+ *
+ * Band ranges cover the union of Lo (80/60/40/30/20 m), Hi
+ * (20/17/15/12/10 m), and Classic (80/40/20/15/10 m) filter boards.
+ * An individual radio supports the five bands of its fitted board.
+ * https://dl2man.de/2-trusdx-assembly/
+ * Power is nominally 0.5 W on USB supply and 5 W on external supply;
+ * these limits describe the radio, not a CAT-adjustable power setting.
+ * https://dl2man.de/
+ */
+#define TRUSDX_MODES (RIG_MODE_LSB | RIG_MODE_USB | RIG_MODE_CW | RIG_MODE_FM | RIG_MODE_AM)
+
+static rmode_t trusdx_modes[KENWOOD_MODE_TABLE_MAX] =
+{
+ RIG_MODE_NONE, RIG_MODE_LSB, RIG_MODE_USB, RIG_MODE_CW,
+ RIG_MODE_FM, RIG_MODE_AM
+};
+
+static struct kenwood_priv_caps trusdx_priv_caps =
+{
+ .cmdtrm = EOM_KEN,
+ .mode_table = trusdx_modes,
+};
+
+static int trusdx_set_vfo(RIG *rig, vfo_t vfo)
+{
+ /* CAT exposes a single frequency through FA, with no FR/FT commands. */
+ (void)rig;
+ return vfo == RIG_VFO_A || vfo == RIG_VFO_CURR ? RIG_OK : -RIG_ENTARGET;
+}
+
+static int trusdx_get_vfo(RIG *rig, vfo_t *vfo)
+{
+ (void)rig;
+ *vfo = RIG_VFO_A;
+ return RIG_OK;
+}
+
+static int trusdx_open(RIG *rig)
+{
+ char id[16];
+ int retval = kenwood_safe_transaction(rig, "ID", id, sizeof(id), 5);
+
+ if (retval != RIG_OK) { return retval; }
+
+ if (strcmp(id, "ID020") != 0) { return -RIG_EPROTO; }
+
+ STATE(rig)->current_vfo = RIG_VFO_A;
+ return RIG_OK;
+}
+
+static int trusdx_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
+{
+ int retval = trusdx_set_vfo(rig, vfo);
+ if (retval != RIG_OK) { return retval; }
+ return kenwood_set_freq(rig, RIG_VFO_A, freq);
+}
+
+static int trusdx_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
+{
+ int retval = trusdx_set_vfo(rig, vfo);
+ if (retval != RIG_OK) { return retval; }
+ return kenwood_get_freq(rig, RIG_VFO_A, freq);
+}
+
+static int trusdx_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
+{
+ int retval = trusdx_set_vfo(rig, vfo);
+ if (retval != RIG_OK) { return retval; }
+
+ /* No variable filter-width command is documented. */
+ if (width != RIG_PASSBAND_NORMAL && width != RIG_PASSBAND_NOCHANGE)
+ {
+ return -RIG_ENAVAIL;
+ }
+
+ return kenwood_set_mode(rig, RIG_VFO_A, mode, RIG_PASSBAND_NOCHANGE);
+}
+
+static int trusdx_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width)
+{
+ int retval = trusdx_set_vfo(rig, vfo);
+ if (retval != RIG_OK) { return retval; }
+ return kenwood_get_mode(rig, RIG_VFO_A, mode, width);
+}
+
+static int trusdx_set_powerstat(RIG *rig, powerstat_t status)
+{
+ /* PS1 is documented, but PS0 (power off) is not. */
+ if (status != RIG_POWER_ON) { return -RIG_ENAVAIL; }
+ return kenwood_transaction(rig, "PS1", NULL, 0);
+}
+
+struct rig_caps trudx_caps =
+{
+ RIG_MODEL(RIG_MODEL_TRUSDX),
+ .model_name = "(tr)uSDX",
+ .mfg_name = "DL2MAN",
+ .version = BACKEND_VER ".3",
+ .copyright = "LGPL",
+ .status = RIG_STATUS_STABLE,
+ .rig_type = RIG_TYPE_TRANSCEIVER,
+ .ptt_type = RIG_PTT_RIG_MICDATA,
+ .dcd_type = RIG_DCD_NONE,
+ .port_type = RIG_PORT_SERIAL,
+ .serial_rate_min = 38400,
+ .serial_rate_max = 115200,
+ .serial_data_bits = 8,
+ .serial_stop_bits = 1,
+ .serial_parity = RIG_PARITY_NONE,
+ .serial_handshake = RIG_HANDSHAKE_NONE,
+ .timeout = 500,
+ .retry = 3,
+ .transceive = RIG_TRN_OFF,
+
+ .rx_range_list1 = {
+ {kHz(3500), kHz(29700), TRUSDX_MODES, -1, -1, RIG_VFO_A},
+ RIG_FRNG_END,
+ }, /*!< Receive frequency range list for ITU region 1 */
+ .tx_range_list1 = {
+ {kHz(3500), kHz(3800), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(5250), kHz(5450), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(7), kHz(7200), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(10100), kHz(10150), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(14), kHz(14350), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(18068), kHz(18168), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(21), kHz(21450), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(24890), kHz(24990), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(28), kHz(29700), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ RIG_FRNG_END,
+ }, /*!< Transmit frequency range list for ITU region 1 */
+ .rx_range_list2 = {
+ {kHz(3500), kHz(29700), TRUSDX_MODES, -1, -1, RIG_VFO_A},
+ RIG_FRNG_END,
+ }, /*!< Receive frequency range list for ITU region 2 */
+ .tx_range_list2 = {
+ {kHz(3500), MHz(4) - 1, TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(5250), kHz(5450), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(7), kHz(7300), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(10100), kHz(10150), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(14), kHz(14350), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(18068), kHz(18168), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(21), kHz(21450), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {kHz(24890), kHz(24990), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ {MHz(28), kHz(29700), TRUSDX_MODES, 500, 5000, RIG_VFO_A},
+ RIG_FRNG_END,
+ }, /*!< Transmit frequency range list for ITU region 2 */
+ .tuning_steps = {
+ {TRUSDX_MODES, 1},
+ RIG_TS_END,
+ },
+ .priv = &trusdx_priv_caps,
+ .rig_init = kenwood_init,
+ .rig_open = trusdx_open,
+ .rig_cleanup = kenwood_cleanup,
+ .set_freq = trusdx_set_freq,
+ .get_freq = trusdx_get_freq,
+ .set_mode = trusdx_set_mode,
+ .get_mode = trusdx_get_mode,
+ .set_vfo = trusdx_set_vfo,
+ .get_vfo = trusdx_get_vfo,
+ .set_ptt = kenwood_set_ptt,
+ .set_powerstat = trusdx_set_powerstat,
+ .get_powerstat = kenwood_get_powerstat,
+ .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
+};
diff --git a/rigs/kenwood/ts480.c b/rigs/kenwood/ts480.c
index 9dbbd73af..ba6b7600e 100644
--- a/rigs/kenwood/ts480.c
+++ b/rigs/kenwood/ts480.c
@@ -1683,216 +1683,6 @@ struct rig_caps ts480_caps =
.hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
};
-/*
- * truSDC rig capabilities
- * Notice that some rigs share the same functions.
- */
-struct rig_caps trudx_caps =
-{
- RIG_MODEL(RIG_MODEL_TRUSDX),
- .model_name = "(tr)uSDX",
- .mfg_name = "DL2MAN",
- .version = BACKEND_VER ".1",
- .copyright = "LGPL",
- .status = RIG_STATUS_STABLE,
- .rig_type = RIG_TYPE_TRANSCEIVER,
- .ptt_type = RIG_PTT_RIG_MICDATA,
- .dcd_type = RIG_DCD_RIG,
- .port_type = RIG_PORT_SERIAL,
- .serial_rate_min = 38400,
- .serial_rate_max = 115200,
- .serial_data_bits = 8,
- .serial_stop_bits = 1,
- .serial_parity = RIG_PARITY_NONE,
- .serial_handshake = RIG_HANDSHAKE_NONE,
- .write_delay = 0,
- .post_write_delay = 0,
- .timeout = 500,
- .retry = 3,
- .preamp = {12, RIG_DBLST_END,},
- .attenuator = {12, RIG_DBLST_END,},
- .max_rit = kHz(9.99),
- .max_xit = kHz(9.99),
- .max_ifshift = Hz(0),
- .targetable_vfo = RIG_TARGETABLE_FREQ,
- .transceive = RIG_TRN_RIG,
- .agc_level_count = 3,
- .agc_levels = { RIG_AGC_OFF, RIG_AGC_FAST, RIG_AGC_SLOW },
-
- .rx_range_list1 = {
- {kHz(100), Hz(59999999), TS480_ALL_MODES, -1, -1, TS480_VFO},
- RIG_FRNG_END,
- }, /*!< Receive frequency range list for ITU region 1 */
- .tx_range_list1 = {
- {kHz(1810), kHz(1850), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO}, /* 100W class */
- {kHz(1810), kHz(1850), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO}, /* 25W class */
- {kHz(3500), kHz(3800), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(3500), kHz(3800), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(7), kHz(7200), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(7), kHz(7200), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {kHz(10100), kHz(10150), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(10100), kHz(10150), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(14), kHz(14350), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(14), kHz(14350), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {kHz(18068), kHz(18168), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(18068), kHz(18168), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(21), kHz(21450), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(21), kHz(21450), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {kHz(24890), kHz(24990), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(24890), kHz(24990), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(28), kHz(29700), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(28), kHz(29700), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(50), kHz(52000), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(50), kHz(52000), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- RIG_FRNG_END,
- }, /*!< Transmit frequency range list for ITU region 1 */
- .rx_range_list2 = {
- {kHz(100), Hz(59999999), TS480_ALL_MODES, -1, -1, TS480_VFO},
- RIG_FRNG_END,
- }, /*!< Receive frequency range list for ITU region 2 */
- .tx_range_list2 = {
- {kHz(1800), MHz(2) - 1, TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO}, /* 100W class */
- {kHz(1800), MHz(2) - 1, TS480_AM_TX_MODES, 5000, 25000, TS480_VFO}, /* 25W class */
- {kHz(3500), MHz(4) - 1, TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(3500), MHz(4) - 1, TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {kHz(5250), kHz(5450), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(5250), kHz(5450), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(7), kHz(7300), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(7), kHz(7300), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {kHz(10100), kHz(10150), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(10100), kHz(10150), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(14), kHz(14350), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(14), kHz(14350), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {kHz(18068), kHz(18168), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(18068), kHz(18168), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(21), kHz(21450), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(21), kHz(21450), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {kHz(24890), kHz(24990), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {kHz(24890), kHz(24990), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(28), kHz(29700), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(28), kHz(29700), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- {MHz(50), kHz(52000), TS480_OTHER_TX_MODES, 5000, 100000, TS480_VFO},
- {MHz(50), kHz(52000), TS480_AM_TX_MODES, 5000, 25000, TS480_VFO},
- RIG_FRNG_END,
- }, /*!< Transmit frequency range list for ITU region 2 */
- .tuning_steps = {
- {TS480_ALL_MODES, kHz(1)},
- {TS480_ALL_MODES, Hz(2500)},
- {TS480_ALL_MODES, kHz(5)},
- {TS480_ALL_MODES, Hz(6250)},
- {TS480_ALL_MODES, kHz(10)},
- {TS480_ALL_MODES, Hz(12500)},
- {TS480_ALL_MODES, kHz(15)},
- {TS480_ALL_MODES, kHz(20)},
- {TS480_ALL_MODES, kHz(25)},
- {TS480_ALL_MODES, kHz(30)},
- {TS480_ALL_MODES, kHz(100)},
- {TS480_ALL_MODES, kHz(500)},
- {TS480_ALL_MODES, MHz(1)},
- {TS480_ALL_MODES, 0}, /* any tuning step */
- RIG_TS_END,
- },
- /* mode/filter list, remember: order matters! */
- .filters = {
- {RIG_MODE_SSB, kHz(2.4)},
- {RIG_MODE_SSB, Hz(270)},
- {RIG_MODE_SSB, Hz(500)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(200)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(50)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(1000)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(80)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(100)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(150)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(300)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(400)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(500)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(600)},
- {RIG_MODE_CW | RIG_MODE_CWR, Hz(2000)},
- {RIG_MODE_RTTY | RIG_MODE_RTTYR, Hz(500)},
- {RIG_MODE_RTTY | RIG_MODE_RTTYR, Hz(250)},
- {RIG_MODE_RTTY | RIG_MODE_RTTYR, Hz(1000)},
- {RIG_MODE_RTTY | RIG_MODE_RTTYR, Hz(1500)},
- {RIG_MODE_AM, kHz(6)},
- {RIG_MODE_AM, kHz(2.4)},
- {RIG_MODE_FM, kHz(12)},
- RIG_FLT_END,
- },
- .vfo_ops = TS480_VFO_OPS,
- .level_gran =
- {
-#define NO_LVL_VOXDELAY
-#define NO_LVL_KEYSPD
-#define NO_LVL_CWPITCH
-#define NO_LVL_BKIN_DLYMS
-#define NO_LVL_SLOPE_LOW
-#define NO_LVL_SLOPE_HIGH
-#include "level_gran_kenwood.h"
-#undef NO_LVL_VOXDELAY
-#undef NO_LVL_KEYSPD
-#undef NO_LVL_CWPITCH
-#undef NO_LVL_BKIN_DLYMS
-#undef NO_LVL_SLOPE_LOW
-#undef NO_LVL_SLOPE_HIGH
- [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 30 }, .step = { .i = 1 } },
- [LVL_KEYSPD] = {.min = {.i = 10}, .max = {.i = 60}, .step = {.i = 1}},
- [LVL_CWPITCH] = {.min = {.i = 400}, .max = {.i = 1000}, .step = {.i = 50}},
- [LVL_BKIN_DLYMS] = {.min = {.i = 0}, .max = {.i = 1000}, .step = {.i = 50}},
- [LVL_SLOPE_LOW] = {.min = {.i = 0}, .max = {.i = 2400}, .step = {.i = 10}},
- [LVL_SLOPE_HIGH] = {.min = {.i = 0}, .max = {.i = 5000}, .step = {.i = 10}},
- },
- .str_cal = TS480_STR_CAL,
- .swr_cal = TS480_SWR_CAL,
-
- .ext_tokens = ts480_ext_tokens,
- .extfuncs = ts480_ext_funcs,
- .extlevels = ts480_ext_levels,
-
- .priv = (void *)& ts480_priv_caps,
- .rig_init = ts480_init,
- .rig_open = kenwood_open,
- .rig_cleanup = kenwood_cleanup,
- .set_freq = kenwood_set_freq,
- .get_freq = kenwood_get_freq,
- .set_rit = ts480_set_rit,
- .get_rit = ts480_get_rit,
- .set_xit = ts480_set_rit,
- .get_xit = ts480_get_rit,
- .set_mode = kenwood_set_mode,
- .get_mode = kenwood_get_mode,
- .set_vfo = kenwood_set_vfo,
- .get_vfo = kenwood_get_vfo_if,
- .set_split_vfo = kenwood_set_split_vfo,
- .get_split_vfo = kenwood_get_split_vfo_if,
- .get_ptt = kenwood_get_ptt,
- .set_ptt = kenwood_set_ptt,
- .get_dcd = kenwood_get_dcd,
- .set_powerstat = kenwood_set_powerstat,
- .get_powerstat = kenwood_get_powerstat,
- .get_info = kenwood_ts480_get_info,
- .reset = kenwood_reset,
- .set_ant = kenwood_set_ant,
- .get_ant = kenwood_get_ant,
- .scan = kenwood_scan, /* not working, invalid arguments using rigctl; kenwood_scan does only support on/off and not tone and CTCSS scan */
- .has_set_level = TS480_LEVEL_SET,
- .has_get_level = TS480_LEVEL_GET,
- .set_level = kenwood_ts480_set_level,
- .get_level = kenwood_ts480_get_level,
- .set_ext_level = ts480_set_ext_level,
- .get_ext_level = ts480_get_ext_level,
- .has_get_func = TS480_FUNC_ALL,
- .has_set_func = TS480_FUNC_ALL,
- .set_func = ts480_set_func,
- .get_func = ts480_get_func,
- .set_ext_func = ts480_set_ext_func,
- .get_ext_func = ts480_get_ext_func,
- .send_morse = kenwood_send_morse,
- .wait_morse = rig_wait_morse,
- .send_voice_mem = kenwood_send_voice_mem,
- .stop_voice_mem = kenwood_stop_voice_mem,
- .vfo_op = kenwood_vfo_op,
- .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS
-};
-
/*
* QRPLabs TS-480 emulation rig capabilities
* Notice that some rigs share the same functions.
diff --git a/simulators/simtrusdx.c b/simulators/simtrusdx.c
index 6527f22f4..380ed2a45 100644
--- a/simulators/simtrusdx.c
+++ b/simulators/simtrusdx.c
@@ -1,295 +1,66 @@
-// can run this using rigctl/rigctld and socat pty devices
+/* CAT control simulator for the documented (tr)uSDX subset.
+ * https://dl2man.de/5-trusdx-details/
+ * Audio streaming is not simulated.
+ */
#define _XOPEN_SOURCE 700
-// since we are POSIX here we need this
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
-
#include "hamlib/rig.h"
#include "misc.h"
-
-
-int mysleep = 20;
-
-float freqA = 14074000;
-float freqB = 14074500;
-int filternum = 7;
-int datamode = 0;
-int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune;
-int tomode = 0;
-int keyspd = 25;
-
-
#include "sim.h"
-
int main(int argc, char *argv[])
{
- char buf[BUFSIZE];
- char *pbuf;
- int fd = openPort(argv[1]);
- int freqa = 14074000, freqb = 140735000;
- int modeA = 1, modeB = 2;
+ char buf[BUFSIZE], reply[BUFSIZE];
+ int fd;
+ long freq = 14075000;
+ int mode = 2;
+
+ if (argc != 2) { return 1; }
+ fd = openPort(argv[1]);
+ if (fd < 0) { return 1; }
while (1)
{
buf[0] = 0;
+ if (getmyline(fd, buf) <= 0) { continue; }
+ printf("Cmd:%s\n", buf);
+ reply[0] = 0;
- if (getmyline(fd, buf) > 0) { printf("Cmd:%s\n", buf); }
-
-// else { return 0; }
-
- if (strcmp(buf, "RM5;") == 0)
- {
- printf("%s\n", buf);
- hl_usleep(mysleep * 1000);
- pbuf = "RM5100000;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
-
- else if (strcmp(buf, "AN0;") == 0)
- {
- printf("%s\n", buf);
- hl_usleep(mysleep * 1000);
- pbuf = "AN030;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strcmp(buf, "IF;") == 0)
- {
- char ifbuf[256];
- printf("%s\n", buf);
- hl_usleep(mysleep * 1000);
- pbuf = "IF000503130001000+0000000000030000000;";
- sprintf(ifbuf, "IF%011d0001000+0000000000030000000;", freqa);
- //pbuf = "IF00010138698 +00000000002000000 ;
- WRITE(fd, ifbuf, strlen(ifbuf));
- }
- else if (strcmp(buf, "NB;") == 0)
- {
- hl_usleep(mysleep * 1000);
- pbuf = "NB0;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strcmp(buf, "RA;") == 0)
- {
- hl_usleep(mysleep * 1000);
- pbuf = "RA01;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strcmp(buf, "RG;") == 0)
- {
- hl_usleep(mysleep * 1000);
- pbuf = "RG055;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strcmp(buf, "MG;") == 0)
- {
- hl_usleep(mysleep * 1000);
- pbuf = "MG050;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strcmp(buf, "AG;") == 0)
- {
- hl_usleep(mysleep * 1000);
- pbuf = "AG100;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strcmp(buf, "FV;") == 0)
- {
- hl_usleep(mysleep * 1000);
- pbuf = "FV1.2;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strncmp(buf, "IS;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "IS+0000;");
- WRITE(fd, buf, strlen(buf));
- printf("%s\n", buf);
- }
- else if (strncmp(buf, "IS", 2) == 0)
- {
- }
- else if (strncmp(buf, "SM;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "SM0035;");
- WRITE(fd, buf, strlen(buf));
- printf("%s\n", buf);
- }
- else if (strncmp(buf, "PC;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "PC100;");
- WRITE(fd, buf, strlen(buf));
- printf("%s\n", buf);
- }
- else if (strcmp(buf, "FW;") == 0)
- {
- //usleep(mysleep * 1000);
- pbuf = "FW240";
- WRITE(fd, pbuf, strlen(pbuf));
- hl_usleep(20 * 1000);
- pbuf = "0;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strncmp(buf, "FW", 2) == 0)
- {
- }
- else if (strcmp(buf, "ID;") == 0)
- {
- printf("%s\n", buf);
- hl_usleep(mysleep * 1000);
- SNPRINTF(buf, sizeof(buf), "ID%03d;", 20);
- WRITE(fd, buf, strlen(buf));
- }
-
- else if (strcmp(buf, "VS;") == 0)
- {
- printf("%s\n", buf);
- hl_usleep(mysleep * 1000);
- pbuf = "VS0;";
- WRITE(fd, pbuf, strlen(pbuf));
- }
- else if (strcmp(buf, "EX032;") == 0)
- {
- static int ant = 0;
- ant = (ant + 1) % 3;
- printf("%s\n", buf);
- hl_usleep(mysleep * 1000);
- SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant);
- WRITE(fd, buf, strlen(buf));
- }
- else if (strncmp(buf, "EX", 2) == 0)
- {
- }
- else if (strcmp(buf, "FA;") == 0)
- {
- SNPRINTF(buf, sizeof(buf), "FA%011d;", freqa);
- WRITE(fd, buf, strlen(buf));
- }
- else if (strcmp(buf, "FB;") == 0)
- {
- SNPRINTF(buf, sizeof(buf), "FB%011d;", freqb);
- WRITE(fd, buf, strlen(buf));
- }
- else if (strncmp(buf, "FA", 2) == 0)
- {
- sscanf(buf, "FA%d", &freqa);
- }
- else if (strncmp(buf, "FB", 2) == 0)
- {
- sscanf(buf, "FB%d", &freqb);
- }
- else if (strncmp(buf, "AI", 2) == 0)
- {
- // nothing to do yet
- }
-
- else if (strncmp(buf, "PS;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "PS1;");
- WRITE(fd, buf, strlen(buf));
- }
- else if (strncmp(buf, "SA;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "SA0;");
- WRITE(fd, buf, strlen(buf));
- }
- else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2],
- buf[2] == '0' ? freqA : freqB,
- buf[2] == '0' ? modeA + '0' : modeB + '0');
- WRITE(fd, buf, strlen(buf));
- }
- else if (strncmp(buf, "SF", 2) == 0)
- {
- mode_t tmpmode = buf[14];
-
- if (buf[2] == '0') { modeA = tmpmode - '0'; }
- else { modeB = tmpmode - '0'; }
-
- printf("modeA=%c, modeB=%c\n", modeA, modeB);
-
- }
- else if (strncmp(buf, "MD;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "MD%d;",
- modeA); // not worried about modeB yet for simulator
- WRITE(fd, buf, strlen(buf));
- }
- else if (strncmp(buf, "MD", 2) == 0)
+ if (!strcmp(buf, "ID;")) { strcpy(reply, "ID020;"); }
+ else if (!strcmp(buf, "FA;")) { SNPRINTF(reply, sizeof(reply), "FA%011ld;", freq); }
+ else if (strlen(buf) == 14 && !strncmp(buf, "FA", 2)
+ && strspn(buf + 2, "0123456789") == 11 && buf[13] == ';')
{
- sscanf(buf, "MD%d", &modeA); // not worried about modeB yet for simulator
+ freq = atol(buf + 2);
}
- else if (strncmp(buf, "FL;", 3) == 0)
+ else if (!strcmp(buf, "MD;")) { SNPRINTF(reply, sizeof(reply), "MD%d;", mode); }
+ else if (strlen(buf) == 4 && !strncmp(buf, "MD", 2)
+ && buf[2] >= '0' && buf[2] <= '5' && buf[3] == ';')
{
- SNPRINTF(buf, sizeof(buf), "FL%03d;", filternum);
- WRITE(fd, buf, strlen(buf));
+ if (buf[2] != '0') { mode = buf[2] - '0'; }
}
- else if (strncmp(buf, "FL", 2) == 0)
+ else if (!strcmp(buf, "IF;"))
{
- sscanf(buf, "FL%d", &filternum);
+ /* Only frequency and mode are meaningful in truSDX IF replies. */
+ SNPRINTF(reply, sizeof(reply), "IF%011ld00000+0000000000%d0000000;", freq, mode);
}
- else if (strcmp(buf, "FR;") == 0)
+ else if (!strcmp(buf, "PS;")) { strcpy(reply, "PS1;"); }
+ else if (!strcmp(buf, "AI;")) { strcpy(reply, "AI0;"); }
+ else if (!strcmp(buf, "RX;") || !strcmp(buf, "TX;")
+ || !strcmp(buf, "TX0;") || !strcmp(buf, "TX1;")
+ || !strcmp(buf, "TX2;") || !strcmp(buf, "PS1;")
+ || !strcmp(buf, "AI0;") || !strcmp(buf, "UA0;"))
{
- SNPRINTF(buf, sizeof(buf), "FR%d;", vfo);
- WRITE(fd, buf, strlen(buf));
+ /* Control commands with no reply. */
}
- else if (strncmp(buf, "FR", 2) == 0)
+ else
{
- sscanf(buf, "FR%d", &vfo);
+ fprintf(stderr, "Unsupported simulator command: %s\n", buf);
+ strcpy(reply, "?;");
}
- else if (strcmp(buf, "FT;") == 0)
- {
- SNPRINTF(buf, sizeof(buf), "FT%d;", vfo_tx);
- WRITE(fd, buf, strlen(buf));
- }
- else if (strncmp(buf, "FT", 2) == 0)
- {
- sscanf(buf, "FT%d", &vfo_tx);
- }
- else if (strncmp(buf, "DA;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "DA%d;", datamode);
- WRITE(fd, buf, strlen(buf));
- printf("%s\n", buf);
- }
- else if (strncmp(buf, "DA", 2) == 0)
- {
- sscanf(buf, "DA%d", &datamode);
- printf("%s\n", buf);
- }
- else if (strncmp(buf, "TO;", 3) == 0)
- {
- SNPRINTF(buf, sizeof(buf), "TO%d;", tomode);
- }
- else if (strncmp(buf, "BD;", 3) == 0)
- {
- }
- else if (strncmp(buf, "BU;", 3) == 0)
- {
- }
- else if (strncmp(buf, "TX", 2) == 0)
- {
- ptt = ptt_mic = ptt_data = ptt_tune = 0;
-
- switch (buf[2])
- {
- case ';': ptt = 1;
-
- case '0': ptt_mic = 1;
-
- case '1': ptt_data = 1;
- case '2': ptt_tune = 1;
- }
-
- }
-
- else if (strlen(buf) > 0)
- {
- fprintf(stderr, "Unknown command: %s\n", buf);
- }
+ if (reply[0]) { WRITE(fd, reply, strlen(reply)); }
}
-
- return 0;
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4e1c3b8ef..356e6e93b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,7 +37,8 @@ DIRECT_TESTS = \
testsmartsdrstatus \
testthd7x \
testthd75emu \
- testts990s
+ testts990s \
+ testtrusdx
GENERATED_TEST_WRAPPERS = \
test2038.sh \
diff --git a/tests/testtrusdx.c b/tests/testtrusdx.c
new file mode 100644
index 000000000..e63105ac7
--- /dev/null
+++ b/tests/testtrusdx.c
@@ -0,0 +1,138 @@
+/* Exercise the documented truSDX CAT subset over a pseudo terminal. */
+#if defined(_WIN32) || defined(WIN32)
+int main(void) { return 77; }
+#else
+#define _XOPEN_SOURCE 600
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include "hamlib/rig.h"
+
+static int emulate(int fd)
+{
+ char cmd[64], reply[80];
+ size_t used = 0;
+ char byte;
+ long freq = 14075000;
+ int mode = 2, failures = 0;
+
+ while (read(fd, &byte, 1) == 1)
+ {
+ if (byte != ';')
+ {
+ if (used + 1 >= sizeof(cmd)) { return 1; }
+ cmd[used++] = byte;
+ continue;
+ }
+
+ cmd[used] = 0;
+ used = 0;
+ reply[0] = 0;
+
+ if (!strcmp(cmd, "ID")) { strcpy(reply, "ID020;"); }
+ else if (!strcmp(cmd, "FA")) { snprintf(reply, sizeof(reply), "FA%011ld;", freq); }
+ else if (strlen(cmd) == 13 && !strncmp(cmd, "FA", 2)
+ && strspn(cmd + 2, "0123456789") == 11) { freq = atol(cmd + 2); }
+ else if (!strcmp(cmd, "MD")) { snprintf(reply, sizeof(reply), "MD%d;", mode); }
+ else if (strlen(cmd) == 3 && !strncmp(cmd, "MD", 2)
+ && cmd[2] >= '1' && cmd[2] <= '5') { mode = cmd[2] - '0'; }
+ else if (!strcmp(cmd, "PS")) { strcpy(reply, "PS1;"); }
+ else if (!strcmp(cmd, "TX") || !strcmp(cmd, "TX0")
+ || !strcmp(cmd, "TX1") || !strcmp(cmd, "RX")
+ || !strcmp(cmd, "PS1")) { /* No reply to setters. */ }
+ else
+ {
+ fprintf(stderr, "Undocumented/unexpected command: %s;\n", cmd);
+ failures++;
+ strcpy(reply, "?;");
+ }
+
+ if (reply[0] && write(fd, reply, strlen(reply)) < 0) { return 1; }
+ }
+
+ return failures ? 1 : 0;
+}
+
+#define CHECK(expr) do { if (!(expr)) { fprintf(stderr, "FAIL line %d: %s\n", __LINE__, #expr); failures++; } } while (0)
+
+int main(void)
+{
+ int master, guard, status, failures = 0;
+ pid_t child;
+ const char *path;
+ RIG *rig;
+ freq_t freq;
+ rmode_t mode;
+ pbwidth_t width;
+ powerstat_t power;
+ ptt_t ptt;
+ value_t value;
+ vfo_t vfo;
+ split_t split;
+ shortfreq_t rit;
+ dcd_t dcd;
+ const rmode_t modes[] = {RIG_MODE_LSB, RIG_MODE_USB, RIG_MODE_CW, RIG_MODE_FM, RIG_MODE_AM};
+
+ alarm(30);
+ master = posix_openpt(O_RDWR | O_NOCTTY);
+ if (master < 0 || grantpt(master) < 0 || unlockpt(master) < 0) { return 1; }
+ path = ptsname(master);
+ if (!path || (guard = open(path, O_RDWR | O_NOCTTY)) < 0) { return 1; }
+ child = fork();
+ if (child < 0) { return 1; }
+ if (child == 0) { close(guard); _exit(emulate(master)); }
+ close(master);
+
+ rig_set_debug_level(RIG_DEBUG_NONE);
+ rig = rig_init(RIG_MODEL_TRUSDX);
+ if (!rig) { return 1; }
+ rig_set_conf(rig, rig_token_lookup(rig, "rig_pathname"), path);
+ rig_set_conf(rig, rig_token_lookup(rig, "cache_timeout"), "0");
+ CHECK(rig_open(rig) == RIG_OK);
+ close(guard);
+ CHECK(rig_get_freq(rig, RIG_VFO_CURR, &freq) == RIG_OK && freq == 14075000);
+ CHECK(rig_get_mode(rig, RIG_VFO_CURR, &mode, &width) == RIG_OK && mode == RIG_MODE_USB);
+ CHECK(rig_set_freq(rig, RIG_VFO_A, 7100000) == RIG_OK);
+ CHECK(rig_get_freq(rig, RIG_VFO_A, &freq) == RIG_OK && freq == 7100000);
+
+ for (size_t i = 0; i < sizeof(modes) / sizeof(modes[0]); i++)
+ {
+ CHECK(rig_set_mode(rig, RIG_VFO_A, modes[i], RIG_PASSBAND_NORMAL) == RIG_OK);
+ CHECK(rig_get_mode(rig, RIG_VFO_A, &mode, &width) == RIG_OK && mode == modes[i]);
+ }
+
+ CHECK(rig_set_ptt(rig, RIG_VFO_A, RIG_PTT_ON) == RIG_OK);
+ CHECK(rig_set_ptt(rig, RIG_VFO_A, RIG_PTT_ON_MIC) == RIG_OK);
+ CHECK(rig_set_ptt(rig, RIG_VFO_A, RIG_PTT_ON_DATA) == RIG_OK);
+ CHECK(rig_set_ptt(rig, RIG_VFO_A, RIG_PTT_OFF) == RIG_OK);
+ CHECK(rig_get_powerstat(rig, &power) == RIG_OK && power == RIG_POWER_ON);
+ CHECK(rig_set_powerstat(rig, RIG_POWER_ON) == RIG_OK);
+ CHECK(rig_set_powerstat(rig, RIG_POWER_OFF) < 0);
+ CHECK(rig_set_vfo(rig, RIG_VFO_B) < 0);
+ CHECK(rig_set_freq(rig, RIG_VFO_B, 7200000) < 0);
+ CHECK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_RTTY, RIG_PASSBAND_NORMAL) < 0);
+ CHECK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_CWR, RIG_PASSBAND_NORMAL) < 0);
+ CHECK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_USB, 500) < 0);
+ CHECK(rig_get_level(rig, RIG_VFO_A, RIG_LEVEL_STRENGTH, &value) < 0);
+ CHECK(rig_set_split_vfo(rig, RIG_VFO_A, RIG_SPLIT_ON, RIG_VFO_B) < 0);
+ /* The frontend synthesizes split-off for single-VFO rigs. */
+ CHECK(rig_get_split_vfo(rig, RIG_VFO_A, &split, &vfo) == RIG_OK
+ && split == RIG_SPLIT_OFF);
+ CHECK(rig_get_rit(rig, RIG_VFO_A, &rit) < 0);
+ CHECK(rig_get_dcd(rig, RIG_VFO_A, &dcd) < 0);
+ CHECK(rig->caps->get_ptt == NULL);
+ /* The frontend may return cached PTT; the backend must not query IF for it. */
+ rig_get_ptt(rig, RIG_VFO_A, &ptt);
+ CHECK(rig_send_morse(rig, RIG_VFO_A, "TEST") < 0);
+ CHECK(rig->caps->has_get_level == 0 && rig->caps->has_set_level == 0);
+ CHECK(rig->caps->has_get_func == 0 && rig->caps->has_set_func == 0);
+ CHECK(rig_close(rig) == RIG_OK);
+ rig_cleanup(rig);
+ waitpid(child, &status, 0);
+ CHECK(WIFEXITED(status) && WEXITSTATUS(status) == 0);
+ return failures ? 1 : 0;
+}
+#endif
commit 1670b83e90fa058bf4e9eb588a1aa7d45f46e531
Author: KJ5HST <kj...@de...>
Date: Thu Oct 22 17:30:15 2026 -0500
fix(windows): include assert declaration in precise timer
The Windows QueryPerformanceCounter implementation calls assert(), and
newer GCC versions reject the missing declaration. Include the owning
header so native UCRT64 builds compile without an implicit declaration.
(cherry picked from commit 2b5608a0a038dee3049206f40b1e4d30c6023680)
diff --git a/lib/precise_time.c b/lib/precise_time.c
index 5cc2c4d49..5896fa03c 100644
--- a/lib/precise_time.c
+++ b/lib/precise_time.c
@@ -88,6 +88,7 @@ double monotonic_seconds()
// On Windows, use QueryPerformanceCounter and QueryPerformanceFrequency.
#include <windows.h>
+#include <assert.h>
static double PCFreq = 0.0;
commit aef8632f49c1d5b69715acf1c56588e03d059171
Author: David Christle <dch...@us...>
Date: Fri Jul 31 17:57:48 2026 -0500
fix(daemons): cap concurrent client threads
Each accepted connection created a detached worker without an
application-level admission limit. Bound active workers with a configurable
32-client default and roll back reservations on failure.
Reject excess connections without disrupting admitted clients, document the
saturation behavior, and cover parsing, accounting, and daemon-level recovery.
(cherry picked from commit 2870074d373732c749bbee0a9de52f0e9575e85e)
diff --git a/doc/man1/ampctld.1 b/doc/man1/ampctld.1
index 5be9b2d1e..4ce082f6d 100644
--- a/doc/man1/ampctld.1
+++ b/doc/man1/ampctld.1
@@ -22,6 +22,7 @@ ampctld \- TCP amplifier control daemon
.OP \-s baud
.OP \-T IPADDR
.OP \-t number
+.OP \-N number
.OP \-C parm=val
.RB [ \-v [ \-Z ]]
.YS
@@ -157,6 +158,14 @@ for multiple
instances, e.g. 4529, 4527, 4525, etc.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fInumber\fP
+Limit the number of concurrent TCP clients to
+.IR number .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.TP
.BR \-T ", " \-\-listen\-addr = \fIIPADDR\fP
Use
.I IPADDR
diff --git a/doc/man1/rigctld.1 b/doc/man1/rigctld.1
index 3c92a6140..4ce1e736f 100644
--- a/doc/man1/rigctld.1
+++ b/doc/man1/rigctld.1
@@ -28,6 +28,7 @@ rigctld \- TCP radio control daemon
.OP \-S char
.OP \-T IPADDR
.OP \-t number
+.OP \-N number
.OP \-C parm=val
.OP \-X seconds
.RB [ \-v [ \-Z ]]
@@ -291,6 +292,14 @@ default port is 4533, it is advisable to use even numbered ports for
e.g. 4532, 4534, 4536, etc.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fInumber\fP
+Limit the number of concurrent TCP clients to
+.IR number .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.TP
.BR \-L ", " \-\-show\-conf
List all config parameters for the radio defined with
.B \-m
diff --git a/doc/man1/rigctltcp.1 b/doc/man1/rigctltcp.1
index b95bbcf8c..d8f5e24f3 100644
--- a/doc/man1/rigctltcp.1
+++ b/doc/man1/rigctltcp.1
@@ -29,6 +29,7 @@ rigctltcp \- TCP multicast control of radio transceivers and receivers
.OP \-C parm=val
.OP \-T ipaddr
.OP \-t num
+.OP \-N num
.OP \-M addr
.OP \-n port
.OP \-W secs
@@ -398,6 +399,15 @@ The default is 4531.
.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fINUM\fP
+Limit the number of concurrent TCP clients to
+.IR NUM .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.
+.TP
.BR \-M ", " \-\-multicast\-addr = \fIADDR\fP
Use
.I ADDR
diff --git a/doc/man1/rotctld.1 b/doc/man1/rotctld.1
index 35e336f8c..a05ff9a20 100644
--- a/doc/man1/rotctld.1
+++ b/doc/man1/rotctld.1
@@ -22,6 +22,7 @@ rotctld \- TCP rotator control daemon
.OP \-s baud
.OP \-T IPADDR
.OP \-t number
+.OP \-N number
.OP \-C parm=val
.RB [ \-v [ \-Z ]]
.YS
@@ -177,6 +178,14 @@ default port is 4533, it is advisable to use odd numbered ports for
e.g. 4533, 4535, 4537, etc.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fInumber\fP
+Limit the number of concurrent TCP clients to
+.IR number .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.TP
.BR \-L ", " \-\-show\-conf
List all configuration parameters for the rotator defined with
.B \-m
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 43b6e0629..4e1c3b8ef 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,6 +19,8 @@ bin_PROGRAMS = rigctl rigctld rigmem rigsmtr rigswr rotctl rotctld rigctlcom rig
DIRECT_TESTS = \
testbandmetadata \
testctlparser \
+ testdaemonclient \
+ testdaemonclients \
testdebug \
testdummyparm \
testid5100 \
@@ -75,16 +77,17 @@ check_PROGRAMS = \
RIGCOMMONSRC = rigctl_parse.c rigctl_parse.h dumpcaps.c dumpstate.c uthash.h rig_tests.c rig_tests.h dumpcaps.h
ROTCOMMONSRC = rotctl_parse.c rotctl_parse.h dumpcaps_rot.c uthash.h dumpcaps_rot.h
AMPCOMMONSRC = ampctl_parse.c ampctl_parse.h dumpcaps_amp.c uthash.h
+DAEMONCLIENTSRC = daemon_client.c daemon_client.h
rigctl_SOURCES = rigctl.c $(RIGCOMMONSRC)
-rigctld_SOURCES = rigctld.c $(RIGCOMMONSRC)
+rigctld_SOURCES = rigctld.c $(RIGCOMMONSRC) $(DAEMONCLIENTSRC)
rigctlcom_SOURCES = rigctlcom.c $(RIGCOMMONSRC)
-rigctltcp_SOURCES = rigctltcp.c $(RIGCOMMONSRC)
+rigctltcp_SOURCES = rigctltcp.c $(RIGCOMMONSRC) $(DAEMONCLIENTSRC)
rigctlsync_SOURCES = rigctlsync.c $(RIGCOMMONSRC)
rotctl_SOURCES = rotctl.c $(ROTCOMMONSRC)
-rotctld_SOURCES = rotctld.c $(ROTCOMMONSRC)
+rotctld_SOURCES = rotctld.c $(ROTCOMMONSRC) $(DAEMONCLIENTSRC)
ampctl_SOURCES = ampctl.c $(AMPCOMMONSRC)
-ampctld_SOURCES = ampctld.c $(AMPCOMMONSRC)
+ampctld_SOURCES = ampctld.c $(AMPCOMMONSRC) $(DAEMONCLIENTSRC)
rigmem_SOURCES = rigmem.c memsave.c memload.c memcsv.c
if TESTS_HAVE_LIBUSB
rigtestlibusb_SOURCES = rigtestlibusb.c
@@ -112,6 +115,7 @@ rigctlsync_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_builddir)/security
testdebug_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testnetrigctl_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testsendraw_CFLAGS = $(AM_CFLAGS)
+testdaemonclient_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testid5100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testid5100_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testicomfallback_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
@@ -148,6 +152,8 @@ testid5100_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhaml
testicomfallback_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testsendraw_SOURCES = testsendraw.c
testsendraw_LDADD = $(NET_LIBS) $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
+testdaemonclient_SOURCES = testdaemonclient.c $(DAEMONCLIENTSRC)
+testdaemonclient_LDADD = $(PTHREAD_LIBS) $(LDADD)
testctlparser_SOURCES = testctlparser.c $(RIGCOMMONSRC)
testctlparser_LDADD = $(PTHREAD_LIBS) $(READLINE_LIBS) $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testmodecompat_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
diff --git a/tests/ampctld.c b/tests/ampctld.c
index ba6454ad0..9de645970 100644
--- a/tests/ampctld.c
+++ b/tests/ampctld.c
@@ -58,6 +58,7 @@
#include "hamlib/amplifier.h"
+#include "daemon_client.h"
#include "ampctl_parse.h"
#include "amplist.h"
#include "rig.h"
@@ -85,7 +86,7 @@ static void short_usage(FILE *fout);
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
-#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVlZ"
+#define SHORT_OPTIONS "m:r:s:C:t:T:N:LuvhVlZ"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@@ -93,6 +94,7 @@ static struct option long_options[] =
{"serial-speed", 1, 0, 's'},
{"port", 1, 0, 't'},
{"listen-addr", 1, 0, 'T'},
+ {"max-clients", 1, 0, 'N'},
{"list", 0, 0, 'l'},
{"set-conf", 1, 0, 'C'},
{"show-conf", 0, 0, 'L'},
@@ -109,6 +111,8 @@ int prompt = 0 ; /* Daemon mode for rigparse return string */
const char *portno = "4531";
const char *src_addr = NULL; /* INADDR_ANY */
+static struct daemon_client_tracker client_tracker =
+ DAEMON_CLIENT_TRACKER_INITIALIZER;
char send_cmd_term = '\r'; /* send_cmd termination char */
@@ -245,6 +249,15 @@ int main(int argc, char *argv[])
src_addr = optarg;
break;
+ case 'N':
+ if (daemon_client_limit_parse(optarg, &client_tracker.limit) != 0)
+ {
+ fprintf(stderr, "Invalid maximum client count: %s\n", optarg);
+ exit(1);
+ }
+
+ break;
+
case 'v':
verbose++;
rig_set_debug(verbose);
@@ -514,33 +527,77 @@ int main(int argc, char *argv[])
#endif
#endif
+ retcode = pthread_attr_init(&attr);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n", strerror(retcode));
+ exit(1);
+ }
+
+ retcode = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
+ strerror(retcode));
+ pthread_attr_destroy(&attr);
+ exit(1);
+ }
+
/*
* main loop accepting connections
*/
- do
+ while (1)
{
+ struct sockaddr_storage cli_addr;
+ socklen_t clilen = sizeof(cli_addr);
+ int client_sock;
+
+ client_sock = accept(sock_listen,
+ (struct sockaddr *)&cli_addr,
+ &clilen);
+
+ if (client_sock < 0)
+ {
+ handle_error(RIG_DEBUG_ERR, "accept");
+ break;
+ }
+
+ if (!daemon_client_tracker_acquire(&client_tracker))
+ {
+ rig_debug(RIG_DEBUG_WARN,
+ "Client limit of %u reached; closing connection\n",
+ client_tracker.limit);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ continue;
+ }
+
arg = calloc(1, sizeof(struct handle_data));
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "calloc: %s\n", strerror(errno));
- exit(1);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
arg->amp = my_amp;
- arg->clilen = sizeof(arg->cli_addr);
- arg->sock = accept(sock_listen,
- (struct sockaddr *) &arg->cli_addr,
- &arg->clilen);
+ arg->sock = client_sock;
+ arg->cli_addr = cli_addr;
+ arg->clilen = clilen;
- if (arg->sock < 0)
- {
- handle_error(RIG_DEBUG_ERR, "accept");
- break;
- }
-
- if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
- arg->clilen,
+ if ((retcode = getnameinfo((struct sockaddr const *)&cli_addr,
+ clilen,
host,
sizeof(host),
serv,
@@ -559,20 +616,23 @@ int main(int argc, char *argv[])
host,
serv);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
retcode = pthread_create(&thread, &attr, handle_socket, arg);
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
- break;
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ free(arg);
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
-
}
- while (retcode == 0);
+ pthread_attr_destroy(&attr);
amp_close(my_amp); /* close port */
amp_cleanup(my_amp); /* if you care about memory */
@@ -672,6 +732,7 @@ handle_exit:
#else
close(handle_data_arg->sock);
#endif
+ daemon_client_tracker_release(&client_tracker);
free(arg);
pthread_exit(NULL);
@@ -689,6 +750,7 @@ static void usage(FILE *fout)
" -r, --amp-file=DEVICE set device of the amplifier to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --port=NUM set TCP listening port, default %s\n"
+ " -N, --max-clients=NUM set maximum concurrent clients, default %u\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL[,...] set config parameters\n"
" -L, --show-conf list all config parameters\n"
@@ -698,7 +760,8 @@ static void usage(FILE *fout)
" -Z, --debug-time-stamps enable time stamps for debug messages\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
- portno);
+ portno,
+ DAEMON_DEFAULT_MAX_CLIENTS);
usage_amp(fout);
}
diff --git a/tests/daemon_client.c b/tests/daemon_client.c
new file mode 100644
index 000000000..3d7a099ae
--- /dev/null
+++ b/tests/daemon_client.c
@@ -0,0 +1,84 @@
+#include "hamlib/config.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "daemon_client.h"
+
+int daemon_client_limit_parse(const char *value, unsigned *limit)
+{
+ char *end;
+ unsigned long parsed;
+ const char *p;
+
+ if (!value || !value[0] || !limit)
+ {
+ return -1;
+ }
+
+ for (p = value; *p; ++p)
+ {
+ if (*p < '0' || *p > '9')
+ {
+ return -1;
+ }
+ }
+
+ errno = 0;
+ parsed = strtoul(value, &end, 10);
+
+ if (errno == ERANGE || *end || parsed == 0 || parsed > UINT_MAX)
+ {
+ return -1;
+ }
+
+ *limit = (unsigned)parsed;
+ return 0;
+}
+
+int daemon_client_tracker_init(struct daemon_client_tracker *tracker,
+ unsigned limit)
+{
+ if (!tracker || limit == 0)
+ {
+ return EINVAL;
+ }
+
+ tracker->active = 0;
+ tracker->limit = limit;
+ return pthread_mutex_init(&tracker->mutex, NULL);
+}
+
+void daemon_client_tracker_destroy(struct daemon_client_tracker *tracker)
+{
+ pthread_mutex_destroy(&tracker->mutex);
+}
+
+int daemon_client_tracker_acquire(struct daemon_client_tracker *tracker)
+{
+ int acquired = 0;
+
+ pthread_mutex_lock(&tracker->mutex);
+
+ if (tracker->active < tracker->limit)
+ {
+ ++tracker->active;
+ acquired = 1;
+ }
+
+ pthread_mutex_unlock(&tracker->mutex);
+ return acquired;
+}
+
+void daemon_client_tracker_release(struct daemon_client_tracker *tracker)
+{
+ pthread_mutex_lock(&tracker->mutex);
+
+ if (tracker->active > 0)
+ {
+ --tracker->active;
+ }
+
+ pthread_mutex_unlock(&tracker->mutex);
+}
diff --git a/tests/daemon_client.h b/tests/daemon_client.h
new file mode 100644
index 000000000..babdee6af
--- /dev/null
+++ b/tests/daemon_client.h
@@ -0,0 +1,24 @@
+#ifndef HAMLIB_TESTS_DAEMON_CLIENT_H
+#define HAMLIB_TESTS_DAEMON_CLIENT_H 1
+
+#include <pthread.h>
+
+#define DAEMON_DEFAULT_MAX_CLIENTS 32U
+#define DAEMON_CLIENT_TRACKER_INITIALIZER \
+ { PTHREAD_MUTEX_INITIALIZER, 0U, DAEMON_DEFAULT_MAX_CLIENTS }
+
+struct daemon_client_tracker
+{
+ pthread_mutex_t mutex;
+ unsigned active;
+ unsigned limit;
+};
+
+int daemon_client_limit_parse(const char *value, unsigned *limit);
+int daemon_client_tracker_init(struct daemon_client_tracker *tracker,
+ unsigned limit);
+void daemon_client_tracker_destroy(struct daemon_client_tracker *tracker);
+int daemon_client_tracker_acquire(struct daemon_client_tracker *tracker);
+void daemon_client_tracker_release(struct daemon_client_tracker *tracker);
+
+#endif
diff --git a/tests/rigctld.c b/tests/rigctld.c
index 5ca2e7a83..93692ed21 100644
--- a/tests/rigctld.c
+++ b/tests/rigctld.c
@@ -71,6 +71,7 @@
#include "network.h"
#include "rigctl_parse.h"
+#include "daemon_client.h"
#include "riglist.h"
#include "token.h"
@@ -79,7 +80,7 @@
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
* TODO: add an option to read from a file
*/
-#define SHORT_OPTIONS "m:r:p:d:P:D:s:S:c:T:t:C:W:w:x:lLuovhVZRA:b"
+#define SHORT_OPTIONS "m:r:p:d:P:D:s:S:c:T:t:N:C:W:w:x:lLuovhVZRA:b"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@@ -93,6 +94,7 @@ static struct option long_options[] =
{"civaddr", 1, 0, 'c'},
{"listen-addr", 1, 0, 'T'},
{"port", 1, 0, 't'},
+ {"max-clients", 1, 0, 'N'},
{"set-conf", 1, 0, 'C'},
{"list", 0, 0, 'l'},
{"show-conf", 0, 0, 'L'},
@@ -122,6 +124,8 @@ static void usage(FILE *fout);
static void short_usage(FILE *fout);
static unsigned client_count;
+static struct daemon_client_tracker client_tracker =
+ DAEMON_CLIENT_TRACKER_INITIALIZER;
static RIG *my_rig; /* handle to rig (instance) */
static volatile int rig_opened = 0;
@@ -474,6 +478,15 @@ int main(int argc, char *argv[])
src_addr = optarg;
break;
+ case 'N':
+ if (daemon_client_limit_parse(optarg, &client_tracker.limit) != 0)
+ {
+ fprintf(stderr, "Invalid maximum client count: %s\n", optarg);
+ exit(1);
+ }
+
+ break;
+
case 'o':
vfo_mode++;
//rig_debug(RIG_DEBUG_ERR, "%s: #0 vfo_mode=%d\n", __func__, vfo_mode);
@@ -544,8 +557,8 @@ int main(int argc, char *argv[])
rig_debug(RIG_DEBUG_VERBOSE, "rigctld %s\n", hamlib_version2);
rig_debug(RIG_DEBUG_VERBOSE, "%s",
"Report bugs to <ham...@li...>\n\n");
- rig_debug(RIG_DEBUG_VERBOSE, "Max# of rigctld client services=%d\n",
- NI_MAXSERV);
+ rig_debug(RIG_DEBUG_VERBOSE, "Max# of rigctld client services=%u\n",
+ client_tracker.limit);
my_rig = rig_init(my_model);
@@ -971,6 +984,24 @@ int main(int argc, char *argv[])
rigctl_parse_init();
+ retcode = pthread_attr_init(&attr);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n", strerror(retcode));
+ exit(1);
+ }
+
+ retcode = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
+ strerror(retcode));
+ pthread_attr_destroy(&attr);
+ exit(1);
+ }
+
/*
* main loop accepting connections
*/
@@ -1019,33 +1050,57 @@ int main(int argc, char *argv[])
else
{
struct handle_data *arg;
+ struct sockaddr_storage cli_addr;
+ socklen_t clilen = sizeof(cli_addr);
+ int client_sock;
+
+ client_sock = accept(sock_listen,
+ (struct sockaddr *)&cli_addr,
+ &clilen);
+
+ if (client_sock < 0)
+ {
+ handle_error(RIG_DEBUG_ERR, "accept");
+ break;
+ }
+
+ if (!daemon_client_tracker_acquire(&client_tracker))
+ {
+ rig_debug(RIG_DEBUG_WARN,
+ "Client limit of %u reached; closing connection\n",
+ client_tracker.limit);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ continue;
+ }
arg = calloc(1, sizeof(struct handle_data));
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "calloc: %s\n", strerror(errno));
- exit(1);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
if (rigctld_password[0] != 0) { arg->use_password = 1; }
arg->rig = my_rig;
- arg->clilen = sizeof(arg->cli_addr);
+ arg->sock = client_sock;
+ arg->cli_addr = cli_addr;
+ arg->clilen = clilen;
arg->vfo_mode = vfo_mode;
- arg->sock = accept(sock_listen,
- (struct sockaddr *)&arg->cli_addr,
- &arg->clilen);
-
- if (arg->sock < 0)
- {
- handle_error(RIG_DEBUG_ERR, "accept");
- free(arg);
- break;
- }
- if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
- arg->clilen,
+ if ((retcode = getnameinfo((struct sockaddr const *)&cli_addr,
+ clilen,
host,
sizeof(host),
serv,
@@ -1063,15 +1118,19 @@ int main(int argc, char *argv[])
host,
serv);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
retcode = pthread_create(&thread, &attr, handle_socket, arg);
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
- break;
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ free(arg);
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
}
@@ -1079,6 +1138,7 @@ int main(int argc, char *argv[])
while (!ctrl_c);
rig_debug(RIG_DEBUG_VERBOSE, "%s: while loop done\n", __func__);
+ pthread_attr_destroy(&attr);
/* allow threads to finish current action */
mutex_rigctld(1);
@@ -1364,7 +1424,9 @@ handle_exit:
#endif
- pthread_setspecific(thread_data_key, NULL); // Tell pthreads we're done with the data
+ pthread_setspecific(thread_data_key,
+ ...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-10-25 13:44:12
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 075b78cb0560e892c81bc73890d633cc11f23f59 (commit)
via fd658fc71fbe08ccf3d986e2c7b9a7f2227047d7 (commit)
via a28be3e88f9830b3cf698717a63ada9ee181fd8c (commit)
via 0ed26e34983b9a6db51991dd894fd2532dfd4791 (commit)
via 0ba8f74b591ee0b9301c9263634ec3669ba180c9 (commit)
via 2b5608a0a038dee3049206f40b1e4d30c6023680 (commit)
via d269f30b754c1b38ad7a5360c32f20d7eafebc9d (commit)
via dcd90133f1d78f226160658db46f59d9837e43be (commit)
via a96343d6cd626bcea3626fa3a031ecb6d2729eb5 (commit)
via 2870074d373732c749bbee0a9de52f0e9575e85e (commit)
via 69b2aa1dc4d1a8c0e71940a930919abf06b59751 (commit)
via 780da9c6259fe9f8d64aa7ad344c9c4aa93fe80e (commit)
via 1391875d827cb5b05c854376cfd45f5ec6e70d3c (commit)
via ca55bcff6a9bca531643e734dda092f2e79c3d98 (commit)
from 06335264db0106053a2d9f7122cab28be27fe15d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 075b78cb0560e892c81bc73890d633cc11f23f59
Merge: fd658fc71 1391875d8
Author: Nate Bargmann <n0...@n0...>
Date: Fri Oct 23 07:22:20 2026 -0500
Merge commit from fork
fix(rigctld): bound send_raw binary parsing
commit fd658fc71fbe08ccf3d986e2c7b9a7f2227047d7
Merge: a28be3e88 69b2aa1dc
Author: Nate Bargmann <n0...@n0...>
Date: Fri Oct 23 07:17:38 2026 -0500
Merge commit from fork
Fix NetRig string parameter union mismatches
commit a28be3e88f9830b3cf698717a63ada9ee181fd8c
Merge: 0ed26e349 ca55bcff6
Author: Nate Bargmann <n0...@n0...>
Date: Fri Oct 23 06:54:57 2026 -0500
Merge commit from fork
fix(rigctl): bound send_cmd_rx response length
commit 0ed26e34983b9a6db51991dd894fd2532dfd4791
Merge: 0ba8f74b5 2870074d3
Author: Nate Bargmann <n0...@n0...>
Date: Fri Oct 23 06:37:44 2026 -0500
Merge commit from fork
fix(daemons): cap concurrent client threads
commit 0ba8f74b591ee0b9301c9263634ec3669ba180c9
Merge: 2b5608a0a 780da9c62
Author: Nate Bargmann <n0...@n0...>
Date: Fri Oct 23 06:23:49 2026 -0500
Merge commit from fork
fix(flexradio): validate SmartSDR status value lengths
diff --cc tests/Makefile.am
index 70e2fbae9,f2cf2d5b4..682bb25f0
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@@ -38,8 -38,8 +38,9 @@@ DIRECT_TESTS =
testnewcatset \
testnewcatwidth \
testrigctlprotocol \
+ testsendraw \
testmodecompat \
+ testsmartsdrstatus \
testthd7x \
testthd75emu \
testts990s \
@@@ -148,9 -146,11 +149,10 @@@ testid5100_CPPFLAGS = $(AM_CPPFLAGS) -I
testicomfallback_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testg90rit_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testgeministatus_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/amplifiers/gemini
-testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu \
- -I$(top_srcdir)/rigs/yaesu/ftx1
+testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu/ftx1
testft991idmeter_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu
testguohetec_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/guohetec
+ testsmartsdrstatus_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/flexradio
if TESTS_HAVE_LIBUSB
rigtestlibusb_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) $(LIBUSB_CFLAGS)
endif
commit 2b5608a0a038dee3049206f40b1e4d30c6023680
Author: KJ5HST <kj...@de...>
Date: Thu Oct 22 17:30:15 2026 -0500
precise_time: include assert.h for the Windows branch
The __WIN32__ branch of lib/precise_time.c calls assert() without
<assert.h>, so a compiler that makes implicit function declarations an
error (GCC 14 and later in C99 and later modes) stops there. A native
MSYS2 UCRT64 build takes this branch; a MinGW cross-build whose headers
define _POSIX_TIMERS takes the clock_gettime branch and never compiles it.
diff --git a/lib/precise_time.c b/lib/precise_time.c
index 5cc2c4d49..5896fa03c 100644
--- a/lib/precise_time.c
+++ b/lib/precise_time.c
@@ -88,6 +88,7 @@ double monotonic_seconds()
// On Windows, use QueryPerformanceCounter and QueryPerformanceFrequency.
#include <windows.h>
+#include <assert.h>
static double PCFreq = 0.0;
commit d269f30b754c1b38ad7a5360c32f20d7eafebc9d
Author: KJ5HST <kj...@de...>
Date: Sun Oct 18 14:42:45 2026 -0400
ftx1: re-read CLAR flags before each CF write instead of caching them
CF P3=0 sets the RX and TX clarifier flags in a single write, so
set_rx_clar() and set_tx_clar() have to preserve the other flag. Since
12ef99613 (per VFO since #2171) that flag came from a cache that a set
never refreshed, so a CLAR change made on the front panel or by another
CAT client was silently undone by the next RIT/XIT set.
Read CF<side>00; immediately before each write and remove the cache,
its invalidation calls in ftx1_set_channel(), and its unit test. The
cost is one extra CF read per RIT/XIT set; the read-then-write window
shrinks to a single CAT round trip.
diff --git a/rigs/yaesu/ftx1/ftx1_clarifier.c b/rigs/yaesu/ftx1/ftx1_clarifier.c
index 60b6255ad..12111bbb8 100644
--- a/rigs/yaesu/ftx1/ftx1_clarifier.c
+++ b/rigs/yaesu/ftx1/ftx1_clarifier.c
@@ -35,36 +35,6 @@
#define FTX1_CF_SETTING_RESP_LEN 11
#define FTX1_CF_FREQ_RESP_LEN 11
-static struct ftx1_clarifier_cache *
-ftx1_get_clar_cache(struct newcat_priv_data *priv, char vfo_param)
-{
- return &priv->ftx1_clar_cache[vfo_param - '0'];
-}
-
-void ftx1_cache_clar_state(struct newcat_priv_data *priv, char vfo_param,
- char rx_enabled, char tx_enabled)
-{
- if (vfo_param < '0' || vfo_param > '1')
- {
- return;
- }
-
- struct ftx1_clarifier_cache *cache = ftx1_get_clar_cache(priv, vfo_param);
- cache->rx_on = rx_enabled;
- cache->tx_on = tx_enabled;
- cache->valid = true;
-}
-
-void ftx1_invalidate_clar_state(struct newcat_priv_data *priv, char vfo_param)
-{
- if (vfo_param < '0' || vfo_param > '1')
- {
- return;
- }
-
- ftx1_get_clar_cache(priv, vfo_param)->valid = false;
-}
-
int ftx1_parse_clar_state(const char *resp, char vfo,
char *rx_enabled, char *tx_enabled)
{
@@ -160,9 +130,6 @@ int ftx1_get_rx_clar(RIG *rig, vfo_t vfo, shortfreq_t *offset)
return -RIG_EPROTO;
}
- /* Cache both RX and TX CLAR states for use by set functions */
- ftx1_cache_clar_state(priv, vfo_param, rx_clar_enabled, tx_clar_enabled);
-
rig_debug(RIG_DEBUG_TRACE, "%s: CF setting response='%s', rx_clar_enabled=%c\n",
__func__, priv->ret_data, rx_clar_enabled);
@@ -207,8 +174,8 @@ int ftx1_set_rx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
struct newcat_priv_data *priv = (struct newcat_priv_data *)STATE(rig)->priv;
int err;
char vfo_param;
+ char rx_clar_enabled;
char tx_clar_enabled;
- struct ftx1_clarifier_cache *cache;
rig_debug(RIG_DEBUG_VERBOSE, "%s called with offset=%ld\n", __func__,
(long)offset);
@@ -222,35 +189,25 @@ int ftx1_set_rx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
}
vfo_param = ftx1_get_cf_vfo_param(rig, vfo);
- cache = ftx1_get_clar_cache(priv, vfo_param);
+ /*
+ * CF P3=0 sets the RX and TX CLAR flags in one write, so read this side's
+ * current flags right before writing to preserve the TX one. Don't
+ * cache them: the front panel or another CAT client can change them at
+ * any time, and a cached copy would silently undo that change.
+ */
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c00;", vfo_param);
- /* Preserve the TX CLAR state cached for this VFO. */
- if (cache->valid)
+ if (RIG_OK != (err = newcat_get_cmd(rig)))
{
- tx_clar_enabled = cache->tx_on;
+ return err;
}
- else
- {
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c00;", vfo_param);
-
- if (RIG_OK != (err = newcat_get_cmd(rig)))
- {
- return err;
- }
-
- char rx_clar_enabled;
- if (ftx1_parse_clar_state(priv->ret_data, vfo_param,
- &rx_clar_enabled, &tx_clar_enabled) != RIG_OK)
- {
- rig_debug(RIG_DEBUG_ERR, "%s: invalid CF setting response '%s'\n",
- __func__, priv->ret_data);
- return -RIG_EPROTO;
- }
-
- ftx1_cache_clar_state(priv, vfo_param, rx_clar_enabled,
- tx_clar_enabled);
- tx_clar_enabled = cache->tx_on;
+ if (ftx1_parse_clar_state(priv->ret_data, vfo_param,
+ &rx_clar_enabled, &tx_clar_enabled) != RIG_OK)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: invalid CF setting response '%s'\n",
+ __func__, priv->ret_data);
+ return -RIG_EPROTO;
}
if (offset == 0)
@@ -269,12 +226,9 @@ int ftx1_set_rx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
if (RIG_OK != (err = newcat_set_cmd(rig)))
{
- ftx1_invalidate_clar_state(priv, vfo_param);
return err;
}
- cache->rx_on = '1';
-
/* Now set the frequency */
if (offset > 0)
{
@@ -292,15 +246,9 @@ int ftx1_set_rx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
if (RIG_OK != (err = newcat_set_cmd(rig)))
{
- ftx1_invalidate_clar_state(priv, vfo_param);
return err;
}
- if (offset == 0)
- {
- cache->rx_on = '0';
- }
-
return RIG_OK;
}
@@ -344,9 +292,6 @@ int ftx1_get_tx_clar(RIG *rig, vfo_t vfo, shortfreq_t *offset)
return -RIG_EPROTO;
}
- /* Cache both RX and TX CLAR states for use by set functions */
- ftx1_cache_clar_state(priv, vfo_param, rx_clar_enabled, tx_clar_enabled);
-
rig_debug(RIG_DEBUG_TRACE, "%s: CF setting response='%s', tx_clar_enabled=%c\n",
__func__, priv->ret_data, tx_clar_enabled);
@@ -392,7 +337,7 @@ int ftx1_set_tx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
int err;
char vfo_param;
char rx_clar_enabled;
- struct ftx1_clarifier_cache *cache;
+ char tx_clar_enabled;
rig_debug(RIG_DEBUG_VERBOSE, "%s called with offset=%ld\n", __func__,
(long)offset);
@@ -406,35 +351,25 @@ int ftx1_set_tx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
}
vfo_param = ftx1_get_cf_vfo_param(rig, vfo);
- cache = ftx1_get_clar_cache(priv, vfo_param);
+ /*
+ * CF P3=0 sets the RX and TX CLAR flags in one write, so read this side's
+ * current flags right before writing to preserve the RX one. Don't
+ * cache them: the front panel or another CAT client can change them at
+ * any time, and a cached copy would silently undo that change.
+ */
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c00;", vfo_param);
- /* Preserve the RX CLAR state cached for this VFO. */
- if (cache->valid)
+ if (RIG_OK != (err = newcat_get_cmd(rig)))
{
- rx_clar_enabled = cache->rx_on;
+ return err;
}
- else
- {
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c00;", vfo_param);
-
- if (RIG_OK != (err = newcat_get_cmd(rig)))
- {
- return err;
- }
-
- char tx_clar_enabled;
- if (ftx1_parse_clar_state(priv->ret_data, vfo_param,
- &rx_clar_enabled, &tx_clar_enabled) != RIG_OK)
- {
- rig_debug(RIG_DEBUG_ERR, "%s: invalid CF setting response '%s'\n",
- __func__, priv->ret_data);
- return -RIG_EPROTO;
- }
-
- ftx1_cache_clar_state(priv, vfo_param, rx_clar_enabled,
- tx_clar_enabled);
- rx_clar_enabled = cache->rx_on;
+ if (ftx1_parse_clar_state(priv->ret_data, vfo_param,
+ &rx_clar_enabled, &tx_clar_enabled) != RIG_OK)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: invalid CF setting response '%s'\n",
+ __func__, priv->ret_data);
+ return -RIG_EPROTO;
}
if (offset == 0)
@@ -453,12 +388,9 @@ int ftx1_set_tx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
if (RIG_OK != (err = newcat_set_cmd(rig)))
{
- ftx1_invalidate_clar_state(priv, vfo_param);
return err;
}
- cache->tx_on = '1';
-
/* Now set the frequency */
if (offset > 0)
{
@@ -476,14 +408,8 @@ int ftx1_set_tx_clar(RIG *rig, vfo_t vfo, shortfreq_t offset)
if (RIG_OK != (err = newcat_set_cmd(rig)))
{
- ftx1_invalidate_clar_state(priv, vfo_param);
return err;
}
- if (offset == 0)
- {
- cache->tx_on = '0';
- }
-
return RIG_OK;
}
diff --git a/rigs/yaesu/ftx1/ftx1_mem.c b/rigs/yaesu/ftx1/ftx1_mem.c
index 28895dfcf..857ed0616 100644
--- a/rigs/yaesu/ftx1/ftx1_mem.c
+++ b/rigs/yaesu/ftx1/ftx1_mem.c
@@ -364,17 +364,14 @@ int ftx1_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str),
"CF100%d0000;", (chan->rit != 0) ? 1 : 0);
(void)newcat_set_cmd(rig);
- ftx1_invalidate_clar_state(priv, '1');
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str),
"CF100%d0000;", (chan->xit != 0) ? 3 : 2);
(void)newcat_set_cmd(rig);
- ftx1_invalidate_clar_state(priv, '1');
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str),
"CF101%c%04d;", dir, off);
(void)newcat_set_cmd(rig);
- ftx1_invalidate_clar_state(priv, '1');
}
else
{
@@ -382,10 +379,8 @@ int ftx1_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan)
* from a previous write or the operator's prior VFO-B. */
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF10000000;");
(void)newcat_set_cmd(rig);
- ftx1_invalidate_clar_state(priv, '1');
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF10020000;");
(void)newcat_set_cmd(rig);
- ftx1_invalidate_clar_state(priv, '1');
}
/* 4. Commit VFO-B to the last-selected memory channel. */
@@ -401,10 +396,8 @@ restore:
* side-effect cleanup. */
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF10000000;");
(void)newcat_set_cmd(rig);
- ftx1_invalidate_clar_state(priv, '1');
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF10020000;");
(void)newcat_set_cmd(rig);
- ftx1_invalidate_clar_state(priv, '1');
if (is_fm_family)
{
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CT10;");
diff --git a/rigs/yaesu/newcat.h b/rigs/yaesu/newcat.h
index a69264d5b..2785f2a51 100644
--- a/rigs/yaesu/newcat.h
+++ b/rigs/yaesu/newcat.h
@@ -125,16 +125,6 @@ struct newcat_priv_caps
const struct newcat_width_info *rtty_widths; // If NULL, use CW widths
};
-#define FTX1_CLARIFIER_VFO_COUNT 2
-
-/* FTX-1 CF P1 selects independent Main (0) and Sub (1) state. */
-struct ftx1_clarifier_cache
-{
- bool valid;
- char rx_on;
- char tx_on;
-};
-
/*
* Private state for newcat rigs
*/
@@ -162,14 +152,9 @@ struct newcat_priv_data
vfo_t ftx1_tx_vfo; /* TX VFO for virtual split */
int ftx1_cache_fix_needed; /* 1 if Main cache needs restoration */
freq_t ftx1_cache_fix_freq; /* Saved Main freq for cache restoration */
- struct ftx1_clarifier_cache ftx1_clar_cache[FTX1_CLARIFIER_VFO_COUNT];
int ftx1_in_memory_mode; /* 1 if driver knows the Main-side is in Memory mode (VM011) */
};
-void ftx1_cache_clar_state(struct newcat_priv_data *priv, char vfo_param,
- char rx_enabled, char tx_enabled);
-void ftx1_invalidate_clar_state(struct newcat_priv_data *priv, char vfo_param);
-
/*
* Functions considered to be Stable:
*
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4e7f06dff..70e2fbae9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -148,8 +148,7 @@ testid5100_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testicomfallback_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testg90rit_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testgeministatus_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/amplifiers/gemini
-testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu \
- -I$(top_srcdir)/rigs/yaesu/ftx1
+testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu/ftx1
testft991idmeter_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu
testguohetec_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/guohetec
if TESTS_HAVE_LIBUSB
diff --git a/tests/testftx1parsers.c b/tests/testftx1parsers.c
index 6a4f7010d..68d3826c6 100644
--- a/tests/testftx1parsers.c
+++ b/tests/testftx1parsers.c
@@ -13,36 +13,6 @@
#include <string.h>
#include "ftx1.h"
-#include "newcat.h"
-
-static int expect_clar_cache_isolated(void)
-{
- struct newcat_priv_data priv = { 0 };
-
- ftx1_cache_clar_state(&priv, '0', '1', '0');
- ftx1_cache_clar_state(&priv, '1', '0', '1');
-
- if (!priv.ftx1_clar_cache[0].valid
- || priv.ftx1_clar_cache[0].rx_on != '1'
- || priv.ftx1_clar_cache[0].tx_on != '0'
- || !priv.ftx1_clar_cache[1].valid
- || priv.ftx1_clar_cache[1].rx_on != '0'
- || priv.ftx1_clar_cache[1].tx_on != '1')
- {
- fprintf(stderr, "CF cache state was not isolated by VFO\n");
- return 1;
- }
-
- ftx1_invalidate_clar_state(&priv, '1');
-
- if (!priv.ftx1_clar_cache[0].valid || priv.ftx1_clar_cache[1].valid)
- {
- fprintf(stderr, "CF cache invalidation affected the wrong VFO\n");
- return 1;
- }
-
- return 0;
-}
static int expect_clar_state(const char *response, char vfo, int expected,
char expected_rx, char expected_tx)
@@ -210,8 +180,7 @@ int main(void)
"ML0002;", "ML2000;", "ML0000"
};
- if (expect_clar_cache_isolated() != 0
- || expect_clar_state("CF00000000;", '0', RIG_OK, '0', '0') != 0
+ if (expect_clar_state("CF00000000;", '0', RIG_OK, '0', '0') != 0
|| expect_clar_state("CF00010000;", '0', RIG_OK, '1', '0') != 0
|| expect_clar_state("CF10010000;", '1', RIG_OK, '1', '0') != 0
|| expect_clar_offset("CF001+1234;", '0', RIG_OK, 1234) != 0
commit dcd90133f1d78f226160658db46f59d9837e43be
Author: KJ5HST <kj...@de...>
Date: Sun Oct 18 14:50:36 2026 -0400
ftx1: send SH width to the targeted receiver, not always MAIN
newcat_set_rx_bandwidth() grouped the FTX-1 with the single-receiver
FTDX10 and FT-710 and always sent "SH00xx;". When set_mode or
set_rx_bandwidth targeted SUB, the width went to MAIN instead: MAIN's
filter was overwritten and SUB's was never set.
Send SH P1 0 xx with P1 = 1 for SUB/VFO-B, matching the read side.
Fixes #2241
diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c
index 2fd0801d9..9581c2ea4 100644
--- a/rigs/yaesu/newcat.c
+++ b/rigs/yaesu/newcat.c
@@ -9276,7 +9276,13 @@ int newcat_set_rx_bandwidth(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
{
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "SH0%02d;", w);
}
- else if (is_ftdx10 || is_ft710 || is_ftx1)
+ else if (is_ftx1)
+ {
+ /* SH P1 P2 P3P3; P1 0=MAIN 1=SUB (the FTX-1 has two receivers), P2 0 */
+ char p1 = (RIG_VFO_SUB == vfo || RIG_VFO_B == vfo) ? '1' : '0';
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "SH%c0%02d;", p1, w);
+ }
+ else if (is_ftdx10 || is_ft710)
{
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "SH00%02d;", w);
}
commit a96343d6cd626bcea3626fa3a031ecb6d2729eb5
Author: KJ5HST <kj...@de...>
Date: Sun Oct 18 15:16:06 2026 -0400
newcat: parse the FTX-1's 30-byte IF reply with the right layout
The 30-byte IF case was added for the FTX-1, whose IF answer has a
5-digit P1 and a 9-digit P2 (IF P1x5 P2x9 P3x5 P4 P5 P6 P7 P8 P9x2 P10;).
It was treated as an 8-digit frequency with P7 at offset 21 and the
clarifier at offset 14, so with an FTX-1 on a generic newcat backend
(e.g. FTDX10/FT-710 models) FA/FB were sent with 8 digits and rejected,
the VFO/memory mode was read from the RX CLAR flag, and RIT/XIT were
read from the wrong field.
Use offset 24 for P7, 16 for P3, and a 9-digit frequency width. The
native FTX-1 backend (model 1051) does not use these paths.
Fixes #2219
diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c
index c0303edcd..2fd0801d9 100644
--- a/rigs/yaesu/newcat.c
+++ b/rigs/yaesu/newcat.c
@@ -3051,7 +3051,7 @@ int newcat_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit)
case 41: // FT-991 V2-01 seems to randomly give 13 extra bytes
case 28: offset = 14; break;
- case 30: offset = 14; break;
+ case 30: offset = 16; break; // FTX-1: 5-digit P1, P3 at 16
default: offset = 0;
}
@@ -3167,7 +3167,7 @@ int newcat_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit)
{
case 27: offset = 13; break;
- case 30: offset = 14; break;
+ case 30: offset = 16; break; // FTX-1: 5-digit P1, P3 at 16
case 41: // FT-991 V2-01 seems to randomly give 13 extra bytes
case 28: offset = 14; break;
@@ -10246,7 +10246,7 @@ int newcat_get_vfo_mode(RIG *rig, vfo_t vfo, vfo_t *vfo_mode)
{
case 27: offset = 21; priv->width_frequency = 8; break;
- case 30: offset = 21; priv->width_frequency = 8; break;
+ case 30: offset = 24; priv->width_frequency = 9; break; // FTX-1: 5-digit P1, 9-digit P2
case 41: // FT-991 V2-01 seems to randomly give 13 extra bytes
case 28: offset = 22; priv->width_frequency = 9; break;
commit 2870074d373732c749bbee0a9de52f0e9575e85e
Author: David Christle <dch...@us...>
Date: Fri Jul 31 17:57:48 2026 -0500
fix(daemons): cap concurrent client threads
Each accepted connection created a detached worker without an
application-level admission limit. Bound active workers with a configurable
32-client default and roll back reservations on failure.
Reject excess connections without disrupting admitted clients, document the
saturation behavior, and cover parsing, accounting, and daemon-level recovery.
diff --git a/doc/man1/ampctld.1 b/doc/man1/ampctld.1
index e3abdd350..adc325e1f 100644
--- a/doc/man1/ampctld.1
+++ b/doc/man1/ampctld.1
@@ -22,6 +22,7 @@ ampctld \- TCP amplifier control daemon
.OP \-s baud
.OP \-T IPADDR
.OP \-t number
+.OP \-N number
.OP \-C parm=val
.RB [ \-v [ \-Z ]]
.YS
@@ -157,6 +158,14 @@ for multiple
instances, e.g. 4529, 4527, 4525, etc.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fInumber\fP
+Limit the number of concurrent TCP clients to
+.IR number .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.TP
.BR \-T ", " \-\-listen\-addr = \fIIPADDR\fP
Use
.I IPADDR
diff --git a/doc/man1/rigctld.1 b/doc/man1/rigctld.1
index a3454897d..5ddeb291e 100644
--- a/doc/man1/rigctld.1
+++ b/doc/man1/rigctld.1
@@ -28,6 +28,7 @@ rigctld \- TCP radio control daemon
.OP \-S char
.OP \-T IPADDR
.OP \-t number
+.OP \-N number
.OP \-C parm=val
.OP \-X seconds
.RB [ \-v [ \-Z ]]
@@ -291,6 +292,14 @@ default port is 4533, it is advisable to use even numbered ports for
e.g. 4532, 4534, 4536, etc.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fInumber\fP
+Limit the number of concurrent TCP clients to
+.IR number .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.TP
.BR \-L ", " \-\-show\-conf
List all config parameters for the radio defined with
.B \-m
diff --git a/doc/man1/rigctltcp.1 b/doc/man1/rigctltcp.1
index b95bbcf8c..d8f5e24f3 100644
--- a/doc/man1/rigctltcp.1
+++ b/doc/man1/rigctltcp.1
@@ -29,6 +29,7 @@ rigctltcp \- TCP multicast control of radio transceivers and receivers
.OP \-C parm=val
.OP \-T ipaddr
.OP \-t num
+.OP \-N num
.OP \-M addr
.OP \-n port
.OP \-W secs
@@ -398,6 +399,15 @@ The default is 4531.
.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fINUM\fP
+Limit the number of concurrent TCP clients to
+.IR NUM .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.
+.TP
.BR \-M ", " \-\-multicast\-addr = \fIADDR\fP
Use
.I ADDR
diff --git a/doc/man1/rotctld.1 b/doc/man1/rotctld.1
index 35e336f8c..a05ff9a20 100644
--- a/doc/man1/rotctld.1
+++ b/doc/man1/rotctld.1
@@ -22,6 +22,7 @@ rotctld \- TCP rotator control daemon
.OP \-s baud
.OP \-T IPADDR
.OP \-t number
+.OP \-N number
.OP \-C parm=val
.RB [ \-v [ \-Z ]]
.YS
@@ -177,6 +178,14 @@ default port is 4533, it is advisable to use odd numbered ports for
e.g. 4533, 4535, 4537, etc.
.
.TP
+.BR \-N ", " \-\-max\-clients = \fInumber\fP
+Limit the number of concurrent TCP clients to
+.IR number .
+.IP
+The value must be a positive integer. The default is 32. Connections accepted
+while the limit is reached are closed immediately.
+.
+.TP
.BR \-L ", " \-\-show\-conf
List all configuration parameters for the rotator defined with
.B \-m
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b5ba02f8c..620ded0b6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -23,6 +23,8 @@ DIRECT_TESTS = \
testcachethread \
testcachevfo \
testctlparser \
+ testdaemonclient \
+ testdaemonclients \
testdebug \
testdummyparm \
testft991idmeter \
@@ -88,16 +90,17 @@ noinst_PROGRAMS = rigstreamtest
RIGCOMMONSRC = rigctl_parse.c rigctl_parse.h rigctld_stream.c rigctld_stream.h rigctld_client.h dumpcaps.c dumpstate.c uthash.h rig_tests.c rig_tests.h dumpcaps.h
ROTCOMMONSRC = rotctl_parse.c rotctl_parse.h dumpcaps_rot.c uthash.h dumpcaps_rot.h
AMPCOMMONSRC = ampctl_parse.c ampctl_parse.h dumpcaps_amp.c uthash.h
+DAEMONCLIENTSRC = daemon_client.c daemon_client.h
rigctl_SOURCES = rigctl.c $(RIGCOMMONSRC)
-rigctld_SOURCES = rigctld.c $(RIGCOMMONSRC)
+rigctld_SOURCES = rigctld.c $(RIGCOMMONSRC) $(DAEMONCLIENTSRC)
rigctlcom_SOURCES = rigctlcom.c $(RIGCOMMONSRC)
-rigctltcp_SOURCES = rigctltcp.c $(RIGCOMMONSRC)
+rigctltcp_SOURCES = rigctltcp.c $(RIGCOMMONSRC) $(DAEMONCLIENTSRC)
rigctlsync_SOURCES = rigctlsync.c $(RIGCOMMONSRC)
rotctl_SOURCES = rotctl.c $(ROTCOMMONSRC)
-rotctld_SOURCES = rotctld.c $(ROTCOMMONSRC)
+rotctld_SOURCES = rotctld.c $(ROTCOMMONSRC) $(DAEMONCLIENTSRC)
ampctl_SOURCES = ampctl.c $(AMPCOMMONSRC)
-ampctld_SOURCES = ampctld.c $(AMPCOMMONSRC)
+ampctld_SOURCES = ampctld.c $(AMPCOMMONSRC) $(DAEMONCLIENTSRC)
rigmem_SOURCES = rigmem.c memsave.c memload.c memcsv.c
rigstreamtest_SOURCES = rigstreamtest.c rigstreamtest_util.c rigstreamtest_util.h
if TESTS_HAVE_LIBUSB
@@ -129,6 +132,7 @@ testcachemode_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testcacherouting_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testcachethread_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testcachevfo_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testdaemonclient_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testctlparser_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgeministatus_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testg90rit_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
@@ -167,6 +171,8 @@ rigctlcom_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(LDADD) $(READLINE_LIBS)
rigctltcp_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(LDADD) $(READLINE_LIBS)
rigctlsync_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(LDADD) $(READLINE_LIBS)
testdebug_LDADD = $(PTHREAD_LIBS) $(LDADD)
+testdaemonclient_SOURCES = testdaemonclient.c $(DAEMONCLIENTSRC)
+testdaemonclient_LDADD = $(PTHREAD_LIBS) $(LDADD)
rigstreamtest_LDADD = $(PTHREAD_LIBS) $(LDADD)
rigstreamtest_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
rigstreamtest_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src \
diff --git a/tests/ampctld.c b/tests/ampctld.c
index a4a681185..04e171982 100644
--- a/tests/ampctld.c
+++ b/tests/ampctld.c
@@ -59,6 +59,7 @@
#include "hamlib/amplifier.h"
#include "hamlib/port.h"
+#include "daemon_client.h"
#include "ampctl_parse.h"
#include "amplist.h"
#include "rig.h"
@@ -86,7 +87,7 @@ static void short_usage(FILE *fout);
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
-#define SHORT_OPTIONS "m:r:s:C:t:T:LuvhVlZ"
+#define SHORT_OPTIONS "m:r:s:C:t:T:N:LuvhVlZ"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@@ -94,6 +95,7 @@ static struct option long_options[] =
{"serial-speed", 1, 0, 's'},
{"port", 1, 0, 't'},
{"listen-addr", 1, 0, 'T'},
+ {"max-clients", 1, 0, 'N'},
{"list", 0, 0, 'l'},
{"set-conf", 1, 0, 'C'},
{"show-conf", 0, 0, 'L'},
@@ -110,6 +112,8 @@ int prompt = 0 ; /* Daemon mode for rigparse return string */
const char *portno = "4531";
const char *src_addr = NULL; /* INADDR_ANY */
+static struct daemon_client_tracker client_tracker =
+ DAEMON_CLIENT_TRACKER_INITIALIZER;
char send_cmd_term = '\r'; /* send_cmd termination char */
@@ -246,6 +250,15 @@ int main(int argc, char *argv[])
src_addr = optarg;
break;
+ case 'N':
+ if (daemon_client_limit_parse(optarg, &client_tracker.limit) != 0)
+ {
+ fprintf(stderr, "Invalid maximum client count: %s\n", optarg);
+ exit(1);
+ }
+
+ break;
+
case 'v':
verbose++;
rig_set_debug(verbose);
@@ -515,33 +528,77 @@ int main(int argc, char *argv[])
#endif
#endif
+ retcode = pthread_attr_init(&attr);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n", strerror(retcode));
+ exit(1);
+ }
+
+ retcode = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
+ strerror(retcode));
+ pthread_attr_destroy(&attr);
+ exit(1);
+ }
+
/*
* main loop accepting connections
*/
- do
+ while (1)
{
+ struct sockaddr_storage cli_addr;
+ socklen_t clilen = sizeof(cli_addr);
+ int client_sock;
+
+ client_sock = accept(sock_listen,
+ (struct sockaddr *)&cli_addr,
+ &clilen);
+
+ if (client_sock < 0)
+ {
+ handle_error(RIG_DEBUG_ERR, "accept");
+ break;
+ }
+
+ if (!daemon_client_tracker_acquire(&client_tracker))
+ {
+ rig_debug(RIG_DEBUG_WARN,
+ "Client limit of %u reached; closing connection\n",
+ client_tracker.limit);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ continue;
+ }
+
arg = calloc(1, sizeof(struct handle_data));
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "calloc: %s\n", strerror(errno));
- exit(1);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
arg->amp = my_amp;
- arg->clilen = sizeof(arg->cli_addr);
- arg->sock = accept(sock_listen,
- (struct sockaddr *) &arg->cli_addr,
- &arg->clilen);
+ arg->sock = client_sock;
+ arg->cli_addr = cli_addr;
+ arg->clilen = clilen;
- if (arg->sock < 0)
- {
- handle_error(RIG_DEBUG_ERR, "accept");
- break;
- }
-
- if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
- arg->clilen,
+ if ((retcode = getnameinfo((struct sockaddr const *)&cli_addr,
+ clilen,
host,
sizeof(host),
serv,
@@ -560,20 +617,23 @@ int main(int argc, char *argv[])
host,
serv);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
retcode = pthread_create(&thread, &attr, handle_socket, arg);
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
- break;
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ free(arg);
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
-
}
- while (retcode == 0);
+ pthread_attr_destroy(&attr);
amp_close(my_amp); /* close port */
amp_cleanup(my_amp); /* if you care about memory */
@@ -673,6 +733,7 @@ handle_exit:
#else
close(handle_data_arg->sock);
#endif
+ daemon_client_tracker_release(&client_tracker);
free(arg);
pthread_exit(NULL);
@@ -690,6 +751,7 @@ static void usage(FILE *fout)
" -r, --amp-file=DEVICE set device of the amplifier to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --port=NUM set TCP listening port, default %s\n"
+ " -N, --max-clients=NUM set maximum concurrent clients, default %u\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL[,...] set config parameters\n"
" -L, --show-conf list all config parameters\n"
@@ -699,7 +761,8 @@ static void usage(FILE *fout)
" -Z, --debug-time-stamps enable time stamps for debug messages\n"
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
- portno);
+ portno,
+ DAEMON_DEFAULT_MAX_CLIENTS);
usage_amp(fout);
}
diff --git a/tests/daemon_client.c b/tests/daemon_client.c
new file mode 100644
index 000000000..3d7a099ae
--- /dev/null
+++ b/tests/daemon_client.c
@@ -0,0 +1,84 @@
+#include "hamlib/config.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "daemon_client.h"
+
+int daemon_client_limit_parse(const char *value, unsigned *limit)
+{
+ char *end;
+ unsigned long parsed;
+ const char *p;
+
+ if (!value || !value[0] || !limit)
+ {
+ return -1;
+ }
+
+ for (p = value; *p; ++p)
+ {
+ if (*p < '0' || *p > '9')
+ {
+ return -1;
+ }
+ }
+
+ errno = 0;
+ parsed = strtoul(value, &end, 10);
+
+ if (errno == ERANGE || *end || parsed == 0 || parsed > UINT_MAX)
+ {
+ return -1;
+ }
+
+ *limit = (unsigned)parsed;
+ return 0;
+}
+
+int daemon_client_tracker_init(struct daemon_client_tracker *tracker,
+ unsigned limit)
+{
+ if (!tracker || limit == 0)
+ {
+ return EINVAL;
+ }
+
+ tracker->active = 0;
+ tracker->limit = limit;
+ return pthread_mutex_init(&tracker->mutex, NULL);
+}
+
+void daemon_client_tracker_destroy(struct daemon_client_tracker *tracker)
+{
+ pthread_mutex_destroy(&tracker->mutex);
+}
+
+int daemon_client_tracker_acquire(struct daemon_client_tracker *tracker)
+{
+ int acquired = 0;
+
+ pthread_mutex_lock(&tracker->mutex);
+
+ if (tracker->active < tracker->limit)
+ {
+ ++tracker->active;
+ acquired = 1;
+ }
+
+ pthread_mutex_unlock(&tracker->mutex);
+ return acquired;
+}
+
+void daemon_client_tracker_release(struct daemon_client_tracker *tracker)
+{
+ pthread_mutex_lock(&tracker->mutex);
+
+ if (tracker->active > 0)
+ {
+ --tracker->active;
+ }
+
+ pthread_mutex_unlock(&tracker->mutex);
+}
diff --git a/tests/daemon_client.h b/tests/daemon_client.h
new file mode 100644
index 000000000..babdee6af
--- /dev/null
+++ b/tests/daemon_client.h
@@ -0,0 +1,24 @@
+#ifndef HAMLIB_TESTS_DAEMON_CLIENT_H
+#define HAMLIB_TESTS_DAEMON_CLIENT_H 1
+
+#include <pthread.h>
+
+#define DAEMON_DEFAULT_MAX_CLIENTS 32U
+#define DAEMON_CLIENT_TRACKER_INITIALIZER \
+ { PTHREAD_MUTEX_INITIALIZER, 0U, DAEMON_DEFAULT_MAX_CLIENTS }
+
+struct daemon_client_tracker
+{
+ pthread_mutex_t mutex;
+ unsigned active;
+ unsigned limit;
+};
+
+int daemon_client_limit_parse(const char *value, unsigned *limit);
+int daemon_client_tracker_init(struct daemon_client_tracker *tracker,
+ unsigned limit);
+void daemon_client_tracker_destroy(struct daemon_client_tracker *tracker);
+int daemon_client_tracker_acquire(struct daemon_client_tracker *tracker);
+void daemon_client_tracker_release(struct daemon_client_tracker *tracker);
+
+#endif
diff --git a/tests/rigctld.c b/tests/rigctld.c
index 87b5d2d92..9c088d6fd 100644
--- a/tests/rigctld.c
+++ b/tests/rigctld.c
@@ -76,6 +76,7 @@
#include "rigctl_parse.h"
#include "rigctld_stream.h"
#include "rigctld_client.h"
+#include "daemon_client.h"
#include "riglist.h"
#include "token.h"
@@ -84,7 +85,7 @@
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
* TODO: add an option to read from a file
*/
-#define SHORT_OPTIONS "m:r:p:d:P:D:s:S:c:T:t:C:W:w:x:lLuovhVZRA:bM:G:"
+#define SHORT_OPTIONS "m:r:p:d:P:D:s:S:c:T:t:N:C:W:w:x:lLuovhVZRA:bM:G:"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@@ -98,6 +99,7 @@ static struct option long_options[] =
{"civaddr", 1, 0, 'c'},
{"listen-addr", 1, 0, 'T'},
{"port", 1, 0, 't'},
+ {"max-clients", 1, 0, 'N'},
{"set-conf", 1, 0, 'C'},
{"list", 0, 0, 'l'},
{"show-conf", 0, 0, 'L'},
@@ -138,6 +140,8 @@ static void short_usage(FILE *fout);
static unsigned client_count;
static HAMLIB_ATOMIC int next_client_id =
1; /* Monotonically increasing client ID */
+static struct daemon_client_tracker client_tracker =
+ DAEMON_CLIENT_TRACKER_INITIALIZER;
static RIG *my_rig; /* handle to rig (instance) */
static volatile int rig_opened = 0;
@@ -300,6 +304,7 @@ int main(int argc, char *argv[])
#endif
pthread_t thread;
+ pthread_attr_t attr;
int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */
int i;
extern int is_rigctld;
@@ -622,6 +627,15 @@ int main(int argc, char *argv[])
src_addr = optarg;
break;
+ case 'N':
+ if (daemon_client_limit_parse(optarg, &client_tracker.limit) != 0)
+ {
+ fprintf(stderr, "Invalid maximum client count: %s\n", optarg);
+ exit(1);
+ }
+
+ break;
+
case 'o':
vfo_mode++;
//rig_debug(RIG_DEBUG_ERR, "%s: #0 vfo_mode=%d\n", __func__, vfo_mode);
@@ -692,8 +706,8 @@ int main(int argc, char *argv[])
rig_debug(RIG_DEBUG_VERBOSE, "rigctld %s\n", hamlib_version2);
rig_debug(RIG_DEBUG_VERBOSE, "%s",
"Report bugs to <ham...@li...>\n\n");
- rig_debug(RIG_DEBUG_VERBOSE, "Max# of rigctld client services=%d\n",
- NI_MAXSERV);
+ rig_debug(RIG_DEBUG_VERBOSE, "Max# of rigctld client services=%u\n",
+ client_tracker.limit);
my_rig = rig_init(my_model);
@@ -1153,6 +1167,24 @@ int main(int argc, char *argv[])
rigctl_parse_init();
+ retcode = pthread_attr_init(&attr);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n", strerror(retcode));
+ exit(1);
+ }
+
+ retcode = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
+ strerror(retcode));
+ pthread_attr_destroy(&attr);
+ exit(1);
+ }
+
/*
* main loop accepting connections
*/
@@ -1201,35 +1233,57 @@ int main(int argc, char *argv[])
else
{
struct handle_data *arg;
- pthread_attr_t attr;
- int attr_ret;
+ struct sockaddr_storage cli_addr;
+ socklen_t clilen = sizeof(cli_addr);
+ int client_sock;
+
+ client_sock = accept(sock_listen,
+ (struct sockaddr *)&cli_addr,
+ &clilen);
+
+ if (client_sock < 0)
+ {
+ handle_error(RIG_DEBUG_ERR, "accept");
+ break;
+ }
+
+ if (!daemon_client_tracker_acquire(&client_tracker))
+ {
+ rig_debug(RIG_DEBUG_WARN,
+ "Client limit of %u reached; closing connection\n",
+ client_tracker.limit);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ continue;
+ }
arg = calloc(1, sizeof(struct handle_data));
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "calloc: %s\n", strerror(errno));
- exit(1);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
if (rigctld_password[0] != 0) { arg->use_password = 1; }
arg->rig = my_rig;
- arg->clilen = sizeof(arg->cli_addr);
+ arg->sock = client_sock;
+ arg->cli_addr = cli_addr;
+ arg->clilen = clilen;
arg->vfo_mode = vfo_mode;
- arg->sock = accept(sock_listen,
- (struct sockaddr *)&arg->cli_addr,
- &arg->clilen);
- if (arg->sock < 0)
- {
- handle_error(RIG_DEBUG_ERR, "accept");
- free(arg);
- break;
- }
-
- if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
- arg->clilen,
+ if ((retcode = getnameinfo((struct sockaddr const *)&cli_addr,
+ clilen,
host,
sizeof(host),
serv,
@@ -1242,69 +1296,25 @@ int main(int argc, char *argv[])
gai_strerror(retcode));
}
- if (client_count >= RIGCTLD_MAX_CLIENTS)
- {
- rig_debug(RIG_DEBUG_ERR,
- "Connection from %s:%s rejected — "
- "max clients (%d) reached\n",
- host, serv, RIGCTLD_MAX_CLIENTS);
- socket_close(arg->sock);
- free(arg);
- continue;
- }
-
arg->client_id = next_client_id++;
rig_debug(RIG_DEBUG_VERBOSE,
"Connection opened from %s:%s (client %d)\n",
host, serv, arg->client_id);
- attr_ret = pthread_attr_init(&attr);
-
- if (attr_ret != 0)
- {
- rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n",
- strerror(attr_ret));
- socket_close(arg->sock);
- free(arg);
- break;
- }
-
- attr_ret = pthread_attr_setdetachstate(&attr,
- PTHREAD_CREATE_DETACHED);
-
- if (attr_ret != 0)
- {
- rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
- strerror(attr_ret));
- int destroy_ret = pthread_attr_destroy(&attr);
-
- if (destroy_ret != 0)
- {
- rig_debug(RIG_DEBUG_WARN, "pthread_attr_destroy: %s\n",
- strerror(destroy_ret));
- }
-
- socket_close(arg->sock);
- free(arg);
- break;
- }
-
retcode = pthread_create(&thread, &attr, handle_socket, arg);
- attr_ret = pthread_attr_destroy(&attr);
-
- if (attr_ret != 0)
- {
- rig_debug(RIG_DEBUG_WARN, "pthread_attr_destroy: %s\n",
- strerror(attr_ret));
- }
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
- socket_close(arg->sock);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
free(arg);
- break;
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
}
@@ -1312,6 +1322,7 @@ int main(int argc, char *argv[])
while (!ctrl_c);
rig_debug(RIG_DEBUG_VERBOSE, "%s: while loop done\n", __func__);
+ pthread_attr_destroy(&attr);
/* allow threads to finish current action */
mutex_rigctld(1);
@@ -1606,6 +1617,7 @@ handle_exit:
pthread_setspecific(thread_data_key,
NULL); // Tell pthreads we're done with the data
+ daemon_client_tracker_release(&client_tracker);
free(arg);
pthread_exit(NULL);
@@ -1629,6 +1641,7 @@ static void usage(FILE *fout)
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
" -t, --port=NUM set TCP listening port, default %s\n"
+ " -N, --max-clients=NUM set maximum concurrent clients, default %u\n"
" -S, --separator=CHAR set char as rigctld response separator, default is \\n\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL[,...] set config parameters\n"
@@ -1665,6 +1678,7 @@ static void usage(FILE *fout)
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
portno,
+ DAEMON_DEFAULT_MAX_CLIENTS,
RIGCTLD_METADATA_INTERVAL_MIN,
RIGCTLD_METADATA_INTERVAL_MAX,
RIGCTLD_METADATA_INTERVAL_DEFAULT,
diff --git a/tests/rigctltcp.c b/tests/rigctltcp.c
index 215a64377..82604baf0 100644
--- a/tests/rigctltcp.c
+++ b/tests/rigctltcp.c
@@ -75,6 +75,7 @@
#include "hamlib/rig_state.h"
#include "misc.h"
#include "network.h"
+#include "daemon_client.h"
#include "riglist.h"
#include "rigctl_parse.h"
@@ -84,7 +85,7 @@
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
* TODO: add an option to read from a file
*/
-#define SHORT_OPTIONS "m:r:p:d:P:D:s:S:c:T:t:C:W:w:x:M:n:A:lLuovhVZR:"
+#define SHORT_OPTIONS "m:r:p:d:P:D:s:S:c:T:t:N:C:W:w:x:M:n:A:lLuovhVZR:"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@@ -98,6 +99,7 @@ static struct option long_options[] =
{"civaddr", 1, 0, 'c'},
{"listen-addr", 1, 0, 'T'},
{"port", 1, 0, 't'},
+ {"max-clients", 1, 0, 'N'},
{"set-conf", 1, 0, 'C'},
{"list", 0, 0, 'l'},
{"show-conf", 0, 0, 'L'},
@@ -124,6 +126,8 @@ void *handle_socket(void *arg);
static void usage(FILE *fout);
static unsigned client_count;
+static struct daemon_client_tracker client_tracker =
+ DAEMON_CLIENT_TRACKER_INITIALIZER;
static RIG *my_rig; /* handle to rig (instance) */
static volatile int rig_opened = 0;
@@ -459,6 +463,15 @@ int main(int argc, char *argv[])
src_addr = optarg;
break;
+ case 'N':
+ if (daemon_client_limit_parse(optarg, &client_tracker.limit) != 0)
+ {
+ fprintf(stderr, "Invalid maximum client count: %s\n", optarg);
+ exit(1);
+ }
+
+ break;
+
case 'o':
vfo_mode++;
//rig_debug(RIG_DEBUG_ERR, "%s: #0 vfo_mode=%d\n", __func__, vfo_mode);
@@ -543,8 +556,8 @@ int main(int argc, char *argv[])
rig_debug(RIG_DEBUG_VERBOSE, "rigctltcp %s\n", hamlib_version2);
rig_debug(RIG_DEBUG_VERBOSE, "%s",
"Report bugs to <ham...@li...>\n\n");
- rig_debug(RIG_DEBUG_VERBOSE, "Max# of rigctld client services=%d\n",
- NI_MAXSERV);
+ rig_debug(RIG_DEBUG_VERBOSE, "Max# of rigctltcp client services=%u\n",
+ client_tracker.limit);
my_rig = rig_init(my_model);
@@ -871,6 +884,24 @@ int main(int argc, char *argv[])
rigctl_parse_init();
+ retcode = pthread_attr_init(&attr);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n", strerror(retcode));
+ exit(1);
+ }
+
+ retcode = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
+ strerror(retcode));
+ pthread_attr_destroy(&attr);
+ exit(1);
+ }
+
/*
* main loop accepting connections
*/
@@ -919,33 +950,57 @@ int main(int argc, char *argv[])
else
{
struct handle_data *arg;
+ struct sockaddr_storage cli_addr;
+ socklen_t clilen = sizeof(cli_addr);
+ int client_sock;
+
+ client_sock = accept(sock_listen,
+ (struct sockaddr *)&cli_addr,
+ &clilen);
+
+ if (client_sock < 0)
+ {
+ handle_error(RIG_DEBUG_ERR, "accept");
+ break;
+ }
+
+ if (!daemon_client_tracker_acquire(&client_tracker))
+ {
+ rig_debug(RIG_DEBUG_WARN,
+ "Client limit of %u reached; closing connection\n",
+ client_tracker.limit);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ continue;
+ }
arg = calloc(1, sizeof(struct handle_data));
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "calloc: %s\n", strerror(errno));
- exit(1);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
if (rigctld_password[0] != 0) { arg->use_password = 1; }
arg->rig = my_rig;
- arg->clilen = sizeof(arg->cli_addr);
+ arg->sock = client_sock;
+ arg->cli_addr = cli_addr;
+ arg->clilen = clilen;
arg->vfo_mode = vfo_mode;
- arg->sock = accept(sock_listen,
- (struct sockaddr *)&arg->cli_addr,
- &arg->clilen);
-
- if (arg->sock < 0)
- {
- handle_error(RIG_DEBUG_ERR, "accept");
- free(arg);
- break;
- }
- if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
- arg->clilen,
+ if ((retcode = getnameinfo((struct sockaddr const *)&cli_addr,
+ clilen,
host,
sizeof(host),
serv,
@@ -963,15 +1018,19 @@ int main(int argc, char *argv[])
host,
serv);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
retcode = pthread_create(&thread, &attr, handle_socket, arg);
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
- break;
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ free(arg);
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
}
@@ -988,6 +1047,8 @@ int main(int argc, char *argv[])
rig_debug(RIG_DEBUG_WARN, "%u outstanding client(s)\n", client_count);
}
+ pthread_attr_destroy(&attr);
+
rig_close(my_rig);
mutex_rigctld(0);
@@ -1357,6 +1418,7 @@ handle_exit:
#endif
pthread_setspecific(thread_data_key, NULL);
+ daemon_client_tracker_release(&client_tracker);
free(arg);
pthread_exit(NULL);
@@ -1387,6 +1449,7 @@ static void usage(FILE *fout)
" -v, --verbose set verbose mode, cumulative (-v to -vvvvv)\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -t, --port=NUM set TCP listening port, default %s\n"
+ " -N, --max-clients=NUM set maximum concurrent clients, default %u\n"
" -M, --multicast-addr=ADDR set multicast UDP address, default %s (off), recommend 224.0.1.1\n"
" -n, --multicast-port=PORT set multicast UDP port, default %d\n"
" -W, --twiddle_timeout=SECONDS timeout after detecting vfo manual change\n"
@@ -1400,6 +1463,7 @@ static void usage(FILE *fout)
" -h, --help display this help and exit\n"
" -V, --version output version information and exit\n\n",
portno,
+ DAEMON_DEFAULT_MAX_CLIENTS,
multicast_addr,
multicast_port);
diff --git a/tests/rotctld.c b/tests/rotctld.c
index b0864b7c6..42c616b99 100644
--- a/tests/rotctld.c
+++ b/tests/rotctld.c
@@ -57,6 +57,7 @@
#include "hamlib/port.h"
#include "hamlib/rot_state.h"
+#include "daemon_client.h"
#include "rig.h"
#include "rotctl_parse.h"
#include "rotlist.h"
@@ -84,7 +85,7 @@ static void short_usage(FILE *fout);
* NB: do NOT use -W since it's reserved by POSIX.
* TODO: add an option to read from a file
*/
-#define SHORT_OPTIONS "m:r:R:s:C:o:O:t:T:LuvhVlZ"
+#define SHORT_OPTIONS "m:r:R:s:C:o:O:t:T:N:LuvhVlZ"
static struct option long_options[] =
{
{"model", 1, 0, 'm'},
@@ -93,6 +94,7 @@ static struct option long_options[] =
{"serial-speed", 1, 0, 's'},
{"port", 1, 0, 't'},
{"listen-addr", 1, 0, 'T'},
+ {"max-clients", 1, 0, 'N'},
{"list", 0, 0, 'l'},
{"set-conf", 1, 0, 'C'},
{"set-azoffset", 1, 0, 'o'},
@@ -108,6 +110,8 @@ static struct option long_options[] =
const char *portno = "4533";
const char *src_addr = NULL; /* INADDR_ANY */
+static struct daemon_client_tracker client_tracker =
+ DAEMON_CLIENT_TRACKER_INITIALIZER;
azimuth_t az_offset;
elevation_t el_offset;
@@ -244,6 +248,15 @@ int main(int argc, char *argv[])
src_addr = optarg;
break;
+ case 'N':
+ if (daemon_client_limit_parse(optarg, &client_tracker.limit) != 0)
+ {
+ fprintf(stderr, "Invalid maximum client count: %s\n", optarg);
+ exit(1);
+ }
+
+ break;
+
case 'o':
az_offset = atof(optarg);
break;
@@ -534,33 +547,77 @@ int main(int argc, char *argv[])
#endif
#endif
+ retcode = pthread_attr_init(&attr);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n", strerror(retcode));
+ exit(1);
+ }
+
+ retcode = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+
+ if (retcode != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
+ strerror(retcode));
+ pthread_attr_destroy(&attr);
+ exit(1);
+ }
+
/*
* main loop accepting connections
*/
- do
+ while (1)
{
+ struct sockaddr_storage cli_addr;
+ socklen_t clilen = sizeof(cli_addr);
+ int client_sock;
+
+ client_sock = accept(sock_listen,
+ (struct sockaddr *)&cli_addr,
+ &clilen);
+
+ if (client_sock < 0)
+ {
+ handle_error(RIG_DEBUG_ERR, "accept");
+ break;
+ }
+
+ if (!daemon_client_tracker_acquire(&client_tracker))
+ {
+ rig_debug(RIG_DEBUG_WARN,
+ "Client limit of %u reached; closing connection\n",
+ client_tracker.limit);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ continue;
+ }
+
arg = calloc(1, sizeof(struct handle_data));
if (!arg)
{
rig_debug(RIG_DEBUG_ERR, "calloc: %s\n", strerror(errno));
- exit(1);
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
arg->rot = my_rot;
- arg->clilen = sizeof(arg->cli_addr);
- arg->sock = accept(sock_listen,
- (struct sockaddr *) &arg->cli_addr,
- &arg->clilen);
+ arg->sock = client_sock;
+ arg->cli_addr = cli_addr;
+ arg->clilen = clilen;
- if (arg->sock < 0)
- {
- handle_error(RIG_DEBUG_ERR, "accept");
- break;
- }
-
- if ((retcode = getnameinfo((struct sockaddr const *)&arg->cli_addr,
- arg->clilen,
+ if ((retcode = getnameinfo((struct sockaddr const *)&cli_addr,
+ clilen,
host,
sizeof(host),
serv,
@@ -579,19 +636,23 @@ int main(int argc, char *argv[])
host,
serv);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
retcode = pthread_create(&thread, &attr, handle_socket, arg);
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
- break;
+#ifdef __MINGW32__
+ closesocket(client_sock);
+#else
+ close(client_sock);
+#endif
+ free(arg);
+ daemon_client_tracker_release(&client_tracker);
+ continue;
}
-
}
- while (retcode == 0);
+
+ pthread_attr_destroy(&attr);
rot_close(my_rot); /* close port */
rot_cleanup(my_rot); /* if you care about memory */
@@ -698,6 +759,7 @@ handle_exit:
#else
close(handle_data_arg->sock);
#endif
+ daemon_client_tracker_release(&client_tracker);
free(arg);
pthread_exit(NULL);
@@ -716,6 +778,7 @@ static void usage(FILE *fout)
" -R, --rot-file2=DEVICE set device of the 2nd rotator controller to operate on\n"
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
" -t, --port=NUM set TCP listening port, default %s\n"
+ " -N, --max-clients=NUM set maximum concurrent clients, default %u\n"
" -T, --listen-addr=IPADDR set listening IP address, default ANY\n"
" -C, --set-conf=PARM=VAL[,...] set config parameters\n"
" -o, --set-azoffset=VAL set offset for azimuth\n"
@@ -727,7 +790,8 @@ static void usage(FILE *fout)
" -Z, --debug-time-stamps enable time stamps for debug messag...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-10-20 02:00:23
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 06335264db0106053a2d9f7122cab28be27fe15d (commit)
via a9a0b789e3157939575de9afe2930a3ba39fe406 (commit)
via fa0ed6d6abe19d1a599cf6c6b0badd699bb3add7 (commit)
via 3b4fa811994f0f061a1a600252af9fe2b02cc25c (commit)
via ff30b987e329387766dde952056658a83ffeb1c6 (commit)
via 91deb674585ec37a49994e1afcab45e58fc5b620 (commit)
via f8df85d184891880d3dc7c3ca0018f849ebf1ee7 (commit)
from 58beb9ab5bb8cf9cb25070ac89f22b24f2df3f48 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 06335264db0106053a2d9f7122cab28be27fe15d
Merge: a9a0b789e ff30b987e
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 15:33:52 2026 -0400
Merge pull request #2255 from dchristle/fix/ptt-instance-configuration
fix(conf): keep PTT overrides local to each rig instance
commit a9a0b789e3157939575de9afe2930a3ba39fe406
Merge: 3b4fa8119 fa0ed6d6a
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 15:33:48 2026 -0400
Merge pull request #2227 from dchristle/fix/rig-send-raw-reply-capacity
fix(core): honor rig_send_raw reply capacity
commit fa0ed6d6abe19d1a599cf6c6b0badd699bb3add7
Author: David Christle <dch...@us...>
Date: Mon Sep 21 22:46:42 2026 +0200
fix(core): honor rig_send_raw reply capacity
The fixed internal buffer can overflow when a caller advertises a larger
reply capacity. Allocate storage for that capacity and an extra byte so
terminated reads can reject replies that would otherwise be truncated.
Preserve the minimum storage needed by the Icom reader. Cover large
replies through Dummy and Python, and exercise capacity boundaries,
binary reads, and Icom frames over a socket transport.
diff --git a/bindings/python/test_rig.py b/bindings/python/test_rig.py
index 91986d615..764090aa6 100755
--- a/bindings/python/test_rig.py
+++ b/bindings/python/test_rig.py
@@ -207,6 +207,9 @@ class TestClass:
assert rig.send_raw(test_bytes_1, "s") == b"tes"
assert rig.send_raw(test_bytes_2, b"\x02") == test_bytes_1
+ test_bytes_3 = bytes(range(255))
+ assert rig.send_raw(test_bytes_3) == test_bytes_3
+
def test_with_open(self, model, rig_file, serial_speed):
"""Call all the methods that depend on open()"""
diff --git a/src/rig.c b/src/rig.c
index 39ede86a5..76d2e441e 100644
--- a/src/rig.c
+++ b/src/rig.c
@@ -1761,7 +1761,6 @@ int HAMLIB_API rig_close(RIG *rig)
ENTERFUNC;
-
caps = rig->caps;
rs = STATE(rig);
rp = RIGPORT(rig);
@@ -8950,6 +8949,11 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
ELAPSED1;
+ if (reply != NULL && reply_len < 1)
+ {
+ RETURNFUNC(-RIG_EINVAL);
+ }
+
rig_debug(RIG_DEBUG_VERBOSE, "%s: writing %d bytes\n", __func__, send_len);
set_transaction_active(rig);
@@ -8974,7 +8978,26 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
if (reply)
{
- unsigned char buf[200];
+ unsigned char stack_buf[200];
+ unsigned char *buf = stack_buf;
+ /* Detect terminated replies that fill the caller's buffer. */
+ size_t buf_len = (size_t)reply_len + 1;
+ int buffer_allocated = 0;
+
+ if (buf_len > sizeof(stack_buf))
+ {
+ buf = malloc(buf_len);
+
+ if (buf == NULL)
+ {
+ rig_flush_force(rp, 1);
+ set_transaction_inactive(rig);
+ ELAPSED2;
+ RETURNFUNC(-RIG_ENOMEM);
+ }
+
+ buffer_allocated = 1;
+ }
if (simulate)
{
@@ -9002,13 +9025,13 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
else if (*term == 0xfd) // then we want an Icom frame
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: reading icom frame\n", __func__);
- retval = read_icom_frame(rp, buf, sizeof(buf));
+ retval = read_icom_frame(rp, buf, reply_len);
}
else // we'll assume the provided terminator works
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: reading frame terminated by 0x%x\n", __func__,
*term);
- retval = read_string(rp, buf, sizeof(buf), (const char *)term,
+ retval = read_string(rp, buf, buf_len, (const char *)term,
1, 0, 1);
}
@@ -9017,6 +9040,8 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
rig_debug(RIG_DEBUG_ERR, "%s: read_string, result=%d\n", __func__, retval);
rig_flush_force(rp, 1);
set_transaction_inactive(rig);
+
+ if (buffer_allocated) { free(buf); }
ELAPSED2;
RETURNFUNC(retval);
}
@@ -9029,12 +9054,16 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
__func__, reply_len, nbytes);
rig_flush_force(rp, 1);
set_transaction_inactive(rig);
+
+ if (buffer_allocated) { free(buf); }
ELAPSED2;
RETURNFUNC(-RIG_EINVAL);
}
}
memcpy(reply, buf, nbytes);
+
+ if (buffer_allocated) { free(buf); }
}
else
{
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b5ba02f8c..c750c7e33 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -38,6 +38,7 @@ DIRECT_TESTS = \
testnewcatset \
testnewcatwidth \
testrigctlprotocol \
+ testsendraw \
testmodecompat \
testthd7x \
testthd75emu \
@@ -73,6 +74,7 @@ check_PROGRAMS = \
testloc \
testmW2power \
testnetrigctl \
+ testsendraw \
testrig \
testrigcaps \
testrigopen \
@@ -125,6 +127,7 @@ rigctltcp_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_srcdir)/src -I$(top_bu
rigctlsync_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I$(top_srcdir)/src -I$(top_builddir)/security
testdebug_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testnetrigctl_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testsendraw_CFLAGS = $(AM_CFLAGS)
testcachemode_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testcacherouting_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testcachethread_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
@@ -173,6 +176,8 @@ rigstreamtest_CPPFLAGS = -I$(top_srcdir)/src -I$(top_builddir)/src \
$(AM_CPPFLAGS)
testnetrigctl_SOURCES = testnetrigctl.c $(top_srcdir)/rigs/dummy/dummy_common.c
testnetrigctl_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
+testsendraw_SOURCES = testsendraw.c
+testsendraw_LDADD = $(NET_LIBS) $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testcachemode_LDADD = $(PTHREAD_LIBS) \
$(top_builddir)/rigs/dummy/libhamlib-dummy.la \
$(LDADD)
diff --git a/tests/testsendraw.c b/tests/testsendraw.c
new file mode 100644
index 000000000..02627e385
--- /dev/null
+++ b/tests/testsendraw.c
@@ -0,0 +1,193 @@
+/*
+ * Hamlib rig_send_raw capacity tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#ifndef _WIN32
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
+
+#include "hamlib/rig.h"
+#include "hamlib/riglist.h"
+#include "hamlib/port.h"
+
+static int test_dummy_reply(void)
+{
+ unsigned char request[255];
+ unsigned char reply[256];
+ RIG *rig;
+ int count;
+
+ for (size_t i = 0; i < sizeof(request); ++i)
+ {
+ request[i] = (unsigned char)i;
+ }
+
+ rig = rig_init(RIG_MODEL_DUMMY);
+
+ if (rig == NULL)
+ {
+ fprintf(stderr, "failed to initialize Dummy rig\n");
+ return 1;
+ }
+
+ count = rig_send_raw(rig, request, sizeof(request), reply, sizeof(reply),
+ NULL);
+ rig_cleanup(rig);
+
+ if (count != sizeof(request) || memcmp(request, reply, count) != 0)
+ {
+ fprintf(stderr, "expected a %zu-byte echoed reply, got %d\n",
+ sizeof(request), count);
+ return 1;
+ }
+
+ return 0;
+}
+
+#ifndef _WIN32
+static int test_transport_reply(const char *name,
+ const unsigned char *response,
+ size_t response_len, int reply_len,
+ unsigned char *term, int expected)
+{
+ int sockets[2];
+ unsigned char reply[514];
+ size_t written = 0;
+ RIG *rig;
+ int count;
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0)
+ {
+ perror("socketpair");
+ return 1;
+ }
+
+ rig = rig_init(RIG_MODEL_FT991);
+
+ if (rig == NULL)
+ {
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->type.rig = RIG_PORT_NETWORK;
+ RIGPORT(rig)->rig = rig;
+ RIGPORT(rig)->timeout = 50;
+ RIGPORT(rig)->retry = 0;
+
+ while (written < response_len)
+ {
+ ssize_t result = write(sockets[1], response + written,
+ response_len - written);
+
+ if (result <= 0)
+ {
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ written += (size_t)result;
+ }
+
+ memset(reply, 0xa5, sizeof(reply));
+ count = rig_send_raw(rig, (const unsigned char *)"FA;", 3,
+ reply, reply_len, term);
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+
+ if (count != expected
+ || (count > 0 && memcmp(response, reply, (size_t)count) != 0))
+ {
+ fprintf(stderr, "%s: expected %d bytes, got %d\n",
+ name, expected, count);
+ return 1;
+ }
+
+ for (size_t i = count > 0 ? (size_t)count : 0; i < sizeof(reply); i++)
+ {
+ if (reply[i] != 0xa5)
+ {
+ fprintf(stderr, "%s: modified reply byte %zu\n", name, i);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int test_transport_replies(void)
+{
+ static const unsigned char response[] = "FA014074000;";
+ static const unsigned char icom_response[] =
+ {
+ 0xfe, 0xfe, 0xe0, 0x94, 0x03, 0, 0, 0, 0, 0, 0xfd
+ };
+ unsigned char term[] = ";";
+ unsigned char icom_term[] = {0xfd};
+ unsigned char large_response[512];
+ int failed = 0;
+
+ failed |= test_transport_reply("terminated reply exceeds capacity",
+ response, sizeof(response) - 1, 8, term,
+ -RIG_EINVAL);
+ failed |= test_transport_reply("terminated reply fills capacity",
+ response, sizeof(response) - 1, 12, term,
+ -RIG_EINVAL);
+ failed |= test_transport_reply("terminated reply fits capacity",
+ response, sizeof(response) - 1, 13, term, 12);
+
+ memset(large_response, 'X', sizeof(large_response));
+ large_response[254] = ';';
+ failed |= test_transport_reply("large terminated reply",
+ large_response, 255, 256, term, 255);
+ failed |= test_transport_reply("large binary reply",
+ large_response, 255, 256, NULL, 255);
+ failed |= test_transport_reply("short binary reply times out",
+ response, 5, 256, NULL, -RIG_ETIMEOUT);
+
+ large_response[254] = 'X';
+ large_response[299] = ';';
+ failed |= test_transport_reply("large reply exceeds capacity",
+ large_response, 300, 256, term, -RIG_EINVAL);
+
+ large_response[299] = 'X';
+ large_response[511] = ';';
+ failed |= test_transport_reply("reply exceeds binding capacity",
+ large_response, sizeof(large_response),
+ 513, term, 512);
+ failed |= test_transport_reply("Icom reply exceeds capacity",
+ icom_response, sizeof(icom_response),
+ 5, icom_term, -RIG_EINVAL);
+ failed |= test_transport_reply("Icom reply fits capacity",
+ icom_response, sizeof(icom_response),
+ 12, icom_term, 11);
+ return failed;
+}
+#endif
+
+int main(void)
+{
+ int failed = test_dummy_reply();
+
+#ifndef _WIN32
+ failed |= test_transport_replies();
+#endif
+
+ return failed;
+}
commit 3b4fa811994f0f061a1a600252af9fe2b02cc25c
Merge: 58beb9ab5 91deb6745
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 14:06:22 2026 -0400
Merge pull request #2263 from KJ5HST/ftx1-ky-memory-play
ftx1: send CW via a keyer TEXT memory; KY is playback-only
commit ff30b987e329387766dde952056658a83ffeb1c6
Author: David Christle <dch...@us...>
Date: Mon Oct 19 10:03:09 2026 -0700
fix(cli): reject unrecognised PTT type selections
Invalid PTT selections could disable PTT while commands still reported
success. Reject them on stderr with status 2 before opening a rig,
rather than continuing with a fallback control method.
diff --git a/NEWS b/NEWS
index 1b08273e7..6a344089f 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,11 @@ Please send Hamlib bug reports to ham...@li...
Version 5.x -- future
+ * Fix: Keep PTT overrides local to each rig instance without changing
+ model capabilities. GitHub PR #2255.
+ * rigctl/rigctld: Honor explicit PTT NONE selections and default to
+ RTS for a PTT device path only when no type was selected. Invalid
+ PTT types now report an error on stderr and exit with status 2.
* QMX: Add SWR and RF power meter readback using the QRP Labs
SW and PC CAT commands. The power meter full scale (6W stock,
12W with the PA0RDT PA modification) is read from the radio at
diff --git a/tests/rigctl.c b/tests/rigctl.c
index e261d1f21..ba1349dba 100644
--- a/tests/rigctl.c
+++ b/tests/rigctl.c
@@ -299,8 +299,6 @@ int main(int argc, char *argv[])
break;
case 'P':
- ptt_type_set = 1;
-
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
@@ -335,10 +333,11 @@ int main(int argc, char *argv[])
}
else
{
- puts("Unrecognised PTT type, using NONE");
- ptt_type = RIG_PTT_NONE;
+ fprintf(stderr, "Unrecognised PTT type '%s'\n", optarg);
+ exit(2);
}
+ ptt_type_set = 1;
break;
case 'D':
diff --git a/tests/rigctld.c b/tests/rigctld.c
index 967d3dcb0..c9830fa73 100644
--- a/tests/rigctld.c
+++ b/tests/rigctld.c
@@ -486,8 +486,6 @@ int main(int argc, char *argv[])
break;
case 'P':
- ptt_type_set = 1;
-
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
@@ -522,10 +520,11 @@ int main(int argc, char *argv[])
}
else
{
- puts("Unrecognised PTT type, using NONE");
- ptt_type = RIG_PTT_NONE;
+ fprintf(stderr, "Unrecognised PTT type '%s'\n", optarg);
+ exit(2);
}
+ ptt_type_set = 1;
break;
case 'D':
diff --git a/tests/testctlptt.sh b/tests/testctlptt.sh
index b0900f7a3..36ea384c6 100755
--- a/tests/testctlptt.sh
+++ b/tests/testctlptt.sh
@@ -2,6 +2,10 @@
set -eu
+tmp_dir=$(mktemp -d "${TMPDIR:-/tmp}/testctlptt.XXXXXX")
+trap 'rm -f "$tmp_dir/stdout" "$tmp_dir/stderr"; rmdir "$tmp_dir"' 0
+trap 'exit 1' 1 2 3 15
+
check_ptt()
{
expected=$1
@@ -19,11 +23,34 @@ check_ptt()
fi
}
+check_invalid_ptt()
+{
+ invalid=$1
+ shift
+
+ if "$program" -m 1 -L -u "$@" >"$tmp_dir/stdout" 2>"$tmp_dir/stderr"
+ then
+ status=0
+ else
+ status=$?
+ fi
+
+ if test "$status" -ne 2 || test -s "$tmp_dir/stdout" ||
+ test "$(cat "$tmp_dir/stderr")" != "Unrecognised PTT type '$invalid'"
+ then
+ printf '%s %s: expected status 2, empty stdout, and invalid PTT diagnostic; got status %s\n' \
+ "$program" "$*" "$status" >&2
+ cat "$tmp_dir/stdout" "$tmp_dir/stderr" >&2
+ exit 1
+ fi
+}
+
for program in ./rigctl ./rigctld
do
check_ptt RIG
check_ptt None -P NONE
check_ptt RTS -P RTS -C timeout=500
+ check_ptt RTS -P RIG -P RTS
check_ptt None -P RIG -C ptt_type=None
check_ptt None -C ptt_type=None -P RIG
check_ptt RIGMICDATA -P RTS -C ptt_type=RIGMICDATA,timeout=500
@@ -34,6 +61,18 @@ do
check_ptt None -p unused-ptt-device -C ptt_type=None
check_ptt RIG -p unused-ptt-device -P RIG
+ for invalid in bogus rig CAT RIGMICDATA Parallel
+ do
+ check_invalid_ptt "$invalid" -P "$invalid"
+ done
+ check_invalid_ptt bogus --ptt-type=bogus
+ check_invalid_ptt bogus -P RTS -P bogus
+ check_invalid_ptt bogus -P bogus -P RTS
+ check_invalid_ptt bogus -p unused-ptt-device -P bogus
+ check_invalid_ptt bogus -P bogus -p unused-ptt-device
+ check_invalid_ptt bogus -C ptt_type=RIG -P bogus
+ check_invalid_ptt bogus -P bogus -C ptt_type=RIG
+
output=$("$program" -m 1 -P NONE -C ptt_type=None -u)
capability=$(printf '%s\n' "$output" | awk '
/^PTT type:/ { sub(/^PTT type:[[:space:]]*/, ""); print; exit }
commit 91deb674585ec37a49994e1afcab45e58fc5b620
Author: KJ5HST <kj...@de...>
Date: Sun Oct 18 15:14:16 2026 -0400
ftx1: send CW via a keyer TEXT memory; KY is playback-only
The FTX-1 has no direct-text CW send. KY is "CW KEYING MEMORY PLAY",
KY P1 P2; with P1 0=TEXT/1=MESSAGE memory and P2 0=stop or 1-5=slot, so
the "KY0<text>;" and "KY0;" forms the driver sent are rejected with "?;".
send_morse: a single digit "1"-"5" plays that TEXT memory (KY0n;). Any
other text is written to TEXT memory 5 with KM (overwriting it,
uppercased, at most 50 characters) and played with KY05;.
stop_morse: KY00;.
The core passes longer messages as 50-character chunks back to back, and
a new KM/KY restarts playback, so each chunk now waits for the previous
one: poll TX; until the transmitter drops (it stays keyed while a memory
plays with break-in), bounded by the keyer speed. After KY, wait briefly
for the radio to key so the next chunk sees it playing. Both waits give
up as soon as stop_morse() flushes the CW queue, so stop stays prompt.
Fixes #2183
diff --git a/rigs/yaesu/ftx1/ftx1_cw.c b/rigs/yaesu/ftx1/ftx1_cw.c
index f250f629e..5e4146191 100644
--- a/rigs/yaesu/ftx1/ftx1_cw.c
+++ b/rigs/yaesu/ftx1/ftx1_cw.c
@@ -8,7 +8,7 @@
* KP P1P2; - Key Pitch Frequency (00-75: 300-1050 Hz in 10Hz steps)
* KR P1; - Keyer Enable (0=off, 1=on)
* KS P1P2P3; - Keyer Speed (004-060 WPM)
- * KY P1 P2...; - CW Message Send (P1=0, P2=message up to 24 chars)
+ * KY P1 P2; - CW Keying Memory Play (P1 0=TEXT/1=MESSAGE, P2 0=stop/1-5=slot)
* KM P1 P2...; - Keyer Memory Read/Write (P1=1-5 slot, P2=message up to 50 chars)
* SD P1P2; - CW Break-in Delay (00-33, see CAT manual for mapping)
* CS P1; - CW Spot (0=off, 1=on)
@@ -26,6 +26,7 @@
#include "misc.h"
#include "yaesu.h"
#include "newcat.h"
+#include "fifo.h"
#define FTX1_CW_SPEED_MIN 4
#define FTX1_CW_SPEED_MAX 60
@@ -34,7 +35,11 @@
/* SD P1P2; - 2 digits, 00-33 (non-linear: 00=30ms, 01=50ms, 02-05=100-250ms, 06-33=300-3000ms) */
#define FTX1_CW_DELAY_MIN 0
#define FTX1_CW_DELAY_MAX 33
-#define FTX1_CW_MSG_MAX 24
+/* TEXT memory that send_morse() overwrites with free text before playing it */
+#define FTX1_CW_SEND_SLOT 5
+
+int ftx1_set_keyer_memory(RIG *rig, int slot, const char *msg);
+extern int ftx1_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt);
/* Set Keyer Speed (KS P1P2P3;) in WPM */
int ftx1_set_keyer_speed(RIG *rig, int wpm)
@@ -172,12 +177,59 @@ int ftx1_get_keyer(RIG *rig, int *enable)
return RIG_OK;
}
-/* Send CW Message (KY P1 P2...;) */
+/*
+ * Poll TX; every 100 ms until the transmitter is keyed (want_keyed=1) or
+ * unkeyed (want_keyed=0), for at most timeout_ms. Gives up early once
+ * stop_morse() has flushed the CW queue. Returns 1 if the state was reached.
+ */
+static int ftx1_wait_tx(RIG *rig, int want_keyed, int timeout_ms)
+{
+ const FIFO_RIG *fifo = STATE(rig)->fifo_morse;
+ ptt_t ptt;
+
+ for (int waited = 0; waited <= timeout_ms; waited += 100)
+ {
+ if (fifo && fifo->flush)
+ {
+ return 0;
+ }
+
+ if (ftx1_get_ptt(rig, RIG_VFO_CURR, &ptt) != RIG_OK)
+ {
+ return 0;
+ }
+
+ if ((ptt != RIG_PTT_OFF) == (want_keyed != 0))
+ {
+ return 1;
+ }
+
+ hl_usleep(100 * 1000);
+ }
+
+ return 0;
+}
+
+/*
+ * Send CW (KM + KY)
+ *
+ * The FTX-1 has no direct-text CW send: KY only plays a keyer memory
+ * (KY P1 P2; P1 0=TEXT memory, P2 0=stop, 1-5=play that slot). A single
+ * digit "1"-"5" plays that TEXT memory. Any other text is written to TEXT
+ * memory FTX1_CW_SEND_SLOT (overwriting it) and played from there.
+ *
+ * A new KM/KY restarts playback, and the core passes a long message as
+ * 50-character chunks back to back, so each chunk waits for the previous
+ * one to finish. With break-in the transmitter stays keyed while a memory
+ * plays; there is no other "playback done" indication over CAT.
+ */
int ftx1_send_morse(RIG *rig, vfo_t vfo, const char *msg)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- char safe_msg[FTX1_CW_MSG_MAX + 1];
- size_t len;
+ const FIFO_RIG *fifo = STATE(rig)->fifo_morse;
+ int slot;
+ int err;
+ int wpm;
(void)vfo; /* Unused */
@@ -186,25 +238,49 @@ int ftx1_send_morse(RIG *rig, vfo_t vfo, const char *msg)
return -RIG_EINVAL;
}
- /* Copy and truncate message */
- strncpy(safe_msg, msg, FTX1_CW_MSG_MAX);
- safe_msg[FTX1_CW_MSG_MAX] = '\0';
+ /* Up to 22 dot units per character (dot = 1200/wpm ms) plus break-in delay */
+ if (ftx1_get_keyer_speed(rig, &wpm) != RIG_OK || wpm < FTX1_CW_SPEED_MIN)
+ {
+ wpm = FTX1_CW_SPEED_MIN;
+ }
- /* Convert to uppercase (CW convention) */
- len = strlen(safe_msg);
- for (size_t i = 0; i < len; i++)
+ if (!ftx1_wait_tx(rig, 0, 50 * 22 * 1200 / wpm + 4000) && fifo && fifo->flush)
{
- if (safe_msg[i] >= 'a' && safe_msg[i] <= 'z')
+ return RIG_OK; /* stop_morse() was called while we waited */
+ }
+
+ if (msg[1] == '\0' && msg[0] >= '1' && msg[0] <= '5')
+ {
+ slot = msg[0] - '0';
+ }
+ else
+ {
+ slot = FTX1_CW_SEND_SLOT;
+
+ /* Uppercases and truncates to the 50-character memory size */
+ if (RIG_OK != (err = ftx1_set_keyer_memory(rig, slot, msg)))
{
- safe_msg[i] = safe_msg[i] - 'a' + 'A';
+ return err;
}
}
- rig_debug(RIG_DEBUG_VERBOSE, "%s: msg='%s'\n", __func__, safe_msg);
+ rig_debug(RIG_DEBUG_VERBOSE, "%s: playing TEXT memory %d\n", __func__, slot);
- /* KY0 msg; - P1=0 indicates direct send */
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KY0%s;", safe_msg);
- return newcat_set_cmd(rig);
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KY0%d;", slot);
+
+ if (RIG_OK != (err = newcat_set_cmd(rig)))
+ {
+ return err;
+ }
+
+ /*
+ * The radio keys a few hundred ms after KY. Wait for that so the next
+ * chunk's check above sees this one playing. Without break-in the
+ * transmitter never keys and this just times out.
+ */
+ (void)ftx1_wait_tx(rig, 1, 1500);
+
+ return RIG_OK;
}
/* Stop CW Message */
@@ -216,8 +292,8 @@ int ftx1_stop_morse(RIG *rig, vfo_t vfo)
rig_debug(RIG_DEBUG_VERBOSE, "%s\n", __func__);
- /* KY0; with no message stops sending */
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KY0;");
+ /* KY P1=0 P2=0: stop keying memory playback */
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KY00;");
return newcat_set_cmd(rig);
}
commit f8df85d184891880d3dc7c3ca0018f849ebf1ee7
Author: David Christle <dch...@us...>
Date: Wed Oct 14 22:39:07 2026 -0700
fix(conf): keep PTT overrides local to each rig instance
Setting ptt_type overwrote shared model capabilities, so selecting None
for one rig disabled CAT PTT on later instances of the same model.
Keep frontend and CLI overrides on the instance PTT port. Preserve
configuration precedence and explicit None selections, and cover
existing and newly initialized rigs with offline regressions.
diff --git a/src/conf.c b/src/conf.c
index d2a02bf0d..a113fd623 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -619,32 +619,26 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
if (!strcmp(val, "RIG"))
{
pttp->type.ptt = RIG_PTT_RIG;
- caps->ptt_type = RIG_PTT_RIG;
}
else if (!strcmp(val, "RIGMICDATA"))
{
pttp->type.ptt = RIG_PTT_RIG_MICDATA;
- caps->ptt_type = RIG_PTT_RIG_MICDATA;
}
else if (!strcmp(val, "DTR"))
{
pttp->type.ptt = RIG_PTT_SERIAL_DTR;
- caps->ptt_type = RIG_PTT_SERIAL_DTR;
}
else if (!strcmp(val, "RTS"))
{
pttp->type.ptt = RIG_PTT_SERIAL_RTS;
- caps->ptt_type = RIG_PTT_SERIAL_RTS;
}
else if (!strcmp(val, "Parallel"))
{
pttp->type.ptt = RIG_PTT_PARALLEL;
- caps->ptt_type = RIG_PTT_PARALLEL;
}
else if (!strcmp(val, "CM108"))
{
pttp->type.ptt = RIG_PTT_CM108;
- caps->ptt_type = RIG_PTT_CM108;
}
else if (!strcmp(val, "GPIO"))
{
@@ -653,21 +647,16 @@ static int frontend_set_conf(RIG *rig, hamlib_token_t token, const char *val)
else if (!strcmp(val, "GPION"))
{
pttp->type.ptt = RIG_PTT_GPION;
- caps->ptt_type = RIG_PTT_GPION;
}
else if (!strcmp(val, "None"))
{
pttp->type.ptt = RIG_PTT_NONE;
- caps->ptt_type = RIG_PTT_NONE;
}
else
{
return -RIG_EINVAL;
}
- // JTDX and WSJTX currently use state.pttport to check for PTT_NONE
- //rs->pttport_deprecated.type.ptt = pttp->type.ptt;
-
break;
case TOK_PTT_PATHNAME:
diff --git a/test/Makefile.am b/test/Makefile.am
index 12893dc3f..19778a21c 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -29,6 +29,9 @@ LDADD = $(top_builddir)/src/libhamlib.la $(top_builddir)/lib/libmisc.la $(DL_LIB
check_PROGRAMS = test_stream_ringbuf test_stream_convert test_stream_codec test_stream_time test_stream_account test_stream_api test_dummy_stream test_rigctld_stream test_rigstreamtest test_rigctld_commands test_netrigctl_stream
+check_PROGRAMS += test_conf
+test_conf_SOURCES = test_conf.c
+
test_stream_codec_SOURCES = test_stream_codec.c
test_stream_codec_LDADD = $(LDADD)
diff --git a/test/test_conf.c b/test/test_conf.c
new file mode 100644
index 000000000..99b7ef821
--- /dev/null
+++ b/test/test_conf.c
@@ -0,0 +1,101 @@
+/*
+ * Hamlib frontend configuration tests
+ * Copyright (c) 2026 by Hamlib Team
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "acutest.h"
+#include "test_debug.h"
+#include <string.h>
+
+static void check_ptt_config(RIG *rig, const char *expected)
+{
+ char actual[32];
+ hamlib_token_t token = rig_token_lookup(rig, "ptt_type");
+
+ TEST_ASSERT(token != RIG_CONF_END);
+ TEST_ASSERT(rig_get_conf2(rig, token, actual, sizeof(actual)) == RIG_OK);
+ TEST_CHECK_(strcmp(actual, expected) == 0,
+ "PTT configuration: expected %s, got %s", expected, actual);
+}
+
+static void test_ptt_overrides_are_instance_local(void)
+{
+ const char *values[] =
+ {
+ "None", "DTR", "RTS", "Parallel", "CM108",
+ "GPIO", "GPION", "RIGMICDATA", "RIG"
+ };
+ RIG *configured = rig_init(RIG_MODEL_DUMMY);
+ RIG *existing = rig_init(RIG_MODEL_DUMMY);
+
+ TEST_ASSERT(configured != NULL && existing != NULL);
+ hamlib_token_t token = rig_token_lookup(configured, "ptt_type");
+ TEST_ASSERT(token != RIG_CONF_END);
+ TEST_ASSERT(configured->caps->ptt_type == RIG_PTT_RIG);
+
+ for (size_t i = 0; i < sizeof(values) / sizeof(values[0]); ++i)
+ {
+ TEST_CASE(values[i]);
+ TEST_ASSERT(rig_set_conf(configured, token, values[i]) == RIG_OK);
+ check_ptt_config(configured, values[i]);
+ check_ptt_config(existing, "RIG");
+ TEST_CHECK(configured->caps->ptt_type == RIG_PTT_RIG);
+ TEST_CHECK(rig_get_caps_int(RIG_MODEL_DUMMY, RIG_CAPS_PTT_TYPE)
+ == RIG_PTT_RIG);
+
+ RIG *subsequent = rig_init(RIG_MODEL_DUMMY);
+ TEST_ASSERT(subsequent != NULL);
+ check_ptt_config(subsequent, "RIG");
+ TEST_CHECK(rig_cleanup(subsequent) == RIG_OK);
+ }
+
+ TEST_CHECK(rig_set_conf(configured, token, "invalid") == -RIG_EINVAL);
+ check_ptt_config(configured, "RIG");
+ TEST_CHECK(rig_cleanup(configured) == RIG_OK);
+ TEST_CHECK(rig_cleanup(existing) == RIG_OK);
+}
+
+static void test_ptt_none_then_cat(void)
+{
+ RIG *configured = rig_init(RIG_MODEL_DUMMY);
+ RIG *existing = rig_init(RIG_MODEL_DUMMY);
+ ptt_t ptt;
+
+ TEST_ASSERT(configured != NULL && existing != NULL);
+ hamlib_token_t token = rig_token_lookup(configured, "ptt_type");
+ TEST_ASSERT(token != RIG_CONF_END);
+ TEST_ASSERT(rig_set_conf(configured, token, "None") == RIG_OK);
+ TEST_ASSERT(rig_set_cache_timeout_ms(configured, HAMLIB_CACHE_ALL, 0)
+ == RIG_OK);
+ TEST_ASSERT(rig_open(configured) == RIG_OK);
+ TEST_CHECK(rig_get_ptt(configured, RIG_VFO_CURR, &ptt) == -RIG_ENAVAIL);
+
+ RIG *subsequent = rig_init(RIG_MODEL_DUMMY);
+ TEST_ASSERT(subsequent != NULL);
+ RIG *cat_rigs[] = { existing, subsequent };
+
+ for (size_t i = 0; i < sizeof(cat_rigs) / sizeof(cat_rigs[0]); ++i)
+ {
+ TEST_ASSERT(rig_set_cache_timeout_ms(cat_rigs[i], HAMLIB_CACHE_ALL, 0)
+ == RIG_OK);
+ TEST_ASSERT(rig_open(cat_rigs[i]) == RIG_OK);
+ TEST_CHECK(rig_get_ptt(cat_rigs[i], RIG_VFO_CURR, &ptt) == RIG_OK);
+ TEST_CHECK(rig_close(cat_rigs[i]) == RIG_OK);
+ TEST_CHECK(rig_cleanup(cat_rigs[i]) == RIG_OK);
+ }
+
+ TEST_CHECK(rig_close(configured) == RIG_OK);
+ TEST_ASSERT(rig_set_conf(configured, token, "RIG") == RIG_OK);
+ TEST_ASSERT(rig_open(configured) == RIG_OK);
+ TEST_CHECK(rig_get_ptt(configured, RIG_VFO_CURR, &ptt) == RIG_OK);
+ TEST_CHECK(rig_close(configured) == RIG_OK);
+ TEST_CHECK(rig_cleanup(configured) == RIG_OK);
+}
+
+TEST_LIST =
+{
+ { "ptt_overrides_are_instance_local", test_ptt_overrides_are_instance_local },
+ { "ptt_none_then_cat", test_ptt_none_then_cat },
+ { NULL, NULL }
+};
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 92128ff9d..d923429d7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -246,6 +246,7 @@ EXTRA_DIST = \
testcaps.sh \
testctlbounds.sh \
testctld.pl \
+ testctlptt.sh \
testroutingaccess.sh \
testrotctld.pl
@@ -256,6 +257,7 @@ check_SCRIPTS = \
rigstreamtest.sh \
testcaps.sh \
testctlbounds.sh \
+ testctlptt.sh \
testroutingaccess.sh \
$(GENERATED_TEST_WRAPPERS)
diff --git a/tests/rigctl.c b/tests/rigctl.c
index 11c4eda71..e261d1f21 100644
--- a/tests/rigctl.c
+++ b/tests/rigctl.c
@@ -223,6 +223,7 @@ int main(int argc, char *argv[])
const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL;
ptt_type_t ptt_type = RIG_PTT_NONE;
+ int ptt_type_set = 0;
dcd_type_t dcd_type = RIG_DCD_NONE;
int serial_rate = 0;
const char *civaddr = NULL; /* NULL means no need to set conf */
@@ -298,6 +299,8 @@ int main(int argc, char *argv[])
break;
case 'P':
+ ptt_type_set = 1;
+
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
@@ -511,7 +514,11 @@ int main(int argc, char *argv[])
exit(2);
}
- my_rig->caps->ptt_type = ptt_type;
+ if (ptt_type_set)
+ {
+ PTTPORT(my_rig)->type.ptt = ptt_type;
+ }
+
const char *token = strtok(conf_parms, ",");
struct rig_state *rs = STATE(my_rig);
@@ -538,7 +545,10 @@ int main(int argc, char *argv[])
exit(2);
}
- ptt_type = my_rig->caps->ptt_type; // in case we set the ptt_type with set_conf
+ if (lookup == TOK_PTT_TYPE)
+ {
+ ptt_type_set = 1;
+ }
token = strtok(NULL, ",");
}
@@ -548,14 +558,6 @@ int main(int argc, char *argv[])
rig_set_conf(my_rig, TOK_PATHNAME, rig_file);
}
- /*
- * ex: RIG_PTT_PARALLEL and /dev/parport0
- */
- if (ptt_type != RIG_PTT_NONE)
- {
- PTTPORT(my_rig)->type.ptt = ptt_type;
- }
-
if (dcd_type != RIG_DCD_NONE)
{
DCDPORT(my_rig)->type.dcd = dcd_type;
@@ -566,10 +568,10 @@ int main(int argc, char *argv[])
strncpy(PTTPORT(my_rig)->pathname, ptt_file, HAMLIB_FILPATHLEN - 1);
// default to RTS when ptt_type is not specified
- if (ptt_type == RIG_PTT_NONE)
+ if (!ptt_type_set)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: defaulting to RTS PTT\n", __func__);
- my_rig->caps->ptt_type = RIG_PTT_SERIAL_RTS;
+ PTTPORT(my_rig)->type.ptt = RIG_PTT_SERIAL_RTS;
}
}
diff --git a/tests/rigctld.c b/tests/rigctld.c
index 87b5d2d92..967d3dcb0 100644
--- a/tests/rigctld.c
+++ b/tests/rigctld.c
@@ -271,6 +271,7 @@ int main(int argc, char *argv[])
int dump_caps_opt = 0;
const char *rig_file = NULL, *ptt_file = NULL, *dcd_file = NULL;
ptt_type_t ptt_type = RIG_PTT_NONE;
+ int ptt_type_set = 0;
dcd_type_t dcd_type = RIG_DCD_NONE;
int serial_rate = 0;
const char *civaddr = NULL; /* NULL means no need to set conf */
@@ -485,6 +486,8 @@ int main(int argc, char *argv[])
break;
case 'P':
+ ptt_type_set = 1;
+
if (!strcmp(optarg, "RIG"))
{
ptt_type = RIG_PTT_RIG;
@@ -707,7 +710,11 @@ int main(int argc, char *argv[])
exit(2);
}
- my_rig->caps->ptt_type = ptt_type;
+ if (ptt_type_set)
+ {
+ PTTPORT(my_rig)->type.ptt = ptt_type;
+ }
+
const char *token = strtok(conf_parms, ",");
struct rig_state *rs = STATE(my_rig);
@@ -735,7 +742,11 @@ int main(int argc, char *argv[])
}
token = strtok(NULL, ",");
- ptt_type = my_rig->caps->ptt_type; // in case we set the ptt_type with set_conf
+
+ if (lookup == TOK_PTT_TYPE)
+ {
+ ptt_type_set = 1;
+ }
}
if (rig_file)
@@ -750,17 +761,6 @@ int main(int argc, char *argv[])
__func__,
rs->twiddle_timeout, rs->uplink, rs->twiddle_rit);
- /*
- * ex: RIG_PTT_PARALLEL and /dev/parport0
- */
- if (ptt_type != RIG_PTT_NONE)
- {
- PTTPORT(my_rig)->type.ptt = ptt_type;
- // This causes segfault since backend rig_caps are const
- // rigctld will use the STATE(rig) version of this for clients
- //my_rig->caps->ptt_type = ptt_type;
- }
-
if (dcd_type != RIG_DCD_NONE)
{
DCDPORT(my_rig)->type.dcd = dcd_type;
@@ -771,10 +771,10 @@ int main(int argc, char *argv[])
strncpy(PTTPORT(my_rig)->pathname, ptt_file, HAMLIB_FILPATHLEN - 1);
// default to RTS when ptt_type is not specified
- if (ptt_type == RIG_PTT_NONE)
+ if (!ptt_type_set)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: defaulting to RTS PTT\n", __func__);
- my_rig->caps->ptt_type = RIG_PTT_SERIAL_RTS;
+ PTTPORT(my_rig)->type.ptt = RIG_PTT_SERIAL_RTS;
}
}
diff --git a/tests/testctlptt.sh b/tests/testctlptt.sh
new file mode 100755
index 000000000..b0900f7a3
--- /dev/null
+++ b/tests/testctlptt.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+set -eu
+
+check_ptt()
+{
+ expected=$1
+ shift
+ output=$("$program" -m 1 -L -u "$@")
+ actual=$(printf '%s\n' "$output" | awk '
+ /^ptt_type:/ { getline; sub(/^.*Value: /, ""); print; exit }
+ ')
+
+ if test "$actual" != "$expected"
+ then
+ printf '%s %s: expected PTT %s, got %s\n' \
+ "$program" "$*" "$expected" "$actual" >&2
+ exit 1
+ fi
+}
+
+for program in ./rigctl ./rigctld
+do
+ check_ptt RIG
+ check_ptt None -P NONE
+ check_ptt RTS -P RTS -C timeout=500
+ check_ptt None -P RIG -C ptt_type=None
+ check_ptt None -C ptt_type=None -P RIG
+ check_ptt RIGMICDATA -P RTS -C ptt_type=RIGMICDATA,timeout=500
+ check_ptt RIG -C ptt_type=None,ptt_type=RIG
+ check_ptt RTS -p unused-ptt-device
+ check_ptt RTS -p unused-ptt-device -C timeout=500
+ check_ptt None -p unused-ptt-device -P NONE
+ check_ptt None -p unused-ptt-device -C ptt_type=None
+ check_ptt RIG -p unused-ptt-device -P RIG
+
+ output=$("$program" -m 1 -P NONE -C ptt_type=None -u)
+ capability=$(printf '%s\n' "$output" | awk '
+ /^PTT type:/ { sub(/^PTT type:[[:space:]]*/, ""); print; exit }
+ ')
+ if test "$capability" != "Rig capable"
+ then
+ printf '%s: PTT override changed model capability to %s\n' \
+ "$program" "$capability" >&2
+ exit 1
+ fi
+done
-----------------------------------------------------------------------
Summary of changes:
NEWS | 5 ++
bindings/python/test_rig.py | 3 +
rigs/yaesu/ftx1/ftx1_cw.c | 114 +++++++++++++++++++++-----
src/conf.c | 11 ---
src/rig.c | 37 ++++++++-
test/Makefile.am | 3 +
test/test_conf.c | 101 +++++++++++++++++++++++
tests/Makefile.am | 7 ++
tests/rigctl.c | 29 +++----
tests/rigctld.c | 33 ++++----
tests/testctlptt.sh | 86 ++++++++++++++++++++
tests/testsendraw.c | 193 ++++++++++++++++++++++++++++++++++++++++++++
12 files changed, 557 insertions(+), 65 deletions(-)
create mode 100644 test/test_conf.c
create mode 100755 tests/testctlptt.sh
create mode 100644 tests/testsendraw.c
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-10-20 01:58:09
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via ddc0a3a14c1d6ef9d8e25cf269d99bd61f602cc2 (commit)
via 189049842a0028f68cd1a581fb42470809607ed0 (commit)
via b479fea717f04730e0bb9d2004f87daedc43fae5 (commit)
from a10d5bf7686415fe184121b6be1b6a911bc23207 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ddc0a3a14c1d6ef9d8e25cf269d99bd61f602cc2
Merge: a10d5bf76 189049842
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 14:12:34 2026 -0400
Merge pull request #2228 from dchristle/backport/4.7-ts990s-data-modes
fix(core): backport DATA submode preservation to 4.7
commit 189049842a0028f68cd1a581fb42470809607ed0
Author: David Christle <dch...@us...>
Date: Mon Oct 19 10:10:41 2026 -0700
fix(kenwood): correct TS-990S data mode handling
TS-990S mode writes affect the operating band even when a different band
is addressed. Restore the prior VFO after failed writes and advertise
all packet DATA profiles for normal-width lookup.
Model operating-band writes in the simulator and exercise preservation,
split routing, and failed-write restoration with a fixture that uses the
4.7 routing state.
diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c
index 02c9f8e3f..5e35b052b 100644
--- a/rigs/kenwood/kenwood.c
+++ b/rigs/kenwood/kenwood.c
@@ -2588,12 +2588,7 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
}
else if (RIG_IS_TS990S)
{
- /* The TS990s has targetable read mode but can only set the mode
- of the current VFO :( So we need to toggle the operating VFO
- to set the "back" VFO mode. This is done here rather than not
- setting caps.targetable_vfo to not include
- RIG_TARGETABLE_MODE since the toggle is not required for
- reading the mode. */
+ /* OM reads address either band, but writes affect the operating band. */
vfo_t curr_vfo;
err = kenwood_get_vfo_main_sub(rig, &curr_vfo);
@@ -2610,16 +2605,16 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
SNPRINTF(buf, sizeof(buf), "OM0%c", c); /* target vfo is ignored */
err = kenwood_transaction(rig, buf, NULL, 0);
- if (err == RIG_OK && vfo != RIG_VFO_CURR && vfo != curr_vfo)
+ if (vfo != RIG_VFO_CURR && vfo != curr_vfo)
{
int err2;
err2 = kenwood_set_vfo_main_sub(rig, curr_vfo);
- if (err2 != RIG_OK) { RETURNFUNC2(err2); }
+ if (err == RIG_OK) { err = err2; }
}
- return RIG_OK;
+ RETURNFUNC2(err);
}
else
{
diff --git a/rigs/kenwood/ts990s.c b/rigs/kenwood/ts990s.c
index 3e667711d..f64865cf4 100644
--- a/rigs/kenwood/ts990s.c
+++ b/rigs/kenwood/ts990s.c
@@ -31,7 +31,8 @@
#define TS990S_AM_MODES RIG_MODE_AM
#define TS990S_FM_MODES (RIG_MODE_FM|RIG_MODE_FMN)
-#define TS990S_OTHER_MODES (RIG_MODE_CW|RIG_MODE_CWR|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_RTTY|RIG_MODE_RTTYR|RIG_MODE_PKTUSB|RIG_MODE_PKTLSB|RIG_MODE_USBD1|RIG_MODE_USBD2|RIG_MODE_USBD3|RIG_MODE_LSBD1|RIG_MODE_LSBD2|RIG_MODE_LSBD3)
+#define TS990S_PACKET_MODES (RIG_MODE_PKTUSB|RIG_MODE_PKTLSB|RIG_MODE_USBD1|RIG_MODE_USBD2|RIG_MODE_USBD3|RIG_MODE_LSBD1|RIG_MODE_LSBD2|RIG_MODE_LSBD3)
+#define TS990S_OTHER_MODES (RIG_MODE_CW|RIG_MODE_CWR|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_RTTY|RIG_MODE_RTTYR|TS990S_PACKET_MODES)
#define TS990S_HP_MODES (TS990S_OTHER_MODES|TS990S_FM_MODES)
#define TS990S_ALL_MODES (TS990S_OTHER_MODES|TS990S_AM_MODES|TS990S_FM_MODES)
@@ -310,25 +311,23 @@ struct rig_caps ts990s_caps =
{RIG_MODE_AM, kHz(2.5)}, /* default narrow - arbitrary choice */
{RIG_MODE_AM, kHz(4)},
{RIG_MODE_AM, kHz(3)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(2.6)}, /* default normal */
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(500)}, /* default narrow -
- arbitrary choice */
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(13)}, /* default wide -
- arbitrary choice */
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(2.8)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(2.4)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(2.2)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(2.0)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(1.5)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, kHz(1.0)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(600)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(400)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(300)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(200)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(150)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(100)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(80)},
- {RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, Hz(50)},
+ {TS990S_PACKET_MODES, kHz(2.6)}, /* default normal */
+ {TS990S_PACKET_MODES, Hz(500)}, /* default narrow - arbitrary choice */
+ {TS990S_PACKET_MODES, kHz(13)}, /* default wide - arbitrary choice */
+ {TS990S_PACKET_MODES, kHz(2.8)},
+ {TS990S_PACKET_MODES, kHz(2.4)},
+ {TS990S_PACKET_MODES, kHz(2.2)},
+ {TS990S_PACKET_MODES, kHz(2.0)},
+ {TS990S_PACKET_MODES, kHz(1.5)},
+ {TS990S_PACKET_MODES, kHz(1.0)},
+ {TS990S_PACKET_MODES, Hz(600)},
+ {TS990S_PACKET_MODES, Hz(400)},
+ {TS990S_PACKET_MODES, Hz(300)},
+ {TS990S_PACKET_MODES, Hz(200)},
+ {TS990S_PACKET_MODES, Hz(150)},
+ {TS990S_PACKET_MODES, Hz(100)},
+ {TS990S_PACKET_MODES, Hz(80)},
+ {TS990S_PACKET_MODES, Hz(50)},
RIG_FLT_END,
},
diff --git a/simulators/simts990.c b/simulators/simts990.c
index d2b96b5af..a1ede810e 100644
--- a/simulators/simts990.c
+++ b/simulators/simts990.c
@@ -382,18 +382,16 @@ int main(int argc, char *argv[])
sprintf(buf, "OM0%c;", modeA);
write(fd, buf, strlen(buf));
}
- else if (strncmp(buf, "OM0", 3) == 0)
- {
- modeA = buf[3];
- }
else if (strncmp(buf, "OM1;", 4) == 0)
{
sprintf(buf, "OM1%c;", modeB);
write(fd, buf, strlen(buf));
}
- else if (strncmp(buf, "OM1", 3) == 0)
+ else if (strncmp(buf, "OM0", 3) == 0 || strncmp(buf, "OM1", 3) == 0)
{
- modeB = buf[3];
+ /* OM writes ignore the band field and affect the operating band. */
+ if (operatingband == 0) { modeA = buf[3]; }
+ else { modeB = buf[3]; }
}
else if (strcmp(buf, "RM;") == 0)
{
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e12eccda0..c953ea9bd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,7 +31,8 @@ DIRECT_TESTS = \
testnewcatset \
testmodecompat \
testthd7x \
- testthd75emu
+ testthd75emu \
+ testts990s
GENERATED_TEST_WRAPPERS = \
test2038.sh \
@@ -114,6 +115,7 @@ testgeministatus_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgs100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testnewcatset_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testelecraftvfo_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testts990s_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testicomts_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testgeministatus_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/amplifiers/gemini
testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu/ftx1
@@ -145,6 +147,7 @@ testicomts_LDADD = $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testgeministatus_LDADD = $(PTHREAD_LIBS) $(top_builddir)/amplifiers/gemini/libhamlib-gemini.la $(LDADD)
testgs100_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/gomspace/libhamlib-gomspace.la $(LDADD)
testelecraftvfo_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood/libhamlib-kenwood.la $(LDADD)
+testts990s_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood/libhamlib-kenwood.la $(LDADD)
testftx1parsers_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testft991idmeter_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testnewcatset_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
diff --git a/tests/testts990s.c b/tests/testts990s.c
new file mode 100644
index 000000000..21d901947
--- /dev/null
+++ b/tests/testts990s.c
@@ -0,0 +1,330 @@
+/*
+ * Hamlib TS-990S mode compatibility tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef _WIN32
+#include <winsock2.h>
+#else
+#include <sys/socket.h>
+#include <unistd.h>
+#endif
+
+#include "hamlib/rig.h"
+#include "hamlib/port.h"
+#include "hamlib/rig_state.h"
+
+extern struct rig_caps ts990s_caps;
+
+struct peer_state
+{
+ int fd;
+ char mode_main;
+ char mode_sub;
+ char operating_band;
+ int fail_next_mode;
+ int fail_verify;
+ int saw_data1_write;
+ int status;
+};
+
+static int close_socket(int fd)
+{
+#ifdef _WIN32
+ return closesocket((SOCKET)fd);
+#else
+ return close(fd);
+#endif
+}
+
+static int read_socket(int fd, char *buffer, size_t length)
+{
+#ifdef _WIN32
+ return recv((SOCKET)fd, buffer, (int)length, 0);
+#else
+ return (int)read(fd, buffer, length);
+#endif
+}
+
+static int write_socket(int fd, const char *buffer, size_t length)
+{
+#ifdef _WIN32
+ return send((SOCKET)fd, buffer, (int)length, 0);
+#else
+ return (int)write(fd, buffer, length);
+#endif
+}
+
+static int read_command(int fd, char *buffer, size_t capacity)
+{
+ size_t used = 0;
+
+ while (used + 1 < capacity)
+ {
+ int count = read_socket(fd, buffer + used, 1);
+
+ if (count <= 0) { return -1; }
+
+ if (buffer[used++] == ';')
+ {
+ buffer[used] = '\0';
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+static int write_reply(int fd, const char *reply)
+{
+ size_t written = 0;
+ size_t length = strlen(reply);
+
+ while (written < length)
+ {
+ int count = write_socket(fd, reply + written, length - written);
+
+ if (count <= 0) { return -1; }
+
+ written += (size_t)count;
+ }
+
+ return 0;
+}
+
+static int handle_command(struct peer_state *peer, const char *command)
+{
+ char reply[16];
+
+ if (strcmp(command, "OM0;") == 0)
+ {
+ snprintf(reply, sizeof(reply), "OM0%c;", peer->mode_main);
+ return write_reply(peer->fd, reply);
+ }
+
+ if (strcmp(command, "OM1;") == 0)
+ {
+ snprintf(reply, sizeof(reply), "OM1%c;", peer->mode_sub);
+ return write_reply(peer->fd, reply);
+ }
+
+ if (strcmp(command, "CB;") == 0)
+ {
+ snprintf(reply, sizeof(reply), "CB%c;", peer->operating_band);
+ return write_reply(peer->fd, reply);
+ }
+
+ if (strcmp(command, "ID;") == 0)
+ {
+ if (peer->fail_verify)
+ {
+ peer->fail_verify = 0;
+ return write_reply(peer->fd, "?;");
+ }
+
+ return write_reply(peer->fd, "ID022;");
+ }
+
+ if (strncmp(command, "CB", 2) == 0 && command[2] != ';')
+ {
+ peer->operating_band = command[2];
+ return 0;
+ }
+
+ if (strncmp(command, "OM0", 3) == 0 && command[3] != ';')
+ {
+ if (command[3] == 'D') { peer->saw_data1_write = 1; }
+
+ if (peer->fail_next_mode)
+ {
+ peer->fail_next_mode = 0;
+ peer->fail_verify = 1;
+ return 0;
+ }
+
+ if (peer->operating_band == '0') { peer->mode_main = command[3]; }
+ else { peer->mode_sub = command[3]; }
+
+ return 0;
+ }
+
+ if (strncmp(command, "TB", 2) == 0)
+ {
+ return 0;
+ }
+
+ return -1;
+}
+
+static void *run_peer(void *arg)
+{
+ struct peer_state *peer = arg;
+ char command[16];
+
+ peer->status = 0;
+
+ for (;;)
+ {
+ if (read_command(peer->fd, command, sizeof(command)) != 0) { return NULL; }
+
+ if (handle_command(peer, command) != 0)
+ {
+ peer->status = 1;
+ return NULL;
+ }
+ }
+}
+
+static int open_test_connection(int sockets[2])
+{
+#ifdef _WIN32
+ (void)sockets;
+ return -1;
+#else
+ return socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
+#endif
+}
+
+static int run_case(const char *name, char mode_main, char mode_sub,
+ rmode_t request, pbwidth_t width, int fail_next_mode,
+ int split, vfo_t target_vfo, int expected_retval, char expected_main,
+ char expected_sub, char expected_operating,
+ int expect_data1_write)
+{
+ int sockets[2];
+ pthread_t thread;
+ struct peer_state peer;
+ RIG *rig;
+ int retval;
+
+ if (open_test_connection(sockets) != 0)
+ {
+ fprintf(stderr, "%s: socket setup failed\n", name);
+ return 1;
+ }
+
+ memset(&peer, 0, sizeof(peer));
+ peer.fd = sockets[1];
+ peer.mode_main = mode_main;
+ peer.mode_sub = mode_sub;
+ peer.operating_band = '0';
+ peer.fail_next_mode = fail_next_mode;
+
+ if (pthread_create(&thread, NULL, run_peer, &peer) != 0)
+ {
+ close_socket(sockets[0]);
+ close_socket(sockets[1]);
+ return 1;
+ }
+
+ rig = rig_init(RIG_MODEL_TS990S);
+
+ if (rig == NULL)
+ {
+ close_socket(sockets[0]);
+ pthread_join(thread, NULL);
+ close_socket(sockets[1]);
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->type.rig = RIG_PORT_NETWORK;
+ RIGPORT(rig)->timeout = 500;
+ RIGPORT(rig)->retry = 0;
+ STATE(rig)->comm_state = 1;
+ STATE(rig)->current_vfo = RIG_VFO_MAIN;
+ STATE(rig)->tx_vfo = RIG_VFO_SUB;
+ STATE(rig)->rx_vfo = RIG_VFO_MAIN;
+
+ if (split)
+ {
+ retval = rig_set_split_vfo(rig, RIG_VFO_MAIN, RIG_SPLIT_ON, RIG_VFO_SUB);
+
+ if (retval != RIG_OK)
+ {
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close_socket(sockets[0]);
+ pthread_join(thread, NULL);
+ close_socket(sockets[1]);
+ return 1;
+ }
+ }
+
+ if (split)
+ {
+ retval = rig_set_split_mode(rig, target_vfo, request, width);
+ }
+ else
+ {
+ retval = rig_set_mode(rig, target_vfo, request, width);
+ }
+
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close_socket(sockets[0]);
+ pthread_join(thread, NULL);
+ close_socket(sockets[1]);
+
+ if (retval != expected_retval
+ || peer.status != 0
+ || peer.mode_main != expected_main
+ || peer.mode_sub != expected_sub
+ || peer.operating_band != expected_operating
+ || peer.saw_data1_write != expect_data1_write)
+ {
+ fprintf(stderr, "%s: result=%d mode=%c/%c operating=%c data1=%d\n",
+ name, retval, peer.mode_main, peer.mode_sub,
+ peer.operating_band, peer.saw_data1_write);
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ int failed = 0;
+
+#ifdef _WIN32
+ return 77;
+#else
+ rig_register(&ts990s_caps);
+
+ {
+ RIG *rig = rig_init(RIG_MODEL_TS990S);
+
+ if (rig == NULL || rig_passband_normal(rig, RIG_MODE_USBD2) != 2600
+ || rig_passband_normal(rig, RIG_MODE_LSBD3) != 2600)
+ {
+ fprintf(stderr, "TS-990S DATA profiles do not advertise a normal width\n");
+ failed = 1;
+ }
+
+ if (rig != NULL) { rig_cleanup(rig); }
+ }
+
+ failed |= run_case("generic USB preserves USBD2", 'H', 'L',
+ RIG_MODE_PKTUSB, RIG_PASSBAND_NOCHANGE, 0, 0, RIG_VFO_MAIN,
+ RIG_OK, 'H', 'L', '0', 0);
+ failed |= run_case("explicit USB width preserves USBD2", 'H', 'L',
+ RIG_MODE_PKTUSB, 2700, 0, 0, RIG_VFO_MAIN, RIG_OK,
+ 'H', 'L', '0', 0);
+ failed |= run_case("split generic USB preserves TX profile", 'H', 'H',
+ RIG_MODE_PKTUSB, RIG_PASSBAND_NOCHANGE, 0, 1, RIG_VFO_MAIN,
+ RIG_OK, 'H', 'H', '0', 0);
+ failed |= run_case("mode error restores operating VFO", 'H', 'L',
+ RIG_MODE_USBD1, RIG_PASSBAND_NOCHANGE, 1, 0, RIG_VFO_SUB,
+ -RIG_ETIMEOUT, 'H', 'L', '0', 1);
+
+ return failed;
+#endif
+}
commit b479fea717f04730e0bb9d2004f87daedc43fae5
Author: David Christle <dch...@us...>
Date: Mon Oct 19 10:09:52 2026 -0700
fix(core): preserve DATA profiles for generic packet requests
Generic packet requests can replace an active DATA profile or skip an
explicit bandwidth change. Resolve them against the target VFO's active
profile, refresh successful no-op queries in the cache, and preserve
split routing and error restoration through the public mode setter.
Use the 4.7 routing state and cover these cases through the public API.
diff --git a/src/rig.c b/src/rig.c
index 8557b3858..6a5e510be 100644
--- a/src/rig.c
+++ b/src/rig.c
@@ -2819,6 +2819,28 @@ int HAMLIB_API rig_get_freqs(RIG *rig, freq_t *freqA, freq_t freqB)
return (-RIG_ENIMPL);
}
+static int mode_satisfies_request(rmode_t requested, rmode_t current)
+{
+ if (requested == current)
+ {
+ return 1;
+ }
+
+ if (requested == RIG_MODE_PKTUSB)
+ {
+ return current == RIG_MODE_USBD1 || current == RIG_MODE_USBD2
+ || current == RIG_MODE_USBD3;
+ }
+
+ if (requested == RIG_MODE_PKTLSB)
+ {
+ return current == RIG_MODE_LSBD1 || current == RIG_MODE_LSBD2
+ || current == RIG_MODE_LSBD3;
+ }
+
+ return 0;
+}
+
/**
* \brief set the mode of the target VFO
@@ -2906,30 +2928,30 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
vfo = vfo_fixup(rig, vfo, cachep->split);
- // if we're not asking for bandwidth and the mode is already set we don't need to do it
- // this will prevent flashing on some rigs like the TS-870
- if (caps->get_mode && width == RIG_PASSBAND_NOCHANGE)
+ // Resolve a generic packet request against a specific DATA profile before setting it.
+ if (caps->get_mode && (width == RIG_PASSBAND_NOCHANGE
+ || mode == RIG_MODE_PKTUSB || mode == RIG_MODE_PKTLSB)
+ && ((caps->targetable_vfo & RIG_TARGETABLE_MODE)
+ || vfo == rs->current_vfo))
{
rmode_t mode_curr;
pbwidth_t width_curr;
retcode = caps->get_mode(rig, vfo, &mode_curr, &width_curr);
- // For Icom rigs we may need to force the filter so we always set mode
-#if 0
- // This should not be necessary anymore with the new filter method for Icom rigs
- // Hopefully fixes issue https://github.com/Hamlib/Hamlib/issues/1580
- if (retcode == RIG_OK && mode == mode_curr
- && RIG_ICOM != RIG_BACKEND_NUM(rig->caps->rig_model))
-#else
- if (retcode == RIG_OK && mode == mode_curr)
-#endif
+ if (retcode == RIG_OK && mode_satisfies_request(mode, mode_curr))
{
- rig_debug(RIG_DEBUG_VERBOSE,
- "%s: mode already %s and bw change not requested\n", __func__,
- rig_strrmode(mode));
- ELAPSED2;
- LOCK(0);
- RETURNFUNC(RIG_OK);
+ mode = mode_curr;
+
+ if (width == RIG_PASSBAND_NOCHANGE)
+ {
+ rig_set_cache_mode(rig, vfo, mode_curr, width_curr);
+ rig_debug(RIG_DEBUG_VERBOSE,
+ "%s: mode already %s and bw change not requested\n", __func__,
+ rig_strrmode(mode_curr));
+ ELAPSED2;
+ LOCK(0);
+ RETURNFUNC(RIG_OK);
+ }
}
}
@@ -2958,7 +2980,7 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
rig_get_cache(rig, vfo, &cache_freq, &cache_ms_freq, &cache_mode,
&cache_ms_mode, &cache_width, &cache_ms_width);
- if (cache_mode == mode)
+ if (cache_mode == mode && width == RIG_PASSBAND_NOCHANGE)
{
rig_debug(RIG_DEBUG_TRACE, "%s: mode not changing, so ignoring\n",
__func__);
@@ -2991,7 +3013,37 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
RETURNFUNC(retcode);
}
- retcode = caps->set_mode(rig, vfo, mode, width);
+ int skip_set_mode = 0;
+
+ if (caps->get_mode && (width == RIG_PASSBAND_NOCHANGE
+ || mode == RIG_MODE_PKTUSB || mode == RIG_MODE_PKTLSB))
+ {
+ rmode_t mode_curr;
+ pbwidth_t width_curr;
+
+ retcode = caps->get_mode(rig, vfo, &mode_curr, &width_curr);
+
+ if (retcode == RIG_OK && mode_satisfies_request(mode, mode_curr))
+ {
+ mode = mode_curr;
+
+ if (width == RIG_PASSBAND_NOCHANGE)
+ {
+ width = width_curr;
+ skip_set_mode = 1;
+ }
+ }
+ else
+ {
+ retcode = RIG_OK;
+ }
+ }
+
+ if (retcode == RIG_OK && !skip_set_mode)
+ {
+ retcode = caps->set_mode(rig, vfo, mode, width);
+ }
+
/* try and revert even if we had an error above */
rc2 = caps->set_vfo(rig, curr_vfo);
@@ -5204,14 +5256,8 @@ int HAMLIB_API rig_set_split_mode(RIG *rig,
|| (rig->caps->rig_model == RIG_MODEL_NETRIGCTL)))
{
HAMLIB_TRACE;
- retcode = caps->set_mode(rig, tx_vfo, tx_mode, tx_width);
+ retcode = rig_set_mode(rig, tx_vfo, tx_mode, tx_width);
ELAPSED2;
-
- if (retcode == RIG_OK)
- {
- rig_set_cache_mode(rig, tx_vfo, tx_mode, tx_width);
- }
-
RETURNFUNC(retcode);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3b56486fa..e12eccda0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@ DIRECT_TESTS = \
testgs100 \
testicomts \
testnewcatset \
+ testmodecompat \
testthd7x \
testthd75emu
@@ -139,6 +140,7 @@ testid5100_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhaml
testicomfallback_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testctlparser_SOURCES = testctlparser.c $(RIGCOMMONSRC)
testctlparser_LDADD = $(PTHREAD_LIBS) $(READLINE_LIBS) $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
+testmodecompat_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testicomts_LDADD = $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testgeministatus_LDADD = $(PTHREAD_LIBS) $(top_builddir)/amplifiers/gemini/libhamlib-gemini.la $(LDADD)
testgs100_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/gomspace/libhamlib-gomspace.la $(LDADD)
diff --git a/tests/testmodecompat.c b/tests/testmodecompat.c
new file mode 100644
index 000000000..39a92d252
--- /dev/null
+++ b/tests/testmodecompat.c
@@ -0,0 +1,385 @@
+/*
+ * Hamlib generic and rig-specific mode compatibility tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <stdio.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/riglist.h"
+
+static struct rig_caps *dummy_caps;
+static int selected_only;
+static int query_error;
+static int write_error;
+static int restore_error;
+
+#define REQUIRE_OK(expression) do { \
+ int result = (expression); \
+ if (result != RIG_OK) { \
+ fprintf(stderr, "%s: %s: %s\n", __func__, #expression, rigerror(result)); \
+ return 1; \
+ } \
+} while (0)
+
+static int fixture_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode,
+ pbwidth_t *width)
+{
+ if (query_error) { return query_error; }
+
+ if (selected_only)
+ {
+ /* A non-targetable radio observes its selected VFO, not the argument. */
+ int retval = dummy_caps->get_vfo(rig, &vfo);
+
+ if (retval != RIG_OK) { return retval; }
+ }
+
+ return dummy_caps->get_mode(rig, vfo, mode, width);
+}
+
+static int fixture_set_mode(RIG *rig, vfo_t vfo, rmode_t mode,
+ pbwidth_t width)
+{
+ if (write_error) { return write_error; }
+
+ if (selected_only)
+ {
+ int retval = dummy_caps->get_vfo(rig, &vfo);
+
+ if (retval != RIG_OK) { return retval; }
+ }
+
+ return dummy_caps->set_mode(rig, vfo, mode, width);
+}
+
+static int fixture_set_vfo(RIG *rig, vfo_t vfo)
+{
+ if (restore_error && vfo == RIG_VFO_A) { return restore_error; }
+
+ return dummy_caps->set_vfo(rig, vfo);
+}
+
+static int expect_state(RIG *rig, const char *scenario, vfo_t vfo,
+ rmode_t expected_mode, pbwidth_t expected_width)
+{
+ rmode_t mode = RIG_MODE_NONE;
+ pbwidth_t width = RIG_PASSBAND_NORMAL;
+ int cached;
+
+ for (cached = 0; cached < 2; cached++)
+ {
+ int retval = cached ? rig_get_mode(rig, vfo, &mode, &width)
+ : dummy_caps->get_mode(rig, vfo, &mode, &width);
+
+ if (retval != RIG_OK || mode != expected_mode || width != expected_width)
+ {
+ fprintf(stderr, "%s: %s %s read returned %s, %s/%ld; expected %s/%ld\n",
+ scenario, rig_strvfo(vfo), cached ? "public" : "backend",
+ rigerror(retval), rig_strrmode(mode), (long)width,
+ rig_strrmode(expected_mode), (long)expected_width);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int expect_selected(RIG *rig, vfo_t expected)
+{
+ vfo_t actual;
+ REQUIRE_OK(dummy_caps->get_vfo(rig, &actual));
+
+ if (actual != expected)
+ {
+ fprintf(stderr, "%s: selected %s, expected %s\n", __func__,
+ rig_strvfo(actual), rig_strvfo(expected));
+ return 1;
+ }
+
+ return 0;
+}
+
+static int expect_error(const char *scenario, int actual, int expected)
+{
+ if (actual != expected)
+ {
+ fprintf(stderr, "%s: returned %s (%d), expected %s (%d)\n", scenario,
+ rigerror(actual), actual, rigerror(expected), expected);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int test_profiles(RIG *rig)
+{
+ static const struct
+ {
+ rmode_t profile;
+ rmode_t generic;
+ } modes[] =
+ {
+ {RIG_MODE_USBD1, RIG_MODE_PKTUSB},
+ {RIG_MODE_USBD2, RIG_MODE_PKTUSB},
+ {RIG_MODE_USBD3, RIG_MODE_PKTUSB},
+ {RIG_MODE_LSBD1, RIG_MODE_PKTLSB},
+ {RIG_MODE_LSBD2, RIG_MODE_PKTLSB},
+ {RIG_MODE_LSBD3, RIG_MODE_PKTLSB}
+ };
+ static const pbwidth_t widths[] =
+ {
+ RIG_PASSBAND_NOCHANGE, 2400, 1800
+ };
+ size_t i, j;
+
+ for (i = 0; i < sizeof(modes) / sizeof(modes[0]); i++)
+ {
+ for (j = 0; j < sizeof(widths) / sizeof(widths[0]); j++)
+ {
+ char scenario[96];
+ pbwidth_t expected = widths[j] == RIG_PASSBAND_NOCHANGE ? 2400 : widths[j];
+ snprintf(scenario, sizeof(scenario), "%s requested as %s, width %ld",
+ rig_strrmode(modes[i].profile), rig_strrmode(modes[i].generic),
+ (long)widths[j]);
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, modes[i].profile, 2400));
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, modes[i].generic, widths[j]));
+
+ if (expect_state(rig, scenario, RIG_VFO_A, modes[i].profile, expected))
+ {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int test_mode_changes(RIG *rig)
+{
+ static const struct
+ {
+ const char *name;
+ rmode_t initial;
+ rmode_t request;
+ } cases[] =
+ {
+ {"explicit USB profile", RIG_MODE_USBD2, RIG_MODE_USBD1},
+ {"explicit LSB profile", RIG_MODE_LSBD2, RIG_MODE_LSBD3},
+ {"USB entering packet mode", RIG_MODE_USB, RIG_MODE_PKTUSB},
+ {"LSB entering packet mode", RIG_MODE_LSB, RIG_MODE_PKTLSB},
+ {"LSB to USB", RIG_MODE_LSBD2, RIG_MODE_PKTUSB},
+ {"USB to LSB", RIG_MODE_USBD3, RIG_MODE_PKTLSB}
+ };
+ size_t i;
+
+ for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ {
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, cases[i].initial, 2400));
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, cases[i].request,
+ RIG_PASSBAND_NOCHANGE));
+
+ if (expect_state(rig, cases[i].name, RIG_VFO_A, cases[i].request, 2400))
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int test_front_panel_change(RIG *rig)
+{
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_USBD1, 2400));
+ /* A front-panel change bypasses the public setter and its cache updates. */
+ REQUIRE_OK(dummy_caps->set_mode(rig, RIG_VFO_A, RIG_MODE_USBD2, 1800));
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_PKTUSB,
+ RIG_PASSBAND_NOCHANGE));
+
+ if (expect_state(rig, "fresh profile query refreshes cache", RIG_VFO_A,
+ RIG_MODE_USBD2, 1800)) { return 1; }
+
+ REQUIRE_OK(dummy_caps->set_mode(rig, RIG_VFO_A, RIG_MODE_USBD2, 2100));
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_USBD2,
+ RIG_PASSBAND_NOCHANGE));
+ return expect_state(rig, "exact-mode query refreshes width cache", RIG_VFO_A,
+ RIG_MODE_USBD2, 2100);
+}
+
+static int test_split_fallback(RIG *rig)
+{
+ freq_t frequency;
+ REQUIRE_OK(rig_set_vfo(rig, RIG_VFO_A));
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_LSBD3, 1800));
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_B, RIG_MODE_USBD2, 2400));
+ REQUIRE_OK(rig_set_freq(rig, RIG_VFO_A, 7100000));
+ REQUIRE_OK(rig_set_freq(rig, RIG_VFO_B, 14074000));
+ REQUIRE_OK(rig_set_split_vfo(rig, RIG_VFO_A, RIG_SPLIT_ON, RIG_VFO_B));
+ REQUIRE_OK(rig_set_split_mode(rig, RIG_VFO_A, RIG_MODE_PKTUSB, 2100));
+
+ if (expect_state(rig, "split width preserves TX profile", RIG_VFO_B,
+ RIG_MODE_USBD2, 2100)) { return 1; }
+
+ REQUIRE_OK(rig_set_split_freq_mode(rig, RIG_VFO_A, 14075000, RIG_MODE_PKTUSB,
+ RIG_PASSBAND_NOCHANGE));
+
+ if (expect_state(rig, "combined request preserves TX profile", RIG_VFO_B,
+ RIG_MODE_USBD2, 2100)
+ || expect_state(rig, "split leaves RX mode intact", RIG_VFO_A,
+ RIG_MODE_LSBD3, 1800)
+ || expect_selected(rig, RIG_VFO_A)) { return 1; }
+
+ REQUIRE_OK(dummy_caps->get_freq(rig, RIG_VFO_B, &frequency));
+
+ if (frequency != 14075000)
+ {
+ fprintf(stderr, "combined request left TX frequency at %.0f\n", frequency);
+ return 1;
+ }
+
+ REQUIRE_OK(dummy_caps->get_freq(rig, RIG_VFO_A, &frequency));
+
+ if (frequency != 7100000)
+ {
+ fprintf(stderr, "split request changed RX frequency to %.0f\n", frequency);
+ return 1;
+ }
+
+ REQUIRE_OK(rig_set_split_vfo(rig, RIG_VFO_A, RIG_SPLIT_OFF, RIG_VFO_A));
+ return 0;
+}
+
+static int test_selected_vfo(RIG *rig, struct rig_caps *caps)
+{
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_USBD3, 1800));
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_B, RIG_MODE_USBD3, 2400));
+ selected_only = 1;
+ caps->targetable_vfo &= ~RIG_TARGETABLE_MODE;
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_B, RIG_MODE_PKTUSB,
+ RIG_PASSBAND_NOCHANGE));
+
+ if (expect_state(rig, "resolve against selected target", RIG_VFO_B,
+ RIG_MODE_USBD3, 2400)) { return 1; }
+
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_B, RIG_MODE_USBD3, 2100));
+
+ if (expect_state(rig, "noncurrent mode still accepts width", RIG_VFO_B,
+ RIG_MODE_USBD3, 2100)
+ || expect_state(rig, "noncurrent request preserves RX", RIG_VFO_A,
+ RIG_MODE_USBD3, 1800)
+ || expect_selected(rig, RIG_VFO_A)) { return 1; }
+
+ selected_only = 0;
+ caps->targetable_vfo = dummy_caps->targetable_vfo;
+ return 0;
+}
+
+static int test_errors(RIG *rig, struct rig_caps *caps)
+{
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_USBD2, 2400));
+ query_error = -RIG_EIO;
+
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_PKTUSB, 1800));
+
+ query_error = 0;
+
+ if (expect_state(rig, "query failure falls back to setter", RIG_VFO_A,
+ RIG_MODE_PKTUSB, 1800)) { return 1; }
+
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_USBD2, 2400));
+ write_error = -RIG_EIO;
+
+ if (expect_error("mode write failure", rig_set_mode(rig, RIG_VFO_A,
+ RIG_MODE_PKTUSB, 1800), -RIG_EIO)) { return 1; }
+
+ write_error = 0;
+
+ if (expect_state(rig, "failed write preserves radio and cache", RIG_VFO_A,
+ RIG_MODE_USBD2, 2400)) { return 1; }
+
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_B, RIG_MODE_LSBD2, 2400));
+ selected_only = 1;
+ caps->targetable_vfo &= ~RIG_TARGETABLE_MODE;
+ query_error = -RIG_EIO;
+
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_B, RIG_MODE_PKTLSB, 1800));
+
+ if (expect_state(rig, "noncurrent query falls back to setter", RIG_VFO_B,
+ RIG_MODE_PKTLSB, 1800)
+ || expect_selected(rig, RIG_VFO_A)) { return 1; }
+
+ query_error = 0;
+ write_error = -RIG_EIO;
+
+ if (expect_error("noncurrent write failure", rig_set_mode(rig, RIG_VFO_B,
+ RIG_MODE_PKTLSB, 1800), -RIG_EIO)
+ || expect_selected(rig, RIG_VFO_A)) { return 1; }
+
+ restore_error = -RIG_ETIMEOUT;
+
+ if (expect_error("operation error precedes restore error",
+ rig_set_mode(rig, RIG_VFO_B, RIG_MODE_PKTLSB, 1800),
+ -RIG_EIO)) { return 1; }
+
+ restore_error = 0;
+ REQUIRE_OK(dummy_caps->set_vfo(rig, RIG_VFO_A));
+ write_error = 0;
+ restore_error = -RIG_ETIMEOUT;
+
+ if (expect_error("restore failure after successful write",
+ rig_set_mode(rig, RIG_VFO_B, RIG_MODE_PKTLSB, 1800),
+ -RIG_ETIMEOUT)
+ || expect_selected(rig, RIG_VFO_B)) { return 1; }
+
+ restore_error = 0;
+ REQUIRE_OK(dummy_caps->set_vfo(rig, RIG_VFO_A));
+ selected_only = 0;
+ caps->targetable_vfo = dummy_caps->targetable_vfo;
+ REQUIRE_OK(rig_set_mode(rig, RIG_VFO_A, RIG_MODE_PKTUSB, 1800));
+ return expect_state(rig, "setter-only backend remains usable", RIG_VFO_A,
+ RIG_MODE_USBD2, 1800);
+}
+
+int main(void)
+{
+ RIG *rig = rig_init(RIG_MODEL_DUMMY);
+ struct rig_caps caps;
+ int failed = 0;
+
+ if (rig == NULL)
+ {
+ fprintf(stderr, "cannot initialize dummy rig\n");
+ return 1;
+ }
+
+ if (rig_open(rig) != RIG_OK)
+ {
+ fprintf(stderr, "cannot open dummy rig\n");
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ dummy_caps = rig->caps;
+ caps = *dummy_caps;
+ caps.get_mode = fixture_get_mode;
+ caps.set_mode = fixture_set_mode;
+ caps.set_vfo = fixture_set_vfo;
+ caps.set_split_mode = NULL;
+ caps.set_split_freq_mode = NULL;
+ rig->caps = ∩︀
+ rig_set_cache_timeout_ms(rig, HAMLIB_CACHE_ALL, 60000);
+
+ failed = test_profiles(rig) || test_mode_changes(rig)
+ || test_front_panel_change(rig) || test_split_fallback(rig)
+ || test_selected_vfo(rig, &caps) || test_errors(rig, &caps);
+
+ rig->caps = dummy_caps;
+ rig_close(rig);
+ rig_cleanup(rig);
+ return failed;
+}
-----------------------------------------------------------------------
Summary of changes:
rigs/kenwood/kenwood.c | 13 +-
rigs/kenwood/ts990s.c | 39 +++--
simulators/simts990.c | 10 +-
src/rig.c | 100 +++++++++----
tests/Makefile.am | 7 +-
tests/testmodecompat.c | 385 +++++++++++++++++++++++++++++++++++++++++++++++++
tests/testts990s.c | 330 ++++++++++++++++++++++++++++++++++++++++++
7 files changed, 821 insertions(+), 63 deletions(-)
create mode 100644 tests/testmodecompat.c
create mode 100644 tests/testts990s.c
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-10-19 17:55:17
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via a10d5bf7686415fe184121b6be1b6a911bc23207 (commit)
via 797f10e081d6de5cd02ae99b9cceb1608809e4b3 (commit)
from fe03d2d3ad5669894c8f594a58f001dc22e3f183 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a10d5bf7686415fe184121b6be1b6a911bc23207
Author: Miao Wang <sha...@gm...>
Date: Sat Sep 5 07:20:14 2026 +0800
ftx1: make rx frequency table continuous
(cherry picked from commit 5502e446bdb97b1973cba900243feedc3e9ae924)
diff --git a/rigs/yaesu/ftx1/ftx1.c b/rigs/yaesu/ftx1/ftx1.c
index ae64c584c..399e3ff15 100644
--- a/rigs/yaesu/ftx1/ftx1.c
+++ b/rigs/yaesu/ftx1/ftx1.c
@@ -1130,10 +1130,11 @@ struct rig_caps ftx1_caps = {
/* FTX-1 uses MAIN/SUB VFOs, not A/B. This ensures vfo_fixup() preserves
* MAIN as MAIN instead of converting to VFOA (which shares cache slot). */
.rx_range_list1 = {
- {kHz(30), MHz(56), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {kHz(30), MHz(75) - 1, FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(75), MHz(76) - 1, FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
{MHz(76), MHz(108), (FTX1_ALL_MODES & (~RIG_MODE_FM)) | RIG_MODE_WFM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(118), MHz(164), RIG_MODE_AM | RIG_MODE_FM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(430), MHz(470), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(108) + 1, MHz(174), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(400), MHz(470), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
RIG_FRNG_END,
},
.tx_range_list1 = {
@@ -1153,10 +1154,11 @@ struct rig_caps ftx1_caps = {
RIG_FRNG_END,
},
.rx_range_list2 = {
- {kHz(30), MHz(56), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {kHz(30), MHz(75) - 1, FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(75), MHz(76) - 1, FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
{MHz(76), MHz(108), (FTX1_ALL_MODES & (~RIG_MODE_FM)) | RIG_MODE_WFM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(118), MHz(164), RIG_MODE_AM | RIG_MODE_FM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(430), MHz(470), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(108) + 1, MHz(174), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(400), MHz(470), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
RIG_FRNG_END,
},
.tx_range_list2 = {
commit 797f10e081d6de5cd02ae99b9cceb1608809e4b3
Author: Miao Wang <sha...@gm...>
Date: Thu Jul 30 11:54:27 2026 +0800
ftx1: include WFM in the frequency table
This commit includes WFM (Wide Frequency Modulation) in the frequency
table for the Yaesu FTX-1 rig. The frequency ranges are updated to
reflect the correct modes for each range, ensuring that WFM is properly
recognized and handled by the rig's capabilities. This change also
adds filter bandwidth information for WFM.
(cherry picked from commit 1944a6736e2e7f31fead6a3bb2baf0fbbdf71b15)
diff --git a/rigs/yaesu/ftx1/ftx1.c b/rigs/yaesu/ftx1/ftx1.c
index efe96514a..ae64c584c 100644
--- a/rigs/yaesu/ftx1/ftx1.c
+++ b/rigs/yaesu/ftx1/ftx1.c
@@ -1110,52 +1110,69 @@ struct rig_caps ftx1_caps = {
{500, 503, RIG_MTYPE_MEM, NEWCAT_MEM_CAP}, /* 60m */
RIG_CHAN_END,
},
+#define FTX1_ALL_MODES ( \
+ RIG_MODE_LSB | \
+ RIG_MODE_USB | \
+ RIG_MODE_CW | \
+ RIG_MODE_FM | \
+ RIG_MODE_AM | \
+ RIG_MODE_RTTY | \
+ RIG_MODE_CWR | \
+ RIG_MODE_PKTLSB | \
+ RIG_MODE_RTTYR | \
+ RIG_MODE_PKTFM | \
+ RIG_MODE_FMN | \
+ RIG_MODE_PKTUSB | \
+ RIG_MODE_AMN | \
+ RIG_MODE_C4FM | \
+ RIG_MODE_PKTFMN | \
+ 0 )
/* FTX-1 uses MAIN/SUB VFOs, not A/B. This ensures vfo_fixup() preserves
* MAIN as MAIN instead of converting to VFOA (which shares cache slot). */
.rx_range_list1 = {
- {kHz(30), MHz(56), RIG_MODE_ALL, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(76), MHz(108), RIG_MODE_WFM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {kHz(30), MHz(56), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(76), MHz(108), (FTX1_ALL_MODES & (~RIG_MODE_FM)) | RIG_MODE_WFM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
{MHz(118), MHz(164), RIG_MODE_AM | RIG_MODE_FM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(430), MHz(470), RIG_MODE_ALL, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(430), MHz(470), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
RIG_FRNG_END,
},
.tx_range_list1 = {
- {kHz(1800), MHz(2) - 1, RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(3.5), MHz(4) - 1, RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(5.1675), MHz(5.4065), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1}, /* 60m */
- {MHz(7), MHz(7.3), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(10.1), MHz(10.15), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(14), MHz(14.35), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(18.068), MHz(18.168), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(21), MHz(21.45), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(24.89), MHz(24.99), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(28), MHz(29.7), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(50), MHz(54), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(144), MHz(148), RIG_MODE_ALL, 5000, 50000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(430), MHz(450), RIG_MODE_ALL, 5000, 20000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {kHz(1800), MHz(2) - 1, FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(3.5), MHz(4) - 1, FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(5.1675), MHz(5.4065), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1}, /* 60m */
+ {MHz(7), MHz(7.3), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(10.1), MHz(10.15), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(14), MHz(14.35), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(18.068), MHz(18.168), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(21), MHz(21.45), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(24.89), MHz(24.99), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(28), MHz(29.7), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(50), MHz(54), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(144), MHz(148), FTX1_ALL_MODES, 5000, 50000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(430), MHz(450), FTX1_ALL_MODES, 5000, 20000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
RIG_FRNG_END,
},
.rx_range_list2 = {
- {kHz(30), MHz(56), RIG_MODE_ALL, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(76), MHz(108), RIG_MODE_WFM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {kHz(30), MHz(56), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(76), MHz(108), (FTX1_ALL_MODES & (~RIG_MODE_FM)) | RIG_MODE_WFM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
{MHz(118), MHz(164), RIG_MODE_AM | RIG_MODE_FM, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(430), MHz(470), RIG_MODE_ALL, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(430), MHz(470), FTX1_ALL_MODES, -1, -1, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
RIG_FRNG_END,
},
.tx_range_list2 = {
- {kHz(1800), MHz(2) - 1, RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(3.5), MHz(4) - 1, RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(5.1675), MHz(5.4065), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1}, /* 60m */
- {MHz(7), MHz(7.3), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(10.1), MHz(10.15), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(14), MHz(14.35), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(18.068), MHz(18.168), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(21), MHz(21.45), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(24.89), MHz(24.99), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(28), MHz(29.7), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(50), MHz(54), RIG_MODE_ALL, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(144), MHz(148), RIG_MODE_ALL, 5000, 50000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
- {MHz(430), MHz(450), RIG_MODE_ALL, 5000, 20000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {kHz(1800), MHz(2) - 1, FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(3.5), MHz(4) - 1, FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(5.1675), MHz(5.4065), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1}, /* 60m */
+ {MHz(7), MHz(7.3), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(10.1), MHz(10.15), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(14), MHz(14.35), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(18.068), MHz(18.168), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(21), MHz(21.45), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(24.89), MHz(24.99), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(28), MHz(29.7), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(50), MHz(54), FTX1_ALL_MODES, 5000, 100000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(144), MHz(148), FTX1_ALL_MODES, 5000, 50000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
+ {MHz(430), MHz(450), FTX1_ALL_MODES, 5000, 20000, RIG_VFO_MAIN | RIG_VFO_SUB, RIG_ANT_1},
RIG_FRNG_END,
},
.tuning_steps = {
@@ -1203,6 +1220,7 @@ struct rig_caps ftx1_caps = {
/* FM modes */
{RIG_MODE_FM | RIG_MODE_PKTFM, Hz(12000)}, /* Normal FM */
{RIG_MODE_FM | RIG_MODE_PKTFM, Hz(9000)}, /* Narrow FM */
+ {RIG_MODE_WFM, kHz(200)}, /* Normal WFM */
/* Any mode, any filter */
{RIG_MODE_SSB | RIG_MODE_CW | RIG_MODE_CWR | RIG_MODE_RTTY | RIG_MODE_RTTYR | RIG_MODE_PKTLSB | RIG_MODE_PKTUSB, RIG_FLT_ANY},
RIG_FLT_END,
-----------------------------------------------------------------------
Summary of changes:
rigs/yaesu/ftx1/ftx1.c | 88 +++++++++++++++++++++++++++++++-------------------
1 file changed, 54 insertions(+), 34 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-10-19 17:54:36
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 58beb9ab5bb8cf9cb25070ac89f22b24f2df3f48 (commit)
via 1905c821e064efcbe3b05d0e26b05e0ef8f668a4 (commit)
via 03d1f0f4d4671cd0c1a3422b9eb2aeefb6356e92 (commit)
via c1bf015e3017c7fca3e44d63e2585b0aed67d86a (commit)
via afde935860a04de2928deff4149cc596efbc6417 (commit)
via 5093ef3dfada30c3cc4c0104c95f448f713fd550 (commit)
via 7eea39451aab2c552202911085d488052fe7f05d (commit)
via 112cfbdbcdd1acde3e657963da3c1bdca2974fe3 (commit)
via 9735544cbc521096a662402fc64b54c1a0e276a9 (commit)
via df8205028d305ba9ad6bead736ba9cb0364fb9d0 (commit)
via aff6e9407fdcbba49c8b6157782050bf2b88c70d (commit)
via 470d2e18caa320d1a2ea3cde329cf76990cf398d (commit)
via 57ad9edaf5c666aed842e89d953346ba13ea139b (commit)
via 396191159ed7d3a7a4ef54fe511fd226bc2dd20f (commit)
via 112304a66090bd7817126c0685a0b0c6ba3409cd (commit)
via 0eb6a03d6cffedbe523a5b15dca81e1b82e7b4d3 (commit)
via ffe697cbf83d2374815faaf9c111e9be10f31598 (commit)
via ac22476c09b7c704643786c23350fcd2ee02b87a (commit)
via 24817648c7d02c26e77de5d00d032ce9d8338e51 (commit)
via 6dcf5952c566bfec348b469a5665adee09013900 (commit)
via 5502e446bdb97b1973cba900243feedc3e9ae924 (commit)
from da925ab930bd11837b1eb9c3148d9a65a16ae9da (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 58beb9ab5bb8cf9cb25070ac89f22b24f2df3f48
Merge: 1905c821e 396191159
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 05:47:34 2026 -0400
Merge pull request #2160 from dchristle/fix/stream-resampler-ratio-bounds
fix(stream): bound resampler ratios and memory use
commit 1905c821e064efcbe3b05d0e26b05e0ef8f668a4
Merge: 03d1f0f4d 470d2e18c
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 05:47:29 2026 -0400
Merge pull request #2225 from dchristle/fix/net-rprt-response-index
fix(net): reject positive RPRT status codes
commit 03d1f0f4d4671cd0c1a3422b9eb2aeefb6356e92
Merge: c1bf015e3 ffe697cbf
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 05:47:24 2026 -0400
Merge pull request #2211 from woodard/strtok
Fix strtok thread-safety issues by using strtok_r instead of strtok
commit c1bf015e3017c7fca3e44d63e2585b0aed67d86a
Merge: afde93586 aff6e9407
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 05:47:19 2026 -0400
Merge pull request #2249 from NanamiKite/g90-rit-set
icom: add G90 RIT setting support
diff --cc tests/Makefile.am
index 263cb862e,d74710c95..b5ba02f8c
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@@ -141,9 -143,9 +143,10 @@@ testnewcatwidth_CFLAGS = $(AM_CFLAGS) $
testicomts_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testid5100_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testicomfallback_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
+ testg90rit_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testgeministatus_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/amplifiers/gemini
-testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu/ftx1
+testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu \
+ -I$(top_srcdir)/rigs/yaesu/ftx1
testft991idmeter_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu
testguohetec_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/guohetec
if TESTS_HAVE_LIBUSB
commit afde935860a04de2928deff4149cc596efbc6417
Merge: 5093ef3df 0eb6a03d6
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 05:47:15 2026 -0400
Merge pull request #2205 from dchristle/fix/rigctld-write-status-test-ipv6
fix(tests): remove write-status IPv6 dependency
commit 5093ef3dfada30c3cc4c0104c95f448f713fd550
Merge: 7eea39451 57ad9edaf
Author: Terrell Deppe <62b...@pr...>
Date: Mon Oct 19 05:47:06 2026 -0400
Merge pull request #2224 from dchristle/fix/test-tx-iq-acceptance-wait
test(rigctld): synchronize IQ TX packet acceptance
commit 7eea39451aab2c552202911085d488052fe7f05d
Merge: 112cfbdbc 5502e446b
Author: Terrell Deppe <62b...@pr...>
Date: Sun Oct 18 13:35:59 2026 -0500
Merge pull request #2196 from shankerwangmiao/pr-ftx1-freq-table
ftx1: make rx frequency table continuous
commit 112cfbdbcdd1acde3e657963da3c1bdca2974fe3
Merge: 9735544cb df8205028
Author: Terrell Deppe <62b...@pr...>
Date: Sun Oct 18 13:35:16 2026 -0500
Merge pull request #2197 from shankerwangmiao/pr-ftx1-tcsql
ftx1: align TONE/TSQL/CSQL functions with Hamlib semantics
commit 9735544cbc521096a662402fc64b54c1a0e276a9
Merge: da925ab93 112304a66
Author: Terrell Deppe <62b...@pr...>
Date: Sun Oct 18 13:34:43 2026 -0500
Merge pull request #2171 from dchristle/ftx1-clarifier-vfo-state
Will address the cache in a different PR.
diff --cc tests/testftx1parsers.c
index 68d3826c6,61928a104..6a4f7010d
--- a/tests/testftx1parsers.c
+++ b/tests/testftx1parsers.c
@@@ -175,12 -175,9 +205,13 @@@ int main(void
"EX0301051;", "EX030104;", "EX0301041junk;",
"EX0301042147483648;"
};
+ static const char *invalid_monitor[] =
+ {
+ "ML0002;", "ML2000;", "ML0000"
+ };
- if (expect_clar_state("CF00000000;", '0', RIG_OK, '0', '0') != 0
+ if (expect_clar_cache_isolated() != 0
+ || expect_clar_state("CF00000000;", '0', RIG_OK, '0', '0') != 0
|| expect_clar_state("CF00010000;", '0', RIG_OK, '1', '0') != 0
|| expect_clar_state("CF10010000;", '1', RIG_OK, '1', '0') != 0
|| expect_clar_offset("CF001+1234;", '0', RIG_OK, 1234) != 0
commit df8205028d305ba9ad6bead736ba9cb0364fb9d0
Author: Miao Wang <sha...@gm...>
Date: Sat Sep 5 05:50:49 2026 +0800
ftx1: align TONE/TSQL/CSQL functions with Hamlib semantics
In Hamlib, the TONE, TSQL, and CSQL functions are independent of each
other, where TONE is used to set the tx of CTCSS tone, TSQL is used to
set the rx of CTCSS tone, and CSQL is used to set the tx/rx of DCS tone.
In ftx1, however, there are only 4 choices for TONE/TSQL/CSQL, which are
totally disabled, TONE only, TONE+TSQL, and CSQL only.
To match the Hamlib semantics, this commit changes the getter and the
setter of TONE/TSQL/CSQL functions.
When CSQL is enabled, ftx1 will be set to CSQL only, and TONE/TSQL will
be disabled. When CSQL is disabled, and ftx1 is currently set to CSQL
only, the rig will be set to disabling all of TONE/TSQL/CSQL.
When TSQL is enabled, ftx1 will be set to TONE+TSQL, and CSQL will be
disabled. When TSQL is disabled, and ftx1 is currently set to TONE+TSQL,
the rig will be set to TONE only.
When TONE is enabled, and ftx1 is currently not in TONE only or
TONE+TSQL, the rig will be set to TONE only. When TONE is disabled, and
ftx1 is currently in TONE only or TONE+TSQL, the rig will be set to
disabling all of TONE/TSQL/CSQL.
With the above changes, disabling one of TONE/TSQL/CSQL when the
function being disabled is currently not enabled will not change the
rig's state, which is consistent with Hamlib semantics.
diff --git a/rigs/yaesu/ftx1/ftx1_func.c b/rigs/yaesu/ftx1/ftx1_func.c
index d19672325..9e323e85a 100644
--- a/rigs/yaesu/ftx1/ftx1_func.c
+++ b/rigs/yaesu/ftx1/ftx1_func.c
@@ -44,6 +44,7 @@
#include <stdlib.h>
#include <hamlib/rig.h>
+#include <assert.h>
#include "serial.h"
#include "misc.h"
#include "cal.h"
@@ -181,6 +182,43 @@ extern int ftx1_get_lock(RIG *rig, int *lock);
extern int ftx1_set_if_shift(RIG *rig, vfo_t vfo, int on, int shift_hz);
extern int ftx1_get_if_shift(RIG *rig, vfo_t vfo, int *on, int *shift_hz);
+static tone_t ftx1_next_ctcss_mode(tone_t current, setting_t func, int status)
+{
+ tone_t new = current;
+ switch (func) {
+ case RIG_FUNC_TONE:
+ if (status == 0) {
+ if (current == FTX1_CTCSS_MODE_ENC || current == FTX1_CTCSS_MODE_TSQ)
+ new = FTX1_CTCSS_MODE_OFF;
+ } else {
+ if (current != FTX1_CTCSS_MODE_ENC && current != FTX1_CTCSS_MODE_TSQ)
+ new = FTX1_CTCSS_MODE_ENC;
+ }
+ break;
+ case RIG_FUNC_TSQL:
+ if (status == 0) {
+ if (current == FTX1_CTCSS_MODE_TSQ)
+ new = FTX1_CTCSS_MODE_ENC;
+ } else {
+ if (current != FTX1_CTCSS_MODE_TSQ)
+ new = FTX1_CTCSS_MODE_TSQ;
+ }
+ break;
+ case RIG_FUNC_CSQL:
+ if (status == 0) {
+ if (current == FTX1_CTCSS_MODE_DCS)
+ new = FTX1_CTCSS_MODE_OFF;
+ } else {
+ if (current != FTX1_CTCSS_MODE_DCS)
+ new = FTX1_CTCSS_MODE_DCS;
+ }
+ break;
+ default:
+ assert(0 && "ftx1_next_ctcss_mode: Unknown function");
+ }
+ return new;
+}
+
/* Main override for set_func */
int ftx1_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
{
@@ -228,11 +266,23 @@ int ftx1_set_func(RIG *rig, vfo_t vfo, setting_t func, int status)
}
return ftx1_set_breakin(rig, 0);
case RIG_FUNC_TONE:
- return ftx1_set_ctcss_mode(rig, status ? FTX1_CTCSS_MODE_ENC : FTX1_CTCSS_MODE_OFF);
case RIG_FUNC_TSQL:
- return ftx1_set_ctcss_mode(rig, status ? FTX1_CTCSS_MODE_TSQ : FTX1_CTCSS_MODE_OFF);
case RIG_FUNC_CSQL:
- return ftx1_set_ctcss_mode(rig, status ? FTX1_CTCSS_MODE_DCS : FTX1_CTCSS_MODE_OFF);
+ {
+ tone_t ctcss_mode;
+ tone_t new_mode;
+ int ret;
+
+ /* Switch to VFO mode before reading the CTCSS mode
+ * so that our read-modify-write operations happen on the same target. */
+ ftx1_ensure_vfo_mode(rig);
+ ret = ftx1_get_ctcss_mode(rig, &ctcss_mode);
+ if (ret != RIG_OK) return ret;
+ new_mode = ftx1_next_ctcss_mode(ctcss_mode, func, status);
+ if (new_mode != ctcss_mode)
+ return ftx1_set_ctcss_mode(rig, new_mode);
+ return RIG_OK; /* No change needed */
+ }
case RIG_FUNC_RIT:
/* FTX-1: Setting RX CLAR to 0 disables it; to enable, use set_rit with offset */
if (!status) return ftx1_set_rx_clar(rig, vfo, 0);
@@ -305,7 +355,7 @@ int ftx1_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status)
{
tone_t ctcss_mode;
ret = ftx1_get_ctcss_mode(rig, &ctcss_mode);
- if (ret == RIG_OK) *status = (ctcss_mode == FTX1_CTCSS_MODE_ENC) ? 1 : 0;
+ if (ret == RIG_OK) *status = (ctcss_mode == FTX1_CTCSS_MODE_ENC || ctcss_mode == FTX1_CTCSS_MODE_TSQ) ? 1 : 0;
return ret;
}
case RIG_FUNC_TSQL:
commit aff6e9407fdcbba49c8b6157782050bf2b88c70d
Author: Nanami Kite <135...@qq...>
Date: Tue Oct 6 15:00:13 2026 +0800
icom: add G90 RIT setting support
diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c
index f7714f254..b07e6a179 100644
--- a/rigs/icom/xiegu.c
+++ b/rigs/icom/xiegu.c
@@ -140,6 +140,9 @@
#define G90_LEVELS (RIG_LEVEL_PREAMP|RIG_LEVEL_ATT|RIG_LEVEL_AGC|RIG_LEVEL_CWPITCH|RIG_LEVEL_RFPOWER|RIG_LEVEL_KEYSPD|RIG_LEVEL_SQL|RIG_LEVEL_RAWSTR|RIG_LEVEL_AF|RIG_LEVEL_RF|RIG_LEVEL_SWR)
+/* Radioddity G90 User Manual V5, p.35: RIT adjustment is +/-500 Hz. */
+#define G90_MAX_RIT Hz(500)
+
#define G90_MEM_CAP { \
.freq = 1, \
.mode = 1, \
@@ -162,6 +165,7 @@
static int x108g_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt);
static int g90_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val);
static int g90_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val);
+static int g90_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit);
static const char *g90_get_info(RIG *rig);
static int x108g_set_split_vfo(RIG *rig, vfo_t vfo, split_t split,
vfo_t tx_vfo);
@@ -944,7 +948,7 @@ struct rig_caps g90_caps =
.dcs_list = common_dcs_list,
.preamp = { 10, RIG_DBLST_END, }, /* FIXME: TBC it's a guess*/
.attenuator = { 12, RIG_DBLST_END, },
- .max_rit = Hz(9999),
+ .max_rit = G90_MAX_RIT,
.max_xit = Hz(9999),
.max_ifshift = Hz(0), /* TODO */
.vfo_ops = X108G_VFO_OPS,
@@ -1037,6 +1041,11 @@ struct rig_caps g90_caps =
.get_ant = NULL,
.get_info = g90_get_info,
+ .set_rit = g90_set_rit,
+ /* Distinct displayed -101/-111 Hz both returned FF FF 01 in testing.
+ * Negative GET is lossy; do not advertise a getter or cache SET as GET.
+ */
+ .get_rit = NULL,
.decode_event = icom_decode_event,
.set_level = g90_set_level,
.get_level = g90_get_level,
@@ -1284,6 +1293,44 @@ int x108g_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt)
return RIG_OK;
}
+/* Standard BCD magnitude and sign for SET, independent of negative GET. */
+static int g90_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit)
+{
+ unsigned char payload[3], ackbuf[MAXFRAMELEN];
+ int ack_len = sizeof(ackbuf), retval;
+
+ /* CI-V 21 00 targets the selected VFO; the frontend handles selection.
+ * Check bounds before negating, including for LONG_MIN inputs.
+ */
+ (void) vfo;
+
+ if (rit < -G90_MAX_RIT || rit > G90_MAX_RIT)
+ {
+ return -RIG_EINVAL;
+ }
+
+ to_bcd(payload, rit < 0 ? -rit : rit, 4);
+ payload[2] = rit < 0 ? 1 : 0;
+
+ /* Zero disables RIT; nonzero enables it on the tested G90.
+ * Do not send a separate 21 01 command or query the lossy 21 00 GET.
+ */
+ retval = icom_transaction(rig, C_CTL_RIT, S_RIT_FREQ,
+ payload, sizeof(payload), ackbuf, &ack_len);
+
+ if (retval != RIG_OK)
+ {
+ return retval;
+ }
+
+ if (ack_len != 1 || ackbuf[0] != ACK)
+ {
+ return -RIG_EPROTO;
+ }
+
+ return RIG_OK;
+}
+
/*
* The stock G90 firmware (v1.81) does not implement C_CTL_ATT the Icom way.
*
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 92128ff9d..d74710c95 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,6 +28,7 @@ DIRECT_TESTS = \
testft991idmeter \
testelecraftvfo \
testftx1parsers \
+ testg90rit \
testgeministatus \
testgs100 \
testguohetec \
@@ -130,6 +131,7 @@ testcachethread_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testcachevfo_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testctlparser_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgeministatus_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testg90rit_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testgs100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testguohetec_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testid5100_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
@@ -141,6 +143,7 @@ testnewcatwidth_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testicomts_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testid5100_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testicomfallback_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
+testg90rit_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testgeministatus_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/amplifiers/gemini
testftx1parsers_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu/ftx1
testft991idmeter_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/yaesu
@@ -188,6 +191,7 @@ testmodecompat_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la $(LDADD)
testicomts_LDADD = $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testid5100_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testicomfallback_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
+testg90rit_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/icom/libhamlib-icom.la $(LDADD)
testgeministatus_LDADD = $(PTHREAD_LIBS) $(top_builddir)/amplifiers/gemini/libhamlib-gemini.la $(LDADD)
testgs100_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/gomspace/libhamlib-gomspace.la $(LDADD)
testelecraftvfo_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood/libhamlib-kenwood.la $(LDADD)
diff --git a/tests/testg90rit.c b/tests/testg90rit.c
new file mode 100644
index 000000000..77d175bf7
--- /dev/null
+++ b/tests/testg90rit.c
@@ -0,0 +1,397 @@
+/*
+ * G90 RIT SET regression tests. No physical radio is needed.
+ * Socket setup follows testicomfallback.c.
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include <limits.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef _WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
+#include <sys/select.h>
+#include <unistd.h>
+#endif
+
+#include "hamlib/rig.h"
+#include "hamlib/port.h"
+#include "hamlib/rig_state.h"
+#include "icom.h"
+#include "misc.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+extern struct rig_caps g90_caps;
+extern struct rig_caps ic7100_caps;
+extern struct rig_caps x6100_caps;
+
+struct exchange
+{
+ shortfreq_t offset;
+ unsigned char request[16];
+ size_t request_len;
+ unsigned char response[16];
+ size_t response_len;
+ int expected_retval;
+};
+
+struct peer_case
+{
+ const struct exchange *exchanges;
+ size_t count;
+ int fd;
+ int status;
+};
+
+static int close_socket(int fd)
+{
+#ifdef _WIN32
+ return closesocket(fd);
+#else
+ return close(fd);
+#endif
+}
+
+static int read_socket(int fd, void *buffer, size_t length)
+{
+#ifdef _WIN32
+ return recv(fd, buffer, (int) length, 0);
+#else
+ return (int) read(fd, buffer, length);
+#endif
+}
+
+static int write_socket(int fd, const void *buffer, size_t length)
+{
+#ifdef _WIN32
+ return send(fd, buffer, (int) length, 0);
+#else
+ return (int) write(fd, buffer, length);
+#endif
+}
+
+static int open_connection(int sockets[2])
+{
+#ifdef _WIN32
+ SOCKET listener, client, peer;
+ struct sockaddr_in address;
+ int length = sizeof(address);
+
+ listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ if (listener == INVALID_SOCKET) { return -1; }
+
+ memset(&address, 0, sizeof(address));
+ address.sin_family = AF_INET;
+ address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ if (bind(listener, (struct sockaddr *) &address, sizeof(address)) != 0
+ || listen(listener, 1) != 0
+ || getsockname(listener, (struct sockaddr *) &address,
+ &length) != 0)
+ {
+ closesocket(listener);
+ return -1;
+ }
+
+ client = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ if (client == INVALID_SOCKET
+ || connect(client, (struct sockaddr *) &address,
+ sizeof(address)) != 0)
+ {
+ if (client != INVALID_SOCKET) { closesocket(client); }
+
+ closesocket(listener);
+ return -1;
+ }
+
+ peer = accept(listener, NULL, NULL);
+ closesocket(listener);
+
+ if (peer == INVALID_SOCKET)
+ {
+ closesocket(client);
+ return -1;
+ }
+
+ sockets[0] = (int) client;
+ sockets[1] = (int) peer;
+ return 0;
+#else
+ return socketpair(AF_UNIX, SOCK_STREAM, 0, sockets);
+#endif
+}
+
+static int has_input(int fd)
+{
+ fd_set readable;
+ struct timeval timeout = { 0, 0 };
+
+ FD_ZERO(&readable);
+ FD_SET(fd, &readable);
+ return select(fd + 1, &readable, NULL, NULL, &timeout);
+}
+
+static void *run_peer(void *arg)
+{
+ struct peer_case *test = arg;
+ size_t i;
+
+ test->status = -1;
+
+ for (i = 0; i < test->count; i++)
+ {
+ const struct exchange *exchange = &test->exchanges[i];
+ unsigned char request[16];
+ size_t received = 0, sent = 0;
+
+ do
+ {
+ if (received == sizeof(request)
+ || read_socket(test->fd, request + received, 1) != 1)
+ {
+ return NULL;
+ }
+ }
+ while (request[received++] != 0xfd);
+
+ if (received != exchange->request_len
+ || memcmp(request, exchange->request, received) != 0)
+ {
+ fprintf(stderr, "unexpected RIT request at step %zu\n", i);
+ return NULL;
+ }
+
+ while (sent < exchange->response_len)
+ {
+ int count = write_socket(test->fd, exchange->response + sent,
+ exchange->response_len - sent);
+
+ if (count <= 0) { return NULL; }
+
+ sent += (size_t) count;
+ }
+ }
+
+ test->status = 0;
+ return NULL;
+}
+
+static RIG *prepare_rig(int fd)
+{
+ RIG *rig = rig_init(RIG_MODEL_G90);
+
+ if (rig == NULL) { return NULL; }
+
+ STATE(rig)->comm_state = 1;
+ rig_set_current_vfo_state(rig, RIG_VFO_A);
+ RIGPORT(rig)->fd = fd;
+ RIGPORT(rig)->type.rig = RIG_PORT_NETWORK;
+ RIGPORT(rig)->retry = 0;
+ RIGPORT(rig)->timeout = 100;
+ ((struct icom_priv_data *) STATE(rig)->priv)->serial_USB_echo_off = 1;
+ return rig;
+}
+
+static void cleanup_rig(RIG *rig, int sockets[2])
+{
+ STATE(rig)->comm_state = 0;
+ RIGPORT(rig)->fd = -1;
+ close_socket(sockets[0]);
+ close_socket(sockets[1]);
+ rig_cleanup(rig);
+}
+
+static int run_case(const char *name, const struct exchange *exchanges,
+ size_t count)
+{
+ int sockets[2], status = 0;
+ pthread_t thread;
+ struct peer_case test = { exchanges, count, -1, -1 };
+ RIG *rig;
+ size_t i;
+
+ if (open_connection(sockets) != 0) { return 1; }
+
+ rig = prepare_rig(sockets[0]);
+
+ if (rig == NULL)
+ {
+ close_socket(sockets[0]);
+ close_socket(sockets[1]);
+ return 1;
+ }
+
+ test.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &test) != 0)
+ {
+ status = 1;
+ }
+ else
+ {
+ shortfreq_t readback = 123;
+
+ for (i = 0; i < count; i++)
+ {
+ int retval = rig_set_rit(rig, RIG_VFO_CURR,
+ exchanges[i].offset);
+
+ if (retval != exchanges[i].expected_retval)
+ {
+ fprintf(stderr, "%s step %zu: expected %d, got %d\n",
+ name, i, exchanges[i].expected_retval, retval);
+ status = 1;
+ }
+ }
+
+ /* Even after a successful SET, do not expose cached pseudo-GET. */
+ if (rig_get_rit(rig, RIG_VFO_CURR, &readback) != -RIG_ENAVAIL
+ || readback != 123)
+ {
+ status = 1;
+ }
+
+ /* The SET path must not send any extra GET or ON/OFF command. */
+ if (has_input(sockets[1]) != 0) { status = 1; }
+
+#ifdef _WIN32
+ shutdown(sockets[0], SD_BOTH);
+#else
+ shutdown(sockets[0], SHUT_RDWR);
+#endif
+ pthread_join(thread, NULL);
+ if (test.status != 0) { status = 1; }
+ }
+
+ cleanup_rig(rig, sockets);
+ printf("%s: %s\n", name, status ? "FAIL" : "PASS");
+ return status;
+}
+
+static int check_bounds_and_capabilities(void)
+{
+ const shortfreq_t invalid[] = { -501, 501, -9999, 9999,
+ LONG_MIN, LONG_MAX };
+ int sockets[2], status = 0;
+ shortfreq_t readback = 123;
+ RIG *rig;
+ size_t i;
+
+ if (open_connection(sockets) != 0) { return 1; }
+
+ rig = prepare_rig(sockets[0]);
+
+ if (rig == NULL)
+ {
+ close_socket(sockets[0]);
+ close_socket(sockets[1]);
+ return 1;
+ }
+
+ if (rig->caps->set_rit == NULL || rig->caps->get_rit != NULL
+ || rig->caps->max_rit != 500 || rig->caps->set_xit != NULL
+ || rig->caps->get_xit != NULL || ic7100_caps.max_rit != 9999
+ || x6100_caps.max_rit != 9999
+ || rig_get_rit(rig, RIG_VFO_CURR, &readback) != -RIG_ENAVAIL
+ || readback != 123)
+ {
+ status = 1;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(invalid); i++)
+ {
+ if (rig_set_rit(rig, RIG_VFO_CURR, invalid[i]) != -RIG_EINVAL)
+ {
+ status = 1;
+ }
+ }
+
+ if (has_input(sockets[1]) != 0) { status = 1; }
+
+ cleanup_rig(rig, sockets);
+ printf("bounds, unavailable GET, no I/O or XIT: %s\n",
+ status ? "FAIL" : "PASS");
+ return status;
+}
+
+#define SET_RIT(value, lo, hi, sign) \
+ { value, \
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, lo, hi, sign, 0xfd }, 10, \
+ { 0xfe, 0xfe, 0xe0, 0x88, 0xfb, 0xfd }, 6, RIG_OK }
+
+int main(void)
+{
+ int status = 0;
+ size_t i;
+ const struct exchange valid[] =
+ {
+ SET_RIT(0, 0x00, 0x00, 0),
+ SET_RIT(100, 0x00, 0x01, 0),
+ SET_RIT(-100, 0x00, 0x01, 1),
+ SET_RIT(101, 0x01, 0x01, 0),
+ SET_RIT(-101, 0x01, 0x01, 1),
+ SET_RIT(111, 0x11, 0x01, 0),
+ SET_RIT(-111, 0x11, 0x01, 1),
+ SET_RIT(1, 0x01, 0x00, 0),
+ SET_RIT(-1, 0x01, 0x00, 1),
+ SET_RIT(-50, 0x50, 0x00, 1),
+ SET_RIT(-110, 0x10, 0x01, 1),
+ SET_RIT(-200, 0x00, 0x02, 1),
+ SET_RIT(500, 0x00, 0x05, 0),
+ SET_RIT(-500, 0x00, 0x05, 1),
+ SET_RIT(0, 0x00, 0x00, 0)
+ };
+ const struct exchange failures[] =
+ {
+ { 100,
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, 0, 1, 0, 0xfd }, 10,
+ { 0xfe, 0xfe, 0xe0, 0x88, 0xfa, 0xfd }, 6, -RIG_ERJCTED },
+ { 100,
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, 0, 1, 0, 0xfd }, 10,
+ { 0xfe, 0xfe, 0xe0, 0x88, 0xfb, 0, 0xfd }, 7, -RIG_EPROTO },
+ { 100,
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, 0, 1, 0, 0xfd }, 10,
+ { 0xfe, 0xfe, 0xe0, 0x88, 0x00, 0xfd }, 6, -RIG_EPROTO },
+ { 100,
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, 0, 1, 0, 0xfd }, 10,
+ { 0xfe, 0xfe, 0xe0, 0x88, 0xfc }, 5, -RIG_BUSBUSY },
+ { 100,
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, 0, 1, 0, 0xfd }, 10,
+ { 0xfe, 0xfe, 0xe0, 0x88, 0x21, 0, 0, 1, 0, 0xfd }, 10,
+ -RIG_EPROTO },
+ { 100,
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, 0, 1, 0, 0xfd }, 10,
+ { 0xfe, 0xfe, 0xe0, 0x88, 0xfd }, 5, -RIG_EPROTO },
+ { 100,
+ { 0xfe, 0xfe, 0x88, 0xe0, 0x21, 0x00, 0, 1, 0, 0xfd }, 10,
+ { 0 }, 0, -RIG_ETIMEOUT }
+ };
+#ifdef _WIN32
+ WSADATA wsa_data;
+
+ if (WSAStartup(MAKEWORD(2, 2), &wsa_data) != 0) { return 1; }
+#endif
+ rig_set_debug(RIG_DEBUG_NONE);
+ rig_register(&g90_caps);
+ rig_register(&ic7100_caps);
+ status |= check_bounds_and_capabilities();
+ status |= run_case("RIT signed BCD SET/ACK and zero reset",
+ valid, ARRAY_SIZE(valid));
+
+ for (i = 0; i < ARRAY_SIZE(failures); i++)
+ {
+ status |= run_case("RIT NAK/malformed ACK/collision/timeout",
+ &failures[i], 1);
+ }
+
+#ifdef _WIN32
+ WSACleanup();
+#endif
+ return status;
+}
commit 470d2e18caa320d1a2ea3cde329cf76990cf398d
Author: David Christle <dch...@us...>
Date: Mon Sep 21 22:46:42 2026 +0200
fix(net): reject positive RPRT status codes
Treat RPRT responses as status lines instead of data lengths.
Reject malformed positive values before callers use response indexes.
Cover both clients with a socket-backed regression test.
diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c
index ba83176ef..3906528c0 100644
--- a/rigs/dummy/netrigctl.c
+++ b/rigs/dummy/netrigctl.c
@@ -54,6 +54,29 @@ struct netrigctl_priv_data
vfo_t tx_vfo;
};
+static int parse_rprt_status(const char *response)
+{
+ const char *token = response + strlen(NETRIGCTL_RET);
+ char *end;
+ long status;
+
+ errno = 0;
+ status = strtol(token, &end, 10);
+
+ while (*end == ' ' || *end == '\t' || *end == '\r' || *end == '\n')
+ {
+ ++end;
+ }
+
+ if (errno == ERANGE || end == token || *end != '\0'
+ || status > 0 || status < INT_MIN || status > INT_MAX)
+ {
+ return -RIG_EPROTO;
+ }
+
+ return (int)status;
+}
+
static int parse_protocol_uint(const char *token, unsigned int *value)
{
char *end;
@@ -117,7 +140,7 @@ static int netrigctl_transaction(RIG *rig, char *cmd, int len, char *buf)
if (strncmp(buf, NETRIGCTL_RET, strlen(NETRIGCTL_RET)) == 0)
{
- return atoi(buf + strlen(NETRIGCTL_RET));
+ return parse_rprt_status(buf);
}
return ret;
diff --git a/rigs/dummy/quisk.c b/rigs/dummy/quisk.c
index bf2895b97..2b6bdcd8e 100644
--- a/rigs/dummy/quisk.c
+++ b/rigs/dummy/quisk.c
@@ -154,6 +154,29 @@ struct quisk_priv_data
vfo_t tx_vfo;
};
+static int parse_rprt_status(const char *response)
+{
+ const char *token = response + strlen(NETRIGCTL_RET);
+ char *end;
+ long status;
+
+ errno = 0;
+ status = strtol(token, &end, 10);
+
+ while (*end == ' ' || *end == '\t' || *end == '\r' || *end == '\n')
+ {
+ ++end;
+ }
+
+ if (errno == ERANGE || end == token || *end != '\0'
+ || status > 0 || status < INT_MIN || status > INT_MAX)
+ {
+ return -RIG_EPROTO;
+ }
+
+ return (int)status;
+}
+
#if 0
int quisk_get_vfo_mode(RIG *rig)
@@ -194,7 +217,7 @@ static int quisk_transaction(RIG *rig, char *cmd, int len, char *buf)
if (strncmp(buf, NETRIGCTL_RET, strlen(NETRIGCTL_RET)) == 0)
{
- return atoi(buf + strlen(NETRIGCTL_RET));
+ return parse_rprt_status(buf);
}
return ret;
diff --git a/tests/testnetrigctl.c b/tests/testnetrigctl.c
index 6a9f556db..416e841ed 100644
--- a/tests/testnetrigctl.c
+++ b/tests/testnetrigctl.c
@@ -41,7 +41,8 @@ enum wire_operation
WIRE_SET_PARM,
WIRE_GET_PARM,
WIRE_MW2POWER,
- WIRE_POWER2MW
+ WIRE_POWER2MW,
+ WIRE_GET_INFO
};
struct wire_case
@@ -271,6 +272,9 @@ static int invoke_wire_operation(RIG *rig, enum wire_operation operation,
RIG_MODE_USB);
*result = mwpower;
return status;
+
+ case WIRE_GET_INFO:
+ return rig->caps->get_info(rig) == NULL ? -RIG_EPROTO : RIG_OK;
}
return -RIG_EINVAL;
@@ -443,6 +447,8 @@ static int test_client_parsing(void)
"nan\n", -RIG_EPROTO, 0.0, 0 },
{ "reject milliwatt suffix", WIRE_POWER2MW,
"\\power2mW 0.500 7177000 USB\n", "25000junk\n",
+ -RIG_EPROTO, 0.0, 0 },
+ { "reject positive RPRT status", WIRE_GET_INFO, "_\n", "RPRT 1\n",
-RIG_EPROTO, 0.0, 0 }
};
const rig_model_t models[] = { RIG_MODEL_NETRIGCTL, RIG_MODEL_QUISK };
commit 57ad9edaf5c666aed842e89d953346ba13ea139b
Author: David Christle <dch...@us...>
Date: Mon Sep 21 21:49:23 2026 +0200
test(rigctld): synchronize IQ TX packet acceptance
Wait for both counters before asserting that the IQ TX feeder completed
all three packets.
diff --git a/test/test_rigctld_commands.c b/test/test_rigctld_commands.c
index 9db93fabc..6dd280051 100644
--- a/test/test_rigctld_commands.c
+++ b/test/test_rigctld_commands.c
@@ -2843,13 +2843,16 @@ void test_tx_iq_data_accepted(void)
int client_sock = create_client_udp_socket();
TEST_CHECK(client_sock >= 0);
- /* Build and send 3 IQ data packets (payload must be 4-byte aligned) */
+ const int expected_packets = 3;
+ const uint64_t expected_frames = (uint64_t)expected_packets * 240;
+
+ /* Build and send IQ data packets (payload must be 4-byte aligned). */
unsigned char payload[960];
memset(payload, 0xCD, sizeof(payload));
int i;
- for (i = 0; i < 3; i++)
+ for (i = 0; i < expected_packets; i++)
{
unsigned char pkt[2048];
size_t pkt_len = build_data_packet(pkt, RIG_STREAM_TYPE_IQ_TX,
@@ -2861,17 +2864,22 @@ void test_tx_iq_data_accepted(void)
TEST_MSG("failed to send TX IQ packet %d", i);
}
- /* The dummy TX scheduler consumes the ring concurrently, so verify
- * arrival via the producer position: 3 packets x 240 IQ pairs. */
- WAIT_UNTIL(rig_stream_get_samples_written(s->backend_stream) >= 3 * 240);
- TEST_CHECK(rig_stream_get_samples_written(s->backend_stream) >= 3 * 240);
+ /* The dummy TX scheduler consumes the ring concurrently. Wait for both
+ * the accepted packet count and producer position so the checks describe
+ * one completed feeder state. */
+ WAIT_UNTIL(s->packet_count >= expected_packets
+ && rig_stream_get_samples_written(s->backend_stream)
+ >= expected_frames);
+ TEST_CHECK(rig_stream_get_samples_written(s->backend_stream)
+ >= expected_frames);
TEST_MSG("TX feeder wrote %llu frames to backend ringbuf",
(unsigned long long)
rig_stream_get_samples_written(s->backend_stream));
- /* Verify feeder processed all 3 packets */
- TEST_CHECK(s->packet_count >= 3);
- TEST_MSG("packet_count: got %d, expected >= 3", s->packet_count);
+ /* Verify feeder processed the expected packets. */
+ TEST_CHECK(s->packet_count >= expected_packets);
+ TEST_MSG("packet_count: got %d, expected >= %d",
+ s->packet_count, expected_packets);
close(client_sock);
commit 396191159ed7d3a7a4ef54fe511fd226bc2dd20f
Author: David Christle <dch...@us...>
Date: Mon Aug 17 11:49:04 2026 -0700
fix(stream): bound resampler ratios and scratch allocation
Reject stream rate pairs outside libsamplerate's single-stage limits
before conversion setup, and cap each fixed scratch buffer at 16 MiB. Keep
capability advertisement consistent and treat overwrite-ring delivery as full
producer consumption.
diff --git a/HAMLIB_STREAMING.md b/HAMLIB_STREAMING.md
index f8a573883..b4ea64c62 100644
--- a/HAMLIB_STREAMING.md
+++ b/HAMLIB_STREAMING.md
@@ -303,10 +303,12 @@ Limits: `HAMLIB_MAX_STREAM_RATES = 32`,
effective rates equal the native rates): the native rates, plus the
curated standard rates {8000, 11025, 16000, 22050, 24000, 44100,
48000, 96000, 192000}, plus every exact integer division (factors
- 2…10) of each native rate. Deduplicated, ascending, bounded by the
- largest native rate: audio up to and including it, I/Q strictly below
- it (an I/Q stream's sample rate is its represented bandwidth, so
- upsampling past the hardware cannot create information).
+ 2…10) of each native rate. Candidates outside libsamplerate's
+ single-stage 1/256…256 conversion-ratio range are omitted. The result
+ is deduplicated, ascending, and bounded by the largest native rate:
+ audio up to and including it, I/Q strictly below it (an I/Q stream's
+ sample rate is its represented bandwidth, so upsampling past the
+ hardware cannot create information).
- **Channels:** the declared list is exact — the effective list equals
the native list, and unlisted counts are never invented (a device may
genuinely support only very specific counts, which is exactly what the
@@ -349,14 +351,16 @@ the server advertises already reflects whether its resampler is present.
**Acceptance at `rig_stream_open()` is by rule, not by list membership** —
the advertised effective list is for discoverability. Any rate at or
-below the largest native rate is accepted when the resampler is built,
-listed or not (e.g. an arbitrary 22 222 Hz). The frontend resolves the
-request to a native source: format prefers the float format (lossless
-staging), then S16, then the lowest declared bit; the rate source is the
-smallest native rate ≥ the request; and a conversion pipeline is
-installed between that source and the stream. Requests beyond the rules
-(a rate above the largest native rate, an I/Q format on an audio stream,
-more channels than the mapping allows) fail with `-RIG_EINVAL`.
+below the largest native rate is accepted when the resampler is built and
+the selected native/requested pair is within libsamplerate's single-stage
+1/256…256 ratio range, listed or not (e.g. an arbitrary 22 222 Hz). The
+frontend resolves the request to a native source: format prefers the float
+format (lossless staging), then S16, then the lowest declared bit; the rate
+source is the smallest native rate ≥ the request; and a conversion pipeline
+is installed between that source and the stream. Requests beyond the rules
+(an unsupported conversion ratio, a rate above the largest native rate, an
+I/Q format on an audio stream, or more channels than the mapping allows)
+fail with `-RIG_EINVAL`.
`rig_stream_get_conversions()` reports the installed stages
(`RIG_STREAM_CONV_FORMAT/RATE/CHANNELS`, 0 = native stream). The same
@@ -562,10 +566,10 @@ Semantics:
(§3.3), resolves the native source the backend will run at, and installs
any conversion pipeline. It additionally rejects a non-positive
`sample_rate` or `channels`, an unknown stream type, a `struct_size` of 0,
- and exhaustion of either the caps `max_streams` limit or the
- `HAMLIB_MAX_STREAMS` slots for that type — all with `-RIG_EINVAL`. A
- request whose conversion stages intersect `require_native` fails with
- `-RIG_ENAVAIL`.
+ a rate conversion outside libsamplerate's supported ratio, and exhaustion
+ of either the caps `max_streams` limit or the `HAMLIB_MAX_STREAMS` slots for
+ that type — all with `-RIG_EINVAL`. A request whose conversion stages
+ intersect `require_native` fails with `-RIG_ENAVAIL`.
- **close** unregisters the stream, wakes any blocked reader or
write-status waiter, then waits for every `rig_stream_*` call already in
flight on that stream to return before the handle is torn down. A
diff --git a/src/stream.c b/src/stream.c
index e04f42bee..9ffa113ff 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -331,11 +331,6 @@ static const int stream_curated_rates[] =
#define STREAM_MAX_DECIM_FACTOR 10
#endif
-static int stream_type_is_iq_type(rig_stream_type_t type)
-{
- return type == RIG_STREAM_TYPE_IQ_RX || type == RIG_STREAM_TYPE_IQ_TX;
-}
-
#ifdef HAVE_SAMPLERATE
/* Append rate to a 0-terminated list if absent and there is room; the
* caller adds in priority order, so on overflow the least useful entries
@@ -374,6 +369,8 @@ static int stream_rate_list_max(const int *rates)
return max;
}
+static int stream_rate_source(const int *native_rates, int requested_rate);
+
#endif /* HAVE_SAMPLERATE */
/* Ascending int comparator for caps list sorting (rates and channel
@@ -425,7 +422,7 @@ static void chan_list_add(int *list, int count)
static void stream_derive_caps(struct rig_stream_caps *dst,
const struct rig_stream_caps *src)
{
- int is_iq = stream_type_is_iq_type(src->type);
+ int is_iq = stream_type_is_iq(src->type);
*dst = *src;
@@ -493,11 +490,11 @@ static void stream_derive_caps(struct rig_stream_caps *dst,
}
#ifdef HAVE_SAMPLERATE
- /* Rates (resampler built): native, then curated standards, then
- * integer divisions of each native rate (factors 2..10, exact results
- * only) — in that priority order, deduplicated, ascending. This list
- * is discoverability; acceptance at open is rule-based. Audio may go
- * up to the largest native rate, I/Q only strictly below it
+ /* Rates (resampler built): native, then reachable curated standards,
+ * then integer divisions of each native rate (factors 2..10, exact
+ * results only) — in that priority order, deduplicated, ascending. This
+ * list is discoverability; acceptance at open is rule-based. Audio may
+ * go up to the largest native rate, I/Q only strictly below it
* (downward-only: the I/Q sample rate is the represented bandwidth).
* Without the resampler the effective rates equal the native rates. */
{
@@ -507,8 +504,11 @@ static void stream_derive_caps(struct rig_stream_caps *dst,
for (int i = 0; stream_curated_rates[i] != 0; i++)
{
int r = stream_curated_rates[i];
+ int native_rate = stream_rate_source(src->sample_rates, r);
- if ((is_iq && r < native_max) || (!is_iq && r <= native_max))
+ if (((is_iq && r < native_max) || (!is_iq && r <= native_max))
+ && native_rate > 0
+ && stream_conv_rate_supported(native_rate, r))
{
stream_rate_list_add(dst->sample_rates, r);
}
@@ -815,23 +815,20 @@ static int caps_rate_native(const struct rig_stream_caps *caps, int rate)
return rate_in_list(caps->sample_rates, rate);
}
-
#ifdef HAVE_SAMPLERATE
-/* Smallest native rate >= rate (the cheapest downconversion source), or 0
- * when the request exceeds every native rate — the effective set is
- * bounded by the largest native rate for audio and I/Q alike. */
-static int caps_rate_source(const struct rig_stream_caps *caps, int rate)
+/* Smallest native rate at or above the requested rate, or zero. */
+static int stream_rate_source(const int *native_rates, int requested_rate)
{
int best = 0;
for (int i = 0; i < HAMLIB_MAX_STREAM_RATES
- && caps->sample_rates[i] != 0; i++)
+ && native_rates[i] != 0; i++)
{
- int r = caps->sample_rates[i];
+ int rate = native_rates[i];
- if (r >= rate && (best == 0 || r < best))
+ if (rate >= requested_rate && (best == 0 || rate < best))
{
- best = r;
+ best = rate;
}
}
@@ -839,6 +836,7 @@ static int caps_rate_source(const struct rig_stream_caps *caps, int rate)
}
#endif
+
/* Resolution for a pre-derived caps entry (native_formats set — a relaying
* backend such as netrigctl): conversion happens on the far side of the
* backend (the server), so the local backend runs at the requested config
@@ -938,8 +936,7 @@ static int resolve_stream_source(const struct rig_stream_config *config,
struct rig_stream_config *backend_cfg,
int *conversions)
{
- int is_iq = config->type == RIG_STREAM_TYPE_IQ_RX
- || config->type == RIG_STREAM_TYPE_IQ_TX;
+ int is_iq = stream_type_is_iq(config->type);
rig_stream_format_t family = is_iq ? STREAM_IQ_FORMAT_MASK
: STREAM_PCM_FORMAT_MASK;
int conv = RIG_STREAM_CONV_NONE;
@@ -1046,13 +1043,14 @@ static int resolve_stream_source(const struct rig_stream_config *config,
return RIG_OK; /* conv stays RIG_STREAM_CONV_NONE */
}
- /* Rate: native, or (resampler built) any rate up to the largest
- * native rate — audio and I/Q alike; I/Q upsampling beyond the
- * hardware is impossible by this bound (sample rate = bandwidth). */
+ /* Rate: native, or any rate that a single resampler stage can convert
+ * against the smallest suitable native source. I/Q remains bounded by
+ * the native bandwidth just like audio is bounded by its largest rate. */
if (!caps_rate_native(caps, config->sample_rate))
{
#ifdef HAVE_SAMPLERATE
- int src_rate = caps_rate_source(caps, config->sample_rate);
+ int src_rate = stream_rate_source(caps->sample_rates,
+ config->sample_rate);
if (src_rate <= 0)
{
@@ -1062,6 +1060,15 @@ static int resolve_stream_source(const struct rig_stream_config *config,
return -RIG_EINVAL;
}
+ if (!stream_conv_rate_supported(src_rate, config->sample_rate))
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: rate conversion %d <-> %d exceeds the "
+ "resampler ratio limit\n",
+ __func__, config->sample_rate, src_rate);
+ return -RIG_EINVAL;
+ }
+
backend_cfg->sample_rate = src_rate;
conv |= RIG_STREAM_CONV_RATE;
#else
@@ -1304,10 +1311,9 @@ int HAMLIB_API rig_stream_open(RIG *rig,
s->backend_config = backend_cfg;
s->conversions = conversions;
- /* The ring buffer holds the CONSUMER's format: the client's request on
+ /* The ring buffer holds the consumer's format: the client's request on
* RX, the backend-native side on TX. */
- int is_rx = config->type == RIG_STREAM_TYPE_AUDIO_RX
- || config->type == RIG_STREAM_TYPE_IQ_RX;
+ int is_rx = stream_type_is_rx(config->type);
const struct rig_stream_config *ring_cfg = is_rx ? config
: &s->backend_config;
@@ -1336,40 +1342,28 @@ int HAMLIB_API rig_stream_open(RIG *rig,
* reported), so no local pipeline is installed for it. */
if (conversions != RIG_STREAM_CONV_NONE && found_caps->native_formats == 0)
{
- int is_iq = config->type == RIG_STREAM_TYPE_IQ_RX
- || config->type == RIG_STREAM_TYPE_IQ_TX;
+ int is_iq = stream_type_is_iq(config->type);
int quality = stream_resample_quality(rig);
- int conv_ret;
-
- if (is_rx)
- {
- conv_ret = stream_conv_init(&s->conv,
- backend_cfg.format,
- backend_cfg.sample_rate,
- backend_cfg.channels,
- config->format,
- config->sample_rate,
- config->channels, is_iq, quality);
- }
- else
- {
- conv_ret = stream_conv_init(&s->conv,
- config->format,
- config->sample_rate,
- config->channels,
- backend_cfg.format,
- backend_cfg.sample_rate,
- backend_cfg.channels, is_iq, quality);
- }
-
- if (conv_ret != 0)
+ const struct rig_stream_config *src_cfg = is_rx ? &backend_cfg
+ : config;
+ const struct rig_stream_config *dst_cfg = is_rx ? config
+ : &backend_cfg;
+ int conv_ret = stream_conv_init(&s->conv,
+ src_cfg->format,
+ src_cfg->sample_rate,
+ src_cfg->channels,
+ dst_cfg->format,
+ dst_cfg->sample_rate,
+ dst_cfg->channels, is_iq, quality);
+
+ if (conv_ret != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR,
"%s: conversion pipeline init failed (0x%x)\n",
__func__, conversions);
free(s);
pthread_mutex_unlock(&ss->stream_mutex);
- return -RIG_ENOMEM;
+ return conv_ret;
}
}
@@ -1456,7 +1450,11 @@ static size_t conv_ring_sink(void *ctx, const void *buf, size_t len)
{
struct rig_stream *s = ctx;
- return stream_ringbuf_write(&s->ringbuf, buf, len);
+ stream_ringbuf_write(&s->ringbuf, buf, len);
+
+ /* The overwrite ring consumes the full producer span even when only its
+ * last capacity bytes remain readable. */
+ return len;
}
size_t stream_backend_write(struct rig_stream *stream, const void *buf,
diff --git a/src/stream_convert.c b/src/stream_convert.c
index 1002ecc73..9d0e10544 100644
--- a/src/stream_convert.c
+++ b/src/stream_convert.c
@@ -31,11 +31,16 @@
#endif
#include "stream_convert.h"
+#include <limits.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_SAMPLERATE
+#include <samplerate.h>
+#endif
+
/* The sample converters dereference multi-byte samples in host byte order and
* perform no byte swapping, so the little-endian wire payload is only correct
* on a little-endian host. Fail the build loudly on a big-endian host rather
@@ -734,8 +739,26 @@ int rig_stream_convert_channels(const void *src, int src_channels,
/* rig_stream_resample — sample rate conversion (requires libsamplerate) */
/* ------------------------------------------------------------------ */
+int stream_conv_rate_supported(int src_rate, int dst_rate)
+{
+ if (src_rate <= 0 || dst_rate <= 0)
+ {
+ return 0;
+ }
+
+ if (src_rate == dst_rate)
+ {
+ return 1;
+ }
+
+#ifdef HAVE_SAMPLERATE
+ return src_is_valid_ratio((double)dst_rate / (double)src_rate);
+#else
+ return 0;
+#endif
+}
+
#ifdef HAVE_SAMPLERATE
-#include <samplerate.h>
/* Map Hamlib quality constants to libsamplerate converter types. */
static int resample_converter_type(int quality)
@@ -803,9 +826,9 @@ int rig_stream_resample(const float *src, int src_rate,
/* Persistent per-stream conversion context (stream_conv) */
/* ------------------------------------------------------------------ */
-/* Frames processed per pipeline pass; bounds the scratch buffers while
- * arbitrarily large writes stream through in slices. */
+/* Frames processed per pipeline pass; bounds scratch working-set growth. */
#define STREAM_CONV_CHUNK_FRAMES 1024
+#define STREAM_CONV_MAX_SCRATCH_BYTES (16U * 1024U * 1024U)
struct stream_conv
{
@@ -875,9 +898,16 @@ int stream_conv_init(struct stream_conv **out,
rig_stream_format_t dst_fmt, int dst_rate, int dst_ch,
int is_iq, int quality)
{
- if (!out || src_rate <= 0 || dst_rate <= 0 || src_ch <= 0 || dst_ch <= 0)
+ if (!out)
{
- return -1;
+ return -RIG_EINVAL;
+ }
+
+ *out = NULL;
+
+ if (src_rate <= 0 || dst_rate <= 0 || src_ch <= 0 || dst_ch <= 0)
+ {
+ return -RIG_EINVAL;
}
int src_ss = rig_stream_format_sample_size(src_fmt);
@@ -885,23 +915,25 @@ int stream_conv_init(struct stream_conv **out,
if (src_ss <= 0 || dst_ss <= 0)
{
- return -1; /* compressed/unknown formats are not convertible */
+ return -RIG_EINVAL;
}
-#ifndef HAVE_SAMPLERATE
-
- if (src_rate != dst_rate)
+ if (!stream_conv_rate_supported(src_rate, dst_rate))
{
- return -1; /* rate conversion requires libsamplerate */
+ return -RIG_EINVAL;
}
-#endif
+ if (src_ch > INT_MAX / src_ss || dst_ch > INT_MAX / dst_ss
+ || (is_iq && src_rate != dst_rate && dst_ch > INT_MAX / 2))
+ {
+ return -RIG_EINVAL;
+ }
struct stream_conv *c = calloc(1, sizeof(*c));
if (!c)
{
- return -1;
+ return -RIG_ENOMEM;
}
c->src_fmt = src_fmt;
@@ -916,14 +948,10 @@ int stream_conv_init(struct stream_conv **out,
c->pivot_fmt = is_iq ? RIG_STREAM_FORMAT_IQ_CF32
: RIG_STREAM_FORMAT_PCM_F32;
- /* Output frames a full input chunk can produce (+margin for the
- * resampler's internal state). Source selection keeps dst <= src rate,
- * but size for either direction to stay safe. */
double ratio = (double)dst_rate / (double)src_rate;
c->out_cap_frames = (size_t)((double)STREAM_CONV_CHUNK_FRAMES
* (ratio > 1.0 ? ratio : 1.0)) + 64;
- /* Scratch sized for the widest stage across the whole pipeline. */
int pivot_ss = rig_stream_format_sample_size(c->pivot_fmt);
size_t worst_frame = (size_t)src_ch * src_ss;
@@ -942,16 +970,23 @@ int stream_conv_init(struct stream_conv **out,
worst_frame = c->dst_frame_bytes;
}
- size_t worst_frames = STREAM_CONV_CHUNK_FRAMES > c->out_cap_frames
- ? STREAM_CONV_CHUNK_FRAMES : c->out_cap_frames;
- c->buf_bytes = worst_frames * worst_frame;
+ size_t scratch_frames = STREAM_CONV_CHUNK_FRAMES > c->out_cap_frames
+ ? STREAM_CONV_CHUNK_FRAMES : c->out_cap_frames;
+
+ if (worst_frame > STREAM_CONV_MAX_SCRATCH_BYTES / scratch_frames)
+ {
+ free(c);
+ return -RIG_EINVAL;
+ }
+
+ c->buf_bytes = scratch_frames * worst_frame;
c->buf_a = malloc(c->buf_bytes);
c->buf_b = malloc(c->buf_bytes);
if (!c->buf_a || !c->buf_b)
{
stream_conv_free(c);
- return -1;
+ return -RIG_ENOMEM;
}
#ifdef HAVE_SAMPLERATE
@@ -970,14 +1005,14 @@ int stream_conv_init(struct stream_conv **out,
if (!c->src_state)
{
stream_conv_free(c);
- return -1;
+ return -RIG_EINVAL;
}
}
#endif
*out = c;
- return 0;
+ return RIG_OK;
}
void stream_conv_free(struct stream_conv *c)
@@ -1143,5 +1178,3 @@ ssize_t stream_conv_process(struct stream_conv *c, const void *buf,
return (ssize_t)(consumed_frames * c->src_frame_bytes);
}
-
-
diff --git a/src/stream_convert.h b/src/stream_convert.h
index 1bd07f989..5a8446759 100644
--- a/src/stream_convert.h
+++ b/src/stream_convert.h
@@ -73,6 +73,9 @@ int rig_stream_resample(const float *src, int src_rate,
size_t src_samples, size_t *dst_samples,
int channels, int quality);
+/* Return non-zero when one conversion stage can serve the rate pair. */
+int stream_conv_rate_supported(int src_rate, int dst_rate);
+
/* --- Persistent per-stream conversion context (frontend data path) --- */
/* Opaque context carrying the stream's conversion pipeline state: scratch
@@ -92,8 +95,9 @@ typedef size_t (*stream_conv_sink_fn)(void *ctx, const void *buf,
* channels when narrowing from more; I/Q only selects a subset. Rate
* conversion requires libsamplerate (fails otherwise) and resamples I/Q
* as interleaved I/Q float pairs; quality is the RIG_RESAMPLE_* sinc
- * converter to use (ignored without rate conversion). Returns 0 and
- * sets *out, or -1. */
+ * converter to use (ignored without rate conversion). Returns RIG_OK and
+ * sets *out, -RIG_EINVAL for unsupported geometry or resampler setup, or
+ * -RIG_ENOMEM when Hamlib scratch allocation fails. */
int stream_conv_init(struct stream_conv **out,
rig_stream_format_t src_fmt, int src_rate, int src_ch,
rig_stream_format_t dst_fmt, int dst_rate, int dst_ch,
diff --git a/test/test_stream_api.c b/test/test_stream_api.c
index e82bc11f6..81fcf8864 100644
--- a/test/test_stream_api.c
+++ b/test/test_stream_api.c
@@ -315,6 +315,47 @@ static struct rig_caps stub_caps_codec_stream =
.stream_close = stub_stream_close,
};
+/* A native rate chosen so 8000 Hz is just outside libsamplerate's
+ * single-stage ratio range while nearby standard and arbitrary rates remain
+ * reachable. Both directions exercise RX downsampling and TX upsampling. */
+static const struct rig_stream_caps stub_ratio_stream_caps[] =
+{
+ {
+ .type = RIG_STREAM_TYPE_AUDIO_RX,
+ .formats = RIG_STREAM_FORMAT_PCM_F32,
+ .sample_rates = { 2056000, 0 },
+ .channels = { 1, 0 },
+ .max_streams = 1,
+ },
+ {
+ .type = RIG_STREAM_TYPE_AUDIO_TX,
+ .formats = RIG_STREAM_FORMAT_PCM_F32,
+ .sample_rates = { 2056000, 0 },
+ .channels = { 1, 0 },
+ .max_streams = 1,
+ },
+ { 0 }
+};
+
+static struct rig_caps stub_caps_ratio_stream =
+{
+ .rig_model = 7,
+ .model_name = "Stub Ratio Stream",
+ .mfg_name = "Test",
+ .version = "1.0",
+ .status = RIG_STATUS_STABLE,
+ .rig_type = RIG_TYPE_TRANSCEIVER,
+ .port_type = RIG_PORT_NONE,
+ .timeout = 1000,
+ .retry = 0,
+ .stream_caps = stub_ratio_stream_caps,
+ .rig_init = stub_rig_init,
+ .rig_cleanup = stub_rig_cleanup,
+ .rig_open = stub_rig_open,
+ .rig_close = stub_rig_close,
+ .stream_open = stub_stream_open,
+ .stream_close = stub_stream_close,
+};
/* Helper: set up a RIG with the given caps, call rig_open-equivalent init. */
static RIG *setup_rig(struct rig_caps *caps)
@@ -497,6 +538,87 @@ void test_caps_derived_rates(void)
teardown_rig(rig);
}
+void test_rate_ratio_limits(void)
+{
+ RIG *rig = setup_rig(&stub_caps_ratio_stream);
+ TEST_ASSERT(rig != NULL);
+
+ const struct rig_stream_caps *rx = rig_stream_caps_at(rig, 0);
+ const struct rig_stream_caps *tx = rig_stream_caps_at(rig, 1);
+ TEST_ASSERT(rx != NULL && tx != NULL);
+
+#ifdef HAVE_SAMPLERATE
+ TEST_CHECK(!rate_in_list(rx->sample_rates, 8000));
+ TEST_CHECK(!rate_in_list(tx->sample_rates, 8000));
+ TEST_CHECK(rate_in_list(rx->sample_rates, 11025));
+ TEST_CHECK(rate_in_list(tx->sample_rates, 11025));
+#endif
+
+ struct rig_stream_config *cfg = rig_stream_config_alloc();
+ TEST_ASSERT(cfg != NULL);
+ cfg->format = RIG_STREAM_FORMAT_PCM_F32;
+ cfg->channels = 1;
+ cfg->buffer_bytes = 64;
+
+ static const rig_stream_type_t types[] =
+ {
+ RIG_STREAM_TYPE_AUDIO_RX,
+ RIG_STREAM_TYPE_AUDIO_TX,
+ };
+ static const struct
+ {
+ int rate;
+ int expected;
+ } cases[] =
+ {
+ { 8000, -RIG_EINVAL },
+#ifdef HAVE_SAMPLERATE
+ { 22222, RIG_OK },
+#else
+ { 22222, -RIG_EINVAL },
+#endif
+ };
+
+ for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ {
+ cfg->sample_rate = cases[i].rate;
+
+ for (size_t j = 0; j < sizeof(types) / sizeof(types[0]); j++)
+ {
+ rig_stream_t *stream = NULL;
+ cfg->type = types[j];
+ int ret = rig_stream_open(rig, cfg, &stream);
+ TEST_CHECK(ret == cases[i].expected);
+
+ if (ret == RIG_OK)
+ {
+ TEST_ASSERT(stream != NULL);
+ TEST_CHECK(rig_stream_get_conversions(stream)
+ == RIG_STREAM_CONV_RATE);
+
+ if (types[j] == RIG_STREAM_TYPE_AUDIO_TX)
+ {
+ float input[1024] = { 0 };
+ size_t written = 0;
+ TEST_CHECK(rig_stream_write(rig, stream, input,
+ sizeof(input), &written,
+ 0, NULL) == RIG_OK);
+ TEST_CHECK(written == sizeof(input));
+ }
+
+ rig_stream_close(rig, stream);
+ }
+ else
+ {
+ TEST_CHECK(stream == NULL);
+ }
+ }
+ }
+
+ rig_stream_config_free(cfg);
+ teardown_rig(rig);
+}
+
void test_caps_derived_channels(void)
{
RIG *rig = setup_rig(&stub_caps_mono_stream);
@@ -2426,6 +2548,7 @@ TEST_LIST =
{ "get_stream_caps", test_get_stream_caps },
{ "caps_derived_formats", test_caps_derived_formats },
{ "caps_derived_rates", test_caps_derived_rates },
+ { "rate_ratio_limits", test_rate_ratio_limits },
{ "caps_derived_channels", test_caps_derived_channels },
{ "channel_list_exact", test_channel_list_exact },
{ "codec_format_native_only", test_codec_format_native_only },
diff --git a/test/test_stream_convert.c b/test/test_stream_convert.c
index 3286424bb..f6eba97de 100644
--- a/test/test_stream_convert.c
+++ b/test/test_stream_convert.c
@@ -29,6 +29,7 @@
#include "acutest.h"
#include "test_debug.h"
#include "stream_convert.h"
+#include <stdint.h>
#include <string.h>
#include <math.h>
@@ -698,6 +699,104 @@ void test_resample_quality_levels(void)
}
}
+#ifdef HAVE_SAMPLERATE
+struct counting_sink
+{
+ size_t bytes;
+};
+
+static size_t count_converted_bytes(void *ctx, const void *buf, size_t len)
+{
+ struct counting_sink *sink = ctx;
+ (void)buf;
+ sink->bytes += len;
+ return len;
+}
+#endif
+
+void test_conversion_context_rate_bounds(void)
+{
+ struct stream_conv *conv = NULL;
+
+ TEST_CHECK(stream_conv_rate_supported(48000, 48000));
+ TEST_CHECK(!stream_conv_rate_supported(0, 48000));
+ TEST_CHECK(!stream_conv_rate_supported(48000, 0));
+
+#ifdef HAVE_SAMPLERATE
+ TEST_CHECK(stream_conv_rate_supported(1, 256));
+ TEST_CHEC...
[truncated message content] |
|
From: n0nb <n0...@us...> - 2026-10-15 02:25:17
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via da925ab930bd11837b1eb9c3148d9a65a16ae9da (commit)
via 8f17dcb932ba1d2a12062d605c03892a8a8cca6f (commit)
from 470518f35cfd6f3b1ce12a8d111e4bb2c1efd26d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit da925ab930bd11837b1eb9c3148d9a65a16ae9da
Merge: 470518f35 8f17dcb93
Author: Terrell Deppe <62b...@pr...>
Date: Wed Oct 14 09:47:57 2026 -0500
Merge pull request #2168 from shankerwangmiao/pr-ftx-1-tuner
ftx1: assume tuner status on when using ATAS antenna
commit 8f17dcb932ba1d2a12062d605c03892a8a8cca6f
Author: Miao Wang <sha...@gm...>
Date: Fri Aug 21 21:47:06 2026 +0800
ftx1: assume tuner status on when using ATAS antenna
When using ATAS antenna, there is no such concept of enabling or
disabling the tuner. We can assume that the tuner is always on when
using ATAS antenna. The user will see the tuner status as "on" and is
thus able to trigger the tune process.
diff --git a/rigs/yaesu/ftx1/ftx1_tx.c b/rigs/yaesu/ftx1/ftx1_tx.c
index b5d512c80..3dcf822ba 100644
--- a/rigs/yaesu/ftx1/ftx1_tx.c
+++ b/rigs/yaesu/ftx1/ftx1_tx.c
@@ -251,6 +251,16 @@ int ftx1_get_tuner(RIG *rig, int *mode)
rig_debug(RIG_DEBUG_VERBOSE, "%s\n", __func__);
+ int type;
+ if (ftx1_get_effective_tuner_type(rig, &type) == RIG_OK &&
+ type == FTX1_TUNER_TYPE_ATAS)
+ {
+ rig_debug(RIG_DEBUG_VERBOSE, "%s: ATAS tuner type detected, always "
+ "reporting tuner active\n", __func__);
+ *mode = 1;
+ return RIG_OK;
+ }
+
SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "AC;");
ret = newcat_get_cmd(rig);
-----------------------------------------------------------------------
Summary of changes:
rigs/yaesu/ftx1/ftx1_tx.c | 10 ++++++++++
1 file changed, 10 insertions(+)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-10-12 13:15:04
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via fe03d2d3ad5669894c8f594a58f001dc22e3f183 (commit)
via 1103f9bd91ad59f336eaa7757cb1455efe14abc0 (commit)
from 0aa18bfd11b9ad38a5b8fb47634c13141f1ea1ec (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit fe03d2d3ad5669894c8f594a58f001dc22e3f183
Merge: 0aa18bfd1 1103f9bd9
Author: dforsi <iu...@gm...>
Date: Sun Oct 11 23:29:44 2026 +0200
Merge pull request #2250 from dforsi/Hamlib-4.7
Merge pull request #2170 from dchristle/ftx1-monitor-safety
commit 1103f9bd91ad59f336eaa7757cb1455efe14abc0
Author: dforsi <iu...@gm...>
Date: Sun Oct 11 19:28:45 2026 +0200
Merge pull request #2170 from dchristle/ftx1-monitor-safety
fix(ftx1): prevent monitor control from keying transmitter
(cherry picked from commit 470518f35cfd6f3b1ce12a8d111e4bb2c1efd26d)
diff --git a/rigs/yaesu/ftx1/ftx1.h b/rigs/yaesu/ftx1/ftx1.h
index a17c04851..a7b14ef21 100644
--- a/rigs/yaesu/ftx1/ftx1.h
+++ b/rigs/yaesu/ftx1/ftx1.h
@@ -272,6 +272,8 @@ extern int ftx1_parse_clar_offset(const char *response, char vfo,
shortfreq_t *offset);
extern int ftx1_parse_ex_menu_response(const char *response, int group,
int section, int item, int *value);
+extern int ftx1_parse_monitor_response(const char *response, int selector,
+ int *level);
extern int ftx1_parse_smeter_response(const char *response, int p1, int *value);
#endif /* _FTX1_H */
diff --git a/rigs/yaesu/ftx1/ftx1_audio.c b/rigs/yaesu/ftx1/ftx1_audio.c
index 8cdba7019..ecf0c29c6 100644
--- a/rigs/yaesu/ftx1/ftx1_audio.c
+++ b/rigs/yaesu/ftx1/ftx1_audio.c
@@ -9,7 +9,7 @@
* RG P1 P2P3P4; - RF Gain (P1=VFO 0/1, P2-P4=000-255)
* MG P1P2P3; - Mic Gain (000-100)
* GT P1P2P3P4; - AGC Time Constant (0000-6000ms or code)
- * ML P1P2P3; - Monitor Level (000-100)
+ * ML P1P2P3; - Monitor on/off or level (selector-dependent)
* SM P1; - S-Meter Read (P1=0 main, returns 0000-0255)
* RM P1; - Meter Read (1=Main S, 2=Sub S, 3=COMP, 4=ALC, 5=PO, 6=SWR, 7=ID, 8=VDD)
* PC P1 P2P2P2; - Power Control (P1=1 field head, P1=2 SPA-1)
@@ -177,6 +177,33 @@ int ftx1_get_mic_gain(RIG *rig, float *val)
return RIG_OK;
}
+int ftx1_parse_monitor_response(const char *response, int selector, int *level)
+{
+ int parsed_level;
+
+ if (selector < 0 || selector > 1 || strlen(response) != 7
+ || response[0] != 'M' || response[1] != 'L'
+ || response[2] != '0' + selector
+ || response[3] < '0' || response[3] > '9'
+ || response[4] < '0' || response[4] > '9'
+ || response[5] < '0' || response[5] > '9'
+ || response[6] != ';')
+ {
+ return -RIG_EPROTO;
+ }
+
+ parsed_level = (response[3] - '0') * 100 + (response[4] - '0') * 10
+ + response[5] - '0';
+
+ if ((selector == 0 && parsed_level > 1) || parsed_level > 100)
+ {
+ return -RIG_EPROTO;
+ }
+
+ *level = parsed_level;
+ return RIG_OK;
+}
+
int ftx1_parse_smeter_response(const char *response, int p1, int *val)
{
int level;
@@ -585,46 +612,46 @@ int ftx1_get_vox_delay(RIG *rig, int *tenths)
}
/*
- * ftx1_set_monitor_level - Set Monitor Level (ML P1 P2P3P4;)
- * CAT command: ML P1 P2P3P4; (P1=VFO 0/1, P2-P4=000-100)
+ * ftx1_set_monitor_level - Set Monitor Level (ML 1 P2P3P4;)
+ * The FTX-1's ML selector 1 controls the global monitor level; it is not a
+ * VFO selector.
*/
int ftx1_set_monitor_level(RIG *rig, vfo_t vfo, float val)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int p1 = ftx1_vfo_to_p1(rig, vfo);
int level = (int)(val * 100);
- rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d val=%f\n", __func__,
- rig_strvfo(vfo), p1, val);
+ (void)vfo;
+
+ rig_debug(RIG_DEBUG_VERBOSE, "%s: val=%f\n", __func__, val);
if (level < 0) level = 0;
if (level > 100) level = 100;
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML%d%03d;", p1, level);
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML1%03d;", level);
return newcat_set_cmd(rig);
}
/*
* ftx1_get_monitor_level - Get Monitor Level
- * Response: ML P1 P2P3P4; (P1=VFO, P2-P4=level)
+ * Response: ML P1 P2P3P4; (P1=1, P2-P4=level)
*/
int ftx1_get_monitor_level(RIG *rig, vfo_t vfo, float *val)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
int ret;
- int p1 = ftx1_vfo_to_p1(rig, vfo);
- int p1_resp, level;
+ int level;
- rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d\n", __func__,
- rig_strvfo(vfo), p1);
+ (void)vfo;
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML%d;", p1);
+ rig_debug(RIG_DEBUG_VERBOSE, "%s\n", __func__);
+
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML1;");
ret = newcat_get_cmd(rig);
if (ret != RIG_OK) return ret;
- /* Response: ML0100 (P1=0, level=100) */
- if (sscanf(priv->ret_data + 2, "%1d%3d", &p1_resp, &level) != 2)
+ if (ftx1_parse_monitor_response(priv->ret_data, 1, &level) != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__,
priv->ret_data);
diff --git a/rigs/yaesu/ftx1/ftx1_tx.c b/rigs/yaesu/ftx1/ftx1_tx.c
index b5d512c80..2e13fd4b7 100644
--- a/rigs/yaesu/ftx1/ftx1_tx.c
+++ b/rigs/yaesu/ftx1/ftx1_tx.c
@@ -7,7 +7,7 @@
* CAT Commands in this file:
* TX P1; - Transmit (P1: 0=RX, 1=TX CAT, 2=TX Data)
* PC P1P2P3; - Power Control (005-100 watts) [also in ftx1_audio.c]
- * MX P1; - Monitor TX Audio (0=off, 1=on)
+ * MX P1; - MOX transmit control
* VX P1; - VOX on/off (0=off, 1=on)
* AC P1P2P3; - Antenna Tuner Control (P1: 0=off, 1=on, 2=tune)
* BI P1; - Break-In on/off (0=off, 1=on) - type via EX020115
@@ -142,39 +142,39 @@ int ftx1_get_vox(RIG *rig, int *status)
return RIG_OK;
}
-/* Set TX Monitor (MX P1;) */
+/* Set TX Monitor using ML selector 0 (000=off, 001=on). */
int ftx1_set_monitor(RIG *rig, int status)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int p1 = status ? 1 : 0;
+ int level = status ? 1 : 0;
rig_debug(RIG_DEBUG_VERBOSE, "%s: status=%d\n", __func__, status);
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MX%d;", p1);
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML0%03d;", level);
return newcat_set_cmd(rig);
}
-/* Get TX Monitor status (MX P1;) */
+/* Get TX Monitor using ML selector 0 (000=off, 001=on). */
int ftx1_get_monitor(RIG *rig, int *status)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int ret, p1;
+ int ret, level;
rig_debug(RIG_DEBUG_VERBOSE, "%s\n", __func__);
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MX;");
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML0;");
ret = newcat_get_cmd(rig);
if (ret != RIG_OK) return ret;
- if (sscanf(priv->ret_data + 2, "%1d", &p1) != 1)
+ if (ftx1_parse_monitor_response(priv->ret_data, 0, &level) != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__,
priv->ret_data);
return -RIG_EPROTO;
}
- *status = p1;
+ *status = level;
rig_debug(RIG_DEBUG_VERBOSE, "%s: status=%d\n", __func__, *status);
diff --git a/tests/testftx1parsers.c b/tests/testftx1parsers.c
index c1c51f15b..68d3826c6 100644
--- a/tests/testftx1parsers.c
+++ b/tests/testftx1parsers.c
@@ -130,6 +130,36 @@ static int expect_smeter(const char *response, int p1, int expected,
return 0;
}
+static int expect_monitor(const char *response, int selector, int expected,
+ int expected_level)
+{
+ int level = 42;
+ int ret = ftx1_parse_monitor_response(response, selector, &level);
+
+ if (ret != expected)
+ {
+ fprintf(stderr, "ML response '%s': expected %d, got %d\n",
+ response, expected, ret);
+ return 1;
+ }
+
+ if (ret == RIG_OK && level != expected_level)
+ {
+ fprintf(stderr, "ML response '%s': expected %d, got %d\n",
+ response, expected_level, level);
+ return 1;
+ }
+
+ if (ret != RIG_OK && level != 42)
+ {
+ fprintf(stderr, "ML response '%s' changed output on failure\n",
+ response);
+ return 1;
+ }
+
+ return 0;
+}
+
int main(void)
{
static const char *invalid_states[] =
@@ -145,6 +175,10 @@ int main(void)
"EX0301051;", "EX030104;", "EX0301041junk;",
"EX0301042147483648;"
};
+ static const char *invalid_monitor[] =
+ {
+ "ML0002;", "ML2000;", "ML0000"
+ };
if (expect_clar_state("CF00000000;", '0', RIG_OK, '0', '0') != 0
|| expect_clar_state("CF00010000;", '0', RIG_OK, '1', '0') != 0
@@ -187,6 +221,24 @@ int main(void)
}
}
+ if (expect_monitor("ML0000;", 0, RIG_OK, 0) != 0
+ || expect_monitor("ML0001;", 0, RIG_OK, 1) != 0
+ || expect_monitor("ML1000;", 1, RIG_OK, 0) != 0
+ || expect_monitor("ML1100;", 1, RIG_OK, 100) != 0
+ || expect_monitor("ML1101;", 1, -RIG_EPROTO, 0) != 0)
+ {
+ return 1;
+ }
+
+ for (size_t i = 0; i < sizeof(invalid_monitor)
+ / sizeof(invalid_monitor[0]); i++)
+ {
+ if (expect_monitor(invalid_monitor[i], 0, -RIG_EPROTO, 0) != 0)
+ {
+ return 1;
+ }
+ }
+
if (expect_smeter("SM0000;", 0, RIG_OK, 0) != 0
|| expect_smeter("SM1255;", 1, RIG_OK, 255) != 0
|| expect_smeter("RM0123;", 0, -RIG_EPROTO, 0) != 0
-----------------------------------------------------------------------
Summary of changes:
rigs/yaesu/ftx1/ftx1.h | 2 ++
rigs/yaesu/ftx1/ftx1_audio.c | 57 ++++++++++++++++++++++++++++++++------------
rigs/yaesu/ftx1/ftx1_tx.c | 18 +++++++-------
tests/testftx1parsers.c | 52 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 105 insertions(+), 24 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-10-12 13:11:36
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 470518f35cfd6f3b1ce12a8d111e4bb2c1efd26d (commit)
via 6a2ca979ab359b4f46b5da01818af5f0473dacad (commit)
from 7a556dbfc80649ddbceedf5b8f8627b990671594 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 470518f35cfd6f3b1ce12a8d111e4bb2c1efd26d
Merge: 7a556dbfc 6a2ca979a
Author: dforsi <iu...@gm...>
Date: Sun Oct 11 19:28:45 2026 +0200
Merge pull request #2170 from dchristle/ftx1-monitor-safety
fix(ftx1): prevent monitor control from keying transmitter
commit 6a2ca979ab359b4f46b5da01818af5f0473dacad
Author: David Christle <dch...@us...>
Date: Sat Aug 22 11:00:19 2026 -0700
fix(ftx1): prevent monitor control from keying transmitter
Map Hamlib monitor control to the FTX-1 ML on/off selector.
Keep ML1 monitor gain separate and validate both response formats.
Fixes: 6362407aa967 ("Add Yaesu FTX-1 backend driver")
diff --git a/rigs/yaesu/ftx1/ftx1.h b/rigs/yaesu/ftx1/ftx1.h
index b86349a5b..860b5c556 100644
--- a/rigs/yaesu/ftx1/ftx1.h
+++ b/rigs/yaesu/ftx1/ftx1.h
@@ -277,6 +277,8 @@ extern int ftx1_parse_clar_offset(const char *response, char vfo,
shortfreq_t *offset);
extern int ftx1_parse_ex_menu_response(const char *response, int group,
int section, int item, int *value);
+extern int ftx1_parse_monitor_response(const char *response, int selector,
+ int *level);
extern int ftx1_parse_smeter_response(const char *response, int p1, int *value);
#endif /* _FTX1_H */
diff --git a/rigs/yaesu/ftx1/ftx1_audio.c b/rigs/yaesu/ftx1/ftx1_audio.c
index dfbdb4026..f05edc3b2 100644
--- a/rigs/yaesu/ftx1/ftx1_audio.c
+++ b/rigs/yaesu/ftx1/ftx1_audio.c
@@ -9,7 +9,7 @@
* RG P1 P2P3P4; - RF Gain (P1=VFO 0/1, P2-P4=000-255)
* MG P1P2P3; - Mic Gain (000-100)
* GT P1P2P3P4; - AGC Time Constant (0000-6000ms or code)
- * ML P1P2P3; - Monitor Level (000-100)
+ * ML P1P2P3; - Monitor on/off or level (selector-dependent)
* SM P1; - S-Meter Read (P1=0 main, returns 0000-0255)
* RM P1; - Meter Read (1=Main S, 2=Sub S, 3=COMP, 4=ALC, 5=PO, 6=SWR, 7=ID, 8=VDD)
* PC P1 P2P2P2; - Power Control (P1=1 field head, P1=2 SPA-1)
@@ -177,6 +177,33 @@ int ftx1_get_mic_gain(RIG *rig, float *val)
return RIG_OK;
}
+int ftx1_parse_monitor_response(const char *response, int selector, int *level)
+{
+ int parsed_level;
+
+ if (selector < 0 || selector > 1 || strlen(response) != 7
+ || response[0] != 'M' || response[1] != 'L'
+ || response[2] != '0' + selector
+ || response[3] < '0' || response[3] > '9'
+ || response[4] < '0' || response[4] > '9'
+ || response[5] < '0' || response[5] > '9'
+ || response[6] != ';')
+ {
+ return -RIG_EPROTO;
+ }
+
+ parsed_level = (response[3] - '0') * 100 + (response[4] - '0') * 10
+ + response[5] - '0';
+
+ if ((selector == 0 && parsed_level > 1) || parsed_level > 100)
+ {
+ return -RIG_EPROTO;
+ }
+
+ *level = parsed_level;
+ return RIG_OK;
+}
+
int ftx1_parse_smeter_response(const char *response, int p1, int *val)
{
int level;
@@ -584,46 +611,46 @@ int ftx1_get_vox_delay(RIG *rig, int *tenths)
}
/*
- * ftx1_set_monitor_level - Set Monitor Level (ML P1 P2P3P4;)
- * CAT command: ML P1 P2P3P4; (P1=VFO 0/1, P2-P4=000-100)
+ * ftx1_set_monitor_level - Set Monitor Level (ML 1 P2P3P4;)
+ * The FTX-1's ML selector 1 controls the global monitor level; it is not a
+ * VFO selector.
*/
int ftx1_set_monitor_level(RIG *rig, vfo_t vfo, float val)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int p1 = ftx1_vfo_to_p1(rig, vfo);
int level = (int)(val * 100);
- rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d val=%f\n", __func__,
- rig_strvfo(vfo), p1, val);
+ (void)vfo;
+
+ rig_debug(RIG_DEBUG_VERBOSE, "%s: val=%f\n", __func__, val);
if (level < 0) level = 0;
if (level > 100) level = 100;
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML%d%03d;", p1, level);
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML1%03d;", level);
return newcat_set_cmd(rig);
}
/*
* ftx1_get_monitor_level - Get Monitor Level
- * Response: ML P1 P2P3P4; (P1=VFO, P2-P4=level)
+ * Response: ML P1 P2P3P4; (P1=1, P2-P4=level)
*/
int ftx1_get_monitor_level(RIG *rig, vfo_t vfo, float *val)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
int ret;
- int p1 = ftx1_vfo_to_p1(rig, vfo);
- int p1_resp, level;
+ int level;
- rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s p1=%d\n", __func__,
- rig_strvfo(vfo), p1);
+ (void)vfo;
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML%d;", p1);
+ rig_debug(RIG_DEBUG_VERBOSE, "%s\n", __func__);
+
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML1;");
ret = newcat_get_cmd(rig);
if (ret != RIG_OK) return ret;
- /* Response: ML0100 (P1=0, level=100) */
- if (sscanf(priv->ret_data + 2, "%1d%3d", &p1_resp, &level) != 2)
+ if (ftx1_parse_monitor_response(priv->ret_data, 1, &level) != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__,
priv->ret_data);
diff --git a/rigs/yaesu/ftx1/ftx1_tx.c b/rigs/yaesu/ftx1/ftx1_tx.c
index b5d512c80..2e13fd4b7 100644
--- a/rigs/yaesu/ftx1/ftx1_tx.c
+++ b/rigs/yaesu/ftx1/ftx1_tx.c
@@ -7,7 +7,7 @@
* CAT Commands in this file:
* TX P1; - Transmit (P1: 0=RX, 1=TX CAT, 2=TX Data)
* PC P1P2P3; - Power Control (005-100 watts) [also in ftx1_audio.c]
- * MX P1; - Monitor TX Audio (0=off, 1=on)
+ * MX P1; - MOX transmit control
* VX P1; - VOX on/off (0=off, 1=on)
* AC P1P2P3; - Antenna Tuner Control (P1: 0=off, 1=on, 2=tune)
* BI P1; - Break-In on/off (0=off, 1=on) - type via EX020115
@@ -142,39 +142,39 @@ int ftx1_get_vox(RIG *rig, int *status)
return RIG_OK;
}
-/* Set TX Monitor (MX P1;) */
+/* Set TX Monitor using ML selector 0 (000=off, 001=on). */
int ftx1_set_monitor(RIG *rig, int status)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int p1 = status ? 1 : 0;
+ int level = status ? 1 : 0;
rig_debug(RIG_DEBUG_VERBOSE, "%s: status=%d\n", __func__, status);
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MX%d;", p1);
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML0%03d;", level);
return newcat_set_cmd(rig);
}
-/* Get TX Monitor status (MX P1;) */
+/* Get TX Monitor using ML selector 0 (000=off, 001=on). */
int ftx1_get_monitor(RIG *rig, int *status)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int ret, p1;
+ int ret, level;
rig_debug(RIG_DEBUG_VERBOSE, "%s\n", __func__);
- SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MX;");
+ SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "ML0;");
ret = newcat_get_cmd(rig);
if (ret != RIG_OK) return ret;
- if (sscanf(priv->ret_data + 2, "%1d", &p1) != 1)
+ if (ftx1_parse_monitor_response(priv->ret_data, 0, &level) != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: failed to parse '%s'\n", __func__,
priv->ret_data);
return -RIG_EPROTO;
}
- *status = p1;
+ *status = level;
rig_debug(RIG_DEBUG_VERBOSE, "%s: status=%d\n", __func__, *status);
diff --git a/tests/testftx1parsers.c b/tests/testftx1parsers.c
index c1c51f15b..68d3826c6 100644
--- a/tests/testftx1parsers.c
+++ b/tests/testftx1parsers.c
@@ -130,6 +130,36 @@ static int expect_smeter(const char *response, int p1, int expected,
return 0;
}
+static int expect_monitor(const char *response, int selector, int expected,
+ int expected_level)
+{
+ int level = 42;
+ int ret = ftx1_parse_monitor_response(response, selector, &level);
+
+ if (ret != expected)
+ {
+ fprintf(stderr, "ML response '%s': expected %d, got %d\n",
+ response, expected, ret);
+ return 1;
+ }
+
+ if (ret == RIG_OK && level != expected_level)
+ {
+ fprintf(stderr, "ML response '%s': expected %d, got %d\n",
+ response, expected_level, level);
+ return 1;
+ }
+
+ if (ret != RIG_OK && level != 42)
+ {
+ fprintf(stderr, "ML response '%s' changed output on failure\n",
+ response);
+ return 1;
+ }
+
+ return 0;
+}
+
int main(void)
{
static const char *invalid_states[] =
@@ -145,6 +175,10 @@ int main(void)
"EX0301051;", "EX030104;", "EX0301041junk;",
"EX0301042147483648;"
};
+ static const char *invalid_monitor[] =
+ {
+ "ML0002;", "ML2000;", "ML0000"
+ };
if (expect_clar_state("CF00000000;", '0', RIG_OK, '0', '0') != 0
|| expect_clar_state("CF00010000;", '0', RIG_OK, '1', '0') != 0
@@ -187,6 +221,24 @@ int main(void)
}
}
+ if (expect_monitor("ML0000;", 0, RIG_OK, 0) != 0
+ || expect_monitor("ML0001;", 0, RIG_OK, 1) != 0
+ || expect_monitor("ML1000;", 1, RIG_OK, 0) != 0
+ || expect_monitor("ML1100;", 1, RIG_OK, 100) != 0
+ || expect_monitor("ML1101;", 1, -RIG_EPROTO, 0) != 0)
+ {
+ return 1;
+ }
+
+ for (size_t i = 0; i < sizeof(invalid_monitor)
+ / sizeof(invalid_monitor[0]); i++)
+ {
+ if (expect_monitor(invalid_monitor[i], 0, -RIG_EPROTO, 0) != 0)
+ {
+ return 1;
+ }
+ }
+
if (expect_smeter("SM0000;", 0, RIG_OK, 0) != 0
|| expect_smeter("SM1255;", 1, RIG_OK, 255) != 0
|| expect_smeter("RM0123;", 0, -RIG_EPROTO, 0) != 0
-----------------------------------------------------------------------
Summary of changes:
rigs/yaesu/ftx1/ftx1.h | 2 ++
rigs/yaesu/ftx1/ftx1_audio.c | 57 ++++++++++++++++++++++++++++++++------------
rigs/yaesu/ftx1/ftx1_tx.c | 18 +++++++-------
tests/testftx1parsers.c | 52 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 105 insertions(+), 24 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-10-04 13:41:43
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 7a556dbfc80649ddbceedf5b8f8627b990671594 (commit)
via 54f427aa3e67658eda4677a18b703b75d5b03dd5 (commit)
via 11ff5246f3d8b77c95d2b7fabb6217fc7194fcda (commit)
via 7e78154e1e3c664176c5473660959c2b1b9d0645 (commit)
from 50b2a9310edc4a481d8a6ef10e948ea8554f97f9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7a556dbfc80649ddbceedf5b8f8627b990671594
Merge: 54f427aa3 7e78154e1
Author: dforsi <iu...@gm...>
Date: Sat Oct 3 18:44:53 2026 +0200
Merge pull request #2230 from dchristle/fix/icom-keyertype-value
fix(icom): return valid KEYERTYPE strings
commit 54f427aa3e67658eda4677a18b703b75d5b03dd5
Merge: 50b2a9310 11ff5246f
Author: dforsi <iu...@gm...>
Date: Sat Oct 3 17:37:30 2026 +0200
Merge pull request #2232 from dchristle/fix/set-mode-routing-lock
fix(core): prevent stale PTT and VFO checks in rig_set_mode
commit 11ff5246f3d8b77c95d2b7fabb6217fc7194fcda
Author: David Christle <dch...@us...>
Date: Tue Sep 22 15:32:34 2026 +0200
fix(core): snapshot mode routing after acquiring the API lock
Read PTT and current VFO state after API serialization so a queued mode
request observes preceding PTT and VFO changes. Retain the cache-locked
snapshot to preserve coherent routing reads.
Extend the Dummy mode tests with deterministic interleavings for PTT on,
PTT off, and current-VFO changes while a mode request waits for the lock.
Fixes: 26b1ac264 ("fix(cache): synchronize cache and routing state")
diff --git a/src/rig.c b/src/rig.c
index 4b3022d00..39ede86a5 100644
--- a/src/rig.c
+++ b/src/rig.c
@@ -2892,10 +2892,10 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
return -RIG_EINVAL;
}
- rig_get_cache_routing_snapshot(rig, &routing);
ENTERFUNC;
ELAPSED1;
LOCK(1);
+ rig_get_cache_routing_snapshot(rig, &routing);
rig_debug(RIG_DEBUG_VERBOSE,
"%s called, vfo=%s, mode=%s, width=%d, curr_vfo=%s\n", __func__,
diff --git a/tests/testcachemode.c b/tests/testcachemode.c
index dc6d973d8..7697c36f5 100644
--- a/tests/testcachemode.c
+++ b/tests/testcachemode.c
@@ -8,7 +8,11 @@
* version 2.1 of the License, or (at your option) any later version.
*/
+#include <pthread.h>
+#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
+#include <time.h>
#include "hamlib/rig.h"
#include "hamlib/riglist.h"
@@ -35,6 +39,150 @@ static int check_status(const char *operation, int status)
return 1;
}
+struct mode_request
+{
+ RIG *rig;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ int entered;
+ int status;
+};
+
+static int observe_mode_entry(enum rig_debug_level_e level, rig_ptr_t arg,
+ const char *fmt, va_list ap)
+{
+ struct mode_request *request = arg;
+ char message[512];
+
+ (void)level;
+ vsnprintf(message, sizeof(message), fmt, ap);
+
+ if (strstr(message, ":rig_set_mode entered") != NULL)
+ {
+ pthread_mutex_lock(&request->mutex);
+ request->entered = 1;
+ pthread_cond_signal(&request->cond);
+ pthread_mutex_unlock(&request->mutex);
+ }
+
+ return RIG_OK;
+}
+
+static void *set_current_mode(void *arg)
+{
+ struct mode_request *request = arg;
+
+ request->status = rig_set_mode(request->rig, RIG_VFO_CURR,
+ RIG_MODE_FM, 12000);
+ return NULL;
+}
+
+static int check_serialized_mode(RIG *rig, ptt_t initial_ptt,
+ ptt_t next_ptt, vfo_t next_vfo)
+{
+ struct mode_request request =
+ {
+ .rig = rig,
+ .mutex = PTHREAD_MUTEX_INITIALIZER,
+ .cond = PTHREAD_COND_INITIALIZER
+ };
+ struct timespec deadline;
+ pthread_t thread;
+ rmode_t mode_a, mode_b;
+ pbwidth_t width;
+ int failed = 1;
+ int status;
+
+ if (check_status("reset PTT", rig_set_ptt(rig, RIG_VFO_CURR, RIG_PTT_OFF))
+ || check_status("reset VFO", rig_set_vfo(rig, RIG_VFO_A))
+ || check_status("reset mode A",
+ rig_set_mode(rig, RIG_VFO_A, RIG_MODE_USB, 2100))
+ || check_status("reset mode B",
+ rig_set_mode(rig, RIG_VFO_B, RIG_MODE_LSB, 2100))
+ || check_status("set initial PTT",
+ rig_set_ptt(rig, RIG_VFO_CURR, initial_ptt)))
+ {
+ goto cleanup;
+ }
+
+ rig_lock(rig, 1);
+ rig_set_debug_callback(observe_mode_entry, &request);
+ rig_set_debug(RIG_DEBUG_VERBOSE);
+ status = pthread_create(&thread, NULL, set_current_mode, &request);
+
+ if (status != 0)
+ {
+ fprintf(stderr, "mode thread creation failed: %d\n", status);
+ rig_lock(rig, 0);
+ goto restore_debug;
+ }
+
+ /* Entry precedes the API lock, so the request cannot run its backend
+ * until the recursive lock owner publishes the new PTT/VFO state. */
+ deadline.tv_sec = time(NULL) + 5;
+ deadline.tv_nsec = 0;
+ pthread_mutex_lock(&request.mutex);
+
+ while (!request.entered && status == 0)
+ {
+ status = pthread_cond_timedwait(&request.cond, &request.mutex,
+ &deadline);
+ }
+
+ pthread_mutex_unlock(&request.mutex);
+
+ if (status != 0)
+ {
+ fprintf(stderr, "mode entry wait failed: %d\n", status);
+ }
+ else
+ {
+ failed = check_status("publish PTT before mode",
+ rig_set_ptt(rig, RIG_VFO_CURR, next_ptt))
+ || check_status("publish VFO before mode",
+ rig_set_vfo(rig, next_vfo));
+ }
+
+ rig_lock(rig, 0);
+ pthread_join(thread, NULL);
+ failed |= check_status("queued mode request", request.status);
+
+restore_debug:
+ rig_set_debug(RIG_DEBUG_ERR);
+ rig_set_debug_callback(NULL, NULL);
+
+ if (!failed
+ && !check_status("read backend mode A",
+ rig->caps->get_mode(rig, RIG_VFO_A, &mode_a, &width))
+ && !check_status("read backend mode B",
+ rig->caps->get_mode(rig, RIG_VFO_B, &mode_b, &width)))
+ {
+ rmode_t expected_a = next_ptt == RIG_PTT_OFF && next_vfo == RIG_VFO_A
+ ? RIG_MODE_FM : RIG_MODE_USB;
+ rmode_t expected_b = next_ptt == RIG_PTT_OFF && next_vfo == RIG_VFO_B
+ ? RIG_MODE_FM : RIG_MODE_LSB;
+
+ failed = mode_a != expected_a || mode_b != expected_b;
+
+ if (failed)
+ {
+ fprintf(stderr,
+ "stale mode routing (PTT %d -> %d, VFO %s): A=%s, B=%s\n",
+ initial_ptt, next_ptt, rig_strvfo(next_vfo),
+ rig_strrmode(mode_a), rig_strrmode(mode_b));
+ }
+ }
+ else
+ {
+ failed = 1;
+ }
+
+cleanup:
+ pthread_cond_destroy(&request.cond);
+ pthread_mutex_destroy(&request.mutex);
+ return failed;
+}
+
int main(void)
{
RIG *rig;
@@ -211,7 +359,9 @@ int main(void)
goto cleanup;
}
- result = 0;
+ result = check_serialized_mode(rig, RIG_PTT_OFF, RIG_PTT_ON, RIG_VFO_A);
+ result |= check_serialized_mode(rig, RIG_PTT_ON, RIG_PTT_OFF, RIG_VFO_A);
+ result |= check_serialized_mode(rig, RIG_PTT_OFF, RIG_PTT_OFF, RIG_VFO_B);
cleanup:
rig_close(rig);
commit 7e78154e1e3c664176c5473660959c2b1b9d0645
Author: David Christle <dch...@us...>
Date: Mon Sep 21 23:17:56 2026 +0200
fix(icom): normalize KEYERTYPE parameter values
Icom decodes KEYERTYPE replies as integers even though the public
parameter is string-valued. Convert valid radio values to stable numeric
strings and reject out-of-range replies before callers format them.
Cover all valid values, malformed input, and rejected transactions
through an IC-785x CI-V exchange.
diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c
index 9ab1222b0..8161a17b1 100644
--- a/rigs/icom/icom.c
+++ b/rigs/icom/icom.c
@@ -7720,13 +7720,33 @@ int icom_get_parm(RIG *rig, setting_t parm, value_t *val)
{
int retval = icom_get_cmd(rig, RIG_VFO_NONE, (struct cmdparams *)&cmd[i], val);
+ if (retval != RIG_OK)
+ {
+ RETURNFUNC(retval);
+ }
+
if (parm == RIG_PARM_BANDSELECT)
{
char *s = (char *)icom_get_band(rig, val->i);
val->s = s;
}
+ else if (parm == RIG_PARM_KEYERTYPE)
+ {
+ static const char *keyer_types[] = { "0", "1", "2" };
- RETURNFUNC(retval);
+ if (val->i < 0
+ || val->i >= (int)(sizeof(keyer_types) /
+ sizeof(keyer_types[0])))
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: invalid keyer type %d\n",
+ __func__, val->i);
+ RETURNFUNC(-RIG_EPROTO);
+ }
+
+ val->cs = keyer_types[val->i];
+ }
+
+ RETURNFUNC(RIG_OK);
}
}
diff --git a/tests/testicomfallback.c b/tests/testicomfallback.c
index ad18a3ef8..c41c8e10f 100644
--- a/tests/testicomfallback.c
+++ b/tests/testicomfallback.c
@@ -29,6 +29,7 @@
extern struct rig_caps ic7100_caps;
extern struct rig_caps ic7300_caps;
+extern struct rig_caps ic785x_caps;
static int close_test_socket(int fd)
{
@@ -158,6 +159,10 @@ static const unsigned char request_frequency[] =
{
0xfe, 0xfe, 0x88, 0xe0, 0x03, 0xfd
};
+static const unsigned char request_keyer_type[] =
+{
+ 0xfe, 0xfe, 0x8e, 0xe0, 0x1a, 0x05, 0x02, 0x54, 0xfd
+};
static const unsigned char response_nak_ic7100[] =
{
@@ -167,6 +172,10 @@ static const unsigned char response_nak_ic7300[] =
{
0xfe, 0xfe, 0xe0, 0x94, 0xfa, 0xfd
};
+static const unsigned char response_nak_ic785x[] =
+{
+ 0xfe, 0xfe, 0xe0, 0x8e, 0xfa, 0xfd
+};
static const unsigned char response_x26[] =
{
0xfe, 0xfe, 0xe0, 0x88, 0x26, 0x00, 0x01, 0x00, 0x01, 0xfd
@@ -194,6 +203,35 @@ static const unsigned char response_frequency[] =
0xfd
};
static const unsigned char response_malformed[] = { 0x00, 0xfd };
+static const unsigned char response_keyer_straight[] =
+{
+ 0xfe, 0xfe, 0xe0, 0x8e, 0x1a, 0x05, 0x02, 0x54, 0x00, 0xfd
+};
+static const unsigned char response_keyer_bug[] =
+{
+ 0xfe, 0xfe, 0xe0, 0x8e, 0x1a, 0x05, 0x02, 0x54, 0x01, 0xfd
+};
+static const unsigned char response_keyer_paddle[] =
+{
+ 0xfe, 0xfe, 0xe0, 0x8e, 0x1a, 0x05, 0x02, 0x54, 0x02, 0xfd
+};
+static const unsigned char response_keyer_invalid[] =
+{
+ 0xfe, 0xfe, 0xe0, 0x8e, 0x1a, 0x05, 0x02, 0x54, 0x03, 0xfd
+};
+
+#define KEYER_EXCHANGES(name, response) \
+ static const struct exchange name[] = \
+ { \
+ { request_keyer_type, sizeof(request_keyer_type), \
+ response, sizeof(response) } \
+ }
+
+KEYER_EXCHANGES(keyer_straight_exchanges, response_keyer_straight);
+KEYER_EXCHANGES(keyer_bug_exchanges, response_keyer_bug);
+KEYER_EXCHANGES(keyer_paddle_exchanges, response_keyer_paddle);
+KEYER_EXCHANGES(keyer_invalid_exchanges, response_keyer_invalid);
+KEYER_EXCHANGES(keyer_rejected_exchanges, response_nak_ic785x);
static const struct exchange old_mode_exchanges[] =
{
@@ -498,6 +536,66 @@ static int run_frequency_case(const char *name,
return 0;
}
+static int run_parm_case(const char *name, const struct exchange *exchanges,
+ int expected_retval, const char *expected_value)
+{
+ int sockets[2];
+ pthread_t thread;
+ struct peer_case test =
+ {
+ .name = name,
+ .exchanges = exchanges,
+ .exchange_count = 1,
+ .fd = -1,
+ .status = -1
+ };
+ RIG *rig;
+ value_t value = { .i = 3 };
+ int retval;
+
+ if (open_test_connection(sockets) != 0)
+ {
+ fprintf(stderr, "%s: test socket setup failed\n", name);
+ return 1;
+ }
+
+ test.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &test) != 0)
+ {
+ close_test_socket(sockets[0]);
+ close_test_socket(sockets[1]);
+ return 1;
+ }
+
+ rig = prepare_rig(RIG_MODEL_IC785x, sockets[0]);
+
+ if (rig == NULL)
+ {
+ close_test_socket(sockets[0]);
+ close_test_socket(sockets[1]);
+ pthread_join(thread, NULL);
+ return 1;
+ }
+
+ retval = rig_get_parm(rig, RIG_PARM_KEYERTYPE, &value);
+ release_rig(rig, sockets[0]);
+ pthread_join(thread, NULL);
+ close_test_socket(sockets[1]);
+
+ if (test.status != 0 || retval != expected_retval
+ || (retval == RIG_OK && strcmp(value.cs, expected_value) != 0))
+ {
+ fprintf(stderr, "%s: expected %d/%s, got %d/%s\n", name,
+ expected_retval, expected_value != NULL ? expected_value : "<error>",
+ retval,
+ retval == RIG_OK ? value.cs : "<error>");
+ return 1;
+ }
+
+ return 0;
+}
+
int main(void)
{
int status = 0;
@@ -515,6 +613,7 @@ int main(void)
rig_register(&ic7100_caps);
rig_register(&ic7300_caps);
+ rig_register(&ic785x_caps);
if (run_mode_case("optional 0x26 NAK", RIG_MODEL_IC7100,
old_mode_exchanges, ARRAY_SIZE(old_mode_exchanges),
@@ -546,6 +645,19 @@ int main(void)
{
status = 1;
}
+ else if (run_parm_case("KEYERTYPE straight", keyer_straight_exchanges,
+ RIG_OK, "0") != 0
+ || run_parm_case("KEYERTYPE bug", keyer_bug_exchanges,
+ RIG_OK, "1") != 0
+ || run_parm_case("KEYERTYPE paddle", keyer_paddle_exchanges,
+ RIG_OK, "2") != 0
+ || run_parm_case("invalid KEYERTYPE", keyer_invalid_exchanges,
+ -RIG_EPROTO, NULL) != 0
+ || run_parm_case("rejected KEYERTYPE", keyer_rejected_exchanges,
+ -RIG_ERJCTED, NULL) != 0)
+ {
+ status = 1;
+ }
#ifdef _WIN32
WSACleanup();
-----------------------------------------------------------------------
Summary of changes:
rigs/icom/icom.c | 22 ++++++-
src/rig.c | 2 +-
tests/testcachemode.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++-
tests/testicomfallback.c | 112 ++++++++++++++++++++++++++++++++++
4 files changed, 285 insertions(+), 3 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-27 16:47:40
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via 0aa18bfd11b9ad38a5b8fb47634c13141f1ea1ec (commit)
via 3e2ef2cd646f1b55e8c0ae5fa07fa407a8c9d8a5 (commit)
via d034b23659ae4e82e5625e0c13723e0478c15e23 (commit)
via 6e631b81a682224c5c431e35064c8704046b70ff (commit)
via ce82e149e7da270673c8956cecf7ac0c2e48d3d8 (commit)
from 13a7c0750f8d02cfadd8d4ebf28a953902832bb7 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0aa18bfd11b9ad38a5b8fb47634c13141f1ea1ec
Merge: 3e2ef2cd6 6e631b81a
Author: dforsi <iu...@gm...>
Date: Sun Sep 27 17:09:01 2026 +0200
Merge pull request #2169 from dchristle/backport/4.7-testnetrigctl-build
build(tests): backport testnetrigctl build fix to 4.7
commit 3e2ef2cd646f1b55e8c0ae5fa07fa407a8c9d8a5
Merge: 13a7c0750 d034b2365
Author: dforsi <iu...@gm...>
Date: Tue Sep 22 23:15:26 2026 +0200
Merge pull request #2235 from dforsi/Hamlib-4.7
Merge pull request #2161 from dchristle/fix/usrp-if-mix-freq-init
commit d034b23659ae4e82e5625e0c13723e0478c15e23
Author: dforsi <iu...@gm...>
Date: Tue Sep 22 22:54:48 2026 +0200
Merge pull request #2161 from dchristle/fix/usrp-if-mix-freq-init
fix(usrp): initialize backend state safely
(cherry picked from commit 50b2a9310edc4a481d8a6ef10e948ea8554f97f9)
diff --git a/rigs/kit/usrp_impl.cc b/rigs/kit/usrp_impl.cc
index 23e9de3bc..8d6d365ca 100644
--- a/rigs/kit/usrp_impl.cc
+++ b/rigs/kit/usrp_impl.cc
@@ -27,63 +27,79 @@
#if defined(HAVE_USRP)
-#include <stdlib.h>
#include <stdio.h>
-#include <errno.h>
+#include <new>
#include <usrp/usrp_standard.h>
+#include "hamlib/rig.h"
+#include "hamlib/rig_state.h"
#include "usrp_impl.h"
#include "token.h"
-struct usrp_priv_data {
- usrp_standard_rx *urx;
- usrp_standard_tx *utx;
- freq_t if_mix_freq;
+struct usrp_priv_data
+{
+ usrp_standard_rx_sptr urx;
+ usrp_standard_tx *utx = nullptr;
+ freq_t if_mix_freq = MHz(45);
};
int usrp_init(RIG *rig)
{
- // cppcheck-suppress leakReturnValNotUsed
- STATE(rig)->priv = static_cast<struct usrp_priv_data*>(malloc(sizeof(struct usrp_priv_data)));
- if (!STATE(rig)->priv) {
- /* whoops! memory shortage! */
- return -RIG_ENOMEM;
- }
-
- return RIG_OK;
+ struct usrp_priv_data *priv = new (std::nothrow) usrp_priv_data {};
+ STATE(rig)->priv = priv;
+
+ if (!priv)
+ {
+ return -RIG_ENOMEM;
+ }
+
+ return RIG_OK;
}
int usrp_cleanup(RIG *rig)
{
- if (!rig)
- return -RIG_EINVAL;
+ if (!rig)
+ {
+ return -RIG_EINVAL;
+ }
- if (STATE(rig)->priv)
- free(STATE(rig)->priv);
- STATE(rig)->priv = NULL;
+ delete static_cast<struct usrp_priv_data *>(STATE(rig)->priv);
+ STATE(rig)->priv = NULL;
- return RIG_OK;
+ return RIG_OK;
}
int usrp_open(RIG *rig)
{
- struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
- int which_board = 0;
- int decim = 125;
+ int which_board = 0;
+ int decim = 125;
- priv->urx = usrp_standard_rx::make (which_board, decim, 1, -1, usrp_standard_rx::FPGA_MODE_NORMAL).get();
- if (priv->urx == 0)
- return -RIG_EIO;
+ if (!priv)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: priv == NULL?\n", __func__);
+ return -RIG_EARG;
+ }
+
+ priv->urx = usrp_standard_rx::make(which_board, decim, 1, -1,
+ usrp_standard_rx::FPGA_MODE_NORMAL);
+
+ if (!priv->urx)
+ {
+ return -RIG_EIO;
+ }
- return RIG_OK;
+ return RIG_OK;
}
int usrp_close(RIG *rig)
{
- struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
if (!priv)
{
@@ -91,9 +107,9 @@ int usrp_close(RIG *rig)
return -RIG_EARG;
}
- delete priv->urx;
+ priv->urx.reset();
- return RIG_OK;
+ return RIG_OK;
}
/*
@@ -101,7 +117,8 @@ int usrp_close(RIG *rig)
*/
int usrp_set_conf(RIG *rig, hamlib_token_t token, const char *val)
{
- struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
if (!priv)
{
@@ -109,14 +126,17 @@ int usrp_set_conf(RIG *rig, hamlib_token_t token, const char *val)
return -RIG_EARG;
}
- switch(token) {
- case TOK_IFMIXFREQ:
- sscanf(val, "%" SCNfreq, &priv->if_mix_freq);
- break;
- default:
- return -RIG_EINVAL;
- }
- return RIG_OK;
+ switch (token)
+ {
+ case TOK_IFMIXFREQ:
+ sscanf(val, "%" SCNfreq, &priv->if_mix_freq);
+ break;
+
+ default:
+ return -RIG_EINVAL;
+ }
+
+ return RIG_OK;
}
/*
@@ -126,7 +146,8 @@ int usrp_set_conf(RIG *rig, hamlib_token_t token, const char *val)
*/
int usrp_get_conf(RIG *rig, hamlib_token_t token, char *val)
{
- const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
if (!priv)
{
@@ -134,22 +155,26 @@ int usrp_get_conf(RIG *rig, hamlib_token_t token, char *val)
return -RIG_EARG;
}
- switch(token) {
- case TOK_IFMIXFREQ:
- sprintf(val, "%" PRIfreq, priv->if_mix_freq);
- break;
- default:
- return -RIG_EINVAL;
- }
- return RIG_OK;
+ switch (token)
+ {
+ case TOK_IFMIXFREQ:
+ sprintf(val, "%" PRIfreq, priv->if_mix_freq);
+ break;
+
+ default:
+ return -RIG_EINVAL;
+ }
+
+ return RIG_OK;
}
int usrp_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
- const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
- int chan = 0;
+ const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
+ int chan = 0;
if (!priv)
{
@@ -157,17 +182,25 @@ int usrp_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
return -RIG_EARG;
}
- if (!priv->urx->set_rx_freq (chan, freq))
- return -RIG_EPROTO;
+ if (!priv->urx)
+ {
+ return -RIG_EIO;
+ }
+
+ if (!priv->urx->set_rx_freq(chan, freq))
+ {
+ return -RIG_EPROTO;
+ }
- return RIG_OK;
+ return RIG_OK;
}
int usrp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
- const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
- int chan = 0;
+ const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
+ int chan = 0;
if (!priv)
{
@@ -175,14 +208,19 @@ int usrp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
return -RIG_EARG;
}
- *freq = priv->urx->rx_freq (chan);
+ if (!priv->urx)
+ {
+ return -RIG_EIO;
+ }
+
+ *freq = priv->urx->rx_freq(chan);
- return RIG_OK;
+ return RIG_OK;
}
-const char * usrp_get_info(RIG *rig)
+const char *usrp_get_info(RIG *rig)
{
- return NULL;
+ return NULL;
}
-#endif /* HAVE_USRP */
+#endif /* HAVE_USRP */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1ffa4d42d..9e8b8be68 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -204,6 +204,13 @@ check_SCRIPTS = \
TESTS = $(check_SCRIPTS) $(DIRECT_TESTS)
+if HAVE_USRP
+check_PROGRAMS += testusrp
+TESTS += testusrp
+testusrp_SOURCES = testusrp.cc
+testusrp_LDADD = $(top_builddir)/rigs/kit/libhamlib-kit.la $(LDADD)
+endif
+
$(top_builddir)/src/libhamlib.la:
$(MAKE) -C $(top_builddir)/src/ libhamlib.la
diff --git a/tests/testusrp.cc b/tests/testusrp.cc
new file mode 100644
index 000000000..4444cb55d
--- /dev/null
+++ b/tests/testusrp.cc
@@ -0,0 +1,86 @@
+/*
+ * Hamlib USRP backend state tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/riglist.h"
+
+extern "C"
+{
+ extern struct rig_caps usrp_caps;
+}
+
+static int check_conf(RIG *rig, hamlib_token_t token, const char *expected)
+{
+ char value[64] = {};
+ int retval = rig_get_conf2(rig, token, value, sizeof(value));
+
+ if (retval != RIG_OK || strcmp(value, expected) != 0)
+ {
+ fprintf(stderr, "expected USRP if_mix_freq %s, got %s (%d)\n",
+ expected, value, retval);
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ RIG *rig;
+ hamlib_token_t token;
+ freq_t freq = 0;
+
+ rig_register(&usrp_caps);
+ rig = rig_init(RIG_MODEL_USRP);
+
+ if (rig == NULL)
+ {
+ fprintf(stderr, "failed to initialize USRP rig\n");
+ return 1;
+ }
+
+ token = rig_token_lookup(rig, "if_mix_freq");
+
+ if (token == RIG_CONF_END)
+ {
+ fprintf(stderr, "USRP if_mix_freq token was not registered\n");
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ if (check_conf(rig, token, "45000000") != 0)
+ {
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ if (rig_set_conf(rig, token, "12345678") != RIG_OK
+ || check_conf(rig, token, "12345678") != 0)
+ {
+ fprintf(stderr, "USRP if_mix_freq did not retain an override\n");
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ if (rig->caps->rig_close(rig) != RIG_OK
+ || rig->caps->set_freq(rig, RIG_VFO_A, 145000000) != -RIG_EIO
+ || rig->caps->get_freq(rig, RIG_VFO_A, &freq) != -RIG_EIO)
+ {
+ fprintf(stderr, "USRP callbacks were not safe without a receiver\n");
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ rig_cleanup(rig);
+ return 0;
+}
commit 6e631b81a682224c5c431e35064c8704046b70ff
Author: David Christle <dch...@us...>
Date: Thu Aug 20 23:26:18 2026 -0700
build(tests): compile AGC parser helper directly
Tests-subdirectory builds can reuse a stale dummy backend archive, which may omit parser helpers. Compile dummy_common.c directly into testnetrigctl so Automake rebuilds the code under test.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 26715d265..21513c193 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -146,7 +146,7 @@ testelecraftvfo_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood
testftx1parsers_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testft991idmeter_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testnewcatset_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
-testnetrigctl_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la
+testnetrigctl_SOURCES = testnetrigctl.c $(top_srcdir)/rigs/dummy/dummy_common.c
if TESTS_HAVE_LIBUSB
rigtestlibusb_LDADD = $(LIBUSB_LIBS)
endif
commit ce82e149e7da270673c8956cecf7ac0c2e48d3d8
Author: David Christle <dch...@us...>
Date: Thu Aug 20 23:25:59 2026 -0700
fix(dummy): bound network AGC level parsing
Peer-provided AGC level lists were parsed with a stale index and could write beyond the fixed eight-entry arrays. Share a bounded parser between the NET rigctl and Quisk backends, add regression coverage, and register the test in the 4.7 test lists.
diff --git a/rigs/dummy/dummy_common.c b/rigs/dummy/dummy_common.c
index b064b46d8..a4ee4610f 100644
--- a/rigs/dummy/dummy_common.c
+++ b/rigs/dummy/dummy_common.c
@@ -20,10 +20,12 @@
*
*/
-// cppcheck-suppress *
+#include <errno.h>
+#include <limits.h>
#include <stdlib.h>
+#include <string.h>
-#include "hamlib/rig.h"
+#include "dummy_common.h"
struct ext_list *alloc_init_ext(const struct confparams *cfp)
{
@@ -75,3 +77,79 @@ struct ext_list *find_ext(struct ext_list *elp, hamlib_token_t token)
return NULL;
}
+
+void dummy_reset_agc_levels(
+ enum agc_level_e agc_levels[HAMLIB_MAX_AGC_LEVELS],
+ int *agc_level_count)
+{
+ for (int i = 0; i < HAMLIB_MAX_AGC_LEVELS; i++)
+ {
+ agc_levels[i] = RIG_AGC_NONE;
+ }
+
+ *agc_level_count = 0;
+}
+
+int dummy_parse_agc_levels(char *value,
+ enum agc_level_e agc_levels[HAMLIB_MAX_AGC_LEVELS],
+ int *agc_level_count)
+{
+ enum agc_level_e parsed_levels[HAMLIB_MAX_AGC_LEVELS];
+ char *saveptr = NULL;
+ char *token;
+ int count = 0;
+
+ if (value == NULL || value[0] == '\0' || agc_levels == NULL
+ || agc_level_count == NULL)
+ {
+ return -RIG_EPROTO;
+ }
+
+ for (int i = 0; i < HAMLIB_MAX_AGC_LEVELS; i++)
+ {
+ parsed_levels[i] = RIG_AGC_NONE;
+ }
+
+ for (token = strtok_r(value, " ", &saveptr); token != NULL;
+ token = strtok_r(NULL, " ", &saveptr))
+ {
+ char *separator;
+ char *endptr;
+ long code;
+
+ if (count == HAMLIB_MAX_AGC_LEVELS)
+ {
+ // Truncate a longer peer list to the array capacity
+ break;
+ }
+
+ separator = strchr(token, '=');
+
+ if (separator == NULL || separator == token || separator[1] == '\0'
+ || strchr(separator + 1, '=') != NULL)
+ {
+ return -RIG_EPROTO;
+ }
+
+ errno = 0;
+ code = strtol(token, &endptr, 10);
+
+ if (errno == ERANGE || code < INT_MIN || code > INT_MAX
+ || endptr != separator)
+ {
+ return -RIG_EPROTO;
+ }
+
+ parsed_levels[count++] = (enum agc_level_e)code;
+ }
+
+ if (count == 0)
+ {
+ return -RIG_EPROTO;
+ }
+
+ memcpy(agc_levels, parsed_levels, sizeof(parsed_levels));
+ *agc_level_count = count;
+
+ return RIG_OK;
+}
diff --git a/rigs/dummy/dummy_common.h b/rigs/dummy/dummy_common.h
index 919a12b4a..394bb5023 100644
--- a/rigs/dummy/dummy_common.h
+++ b/rigs/dummy/dummy_common.h
@@ -26,5 +26,11 @@
struct ext_list *alloc_init_ext(const struct confparams *cfp);
struct ext_list *find_ext(struct ext_list *elp, hamlib_token_t token);
+void dummy_reset_agc_levels(
+ enum agc_level_e agc_levels[HAMLIB_MAX_AGC_LEVELS],
+ int *agc_level_count);
+int dummy_parse_agc_levels(char *value,
+ enum agc_level_e agc_levels[HAMLIB_MAX_AGC_LEVELS],
+ int *agc_level_count);
#endif /* _DUMMY_H */
diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c
index 5a26b6d73..1c59bb049 100644
--- a/rigs/dummy/netrigctl.c
+++ b/rigs/dummy/netrigctl.c
@@ -31,6 +31,7 @@
#include "num_stdio.h"
#include "dummy.h"
+#include "dummy_common.h"
#define CMD_MAX 64
#define BUF_MAX 1024
@@ -623,6 +624,10 @@ static int netrigctl_open(RIG *rig)
rs->vfo_list = RIG_VFO_A | RIG_VFO_B;
}
+ dummy_reset_agc_levels(rig->caps->agc_levels,
+ &rig->caps->agc_level_count);
+ dummy_reset_agc_levels(rs->agc_levels, &rs->agc_level_count);
+
if (prot_ver == 0) { RETURNFUNC(RIG_OK); }
// otherwise we continue reading protocol 1 fields
@@ -800,31 +805,26 @@ static int netrigctl_open(RIG *rig)
}
else if (strcmp(setting, "agc_levels") == 0)
{
- char *p = strtok(value, " ");
- rig->caps->agc_levels[0] = RIG_AGC_NONE; // default value gets overwritten
- rig->caps->agc_level_count = 0;
-
- while (p)
- {
- int agc_code;
- char agc_string[32];
- int n = sscanf(p, "%d=%31s\n", &agc_code, agc_string);
+ enum agc_level_e agc_levels[HAMLIB_MAX_AGC_LEVELS];
+ int agc_level_count;
- if (n == 2)
- {
- rig->caps->agc_levels[i++] = agc_code;
- rig->caps->agc_level_count++;
- rig_debug(RIG_DEBUG_VERBOSE, "%s: rig has agc code=%d, level=%s\n", __func__,
- agc_code, agc_string);
- }
- else
- {
- rig_debug(RIG_DEBUG_ERR, "%s did not parse code=agc from '%s'\n", __func__, p);
- }
+ ret = dummy_parse_agc_levels(value, agc_levels, &agc_level_count);
- rig_debug(RIG_DEBUG_VERBOSE, "%d=%s\n", agc_code, agc_string);
- p = strtok(NULL, " ");
+ if (ret != RIG_OK)
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: ignoring invalid agc_levels field '%s'\n",
+ __func__, buf);
+ dummy_reset_agc_levels(rig->caps->agc_levels,
+ &rig->caps->agc_level_count);
+ dummy_reset_agc_levels(rs->agc_levels,
+ &rs->agc_level_count);
+ continue;
}
+
+ memcpy(rig->caps->agc_levels, agc_levels, sizeof(agc_levels));
+ memcpy(rs->agc_levels, agc_levels, sizeof(agc_levels));
+ rig->caps->agc_level_count = rs->agc_level_count = agc_level_count;
}
else if (strcmp(setting, "level_gran") == 0)
{
diff --git a/rigs/dummy/quisk.c b/rigs/dummy/quisk.c
index 9c9893d57..2909a0c66 100644
--- a/rigs/dummy/quisk.c
+++ b/rigs/dummy/quisk.c
@@ -31,6 +31,7 @@
#include "num_stdio.h"
#include "dummy.h"
+#include "dummy_common.h"
#define CMD_MAX 64
#define BUF_MAX 1024
@@ -573,6 +574,10 @@ static int quisk_open(RIG *rig)
HAMLIB_TRACE;
#endif
+ dummy_reset_agc_levels(rig->caps->agc_levels,
+ &rig->caps->agc_level_count);
+ dummy_reset_agc_levels(rs->agc_levels, &rs->agc_level_count);
+
if (prot_ver == 0) { RETURNFUNC(RIG_OK); }
HAMLIB_TRACE;
@@ -738,31 +743,26 @@ static int quisk_open(RIG *rig)
}
else if (strcmp(setting, "agc_levels") == 0)
{
- char *p = strtok(value, " ");
- rig->caps->agc_levels[0] = RIG_AGC_NONE; // default value gets overwritten
- rig->caps->agc_level_count = 0;
-
- while (p)
- {
- int agc_code;
- char agc_string[32];
- int n = sscanf(p, "%d=%31s\n", &agc_code, agc_string);
+ enum agc_level_e agc_levels[HAMLIB_MAX_AGC_LEVELS];
+ int agc_level_count;
- if (n == 2)
- {
- rig->caps->agc_levels[i++] = agc_code;
- rig->caps->agc_level_count++;
- rig_debug(RIG_DEBUG_VERBOSE, "%s: rig has agc code=%d, level=%s\n", __func__,
- agc_code, agc_string);
- }
- else
- {
- rig_debug(RIG_DEBUG_ERR, "%s did not parse code=agc from '%s'\n", __func__, p);
- }
+ ret = dummy_parse_agc_levels(value, agc_levels, &agc_level_count);
- rig_debug(RIG_DEBUG_VERBOSE, "%d=%s\n", agc_code, agc_string);
- p = strtok(NULL, " ");
+ if (ret != RIG_OK)
+ {
+ rig_debug(RIG_DEBUG_ERR,
+ "%s: ignoring invalid agc_levels field '%s'\n",
+ __func__, buf);
+ dummy_reset_agc_levels(rig->caps->agc_levels,
+ &rig->caps->agc_level_count);
+ dummy_reset_agc_levels(rs->agc_levels,
+ &rs->agc_level_count);
+ continue;
}
+
+ memcpy(rig->caps->agc_levels, agc_levels, sizeof(agc_levels));
+ memcpy(rs->agc_levels, agc_levels, sizeof(agc_levels));
+ rig->caps->agc_level_count = rs->agc_level_count = agc_level_count;
}
else if (strcmp(setting, "level_gran") == 0)
{
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1ffa4d42d..26715d265 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -40,6 +40,7 @@ GENERATED_TEST_WRAPPERS = \
testfreq.sh \
testgrid.sh \
testloc.sh \
+ testnetrigctl.sh \
testrig.sh \
testrigcaps.sh
@@ -58,6 +59,7 @@ check_PROGRAMS = \
testgrid \
testloc \
testmW2power \
+ testnetrigctl \
testrig \
testrigcaps \
testrigopen \
@@ -144,6 +146,7 @@ testelecraftvfo_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/kenwood
testftx1parsers_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testft991idmeter_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testnewcatset_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
+testnetrigctl_LDADD = $(top_builddir)/rigs/dummy/libhamlib-dummy.la
if TESTS_HAVE_LIBUSB
rigtestlibusb_LDADD = $(LIBUSB_LIBS)
endif
@@ -232,6 +235,10 @@ testrig.sh:
echo 'LD_LIBRARY_PATH=$(top_builddir)/src/.libs:$(top_builddir)/dummy/.libs ./testrig 1' > testrig.sh
chmod +x ./testrig.sh
+testnetrigctl.sh:
+ echo './testnetrigctl' > testnetrigctl.sh
+ chmod +x ./testnetrigctl.sh
+
testfreq.sh:
echo './testfreq' > testfreq.sh
chmod +x ./testfreq.sh
diff --git a/tests/testnetrigctl.c b/tests/testnetrigctl.c
new file mode 100644
index 000000000..4fb533912
--- /dev/null
+++ b/tests/testnetrigctl.c
@@ -0,0 +1,120 @@
+/*
+ * Hamlib NET rigctl parser tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <stdio.h>
+
+#include "../rigs/dummy/dummy_common.h"
+
+struct parse_case
+{
+ const char *name;
+ char *value;
+ int expected_ret;
+ int expected_count;
+ const enum agc_level_e *expected_levels;
+};
+
+static void fill_levels(enum agc_level_e *levels, enum agc_level_e value)
+{
+ for (int i = 0; i < HAMLIB_MAX_AGC_LEVELS; i++)
+ {
+ levels[i] = value;
+ }
+}
+
+static int expect_state(const char *name, const enum agc_level_e *levels,
+ const enum agc_level_e *expected, int count,
+ int expected_count)
+{
+ if (count != expected_count)
+ {
+ fprintf(stderr, "%s: expected count %d, got %d\n", name,
+ expected_count, count);
+ return 1;
+ }
+
+ for (int i = 0; i < HAMLIB_MAX_AGC_LEVELS; i++)
+ {
+ if (levels[i] != expected[i])
+ {
+ fprintf(stderr, "%s: level %d expected %d, got %d\n", name, i,
+ expected[i], levels[i]);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ char short_value[] = "2=FAST 3=SLOW";
+ char maximum_value[] =
+ "0=OFF 1=SUPERFAST 2=FAST 3=SLOW 4=USER 5=MEDIUM 6=AUTO 7=LONG";
+ char ninth_value[] =
+ "0=OFF 1=SUPERFAST 2=FAST 3=SLOW 4=USER 5=MEDIUM 6=AUTO 7=LONG 8=ON";
+ char malformed_value[] = "0=OFF invalid 2=FAST";
+ const enum agc_level_e none[HAMLIB_MAX_AGC_LEVELS] = {
+ RIG_AGC_NONE, RIG_AGC_NONE, RIG_AGC_NONE, RIG_AGC_NONE,
+ RIG_AGC_NONE, RIG_AGC_NONE, RIG_AGC_NONE, RIG_AGC_NONE
+ };
+ const enum agc_level_e user[HAMLIB_MAX_AGC_LEVELS] = {
+ RIG_AGC_USER, RIG_AGC_USER, RIG_AGC_USER, RIG_AGC_USER,
+ RIG_AGC_USER, RIG_AGC_USER, RIG_AGC_USER, RIG_AGC_USER
+ };
+ const enum agc_level_e short_levels[HAMLIB_MAX_AGC_LEVELS] = {
+ RIG_AGC_FAST, RIG_AGC_SLOW, RIG_AGC_NONE, RIG_AGC_NONE,
+ RIG_AGC_NONE, RIG_AGC_NONE, RIG_AGC_NONE, RIG_AGC_NONE
+ };
+ const enum agc_level_e maximum_levels[HAMLIB_MAX_AGC_LEVELS] = {
+ RIG_AGC_OFF, RIG_AGC_SUPERFAST, RIG_AGC_FAST, RIG_AGC_SLOW,
+ RIG_AGC_USER, RIG_AGC_MEDIUM, RIG_AGC_AUTO, RIG_AGC_LONG
+ };
+ struct parse_case cases[] = {
+ { "short list", short_value, RIG_OK, 2, short_levels },
+ { "maximum list", maximum_value, RIG_OK, HAMLIB_MAX_AGC_LEVELS,
+ maximum_levels },
+ { "ninth entry truncated", ninth_value, RIG_OK, HAMLIB_MAX_AGC_LEVELS,
+ maximum_levels },
+ { "malformed token", malformed_value, -RIG_EPROTO, 42, user }
+ };
+ enum agc_level_e levels[HAMLIB_MAX_AGC_LEVELS];
+ int count = 42;
+
+ fill_levels(levels, RIG_AGC_USER);
+ dummy_reset_agc_levels(levels, &count);
+
+ if (expect_state("reset", levels, none, count, 0) != 0)
+ {
+ return 1;
+ }
+
+ for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ {
+ fill_levels(levels, RIG_AGC_USER);
+ count = 42;
+ int ret = dummy_parse_agc_levels(cases[i].value, levels, &count);
+
+ if (ret != cases[i].expected_ret)
+ {
+ fprintf(stderr, "%s: expected return %d, got %d\n", cases[i].name,
+ cases[i].expected_ret, ret);
+ return 1;
+ }
+
+ if (expect_state(cases[i].name, levels, cases[i].expected_levels,
+ count, cases[i].expected_count) != 0)
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
-----------------------------------------------------------------------
Summary of changes:
rigs/dummy/dummy_common.c | 82 +++++++++++++++++++++++-
rigs/dummy/dummy_common.h | 6 ++
rigs/dummy/netrigctl.c | 44 ++++++-------
rigs/dummy/quisk.c | 44 ++++++-------
rigs/kit/usrp_impl.cc | 158 ++++++++++++++++++++++++++++------------------
tests/Makefile.am | 14 ++++
tests/testnetrigctl.c | 120 +++++++++++++++++++++++++++++++++++
tests/testusrp.cc | 86 +++++++++++++++++++++++++
8 files changed, 448 insertions(+), 106 deletions(-)
create mode 100644 tests/testnetrigctl.c
create mode 100644 tests/testusrp.cc
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-27 16:46:29
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 50b2a9310edc4a481d8a6ef10e948ea8554f97f9 (commit)
via 15249506e17954c78f5d9ecebe6106dad090850c (commit)
via cc7741ca8d7cc13c12fb1b997ac9c8429cba3655 (commit)
from f20d4df79d2ea697490c801ba4320348a2ef29bf (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 50b2a9310edc4a481d8a6ef10e948ea8554f97f9
Merge: f20d4df79 15249506e
Author: dforsi <iu...@gm...>
Date: Tue Sep 22 22:54:48 2026 +0200
Merge pull request #2161 from dchristle/fix/usrp-if-mix-freq-init
fix(usrp): initialize backend state safely
commit 15249506e17954c78f5d9ecebe6106dad090850c
Author: Daniele Forsi IU5HKX <iu...@gm...>
Date: Tue Sep 22 00:29:22 2026 +0200
Fix build failure
Fixes:
usrp_impl.cc: In function 'int usrp_init(RIG*)':
usrp_impl.cc:49:5: error: 'STATE' was not declared in this scope; did you mean 'ESTALE'?
49 | STATE(rig)->priv = priv;
...
diff --git a/rigs/kit/usrp_impl.cc b/rigs/kit/usrp_impl.cc
index a7df68913..8d6d365ca 100644
--- a/rigs/kit/usrp_impl.cc
+++ b/rigs/kit/usrp_impl.cc
@@ -31,6 +31,8 @@
#include <new>
#include <usrp/usrp_standard.h>
+#include "hamlib/rig.h"
+#include "hamlib/rig_state.h"
#include "usrp_impl.h"
#include "token.h"
commit cc7741ca8d7cc13c12fb1b997ac9c8429cba3655
Author: David Christle <dch...@us...>
Date: Mon Aug 17 23:57:26 2026 -0700
fix(usrp): initialize backend state safely
Initialize the USRP private state with valid defaults and retain receiver ownership through cleanup.
diff --git a/rigs/kit/usrp_impl.cc b/rigs/kit/usrp_impl.cc
index 23e9de3bc..a7df68913 100644
--- a/rigs/kit/usrp_impl.cc
+++ b/rigs/kit/usrp_impl.cc
@@ -27,63 +27,77 @@
#if defined(HAVE_USRP)
-#include <stdlib.h>
#include <stdio.h>
-#include <errno.h>
+#include <new>
#include <usrp/usrp_standard.h>
#include "usrp_impl.h"
#include "token.h"
-struct usrp_priv_data {
- usrp_standard_rx *urx;
- usrp_standard_tx *utx;
- freq_t if_mix_freq;
+struct usrp_priv_data
+{
+ usrp_standard_rx_sptr urx;
+ usrp_standard_tx *utx = nullptr;
+ freq_t if_mix_freq = MHz(45);
};
int usrp_init(RIG *rig)
{
- // cppcheck-suppress leakReturnValNotUsed
- STATE(rig)->priv = static_cast<struct usrp_priv_data*>(malloc(sizeof(struct usrp_priv_data)));
- if (!STATE(rig)->priv) {
- /* whoops! memory shortage! */
- return -RIG_ENOMEM;
- }
-
- return RIG_OK;
+ struct usrp_priv_data *priv = new (std::nothrow) usrp_priv_data {};
+ STATE(rig)->priv = priv;
+
+ if (!priv)
+ {
+ return -RIG_ENOMEM;
+ }
+
+ return RIG_OK;
}
int usrp_cleanup(RIG *rig)
{
- if (!rig)
- return -RIG_EINVAL;
+ if (!rig)
+ {
+ return -RIG_EINVAL;
+ }
- if (STATE(rig)->priv)
- free(STATE(rig)->priv);
- STATE(rig)->priv = NULL;
+ delete static_cast<struct usrp_priv_data *>(STATE(rig)->priv);
+ STATE(rig)->priv = NULL;
- return RIG_OK;
+ return RIG_OK;
}
int usrp_open(RIG *rig)
{
- struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
- int which_board = 0;
- int decim = 125;
+ int which_board = 0;
+ int decim = 125;
- priv->urx = usrp_standard_rx::make (which_board, decim, 1, -1, usrp_standard_rx::FPGA_MODE_NORMAL).get();
- if (priv->urx == 0)
- return -RIG_EIO;
+ if (!priv)
+ {
+ rig_debug(RIG_DEBUG_ERR, "%s: priv == NULL?\n", __func__);
+ return -RIG_EARG;
+ }
+
+ priv->urx = usrp_standard_rx::make(which_board, decim, 1, -1,
+ usrp_standard_rx::FPGA_MODE_NORMAL);
+
+ if (!priv->urx)
+ {
+ return -RIG_EIO;
+ }
- return RIG_OK;
+ return RIG_OK;
}
int usrp_close(RIG *rig)
{
- struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
if (!priv)
{
@@ -91,9 +105,9 @@ int usrp_close(RIG *rig)
return -RIG_EARG;
}
- delete priv->urx;
+ priv->urx.reset();
- return RIG_OK;
+ return RIG_OK;
}
/*
@@ -101,7 +115,8 @@ int usrp_close(RIG *rig)
*/
int usrp_set_conf(RIG *rig, hamlib_token_t token, const char *val)
{
- struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
if (!priv)
{
@@ -109,14 +124,17 @@ int usrp_set_conf(RIG *rig, hamlib_token_t token, const char *val)
return -RIG_EARG;
}
- switch(token) {
- case TOK_IFMIXFREQ:
- sscanf(val, "%" SCNfreq, &priv->if_mix_freq);
- break;
- default:
- return -RIG_EINVAL;
- }
- return RIG_OK;
+ switch (token)
+ {
+ case TOK_IFMIXFREQ:
+ sscanf(val, "%" SCNfreq, &priv->if_mix_freq);
+ break;
+
+ default:
+ return -RIG_EINVAL;
+ }
+
+ return RIG_OK;
}
/*
@@ -126,7 +144,8 @@ int usrp_set_conf(RIG *rig, hamlib_token_t token, const char *val)
*/
int usrp_get_conf(RIG *rig, hamlib_token_t token, char *val)
{
- const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
+ const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
if (!priv)
{
@@ -134,22 +153,26 @@ int usrp_get_conf(RIG *rig, hamlib_token_t token, char *val)
return -RIG_EARG;
}
- switch(token) {
- case TOK_IFMIXFREQ:
- sprintf(val, "%" PRIfreq, priv->if_mix_freq);
- break;
- default:
- return -RIG_EINVAL;
- }
- return RIG_OK;
+ switch (token)
+ {
+ case TOK_IFMIXFREQ:
+ sprintf(val, "%" PRIfreq, priv->if_mix_freq);
+ break;
+
+ default:
+ return -RIG_EINVAL;
+ }
+
+ return RIG_OK;
}
int usrp_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
{
- const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
- int chan = 0;
+ const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
+ int chan = 0;
if (!priv)
{
@@ -157,17 +180,25 @@ int usrp_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
return -RIG_EARG;
}
- if (!priv->urx->set_rx_freq (chan, freq))
- return -RIG_EPROTO;
+ if (!priv->urx)
+ {
+ return -RIG_EIO;
+ }
+
+ if (!priv->urx->set_rx_freq(chan, freq))
+ {
+ return -RIG_EPROTO;
+ }
- return RIG_OK;
+ return RIG_OK;
}
int usrp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
{
- const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data*>(STATE(rig)->priv);
- int chan = 0;
+ const struct usrp_priv_data *priv = static_cast<struct usrp_priv_data *>(STATE(
+ rig)->priv);
+ int chan = 0;
if (!priv)
{
@@ -175,14 +206,19 @@ int usrp_get_freq(RIG *rig, vfo_t vfo, freq_t *freq)
return -RIG_EARG;
}
- *freq = priv->urx->rx_freq (chan);
+ if (!priv->urx)
+ {
+ return -RIG_EIO;
+ }
+
+ *freq = priv->urx->rx_freq(chan);
- return RIG_OK;
+ return RIG_OK;
}
-const char * usrp_get_info(RIG *rig)
+const char *usrp_get_info(RIG *rig)
{
- return NULL;
+ return NULL;
}
-#endif /* HAVE_USRP */
+#endif /* HAVE_USRP */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ce4432752..546fa3254 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -258,6 +258,13 @@ check_SCRIPTS = \
TESTS = $(check_SCRIPTS) $(DIRECT_TESTS)
+if HAVE_USRP
+check_PROGRAMS += testusrp
+TESTS += testusrp
+testusrp_SOURCES = testusrp.cc
+testusrp_LDADD = $(top_builddir)/rigs/kit/libhamlib-kit.la $(LDADD)
+endif
+
$(top_builddir)/src/libhamlib.la:
$(MAKE) -C $(top_builddir)/src/ libhamlib.la
diff --git a/tests/testusrp.cc b/tests/testusrp.cc
new file mode 100644
index 000000000..4444cb55d
--- /dev/null
+++ b/tests/testusrp.cc
@@ -0,0 +1,86 @@
+/*
+ * Hamlib USRP backend state tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/riglist.h"
+
+extern "C"
+{
+ extern struct rig_caps usrp_caps;
+}
+
+static int check_conf(RIG *rig, hamlib_token_t token, const char *expected)
+{
+ char value[64] = {};
+ int retval = rig_get_conf2(rig, token, value, sizeof(value));
+
+ if (retval != RIG_OK || strcmp(value, expected) != 0)
+ {
+ fprintf(stderr, "expected USRP if_mix_freq %s, got %s (%d)\n",
+ expected, value, retval);
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ RIG *rig;
+ hamlib_token_t token;
+ freq_t freq = 0;
+
+ rig_register(&usrp_caps);
+ rig = rig_init(RIG_MODEL_USRP);
+
+ if (rig == NULL)
+ {
+ fprintf(stderr, "failed to initialize USRP rig\n");
+ return 1;
+ }
+
+ token = rig_token_lookup(rig, "if_mix_freq");
+
+ if (token == RIG_CONF_END)
+ {
+ fprintf(stderr, "USRP if_mix_freq token was not registered\n");
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ if (check_conf(rig, token, "45000000") != 0)
+ {
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ if (rig_set_conf(rig, token, "12345678") != RIG_OK
+ || check_conf(rig, token, "12345678") != 0)
+ {
+ fprintf(stderr, "USRP if_mix_freq did not retain an override\n");
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ if (rig->caps->rig_close(rig) != RIG_OK
+ || rig->caps->set_freq(rig, RIG_VFO_A, 145000000) != -RIG_EIO
+ || rig->caps->get_freq(rig, RIG_VFO_A, &freq) != -RIG_EIO)
+ {
+ fprintf(stderr, "USRP callbacks were not safe without a receiver\n");
+ rig_cleanup(rig);
+ return 1;
+ }
+
+ rig_cleanup(rig);
+ return 0;
+}
-----------------------------------------------------------------------
Summary of changes:
rigs/kit/usrp_impl.cc | 158 +++++++++++++++++++++++++++++++-------------------
tests/Makefile.am | 7 +++
tests/testusrp.cc | 86 +++++++++++++++++++++++++++
3 files changed, 191 insertions(+), 60 deletions(-)
create mode 100644 tests/testusrp.cc
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-21 19:48:47
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via f20d4df79d2ea697490c801ba4320348a2ef29bf (commit)
via a8aa0e229db40f4b937167c42d50c62b1bbb348a (commit)
from 9e224cc54a9bc04f8bce8afe076e4fd2ec152995 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f20d4df79d2ea697490c801ba4320348a2ef29bf
Merge: 9e224cc54 a8aa0e229
Author: Nate Bargmann <n0...@n0...>
Date: Mon Sep 21 12:19:28 2026 -0500
Merge GitHub PR #2158
commit a8aa0e229db40f4b937167c42d50c62b1bbb348a
Author: David Christle <dch...@us...>
Date: Sun Aug 16 22:29:14 2026 -0700
fix(yaesu): preserve legacy NewCAT bandwidth handling
FT-450, FT-450D, and FTDX9000 caps do not provide private
width tables. Shared width selection dereferenced the null caps before
the legacy mapping in both the mode set and get paths.
Centralize width-table selection behind a null-safe helper and cover
legacy USB and CW round trips with socket-backed tests.
Fixes: 4053430b621b ("More trading a little more data for less code")
Fixes: 6ad414dc8275 ("Start converting get_rx_bandwidth to common CW/RTTY/SSB handling")
diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c
index 19562027c..c0303edcd 100644
--- a/rigs/yaesu/newcat.c
+++ b/rigs/yaesu/newcat.c
@@ -727,6 +727,41 @@ static int newcat_get_index_from_width(pbwidth_t width,
return info->count - 1; // Not found, use the maximum
}
+static const struct newcat_width_info *newcat_width_info_for_mode(
+ const struct newcat_priv_caps *priv_caps, rmode_t mode)
+{
+ if (priv_caps == NULL)
+ {
+ return NULL;
+ }
+
+ switch (mode)
+ {
+ case RIG_MODE_RTTY:
+ case RIG_MODE_RTTYR:
+ if (priv_caps->rtty_widths != NULL)
+ {
+ return priv_caps->rtty_widths;
+ }
+
+ HL_FALLTHROUGH
+
+ case RIG_MODE_PKTUSB:
+ case RIG_MODE_PKTLSB:
+ case RIG_MODE_CW:
+ case RIG_MODE_CWR:
+ case RIG_MODE_PSK:
+ return priv_caps->cw_widths;
+
+ case RIG_MODE_LSB:
+ case RIG_MODE_USB:
+ return priv_caps->ssb_widths;
+
+ default:
+ return &dummy_widths;
+ }
+}
+
/*
* ************************************
*
@@ -8758,45 +8793,7 @@ int newcat_set_rx_bandwidth(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
// NOTE: RIG_PASSBAND_NORMAL (0) should select the default filter width (SH00)
- // Preselect set of possible widths
- switch (mode)
- {
- case RIG_MODE_RTTY:
- case RIG_MODE_RTTYR:
- width_info = priv_caps->rtty_widths; // Set RTTY data if different
- HL_FALLTHROUGH // Fall into CW
-
- case RIG_MODE_PKTUSB:
- case RIG_MODE_PKTLSB:
- case RIG_MODE_CW:
- case RIG_MODE_CWR:
- case RIG_MODE_PSK: // For FTX-1
- if (width_info == NULL)
- {
- width_info = priv_caps->cw_widths;
- }
-
- break;
-
- case RIG_MODE_LSB:
- case RIG_MODE_USB:
- width_info = priv_caps->ssb_widths;
- break;
-
-#if 0
-
- case RIG_MODE_AM:
- case RIG_MODE_FM:
- case RIG_MODE_PKTFM:
- case RIG_MODE_FMN:
- //????
- break;
-#endif
-
- default:
- width_info = &dummy_widths; // Just in case...
-
- }
+ width_info = newcat_width_info_for_mode(priv_caps, mode);
if (is_ft950)
{
@@ -9507,44 +9504,7 @@ int newcat_get_rx_bandwidth(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t *width)
main_sub_vfo = (RIG_VFO_B == vfo || RIG_VFO_SUB == vfo) ? '1' : '0';
}
- // Preselect set of possible widths
- switch (mode)
- {
- case RIG_MODE_RTTY:
- case RIG_MODE_RTTYR:
- width_info = priv_caps->rtty_widths; // Set RTTY data if different
- HL_FALLTHROUGH // Fall into CW
-
- case RIG_MODE_PKTUSB:
- case RIG_MODE_PKTLSB:
- case RIG_MODE_CW:
- case RIG_MODE_CWR:
- case RIG_MODE_PSK: // For FTX-1
- if (width_info == NULL)
- {
- width_info = priv_caps->cw_widths;
- }
-
- break;
-
- case RIG_MODE_LSB:
- case RIG_MODE_USB:
- width_info = priv_caps->ssb_widths;
- break;
-
-#if 0
-
- case RIG_MODE_AM:
- case RIG_MODE_FM:
- case RIG_MODE_PKTFM:
- case RIG_MODE_FMN:
- //????
- break;
-#endif
-
- default:
- width_info = &dummy_widths; // Just in case...
- }
+ width_info = newcat_width_info_for_mode(priv_caps, mode);
if (sh_command_valid)
{
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ce4432752..c0ed671db 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -35,6 +35,7 @@ DIRECT_TESTS = \
testicomts \
testpoll \
testnewcatset \
+ testnewcatwidth \
testrigctlprotocol \
testmodecompat \
testthd7x \
@@ -136,6 +137,7 @@ testnewcatset_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testicomfallback_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testelecraftvfo_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testts990s_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+testnewcatwidth_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
testicomts_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testid5100_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
testicomfallback_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/rigs/icom
@@ -194,6 +196,7 @@ testftx1parsers_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testft991idmeter_LDADD = $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
testguohetec_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/guohetec/libhamlib-guohetec.la $(LDADD)
testnewcatset_LDADD = $(NET_LIBS) $(PTHREAD_LIBS) $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
+testnewcatwidth_LDADD = $(PTHREAD_LIBS) $(top_builddir)/rigs/yaesu/libhamlib-yaesu.la $(LDADD)
if TESTS_HAVE_LIBUSB
rigtestlibusb_LDADD = $(LIBUSB_LIBS)
endif
diff --git a/tests/testnewcatwidth.c b/tests/testnewcatwidth.c
new file mode 100644
index 000000000..5c943cfa9
--- /dev/null
+++ b/tests/testnewcatwidth.c
@@ -0,0 +1,286 @@
+/*
+ * Hamlib Yaesu NewCAT legacy bandwidth tests
+ * Copyright (c) 2026 by Hamlib Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#ifdef _WIN32
+
+#include <stdio.h>
+
+int main(void)
+{
+ printf("testnewcatwidth: skipped, requires socketpair()\n");
+ return 77;
+}
+
+#else
+
+#include <poll.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#include "hamlib/rig.h"
+#include "hamlib/port.h"
+#include "hamlib/rig_state.h"
+
+extern struct rig_caps ft450_caps;
+extern struct rig_caps ft9000_caps;
+
+enum test_operation
+{
+ TEST_SET_MODE,
+ TEST_GET_MODE
+};
+
+struct peer_case
+{
+ int fd;
+ const char *mode_command;
+ const char *mode_response;
+ const char *width_command;
+ const char *width_response;
+ int status;
+};
+
+struct width_case
+{
+ const char *name;
+ rig_model_t model;
+ enum test_operation operation;
+ rmode_t mode;
+ pbwidth_t width;
+ const char *mode_command;
+ const char *mode_response;
+ const char *width_command;
+ const char *width_response;
+};
+
+static int read_frame(int fd, char *buffer, size_t capacity)
+{
+ size_t used = 0;
+
+ while (used + 1 < capacity)
+ {
+ struct pollfd descriptor = { .fd = fd, .events = POLLIN };
+ ssize_t count;
+
+ if (poll(&descriptor, 1, 2000) != 1)
+ {
+ return -1;
+ }
+
+ count = read(fd, buffer + used, 1);
+
+ if (count != 1)
+ {
+ return -1;
+ }
+
+ if (buffer[used++] == ';')
+ {
+ buffer[used] = '\0';
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+static int write_all(int fd, const char *buffer)
+{
+ size_t length = strlen(buffer);
+ size_t written = 0;
+
+ while (written < length)
+ {
+ ssize_t count = write(fd, buffer + written, length - written);
+
+ if (count <= 0)
+ {
+ return -1;
+ }
+
+ written += (size_t)count;
+ }
+
+ return 0;
+}
+
+static int exchange(int fd, const char *expected, const char *response)
+{
+ char command[32];
+
+ if (read_frame(fd, command, sizeof(command)) != 0
+ || strcmp(command, expected) != 0)
+ {
+ return -1;
+ }
+
+ if (response != NULL && write_all(fd, response) != 0)
+ {
+ return -1;
+ }
+
+ return 0;
+}
+
+static void *run_peer(void *arg)
+{
+ struct peer_case *test = arg;
+
+ test->status = -1;
+
+ if (exchange(test->fd, test->mode_command,
+ test->mode_response) != 0
+ || exchange(test->fd, test->width_command,
+ test->width_response) != 0)
+ {
+ return NULL;
+ }
+
+ test->status = 0;
+ return NULL;
+}
+
+static int run_case(const struct width_case *test_case)
+{
+ int sockets[2];
+ pthread_t thread;
+ struct peer_case peer =
+ {
+ .fd = -1,
+ .mode_command = test_case->mode_command,
+ .mode_response = test_case->mode_response,
+ .width_command = test_case->width_command,
+ .width_response = test_case->width_response,
+ .status = -1
+ };
+ RIG *rig;
+ rmode_t mode = test_case->mode;
+ pbwidth_t width = test_case->width;
+ int retval;
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) != 0)
+ {
+ perror("socketpair");
+ return 1;
+ }
+
+ rig = rig_init(test_case->model);
+
+ if (rig == NULL)
+ {
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ RIGPORT(rig)->fd = sockets[0];
+ RIGPORT(rig)->timeout = 100;
+ RIGPORT(rig)->retry = 0;
+ STATE(rig)->powerstat = RIG_POWER_ON;
+ peer.fd = sockets[1];
+
+ if (pthread_create(&thread, NULL, run_peer, &peer) != 0)
+ {
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+ return 1;
+ }
+
+ if (test_case->operation == TEST_SET_MODE)
+ {
+ retval = rig->caps->set_mode(rig, RIG_VFO_A, mode, width);
+ }
+ else
+ {
+ mode = RIG_MODE_NONE;
+ width = RIG_PASSBAND_NORMAL;
+ retval = rig->caps->get_mode(rig, RIG_VFO_A, &mode, &width);
+ }
+
+ pthread_join(thread, NULL);
+ RIGPORT(rig)->fd = -1;
+ rig_cleanup(rig);
+ close(sockets[0]);
+ close(sockets[1]);
+
+ if (peer.status != 0 || retval != RIG_OK
+ || mode != test_case->mode || width != test_case->width)
+ {
+ fprintf(stderr,
+ "%s: expected %d/%s/%d, got %d/%s/%d (peer %d)\n",
+ test_case->name, RIG_OK, rig_strrmode(test_case->mode),
+ (int)test_case->width, retval, rig_strrmode(mode),
+ (int)width, peer.status);
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(void)
+{
+ static const struct width_case cases[] =
+ {
+ {
+ "FT-450 set USB", RIG_MODEL_FT450, TEST_SET_MODE,
+ RIG_MODE_USB, 2400, "MD02;", NULL, "SH016;", NULL
+ },
+ {
+ "FT-450 get USB", RIG_MODEL_FT450, TEST_GET_MODE,
+ RIG_MODE_USB, 2400, "MD0;", "MD02;", "SH0;", "SH016;"
+ },
+ {
+ "FT-450 set CW", RIG_MODEL_FT450, TEST_SET_MODE,
+ RIG_MODE_CW, 500, "MD03;", NULL, "SH006;", NULL
+ },
+ {
+ "FT-450 get CW", RIG_MODEL_FT450, TEST_GET_MODE,
+ RIG_MODE_CW, 500, "MD0;", "MD03;", "SH0;", "SH006;"
+ },
+ {
+ "FTDX-9000 set USB", RIG_MODEL_FT9000, TEST_SET_MODE,
+ RIG_MODE_USB, 2400, "MD02;", NULL, "SH016;", NULL
+ },
+ {
+ "FTDX-9000 get USB", RIG_MODEL_FT9000, TEST_GET_MODE,
+ RIG_MODE_USB, 2400, "MD0;", "MD02;", "SH0;", "SH016;"
+ },
+ {
+ "FTDX-9000 set CW", RIG_MODEL_FT9000, TEST_SET_MODE,
+ RIG_MODE_CW, 500, "MD03;", NULL, "SH006;", NULL
+ },
+ {
+ "FTDX-9000 get CW", RIG_MODEL_FT9000, TEST_GET_MODE,
+ RIG_MODE_CW, 500, "MD0;", "MD03;", "SH0;", "SH006;"
+ }
+ };
+ size_t i;
+
+ rig_set_debug(RIG_DEBUG_NONE);
+ rig_register(&ft450_caps);
+ rig_register(&ft9000_caps);
+
+ for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+ {
+ if (run_case(&cases[i]) != 0)
+ {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+#endif /* !_WIN32 */
-----------------------------------------------------------------------
Summary of changes:
rigs/yaesu/newcat.c | 114 +++++++------------
tests/Makefile.am | 3 +
tests/testnewcatwidth.c | 286 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 326 insertions(+), 77 deletions(-)
create mode 100644 tests/testnewcatwidth.c
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-21 13:28:18
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 9e224cc54a9bc04f8bce8afe076e4fd2ec152995 (commit)
via 96ba014a9b0f208f5ba0e8b49c06c0dac6430ed7 (commit)
via f3db0910413a7783af0c2a0a8f95bad2ffc45fb7 (commit)
from 79b5e29d8d903ba6882fb9febdbb3e724c434227 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9e224cc54a9bc04f8bce8afe076e4fd2ec152995
Author: David Christle <dch...@us...>
Date: Sun Aug 16 19:16:40 2026 -0700
fix(rigctld): clean up client thread launch failures
Destroy detached-thread attributes after every initialized launch attempt. Close the accepted socket and release its connection data when attribute setup or pthread_create fails, using the portable socket helper on all early rejection paths.
diff --git a/tests/rigctld.c b/tests/rigctld.c
index e7b6d46f8..87b5d2d92 100644
--- a/tests/rigctld.c
+++ b/tests/rigctld.c
@@ -300,7 +300,6 @@ int main(int argc, char *argv[])
#endif
pthread_t thread;
- pthread_attr_t attr;
int vfo_mode = 0; /* vfo_mode=0 means target VFO is current VFO */
int i;
extern int is_rigctld;
@@ -1202,6 +1201,8 @@ int main(int argc, char *argv[])
else
{
struct handle_data *arg;
+ pthread_attr_t attr;
+ int attr_ret;
arg = calloc(1, sizeof(struct handle_data));
@@ -1247,7 +1248,7 @@ int main(int argc, char *argv[])
"Connection from %s:%s rejected — "
"max clients (%d) reached\n",
host, serv, RIGCTLD_MAX_CLIENTS);
- close(arg->sock);
+ socket_close(arg->sock);
free(arg);
continue;
}
@@ -1258,14 +1259,51 @@ int main(int argc, char *argv[])
"Connection opened from %s:%s (client %d)\n",
host, serv, arg->client_id);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ attr_ret = pthread_attr_init(&attr);
+
+ if (attr_ret != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_init: %s\n",
+ strerror(attr_ret));
+ socket_close(arg->sock);
+ free(arg);
+ break;
+ }
+
+ attr_ret = pthread_attr_setdetachstate(&attr,
+ PTHREAD_CREATE_DETACHED);
+
+ if (attr_ret != 0)
+ {
+ rig_debug(RIG_DEBUG_ERR, "pthread_attr_setdetachstate: %s\n",
+ strerror(attr_ret));
+ int destroy_ret = pthread_attr_destroy(&attr);
+
+ if (destroy_ret != 0)
+ {
+ rig_debug(RIG_DEBUG_WARN, "pthread_attr_destroy: %s\n",
+ strerror(destroy_ret));
+ }
+
+ socket_close(arg->sock);
+ free(arg);
+ break;
+ }
retcode = pthread_create(&thread, &attr, handle_socket, arg);
+ attr_ret = pthread_attr_destroy(&attr);
+
+ if (attr_ret != 0)
+ {
+ rig_debug(RIG_DEBUG_WARN, "pthread_attr_destroy: %s\n",
+ strerror(attr_ret));
+ }
if (retcode != 0)
{
rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
+ socket_close(arg->sock);
+ free(arg);
break;
}
commit 96ba014a9b0f208f5ba0e8b49c06c0dac6430ed7
Author: David Christle <dch...@us...>
Date: Sun Aug 16 19:15:34 2026 -0700
fix(rigctld): guard stream handles during control calls
Feeder auto-close can free a backend stream after a registry lookup unlocks but before the public API acquires its lifetime guard. Keep the registry lock through pause, resume, and drain calls, and verify the invariant with backend probe hooks.
diff --git a/test/test_rigctld_commands.c b/test/test_rigctld_commands.c
index 7a0261859..7c37e2e7a 100644
--- a/test/test_rigctld_commands.c
+++ b/test/test_rigctld_commands.c
@@ -3510,6 +3510,87 @@ void test_tx_metadata_truncated_rejected(void)
/* --- Stream control command tests --- */
+static int registry_lock_observed;
+
+
+static int stream_control_lock_probe(RIG *rig, struct rig_stream *stream)
+{
+ int ret;
+
+ (void)rig;
+ (void)stream;
+ ret = pthread_mutex_trylock(&g_stream_registry.lock);
+ registry_lock_observed = ret == EBUSY;
+
+ if (ret == 0)
+ {
+ pthread_mutex_unlock(&g_stream_registry.lock);
+ }
+
+ return RIG_OK;
+}
+
+
+static int stream_drain_lock_probe(RIG *rig, struct rig_stream *stream,
+ int timeout_ms)
+{
+ (void)timeout_ms;
+ return stream_control_lock_probe(rig, stream);
+}
+
+
+void test_cmd_stream_controls_hold_registry_lock(void)
+{
+ RIG *rig = stream_test_begin();
+ char buf[1024];
+ char cmd[64];
+ int stream_id = -1;
+ int udp_port = -1;
+
+ TEST_ASSERT(rig != NULL);
+
+ struct rig_caps probe_caps = *rig->caps;
+ probe_caps.stream_pause = stream_control_lock_probe;
+ probe_caps.stream_resume = stream_control_lock_probe;
+ probe_caps.stream_drain = stream_drain_lock_probe;
+ rig->caps = &probe_caps;
+
+ int ret = run_cmd(rig, "\\stream_open AUDIO_TX PCM_S16 48000",
+ buf, sizeof(buf));
+ TEST_CHECK(ret == RIG_OK);
+
+ if (ret == RIG_OK)
+ {
+ TEST_CHECK(parse_open_response(buf, &stream_id, &udp_port) == 0);
+ }
+
+ if (stream_id >= 0)
+ {
+ registry_lock_observed = 0;
+ snprintf(cmd, sizeof(cmd), "\\stream_pause %d", stream_id);
+ TEST_CHECK(run_cmd(rig, cmd, buf, sizeof(buf)) == RIG_OK);
+ TEST_CHECK(registry_lock_observed);
+
+ registry_lock_observed = 0;
+ snprintf(cmd, sizeof(cmd), "\\stream_resume %d", stream_id);
+ TEST_CHECK(run_cmd(rig, cmd, buf, sizeof(buf)) == RIG_OK);
+ TEST_CHECK(registry_lock_observed);
+
+ registry_lock_observed = 0;
+ snprintf(cmd, sizeof(cmd), "\\stream_drain %d", stream_id);
+ TEST_CHECK(run_cmd(rig, cmd, buf, sizeof(buf)) == RIG_OK);
+ TEST_CHECK(registry_lock_observed);
+ }
+
+ if (stream_id >= 0)
+ {
+ snprintf(cmd, sizeof(cmd), "\\stream_close %d", stream_id);
+ run_cmd(rig, cmd, buf, sizeof(buf));
+ }
+
+ stream_test_end(rig);
+}
+
void test_cmd_stream_pause_resume(void)
{
RIG *rig = stream_test_begin();
@@ -6139,6 +6220,8 @@ TEST_LIST =
{ "tx_metadata_truncated_rejected", test_tx_metadata_truncated_rejected },
/* Stream control commands */
+ { "cmd_stream_controls_hold_registry_lock",
+ test_cmd_stream_controls_hold_registry_lock },
{ "cmd_stream_pause_resume", test_cmd_stream_pause_resume },
{ "cmd_stream_mute_unmute", test_cmd_stream_mute_unmute },
{ "cmd_stream_pause_not_found", test_cmd_stream_pause_not_found },
diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c
index f77869667..e43c877af 100644
--- a/tests/rigctl_parse.c
+++ b/tests/rigctl_parse.c
@@ -7325,13 +7325,10 @@ declare_proto_rig(stream_pause)
if (!stream) { RETURNFUNC2(err); }
- /* Release the registry lock before the (possibly blocking) backend call so
- * one client's pause cannot stall every other client's stream command. The
- * backend stream cannot be freed underneath us: rig_stream_close() drains
- * its in-use count, which this call holds for its duration. */
- rig_stream_t *backend = stream->backend_stream;
+ /* Keep the registry-owned handle pinned until the public API has entered
+ * and released its internal stream-lifetime guard. */
+ retval = rig_stream_pause(rig, stream->backend_stream);
rigctld_stream_registry_unlock(&g_stream_registry);
- retval = rig_stream_pause(rig, backend);
RETURNFUNC2(retval);
}
@@ -7349,10 +7346,8 @@ declare_proto_rig(stream_resume)
if (!stream) { RETURNFUNC2(err); }
- /* See stream_pause: drop the registry lock before the backend call. */
- rig_stream_t *backend = stream->backend_stream;
+ retval = rig_stream_resume(rig, stream->backend_stream);
rigctld_stream_registry_unlock(&g_stream_registry);
- retval = rig_stream_resume(rig, backend);
RETURNFUNC2(retval);
}
@@ -7457,11 +7452,8 @@ declare_proto_rig(stream_drain)
if (!stream) { RETURNFUNC2(err); }
- /* See stream_pause: drop the registry lock before the 1 s flush so it does
- * not stall every other client's stream command for its whole duration. */
- rig_stream_t *backend = stream->backend_stream;
+ retval = rig_stream_drain(rig, stream->backend_stream, 1000);
rigctld_stream_registry_unlock(&g_stream_registry);
- retval = rig_stream_drain(rig, backend, 1000);
RETURNFUNC2(retval);
}
commit f3db0910413a7783af0c2a0a8f95bad2ffc45fb7
Author: David Christle <dch...@us...>
Date: Sun Aug 16 16:43:24 2026 -0700
fix(rigctld): quiesce stream feeders before rig close
rig_close() frees backend stream handles while rigctld feeders may still use them, allowing an idle client disconnect to trigger a use-after-free.
Centralize rig shutdown behind registry-wide feeder teardown and close client-owned streams before the last-client idle transition. Add registry and end-to-end regression coverage for abrupt disconnect and reopen.
diff --git a/test/test_netrigctl_stream.c b/test/test_netrigctl_stream.c
index cddcc5af3..5465eb0c5 100644
--- a/test/test_netrigctl_stream.c
+++ b/test/test_netrigctl_stream.c
@@ -71,6 +71,7 @@ struct rigctld_proc
{
pid_t pid;
int port;
+ int idle;
char log_path[64];
};
@@ -279,6 +280,9 @@ static int start_rigctld_once(struct rigctld_proc *proc,
if (proc->pid == 0)
{
+ char *child_argv[16];
+ int child_argc = 0;
+
/* Child: silence stdout, but capture stderr in a per-daemon log;
* /dev/null for stderr made failures undiagnosable. On redirect
* failure the inherited stream simply stays in place. */
@@ -289,28 +293,32 @@ static int start_rigctld_once(struct rigctld_proc *proc,
if (freopen("/dev/null", "w", stderr) == NULL) {}
}
- if (source_id_opt && set_conf_opt)
- {
- execlp(rigctld_path, "rigctld", "-m", "1", "-t", port_str, verbosity,
- "--stream-source-id", source_id_opt,
- "--set-conf", set_conf_opt, NULL);
- }
- else if (source_id_opt)
+ child_argv[child_argc++] = (char *)"rigctld";
+ child_argv[child_argc++] = (char *)"-m";
+ child_argv[child_argc++] = (char *)"1";
+ child_argv[child_argc++] = (char *)"-t";
+ child_argv[child_argc++] = port_str;
+ child_argv[child_argc++] = (char *)verbosity;
+
+ if (proc->idle)
{
- execlp(rigctld_path, "rigctld", "-m", "1", "-t", port_str, verbosity,
- "--stream-source-id", source_id_opt, NULL);
+ child_argv[child_argc++] = (char *)"-R";
}
- else if (set_conf_opt)
+
+ if (source_id_opt)
{
- execlp(rigctld_path, "rigctld", "-m", "1", "-t", port_str, verbosity,
- "--set-conf", set_conf_opt, NULL);
+ child_argv[child_argc++] = (char *)"--stream-source-id";
+ child_argv[child_argc++] = (char *)source_id_opt;
}
- else
+
+ if (set_conf_opt)
{
- execlp(rigctld_path, "rigctld", "-m", "1", "-t", port_str, verbosity,
- NULL);
+ child_argv[child_argc++] = (char *)"--set-conf";
+ child_argv[child_argc++] = (char *)set_conf_opt;
}
+ child_argv[child_argc] = NULL;
+ execvp(rigctld_path, child_argv);
_exit(127);
}
@@ -333,6 +341,13 @@ static int start_rigctld(struct rigctld_proc *proc)
}
+static int start_idle_rigctld(struct rigctld_proc *proc)
+{
+ proc->idle = 1;
+ return start_rigctld_opt(proc, NULL, NULL);
+}
+
+
/* Replay the daemon's captured stderr into ours so a CI log shows why a
* subscribe or event was dropped; silent when the daemon logged nothing. */
static void dump_rigctld_log(const char *path)
@@ -2688,6 +2703,226 @@ static int query_source_id_raw(int port)
}
+struct raw_stream_connection
+{
+ int tcp_sock;
+ int udp_sock;
+};
+
+
+static int send_all(int sock, const void *buf, size_t len)
+{
+ const unsigned char *p = buf;
+
+ while (len > 0)
+ {
+ ssize_t n = send(sock, p, len, 0);
+
+ if (n <= 0)
+ {
+ return -1;
+ }
+
+ p += n;
+ len -= (size_t)n;
+ }
+
+ return 0;
+}
+
+
+static int raw_stream_open_once(int port, struct raw_stream_connection *conn)
+{
+ struct sockaddr_in addr;
+ const char *cmd = "+\\stream_open AUDIO_RX PCM_S16 48000\n";
+ char response[1024] = "";
+ size_t total = 0;
+ int stream_id = -1;
+ int udp_port = -1;
+ unsigned int subscribe_token = 0;
+
+ conn->tcp_sock = -1;
+ conn->udp_sock = -1;
+ conn->tcp_sock = socket(AF_INET, SOCK_STREAM, 0);
+
+ if (conn->tcp_sock < 0)
+ {
+ return -1;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ addr.sin_port = htons(port);
+
+ if (connect(conn->tcp_sock, (struct sockaddr *)&addr, sizeof(addr)) < 0
+ || send_all(conn->tcp_sock, cmd, strlen(cmd)) < 0)
+ {
+ goto fail;
+ }
+
+ while (total < sizeof(response) - 1 && strstr(response, "RPRT") == NULL)
+ {
+ fd_set fds;
+ struct timeval tv = { 3, 0 };
+ FD_ZERO(&fds);
+ FD_SET(conn->tcp_sock, &fds);
+
+ if (select(conn->tcp_sock + 1, &fds, NULL, NULL, &tv) <= 0)
+ {
+ goto fail;
+ }
+
+ ssize_t n = recv(conn->tcp_sock, response + total,
+ sizeof(response) - 1 - total, 0);
+
+ if (n <= 0)
+ {
+ goto fail;
+ }
+
+ total += (size_t)n;
+ response[total] = '\0';
+ }
+
+ const char *id_line = strstr(response, "stream_id: ");
+ const char *port_line = strstr(response, "udp_port: ");
+ const char *token_line = strstr(response, "subscribe_token: ");
+
+ if (!strstr(response, "RPRT 0") || !id_line || !port_line || !token_line
+ || sscanf(id_line, "stream_id: %d", &stream_id) != 1
+ || sscanf(port_line, "udp_port: %d", &udp_port) != 1
+ || sscanf(token_line, "subscribe_token: %u", &subscribe_token) != 1)
+ {
+ goto fail;
+ }
+
+ conn->udp_sock = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (conn->udp_sock < 0)
+ {
+ goto fail;
+ }
+
+ unsigned char packet[RIG_STREAM_HEADER_SIZE];
+ struct rig_stream_packet_header hdr;
+ stream_control_header_init(&hdr, RIG_STREAM_TYPE_AUDIO_RX,
+ (uint16_t)stream_id, subscribe_token,
+ RIG_STREAM_CTRL_SUBSCRIBE);
+ stream_packet_header_pack(&hdr, packet);
+ addr.sin_port = htons((uint16_t)udp_port);
+
+ if (sendto(conn->udp_sock, packet, sizeof(packet), 0,
+ (struct sockaddr *)&addr, sizeof(addr)) != (ssize_t)sizeof(packet))
+ {
+ goto fail;
+ }
+
+ fd_set fds;
+ struct timeval tv = { 3, 0 };
+ FD_ZERO(&fds);
+ FD_SET(conn->udp_sock, &fds);
+
+ if (select(conn->udp_sock + 1, &fds, NULL, NULL, &tv) <= 0)
+ {
+ goto fail;
+ }
+
+ ssize_t n = recv(conn->udp_sock, packet, sizeof(packet), 0);
+
+ if (n < RIG_STREAM_HEADER_SIZE
+ || stream_packet_header_unpack(packet, (size_t)n, &hdr) != 0
+ || hdr.stream_id != stream_id
+ || hdr.subscribe_token != subscribe_token
+ || !(hdr.control & RIG_STREAM_CTRL_SUBSCRIBE_ACK))
+ {
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+
+ if (conn->udp_sock >= 0)
+ {
+ close(conn->udp_sock);
+ conn->udp_sock = -1;
+ }
+
+ if (conn->tcp_sock >= 0)
+ {
+ close(conn->tcp_sock);
+ conn->tcp_sock = -1;
+ }
+
+ return -1;
+}
+
+
+static int raw_stream_open(int port, struct raw_stream_connection *conn)
+{
+ for (int attempt = 0; attempt < 3; attempt++)
+ {
+ if (raw_stream_open_once(port, conn) == 0)
+ {
+ return 0;
+ }
+
+ usleep(100000);
+ }
+
+ return -1;
+}
+
+
+/* In idle mode the last control disconnect closes the backend rig. A live RX
+ * feeder must be joined before that close, even when the client never sends
+ * stream_close. */
+void test_idle_abrupt_disconnect_closes_stream(void)
+{
+ struct rigctld_proc proc = {0};
+ struct raw_stream_connection first = { -1, -1 };
+ struct raw_stream_connection reopened = { -1, -1 };
+
+ if (start_idle_rigctld(&proc) < 0)
+ {
+ TEST_CHECK_(0, "could not start idle rigctld");
+ return;
+ }
+
+ int opened = raw_stream_open(proc.port, &first);
+ TEST_CHECK(opened == 0);
+
+ if (opened < 0)
+ {
+ stop_rigctld(&proc);
+ return;
+ }
+
+ /* Drop the control session without a stream_close command. */
+ close(first.tcp_sock);
+ close(first.udp_sock);
+ usleep(250000);
+
+ TEST_CHECK(rigctld_alive(&proc));
+ opened = raw_stream_open(proc.port, &reopened);
+ TEST_CHECK(opened == 0);
+
+ if (reopened.tcp_sock >= 0)
+ {
+ close(reopened.tcp_sock);
+ }
+
+ if (reopened.udp_sock >= 0)
+ {
+ close(reopened.udp_sock);
+ }
+
+ usleep(250000);
+ stop_rigctld(&proc);
+}
+
+
/* rigctld --stream-source-id stamps the CLI value; without it a stable
* derived ID in 0x1000-0xFFFF is used, unchanged across a daemon restart
* on the same static configuration. */
@@ -2751,6 +2986,7 @@ TEST_LIST =
{ "open_close_reopen", test_open_close_reopen },
{ "rx_pause_resume", test_rx_pause_resume },
{ "tx_flush_forwards", test_tx_flush_forwards },
+ { "idle_abrupt_disconnect_closes_stream", test_idle_abrupt_disconnect_closes_stream },
{ "stream_source_id_cli_and_derived", test_stream_source_id_cli_and_derived },
{ "subscribe_retransmits_after_loss", test_subscribe_retransmits_after_loss },
{ "subscribe_ignores_non_ack_first", test_subscribe_ignores_non_ack_first },
diff --git a/test/test_rigctld_stream.c b/test/test_rigctld_stream.c
index 6b3d3d8b2..19296dd84 100644
--- a/test/test_rigctld_stream.c
+++ b/test/test_rigctld_stream.c
@@ -864,6 +864,92 @@ void test_registry_close_by_client(void)
}
+void test_registry_close_all(void)
+{
+ struct rigctld_stream_registry reg;
+ rigctld_stream_registry_init(®);
+
+ struct rigctld_stream *s1 = rigctld_stream_alloc();
+ struct rigctld_stream *s2 = rigctld_stream_alloc();
+ struct rigctld_stream *s3 = rigctld_stream_alloc();
+ TEST_ASSERT(s1 != NULL && s2 != NULL && s3 != NULL);
+
+ s1->stream_id = 1;
+ s1->type = RIG_STREAM_TYPE_AUDIO_RX;
+ s1->client_id = 10;
+ s2->stream_id = 2;
+ s2->type = RIG_STREAM_TYPE_AUDIO_TX;
+ s2->client_id = 20;
+ s3->stream_id = 3;
+ s3->type = RIG_STREAM_TYPE_IQ_RX;
+ s3->client_id = 10;
+
+ TEST_ASSERT(rigctld_stream_registry_insert(®, s1) == 0);
+ TEST_ASSERT(rigctld_stream_registry_insert(®, s2) == 0);
+ TEST_ASSERT(rigctld_stream_registry_insert(®, s3) == 0);
+
+ TEST_CHECK(rigctld_stream_registry_close_all(®) == 3);
+ TEST_CHECK(rigctld_stream_registry_count(®) == 0);
+ TEST_CHECK(rigctld_stream_registry_close_all(®) == 0);
+
+ /* Closing all leaves the registry initialized and reusable. */
+ struct rigctld_stream *replacement = rigctld_stream_alloc();
+ TEST_ASSERT(replacement != NULL);
+ replacement->stream_id = 4;
+ replacement->type = RIG_STREAM_TYPE_AUDIO_RX;
+ replacement->client_id = 30;
+ TEST_ASSERT(rigctld_stream_registry_insert(®, replacement) == 0);
+ TEST_CHECK(rigctld_stream_registry_count(®) == 1);
+ TEST_CHECK(rigctld_stream_registry_close_all(®) == 1);
+
+ rigctld_stream_registry_destroy(®);
+}
+
+
+static HAMLIB_ATOMIC int close_all_feeder_exited;
+
+
+static void *close_all_test_feeder(void *arg)
+{
+ struct rigctld_stream *stream = arg;
+
+ while (stream->running)
+ {
+ usleep(1000);
+ }
+
+ close_all_feeder_exited = 1;
+ return NULL;
+}
+
+
+void test_registry_close_all_stops_feeder(void)
+{
+ struct rigctld_stream_registry reg;
+ struct rigctld_stream *stream;
+
+ rigctld_stream_registry_init(®);
+ stream = rigctld_stream_alloc();
+ TEST_ASSERT(stream != NULL);
+
+ stream->stream_id = 1;
+ stream->type = RIG_STREAM_TYPE_AUDIO_RX;
+ stream->client_id = 10;
+ stream->running = 1;
+ close_all_feeder_exited = 0;
+ TEST_ASSERT(pthread_create(&stream->feeder_thread, NULL,
+ close_all_test_feeder, stream) == 0);
+ stream->feeder_started = 1;
+ TEST_ASSERT(rigctld_stream_registry_insert(®, stream) == 0);
+
+ TEST_CHECK(rigctld_stream_registry_close_all(®) == 1);
+ TEST_CHECK(close_all_feeder_exited == 1);
+ TEST_CHECK(rigctld_stream_registry_count(®) == 0);
+
+ rigctld_stream_registry_destroy(®);
+}
+
+
void test_registry_insert_full(void)
{
struct rigctld_stream_registry reg;
@@ -2857,6 +2943,8 @@ TEST_LIST =
{ "registry_remove", test_registry_remove },
{ "registry_multiple_types", test_registry_multiple_types },
{ "registry_close_by_client", test_registry_close_by_client },
+ { "registry_close_all", test_registry_close_all },
+ { "registry_close_all_stops_feeder", test_registry_close_all_stops_feeder },
{ "registry_insert_full", test_registry_insert_full },
{ "stream_alloc_defaults", test_stream_alloc_defaults },
diff --git a/tests/rigctld.c b/tests/rigctld.c
index f9329ba76..e7b6d46f8 100644
--- a/tests/rigctld.c
+++ b/tests/rigctld.c
@@ -180,6 +180,19 @@ void mutex_rigctld(int lock)
}
+
+/* The daemon registry owns feeder threads that retain rig_stream_t handles.
+ * They must be gone before rig_close() invalidates the rig's stream state. */
+static int rigctld_close_rig(void)
+{
+ int retcode;
+
+ rigctld_stream_registry_close_all(&g_stream_registry);
+ retcode = rig_close(my_rig);
+ rig_opened = 0;
+ return retcode;
+}
+
#ifdef WIN32
static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
{
@@ -881,7 +894,7 @@ int main(int argc, char *argv[])
// So they need to release the rig when no clients are connected
if (rigctld_idle)
{
- rig_close(my_rig); /* we will reopen for clients */
+ rigctld_close_rig();
if (verbose > RIG_DEBUG_ERR)
{
@@ -1275,7 +1288,7 @@ int main(int argc, char *argv[])
#else
close(sock_listen);
#endif
- rig_close(my_rig);
+ rigctld_close_rig();
mutex_rigctld(0);
rigctld_stream_registry_destroy(&g_stream_registry);
@@ -1329,6 +1342,7 @@ void *handle_socket(void *arg)
char send_cmd_term = '\r'; /* send_cmd termination char */
int ext_resp = 0;
char my_resp_sep = resp_sep; // Separator for this connection, initial default
+ unsigned remaining_clients;
rig_powerstat = RIG_POWER_ON; // defaults to power on
struct timespec powerstat_check_time;
@@ -1455,8 +1469,7 @@ void *handle_socket(void *arg)
do
{
mutex_rigctld(1);
- retcode = rig_close(my_rig);
- rig_opened = 0;
+ retcode = rigctld_close_rig();
mutex_rigctld(0);
rig_debug(RIG_DEBUG_ERR, "%s: rig_close retcode=%d\n", __func__, retcode);
@@ -1480,18 +1493,19 @@ void *handle_socket(void *arg)
while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(retcode)));
mutex_rigctld(1);
+ rigctld_stream_registry_close_by_client(&g_stream_registry, my_client_id);
+ remaining_clients = --client_count;
- if (rigctld_idle && client_count == 1)
+ if (rigctld_idle && remaining_clients == 0)
{
- rig_close(my_rig);
+ rigctld_close_rig();
if (verbose > RIG_DEBUG_ERR) { printf("Closed rig model %s. Will reopen for new clients\n", my_rig->caps->model_name); }
}
- --client_count;
mutex_rigctld(0);
- if (rigctld_idle && client_count > 0) { printf("%u client%s still connected so rig remains open\n", client_count, client_count > 1 ? "s" : ""); }
+ if (rigctld_idle && remaining_clients > 0) { printf("%u client%s still connected so rig remains open\n", remaining_clients, remaining_clients > 1 ? "s" : ""); }
#if 0
mutex_rigctld(1);
@@ -1530,8 +1544,6 @@ void *handle_socket(void *arg)
host,
serv);
- rigctld_stream_registry_close_by_client(&g_stream_registry, my_client_id);
-
handle_exit:
// for MINGW we close the handle before fclose
diff --git a/tests/rigctld_stream.c b/tests/rigctld_stream.c
index 7bba175af..387fbd4e9 100644
--- a/tests/rigctld_stream.c
+++ b/tests/rigctld_stream.c
@@ -244,33 +244,7 @@ int rigctld_stream_registry_init(struct rigctld_stream_registry *reg)
void rigctld_stream_registry_destroy(struct rigctld_stream_registry *reg)
{
- int t, i;
-
- /* Collect all streams, then stop feeders outside lock to avoid deadlock */
- struct rigctld_stream *all[RIG_STREAM_TYPE_COUNT * RIGCTLD_MAX_STREAMS];
- int count = 0;
-
- pthread_mutex_lock(®->lock);
-
- for (t = 0; t < RIG_STREAM_TYPE_COUNT; t++)
- {
- for (i = 0; i < RIGCTLD_MAX_STREAMS; i++)
- {
- if (reg->streams[t][i] != NULL)
- {
- all[count++] = reg->streams[t][i];
- reg->streams[t][i] = NULL;
- }
- }
- }
-
- pthread_mutex_unlock(®->lock);
-
- for (i = 0; i < count; i++)
- {
- rigctld_stream_feeder_stop(all[i]);
- rigctld_stream_cleanup_resources(all[i]);
- }
+ rigctld_stream_registry_close_all(reg);
pthread_mutex_destroy(®->lock);
reg->initialized = 0;
@@ -475,8 +449,8 @@ void rigctld_stream_cleanup_resources(struct rigctld_stream *stream)
}
-int rigctld_stream_registry_close_by_client(struct rigctld_stream_registry *reg,
- int client_id)
+static int rigctld_stream_registry_close_matching(
+ struct rigctld_stream_registry *reg, int client_id, int close_all)
{
struct rigctld_stream *to_close[RIGCTLD_MAX_STREAMS * RIG_STREAM_TYPE_COUNT];
int close_count = 0;
@@ -490,7 +464,8 @@ int rigctld_stream_registry_close_by_client(struct rigctld_stream_registry *reg,
for (i = 0; i < RIGCTLD_MAX_STREAMS; i++)
{
if (reg->streams[t][i] != NULL
- && reg->streams[t][i]->client_id == client_id)
+ && (close_all
+ || reg->streams[t][i]->client_id == client_id))
{
to_close[close_count++] = reg->streams[t][i];
reg->streams[t][i] = NULL;
@@ -500,7 +475,15 @@ int rigctld_stream_registry_close_by_client(struct rigctld_stream_registry *reg,
pthread_mutex_unlock(®->lock);
- /* Full cleanup outside lock (feeder_stop may block on pthread_join) */
+ /* Wake every feeder before joining any of them so teardown latency is
+ * bounded by the slowest feeder rather than the sum of their waits. */
+ for (i = 0; i < close_count; i++)
+ {
+ to_close[i]->running = 0;
+ }
+
+ /* Full cleanup outside lock: a feeder may need the registry lock while
+ * auto-closing before pthread_join can complete. */
for (i = 0; i < close_count; i++)
{
rigctld_stream_feeder_stop(to_close[i]);
@@ -511,6 +494,19 @@ int rigctld_stream_registry_close_by_client(struct rigctld_stream_registry *reg,
}
+int rigctld_stream_registry_close_by_client(struct rigctld_stream_registry *reg,
+ int client_id)
+{
+ return rigctld_stream_registry_close_matching(reg, client_id, 0);
+}
+
+
+int rigctld_stream_registry_close_all(struct rigctld_stream_registry *reg)
+{
+ return rigctld_stream_registry_close_matching(reg, 0, 1);
+}
+
+
int rigctld_stream_registry_count(struct rigctld_stream_registry *reg)
{
int t, i;
diff --git a/tests/rigctld_stream.h b/tests/rigctld_stream.h
index 64ea7ca51..fe37f289e 100644
--- a/tests/rigctld_stream.h
+++ b/tests/rigctld_stream.h
@@ -229,6 +229,10 @@ struct rigctld_stream *rigctld_stream_registry_remove(
int rigctld_stream_registry_close_by_client(struct rigctld_stream_registry *reg,
int client_id);
+/* Remove and free every stream while leaving the registry reusable.
+ * Returns the number of streams closed. */
+int rigctld_stream_registry_close_all(struct rigctld_stream_registry *reg);
+
/* Count active streams in the registry. */
int rigctld_stream_registry_count(struct rigctld_stream_registry *reg);
-----------------------------------------------------------------------
Summary of changes:
test/test_netrigctl_stream.c | 266 ++++++++++++++++++++++++++++++++++++++++---
test/test_rigctld_commands.c | 83 ++++++++++++++
test/test_rigctld_stream.c | 88 ++++++++++++++
tests/rigctl_parse.c | 18 +--
tests/rigctld.c | 78 ++++++++++---
tests/rigctld_stream.c | 58 +++++-----
tests/rigctld_stream.h | 4 +
7 files changed, 522 insertions(+), 73 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-20 23:01:29
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 79b5e29d8d903ba6882fb9febdbb3e724c434227 (commit)
via c4001176a2a07dd4e3598364a99671eeac945ad6 (commit)
via 2cdc27a209f038c117a02dc70adba097b5d74a92 (commit)
via ea70993aa6f5ce368257fe4d644f1e39e4909038 (commit)
from 6614c5268b7fa7cc9f8e10b15bb169c3fc0b7047 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 79b5e29d8d903ba6882fb9febdbb3e724c434227
Merge: 6614c5268 c4001176a
Author: dforsi <iu...@gm...>
Date: Sun Sep 20 23:04:46 2026 +0200
Merge pull request #2217 from jonsnow1357/master
fix(ats-mini): make return codes negative
commit c4001176a2a07dd4e3598364a99671eeac945ad6
Merge: 2cdc27a20 d7864749e
Author: Jon Snow <518...@us...>
Date: Sat Sep 19 20:54:55 2026 -0400
Merge branch 'Hamlib:master' into master
commit 2cdc27a209f038c117a02dc70adba097b5d74a92
Merge: ea70993aa 8580f2e24
Author: Jon Snow <518...@us...>
Date: Wed Sep 16 20:36:44 2026 -0400
Merge branch 'Hamlib:master' into master
commit ea70993aa6f5ce368257fe4d644f1e39e4909038
Author: Jon Snow <jon...@gm...>
Date: Mon Sep 14 21:02:42 2026 -0400
make return codes negative
diff --git a/rigs/ats-mini/ats.c b/rigs/ats-mini/ats.c
index 741ba4d7b..2e0feb47c 100644
--- a/rigs/ats-mini/ats.c
+++ b/rigs/ats-mini/ats.c
@@ -34,10 +34,10 @@ static int p_ats_write(RIG *rig, const unsigned char *cmd) {
int res_uart = write_block(RIGPORT(rig), cmd, strlen((const char *)cmd));
if (res_uart != RIG_OK) {
rig_debug(RIG_DEBUG_ERR, "%s: write_block failed: %d\n", __func__, res_uart);
- return RIG_EIO;
+ return -RIG_EIO;
}
usleep(MINI_UART_CMD_DLY * 1000);
- return res_uart;
+ return RIG_OK;
}
static int p_ats_update_state(RIG *rig) {
@@ -57,7 +57,7 @@ static int p_ats_update_state(RIG *rig) {
if (to > MINI_UART_TO_CNT) {
rig_debug(RIG_DEBUG_ERR, "%s: read_block TIMEOUT\n", __func__);
- return RIG_ETIMEOUT;
+ return -RIG_ETIMEOUT;
}
if (nb_uart <= 0) {
// rig_debug(RIG_DEBUG_ERR, "%s: read_block failed: %d\n", __func__, n_b);
@@ -83,7 +83,7 @@ static int p_ats_update_state(RIG *rig) {
struct ats_mini_mon_data *tmp_mon_data = (struct ats_mini_mon_data *)
calloc(1, sizeof(struct ats_mini_mon_data));
if (!tmp_mon_data) {
- return RIG_ENOMEM;
+ return -RIG_ENOMEM;
}
idx = 0;
@@ -101,7 +101,7 @@ static int p_ats_update_state(RIG *rig) {
if (strlen(token) >= MINI_BANDNAME_LEN) {
rig_debug(RIG_DEBUG_ERR, "UNEXPECTED bandname");
free(tmp_mon_data);
- return RIG_EPROTO;
+ return -RIG_EPROTO;
}
memcpy(tmp_mon_data->bandname, token, (MINI_BANDNAME_LEN - 1));
break;
@@ -154,7 +154,7 @@ static int p_ats_update_state(RIG *rig) {
if (idx > MINI_UART_MAX_TOKEN) {
rig_debug(RIG_DEBUG_ERR, "%s: parse failure\n", __func__);
free(tmp_mon_data);
- return RIG_EPROTO;
+ return -RIG_EPROTO;
}
}
@@ -206,7 +206,7 @@ static int p_ats_set_band(RIG *rig, mini_band_id_t band_id) {
if (strcmp(mon_data->bandname, start_bandname) == 0) {
rig_debug(RIG_DEBUG_ERR, "%s: CANNOT switch band\n", __func__);
- return RIG_EINVAL;
+ return -RIG_EINVAL;
}
};
@@ -217,7 +217,7 @@ static int p_ats_set_mode(RIG *rig, rmode_t mode_id) {
if ((mode_id != RIG_MODE_AM) && (mode_id != RIG_MODE_USB) && (mode_id != RIG_MODE_LSB)
&& ( mode_id != RIG_MODE_FM)) {
rig_debug(RIG_DEBUG_ERR, "%s: UNSUPPORTED mode\n", __func__);
- return RIG_EINVAL;
+ return -RIG_EINVAL;
}
struct ats_mini_mon_data *mon_data = STATE(rig)->priv;
@@ -246,7 +246,7 @@ static int p_ats_set_mode(RIG *rig, rmode_t mode_id) {
if (mon_data->mode == start_mode_id) {
rig_debug(RIG_DEBUG_ERR, "%s: CANNOT switch mode\n", __func__);
- return RIG_EINVAL;
+ return -RIG_EINVAL;
}
};
@@ -285,7 +285,7 @@ static int ats_mini_open(RIG *rig) {
if (!rig || !STATE(rig)) {
rig_debug(RIG_DEBUG_ERR, "%s: NULL rig or state\n", __func__);
- return RIG_EARG;
+ return -RIG_EARG;
}
// rig_debug(RIG_DEBUG_VERBOSE, "%s, flush UART\n", __func__);
@@ -423,9 +423,9 @@ struct rig_caps ats_mini_caps = {
RIG_MODEL(RIG_MODEL_ATS_MINI),
.model_name = "ATS Mini",
.mfg_name = "AMNVOLT",
- .version = "20260701.0",
+ .version = "20260901.0",
.copyright = "LGPL",
- .status = RIG_STATUS_ALPHA,
+ .status = RIG_STATUS_BETA,
.rig_type = RIG_TYPE_RECEIVER,
.ptt_type = RIG_PTT_NONE,
.dcd_type = RIG_DCD_NONE,
@@ -485,6 +485,10 @@ struct rig_caps ats_mini_caps = {
},
RIG_FRNG_END,
},
+ .tx_range_list1 =
+ {
+ RIG_FRNG_END,
+ },
.rx_range_list2 =
{
{
@@ -499,7 +503,7 @@ struct rig_caps ats_mini_caps = {
},
RIG_FRNG_END,
},
- .tx_range_list1 =
+ .tx_range_list2 =
{
RIG_FRNG_END,
},
-----------------------------------------------------------------------
Summary of changes:
rigs/ats-mini/ats.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-20 19:45:02
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via 13a7c0750f8d02cfadd8d4ebf28a953902832bb7 (commit)
via 5d9471dfbbe4f38542e5306b90d0eee91e524d23 (commit)
from 182c1984d7e917b906a2e49b662afb1966ec569e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 13a7c0750f8d02cfadd8d4ebf28a953902832bb7
Author: Nate Bargmann <n0...@n0...>
Date: Sun Sep 20 14:44:08 2026 -0500
Update NEWS for FTX-1 DCS fix
diff --git a/NEWS b/NEWS
index 801b9fb24..743add395 100644
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,8 @@ Version 4.7.3
get. GitHub PR #2121. (TNX Chris Lawson)
* G90: Correct advertised modes/levels/funcs/ranges, clamp RFPOWER.
GitHub PR #2153. (TNX jbdubbs)
+ * Fix(FTX-1): Correct DCS parser format type. GitHub PR #2156.
+ (TNX David Christle)
Version 4.7.2
* 2026-06-21
commit 5d9471dfbbe4f38542e5306b90d0eee91e524d23
Author: David Christle <dch...@us...>
Date: Sun Aug 16 21:39:32 2026 -0700
fix(ftx1): correct DCS parser format type
The DCS getter passed an unsigned int pointer to a signed scanf conversion and logged the value with a signed format. Use int for the parsed table index to match both format conversions and the range-check helper.
(cherry picked from commit 85218f5ecb09de6aa080550af72ac97b6af8b5fb)
diff --git a/rigs/yaesu/ftx1/ftx1_ctcss.c b/rigs/yaesu/ftx1/ftx1_ctcss.c
index fd08cb359..a7cedc340 100644
--- a/rigs/yaesu/ftx1/ftx1_ctcss.c
+++ b/rigs/yaesu/ftx1/ftx1_ctcss.c
@@ -324,8 +324,7 @@ int ftx1_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
int ftx1_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int ret, p1p2;
- unsigned int dcs_num;
+ int ret, p1p2, dcs_num;
(void)vfo; /* Unused */
-----------------------------------------------------------------------
Summary of changes:
NEWS | 2 ++
rigs/yaesu/ftx1/ftx1_ctcss.c | 3 +--
2 files changed, 3 insertions(+), 2 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-20 19:34:57
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 6614c5268b7fa7cc9f8e10b15bb169c3fc0b7047 (commit)
via 85218f5ecb09de6aa080550af72ac97b6af8b5fb (commit)
from 9589c94a6dccd422ba2f34e1a9a6b8288a25466b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 6614c5268b7fa7cc9f8e10b15bb169c3fc0b7047
Merge: 9589c94a6 85218f5ec
Author: Nate Bargmann <n0...@n0...>
Date: Sun Sep 20 12:20:06 2026 -0500
Merge GitHub PR #2156
commit 85218f5ecb09de6aa080550af72ac97b6af8b5fb
Author: David Christle <dch...@us...>
Date: Sun Aug 16 21:39:32 2026 -0700
fix(ftx1): correct DCS parser format type
The DCS getter passed an unsigned int pointer to a signed scanf conversion and logged the value with a signed format. Use int for the parsed table index to match both format conversions and the range-check helper.
diff --git a/rigs/yaesu/ftx1/ftx1_ctcss.c b/rigs/yaesu/ftx1/ftx1_ctcss.c
index 71d378aee..1c466bc32 100644
--- a/rigs/yaesu/ftx1/ftx1_ctcss.c
+++ b/rigs/yaesu/ftx1/ftx1_ctcss.c
@@ -322,8 +322,7 @@ int ftx1_set_dcs_code(RIG *rig, vfo_t vfo, tone_t code)
int ftx1_get_dcs_code(RIG *rig, vfo_t vfo, tone_t *code)
{
struct newcat_priv_data *priv = STATE(rig)->priv;
- int ret, p1p2;
- unsigned int dcs_num;
+ int ret, p1p2, dcs_num;
(void)vfo; /* Unused */
-----------------------------------------------------------------------
Summary of changes:
rigs/yaesu/ftx1/ftx1_ctcss.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-20 17:12:34
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 9589c94a6dccd422ba2f34e1a9a6b8288a25466b (commit)
via b31a61b7187fa079dba51a6206a0f92b303abf35 (commit)
via d3e0fcdf3576f8e5ca39b4ad9cea246755c13644 (commit)
from 0c56dafd8fd0a042717cccd5da0610914cfb80a9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9589c94a6dccd422ba2f34e1a9a6b8288a25466b
Author: Nate Bargmann <n0...@n0...>
Date: Sun Sep 20 12:01:52 2026 -0500
Update NEWS for clearing rigctld PID fix
diff --git a/NEWS b/NEWS
index 6fbd3be23..1b08273e7 100644
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,8 @@ Version 5.x -- future
#2146. (TNX David Christle)
* Core: Add exclusive mode support to serial port opening. GitHub
PR #2200. (TNX Ben Woodard)
+ * Tests: Clear rigctld PID after startup timeout. GitHub PR #2154.
+ (TNX David Christle)
Version 4.7.2
* 2026-06-21
commit b31a61b7187fa079dba51a6206a0f92b303abf35
Merge: 0c56dafd8 d3e0fcdf3
Author: Nate Bargmann <n0...@n0...>
Date: Sun Sep 20 11:47:11 2026 -0500
Merge GitHub PR #2154
commit d3e0fcdf3576f8e5ca39b4ad9cea246755c13644
Author: David Christle <dch...@us...>
Date: Sun Aug 16 13:28:42 2026 -0700
fix(tests): clear rigctld PID after startup timeout
The timeout path reaped rigctld but left its PID visible to retry
cleanup. A second signal could then target the stale numeric PID.
Mark the child invalid immediately after waitpid consumes it.
diff --git a/test/test_netrigctl_stream.c b/test/test_netrigctl_stream.c
index 0de7a362c..b5078b93e 100644
--- a/test/test_netrigctl_stream.c
+++ b/test/test_netrigctl_stream.c
@@ -319,6 +319,7 @@ static int start_rigctld_once(struct rigctld_proc *proc,
{
kill(proc->pid, SIGTERM);
waitpid(proc->pid, NULL, 0);
+ proc->pid = -1;
return -1;
}
-----------------------------------------------------------------------
Summary of changes:
NEWS | 2 ++
test/test_netrigctl_stream.c | 1 +
2 files changed, 3 insertions(+)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-20 14:27:45
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, Hamlib-4.7 has been updated
via 182c1984d7e917b906a2e49b662afb1966ec569e (commit)
via 99dc1295f1088e182acee619d92876da2dee5f5c (commit)
from dcf5897c27fe9e2f575c91e2b8883cc2f847dad0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 182c1984d7e917b906a2e49b662afb1966ec569e
Author: Nate Bargmann <n0...@n0...>
Date: Sun Sep 20 09:26:38 2026 -0500
Update NEWS for Xiegu G90 fixes
diff --git a/NEWS b/NEWS
index d1cae018e..801b9fb24 100644
--- a/NEWS
+++ b/NEWS
@@ -60,9 +60,10 @@ Version 4.7.3
SW and PC CAT commands. The power meter full scale (6W stock,
12W with the PA0RDT PA modification) is read from the radio at
open time. (TNX Jan Szumiec)
- * G90: fix ATT ACK, get_info, AGC map, default CI-V address, and split
+ * G90: Fix ATT ACK, get_info, AGC map, default CI-V address, and split
get. GitHub PR #2121. (TNX Chris Lawson)
-
+ * G90: Correct advertised modes/levels/funcs/ranges, clamp RFPOWER.
+ GitHub PR #2153. (TNX jbdubbs)
Version 4.7.2
* 2026-06-21
commit 99dc1295f1088e182acee619d92876da2dee5f5c
Author: jbdubbs <ja...@we...>
Date: Sun Aug 16 18:05:05 2026 -0400
G90: fix over-claimed capabilities and RFPOWER BCD decode
Corrects rigs/icom/xiegu.c only. Backend version .11 -> .12.
New G90_ALL_RX_MODES/G90_FUNCS/G90_LEVELS/G90_MEM_CAP macros, replacing
the shared X108G_* macros for the G90 only.
Removed:
- RIG_FUNC_NR / RIG_LEVEL_NR: no NR on this rig
- RIG_LEVEL_VOXDELAY, RIG_FUNC_ARO: not implemented on this rig
- RIG_LEVEL_MICGAIN/PBT_IN/PBT_OUT/NOTCHF_RAW/VOXGAIN/ALC/BKINDL/COMP:
undocumented 0x14 subcommands, manual states these return a fixed 255
- VHF/UHF + 6m/2m/70cm ranges: HF+60m only, 0.5-30MHz. Max power
100W -> real 20W.
- RIG_MODE_WFM: not a real mode on this rig
Kept:
- RIG_LEVEL_RF, RIG_MODE_FM: undocumented but confirmed working
- RIG_MODE_FMN: same CI-V byte as FM (0x05), not a distinct mode
Added/fixed:
- RIG_FUNC_TUNER: built-in ATU (0x1C/0x01)
- g90_get_level() override for RIG_LEVEL_RFPOWER: clamps to 1.0
against a non-conformant BCD byte (0x5f) the rig sends at full power
- Simulator: malformed-BCD RFPOWER repro at max power
(cherry picked from commit b61dd14d461f35f4d6143993f8cbd1386af98847)
diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c
index eece1d9b5..7d2f7aba8 100644
--- a/rigs/icom/xiegu.c
+++ b/rigs/icom/xiegu.c
@@ -115,6 +115,47 @@
.levels = RIG_LEVEL_SET(X108G_LEVELS), \
}
+/*
+ * G90-specific capabilities, kept separate from the X108G_* macros above
+ * so X108G/X6100/X6200/X5105 are unaffected.
+ *
+ * Sources: Radioddity "Xiegu G90 CAT control and digital modes" manual v1.0
+ * (2021-06-23) and the official Radioddity G90 spec sheet.
+ *
+ * - HF+60m only: 0.5-30MHz RX, no 6m/2m/70cm/VHF/UHF.
+ * - No RIG_FUNC_NR / RIG_LEVEL_NR: no noise reduction on this rig.
+ * - RIG_FUNC_TUNER added: built-in ATU, CI-V 0x1C/0x01.
+ * - RIG_LEVEL_VOXDELAY, RIG_FUNC_ARO: not implemented on this rig.
+ * - RIG_LEVEL_BKINDL/MICGAIN/PBT_IN/PBT_OUT/NOTCHF_RAW/VOXGAIN/ALC/COMP:
+ * undocumented 0x14 subcommands; manual states these return a fixed 255.
+ * - RIG_LEVEL_RF kept though undocumented; confirmed working.
+ * - RIG_FUNC_ANF dropped: no auto notch filter on this rig.
+ * - RIG_MODE_FMN kept (S_FMN == S_FM == 0x05, not a distinct mode);
+ * RIG_MODE_WFM dropped (S_WFM == 0x06, no broadcast-FM reception).
+ */
+#define G90_ALL_RX_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_CWR|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_FMN|RIG_MODE_PKTUSB|RIG_MODE_PKTLSB)
+#define G90_NOT_TS_MODES (G90_ALL_RX_MODES &~ X108G_1HZ_TS_MODES)
+
+#define G90_FUNCS (RIG_FUNC_NB|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_TONE|RIG_FUNC_TSQL|RIG_FUNC_SBKIN|RIG_FUNC_FBKIN|RIG_FUNC_MON|RIG_FUNC_MN|RIG_FUNC_VSC|RIG_FUNC_LOCK|RIG_FUNC_TUNER)
+
+#define G90_LEVELS (RIG_LEVEL_PREAMP|RIG_LEVEL_ATT|RIG_LEVEL_AGC|RIG_LEVEL_CWPITCH|RIG_LEVEL_RFPOWER|RIG_LEVEL_KEYSPD|RIG_LEVEL_SQL|RIG_LEVEL_RAWSTR|RIG_LEVEL_AF|RIG_LEVEL_RF|RIG_LEVEL_SWR)
+
+#define G90_MEM_CAP { \
+ .freq = 1, \
+ .mode = 1, \
+ .width = 1, \
+ .split = 1, \
+ .tx_freq = 1, \
+ .tx_mode = 1, \
+ .tx_width = 1, \
+ .rptr_offs = 1, \
+ .rptr_shift = 1, \
+ .ctcss_tone = 1, \
+ .ctcss_sql = 1, \
+ .funcs = G90_FUNCS, \
+ .levels = RIG_LEVEL_SET(G90_LEVELS), \
+}
+
/*
* Prototypes
*/
@@ -889,10 +930,10 @@ struct rig_caps g90_caps =
.post_write_delay = 0,
.timeout = 1000,
.retry = 3,
- .has_get_func = X108G_FUNCS,
- .has_set_func = X108G_FUNCS,
- .has_get_level = X108G_LEVELS,
- .has_set_level = RIG_LEVEL_SET(X108G_LEVELS),
+ .has_get_func = G90_FUNCS,
+ .has_set_func = G90_FUNCS,
+ .has_get_level = G90_LEVELS,
+ .has_set_level = RIG_LEVEL_SET(G90_LEVELS),
.has_get_parm = X108G_PARMS,
.has_set_parm = RIG_PARM_SET(X108G_PARMS),
.level_gran = {
@@ -915,55 +956,45 @@ struct rig_caps g90_caps =
.chan_desc_sz = 0, /* TODO */
.chan_list = {
- { 1, 99, RIG_MTYPE_MEM, X108G_MEM_CAP },
- { 100, 105, RIG_MTYPE_EDGE, X108G_MEM_CAP }, /* two by two */
- { 106, 107, RIG_MTYPE_CALL, X108G_MEM_CAP },
+ { 1, 99, RIG_MTYPE_MEM, G90_MEM_CAP },
+ { 100, 105, RIG_MTYPE_EDGE, G90_MEM_CAP }, /* two by two */
+ { 106, 107, RIG_MTYPE_CALL, G90_MEM_CAP },
RIG_CHAN_END,
},
- .rx_range_list1 = { {kHz(30), MHz(199.999999), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS},
- {MHz(400), MHz(470), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
+ .rx_range_list1 = { {kHz(500), MHz(30), G90_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
},
.tx_range_list1 = {
- FRQ_RNG_HF(1, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_6m(1, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_2m(1, X108G_OTHER_TX_MODES, W(2), W(50), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(1, X108G_OTHER_TX_MODES, W(2), W(35), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_HF(1, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_6m(1, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_2m(1, X108G_AM_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(1, X108G_OTHER_TX_MODES, W(2), W(14), X108G_VFOS, RIG_ANT_2),
+ FRQ_RNG_HF(1, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_60m(1, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_HF(1, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
+ FRQ_RNG_60m(1, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
RIG_FRNG_END,
},
- .rx_range_list2 = { {kHz(30), MHz(199.999999), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS},
- {MHz(400), MHz(470), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
+ .rx_range_list2 = { {kHz(500), MHz(30), G90_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
},
- .tx_range_list2 = { /* needs the 5 MHz channels added */
- FRQ_RNG_HF(2, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_6m(2, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_2m(2, X108G_OTHER_TX_MODES, W(2), W(50), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(2, X108G_OTHER_TX_MODES, W(2), W(35), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_HF(2, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_6m(2, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_2m(2, X108G_AM_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(2, X108G_OTHER_TX_MODES, W(2), W(14), X108G_VFOS, RIG_ANT_2),
+ .tx_range_list2 = {
+ FRQ_RNG_HF(2, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_60m(2, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_HF(2, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
+ FRQ_RNG_60m(2, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
RIG_FRNG_END,
},
.tuning_steps = {
{X108G_1HZ_TS_MODES, 1},
- {X108G_NOT_TS_MODES, 10},
- {X108G_ALL_RX_MODES, Hz(100)},
- {X108G_ALL_RX_MODES, kHz(1)},
- {X108G_ALL_RX_MODES, kHz(5)},
- {X108G_ALL_RX_MODES, kHz(9)},
- {X108G_ALL_RX_MODES, kHz(10)},
- {X108G_ALL_RX_MODES, kHz(12.5)},
- {X108G_ALL_RX_MODES, kHz(20)},
- {X108G_ALL_RX_MODES, kHz(25)},
- {X108G_ALL_RX_MODES, kHz(100)},
- {X108G_NOT_TS_MODES, MHz(1)},
+ {G90_NOT_TS_MODES, 10},
+ {G90_ALL_RX_MODES, Hz(100)},
+ {G90_ALL_RX_MODES, kHz(1)},
+ {G90_ALL_RX_MODES, kHz(5)},
+ {G90_ALL_RX_MODES, kHz(9)},
+ {G90_ALL_RX_MODES, kHz(10)},
+ {G90_ALL_RX_MODES, kHz(12.5)},
+ {G90_ALL_RX_MODES, kHz(20)},
+ {G90_ALL_RX_MODES, kHz(25)},
+ {G90_ALL_RX_MODES, kHz(100)},
+ {G90_NOT_TS_MODES, MHz(1)},
RIG_TS_END,
},
@@ -982,7 +1013,6 @@ struct rig_caps g90_caps =
{RIG_MODE_AM, kHz(6)},
{RIG_MODE_AM, kHz(3)},
{RIG_MODE_AM, kHz(9)},
- {RIG_MODE_WFM, kHz(280)},
RIG_FLT_END,
},
@@ -1358,11 +1388,28 @@ static int g90_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
/*
* g90_get_level
* Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL
+ *
+ * RIG_LEVEL_RFPOWER: at full power, G90 firmware replies with a
+ * non-conformant BCD byte (0x5f) instead of 0x02 0x55 (255), which
+ * decodes to a value above the declared 1.0 max. Clamped here rather
+ * than in icom_get_level() since it's G90-specific.
*/
static int g90_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
int retval, state;
+ if (level == RIG_LEVEL_RFPOWER)
+ {
+ retval = icom_get_level(rig, vfo, level, val);
+
+ if (retval == RIG_OK && val->f > 1.0f)
+ {
+ val->f = 1.0f;
+ }
+
+ return retval;
+ }
+
if (level != RIG_LEVEL_ATT)
{
return icom_get_level(rig, vfo, level, val);
diff --git a/simulators/simxiegug90.c b/simulators/simxiegug90.c
index 755ff2ebf..9b61d7d3d 100644
--- a/simulators/simxiegug90.c
+++ b/simulators/simxiegug90.c
@@ -202,7 +202,17 @@ void frameParse(int fd, unsigned char *frame, int len)
if (power_level > 250) { power_level = 0; }
- to_bcd(&frame[6], (long long)power_level, 2);
+ if (power_level >= 250)
+ {
+ // Malformed BCD (0x5f) at max power -- see g90_get_level()
+ frame[6] = 0x02;
+ frame[7] = 0x5f;
+ }
+ else
+ {
+ to_bcd(&frame[6], (long long)power_level, 2);
+ }
+
frame[8] = 0xfd;
write(fd, frame, 9);
break;
-----------------------------------------------------------------------
Summary of changes:
NEWS | 5 +-
rigs/icom/xiegu.c | 127 ++++++++++++++++++++++++++++++++---------------
simulators/simxiegug90.c | 12 ++++-
3 files changed, 101 insertions(+), 43 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|
|
From: n0nb <n0...@us...> - 2026-09-20 14:10:44
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Hamlib -- Ham radio control libraries".
The branch, master has been updated
via 0c56dafd8fd0a042717cccd5da0610914cfb80a9 (commit)
via b61dd14d461f35f4d6143993f8cbd1386af98847 (commit)
from bfea1769f3ada04c9f16b42d08f68eff2d031c71 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0c56dafd8fd0a042717cccd5da0610914cfb80a9
Merge: bfea1769f b61dd14d4
Author: Nate Bargmann <n0...@n0...>
Date: Sun Sep 20 08:57:19 2026 -0500
Merge GitHub #2153
commit b61dd14d461f35f4d6143993f8cbd1386af98847
Author: jbdubbs <ja...@we...>
Date: Sun Aug 16 18:05:05 2026 -0400
G90: fix over-claimed capabilities and RFPOWER BCD decode
Corrects rigs/icom/xiegu.c only. Backend version .11 -> .12.
New G90_ALL_RX_MODES/G90_FUNCS/G90_LEVELS/G90_MEM_CAP macros, replacing
the shared X108G_* macros for the G90 only.
Removed:
- RIG_FUNC_NR / RIG_LEVEL_NR: no NR on this rig
- RIG_LEVEL_VOXDELAY, RIG_FUNC_ARO: not implemented on this rig
- RIG_LEVEL_MICGAIN/PBT_IN/PBT_OUT/NOTCHF_RAW/VOXGAIN/ALC/BKINDL/COMP:
undocumented 0x14 subcommands, manual states these return a fixed 255
- VHF/UHF + 6m/2m/70cm ranges: HF+60m only, 0.5-30MHz. Max power
100W -> real 20W.
- RIG_MODE_WFM: not a real mode on this rig
Kept:
- RIG_LEVEL_RF, RIG_MODE_FM: undocumented but confirmed working
- RIG_MODE_FMN: same CI-V byte as FM (0x05), not a distinct mode
Added/fixed:
- RIG_FUNC_TUNER: built-in ATU (0x1C/0x01)
- g90_get_level() override for RIG_LEVEL_RFPOWER: clamps to 1.0
against a non-conformant BCD byte (0x5f) the rig sends at full power
- Simulator: malformed-BCD RFPOWER repro at max power
diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c
index bde266f0e..f7714f254 100644
--- a/rigs/icom/xiegu.c
+++ b/rigs/icom/xiegu.c
@@ -115,6 +115,47 @@
.levels = RIG_LEVEL_SET(X108G_LEVELS), \
}
+/*
+ * G90-specific capabilities, kept separate from the X108G_* macros above
+ * so X108G/X6100/X6200/X5105 are unaffected.
+ *
+ * Sources: Radioddity "Xiegu G90 CAT control and digital modes" manual v1.0
+ * (2021-06-23) and the official Radioddity G90 spec sheet.
+ *
+ * - HF+60m only: 0.5-30MHz RX, no 6m/2m/70cm/VHF/UHF.
+ * - No RIG_FUNC_NR / RIG_LEVEL_NR: no noise reduction on this rig.
+ * - RIG_FUNC_TUNER added: built-in ATU, CI-V 0x1C/0x01.
+ * - RIG_LEVEL_VOXDELAY, RIG_FUNC_ARO: not implemented on this rig.
+ * - RIG_LEVEL_BKINDL/MICGAIN/PBT_IN/PBT_OUT/NOTCHF_RAW/VOXGAIN/ALC/COMP:
+ * undocumented 0x14 subcommands; manual states these return a fixed 255.
+ * - RIG_LEVEL_RF kept though undocumented; confirmed working.
+ * - RIG_FUNC_ANF dropped: no auto notch filter on this rig.
+ * - RIG_MODE_FMN kept (S_FMN == S_FM == 0x05, not a distinct mode);
+ * RIG_MODE_WFM dropped (S_WFM == 0x06, no broadcast-FM reception).
+ */
+#define G90_ALL_RX_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_CWR|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_FMN|RIG_MODE_PKTUSB|RIG_MODE_PKTLSB)
+#define G90_NOT_TS_MODES (G90_ALL_RX_MODES &~ X108G_1HZ_TS_MODES)
+
+#define G90_FUNCS (RIG_FUNC_NB|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_TONE|RIG_FUNC_TSQL|RIG_FUNC_SBKIN|RIG_FUNC_FBKIN|RIG_FUNC_MON|RIG_FUNC_MN|RIG_FUNC_VSC|RIG_FUNC_LOCK|RIG_FUNC_TUNER)
+
+#define G90_LEVELS (RIG_LEVEL_PREAMP|RIG_LEVEL_ATT|RIG_LEVEL_AGC|RIG_LEVEL_CWPITCH|RIG_LEVEL_RFPOWER|RIG_LEVEL_KEYSPD|RIG_LEVEL_SQL|RIG_LEVEL_RAWSTR|RIG_LEVEL_AF|RIG_LEVEL_RF|RIG_LEVEL_SWR)
+
+#define G90_MEM_CAP { \
+ .freq = 1, \
+ .mode = 1, \
+ .width = 1, \
+ .split = 1, \
+ .tx_freq = 1, \
+ .tx_mode = 1, \
+ .tx_width = 1, \
+ .rptr_offs = 1, \
+ .rptr_shift = 1, \
+ .ctcss_tone = 1, \
+ .ctcss_sql = 1, \
+ .funcs = G90_FUNCS, \
+ .levels = RIG_LEVEL_SET(G90_LEVELS), \
+}
+
/*
* Prototypes
*/
@@ -889,10 +930,10 @@ struct rig_caps g90_caps =
.post_write_delay = 0,
.timeout = 1000,
.retry = 3,
- .has_get_func = X108G_FUNCS,
- .has_set_func = X108G_FUNCS,
- .has_get_level = X108G_LEVELS,
- .has_set_level = RIG_LEVEL_SET(X108G_LEVELS),
+ .has_get_func = G90_FUNCS,
+ .has_set_func = G90_FUNCS,
+ .has_get_level = G90_LEVELS,
+ .has_set_level = RIG_LEVEL_SET(G90_LEVELS),
.has_get_parm = X108G_PARMS,
.has_set_parm = RIG_PARM_SET(X108G_PARMS),
.level_gran = {
@@ -915,55 +956,45 @@ struct rig_caps g90_caps =
.chan_desc_sz = 0, /* TODO */
.chan_list = {
- { 1, 99, RIG_MTYPE_MEM, X108G_MEM_CAP },
- { 100, 105, RIG_MTYPE_EDGE, X108G_MEM_CAP }, /* two by two */
- { 106, 107, RIG_MTYPE_CALL, X108G_MEM_CAP },
+ { 1, 99, RIG_MTYPE_MEM, G90_MEM_CAP },
+ { 100, 105, RIG_MTYPE_EDGE, G90_MEM_CAP }, /* two by two */
+ { 106, 107, RIG_MTYPE_CALL, G90_MEM_CAP },
RIG_CHAN_END,
},
- .rx_range_list1 = { {kHz(30), MHz(199.999999), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS},
- {MHz(400), MHz(470), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
+ .rx_range_list1 = { {kHz(500), MHz(30), G90_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
},
.tx_range_list1 = {
- FRQ_RNG_HF(1, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_6m(1, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_2m(1, X108G_OTHER_TX_MODES, W(2), W(50), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(1, X108G_OTHER_TX_MODES, W(2), W(35), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_HF(1, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_6m(1, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_2m(1, X108G_AM_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(1, X108G_OTHER_TX_MODES, W(2), W(14), X108G_VFOS, RIG_ANT_2),
+ FRQ_RNG_HF(1, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_60m(1, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_HF(1, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
+ FRQ_RNG_60m(1, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
RIG_FRNG_END,
},
- .rx_range_list2 = { {kHz(30), MHz(199.999999), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS},
- {MHz(400), MHz(470), X108G_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
+ .rx_range_list2 = { {kHz(500), MHz(30), G90_ALL_RX_MODES, -1, -1, X108G_VFOS}, RIG_FRNG_END,
},
- .tx_range_list2 = { /* needs the 5 MHz channels added */
- FRQ_RNG_HF(2, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_6m(2, X108G_OTHER_TX_MODES, W(2), W(100), X108G_VFOS, RIG_ANT_1),
- FRQ_RNG_2m(2, X108G_OTHER_TX_MODES, W(2), W(50), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(2, X108G_OTHER_TX_MODES, W(2), W(35), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_HF(2, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_6m(2, X108G_AM_TX_MODES, W(1), W(40), X108G_VFOS, RIG_ANT_1), /* AM class */
- FRQ_RNG_2m(2, X108G_AM_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_2),
- FRQ_RNG_70cm(2, X108G_OTHER_TX_MODES, W(2), W(14), X108G_VFOS, RIG_ANT_2),
+ .tx_range_list2 = {
+ FRQ_RNG_HF(2, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_60m(2, X108G_OTHER_TX_MODES, W(2), W(20), X108G_VFOS, RIG_ANT_1),
+ FRQ_RNG_HF(2, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
+ FRQ_RNG_60m(2, X108G_AM_TX_MODES, W(1), W(20), X108G_VFOS, RIG_ANT_1), /* AM class */
RIG_FRNG_END,
},
.tuning_steps = {
{X108G_1HZ_TS_MODES, 1},
- {X108G_NOT_TS_MODES, 10},
- {X108G_ALL_RX_MODES, Hz(100)},
- {X108G_ALL_RX_MODES, kHz(1)},
- {X108G_ALL_RX_MODES, kHz(5)},
- {X108G_ALL_RX_MODES, kHz(9)},
- {X108G_ALL_RX_MODES, kHz(10)},
- {X108G_ALL_RX_MODES, kHz(12.5)},
- {X108G_ALL_RX_MODES, kHz(20)},
- {X108G_ALL_RX_MODES, kHz(25)},
- {X108G_ALL_RX_MODES, kHz(100)},
- {X108G_NOT_TS_MODES, MHz(1)},
+ {G90_NOT_TS_MODES, 10},
+ {G90_ALL_RX_MODES, Hz(100)},
+ {G90_ALL_RX_MODES, kHz(1)},
+ {G90_ALL_RX_MODES, kHz(5)},
+ {G90_ALL_RX_MODES, kHz(9)},
+ {G90_ALL_RX_MODES, kHz(10)},
+ {G90_ALL_RX_MODES, kHz(12.5)},
+ {G90_ALL_RX_MODES, kHz(20)},
+ {G90_ALL_RX_MODES, kHz(25)},
+ {G90_ALL_RX_MODES, kHz(100)},
+ {G90_NOT_TS_MODES, MHz(1)},
RIG_TS_END,
},
@@ -982,7 +1013,6 @@ struct rig_caps g90_caps =
{RIG_MODE_AM, kHz(6)},
{RIG_MODE_AM, kHz(3)},
{RIG_MODE_AM, kHz(9)},
- {RIG_MODE_WFM, kHz(280)},
RIG_FLT_END,
},
@@ -1358,11 +1388,28 @@ static int g90_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val)
/*
* g90_get_level
* Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL
+ *
+ * RIG_LEVEL_RFPOWER: at full power, G90 firmware replies with a
+ * non-conformant BCD byte (0x5f) instead of 0x02 0x55 (255), which
+ * decodes to a value above the declared 1.0 max. Clamped here rather
+ * than in icom_get_level() since it's G90-specific.
*/
static int g90_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val)
{
int retval, state;
+ if (level == RIG_LEVEL_RFPOWER)
+ {
+ retval = icom_get_level(rig, vfo, level, val);
+
+ if (retval == RIG_OK && val->f > 1.0f)
+ {
+ val->f = 1.0f;
+ }
+
+ return retval;
+ }
+
if (level != RIG_LEVEL_ATT)
{
return icom_get_level(rig, vfo, level, val);
diff --git a/simulators/simxiegug90.c b/simulators/simxiegug90.c
index 755ff2ebf..9b61d7d3d 100644
--- a/simulators/simxiegug90.c
+++ b/simulators/simxiegug90.c
@@ -202,7 +202,17 @@ void frameParse(int fd, unsigned char *frame, int len)
if (power_level > 250) { power_level = 0; }
- to_bcd(&frame[6], (long long)power_level, 2);
+ if (power_level >= 250)
+ {
+ // Malformed BCD (0x5f) at max power -- see g90_get_level()
+ frame[6] = 0x02;
+ frame[7] = 0x5f;
+ }
+ else
+ {
+ to_bcd(&frame[6], (long long)power_level, 2);
+ }
+
frame[8] = 0xfd;
write(fd, frame, 9);
break;
-----------------------------------------------------------------------
Summary of changes:
rigs/icom/xiegu.c | 127 ++++++++++++++++++++++++++++++++---------------
simulators/simxiegug90.c | 12 ++++-
2 files changed, 98 insertions(+), 41 deletions(-)
hooks/post-receive
--
Hamlib -- Ham radio control libraries
|