From 921d4d43ef14caada6e48151250b1353fb9dea61 Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Thu, 19 May 2022 12:28:49 -0500 Subject: [PATCH] Add -S/--separator option to rigctld to allow something other then \n as a field separator Should work better for node-red parsing https://github.com/Hamlib/Hamlib/issues/1030 --- doc/man1/rigctld.1 | 7 +++++++ tests/rigctl_parse.c | 1 + tests/rigctld.c | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doc/man1/rigctld.1 b/doc/man1/rigctld.1 index a0cee7eb4..b8b18b35b 100644 --- a/doc/man1/rigctld.1 +++ b/doc/man1/rigctld.1 @@ -202,6 +202,13 @@ is in decimal notation, unless prefixed by in which case it is hexadecimal. . .TP +.BR \-S ", " \-\-separator = \fIchar\fP +Use char as separator instead of line feed +.IP +The default is \n +.IP +. +.TP .BR \-T ", " \-\-listen\-addr = \fIIPADDR\fP Use .I IPADDR diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index de1aeb654..c684ccc34 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -1782,6 +1782,7 @@ readline_repeat: } } } + if (*resp_sep_ptr != '\n') fprintf(fout, "\n"); fflush(fout); diff --git a/tests/rigctld.c b/tests/rigctld.c index 231759537..c561d35cf 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -84,7 +84,7 @@ * keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks. * TODO: add an option to read from a file */ -#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:T:t:C:W:w:x:z:lLuovhVZMA:n:" +#define SHORT_OPTIONS "m:r:p:d:P:D:s:S:c:T:t:C:W:w:x:z:lLuovhVZMA:n:" static struct option long_options[] = { {"model", 1, 0, 'm'}, @@ -94,6 +94,7 @@ static struct option long_options[] = {"ptt-type", 1, 0, 'P'}, {"dcd-type", 1, 0, 'D'}, {"serial-speed", 1, 0, 's'}, + {"separator", 1, 0, 'S'}, {"civaddr", 1, 0, 'c'}, {"listen-addr", 1, 0, 'T'}, {"port", 1, 0, 't'}, @@ -150,6 +151,7 @@ const char *src_addr = NULL; /* INADDR_ANY */ const char *multicast_addr = "0.0.0.0"; int multicast_port = 4532; extern char rigctld_password[65]; +char resp_sep = '\n'; #define MAXCONFLEN 1024 @@ -460,6 +462,16 @@ int main(int argc, char *argv[]) civaddr = optarg; break; + case 'S': + if (!optarg) + { + usage(); /* wrong arg count */ + exit(1); + } + resp_sep = *optarg; + rig_debug(RIG_DEBUG_VERBOSE, "%s: resp_sep=%c\n", __func__, resp_sep); + break; + case 's': if (!optarg) { @@ -1135,7 +1147,6 @@ void *handle_socket(void *arg) char serv[NI_MAXSERV]; char send_cmd_term = '\r'; /* send_cmd termination char */ int ext_resp = 0; - char resp_sep = '\n'; fsockin = get_fsockin(handle_data_arg); @@ -1351,6 +1362,7 @@ void usage(void) " -s, --serial-speed=BAUD set serial speed of the serial port\n" " -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n" " -t, --port=NUM set TCP listening port, default %s\n" + " -S, --separator=CHAR set char as rigctld response separator, default is \\n\n" " -T, --listen-addr=IPADDR set listening IP address, default ANY\n" " -C, --set-conf=PARM=VAL set config parameters\n" " -L, --show-conf list all config parameters\n"