From f555eceff9dd05c5f035f6701f3526d013cb84e9 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Thu, 2 Jun 2022 15:55:56 -0500 Subject: [PATCH] Got set_lock_mode and get_lock_mode working now https://github.com/Hamlib/Hamlib/issues/1044 --- doc/man1/rigctl.1 | 4 ++-- doc/man1/rigctld.1 | 4 ++-- include/hamlib/rig.h | 5 +++++ rigs/dummy/netrigctl.c | 18 ++++++++++++++++++ src/rig.c | 27 ++++++++++++++++++++++++++- tests/rigctl_parse.c | 16 +++++++++++++--- 6 files changed, 66 insertions(+), 8 deletions(-) diff --git a/doc/man1/rigctl.1 b/doc/man1/rigctl.1 index 3747b1cbb..1e456608d 100644 --- a/doc/man1/rigctl.1 +++ b/doc/man1/rigctl.1 @@ -1219,14 +1219,14 @@ Sends password to rigctld when rigctld has been secured with -A. Must use the 3 . .TP .BR set_lock_mode " \(aq" \fILocked\fP \(aq -Turns mode lock on(1) or off(0). Turning on will prevent all clients from changing the rig mode. +Turns mode lock on(1) or off(0) (only when using rigctld). Turning on will prevent all clients from changing the rig mode. For example this is useful when running CW Skimmer in FM mode on an IC-7300. Clicking spots in a spotting program will not change the VFOA mode when lock is on. So "set_lock_mode 1" when CW Skimmer is started and "set_lock_mode 0" when CW Skimmer is stopped. . .TP .BR get_lock_mode -Returns current lock mode status 1=On, 2=Off +Returns current lock mode status 1=On, 2=Off (only useful when using rigctld) . .SH READLINE . diff --git a/doc/man1/rigctld.1 b/doc/man1/rigctld.1 index a01ea92e2..8a37a5bde 100644 --- a/doc/man1/rigctld.1 +++ b/doc/man1/rigctld.1 @@ -1142,14 +1142,14 @@ This can be dyamically changed while running. . .TP .BR set_lock_mode " \(aq" \fILocked\fP \(aq -Turns mode lock on(1) or off(0). Turning on will prevent all clients from changing the rig mode. +Turns mode lock on(1) or off(0) (only when using rigctld). Turning on will prevent all clients from changing the rig mode. For example this is useful when running CW Skimmer in FM mode on an IC-7300. Clicking spots in a spotting program will not change the VFOA mode when lock is on. So "set_lock_mode 1" when CW Skimmer is started and "set_lock_mode 0" when CW Skimmer is stopped. . .TP .BR get_lock_mode -Returns current lock mode status 1=On, 2=Off +Returns current lock mode status 1=On, 2=Off (only useful with rigctld) . . .SH PROTOCOL diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index d0d3e858d..e9c8bdce8 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2049,6 +2049,8 @@ struct rig_caps { char *hamlib_check_rig_caps; // a constant value we can check for hamlib integrity int (*get_conf2)(RIG *rig, token_t token, char *val, int val_len); int (*password)(RIG *rig, const char *key1); /*< Send encrypted password if rigctld is secured with -A/--password */ + int (*set_lock_mode)(RIG *rig, int mode); + int (*get_lock_mode)(RIG *rig, int *mode); }; //! @endcond @@ -3406,6 +3408,9 @@ locator2longlat HAMLIB_PARAMS((double *longitude, extern HAMLIB_EXPORT(char*) rig_make_md5(char *pass); +extern HAMLIB_EXPORT(int) rig_set_lock_mode(RIG *rig, int lock); +extern HAMLIB_EXPORT(int) rig_get_lock_mode(RIG *rig, int *lock); + //! @endcond diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c index fb19f8eee..cf5827669 100644 --- a/rigs/dummy/netrigctl.c +++ b/rigs/dummy/netrigctl.c @@ -2649,6 +2649,22 @@ int netrigctl_password(RIG *rig, const char *key1) RETURNFUNC(retval); } +int lock_mode; + +int netrigctl_set_lock_mode(RIG *rig, int mode) +{ + //rig->state.lock_mode = mode; + lock_mode = mode; + return (RIG_OK); +} + +int netrigctl_get_lock_mode(RIG *rig, int *mode) +{ + //*mode = rig->state.lock_mode; + *mode = lock_mode; + return (RIG_OK); +} + /* * Netrigctl rig capabilities. */ @@ -2764,6 +2780,8 @@ struct rig_caps netrigctl_caps = .power2mW = netrigctl_power2mW, .mW2power = netrigctl_mW2power, .password = netrigctl_password, + .set_lock_mode = netrigctl_set_lock_mode, + .get_lock_mode = netrigctl_get_lock_mode, .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; diff --git a/src/rig.c b/src/rig.c index 364e923b2..8ededa71f 100644 --- a/src/rig.c +++ b/src/rig.c @@ -4165,7 +4165,8 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, // some rigs exhibit undesirable flashing when swapping vfos in split // so we turn it off, do our thing, and turn split back on rx_vfo = vfo; - if (tx_vfo == RIG_VFO_B) rx_vfo = RIG_VFO_A; + + if (tx_vfo == RIG_VFO_B) { rx_vfo = RIG_VFO_A; } if (vfo == RIG_VFO_CURR && tx_vfo == RIG_VFO_B) { rx_vfo = RIG_VFO_A; } else if (vfo == RIG_VFO_CURR && tx_vfo == RIG_VFO_A) { rx_vfo = RIG_VFO_B; } @@ -7306,3 +7307,27 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send, RETURNFUNC(retval); } + +HAMLIB_EXPORT(int) rig_set_lock_mode(RIG *rig, int mode) +{ + int retcode = -RIG_ENAVAIL; + + if (rig->caps->set_lock_mode) + { + retcode = rig->caps->set_lock_mode(rig, mode); + } + + return (retcode); +} + +HAMLIB_EXPORT(int) rig_get_lock_mode(RIG *rig, int *mode) +{ + int retcode = -RIG_ENAVAIL; + + if (rig->caps->get_lock_mode) + { + retcode = rig->caps->get_lock_mode(rig, mode); + } + + return (retcode); +} diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 97d5f5c6d..e1f2e8269 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -5223,17 +5223,27 @@ declare_proto_rig(set_lock_mode) { int lock; CHKSCN1ARG(sscanf(arg1, "%d", &lock)); - rig->state.lock_mode = lock != 0; - return RIG_OK; + return (rig_set_lock_mode(rig, lock)); } + /* '0xa3' */ declare_proto_rig(get_lock_mode) { + int retval; + int lock; + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf(fout, "%s: ", cmd->arg1); } - fprintf(fout, "%d\n", rig->state.lock_mode); + retval = rig_get_lock_mode(rig, &lock); + + if (retval != RIG_OK) + { + return retval; + } + + fprintf(fout, "%d\n", lock); return RIG_OK; }