From 386b08dc4f529876f5c22fb36131b5fba73b064a Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Thu, 29 Apr 2021 10:49:29 -0500 Subject: [PATCH] Add ctcss_list and dcs_list to rigctld so rigcctld caps reflects the connected rig https://github.com/Hamlib/Hamlib/issues/659 --- include/hamlib/rig.h | 6 ++-- rigs/dummy/netrigctl.c | 70 +++++++++++++++++++++++++++++++++++++++--- rigs/kenwood/kenwood.c | 6 ++-- rigs/kenwood/kenwood.h | 6 ++-- rigs/kenwood/pihpsdr.c | 4 +-- rigs/kenwood/thf6a.c | 2 +- rigs/kenwood/thf7.c | 2 +- rigs/kenwood/ts2000.c | 4 +-- rigs/pcr/pcr.c | 4 +-- rigs/pcr/pcr.h | 4 +-- rigs/uniden/bc898.c | 2 +- rigs/uniden/uniden.c | 4 +-- rigs/uniden/uniden.h | 6 ++-- rigs/yaesu/ft100.c | 4 +-- rigs/yaesu/ft1000mp.c | 2 +- rigs/yaesu/ft736.c | 2 +- rigs/yaesu/ft767gx.c | 2 +- rigs/yaesu/ft847.c | 2 +- src/tones.c | 8 ++--- src/tones.h | 16 +++++++--- tests/rigctl_parse.c | 17 ++++++++++ 21 files changed, 131 insertions(+), 42 deletions(-) diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index ffb08df7f..1f1c781ee 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -214,6 +214,8 @@ typedef struct s_rig RIG; * * Digitally-Coded Squelch codes are simple direct integers. */ +#define CTCSS_LIST_SIZE 60 +#define DCS_LIST_SIZE 128 typedef unsigned int tone_t; @@ -1639,8 +1641,8 @@ struct rig_caps { const struct confparams *extfuncs; /*!< Extension func list, \sa ext.c */ int *ext_tokens; /*!< Extension token list */ - const tone_t *ctcss_list; /*!< CTCSS tones list, zero ended */ - const tone_t *dcs_list; /*!< DCS code list, zero ended */ + tone_t *ctcss_list; /*!< CTCSS tones list, zero ended */ + tone_t *dcs_list; /*!< DCS code list, zero ended */ int preamp[HAMLIB_MAXDBLSTSIZ]; /*!< Preamp list in dB, 0 terminated */ int attenuator[HAMLIB_MAXDBLSTSIZ]; /*!< Preamp list in dB, 0 terminated */ diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c index 20c7cd50b..e23f10556 100644 --- a/rigs/dummy/netrigctl.c +++ b/rigs/dummy/netrigctl.c @@ -41,7 +41,7 @@ #include "dummy.h" #define CMD_MAX 64 -#define BUF_MAX 96 +#define BUF_MAX 1024 #define CHKSCN1ARG(a) if ((a) != 1) return -RIG_EPROTO; else do {} while(0) @@ -198,6 +198,48 @@ static int netrigctl_cleanup(RIG *rig) return RIG_OK; } +int parse_array_int(const char *s, const char *delim, int *array, int array_len) +{ + char *p; + char *dup = strdup(s); + char *rest = dup; + int n=0; + ENTERFUNC; + while((p = strtok_r(rest, delim, &rest))) + { + if (n == array_len) { // too many items + return n; + } + array[n] = atoi(p); + //printf("%d\n", array[n]); + ++n; + } + free(dup); + return n; +} + +int parse_array_double(const char *s, const char *delim, double *array, int array_len) +{ + char *p; + char *dup = strdup(s); + char *rest = dup; + int n=0; + ENTERFUNC; + while((p = strtok_r(rest, delim, &rest))) + { + if (n == array_len) { // too many items + return n; + } + array[n] = atof(p); + //printf("%f\n", array[n]); + ++n; + } + free(dup); + return n; +} + + + static int netrigctl_open(RIG *rig) { int ret, len, i; @@ -576,7 +618,7 @@ static int netrigctl_open(RIG *rig) do { - char setting[32], value[256]; + char setting[32], value[1024]; ret = read_string(&rig->state.rigport, buf, BUF_MAX, "\n", 1); strtok(buf, "\r\n"); // chop the EOL @@ -587,7 +629,7 @@ static int netrigctl_open(RIG *rig) if (strncmp(buf, "done", 4) == 0) { return RIG_OK; } - if (sscanf(buf, "%31[^=]=%255[^\t\n]", setting, value) == 2) + if (sscanf(buf, "%31[^=]=%1024[^\t\n]", setting, value) == 2) { if (strcmp(setting, "vfo_ops") == 0) { @@ -679,7 +721,7 @@ static int netrigctl_open(RIG *rig) if (!has) { rig->caps->power2mW = NULL; } } - else if (strcmp(setting, "has_mw2power") == 0) + else if (strcmp(setting, "has_mW2power") == 0) { int has = strtol(value, NULL, 0); @@ -692,6 +734,26 @@ static int netrigctl_open(RIG *rig) rig_debug(RIG_DEBUG_TRACE, "%s: timeout value = '%s', final timeout=%d\n", __func__, value, rig->caps->timeout); } + else if (strcmp(setting, "ctcss_list") == 0) + { + int i; + int n; + double ctcss[CTCSS_LIST_SIZE]; + rig->caps->ctcss_list = calloc(CTCSS_LIST_SIZE, sizeof(tone_t)); + n = parse_array_double(value, " \n\r", ctcss, CTCSS_LIST_SIZE); + for(i=0;icaps->ctcss_list[i] = ctcss[i]*10; + if (n < CTCSS_LIST_SIZE) rig->caps->ctcss_list[n] = 0; + } + else if (strcmp(setting,"dcs_list") == 0) + { + int i; + int n; + int dcs[DCS_LIST_SIZE+1]; + rig->caps->dcs_list = calloc(DCS_LIST_SIZE, sizeof(tone_t)); + n = parse_array_int(value, " \n\r", dcs, DCS_LIST_SIZE); + for(i=0;icaps->dcs_list[i] = dcs[i]; + if (n < DCS_LIST_SIZE) rig->caps->dcs_list[n] = 0; + } else { // not an error -- just a warning for backward compatibility diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index c39cbf5ca..3ad2842a5 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -157,7 +157,7 @@ rmode_t kenwood_mode_table[KENWOOD_MODE_TABLE_MAX] = /* * 38 CTCSS sub-audible tones */ -const tone_t kenwood38_ctcss_list[] = +tone_t kenwood38_ctcss_list[] = { 670, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, 1318, @@ -170,7 +170,7 @@ const tone_t kenwood38_ctcss_list[] = /* * 42 CTCSS sub-audible tones */ -const tone_t kenwood42_ctcss_list[] = +tone_t kenwood42_ctcss_list[] = { 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, 1318, @@ -184,7 +184,7 @@ const tone_t kenwood42_ctcss_list[] = * * See enum rig_conf_e and struct confparams in rig.h */ -const struct confparams kenwood_cfg_params[] = +struct confparams kenwood_cfg_params[] = { { TOK_FINE, "fine", "Fine", "Fine step mode", diff --git a/rigs/kenwood/kenwood.h b/rigs/kenwood/kenwood.h index abe0829a5..76b6436d8 100644 --- a/rigs/kenwood/kenwood.h +++ b/rigs/kenwood/kenwood.h @@ -50,7 +50,7 @@ #define TOK_FUNC_FILTER_WIDTH_DATA TOKEN_BACKEND(6) // Data communications mode that affects SL/SH/FW commands /* Token structure assigned to .cfgparams in rig_caps */ -extern const struct confparams kenwood_cfg_params[]; +extern struct confparams kenwood_cfg_params[]; /* @@ -173,8 +173,8 @@ struct kenwood_priv_data extern rmode_t kenwood_mode_table[KENWOOD_MODE_TABLE_MAX]; -extern const tone_t kenwood38_ctcss_list[]; -extern const tone_t kenwood42_ctcss_list[]; +extern tone_t kenwood38_ctcss_list[]; +extern tone_t kenwood42_ctcss_list[]; int kenwood_transaction(RIG *rig, const char *cmdstr, char *data, size_t datasize); int kenwood_safe_transaction(RIG *rig, const char *cmd, char *buf, diff --git a/rigs/kenwood/pihpsdr.c b/rigs/kenwood/pihpsdr.c index 05830c136..3136e1dc9 100644 --- a/rigs/kenwood/pihpsdr.c +++ b/rigs/kenwood/pihpsdr.c @@ -130,8 +130,8 @@ const struct rig_caps pihpsdr_caps = .parm_gran = {}, .vfo_ops = PIHPSDR_VFO_OP, .scan_ops = PIHPSDR_SCAN_OP, - .ctcss_list = static_common_ctcss_list, - .dcs_list = static_common_dcs_list, + .ctcss_list = common_ctcss_list, + .dcs_list = common_dcs_list, .preamp = { 20, RIG_DBLST_END, }, /* FIXME: real preamp? */ .attenuator = { 20, RIG_DBLST_END, }, .max_rit = kHz(20), diff --git a/rigs/kenwood/thf6a.c b/rigs/kenwood/thf6a.c index 9fc73e537..d7eb15138 100644 --- a/rigs/kenwood/thf6a.c +++ b/rigs/kenwood/thf6a.c @@ -71,7 +71,7 @@ .dcs_sql=1, /* CTCSS 01..42 */ -static const tone_t thf6_ctcss_list[] = +static tone_t thf6_ctcss_list[] = { 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, diff --git a/rigs/kenwood/thf7.c b/rigs/kenwood/thf7.c index 68a8d5f55..eda15a8d1 100644 --- a/rigs/kenwood/thf7.c +++ b/rigs/kenwood/thf7.c @@ -65,7 +65,7 @@ .dcs_sql=1, /* CTCSS 01..42 */ -static const tone_t thf7_ctcss_list[] = +static tone_t thf7_ctcss_list[] = { 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, diff --git a/rigs/kenwood/ts2000.c b/rigs/kenwood/ts2000.c index 606153661..87c9b0ee6 100644 --- a/rigs/kenwood/ts2000.c +++ b/rigs/kenwood/ts2000.c @@ -65,7 +65,7 @@ static int ts2000_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan); /* * 38 CTCSS sub-audible tones + 1750 tone */ -const tone_t ts2000_ctcss_list[] = +tone_t ts2000_ctcss_list[] = { 670, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, 1318, @@ -79,7 +79,7 @@ const tone_t ts2000_ctcss_list[] = /* * 103 available DCS codes */ -static const tone_t ts2000_dcs_list[] = +tone_t ts2000_dcs_list[] = { 23, 25, 26, 31, 32, 36, 43, 47, 51, 53, 54, 65, 71, 72, 73, 74, 114, 115, 116, 122, 125, 131, diff --git a/rigs/pcr/pcr.c b/rigs/pcr/pcr.c index 8352987f3..8add36dab 100644 --- a/rigs/pcr/pcr.c +++ b/rigs/pcr/pcr.c @@ -76,7 +76,7 @@ * Don't even touch a single bit! indexes will be used in the protocol! * 51 tones, the 60.0 Hz tone is missing. */ -const tone_t pcr_ctcss_list[] = +tone_t pcr_ctcss_list[] = { 670, 693, 710, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, @@ -91,7 +91,7 @@ const tone_t pcr_ctcss_list[] = * Don't even touch a single bit! indexes will be used in the protocol! * 104 codes */ -const tone_t pcr_dcs_list[] = +tone_t pcr_dcs_list[] = { 23, 25, 26, 31, 32, 36, 43, 47, 51, 53, 54, 65, 71, 72, 73, 74, 114, 115, 116, 122, 125, 131, diff --git a/rigs/pcr/pcr.h b/rigs/pcr/pcr.h index 25516ca17..89714f1f1 100644 --- a/rigs/pcr/pcr.h +++ b/rigs/pcr/pcr.h @@ -81,8 +81,8 @@ struct pcr_priv_caps #define pcr_caps(rig) ((struct pcr_priv_caps *)(rig)->caps->priv) -extern const tone_t pcr_ctcss_list[]; -extern const tone_t pcr_dcs_list[]; +extern tone_t pcr_ctcss_list[]; +extern tone_t pcr_dcs_list[]; int pcr_init(RIG *rig); int pcr_cleanup(RIG *rig); diff --git a/rigs/uniden/bc898.c b/rigs/uniden/bc898.c index bfaa4f6b6..dd55beacb 100644 --- a/rigs/uniden/bc898.c +++ b/rigs/uniden/bc898.c @@ -53,7 +53,7 @@ { 255, 60 }, \ } } -static const tone_t bc898_ctcss_list[] = +static tone_t bc898_ctcss_list[] = { 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, diff --git a/rigs/uniden/uniden.c b/rigs/uniden/uniden.c index 68ecf9da8..bdd81e9a0 100644 --- a/rigs/uniden/uniden.c +++ b/rigs/uniden/uniden.c @@ -55,7 +55,7 @@ uniden_id_string_list[] = }; -const tone_t uniden_ctcss_list[] = +tone_t uniden_ctcss_list[] = { 670, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, @@ -64,7 +64,7 @@ const tone_t uniden_ctcss_list[] = 2418, 2503, 0 }; -const tone_t uniden_dcs_list[] = +tone_t uniden_dcs_list[] = { 23, 25, 26, 31, 32, 36, 43, 47, 51, 53, 54, 65, 71, 72, 73, 74, 114, 115, 116, 122, diff --git a/rigs/uniden/uniden.h b/rigs/uniden/uniden.h index ed3eea64b..97d5f329a 100644 --- a/rigs/uniden/uniden.h +++ b/rigs/uniden/uniden.h @@ -51,11 +51,11 @@ { 255, 60 }, \ } } -extern const tone_t uniden_ctcss_list[]; -extern const tone_t uniden_dcs_list[]; +extern tone_t uniden_ctcss_list[]; +extern tone_t uniden_dcs_list[]; int uniden_transaction (RIG *rig, const char *cmdstr, int cmd_len, - const char *replystr, char *data, size_t *datasize); +const char *replystr, char *data, size_t *datasize); int uniden_set_freq(RIG *rig, vfo_t vfo, freq_t freq); int uniden_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); int uniden_get_freq_2(RIG *rig, vfo_t vfo, freq_t *freq); diff --git a/rigs/yaesu/ft100.c b/rigs/yaesu/ft100.c index da0a018cd..52b18a8bb 100644 --- a/rigs/yaesu/ft100.c +++ b/rigs/yaesu/ft100.c @@ -120,7 +120,7 @@ static const yaesu_cmd_set_t ncmd[] = }; -static const tone_t ft100_ctcss_list[] = +static tone_t ft100_ctcss_list[] = { 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, \ 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, \ @@ -129,7 +129,7 @@ static const tone_t ft100_ctcss_list[] = 2503, 0 }; -static const tone_t ft100_dcs_list[] = +static tone_t ft100_dcs_list[] = { 23, 25, 26, 31, 32, 36, 43, 47, 51, 53, \ 54, 65, 71, 72, 73, 74, 114, 115, 116, 122, 125, 131, \ diff --git a/rigs/yaesu/ft1000mp.c b/rigs/yaesu/ft1000mp.c index 0d59d7ebf..814f6b59b 100644 --- a/rigs/yaesu/ft1000mp.c +++ b/rigs/yaesu/ft1000mp.c @@ -157,7 +157,7 @@ static const yaesu_cmd_set_t ncmd[] = /** * 33 CTCSS sub-audible tones */ -static const tone_t ft1000mp_ctcss_list[] = +static tone_t ft1000mp_ctcss_list[] = { 670, 719, 770, 825, 885, 948, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, diff --git a/rigs/yaesu/ft736.c b/rigs/yaesu/ft736.c index a406431b8..ec4a023eb 100644 --- a/rigs/yaesu/ft736.c +++ b/rigs/yaesu/ft736.c @@ -80,7 +80,7 @@ static int ft736_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone); /* Some tones are present twice, the second value is * higher Q (80), according to manual. */ -static const tone_t ft736_ctcss_list[] = +static tone_t ft736_ctcss_list[] = { 670, 719, 770, 825, 885, 948, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, 1318, 1365, 1413, 1462, 1514, 1567, diff --git a/rigs/yaesu/ft767gx.c b/rigs/yaesu/ft767gx.c index 9ddad66be..290f4a6de 100644 --- a/rigs/yaesu/ft767gx.c +++ b/rigs/yaesu/ft767gx.c @@ -249,7 +249,7 @@ struct ft767_priv_data unsigned char ack_cmd[5]; }; -const tone_t static_767gx_ctcss_list[] = +tone_t static_767gx_ctcss_list[] = { CTCSS_TONE_LIST }; diff --git a/rigs/yaesu/ft847.c b/rigs/yaesu/ft847.c index 9ac8e0815..da42a36d1 100644 --- a/rigs/yaesu/ft847.c +++ b/rigs/yaesu/ft847.c @@ -193,7 +193,7 @@ static const yaesu_cmd_set_t ncmd[] = * 39 CTCSS sub-audible tones * c.f. ft847_set_ctcss_tone() */ -static const tone_t ft847_ctcss_list[] = +static tone_t ft847_ctcss_list[] = { 670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, diff --git a/src/tones.c b/src/tones.c index bb3ec0096..d5c2ff8b2 100644 --- a/src/tones.c +++ b/src/tones.c @@ -44,7 +44,7 @@ /** * 52 CTCSS sub-audible tones */ -const tone_t full_ctcss_list[] = { FULL_CTCSS_LIST }; +tone_t full_ctcss_list[] = { FULL_CTCSS_LIST }; /** * 50 CTCSS sub-audible tones, from 67.0Hz to 254.1Hz @@ -53,17 +53,17 @@ const tone_t full_ctcss_list[] = { FULL_CTCSS_LIST }; * backends depend on it. If you need to, create a copy for your * own caps. --SF */ -const tone_t common_ctcss_list[] = { COMMON_CTCSS_LIST }; +tone_t common_ctcss_list[] = { COMMON_CTCSS_LIST }; /** * 104 DCS codes */ -const tone_t common_dcs_list[] = { COMMON_DCS_LIST }; +tone_t common_dcs_list[] = { COMMON_DCS_LIST }; /** * 106 DCS codes */ -const tone_t full_dcs_list[] = { FULL_DCS_LIST }; +tone_t full_dcs_list[] = { FULL_DCS_LIST }; #endif diff --git a/src/tones.h b/src/tones.h index 852554330..204b66f7f 100644 --- a/src/tones.h +++ b/src/tones.h @@ -37,10 +37,12 @@ 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \ 0, +#if 0 static const tone_t static_full_ctcss_list[] = { FULL_CTCSS_LIST }; +#endif #define FULL_CTCSS_LIST_COUNT 52 @@ -60,10 +62,12 @@ static const tone_t static_full_ctcss_list[] = 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541, \ 0, +#if 0 static const tone_t static_common_ctcss_list[] = { COMMON_CTCSS_LIST }; +#endif #define COMMON_CTCSS_LIST_COUNT 50 @@ -83,10 +87,12 @@ static const tone_t static_common_ctcss_list[] = 662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \ 0, +#if 0 static const tone_t static_common_dcs_list[] = { COMMON_DCS_LIST }; +#endif #define COMMON_DCS_LIST_COUNT 104 @@ -105,10 +111,12 @@ static const tone_t static_common_dcs_list[] = 662, 664, 703, 712, 723, 731, 732, 734, 743, 754, \ 0, +#if 0 static const tone_t static_full_dcs_list[] = { FULL_DCS_LIST }; +#endif #define FULL_DCS_LIST_COUNT 106 @@ -124,10 +132,10 @@ static const tone_t static_full_dcs_list[] = #else -extern const HAMLIB_EXPORT_VAR(tone_t) full_ctcss_list[]; -extern const HAMLIB_EXPORT_VAR(tone_t) common_ctcss_list[]; -extern const HAMLIB_EXPORT_VAR(tone_t) full_dcs_list[]; -extern const HAMLIB_EXPORT_VAR(tone_t) common_dcs_list[]; +extern HAMLIB_EXPORT_VAR(tone_t) full_ctcss_list[]; +extern HAMLIB_EXPORT_VAR(tone_t) common_ctcss_list[]; +extern HAMLIB_EXPORT_VAR(tone_t) full_dcs_list[]; +extern HAMLIB_EXPORT_VAR(tone_t) common_dcs_list[]; #endif diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 2e6813b42..018922115 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -4350,6 +4350,23 @@ declare_proto_rig(dump_state) fprintf(fout, "has_power2mW=%d\n", rig->caps->power2mW != NULL); fprintf(fout, "has_mW2power=%d\n", rig->caps->mW2power != NULL); fprintf(fout, "timeout=%d\n", rig->caps->timeout); + fprintf(fout, "ctcss_list="); + for (i = 0; i < CTCSS_LIST_SIZE && rig->caps->ctcss_list[i] != 0; i++) + { + fprintf(fout, + " %u.%1u", + rig->caps->ctcss_list[i] / 10, rig->caps->ctcss_list[i] % 10); + } + fprintf(fout, "\n"); + fprintf(fout, "dcs_list="); + for (i = 0; i < DCS_LIST_SIZE && rig->caps->dcs_list[i] != 0; i++) + { + fprintf(fout, + " %u", + rig->caps->dcs_list[i]); + } + fprintf(fout, "\n"); + fprintf(fout, "done\n"); }