From af5ea58350f34ba918685e6bd72b272a6bb1d9ad Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Mon, 18 Dec 2023 15:26:46 -0600 Subject: [PATCH] Add -# --skip_init option to rigctl --- NEWS | 1 + doc/man1/rigctl.1 | 5 +++++ include/hamlib/rig.h | 1 + src/rig.c | 14 ++++++++++++-- tests/rigctl.c | 8 ++++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 644b7fd1a..9fadc11a2 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ Version 5.x -- future * Change FT1000MP Mark V model names to align with FT1000MP Version 4.6 + * Add -# --skip_init option to rigctl to skip rig initialization -- useful for executing commands quickly * rig_caps is no longer constant -- this may break some 3rd party relying on the "const" declaration. Here's an example of how to handle compatiblity. #ifdef RIGCAPS_NOT_CONST static int add_to_list(struct rig_caps* rc, void*) diff --git a/doc/man1/rigctl.1 b/doc/man1/rigctl.1 index db4535e2e..baf5b8fa8 100644 --- a/doc/man1/rigctl.1 +++ b/doc/man1/rigctl.1 @@ -1424,6 +1424,11 @@ Can also use 1,2,3,4 Reads GPIO1, GPIO2, GPIO3, GPIO4 on the GPIO ptt port Can also use 1,2,3,4 . +.TP +.BR skip_init +.EX +Skips rig initialization -- useful when executing commands with rigctl to speed up things +. .SH READLINE . If diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 718e55d90..4428dab24 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -156,6 +156,7 @@ typedef struct // cookie is 26-char time code plus 10-char (2^31-1) random number #define HAMLIB_COOKIE_SIZE 37 extern int cookie_use; // this is global as once one client requests it everybody needs to honor it +extern int skip_init; // allow rigctl to skip any radio commands at startup //! @cond Doxygen_Suppress extern HAMLIB_EXPORT_VAR(const char) hamlib_version[]; diff --git a/src/rig.c b/src/rig.c index ce6a185ba..40051a2c8 100644 --- a/src/rig.c +++ b/src/rig.c @@ -100,6 +100,7 @@ const char hamlib_version[21] = "Hamlib " PACKAGE_VERSION; const char *hamlib_version2 = "Hamlib " PACKAGE_VERSION " " HAMLIBDATETIME " " ARCHBITS; HAMLIB_EXPORT_VAR(int) cookie_use; +HAMLIB_EXPORT_VAR(int) skip_init; HAMLIB_EXPORT_VAR(int) lock_mode; // for use by rigctld HAMLIB_EXPORT_VAR(powerstat_t) rig_powerstat; // for use by both rigctld and rigctl @@ -1326,6 +1327,8 @@ int HAMLIB_API rig_open(RIG *rig) } #if defined(HAVE_PTHREAD) + if (!skip_init) + { status = async_data_handler_start(rig); if (status < 0) @@ -1334,7 +1337,7 @@ int HAMLIB_API rig_open(RIG *rig) rig->state.comm_status = RIG_COMM_STATUS_ERROR; RETURNFUNC2(status); } - + } #endif rs->comm_state = 1; @@ -1354,7 +1357,7 @@ int HAMLIB_API rig_open(RIG *rig) if (caps->rig_open != NULL) { - if (caps->get_powerstat != NULL) + if (caps->get_powerstat != NULL && !skip_init) { powerstat_t powerflag; status = rig_get_powerstat(rig, &powerflag); @@ -1388,8 +1391,11 @@ int HAMLIB_API rig_open(RIG *rig) { remove_opened_rig(rig); #if defined(HAVE_PTHREAD) + if (!skip_init) + { async_data_handler_stop(rig); morse_data_handler_stop(rig); + } #endif port_close(&rs->rigport, rs->rigport.type.rig); memcpy(&rs->rigport_deprecated, &rs->rigport, sizeof(hamlib_port_t_deprecated)); @@ -1443,6 +1449,7 @@ int HAMLIB_API rig_open(RIG *rig) rig_strvfo(rs->current_vfo)); } } + if (skip_init) return RIG_OK; #if defined(HAVE_PTHREAD) status = morse_data_handler_start(rig); @@ -1595,11 +1602,14 @@ int HAMLIB_API rig_close(RIG *rig) rig->state.comm_status = RIG_COMM_STATUS_DISCONNECTED; #if defined(HAVE_PTHREAD) + if (!skip_init) + { morse_data_handler_stop(rig); async_data_handler_stop(rig); rig_poll_routine_stop(rig); network_multicast_receiver_stop(rig); network_multicast_publisher_stop(rig); + } #endif /* diff --git a/tests/rigctl.c b/tests/rigctl.c index dcf24a16d..ccb6b1cf0 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -79,7 +79,7 @@ static void usage(void); * 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:p:d:P:D:s:c:t:lC:LuonvhVYZ!" +#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhVYZ!#" static struct option long_options[] = { {"model", 1, 0, 'm'}, @@ -107,6 +107,7 @@ static struct option long_options[] = {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, {"cookie", 0, 0, '!'}, + {"skipinit", 0, 0, '#'}, {0, 0, 0, 0} }; @@ -254,6 +255,9 @@ int main(int argc, char *argv[]) switch (c) { + case '#': + skip_init = 1; + break; case '!': cookie_use = 1; break; @@ -679,7 +683,7 @@ int main(int argc, char *argv[]) my_rig->caps->model_name); } - if (my_rig->caps->get_powerstat) + if (!skip_init && my_rig->caps->get_powerstat) { rig_get_powerstat(my_rig, &rig_powerstat); my_rig->state.powerstat = rig_powerstat;