2001-12-28 20:34:30 +00:00
|
|
|
/*
|
2010-04-25 17:29:53 +00:00
|
|
|
* rotctl.c - (C) Stephane Fillod 2000-2010
|
2013-02-05 18:54:05 +00:00
|
|
|
* (C) Nate Bargmann 2003,2007,2010,2011,2012,2013
|
|
|
|
* (C) The Hamlib Group 2002,2006
|
2001-12-28 20:34:30 +00:00
|
|
|
*
|
|
|
|
* This program test/control a rotator using Hamlib.
|
2010-02-14 22:18:00 +00:00
|
|
|
* It takes commands in interactive mode as well as
|
2001-12-28 20:34:30 +00:00
|
|
|
* from command line options.
|
|
|
|
*
|
|
|
|
*
|
2011-08-22 01:51:06 +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.
|
2010-02-14 22:18:00 +00:00
|
|
|
*
|
2011-08-22 01:51:06 +00:00
|
|
|
* 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.
|
2010-02-14 22:18:00 +00:00
|
|
|
*
|
2011-08-22 01:51:06 +00:00
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-02-14 22:18:00 +00:00
|
|
|
*
|
2001-12-28 20:34:30 +00:00
|
|
|
*/
|
2022-02-04 13:41:36 +00:00
|
|
|
#include <hamlib/config.h>
|
2001-12-28 20:34:30 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-09-06 10:43:59 +00:00
|
|
|
#include <ctype.h>
|
2013-02-23 02:45:57 +00:00
|
|
|
#include <errno.h>
|
2001-12-28 20:34:30 +00:00
|
|
|
#include <getopt.h>
|
|
|
|
|
2013-02-22 23:18:30 +00:00
|
|
|
#ifdef HAVE_LIBREADLINE
|
|
|
|
# if defined(HAVE_READLINE_READLINE_H)
|
|
|
|
# include <readline/readline.h>
|
|
|
|
# elif defined(HAVE_READLINE_H) /* !defined(HAVE_READLINE_READLINE_H) */
|
|
|
|
# include <readline.h>
|
|
|
|
# else /* !defined(HAVE_READLINE_H) */
|
2017-08-09 18:09:55 +00:00
|
|
|
extern char *readline();
|
2013-02-22 23:18:30 +00:00
|
|
|
# endif /* HAVE_READLINE_H */
|
|
|
|
#else
|
|
|
|
/* no readline */
|
|
|
|
#endif /* HAVE_LIBREADLINE */
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2013-02-23 02:45:57 +00:00
|
|
|
# include <sys/stat.h>
|
|
|
|
# define HST_SHRT_OPTS "iI"
|
2013-02-23 01:09:50 +00:00
|
|
|
# if defined(HAVE_READLINE_HISTORY_H)
|
|
|
|
# include <readline/history.h>
|
|
|
|
# elif defined(HAVE_HISTORY_H)
|
|
|
|
# include <history.h>
|
|
|
|
# else /* !defined(HAVE_HISTORY_H) */
|
2017-08-09 18:09:55 +00:00
|
|
|
extern void add_history();
|
|
|
|
extern int write_history();
|
|
|
|
extern int read_history();
|
2013-02-23 01:09:50 +00:00
|
|
|
# endif /* defined(HAVE_READLINE_HISTORY_H) */
|
2013-02-23 02:45:57 +00:00
|
|
|
#else
|
|
|
|
/* no history */
|
2017-10-06 23:58:42 +00:00
|
|
|
# define HST_SHRT_OPTS ""
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif /* HAVE_READLINE_HISTORY */
|
|
|
|
|
|
|
|
|
2001-12-28 20:34:30 +00:00
|
|
|
#include <hamlib/rotator.h>
|
|
|
|
#include "misc.h"
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
#include "rotctl_parse.h"
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/*
|
2001-12-28 20:34:30 +00:00
|
|
|
* Prototypes
|
|
|
|
*/
|
|
|
|
void usage();
|
|
|
|
|
|
|
|
/*
|
2010-02-14 22:18:00 +00:00
|
|
|
* Reminder: when adding long options,
|
2007-02-24 20:24:34 +00:00
|
|
|
* keep up to date SHORT_OPTIONS, usage()'s output and man page. thanks.
|
2001-12-28 20:34:30 +00:00
|
|
|
* NB: do NOT use -W since it's reserved by POSIX.
|
|
|
|
* TODO: add an option to read from a file
|
|
|
|
*/
|
2021-07-24 04:28:02 +00:00
|
|
|
#define SHORT_OPTIONS "+m:r:R:s:C:o:O:t:LvhVluZ"
|
2017-10-06 23:58:42 +00:00
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
{"model", 1, 0, 'm'},
|
|
|
|
{"rot-file", 1, 0, 'r'},
|
2021-07-24 04:28:02 +00:00
|
|
|
{"rot-file2", 1, 0, 'R'},
|
2017-08-09 18:09:55 +00:00
|
|
|
{"serial-speed", 1, 0, 's'},
|
|
|
|
{"send-cmd-term", 1, 0, 't'},
|
|
|
|
{"list", 0, 0, 'l'},
|
|
|
|
{"set-conf", 1, 0, 'C'},
|
2019-12-03 05:30:08 +00:00
|
|
|
{"set-azoffset", 1, 0, 'o'},
|
|
|
|
{"set-eloffset", 1, 0, 'O'},
|
2017-08-09 18:09:55 +00:00
|
|
|
{"show-conf", 0, 0, 'L'},
|
|
|
|
{"dump-caps", 0, 0, 'u'},
|
2019-11-30 16:19:08 +00:00
|
|
|
{"debug-time-stamps", 0, 0, 'Z'},
|
2013-02-23 02:45:57 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
{"read-history", 0, 0, 'i'},
|
|
|
|
{"save-history", 0, 0, 'I'},
|
2013-02-23 02:45:57 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
{"verbose", 0, 0, 'v'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{"version", 0, 0, 'V'},
|
|
|
|
{0, 0, 0, 0}
|
2001-12-28 20:34:30 +00:00
|
|
|
};
|
|
|
|
|
2020-04-01 19:51:50 +00:00
|
|
|
#define MAXCONFLEN 1024
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2013-02-22 23:18:30 +00:00
|
|
|
/* variable for readline support */
|
|
|
|
#ifdef HAVE_LIBREADLINE
|
|
|
|
static const int have_rl = 1;
|
|
|
|
#endif
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
int main(int argc, char *argv[])
|
2010-02-14 22:18:00 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
ROT *my_rot; /* handle to rot (instance) */
|
|
|
|
rot_model_t my_model = ROT_MODEL_DUMMY;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
int retcode; /* generic return code from functions */
|
|
|
|
int exitcode;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
int verbose = 0;
|
|
|
|
int show_conf = 0;
|
|
|
|
int dump_caps_opt = 0;
|
2018-10-25 23:26:25 +00:00
|
|
|
|
2013-02-23 02:45:57 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
int rd_hist = 0;
|
|
|
|
int sv_hist = 0;
|
|
|
|
const char *hist_dir = NULL;
|
|
|
|
const char hist_file[] = "/.rotctl_history";
|
|
|
|
char *hist_path = NULL;
|
2018-10-25 23:26:25 +00:00
|
|
|
#endif /* HAVE_READLINE_HISTORY */
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
const char *rot_file = NULL;
|
2021-07-24 04:28:02 +00:00
|
|
|
const char *rot_file2 = NULL; // for 2nd controller for RT21
|
2017-08-09 18:09:55 +00:00
|
|
|
int serial_rate = 0;
|
|
|
|
char conf_parms[MAXCONFLEN] = "";
|
2019-08-25 07:58:19 +00:00
|
|
|
int interactive = 1; /* if no cmd on command line, switch to interactive */
|
|
|
|
int prompt = 1; /* Print prompt in rotctl */
|
|
|
|
char send_cmd_term = '\r'; /* send_cmd termination char */
|
2019-12-03 05:30:08 +00:00
|
|
|
azimuth_t az_offset = 0;
|
|
|
|
elevation_t el_offset = 0;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int c;
|
|
|
|
int option_index = 0;
|
2020-07-01 13:52:44 +00:00
|
|
|
char dummy[2];
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
c = getopt_long(argc,
|
|
|
|
argv,
|
|
|
|
SHORT_OPTIONS HST_SHRT_OPTS,
|
|
|
|
long_options,
|
|
|
|
&option_index);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (c == -1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
switch (c)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
version();
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
case 'm':
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!optarg)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
my_model = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!optarg)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rot_file = optarg;
|
|
|
|
break;
|
|
|
|
|
2021-07-24 04:28:02 +00:00
|
|
|
case 'R':
|
|
|
|
if (!optarg)
|
|
|
|
{
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
rot_file2 = optarg;
|
|
|
|
break;
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
case 's':
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!optarg)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-07-01 13:52:44 +00:00
|
|
|
if (sscanf(optarg, "%d%1s", &serial_rate, dummy) != 1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Invalid baud rate of %s\n", optarg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!optarg)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (*conf_parms != '\0')
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
strcat(conf_parms, ",");
|
|
|
|
}
|
|
|
|
|
2020-04-01 19:51:50 +00:00
|
|
|
if (strlen(conf_parms) + strlen(optarg) > MAXCONFLEN - 24)
|
|
|
|
{
|
|
|
|
printf("Length of conf_parms exceeds internal maximum of %d\n",
|
|
|
|
MAXCONFLEN - 24);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
strncat(conf_parms, optarg, MAXCONFLEN - strlen(conf_parms));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!optarg)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (strlen(optarg) > 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
send_cmd_term = strtol(optarg, NULL, 0);
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
send_cmd_term = optarg[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2019-12-03 05:30:08 +00:00
|
|
|
|
|
|
|
case 'o':
|
|
|
|
if (!optarg)
|
|
|
|
{
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
az_offset = atof(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'O':
|
|
|
|
if (!optarg)
|
|
|
|
{
|
|
|
|
usage(); /* wrong arg count */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
el_offset = atof(optarg);
|
|
|
|
break;
|
|
|
|
|
2013-02-23 02:45:57 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
case 'i':
|
|
|
|
rd_hist++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
sv_hist++;
|
|
|
|
break;
|
2018-10-25 23:26:25 +00:00
|
|
|
#endif /* HAVE_READLINE_HISTORY */
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
case 'v':
|
|
|
|
verbose++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
show_conf++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
rig_set_debug(0);
|
|
|
|
list_models();
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
dump_caps_opt++;
|
|
|
|
break;
|
|
|
|
|
2018-04-14 22:20:28 +00:00
|
|
|
case 'Z':
|
|
|
|
rig_set_debug_time_stamp(1);
|
|
|
|
break;
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
default:
|
|
|
|
usage(); /* unknown option? */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rig_set_debug(verbose);
|
|
|
|
|
2021-03-20 03:56:18 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "rotctl %s\n", hamlib_version2);
|
2019-11-30 16:04:31 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s",
|
2017-08-09 18:09:55 +00:00
|
|
|
"Report bugs to <hamlib-developer@lists.sourceforge.net>\n\n");
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2010-04-25 17:29:53 +00:00
|
|
|
/*
|
2017-08-09 18:09:55 +00:00
|
|
|
* at least one command on command line,
|
|
|
|
* disable interactive mode
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
if (optind < argc)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
interactive = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my_rot = rot_init(my_model);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!my_rot)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Unknown rot num %d, or initialization error.\n",
|
|
|
|
my_model);
|
|
|
|
|
|
|
|
fprintf(stderr, "Please check with --list option.\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
retcode = set_conf(my_rot, conf_parms);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rot_file)
|
|
|
|
{
|
2021-03-06 20:59:57 +00:00
|
|
|
strncpy(my_rot->state.rotport.pathname, rot_file, HAMLIB_FILPATHLEN - 1);
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 04:28:02 +00:00
|
|
|
if (rot_file2)
|
|
|
|
{
|
|
|
|
strncpy(my_rot->state.rotport2.pathname, rot_file2, HAMLIB_FILPATHLEN - 1);
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
/* FIXME: bound checking and port type == serial */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (serial_rate != 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
my_rot->state.rotport.parm.serial.rate = serial_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* print out conf parameters
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
if (show_conf)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
rot_token_foreach(my_rot, print_conf_list, (rig_ptr_t)my_rot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out capabilities, and exits immediately as we may be interested
|
|
|
|
* only in caps, and rig_open may fail.
|
2010-04-25 17:29:53 +00:00
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
if (dump_caps_opt)
|
|
|
|
{
|
2010-04-25 17:29:53 +00:00
|
|
|
dumpcaps_rot(my_rot, stdout);
|
2017-08-09 18:09:55 +00:00
|
|
|
rot_cleanup(my_rot); /* if you care about memory */
|
2010-04-25 17:29:53 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
retcode = rot_open(my_rot);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr, "rot_open: error = %s \n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-12-03 05:30:08 +00:00
|
|
|
my_rot->state.az_offset = az_offset;
|
|
|
|
my_rot->state.el_offset = el_offset;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (verbose > 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("Opened rot model %d, '%s'\n",
|
|
|
|
my_rot->caps->rot_model,
|
|
|
|
my_rot->caps->model_name);
|
|
|
|
}
|
2002-09-06 10:43:59 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE,
|
|
|
|
"Backend version: %s, Status: %s\n",
|
|
|
|
my_rot->caps->version,
|
|
|
|
rig_strstatus(my_rot->caps->status));
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
exitcode = 0;
|
2010-12-01 21:41:55 +00:00
|
|
|
|
2013-02-22 23:18:30 +00:00
|
|
|
#ifdef HAVE_LIBREADLINE
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive && prompt && have_rl)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
rl_readline_name = "rotctl";
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
using_history(); /* Initialize Readline History */
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rd_hist || sv_hist)
|
|
|
|
{
|
2019-12-09 23:12:13 +00:00
|
|
|
int hist_path_size;
|
2020-01-15 21:58:04 +00:00
|
|
|
struct stat hist_dir_stat;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(hist_dir = getenv("ROTCTL_HIST_DIR")))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
hist_dir = getenv("HOME");
|
|
|
|
}
|
2013-02-23 02:45:57 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
if (((stat(hist_dir, &hist_dir_stat) == -1) && (errno == ENOENT))
|
2019-11-30 16:19:08 +00:00
|
|
|
|| !(S_ISDIR(hist_dir_stat.st_mode)))
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2013-02-23 02:45:57 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr, "Warning: %s is not a directory!\n", hist_dir);
|
|
|
|
}
|
2013-02-23 02:45:57 +00:00
|
|
|
|
2019-12-09 23:12:13 +00:00
|
|
|
hist_path_size = sizeof(char) * (strlen(hist_dir) + strlen(hist_file) + 1);
|
2019-11-30 16:19:08 +00:00
|
|
|
hist_path = (char *)calloc(hist_path_size, sizeof(char));
|
2018-04-16 15:39:05 +00:00
|
|
|
|
2022-01-11 06:00:44 +00:00
|
|
|
SNPRINTF(hist_path, hist_path_size, "%s%s", hist_dir, hist_file);
|
2013-02-23 02:45:57 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rd_hist && hist_path)
|
|
|
|
{
|
|
|
|
if (read_history(hist_path) == ENOENT)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Warning: Could not read history from %s\n",
|
|
|
|
hist_path);
|
|
|
|
}
|
|
|
|
}
|
2013-02-23 02:45:57 +00:00
|
|
|
|
2018-10-25 23:26:25 +00:00
|
|
|
#endif /* HAVE_READLINE_HISTORY */
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_LIBREADLINE */
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
do
|
|
|
|
{
|
2019-08-25 07:58:19 +00:00
|
|
|
retcode = rotctl_parse(my_rot, stdin, stdout, argv, argc,
|
2019-08-29 13:27:22 +00:00
|
|
|
interactive, prompt, send_cmd_term);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retcode == 2)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
exitcode = 2;
|
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
while (retcode == 0 || retcode == 2);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2013-02-23 02:45:57 +00:00
|
|
|
#ifdef HAVE_LIBREADLINE
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive && prompt && have_rl)
|
|
|
|
{
|
2013-02-23 02:45:57 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (sv_hist && hist_path)
|
|
|
|
{
|
|
|
|
if (write_history(hist_path) == ENOENT)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"\nWarning: Could not write history to %s\n",
|
|
|
|
hist_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((rd_hist || sv_hist) && hist_path)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
free(hist_path);
|
|
|
|
hist_path = (char *)NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-25 23:26:25 +00:00
|
|
|
#endif /* HAVE_READLINE_HISTORY */
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 23:26:25 +00:00
|
|
|
#endif /* HAVE_LIBREADLINE */
|
|
|
|
rot_close(my_rot); /* close port */
|
2017-08-09 18:09:55 +00:00
|
|
|
rot_cleanup(my_rot); /* if you care about memory */
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return exitcode;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2001-12-28 20:34:30 +00:00
|
|
|
void usage()
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("Usage: rotctl [OPTION]... [COMMAND]...\n"
|
|
|
|
"Send COMMANDs to a connected antenna rotator.\n\n");
|
|
|
|
|
|
|
|
printf(
|
2017-10-06 23:58:42 +00:00
|
|
|
" -m, --model=ID select rotator model number. See model list\n"
|
|
|
|
" -r, --rot-file=DEVICE set device of the rotator to operate on\n"
|
2021-07-24 04:28:02 +00:00
|
|
|
" -R, --rot-file2=DEVICE set device of the 2nd rotator controller to operate on\n"
|
2017-10-06 23:58:42 +00:00
|
|
|
" -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"
|
2019-12-03 05:30:08 +00:00
|
|
|
" -o, --set-azoffset==VAL set offset for azimuth\n"
|
|
|
|
" -O, --set-eloffset==VAL set offset for elevation\n"
|
2017-10-06 23:58:42 +00:00
|
|
|
" -L, --show-conf list all config parameters\n"
|
|
|
|
" -l, --list list all model numbers and exit\n"
|
|
|
|
" -u, --dump-caps dump capabilities and exit\n"
|
2013-02-23 02:45:57 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-10-06 23:58:42 +00:00
|
|
|
" -i, --read-history read prior interactive session history\n"
|
|
|
|
" -I, --save-history save current interactive session history\n"
|
2013-02-23 02:45:57 +00:00
|
|
|
#endif
|
2017-10-06 23:58:42 +00:00
|
|
|
" -v, --verbose set verbose mode, cumulative\n"
|
2018-04-14 22:20:28 +00:00
|
|
|
" -Z, --debug-time-stamps enable time stamps for debug messages\n"
|
2017-10-06 23:58:42 +00:00
|
|
|
" -h, --help display this help and exit\n"
|
|
|
|
" -V, --version output version information and exit\n\n"
|
2017-08-09 18:09:55 +00:00
|
|
|
);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
usage_rot(stdout);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("\nReport bugs to <hamlib-developer@lists.sourceforge.net>.\n");
|
2003-02-27 03:47:47 +00:00
|
|
|
}
|