From e05b79acd311caf0c2c9a14a8711881566a1362a Mon Sep 17 00:00:00 2001 From: George Baltz N3GB Date: Mon, 13 Nov 2023 12:47:18 -0500 Subject: [PATCH] Move meter reader to kenwood.c, so it can be used by ts990.c --- rigs/kenwood/kenwood.c | 48 ++++++++++++++++++++++++++++++++ rigs/kenwood/kenwood.h | 1 + rigs/kenwood/ts890s.c | 62 ++++-------------------------------------- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 7974d4423..f6aaed97c 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -3471,6 +3471,54 @@ int get_kenwood_level(RIG *rig, const char *cmd, float *fval, int *ival) RETURNFUNC(RIG_OK); } +/* Helper to get and parse meter values using RM + * Note that we turn readings on, but nothing off. + * 'pips' is the number of LED bars lit in the digital meter, max=70 + */ +int get_kenwood_meter_reading(RIG *rig, char meter, int *pips) +{ + char reading[9]; /* 8 char + '\0' */ + int retval; + char target[] = "RMx1"; /* Turn on reading this meter */ + + target[2] = meter; + retval = kenwood_transaction(rig, target, NULL, 0); + + if (retval != RIG_OK) + { + return retval; + } + + /* Read the first value */ + retval = kenwood_transaction(rig, "RM", reading, sizeof(reading)); + + if (retval != RIG_OK) + { + return retval; + } + + /* Find the one we want */ + while (strncmp(reading, target, 3) != 0) + { + /* That wasn't it, get the next one */ + retval = kenwood_transaction(rig, NULL, reading, sizeof(reading)); + + if (retval != RIG_OK) + { + return retval; + } + + if (reading[0] != target[0] || reading[1] != target[1]) + { + /* Somebody else's data, bail */ + return -RIG_EPROTO; + } + } + + sscanf(reading + 3, "%4d", pips); + return RIG_OK; + +} /* * kenwood_get_level diff --git a/rigs/kenwood/kenwood.h b/rigs/kenwood/kenwood.h index 0e2a3858f..6d2062dc1 100644 --- a/rigs/kenwood/kenwood.h +++ b/rigs/kenwood/kenwood.h @@ -264,6 +264,7 @@ int kenwood_get_trn(RIG *rig, int *trn); /* only use if returned string has length 6, e.g. 'SQ011;' */ int get_kenwood_level(RIG *rig, const char *cmd, float *fval, int *ival); int get_kenwood_func(RIG *rig, const char *cmd, int *status); +int get_kenwood_meter_reading(RIG *rig, char meter, int *pips); extern const struct rig_caps ts950s_caps; extern const struct rig_caps ts950sdx_caps; diff --git a/rigs/kenwood/ts890s.c b/rigs/kenwood/ts890s.c index e89a29092..f71d009fb 100644 --- a/rigs/kenwood/ts890s.c +++ b/rigs/kenwood/ts890s.c @@ -106,56 +106,6 @@ int kenwood_ts890_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) return kenwood_transaction(rig, levelbuf, NULL, 0); } -/* Helper to get and parse meter values using RM - * Note that we turn readings on, but nothing off. - * 'pips' is the number of LED bars lit in the digital meter, max=70 - */ -static -int ts890_get_meter_reading(RIG *rig, char meter, int *pips) -{ - char reading[9]; /* 8 char + '\0' */ - int retval; - char target[] = "RMx1"; /* Turn on reading this meter */ - - target[2] = meter; - retval = kenwood_transaction(rig, target, NULL, 0); - - if (retval != RIG_OK) - { - return retval; - } - - /* Read the first value */ - retval = kenwood_transaction(rig, "RM", reading, sizeof(reading)); - - if (retval != RIG_OK) - { - return retval; - } - - /* Find the one we want */ - while (strncmp(reading, target, 3) != 0) - { - /* That wasn't it, get the next one */ - retval = kenwood_transaction(rig, NULL, reading, sizeof(reading)); - - if (retval != RIG_OK) - { - return retval; - } - - if (reading[0] != target[0] || reading[1] != target[1]) - { - /* Somebody else's data, bail */ - return -RIG_EPROTO; - } - } - - sscanf(reading + 3, "%4d", pips); - return RIG_OK; - -} - int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { char ackbuf[50]; @@ -253,7 +203,7 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return RIG_OK; case RIG_LEVEL_ALC: - retval = ts890_get_meter_reading(rig, '1', &levelint); + retval = get_kenwood_meter_reading(rig, '1', &levelint); if (retval != RIG_OK) { @@ -264,7 +214,7 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return RIG_OK; case RIG_LEVEL_SWR: - retval = ts890_get_meter_reading(rig, '2', &levelint); + retval = get_kenwood_meter_reading(rig, '2', &levelint); if (retval != RIG_OK) { @@ -287,7 +237,7 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return RIG_OK; case RIG_LEVEL_COMP_METER: - retval = ts890_get_meter_reading(rig, '3', &levelint); + retval = get_kenwood_meter_reading(rig, '3', &levelint); if (retval != RIG_OK) { @@ -301,7 +251,7 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return RIG_OK; case RIG_LEVEL_ID_METER: - retval = ts890_get_meter_reading(rig, '4', &levelint); + retval = get_kenwood_meter_reading(rig, '4', &levelint); if (retval != RIG_OK) { @@ -312,7 +262,7 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return RIG_OK; case RIG_LEVEL_VD_METER: - retval = ts890_get_meter_reading(rig, '5', &levelint); + retval = get_kenwood_meter_reading(rig, '5', &levelint); if (retval != RIG_OK) { @@ -324,7 +274,7 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) case RIG_LEVEL_TEMP_METER: #if 0 - retval = ts890_get_meter_reading(rig, '6', &levelint); + retval = get_kenwood_meter_reading(rig, '6', &levelint); if (retval != RIG_OK) {