2004-06-14 20:13:35 +00:00
|
|
|
/*
|
|
|
|
* rigswr.c - (C) Stephane Fillod and Thierry Leconte 2004
|
|
|
|
*
|
|
|
|
* This program output swr curve value
|
|
|
|
* using Hamlib.
|
|
|
|
*
|
2005-04-04 22:26:38 +00:00
|
|
|
* $Id: rigswr.c,v 1.3 2005-04-04 22:26:38 fillods Exp $
|
2004-06-14 20:13:35 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
#include <hamlib/rig.h>
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prototypes
|
|
|
|
*/
|
2005-04-04 22:26:38 +00:00
|
|
|
static void usage();
|
|
|
|
static void version();
|
|
|
|
static int set_conf(RIG *rig, char *conf_parms);
|
2004-06-14 20:13:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reminder: when adding long options,
|
2005-04-04 22:26:38 +00:00
|
|
|
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
|
2004-06-14 20:13:35 +00:00
|
|
|
* NB: do NOT use -W since it's reserved by POSIX.
|
|
|
|
*/
|
2004-06-14 22:22:31 +00:00
|
|
|
#define SHORT_OPTIONS "m:r:s:c:C:p:P:vhV"
|
2004-06-14 20:13:35 +00:00
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{"model", 1, 0, 'm'},
|
|
|
|
{"rig-file", 1, 0, 'r'},
|
|
|
|
{"serial-speed", 1, 0, 's'},
|
|
|
|
{"civaddr", 1, 0, 'c'},
|
|
|
|
{"set-conf", 1, 0, 'C'},
|
2004-06-14 22:22:31 +00:00
|
|
|
{"ptt-file", 1, 0, 'p'},
|
|
|
|
{"ptt-type", 1, 0, 'P'},
|
2004-06-14 20:13:35 +00:00
|
|
|
{"verbose", 0, 0, 'v'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"version", 0, 0, 'V'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAXCONFLEN 128
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
RIG *rig; /* handle to rig (nstance) */
|
|
|
|
rig_model_t my_model = RIG_MODEL_DUMMY;
|
|
|
|
|
|
|
|
int retcode; /* generic return code from functions */
|
|
|
|
|
|
|
|
int verbose = 0;
|
2004-06-14 22:22:31 +00:00
|
|
|
const char *rig_file=NULL, *ptt_file=NULL;
|
|
|
|
ptt_type_t ptt_type = RIG_PTT_NONE;
|
2004-06-14 20:13:35 +00:00
|
|
|
int serial_rate = 0;
|
|
|
|
char *civaddr = NULL; /* NULL means no need to set conf */
|
|
|
|
char conf_parms[MAXCONFLEN] = "";
|
|
|
|
freq_t freq,freqstop;
|
|
|
|
freq_t step=kHz(100);
|
2004-06-14 22:22:31 +00:00
|
|
|
value_t pwr;
|
2004-06-14 20:13:35 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int c;
|
|
|
|
int option_index = 0;
|
|
|
|
|
|
|
|
c = getopt_long (argc, argv, SHORT_OPTIONS,
|
2005-04-04 22:26:38 +00:00
|
|
|
long_options, &option_index);
|
2004-06-14 20:13:35 +00:00
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(c) {
|
2005-04-04 22:26:38 +00:00
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
case 'V':
|
|
|
|
version();
|
|
|
|
exit(0);
|
|
|
|
case 'm':
|
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
my_model = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
rig_file = optarg;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
civaddr = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
serial_rate = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (*conf_parms != '\0')
|
|
|
|
strcat(conf_parms, ",");
|
|
|
|
strncat(conf_parms, optarg, MAXCONFLEN-strlen(conf_parms));
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
if (!optarg) {
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ptt_file = optarg;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
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;
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(); /* unknown option? */
|
|
|
|
exit(1);
|
2004-06-14 20:13:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rig_set_debug(verbose<2 ? RIG_DEBUG_WARN: verbose);
|
|
|
|
|
2004-06-14 22:22:31 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "rigswr, %s\n", hamlib_version);
|
2004-06-14 20:13:35 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "Report bugs to "
|
2005-04-04 22:26:38 +00:00
|
|
|
"<hamlib-developer@lists.sourceforge.net>\n\n");
|
2004-06-14 20:13:35 +00:00
|
|
|
|
|
|
|
if (optind+1 >= argc) {
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rig = rig_init(my_model);
|
|
|
|
|
|
|
|
if (!rig) {
|
|
|
|
fprintf(stderr, "Unknown rig num %d, or initialization error.\n",
|
|
|
|
my_model);
|
|
|
|
fprintf(stderr, "Please check with --list option.\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
retcode = set_conf(rig, conf_parms);
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2004-06-14 22:22:31 +00:00
|
|
|
if (ptt_type != RIG_PTT_NONE)
|
|
|
|
rig->state.pttport.type.ptt = ptt_type;
|
|
|
|
if (ptt_file)
|
|
|
|
strncpy(rig->state.pttport.pathname, ptt_file, FILPATHLEN);
|
|
|
|
|
2004-06-14 20:13:35 +00:00
|
|
|
if (rig_file)
|
|
|
|
strncpy(rig->state.rigport.pathname, rig_file, FILPATHLEN);
|
|
|
|
|
|
|
|
/* FIXME: bound checking and port type == serial */
|
|
|
|
if (serial_rate != 0)
|
|
|
|
rig->state.rigport.parm.serial.rate = serial_rate;
|
|
|
|
if (civaddr)
|
|
|
|
rig_set_conf(rig, rig_token_lookup(rig, "civaddr"), civaddr);
|
|
|
|
|
2004-06-14 22:22:31 +00:00
|
|
|
|
|
|
|
if(!rig_has_get_level(rig,RIG_LEVEL_SWR) ||
|
|
|
|
rig->state.pttport.type.ptt == RIG_PTT_NONE) {
|
|
|
|
fprintf(stderr,"rig backend for %s could not get SWR"
|
|
|
|
"or has unsufficient capability\nSorry\n",
|
|
|
|
rig->caps->model_name);
|
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
2004-06-14 20:13:35 +00:00
|
|
|
retcode = rig_open(rig);
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
fprintf(stderr,"rig_open: error = %s \n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose > 0)
|
2005-04-04 22:26:38 +00:00
|
|
|
printf("Opened rig model %d, '%s'\n", rig->caps->rig_model,
|
|
|
|
rig->caps->model_name);
|
2004-06-14 20:13:35 +00:00
|
|
|
|
|
|
|
freq=atof(argv[optind++]);
|
|
|
|
freqstop=atof(argv[optind++]);
|
|
|
|
if (optind < argc)
|
|
|
|
step=atof(argv[optind]);
|
|
|
|
|
|
|
|
rig_set_freq(rig,RIG_VFO_CURR,freq);
|
2004-06-14 22:22:31 +00:00
|
|
|
rig_set_mode(rig,RIG_VFO_CURR,RIG_MODE_CW,RIG_PASSBAND_NORMAL);
|
|
|
|
|
|
|
|
pwr.f = 0.25; /* 25% of RF POWER */
|
|
|
|
rig_set_level(rig,RIG_VFO_CURR,RIG_LEVEL_RFPOWER,pwr);
|
2004-06-14 20:13:35 +00:00
|
|
|
|
|
|
|
while(freq<=freqstop) {
|
|
|
|
value_t swr;
|
|
|
|
|
|
|
|
rig_set_ptt(rig,RIG_VFO_CURR,RIG_PTT_ON);
|
|
|
|
usleep(500000);
|
|
|
|
rig_get_level(rig,RIG_VFO_CURR,RIG_LEVEL_SWR,&swr);
|
|
|
|
rig_set_ptt(rig,RIG_VFO_CURR,RIG_PTT_OFF);
|
|
|
|
|
|
|
|
printf("%10.0f %4.2f\n",freq,swr.f);
|
|
|
|
freq+=step;
|
|
|
|
rig_set_freq(rig,RIG_VFO_CURR,freq);
|
|
|
|
}
|
|
|
|
|
2004-06-14 22:22:31 +00:00
|
|
|
rig_close(rig);
|
|
|
|
|
2004-06-14 20:13:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void version()
|
|
|
|
{
|
2005-04-04 22:26:38 +00:00
|
|
|
printf("rigswr, %s\n\n", hamlib_version);
|
|
|
|
printf("%s\n", hamlib_copyright);
|
2004-06-14 20:13:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usage()
|
|
|
|
{
|
2005-04-04 22:26:38 +00:00
|
|
|
printf("Usage: rigswr [OPTION]... start_freq stop_freq [freq_step]\n"
|
2004-06-14 20:13:35 +00:00
|
|
|
"Output SWR vs Frequency.\n\n");
|
|
|
|
|
|
|
|
|
2005-04-04 22:26:38 +00:00
|
|
|
printf(
|
2004-06-14 20:13:35 +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"
|
|
|
|
" -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"
|
|
|
|
" -C, --set-conf=PARM=VAL set config parameters\n"
|
2004-06-14 22:22:31 +00:00
|
|
|
" -p, --ptt-file=DEVICE set device of the PTT device to operate on\n"
|
|
|
|
" -P, --ptt-type=TYPE set type of the PTT device to operate on\n"
|
2004-06-14 20:13:35 +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"
|
|
|
|
);
|
|
|
|
|
|
|
|
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int set_conf(RIG *rig, char *conf_parms)
|
|
|
|
{
|
|
|
|
char *p, *q, *n;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
p = conf_parms;
|
|
|
|
while (p && *p != '\0') {
|
|
|
|
/* FIXME: left hand value of = cannot be null */
|
|
|
|
q = strchr(p, '=');
|
|
|
|
if (q) *q++ = '\0';
|
|
|
|
n = strchr(q, ',');
|
|
|
|
if (n) *n++ = '\0';
|
|
|
|
|
|
|
|
ret = rig_set_conf(rig, rig_token_lookup(rig, p), q);
|
|
|
|
if (ret != RIG_OK)
|
2005-04-04 22:26:38 +00:00
|
|
|
return ret;
|
2004-06-14 20:13:35 +00:00
|
|
|
p = n;
|
|
|
|
}
|
|
|
|
return RIG_OK;
|
|
|
|
}
|