kopia lustrzana https://github.com/Hamlib/Hamlib
flexible command termination for send_cmd
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2557 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.9
rodzic
a18e75470f
commit
025c1f4dd1
|
@ -2,7 +2,7 @@
|
|||
.\" First parameter, NAME, should be all caps
|
||||
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
||||
.\" other parameters are allowed: see man(7), man(1)
|
||||
.TH RIGCTL "1" "September 21, 2008" "Hamlib" "Radio Control Program"
|
||||
.TH RIGCTL "1" "January 4, 2009" "Hamlib" "Radio Control Program"
|
||||
.\" Please adjust this date whenever revising the manpage.
|
||||
.\"
|
||||
.\" Some roff macros, for reference:
|
||||
|
@ -86,6 +86,13 @@ Icom rigs.
|
|||
NB: the \fIid\fP is in decimal notation, unless prefixed by
|
||||
\fI0x\fP, in which case it is hexadecimal.
|
||||
.TP
|
||||
.B \-t, --send-cmd-term=char
|
||||
Change the termination \fIchar\fP for text protocol when using the \fIsend_cmd\fP command.
|
||||
The default value is <CR>. Non ASCII printable characters can be specified as an
|
||||
ASCII number, in hexadecimal format, prepended with 0x. You may pass an empty string
|
||||
for no termination char. The string -1 tells rigctl to switch to binary protocol.
|
||||
See the \fIsend_cmd\fP command for further explanation.
|
||||
.TP
|
||||
.B \-L, --show-conf
|
||||
List all config parameters for the radio defined with -m above.
|
||||
.TP
|
||||
|
@ -340,9 +347,11 @@ power in milli-Watts. The \fIfrequency\fP and \fImode\fP also need to be
|
|||
provided as output power may vary according to these values.
|
||||
.TP
|
||||
.B w, send_cmd
|
||||
Send raw command string to rig.
|
||||
Send raw command string to the rig.
|
||||
.br
|
||||
For binary protocols enter values as \\0xAA\\0xBB
|
||||
<CR> (or send-cmd-term, see \fI-t\fP option) is appended automatically at the end
|
||||
of the command for text protocols.
|
||||
For binary protocols, enter values as \\0xAA\\0xBB
|
||||
|
||||
.SH EXAMPLES
|
||||
Start \fBrigctl\fP for a Yaesu FT-920 using a USB to serial adapter in
|
||||
|
@ -393,7 +402,7 @@ Written by Stephane Fillod and the Hamlib Group
|
|||
.br
|
||||
<http://www.hamlib.org>.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2000-2008 Stephane Fillod, Frank Singleton, and the Hamlib
|
||||
Copyright \(co 2000-2009 Stephane Fillod, Frank Singleton, and the Hamlib
|
||||
Group.
|
||||
.br
|
||||
This is free software; see the source for copying conditions.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* rigctl.c - (C) Stephane Fillod 2000-2008
|
||||
* rigctl.c - (C) Stephane Fillod 2000-2009
|
||||
*
|
||||
* This program test/control a radio using Hamlib.
|
||||
* It takes commands in interactive mode as well as
|
||||
* from command line options.
|
||||
*
|
||||
* $Id: rigctl.c,v 1.69 2008-12-10 08:37:35 fillods Exp $
|
||||
* $Id: rigctl.c,v 1.70 2009-01-04 14:49:17 fillods Exp $
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -58,7 +58,7 @@ void usage(void);
|
|||
* NB: do NOT use -W since it's reserved by POSIX.
|
||||
* TODO: add an option to read from a file
|
||||
*/
|
||||
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:lC:LuovhV"
|
||||
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:t:lC:LuovhV"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"model", 1, 0, 'm'},
|
||||
|
@ -69,6 +69,7 @@ static struct option long_options[] =
|
|||
{"dcd-type", 1, 0, 'D'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"civaddr", 1, 0, 'c'},
|
||||
{"send-cmd-term", 1, 0, 't'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf",0, 0, 'L'},
|
||||
|
@ -87,6 +88,8 @@ int prompt = 1; /* Print prompt in rigctl */
|
|||
int opt_end= 0; /* only used by rigctld */
|
||||
int vfo_mode; /* vfo_mode=0 means target VFO is current VFO */
|
||||
|
||||
char send_cmd_term = '\r'; /* send_cmd termination char */
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
RIG *my_rig; /* handle to rig (nstance) */
|
||||
|
@ -193,6 +196,16 @@ int main (int argc, char *argv[])
|
|||
}
|
||||
civaddr = optarg;
|
||||
break;
|
||||
case 't':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(optarg) > 1)
|
||||
send_cmd_term = strtol(optarg, NULL, 0);
|
||||
else
|
||||
send_cmd_term = optarg[0];
|
||||
break;
|
||||
case 's':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
|
@ -276,7 +289,7 @@ int main (int argc, char *argv[])
|
|||
if (serial_rate != 0)
|
||||
my_rig->state.rigport.parm.serial.rate = serial_rate;
|
||||
if (civaddr)
|
||||
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
|
||||
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
|
||||
|
||||
/*
|
||||
* print out conf parameters
|
||||
|
@ -334,6 +347,7 @@ void usage(void)
|
|||
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
|
||||
" -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, --send-cmd-term=CHAR set send_cmd command termination char\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* rigctl_parse.c - (C) Stephane Fillod 2000-2008
|
||||
* rigctl_parse.c - (C) Stephane Fillod 2000-2009
|
||||
*
|
||||
* This program test/control a radio using Hamlib.
|
||||
* It takes commands in interactive mode as well as
|
||||
* from command line options.
|
||||
*
|
||||
* $Id: rigctl_parse.c,v 1.13 2009-01-04 14:23:43 mrtembry Exp $
|
||||
* $Id: rigctl_parse.c,v 1.14 2009-01-04 14:49:17 fillods Exp $
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -276,6 +276,7 @@ extern int interactive;
|
|||
extern int prompt;
|
||||
extern int opt_end;
|
||||
extern int vfo_mode;
|
||||
extern char send_cmd_term;
|
||||
|
||||
int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc)
|
||||
{
|
||||
|
@ -1929,12 +1930,15 @@ declare_proto_rig(send_cmd)
|
|||
#define BUFSZ 128
|
||||
char bufcmd[BUFSZ];
|
||||
char buf[BUFSZ];
|
||||
char eom_buf[4] = { 0xa, 0xd, 0, 0 };
|
||||
|
||||
/*
|
||||
* binary protocols enter values as \0xZZ\0xYY..
|
||||
*/
|
||||
backend_num = RIG_BACKEND_NUM(rig->caps->rig_model);
|
||||
if (backend_num == RIG_YAESU || backend_num == RIG_ICOM ||
|
||||
if (send_cmd_term == -1 ||
|
||||
backend_num == RIG_YAESU ||
|
||||
backend_num == RIG_ICOM ||
|
||||
backend_num == RIG_KACHINA ||
|
||||
backend_num == RIG_MICROTUNE) {
|
||||
const char *p = arg1, *pp = NULL;
|
||||
|
@ -1943,18 +1947,23 @@ declare_proto_rig(send_cmd)
|
|||
pp = p+1;
|
||||
bufcmd[i] = strtol(p+1, (char **) &p, 0);
|
||||
}
|
||||
cmd_len = i-1;
|
||||
/* must save length to allow 0x00 to be sent as part of a command
|
||||
*/
|
||||
cmd_len = i-1;
|
||||
|
||||
/* no End Of Message chars */
|
||||
eom_buf[0] = '\0';
|
||||
} else {
|
||||
/* text protocol */
|
||||
|
||||
strncpy(bufcmd,arg1,BUFSZ);
|
||||
bufcmd[BUFSZ-1] = '\0';
|
||||
bufcmd[BUFSZ-2] = '\0';
|
||||
cmd_len = strlen(bufcmd);
|
||||
/*
|
||||
* assumes CR is end of line char
|
||||
* for all ascii protocols
|
||||
*/
|
||||
strcat(bufcmd, "\r");
|
||||
|
||||
/* Automatic termination char */
|
||||
if (send_cmd_term != 0)
|
||||
bufcmd[cmd_len++] = send_cmd_term;
|
||||
eom_buf[2] = send_cmd_term;
|
||||
}
|
||||
|
||||
rs = &rig->state;
|
||||
|
@ -1968,9 +1977,12 @@ declare_proto_rig(send_cmd)
|
|||
if (interactive && prompt)
|
||||
fprintf(fout, "%s: ", cmd->arg2);
|
||||
|
||||
#define EOM "\0xa"
|
||||
do {
|
||||
retval = read_string(&rs->rigport, buf, BUFSZ, EOM, strlen(EOM));
|
||||
/*
|
||||
* assumes CR or LF is end of line char
|
||||
* for all ascii protocols
|
||||
*/
|
||||
retval = read_string(&rs->rigport, buf, BUFSZ, eom_buf, strlen(eom_buf));
|
||||
if (retval < 0)
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* rigctld.c - (C) Stephane Fillod 2000-2008
|
||||
* rigctld.c - (C) Stephane Fillod 2000-2009
|
||||
*
|
||||
* This program test/control a radio using Hamlib.
|
||||
* It takes commands from network connection.
|
||||
*
|
||||
* $Id: rigctld.c,v 1.10 2008-12-10 08:37:35 fillods Exp $
|
||||
* $Id: rigctld.c,v 1.11 2009-01-04 14:49:17 fillods Exp $
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -108,6 +108,7 @@ int prompt= 0 ; /* Daemon mode for rigparse return string */
|
|||
int opt_end= 0 ; /* END marker for rigctld */
|
||||
int vfo_mode; /* vfo_mode=0 means target VFO is current VFO */
|
||||
|
||||
char send_cmd_term = '\r'; /* send_cmd termination char */
|
||||
|
||||
int portno = 4532;
|
||||
uint32_t src_addr = INADDR_ANY;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
.\" First parameter, NAME, should be all caps
|
||||
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
|
||||
.\" other parameters are allowed: see man(7), man(1)
|
||||
.TH ROTCTL "1" "February 24, 2007" "Hamlib" "Rotator Control Program"
|
||||
.TH ROTCTL "1" "January 4, 2009" "Hamlib" "Rotator Control Program"
|
||||
.\" Please adjust this date whenever revising the manpage.
|
||||
.\"
|
||||
.\" Some roff macros, for reference:
|
||||
|
@ -56,6 +56,13 @@ Default is \fB/dev/rotator\fP (may be a symbolic link to the actual device).
|
|||
Set serial speed to \fIbaud\fP rate. Uses maximum serial speed from rotator
|
||||
backend capabilites as default.
|
||||
.TP
|
||||
.B \-t, --send-cmd-term=char
|
||||
Change the termination \fIchar\fP for text protocol when using the \fIsend_cmd\fP command.
|
||||
The default value is <CR>. Non ASCII printable characters can be specified as an
|
||||
ASCII number, in hexadecimal format, prepended with 0x. You may pass an empty string
|
||||
for no termination char. The string -1 tells rotctl to switch to binary protocol.
|
||||
See the \fIsend_cmd\fP command for further explanation.
|
||||
.TP
|
||||
.B \-L, --show-conf
|
||||
List all config parameters for the rotor defined with -m above.
|
||||
.TP
|
||||
|
@ -124,6 +131,14 @@ See -L output
|
|||
.TP
|
||||
.B _, get_info
|
||||
Get misc information on the rotator.
|
||||
.TP
|
||||
.B w, send_cmd
|
||||
Send raw command string to the rotator.
|
||||
.br
|
||||
<CR> (or send-cmd-term, see \fI-t\fP option) is appended automatically at the end
|
||||
of the command for text protocols.
|
||||
For binary protocols, enter values as \\0xAA\\0xBB
|
||||
|
||||
.SH EXAMPLES
|
||||
Start \fBrotctl\fP for RotorEZ using COM1:
|
||||
|
||||
|
@ -161,7 +176,7 @@ Written by Stephane Fillod and the Hamlib Group
|
|||
.br
|
||||
<http://www.hamlib.org>.
|
||||
.SH COPYRIGHT
|
||||
Copyright \(co 2000-2007 Stephane Fillod and the Hamlib Group.
|
||||
Copyright \(co 2000-2009 Stephane Fillod and the Hamlib Group.
|
||||
.br
|
||||
This is free software; see the source for copying conditions.
|
||||
There is NO warranty; not even for MERCHANTABILITY
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* rotctl.c - (C) Stephane Fillod 2000-2008
|
||||
* rotctl.c - (C) Stephane Fillod 2000-2009
|
||||
*
|
||||
* This program test/control a rotator using Hamlib.
|
||||
* It takes commands in interactive mode as well as
|
||||
* from command line options.
|
||||
*
|
||||
* $Id: rotctl.c,v 1.12 2008-10-27 22:23:36 fillods Exp $
|
||||
* $Id: rotctl.c,v 1.13 2009-01-04 14:49:17 fillods Exp $
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -52,12 +52,13 @@ void usage();
|
|||
* NB: do NOT use -W since it's reserved by POSIX.
|
||||
* TODO: add an option to read from a file
|
||||
*/
|
||||
#define SHORT_OPTIONS "m:r:s:C:LvhVl"
|
||||
#define SHORT_OPTIONS "m:r:s:C:t:LvhVl"
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"model", 1, 0, 'm'},
|
||||
{"rot-file", 1, 0, 'r'},
|
||||
{"serial-speed", 1, 0, 's'},
|
||||
{"send-cmd-term", 1, 0, 't'},
|
||||
{"list", 0, 0, 'l'},
|
||||
{"set-conf", 1, 0, 'C'},
|
||||
{"show-conf",0, 0, 'L'},
|
||||
|
@ -73,6 +74,8 @@ int interactive = 1; /* if no cmd on command line, switch to interactive */
|
|||
int prompt = 1; /* Print prompt in rotctl */
|
||||
int opt_end= 0 ; /* only used by rotctld */
|
||||
|
||||
char send_cmd_term = '\r'; /* send_cmd termination char */
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
ROT *my_rot; /* handle to rot (instance) */
|
||||
|
@ -132,6 +135,16 @@ int main (int argc, char *argv[])
|
|||
strcat(conf_parms, ",");
|
||||
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
|
||||
break;
|
||||
case 't':
|
||||
if (!optarg) {
|
||||
usage(); /* wrong arg count */
|
||||
exit(1);
|
||||
}
|
||||
if (strlen(optarg) > 1)
|
||||
send_cmd_term = strtol(optarg, NULL, 0);
|
||||
else
|
||||
send_cmd_term = optarg[0];
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
|
@ -219,6 +232,7 @@ void usage()
|
|||
" -m, --model=ID select rotator model number. See model list\n"
|
||||
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
|
||||
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
||||
" -t, --send-cmd-term=CHAR set send_cmd command termination char\n"
|
||||
" -C, --set-conf=PARM=VAL set config parameters\n"
|
||||
" -L, --show-conf list all config parameters\n"
|
||||
" -l, --list list all model numbers and exit\n"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* rotctl.c - (C) Stephane Fillod 2000-2008
|
||||
* rotctl.c - (C) Stephane Fillod 2000-2009
|
||||
*
|
||||
* This program test/control a rotator using Hamlib.
|
||||
* It takes commands in interactive mode as well as
|
||||
* from command line options.
|
||||
*
|
||||
* $Id: rotctl_parse.c,v 1.4 2009-01-01 18:19:26 fillods Exp $
|
||||
* $Id: rotctl_parse.c,v 1.5 2009-01-04 14:49:17 fillods Exp $
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -160,6 +160,7 @@ static int scanfc(FILE *fin, const char *format, void *p)
|
|||
extern int interactive;
|
||||
extern int prompt;
|
||||
extern int opt_end;
|
||||
extern char send_cmd_term;
|
||||
|
||||
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc)
|
||||
{
|
||||
|
@ -572,6 +573,7 @@ declare_proto_rot(send_cmd)
|
|||
#define BUFSZ 128
|
||||
char bufcmd[BUFSZ];
|
||||
char buf[BUFSZ];
|
||||
char eom_buf[4] = { 0xa, 0xd, 0, 0 };
|
||||
|
||||
/*
|
||||
* binary protocols enter values as \0xZZ\0xYY..
|
||||
|
@ -579,25 +581,31 @@ declare_proto_rot(send_cmd)
|
|||
* Rem: no binary protocol for rotator as of now
|
||||
*/
|
||||
backend_num = ROT_BACKEND_NUM(rot->caps->rot_model);
|
||||
if (backend_num == -1) {
|
||||
if (send_cmd_term == -1 || backend_num == -1) {
|
||||
const char *p = arg1, *pp = NULL;
|
||||
int i;
|
||||
for (i=0; i < BUFSZ-1 && p != pp; i++) {
|
||||
pp = p+1;
|
||||
bufcmd[i] = strtol(p+1, (char **) &p, 0);
|
||||
}
|
||||
cmd_len = i-1;
|
||||
/* must save length to allow 0x00 to be sent as part of a command
|
||||
*/
|
||||
cmd_len = i-1;
|
||||
|
||||
/* no End Of Message chars */
|
||||
eom_buf[0] = '\0';
|
||||
} else {
|
||||
/* text protocol */
|
||||
|
||||
strncpy(bufcmd,arg1,BUFSZ);
|
||||
bufcmd[BUFSZ-1] = '\0';
|
||||
/*
|
||||
* assumes CR is end of line char
|
||||
* for all ascii protocols.
|
||||
*/
|
||||
strcat(bufcmd, "\r");
|
||||
bufcmd[BUFSZ-2] = '\0';
|
||||
|
||||
cmd_len = strlen(bufcmd);
|
||||
|
||||
/* Automatic termination char */
|
||||
if (send_cmd_term != 0)
|
||||
bufcmd[cmd_len++] = send_cmd_term;
|
||||
eom_buf[2] = send_cmd_term;
|
||||
}
|
||||
|
||||
rs = &rot->state;
|
||||
|
@ -611,9 +619,12 @@ declare_proto_rot(send_cmd)
|
|||
if (interactive && prompt)
|
||||
fprintf(fout, "%s: ", cmd->arg2);
|
||||
|
||||
#define EOM "\0xa"
|
||||
do {
|
||||
retval = read_string(&rs->rotport, buf, BUFSZ, EOM, strlen(EOM));
|
||||
/*
|
||||
* assumes CR or LF is end of line char
|
||||
* for all ascii protocols
|
||||
*/
|
||||
retval = read_string(&rs->rotport, buf, BUFSZ, eom_buf, strlen(eom_buf));
|
||||
if (retval < 0)
|
||||
break;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* rotctld.c - (C) Stephane Fillod 2000-2008
|
||||
* rotctld.c - (C) Stephane Fillod 2000-2009
|
||||
*
|
||||
* This program test/control a rotator using Hamlib.
|
||||
* It takes commands from network connection.
|
||||
*
|
||||
* $Id: rotctld.c,v 1.6 2008-11-02 12:39:36 fillods Exp $
|
||||
* $Id: rotctld.c,v 1.7 2009-01-04 14:49:17 fillods Exp $
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -101,6 +101,8 @@ int opt_end= 0 ; /* END marker for rotctld */
|
|||
int portno = 4533;
|
||||
uint32_t src_addr = INADDR_ANY;
|
||||
|
||||
char send_cmd_term = '\r'; /* send_cmd termination char */
|
||||
|
||||
#define MAXCONFLEN 128
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue