From 02ffc6d6dcaa34100e2b7ff93e7713999505c45c Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sun, 5 Nov 2023 17:03:21 -0600 Subject: [PATCH] More set_conf/get_conf work https://github.com/Hamlib/Hamlib/issues/971 --- src/network.c | 10 ++- tests/ampctl.c | 24 +++++-- tests/ampctl_parse.c | 2 +- tests/ampctld.c | 27 +++++--- tests/dumpcaps.c | 13 ++++ tests/dumpcaps_rot.c | 7 +++ tests/rigctl.c | 26 ++++++-- tests/rigctl_parse.c | 130 +++++++++++++++++++++++--------------- tests/rigctl_parse.h | 2 + tests/rigctlcom.c | 3 +- tests/rigctld.c | 27 ++++++-- tests/rigctltcp.c | 3 +- tests/rotctl.c | 24 +++++-- tests/rotctl_parse.c | 146 +++++++++++++++++++++++++++---------------- tests/rotctl_parse.h | 1 + tests/rotctld.c | 24 +++++-- 16 files changed, 329 insertions(+), 140 deletions(-) diff --git a/src/network.c b/src/network.c index c4754cbd1..a68329149 100644 --- a/src/network.c +++ b/src/network.c @@ -999,15 +999,19 @@ void *multicast_receiver(void *arg) __LINE__); int optval = 1; +#ifdef __MINGW32__ + if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (PCHAR)&optval, sizeof(optval)) < 0) +#else if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) +#endif { rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP address reuse: %s\n", __func__, strerror(errno)); return NULL; } -#if defined(SO_REUSEPORT) // Windows does not have SO_REUSEPORT. However, SO_REUSEADDR works in a similar way. +#if defined(SO_REUSEPORT) if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP port reuse: %s\n", __func__, @@ -1038,7 +1042,11 @@ void *multicast_receiver(void *arg) mreq.imr_multiaddr.s_addr = inet_addr(args->multicast_addr); mreq.imr_interface.s_addr = htonl(INADDR_ANY); +#ifdef __MINGW32__ + if (setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (PCHAR)&mreq, sizeof(mreq)) < 0) +#else if (setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) +#endif { rig_debug(RIG_DEBUG_ERR, "%s: error joining multicast group %s:%d: %s\n", __func__, args->multicast_addr, args->multicast_port, strerror(errno)); diff --git a/tests/ampctl.c b/tests/ampctl.c index 6a179206f..5c75e5034 100644 --- a/tests/ampctl.c +++ b/tests/ampctl.c @@ -298,12 +298,28 @@ int main(int argc, char *argv[]) exit(2); } - retcode = set_conf(my_amp, conf_parms); + char *token=strtok(conf_parms,","); - if (retcode != RIG_OK) + while(token) { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); + char mytoken[100], myvalue[100]; + token_t lookup; + sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); + lookup = amp_token_lookup(my_amp,mytoken); + if (lookup == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); + token = strtok(NULL, ","); + continue; + } + retcode = amp_set_conf(my_amp, amp_token_lookup(my_amp,mytoken), myvalue); + if (retcode != RIG_OK) + { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } + token = strtok(NULL, ","); } if (amp_file) diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 01ffba765..41d080d7a 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -1630,7 +1630,7 @@ int set_conf(AMP *my_amp, char *conf_parms) } else { - rig_debug(RIG_DEBUG_WARN, "%s: invalid token %s for this rig\n", __func__, p); + rig_debug(RIG_DEBUG_WARN, "%s: invalid token %s for this amp\n", __func__, p); } p = n; diff --git a/tests/ampctld.c b/tests/ampctld.c index 6aeef098c..8244a5441 100644 --- a/tests/ampctld.c +++ b/tests/ampctld.c @@ -323,17 +323,30 @@ int main(int argc, char *argv[]) exit(2); } -#if 0 - retcode = set_conf(my_amp, conf_parms); + char *token=strtok(conf_parms,","); - if (retcode != RIG_OK) + while(token) { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); + char mytoken[100], myvalue[100]; + token_t lookup; + sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); + lookup = amp_token_lookup(my_amp,mytoken); + if (lookup == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); + token = strtok(NULL, ","); + continue; + } + retcode = amp_set_conf(my_amp, amp_token_lookup(my_amp,mytoken), myvalue); + if (retcode != RIG_OK) + { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } + token = strtok(NULL, ","); } -#endif - if (amp_file) { strncpy(my_amp->state.ampport.pathname, amp_file, HAMLIB_FILPATHLEN - 1); diff --git a/tests/dumpcaps.c b/tests/dumpcaps.c index f1d99de0d..db473caab 100644 --- a/tests/dumpcaps.c +++ b/tests/dumpcaps.c @@ -28,6 +28,7 @@ #include "sprintflst.h" #include "rigctl_parse.h" #include "../rigs/icom/icom.h" +#include "dumpcaps.h" void range_print(FILE *fout, const struct freq_range_list range_list[], int rx); int range_sanity_check(const struct freq_range_list range_list[], int rx); @@ -1238,3 +1239,15 @@ int dumpconf(RIG *rig, FILE *fout) return 0; } + +int dumpconf_list(RIG *rig, FILE *fout) +{ + rig_token_foreach(rig, print_conf_list2, (rig_ptr_t)rig); + return 0; +} + +int dumpconf_list_rot(ROT *rot, FILE *fout) +{ + rot_token_foreach(rot, print_conf_list2, rot); + return 0; +} diff --git a/tests/dumpcaps_rot.c b/tests/dumpcaps_rot.c index 69626dd46..408defc70 100644 --- a/tests/dumpcaps_rot.c +++ b/tests/dumpcaps_rot.c @@ -242,3 +242,10 @@ int dumpcaps_rot(ROT *rot, FILE *fout) return backend_warnings; } + +int dumpconf_list(ROT *rot, FILE *fout) +{ + rot_token_foreach(rot, print_conf_list, rot); + return 0; +} + diff --git a/tests/rigctl.c b/tests/rigctl.c index 6ae1bd9e1..73e5380ad 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -555,12 +555,28 @@ int main(int argc, char *argv[]) exit(2); } - retcode = set_conf(my_rig, conf_parms); - - if (retcode != RIG_OK) + char *token=strtok(conf_parms,","); + + while(token) { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); + char mytoken[100], myvalue[100]; + token_t lookup; + sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); + lookup = rig_token_lookup(my_rig,mytoken); + if (lookup == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); + token = strtok(NULL, ","); + continue; + } + retcode = rig_set_conf(my_rig, rig_token_lookup(my_rig,mytoken), myvalue); + if (retcode != RIG_OK) + { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } + token = strtok(NULL, ","); } if (rig_file) diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index d488ec0f2..668034b8b 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -270,6 +270,8 @@ declare_proto_rig(hamlib_version); declare_proto_rig(test); declare_proto_rig(cm108_get_bit); declare_proto_rig(cm108_set_bit); +declare_proto_rig(set_conf); +declare_proto_rig(get_conf); /* @@ -390,6 +392,8 @@ static struct test_table test_list[] = { 0xa8, "hamlib_version", ACTION(hamlib_version), ARG_NOVFO }, { 0xa9, "get_gpio", ACTION(cm108_get_bit), ARG_NOVFO | ARG_IN1 | ARG_OUT1, "GPIO#", "0/1" }, { 0xaa, "set_gpio", ACTION(cm108_set_bit), ARG_NOVFO | ARG_IN , "GPIO#", "0/1" }, + { 0xac, "set_conf", ACTION(set_conf), ARG_NOVFO | ARG_IN , "Token", "Token Value" }, + { 0xad, "get_conf", ACTION(get_conf), ARG_NOVFO | ARG_IN1 | ARG_OUT2, "Token", "Value"}, { 0x00, "", NULL }, }; @@ -1989,6 +1993,21 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) return 1; /* !=0, we want them all ! */ } +// short list for rigctl/rigctld display +int print_conf_list2(const struct confparams *cfp, rig_ptr_t data) +{ + RIG *rig = (RIG *) data; + char buf[128] = ""; + + rig_get_conf(rig, cfp->token, buf); + fprintf(stdout,"%s: \"%s\"\n" "\t" "Default: %s, Value: %s\n", + cfp->name, + cfp->tooltip, + cfp->dflt, + buf); + + return 1; /* !=0, we want them all ! */ +} static int hash_model_list(const struct rig_caps *caps, void *data) { @@ -2040,58 +2059,6 @@ void list_models() hash_delete_all(); } - -int set_conf(RIG *my_rig, char *conf_parms) -{ - char *p, *n; - int token; - - rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - p = conf_parms; - - while (p && *p != '\0') - { - int ret; - - /* FIXME: left hand value of = cannot be null */ - char *q = strchr(p, '='); - - if (!q) - { - return (-RIG_EINVAL); - } - - *q++ = '\0'; - n = strchr(q, ','); - - if (n) - { - *n++ = '\0'; - } - - token = rig_token_lookup(my_rig, p); - - if (token != 0) - { - ret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); - - if (ret != RIG_OK) - { - return (ret); - } - } - else - { - rig_debug(RIG_DEBUG_WARN, "%s: invalid token %s for this rig\n", __func__, p); - } - - p = n; - } - - return (RIG_OK); -} - - /* * static int (f)(RIG *rig, FILE *fout, int interactive, const struct test_table *cmd, * vfo_t vfo, const void *arg1, const void *arg2, const void *arg3) @@ -5790,3 +5757,62 @@ declare_proto_rig(cm108_set_bit) } return retval; } + +declare_proto_rig(get_conf) +{ + int ret; + rig_debug(RIG_DEBUG_ERR, "%s: \n", __func__); + if (arg1 == NULL || arg1[0] == '?') + { + dumpconf_list(rig, stdout); + debugmsgsave[0] = 0; + debugmsgsave2[0] = 0; + return RIG_OK; + } + token_t mytoken = rig_token_lookup(rig, arg1); + if (mytoken == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rig\n", __func__, arg1); + ret = -RIG_EINVAL; + } + else + { + char value[4096]; // no max value known -- should we limit it? + ret = rig_get_conf(rig, mytoken, value); + if (ret != RIG_OK) + { + return ret; + } + fprintf(fout, "%s=%s\n", arg1, value); + } + + return (ret); +} + +declare_proto_rig(set_conf) +{ + int ret; + rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); + + + if (arg1[0] == '?') + { + dumpconf_list(rig, fout); + debugmsgsave[0] = 0; + debugmsgsave2[0] = 0; + return RIG_OK; + } + token_t mytoken = rig_token_lookup(rig, arg1); + if (mytoken == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rig\n", __func__, arg1); + ret = -RIG_EINVAL; + } + else + { + ret = rig_set_conf(rig, rig_token_lookup(rig, arg1), arg2); + } + + return (ret); +} + diff --git a/tests/rigctl_parse.h b/tests/rigctl_parse.h index 1553d2096..72fdeb9fb 100644 --- a/tests/rigctl_parse.h +++ b/tests/rigctl_parse.h @@ -38,6 +38,7 @@ int dumpcaps(RIG *, FILE *); int dumpstate(RIG *, FILE *); int dumpconf(RIG *, FILE *); +int dumpconf_list(RIG *, FILE *); /* * Prototypes @@ -47,6 +48,7 @@ void version(); void list_models(); int dump_chan(FILE *, RIG *, channel_t *); int print_conf_list(const struct confparams *cfp, rig_ptr_t data); +int print_conf_list2(const struct confparams *cfp, rig_ptr_t data); int set_conf(RIG *my_rig, char *conf_parms); typedef void (*sync_cb_t)(int); diff --git a/tests/rigctlcom.c b/tests/rigctlcom.c index 329337467..b81f03a97 100644 --- a/tests/rigctlcom.c +++ b/tests/rigctlcom.c @@ -492,7 +492,8 @@ int main(int argc, char *argv[]) exit(2); } - retcode = set_conf(my_rig, conf_parms); + retcode = -RIG_ENIMPL; +// retcode = set_conf(my_rig, conf_parms); if (retcode != RIG_OK) { diff --git a/tests/rigctld.c b/tests/rigctld.c index dda18b891..2bce5b814 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -659,13 +659,28 @@ int main(int argc, char *argv[]) fprintf(stderr, "Please check with --list option.\n"); exit(2); } - - retcode = set_conf(my_rig, conf_parms); - - if (retcode != RIG_OK) + + char *token=strtok(conf_parms,","); + while(token) { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); + char mytoken[100], myvalue[100]; + token_t lookup; + sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); + lookup = rig_token_lookup(my_rig,mytoken); + if (lookup == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); + token = strtok(NULL, ","); + continue; + } + retcode = rig_set_conf(my_rig, rig_token_lookup(my_rig,mytoken), myvalue); + if (retcode != RIG_OK) + { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } + token = strtok(NULL, ","); } if (rig_file) diff --git a/tests/rigctltcp.c b/tests/rigctltcp.c index 7053b49d4..51beb5433 100644 --- a/tests/rigctltcp.c +++ b/tests/rigctltcp.c @@ -674,7 +674,8 @@ int main(int argc, char *argv[]) exit(2); } - retcode = set_conf(my_rig, conf_parms); + retcode = -RIG_ENIMPL; +// retcode = set_conf(my_rig, conf_parms); if (retcode != RIG_OK) { diff --git a/tests/rotctl.c b/tests/rotctl.c index 3a680719c..cdf2b7775 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -339,12 +339,28 @@ int main(int argc, char *argv[]) exit(2); } - retcode = set_conf(my_rot, conf_parms); + char *token=strtok(conf_parms,","); - if (retcode != RIG_OK) + while(token) { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); + char mytoken[100], myvalue[100]; + token_t lookup; + sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); + lookup = rot_token_lookup(my_rot,mytoken); + if (lookup == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n", __func__, mytoken); + token = strtok(NULL, ","); + continue; + } + retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot,mytoken), myvalue); + if (retcode != RIG_OK) + { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } + token = strtok(NULL, ","); } if (rot_file) diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index acbe40df7..4191c751a 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -24,8 +24,6 @@ * */ -// TODO: Add "symmetric" set_conf + get_conf to rigctl+rotctl - #include #include @@ -65,7 +63,7 @@ extern int read_history(); #include #include "iofunc.h" #include "misc.h" - +#include "dumpcaps_rot.h" /* HAVE_SSLEEP is defined when Windows Sleep is found * HAVE_SLEEP is defined when POSIX sleep is found @@ -189,10 +187,12 @@ declare_proto_rot(set_parm); declare_proto_rot(get_parm); declare_proto_rot(get_info); declare_proto_rot(get_status); -declare_proto_rot(inter_set_conf); /* interactive mode set_conf */ +declare_proto_rot(set_conf); +declare_proto_rot(get_conf); declare_proto_rot(send_cmd); declare_proto_rot(dump_state); declare_proto_rot(dump_caps); +declare_proto_rot(dump_conf); /* Follows are functions from locator.c */ declare_proto_rot(loc2lonlat); declare_proto_rot(lonlat2loc); @@ -224,11 +224,12 @@ struct test_table test_list[] = { 'u', "get_func", ACTION(get_func), ARG_IN1 | ARG_OUT2, "Func", "Func Status" }, { 'X', "set_parm", ACTION(set_parm), ARG_IN, "Parm", "Parm Value" }, { 'x', "get_parm", ACTION(get_parm), ARG_IN1 | ARG_OUT2, "Parm", "Parm Value" }, - { 'C', "set_conf", ACTION(inter_set_conf), ARG_IN, "Token", "Value" }, + { 'C', "set_conf", ACTION(set_conf), ARG_IN, "Token", "Value" }, { '_', "get_info", ACTION(get_info), ARG_OUT, "Info" }, { 's', "get_status", ACTION(get_status), ARG_OUT, "Status flags" }, { 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2, "Cmd", "Reply" }, { '1', "dump_caps", ACTION(dump_caps), }, + { '3', "dump_conf", ACTION(dump_conf), }, { 0x8f, "dump_state", ACTION(dump_state), ARG_OUT }, { 'L', "lonlat2loc", ACTION(lonlat2loc), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1, "Longitude", "Latitude", "Loc Len [2-12]", "Locator" }, { 'l', "loc2lonlat", ACTION(loc2lonlat), ARG_IN1 | ARG_OUT1 | ARG_OUT2, "Locator", "Longitude", "Latitude" }, @@ -240,6 +241,7 @@ struct test_table test_list[] = { 'A', "a_sp2a_lp", ACTION(az_sp2az_lp), ARG_IN1 | ARG_OUT1, "Short Path Deg", "Long Path Deg" }, { 'a', "d_sp2d_lp", ACTION(dist_sp2dist_lp), ARG_IN1 | ARG_OUT1, "Short Path km", "Long Path km" }, { 0x8c, "pause", ACTION(pause), ARG_IN, "Seconds" }, + { 0xad, "get_conf", ACTION(get_conf), ARG_IN1 | ARG_OUT2, "Token", "Value"}, { 0x00, "", NULL }, }; @@ -1574,7 +1576,7 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) char buf[128] = ""; rot_get_conf2(rot, cfp->token, buf, sizeof(buf)); - printf("%s: \"%s\"\n" "\tDefault: %s, Value: %s\n", + fprintf(stdout,"%s: \"%s\"\n" "\tDefault: %s, Value: %s\n", cfp->name, cfp->tooltip, cfp->dflt, @@ -1583,14 +1585,14 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) switch (cfp->type) { case RIG_CONF_NUMERIC: - printf("\tRange: %.1f..%.1f, step %.1f\n", + fprintf(stdout,"\tRange: %.1f..%.1f, step %.1f\n", cfp->u.n.min, cfp->u.n.max, cfp->u.n.step); break; case RIG_CONF_CHECKBUTTON: - printf("\tCheckbox: 0,1\n"); + fprintf(stdout,"\tCheckbox: 0,1\n"); break; case RIG_CONF_COMBO: @@ -1599,14 +1601,14 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) break; } - printf("\tCombo: %s", cfp->u.c.combostr[0]); + fprintf(stdout,"\tCombo: %s", cfp->u.c.combostr[0]); for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) { - printf(", %s", cfp->u.c.combostr[i]); + fprintf(stdout,", %s", cfp->u.c.combostr[i]); } - printf("\n"); + fprintf(stdout,"\n"); break; default: @@ -1666,55 +1668,64 @@ void list_models() hash_delete_all(); } - -int set_conf(ROT *my_rot, char *conf_parms) +declare_proto_rot(get_conf) { - char *p; - - rot_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); - p = conf_parms; - - while (p && *p != '\0') + int ret; + rig_debug(RIG_DEBUG_ERR, "%s: \n", __func__); + if (arg1 == NULL || arg1[0] == '?') { - int token; - char *q, *n = NULL; - /* FIXME: left hand value of = cannot be null */ - q = strchr(p, '='); - - if (!q) + dumpconf_list(rot, fout); + debugmsgsave[0] = 0; + debugmsgsave2[0] = 0; + return RIG_OK; + } + token_t mytoken = rot_token_lookup(rot, arg1); + if (mytoken == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rot\n", __func__, arg1); + ret = -RIG_EINVAL; + } + else + { + char value[4096]; + ret = rot_get_conf(rot, rot_token_lookup(rot, arg1), value); + if (ret != RIG_OK) { - return RIG_EINVAL; + return ret; } - - *q++ = '\0'; - n = strchr(q, ','); - - if (n) - { - *n++ = '\0'; - } - - token = rot_token_lookup(my_rot, p); - - if (token != 0) - { - int ret; - ret = rot_set_conf(my_rot, token, q); - - if (ret != RIG_OK) - { - return ret; - } - } - else - { - rig_debug(RIG_DEBUG_WARN, "%s: invalid token %s for this rig\n", __func__, p); - } - - p = n; + fprintf(fout, "%s=%s\n", arg1, value); } - return RIG_OK; + return (ret); +} + + +/* 'C' */ +declare_proto_rot(set_conf) +{ + int ret; + rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); + + if (arg1[0] == '?') + { + dumpconf_list(rot, fout); + debugmsgsave[0] = 0; + debugmsgsave2[0] = 0; + return RIG_OK; + } + + token_t mytoken = rot_token_lookup(rot, arg1); + if (mytoken == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rot\n", __func__, arg1); + ret = -RIG_EINVAL; + } + else + { + ret = rot_set_conf(rot, rot_token_lookup(rot, arg1), arg2); + } + + return (ret); } @@ -2344,6 +2355,7 @@ declare_proto_rot(get_parm) } +#if 0 // replace by set_conf /* 'C' */ declare_proto_rot(inter_set_conf) { @@ -2361,6 +2373,7 @@ declare_proto_rot(inter_set_conf) SNPRINTF(buf, sizeof(buf), "%s=%s", arg1, arg2); return set_conf(rot, buf); } +#endif /* '1' */ declare_proto_rot(dump_caps) @@ -2370,6 +2383,14 @@ declare_proto_rot(dump_caps) return RIG_OK; } +declare_proto_rot(dump_conf) +{ + ENTERFUNC2; + + dumpconf_list(rot, fout); + + RETURNFUNC2(RIG_OK); +} /* For rotctld internal use * '0x8f' @@ -2862,3 +2883,20 @@ declare_proto_rot(pause) sleep(seconds); return RIG_OK; } + +// short list for rigctl/rigctld display +int print_conf_list2(const struct confparams *cfp, rig_ptr_t data, FILE *fout) +{ + ROT *rot = (ROT *) data; + char buf[128] = ""; + + rot_get_conf(rot, cfp->token, buf); + fprintf(fout,"%s: \"%s\"\n" "\t" "Default: %s, Value: %s\n", + cfp->name, + cfp->tooltip, + cfp->dflt, + buf); + + return 1; /* !=0, we want them all ! */ +} + diff --git a/tests/rotctl_parse.h b/tests/rotctl_parse.h index 269d4a9c9..8743fc84f 100644 --- a/tests/rotctl_parse.h +++ b/tests/rotctl_parse.h @@ -42,6 +42,7 @@ void usage_rot(FILE *); void version(); void list_models(); int print_conf_list(const struct confparams *cfp, rig_ptr_t data); +int print_conf_list2(const struct confparams *cfp, rig_ptr_t data, FILE *fout); int set_conf(ROT *my_rot, char *conf_parms); int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, const char **argv, int argc, diff --git a/tests/rotctld.c b/tests/rotctld.c index f3c5e2f41..e0a37ffe3 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -345,12 +345,28 @@ int main(int argc, char *argv[]) exit(2); } - retcode = set_conf(my_rot, conf_parms); + char *token=strtok(conf_parms,","); - if (retcode != RIG_OK) + while(token) { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); + char mytoken[100], myvalue[100]; + token_t lookup; + sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); + lookup = rot_token_lookup(my_rot,mytoken); + if (lookup == 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n", __func__, mytoken); + token = strtok(NULL, ","); + continue; + } + retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot,mytoken), myvalue); + if (retcode != RIG_OK) + { + fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); + exit(2); + } + token = strtok(NULL, ","); } if (rot_file)