From 5add4b343d14c900f46ad770d580781c5195327d Mon Sep 17 00:00:00 2001 From: Michael Black W9MDB Date: Fri, 16 Oct 2020 08:41:57 -0500 Subject: [PATCH] Add rig_stop_morse to API and stop_morse command for rigctl No rigs implemented yet https://github.com/Hamlib/Hamlib/issues/240 --- include/hamlib/rig.h | 5 ++++ src/rig.c | 59 ++++++++++++++++++++++++++++++++++++++++++++ tests/rigctl_parse.c | 8 ++++++ 3 files changed, 72 insertions(+) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index d78f42a6b..bc4f1cb77 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -1792,6 +1792,7 @@ struct rig_caps { int (*recv_dtmf)(RIG *rig, vfo_t vfo, char *digits, int *length); int (*send_morse)(RIG *rig, vfo_t vfo, const char *msg); + int (*stop_morse)(RIG *rig, vfo_t vfo); int (*send_voice_mem)(RIG *rig, vfo_t vfo, int ch); @@ -2503,6 +2504,10 @@ rig_send_morse HAMLIB_PARAMS((RIG *rig, vfo_t vfo, const char *msg)); +extern HAMLIB_EXPORT(int) +rig_stop_morse HAMLIB_PARAMS((RIG *rig, + vfo_t vfo)); + extern HAMLIB_EXPORT(int) rig_send_voice_mem HAMLIB_PARAMS((RIG *rig, vfo_t vfo, diff --git a/src/rig.c b/src/rig.c index 99e3dca13..9d9194a0d 100644 --- a/src/rig.c +++ b/src/rig.c @@ -5000,6 +5000,65 @@ int HAMLIB_API rig_send_morse(RIG *rig, vfo_t vfo, const char *msg) return retcode; } +/** + * \brief stop morse code + * \param rig The rig handle + * \param vfo The target VFO + * + * Stops the send morse message. + * + * \return RIG_OK if the operation has been successful, otherwise + * a negative value if an error occurred (in which case, cause is + * set appropriately). + * + */ +int HAMLIB_API rig_stop_morse(RIG *rig, vfo_t vfo) +{ + const struct rig_caps *caps; + int retcode, rc2; + vfo_t curr_vfo; + + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); + caps = rig->caps; + + if (caps->stop_morse == NULL) + { + return -RIG_ENAVAIL; + } + + if ((caps->targetable_vfo & RIG_TARGETABLE_PURE) + || vfo == RIG_VFO_CURR + || vfo == rig->state.current_vfo) + { + return caps->stop_morse(rig, vfo); + } + + if (!caps->set_vfo) + { + return -RIG_ENTARGET; + } + + curr_vfo = rig->state.current_vfo; + retcode = caps->set_vfo(rig, vfo); + + if (retcode != RIG_OK) + { + return retcode; + } + + retcode = caps->stop_morse(rig, vfo); + /* try and revert even if we had an error above */ + rc2 = caps->set_vfo(rig, curr_vfo); + + if (RIG_OK == retcode) + { + /* return the first error code */ + retcode = rc2; + } + + return retcode; +} + /** * \brief send voice memory content diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 6f2a62ef3..07d5d47f1 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -217,6 +217,7 @@ declare_proto_rig(set_ant); declare_proto_rig(get_ant); declare_proto_rig(reset); declare_proto_rig(send_morse); +declare_proto_rig(stop_morse); declare_proto_rig(send_voice_mem); declare_proto_rig(send_cmd); declare_proto_rig(set_powerstat); @@ -311,6 +312,7 @@ static struct test_table test_list[] = { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply" }, { 'W', "send_cmd_rx", ACTION(send_cmd), ARG_IN | ARG_OUT2 | ARG_NOVFO, "Cmd", "Reply"}, { 'b', "send_morse", ACTION(send_morse), ARG_IN | ARG_IN_LINE, "Morse" }, + { 0xbb, "stop_morse", ACTION(stop_morse), }, { 0x94, "send_voice_mem", ACTION(send_voice_mem), ARG_IN, "Voice Mem#" }, { 0x8b, "get_dcd", ACTION(get_dcd), ARG_OUT, "DCD" }, { 0x8d, "set_twiddle", ACTION(set_twiddle), ARG_IN | ARG_NOVFO, "Timeout (secs)" }, @@ -4217,6 +4219,12 @@ declare_proto_rig(send_morse) return rig_send_morse(rig, vfo, arg1); } +/* 0xvv */ +declare_proto_rig(stop_morse) +{ + return rig_stop_morse(rig, vfo); +} + /* '8' */ declare_proto_rig(send_voice_mem) {