2000-10-29 16:35:29 +00:00
|
|
|
/*
|
2008-01-05 18:13:12 +00:00
|
|
|
* rigctl.c - (C) Stephane Fillod 2000-2008
|
2000-10-29 16:35:29 +00:00
|
|
|
*
|
|
|
|
* This program test/control a radio using Hamlib.
|
2001-07-20 11:09:26 +00:00
|
|
|
* It takes commands in interactive mode as well as
|
|
|
|
* from command line options.
|
2000-10-29 16:35:29 +00:00
|
|
|
*
|
2008-05-23 14:26:09 +00:00
|
|
|
* $Id: rigctl.c,v 1.67 2008-05-23 14:26:09 fillods Exp $
|
2000-10-29 16:35:29 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2000-10-29 16:35:29 +00:00
|
|
|
#include <stdio.h>
|
2001-07-20 11:09:26 +00:00
|
|
|
#include <stdlib.h>
|
2000-10-29 16:35:29 +00:00
|
|
|
#include <string.h>
|
2001-02-25 23:14:19 +00:00
|
|
|
#include <unistd.h>
|
2002-09-06 10:43:59 +00:00
|
|
|
#include <ctype.h>
|
2003-05-03 13:17:25 +00:00
|
|
|
#include <errno.h>
|
2001-02-25 23:14:19 +00:00
|
|
|
|
|
|
|
#include <getopt.h>
|
2000-10-29 16:35:29 +00:00
|
|
|
|
|
|
|
#include <hamlib/rig.h>
|
2001-12-20 07:51:02 +00:00
|
|
|
#include "misc.h"
|
2005-04-11 22:11:28 +00:00
|
|
|
#include "iofunc.h"
|
|
|
|
#include "serial.h"
|
2003-11-16 17:34:00 +00:00
|
|
|
#include "sprintflst.h"
|
2000-10-29 16:35:29 +00:00
|
|
|
|
2007-11-11 23:04:22 +00:00
|
|
|
#include "rigctl_parse.h"
|
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
#define MAXNAMSIZ 32
|
2001-02-25 23:14:19 +00:00
|
|
|
#define MAXNBOPT 100 /* max number of different options */
|
|
|
|
|
2000-10-29 16:35:29 +00:00
|
|
|
|
2007-11-11 23:04:22 +00:00
|
|
|
void usage(void);
|
2001-07-20 11:09:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reminder: when adding long options,
|
|
|
|
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
|
|
|
|
* NB: do NOT use -W since it's reserved by POSIX.
|
|
|
|
* TODO: add an option to read from a file
|
|
|
|
*/
|
2003-03-27 23:44:20 +00:00
|
|
|
#define SHORT_OPTIONS "m:r:p:d:P:D:s:c:lC:LuovhV"
|
2001-07-20 11:09:26 +00:00
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{"model", 1, 0, 'm'},
|
|
|
|
{"rig-file", 1, 0, 'r'},
|
|
|
|
{"ptt-file", 1, 0, 'p'},
|
|
|
|
{"dcd-file", 1, 0, 'd'},
|
|
|
|
{"ptt-type", 1, 0, 'P'},
|
|
|
|
{"dcd-type", 1, 0, 'D'},
|
2001-12-21 09:48:51 +00:00
|
|
|
{"serial-speed", 1, 0, 's'},
|
2001-09-22 11:49:19 +00:00
|
|
|
{"civaddr", 1, 0, 'c'},
|
2001-07-20 11:09:26 +00:00
|
|
|
{"list", 0, 0, 'l'},
|
2001-12-20 07:51:02 +00:00
|
|
|
{"set-conf", 1, 0, 'C'},
|
|
|
|
{"show-conf",0, 0, 'L'},
|
2002-09-06 14:07:17 +00:00
|
|
|
{"dump-caps", 0, 0, 'u'},
|
2003-03-27 23:44:20 +00:00
|
|
|
{"vfo", 0, 0, 'o'},
|
2001-07-20 11:09:26 +00:00
|
|
|
{"verbose", 0, 0, 'v'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"version", 0, 0, 'V'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2001-12-20 07:51:02 +00:00
|
|
|
#define MAXCONFLEN 128
|
|
|
|
|
2008-01-12 00:36:58 +00:00
|
|
|
int interactive = 1; /* if no cmd on command line, switch to interactive */
|
|
|
|
int prompt = 1; /* Print prompt in rigctl */
|
2007-11-11 23:04:22 +00:00
|
|
|
|
2001-02-25 23:14:19 +00:00
|
|
|
int main (int argc, char *argv[])
|
2007-11-11 23:04:22 +00:00
|
|
|
{
|
2000-10-29 16:35:29 +00:00
|
|
|
RIG *my_rig; /* handle to rig (nstance) */
|
2001-07-20 11:09:26 +00:00
|
|
|
rig_model_t my_model = RIG_MODEL_DUMMY;
|
2000-10-29 16:35:29 +00:00
|
|
|
|
|
|
|
int retcode; /* generic return code from functions */
|
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
int verbose = 0;
|
2003-03-27 23:44:20 +00:00
|
|
|
int vfo_mode = 0;
|
2001-12-20 07:51:02 +00:00
|
|
|
int show_conf = 0;
|
2002-09-06 14:07:17 +00:00
|
|
|
int dump_caps_opt = 0;
|
2001-07-20 11:09:26 +00:00
|
|
|
const char *rig_file=NULL, *ptt_file=NULL, *dcd_file=NULL;
|
|
|
|
ptt_type_t ptt_type = RIG_PTT_NONE;
|
|
|
|
dcd_type_t dcd_type = RIG_DCD_NONE;
|
2001-12-21 09:48:51 +00:00
|
|
|
int serial_rate = 0;
|
2001-09-22 11:49:19 +00:00
|
|
|
char *civaddr = NULL; /* NULL means no need to set conf */
|
2001-12-20 07:51:02 +00:00
|
|
|
char conf_parms[MAXCONFLEN] = "";
|
2000-10-29 16:35:29 +00:00
|
|
|
|
2001-02-25 23:14:19 +00:00
|
|
|
while(1) {
|
|
|
|
int c;
|
|
|
|
int option_index = 0;
|
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
c = getopt_long (argc, argv, SHORT_OPTIONS,
|
2001-02-25 23:14:19 +00:00
|
|
|
long_options, &option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
switch(c) {
|
|
|
|
case 'h':
|
2005-04-10 22:32:54 +00:00
|
|
|
usage();
|
|
|
|
exit(0);
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'V':
|
2005-04-10 22:32:54 +00:00
|
|
|
version();
|
|
|
|
exit(0);
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'm':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
my_model = atoi(optarg);
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'r':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rig_file = optarg;
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'p':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ptt_file = optarg;
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'd':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
dcd_file = optarg;
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'P':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strcmp(optarg, "RIG"))
|
|
|
|
ptt_type = RIG_PTT_RIG;
|
|
|
|
else if (!strcmp(optarg, "DTR"))
|
|
|
|
ptt_type = RIG_PTT_SERIAL_DTR;
|
|
|
|
else if (!strcmp(optarg, "RTS"))
|
|
|
|
ptt_type = RIG_PTT_SERIAL_RTS;
|
|
|
|
else if (!strcmp(optarg, "PARALLEL"))
|
|
|
|
ptt_type = RIG_PTT_PARALLEL;
|
|
|
|
else if (!strcmp(optarg, "NONE"))
|
|
|
|
ptt_type = RIG_PTT_NONE;
|
|
|
|
else
|
|
|
|
ptt_type = atoi(optarg);
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'D':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!strcmp(optarg, "RIG"))
|
|
|
|
dcd_type = RIG_DCD_RIG;
|
|
|
|
else if (!strcmp(optarg, "DSR"))
|
|
|
|
dcd_type = RIG_DCD_SERIAL_DSR;
|
|
|
|
else if (!strcmp(optarg, "CTS"))
|
|
|
|
dcd_type = RIG_DCD_SERIAL_CTS;
|
|
|
|
else if (!strcmp(optarg, "CD"))
|
|
|
|
dcd_type = RIG_DCD_SERIAL_CAR;
|
|
|
|
else if (!strcmp(optarg, "PARALLEL"))
|
|
|
|
dcd_type = RIG_DCD_PARALLEL;
|
|
|
|
else if (!strcmp(optarg, "NONE"))
|
|
|
|
dcd_type = RIG_DCD_NONE;
|
|
|
|
else
|
|
|
|
dcd_type = atoi(optarg);
|
|
|
|
break;
|
2001-09-22 11:49:19 +00:00
|
|
|
case 'c':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
civaddr = optarg;
|
|
|
|
break;
|
2001-12-21 09:48:51 +00:00
|
|
|
case 's':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
serial_rate = atoi(optarg);
|
|
|
|
break;
|
2001-12-20 07:51:02 +00:00
|
|
|
case 'C':
|
2005-04-10 22:32:54 +00:00
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (*conf_parms != '\0')
|
|
|
|
strcat(conf_parms, ",");
|
|
|
|
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
|
|
|
|
break;
|
2003-03-27 23:44:20 +00:00
|
|
|
case 'o':
|
2005-04-10 22:32:54 +00:00
|
|
|
vfo_mode++;
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'v':
|
2005-04-10 22:32:54 +00:00
|
|
|
verbose++;
|
|
|
|
break;
|
2001-12-20 07:51:02 +00:00
|
|
|
case 'L':
|
2005-04-10 22:32:54 +00:00
|
|
|
show_conf++;
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
case 'l':
|
2005-04-10 22:32:54 +00:00
|
|
|
list_models();
|
|
|
|
exit(0);
|
2002-09-06 14:07:17 +00:00
|
|
|
case 'u':
|
2005-04-10 22:32:54 +00:00
|
|
|
dump_caps_opt++;
|
|
|
|
break;
|
2001-07-20 11:09:26 +00:00
|
|
|
default:
|
2005-04-10 22:32:54 +00:00
|
|
|
usage(); /* unknown option? */
|
|
|
|
exit(1);
|
2001-07-20 11:09:26 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-27 23:58:24 +00:00
|
|
|
|
|
|
|
rig_set_debug(verbose<2 ? RIG_DEBUG_WARN: verbose);
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "rigctl, %s\n", hamlib_version);
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
2005-04-10 22:32:54 +00:00
|
|
|
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
2001-02-25 23:14:19 +00:00
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
/*
|
|
|
|
* at least one command on command line,
|
|
|
|
* disable interactive mode
|
|
|
|
*/
|
|
|
|
if (optind < argc)
|
2001-02-25 23:14:19 +00:00
|
|
|
interactive = 0;
|
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
my_rig = rig_init(my_model);
|
2001-02-25 23:14:19 +00:00
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
if (!my_rig) {
|
2005-04-10 22:32:54 +00:00
|
|
|
fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
|
|
|
|
my_model);
|
|
|
|
fprintf(stderr, "Please check with --list option.\n");
|
|
|
|
exit(2);
|
2001-02-25 23:14:19 +00:00
|
|
|
}
|
2000-10-29 16:35:29 +00:00
|
|
|
|
2001-12-26 23:34:56 +00:00
|
|
|
retcode = set_conf(my_rig, conf_parms);
|
2001-12-20 07:51:02 +00:00
|
|
|
if (retcode != RIG_OK) {
|
2005-04-10 22:32:54 +00:00
|
|
|
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
|
|
|
exit(2);
|
2001-12-20 07:51:02 +00:00
|
|
|
}
|
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
if (rig_file)
|
2001-07-25 21:59:55 +00:00
|
|
|
strncpy(my_rig->state.rigport.pathname, rig_file, FILPATHLEN);
|
2001-02-25 23:14:19 +00:00
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
/*
|
|
|
|
* ex: RIG_PTT_PARALLEL and /dev/parport0
|
|
|
|
*/
|
|
|
|
if (ptt_type != RIG_PTT_NONE)
|
|
|
|
my_rig->state.pttport.type.ptt = ptt_type;
|
|
|
|
if (dcd_type != RIG_DCD_NONE)
|
|
|
|
my_rig->state.dcdport.type.dcd = dcd_type;
|
|
|
|
if (ptt_file)
|
2001-07-25 21:59:55 +00:00
|
|
|
strncpy(my_rig->state.pttport.pathname, ptt_file, FILPATHLEN);
|
2001-07-20 11:09:26 +00:00
|
|
|
if (dcd_file)
|
2001-07-25 21:59:55 +00:00
|
|
|
strncpy(my_rig->state.dcdport.pathname, dcd_file, FILPATHLEN);
|
2001-12-21 09:48:51 +00:00
|
|
|
/* FIXME: bound checking and port type == serial */
|
|
|
|
if (serial_rate != 0)
|
|
|
|
my_rig->state.rigport.parm.serial.rate = serial_rate;
|
2001-09-22 11:49:19 +00:00
|
|
|
if (civaddr)
|
|
|
|
rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr);
|
|
|
|
|
2001-12-20 07:51:02 +00:00
|
|
|
/*
|
|
|
|
* print out conf parameters
|
|
|
|
*/
|
|
|
|
if (show_conf) {
|
2008-05-23 14:26:09 +00:00
|
|
|
dumpconf(my_rig, stdout);
|
2001-12-20 07:51:02 +00:00
|
|
|
}
|
2000-10-29 16:35:29 +00:00
|
|
|
|
2002-09-06 14:07:17 +00:00
|
|
|
/*
|
2008-05-23 14:26:09 +00:00
|
|
|
* print out capabilities, and exists immediately
|
2002-09-06 14:07:17 +00:00
|
|
|
* We may be interested only in only caps, and rig_open may fail.
|
|
|
|
*/
|
|
|
|
if (dump_caps_opt) {
|
2008-01-05 18:13:12 +00:00
|
|
|
dumpcaps(my_rig, stdout);
|
2002-09-06 14:07:17 +00:00
|
|
|
rig_cleanup(my_rig); /* if you care about memory */
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2001-12-26 23:34:56 +00:00
|
|
|
retcode = rig_open(my_rig);
|
|
|
|
if (retcode != RIG_OK) {
|
2005-04-10 22:32:54 +00:00
|
|
|
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
|
|
|
|
exit(2);
|
2001-07-20 11:09:26 +00:00
|
|
|
}
|
2000-10-29 16:35:29 +00:00
|
|
|
|
2001-07-20 11:09:26 +00:00
|
|
|
if (verbose > 0)
|
2005-04-10 22:32:54 +00:00
|
|
|
printf("Opened rig model %d, '%s'\n", my_rig->caps->rig_model,
|
|
|
|
my_rig->caps->model_name);
|
2002-01-27 23:58:24 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "Backend version: %s, Status: %s\n",
|
2005-04-10 22:32:54 +00:00
|
|
|
my_rig->caps->version, rig_strstatus(my_rig->caps->status));
|
2001-07-20 11:09:26 +00:00
|
|
|
|
2007-11-11 23:04:22 +00:00
|
|
|
do {
|
|
|
|
retcode = rigctl_parse(my_rig, stdin, stdout, argv, argc);
|
2000-10-29 16:35:29 +00:00
|
|
|
}
|
2007-11-11 23:04:22 +00:00
|
|
|
while (retcode == 0);
|
2000-10-29 16:35:29 +00:00
|
|
|
|
|
|
|
rig_close(my_rig); /* close port */
|
|
|
|
rig_cleanup(my_rig); /* if you care about memory */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-11 23:04:22 +00:00
|
|
|
void usage(void)
|
2001-07-20 11:09:26 +00:00
|
|
|
{
|
2005-04-10 22:32:54 +00:00
|
|
|
printf("Usage: rigctl [OPTION]... [COMMAND]...\n"
|
|
|
|
"Send COMMANDs to a connected radio transceiver or receiver.\n\n");
|
2001-07-20 11:09:26 +00:00
|
|
|
|
|
|
|
|
2005-04-10 22:32:54 +00:00
|
|
|
printf(
|
2001-07-20 11:09:26 +00:00
|
|
|
" -m, --model=ID select radio model number. See model list\n"
|
|
|
|
" -r, --rig-file=DEVICE set device of the radio to operate on\n"
|
|
|
|
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
|
|
|
|
" -d, --dcd-file=DEVICE set device of the DCD device to operate on\n"
|
|
|
|
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
|
|
|
|
" -D, --dcd-type=TYPE set type of the DCD device to operate on\n"
|
2001-12-21 09:48:51 +00:00
|
|
|
" -s, --serial-speed=BAUD set serial speed of the serial port\n"
|
2002-01-27 23:58:24 +00:00
|
|
|
" -c, --civaddr=ID set CI-V address, decimal (for Icom rigs only)\n"
|
2001-12-20 07:51:02 +00:00
|
|
|
" -C, --set-conf=PARM=VAL set config parameters\n"
|
|
|
|
" -L, --show-conf list all config parameters\n"
|
2001-07-20 11:09:26 +00:00
|
|
|
" -l, --list list all model numbers and exit\n"
|
2002-09-06 14:07:17 +00:00
|
|
|
" -u, --dump-caps dump capabilities and exit\n"
|
2003-03-27 23:44:20 +00:00
|
|
|
" -o, --vfo do not default to VFO_CURR, require extra vfo arg\n"
|
2001-07-20 11:09:26 +00:00
|
|
|
" -v, --verbose set verbose mode, cumulative\n"
|
|
|
|
" -h, --help display this help and exit\n"
|
|
|
|
" -V, --version output version information and exit\n\n"
|
|
|
|
);
|
|
|
|
|
2008-01-05 18:13:12 +00:00
|
|
|
usage_rig(stdout);
|
2001-07-20 11:09:26 +00:00
|
|
|
|
2005-04-10 22:32:54 +00:00
|
|
|
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
2001-07-20 11:09:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|