2008-09-12 22:55:10 +00:00
|
|
|
/*
|
2010-04-25 17:29:53 +00:00
|
|
|
* rotctl_parse.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,2011
|
2008-09-12 22:55:10 +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
|
2008-09-12 22:55:10 +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
|
|
|
*
|
2008-09-12 22:55:10 +00:00
|
|
|
*/
|
|
|
|
|
2020-11-24 19:51:10 +00:00
|
|
|
// TODO: Add "symmetric" set_conf + get_conf to rigctl+rotctl
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2017-08-09 18:09:55 +00:00
|
|
|
# include "config.h"
|
2008-09-12 22:55:10 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.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
|
|
|
|
# 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) */
|
2017-08-09 18:09:55 +00:00
|
|
|
/* no history */
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif /* HAVE_READLINE_HISTORY */
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
#include <hamlib/rotator.h>
|
2008-09-21 19:27:54 +00:00
|
|
|
#include "serial.h"
|
2008-09-12 22:55:10 +00:00
|
|
|
#include "misc.h"
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2014-05-02 18:44:29 +00:00
|
|
|
/* HAVE_SSLEEP is defined when Windows Sleep is found
|
|
|
|
* HAVE_SLEEP is defined when POSIX sleep is found
|
|
|
|
* _WIN32 is defined when compiling with MinGW
|
|
|
|
*
|
|
|
|
* When cross-compiling from POSIX to Windows using MinGW, HAVE_SLEEP
|
|
|
|
* will often be defined by configure although it is not supported by
|
|
|
|
* MinGW. So substitute the sleep definition below in such a case and
|
|
|
|
* when compiling on Windows using MinGW where HAVE_SLEEP will be
|
|
|
|
* undefined.
|
|
|
|
*
|
|
|
|
* FIXME: Needs better handling for all versions of MinGW.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#if (defined(HAVE_SSLEEP) || defined(_WIN32)) && (!defined(HAVE_SLEEP))
|
2017-10-06 23:58:42 +00:00
|
|
|
# include "hl_sleep.h"
|
2014-05-02 18:44:29 +00:00
|
|
|
#endif
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
#include "rotctl_parse.h"
|
2020-11-24 19:51:10 +00:00
|
|
|
#include "sprintflst.h"
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
/* Hash table implementation See: http://uthash.sourceforge.net/ */
|
|
|
|
#include "uthash.h"
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
2017-10-06 23:58:42 +00:00
|
|
|
# include <pthread.h>
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
static pthread_mutex_t rot_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#endif
|
|
|
|
|
2014-05-02 18:44:29 +00:00
|
|
|
#define STR1(S) #S
|
|
|
|
#define STR(S) STR1(S)
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
#define MAXNAMSIZ 32
|
2017-08-09 18:09:55 +00:00
|
|
|
#define MAXNBOPT 100 /* max number of different options */
|
2014-05-02 18:44:29 +00:00
|
|
|
#define MAXARGSZ 127
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
#define ARG_IN1 0x01
|
|
|
|
#define ARG_OUT1 0x02
|
|
|
|
#define ARG_IN2 0x04
|
|
|
|
#define ARG_OUT2 0x08
|
|
|
|
#define ARG_IN3 0x10
|
|
|
|
#define ARG_OUT3 0x20
|
|
|
|
#define ARG_IN4 0x40
|
|
|
|
#define ARG_OUT4 0x80
|
2008-09-21 19:27:54 +00:00
|
|
|
#define ARG_IN_LINE 0x4000
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
#define ARG_NONE 0
|
2008-09-12 22:55:10 +00:00
|
|
|
#define ARG_IN (ARG_IN1|ARG_IN2|ARG_IN3|ARG_IN4)
|
|
|
|
#define ARG_OUT (ARG_OUT1|ARG_OUT2|ARG_OUT3|ARG_OUT4)
|
|
|
|
|
2013-02-22 23:18:30 +00:00
|
|
|
/* variables for readline support */
|
2020-01-15 23:05:31 +00:00
|
|
|
#ifdef HAVE_LIBREADLINE
|
2013-02-22 23:18:30 +00:00
|
|
|
static char *input_line = (char *)NULL;
|
|
|
|
static char *result = (char *)NULL;
|
2017-08-09 18:09:55 +00:00
|
|
|
static char *parsed_input[sizeof(char *) * 7];
|
2013-02-22 23:18:30 +00:00
|
|
|
static const int have_rl = 1;
|
2020-01-15 23:05:31 +00:00
|
|
|
#endif
|
2013-02-23 01:09:50 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
|
|
|
static char *rp_hist_buf = (char *)NULL;
|
|
|
|
#endif
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
struct test_table
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
unsigned char cmd;
|
|
|
|
const char *name;
|
|
|
|
int (*rot_routine)(ROT *,
|
|
|
|
FILE *,
|
|
|
|
int,
|
2019-08-25 07:58:19 +00:00
|
|
|
int,
|
|
|
|
char,
|
|
|
|
int,
|
|
|
|
char,
|
2017-08-09 18:09:55 +00:00
|
|
|
const struct test_table *,
|
|
|
|
const char *,
|
|
|
|
const char *,
|
|
|
|
const char *,
|
|
|
|
const char *,
|
|
|
|
const char *,
|
|
|
|
const char *);
|
|
|
|
int flags;
|
|
|
|
const char *arg1;
|
|
|
|
const char *arg2;
|
|
|
|
const char *arg3;
|
|
|
|
const char *arg4;
|
|
|
|
const char *arg5;
|
|
|
|
const char *arg6;
|
2008-09-12 22:55:10 +00:00
|
|
|
};
|
|
|
|
|
2010-04-05 10:15:36 +00:00
|
|
|
#define CHKSCN1ARG(a) if ((a) != 1) return -RIG_EINVAL; else do {} while(0)
|
|
|
|
|
2020-11-24 19:51:10 +00:00
|
|
|
#define ACTION(f) rotctl_##f
|
2017-08-09 18:09:55 +00:00
|
|
|
#define declare_proto_rot(f) static int (ACTION(f))(ROT *rot, \
|
|
|
|
FILE *fout, \
|
|
|
|
int interactive, \
|
2019-08-25 07:58:19 +00:00
|
|
|
int prompt, \
|
|
|
|
char send_cmd_term, \
|
|
|
|
int ext_resp, \
|
|
|
|
char resp_sep, \
|
2017-08-09 18:09:55 +00:00
|
|
|
const struct test_table *cmd, \
|
|
|
|
const char *arg1, \
|
|
|
|
const char *arg2, \
|
|
|
|
const char *arg3, \
|
|
|
|
const char *arg4, \
|
|
|
|
const char *arg5, \
|
|
|
|
const char *arg6)
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
declare_proto_rot(set_position);
|
|
|
|
declare_proto_rot(get_position);
|
|
|
|
declare_proto_rot(stop);
|
|
|
|
declare_proto_rot(park);
|
|
|
|
declare_proto_rot(reset);
|
|
|
|
declare_proto_rot(move);
|
2020-11-24 19:51:10 +00:00
|
|
|
declare_proto_rot(set_level);
|
|
|
|
declare_proto_rot(get_level);
|
|
|
|
declare_proto_rot(set_func);
|
|
|
|
declare_proto_rot(get_func);
|
|
|
|
declare_proto_rot(set_parm);
|
|
|
|
declare_proto_rot(get_parm);
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(get_info);
|
2020-12-03 19:40:34 +00:00
|
|
|
declare_proto_rot(get_status);
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(inter_set_conf); /* interactive mode set_conf */
|
2008-09-21 19:27:54 +00:00
|
|
|
declare_proto_rot(send_cmd);
|
|
|
|
declare_proto_rot(dump_state);
|
2010-02-14 22:18:00 +00:00
|
|
|
declare_proto_rot(dump_caps);
|
|
|
|
/* Follows are functions from locator.c */
|
|
|
|
declare_proto_rot(loc2lonlat);
|
|
|
|
declare_proto_rot(lonlat2loc);
|
|
|
|
declare_proto_rot(d_m_s2dec);
|
|
|
|
declare_proto_rot(dec2d_m_s);
|
|
|
|
declare_proto_rot(d_mm2dec);
|
|
|
|
declare_proto_rot(dec2d_mm);
|
|
|
|
declare_proto_rot(coord2qrb);
|
|
|
|
declare_proto_rot(az_sp2az_lp);
|
|
|
|
declare_proto_rot(dist_sp2dist_lp);
|
2014-05-02 18:44:29 +00:00
|
|
|
declare_proto_rot(pause);
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* convention: upper case cmd is set, lowercase is get
|
|
|
|
*
|
|
|
|
* NB: 'q' 'Q' '?' are reserved by interactive mode interface
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
struct test_table test_list[] =
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
{ 'P', "set_pos", ACTION(set_position), ARG_IN, "Azimuth", "Elevation" },
|
|
|
|
{ 'p', "get_pos", ACTION(get_position), ARG_OUT, "Azimuth", "Elevation" },
|
|
|
|
{ 'K', "park", ACTION(park), ARG_NONE, },
|
|
|
|
{ 'S', "stop", ACTION(stop), ARG_NONE, },
|
|
|
|
{ 'R', "reset", ACTION(reset), ARG_IN, "Reset" },
|
|
|
|
{ 'M', "move", ACTION(move), ARG_IN, "Direction", "Speed" },
|
2020-11-24 19:51:10 +00:00
|
|
|
{ 'V', "set_level", ACTION(set_level), ARG_IN, "Level", "Level Value" },
|
|
|
|
{ 'v', "get_level", ACTION(get_level), ARG_IN1 | ARG_OUT2, "Level", "Level Value" },
|
|
|
|
{ 'U', "set_func", ACTION(set_func), ARG_IN, "Func", "Func Status" },
|
|
|
|
{ 'u', "get_func", ACTION(get_func), ARG_IN1 | ARG_OUT2, "Func", "Func Status" },
|
|
|
|
{ 'X', "set_parm", ACTION(set_parm), ARG_IN, "Parm", "Parm Value" },
|
|
|
|
{ 'x', "get_parm", ACTION(get_parm), ARG_IN1 | ARG_OUT2, "Parm", "Parm Value" },
|
2017-08-09 18:09:55 +00:00
|
|
|
{ 'C', "set_conf", ACTION(inter_set_conf), ARG_IN, "Token", "Value" },
|
|
|
|
{ '_', "get_info", ACTION(get_info), ARG_OUT, "Info" },
|
2020-12-03 19:40:34 +00:00
|
|
|
{ 's', "get_status", ACTION(get_status), ARG_OUT, "Status flags" },
|
2017-08-09 18:09:55 +00:00
|
|
|
{ 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2, "Cmd", "Reply" },
|
|
|
|
{ '1', "dump_caps", ACTION(dump_caps), },
|
|
|
|
{ 0x8f, "dump_state", ACTION(dump_state), ARG_OUT },
|
|
|
|
{ 'L', "lonlat2loc", ACTION(lonlat2loc), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1, "Longitude", "Latitude", "Loc Len [2-12]", "Locator" },
|
|
|
|
{ 'l', "loc2lonlat", ACTION(loc2lonlat), ARG_IN1 | ARG_OUT1 | ARG_OUT2, "Locator", "Longitude", "Latitude" },
|
|
|
|
{ 'D', "dms2dec", ACTION(d_m_s2dec), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_IN4 | ARG_OUT1, "Degrees", "Minutes", "Seconds", "S/W", "Dec Degrees" },
|
|
|
|
{ 'd', "dec2dms", ACTION(dec2d_m_s), ARG_IN1 | ARG_OUT1 | ARG_OUT2 | ARG_OUT3 | ARG_OUT4, "Dec Degrees", "Degrees", "Minutes", "Seconds", "S/W" },
|
|
|
|
{ 'E', "dmmm2dec", ACTION(d_mm2dec), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_OUT1, "Degrees", "Dec Minutes", "S/W", "Dec Deg" },
|
|
|
|
{ 'e', "dec2dmmm", ACTION(dec2d_mm), ARG_IN1 | ARG_OUT1 | ARG_OUT2 | ARG_OUT3, "Dec Deg", "Degrees", "Dec Minutes", "S/W" },
|
|
|
|
{ 'B', "qrb", ACTION(coord2qrb), ARG_IN1 | ARG_IN2 | ARG_IN3 | ARG_IN4 | ARG_OUT1 | ARG_OUT2, "Lon 1", "Lat 1", "Lon 2", "Lat 2", "QRB Distance", "QRB Azimuth" },
|
|
|
|
{ 'A', "a_sp2a_lp", ACTION(az_sp2az_lp), ARG_IN1 | ARG_OUT1, "Short Path Deg", "Long Path Deg" },
|
|
|
|
{ 'a', "d_sp2d_lp", ACTION(dist_sp2dist_lp), ARG_IN1 | ARG_OUT1, "Short Path km", "Long Path km" },
|
|
|
|
{ 0x8c, "pause", ACTION(pause), ARG_IN, "Seconds" },
|
|
|
|
{ 0x00, "", NULL },
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
struct test_table *find_cmd_entry(int cmd)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int i;
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2019-12-06 18:13:38 +00:00
|
|
|
for (i = 0; test_list[i].cmd != 0x00; i++)
|
2017-10-06 23:58:42 +00:00
|
|
|
if (test_list[i].cmd == cmd)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-01-14 20:18:47 +00:00
|
|
|
if (test_list[i].cmd == 0x00)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return &test_list[i];
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
2012-02-13 20:29:35 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
/* Structure for hash table provided by uthash.h
|
|
|
|
*
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 07:02:12 +00:00
|
|
|
* Structure and hash functions patterned after/copied from example.c
|
2012-02-13 20:29:35 +00:00
|
|
|
* distributed with the uthash package. See: http://uthash.sourceforge.net/
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
struct mod_lst
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int id; /* caps->rot_model This is the hash key */
|
|
|
|
char mfg_name[32]; /* caps->mfg_name */
|
|
|
|
char model_name[32]; /* caps->model_name */
|
|
|
|
char version[32]; /* caps->version */
|
|
|
|
char status[32]; /* caps->status */
|
2020-03-06 05:48:14 +00:00
|
|
|
char macro_name[32]; /* caps->macro_name */
|
2017-08-09 18:09:55 +00:00
|
|
|
UT_hash_handle hh; /* makes this structure hashable */
|
2012-02-13 20:29:35 +00:00
|
|
|
};
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
/* Hash declaration. Must be initialized to NULL */
|
|
|
|
struct mod_lst *models = NULL;
|
|
|
|
|
|
|
|
/* Add model information to the hash */
|
2017-08-09 18:09:55 +00:00
|
|
|
void hash_add_model(int id,
|
|
|
|
const char *mfg_name,
|
|
|
|
const char *model_name,
|
|
|
|
const char *version,
|
2020-03-06 05:48:14 +00:00
|
|
|
const char *status,
|
|
|
|
const char *macro_name)
|
2012-02-13 20:29:35 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
struct mod_lst *s;
|
2012-02-13 20:29:35 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
s = (struct mod_lst *)malloc(sizeof(struct mod_lst));
|
2012-02-13 20:29:35 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
s->id = id;
|
|
|
|
snprintf(s->mfg_name, sizeof(s->mfg_name), "%s", mfg_name);
|
|
|
|
snprintf(s->model_name, sizeof(s->model_name), "%s", model_name);
|
|
|
|
snprintf(s->version, sizeof(s->version), "%s", version);
|
|
|
|
snprintf(s->status, sizeof(s->status), "%s", status);
|
2020-03-06 05:48:14 +00:00
|
|
|
snprintf(s->macro_name, sizeof(s->macro_name), "%s", macro_name);
|
2012-02-13 20:29:35 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
HASH_ADD_INT(models, id, s); /* id: name of key field */
|
2012-02-13 20:29:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
/* Hash sorting functions */
|
|
|
|
int hash_model_id_sort(struct mod_lst *a, struct mod_lst *b)
|
|
|
|
{
|
2019-12-06 18:13:38 +00:00
|
|
|
return (a->id > b->id);
|
2012-02-13 20:29:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
void hash_sort_by_model_id()
|
|
|
|
{
|
|
|
|
HASH_SORT(models, hash_model_id_sort);
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
/* Delete hash */
|
2017-08-09 18:09:55 +00:00
|
|
|
void hash_delete_all()
|
|
|
|
{
|
2020-09-01 14:06:46 +00:00
|
|
|
struct mod_lst *current_model, *tmp = NULL;
|
2012-02-13 20:29:35 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
HASH_ITER(hh, models, current_model, tmp)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/* delete it (models advances to next) */
|
|
|
|
HASH_DEL(models, current_model);
|
|
|
|
free(current_model); /* free it */
|
|
|
|
}
|
2012-02-13 20:29:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-15 23:05:31 +00:00
|
|
|
#ifdef HAVE_LIBREADLINE
|
2013-02-22 23:18:30 +00:00
|
|
|
/* Frees allocated memory and sets pointers to NULL before calling readline
|
|
|
|
* and then parses the input into space separated tokens.
|
|
|
|
*/
|
|
|
|
static void rp_getline(const char *s)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* free allocated memory and set pointers to NULL */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (input_line)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
free(input_line);
|
|
|
|
input_line = (char *)NULL;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
result = (char *)NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cmd, arg1, arg2, arg3, arg4, arg5, arg6
|
|
|
|
* arg5 and arg 6 are currently unused.
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
for (i = 0; i < 7; i++)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Action! Returns typed line with newline stripped. */
|
|
|
|
input_line = readline(s);
|
2013-02-22 23:18:30 +00:00
|
|
|
}
|
2020-01-15 23:05:31 +00:00
|
|
|
#endif
|
2013-02-22 23:18:30 +00:00
|
|
|
|
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
/*
|
|
|
|
* TODO: use Lex?
|
|
|
|
*/
|
|
|
|
char parse_arg(const char *arg)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int i;
|
|
|
|
|
2019-12-24 21:12:05 +00:00
|
|
|
for (i = 0; test_list[i].cmd != 0; i++)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
|
|
|
if (!strncmp(arg, test_list[i].name, MAXNAMSIZ))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return test_list[i].cmd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/*
|
2008-09-12 22:55:10 +00:00
|
|
|
* This scanf works even in presence of signals (timer, SIGIO, ..)
|
|
|
|
*/
|
|
|
|
static int scanfc(FILE *fin, const char *format, void *p)
|
|
|
|
{
|
2017-10-06 23:58:42 +00:00
|
|
|
do
|
|
|
|
{
|
2019-12-24 21:12:05 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
ret = fscanf(fin, format, p);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
if (errno == EINTR)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_ERR, "fscanf: %s\n", strerror(errno));
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "fscanf: parsing '%s' with '%s'\n", (char *)p, format);
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
while (1);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2014-05-02 18:44:29 +00:00
|
|
|
/*
|
|
|
|
* function to get the next word from the command line or from stdin
|
|
|
|
* until stdin exhausted. stdin is read if the special token '-' is
|
|
|
|
* found on the command line.
|
|
|
|
*
|
|
|
|
* returns EOF when words exhausted
|
|
|
|
* returns <0 is error number
|
|
|
|
* returns >=0 when successful
|
|
|
|
*/
|
2017-08-09 18:09:55 +00:00
|
|
|
static int next_word(char *buffer, int argc, char *argv[], int newline)
|
2014-05-02 18:44:29 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int ret;
|
|
|
|
char c;
|
|
|
|
static int reading_stdin;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!reading_stdin)
|
|
|
|
{
|
|
|
|
if (optind >= argc)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return EOF;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (newline
|
|
|
|
&& '-' == argv[optind][0]
|
|
|
|
&& 1 == strlen(argv[optind]))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
++optind;
|
|
|
|
reading_stdin = 1;
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (reading_stdin)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
ret = scanf(" %c%" STR(MAXARGSZ) "[^ \t\n#]", &c, &buffer[1]);
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
while (EINTR == ret);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (ret > 0 && '#' == c)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
ret = scanf("%*[^\n]");
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
while (EINTR == ret); /* consume comments */
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
ret = 0;
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
while (!ret);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (EOF == ret)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
reading_stdin = 0;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (ret < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "scanf: %s\n", strerror(errno));
|
|
|
|
reading_stdin = 0;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
buffer[0] = c;
|
|
|
|
buffer[1 == ret ? 1 : MAXARGSZ] = '\0';
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (newline)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs(buffer, stdout);
|
|
|
|
putchar(' ');
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!reading_stdin)
|
|
|
|
{
|
|
|
|
if (optind < argc)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
strncpy(buffer, argv[optind++], MAXARGSZ);
|
|
|
|
buffer[MAXARGSZ] = '\0';
|
|
|
|
ret = 1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
ret = EOF;
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return ret;
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
#define fprintf_flush(f, a...) \
|
|
|
|
({ int __ret; \
|
|
|
|
__ret = fprintf((f), a); \
|
|
|
|
fflush((f)); \
|
|
|
|
__ret; \
|
|
|
|
})
|
2010-05-05 20:11:55 +00:00
|
|
|
|
|
|
|
|
2019-08-25 07:58:19 +00:00
|
|
|
int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, char *argv[], int argc,
|
2019-08-29 13:27:22 +00:00
|
|
|
int interactive, int prompt, char send_cmd_term)
|
2010-02-14 22:18:00 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int retcode; /* generic return code from functions */
|
|
|
|
unsigned char cmd;
|
2019-12-03 22:15:33 +00:00
|
|
|
struct test_table *cmd_entry = NULL;
|
2019-08-29 13:27:22 +00:00
|
|
|
int ext_resp = 0;
|
|
|
|
char resp_sep = '\n';
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
char command[MAXARGSZ + 1];
|
|
|
|
char arg1[MAXARGSZ + 1], *p1 = NULL;
|
|
|
|
char arg2[MAXARGSZ + 1], *p2 = NULL;
|
|
|
|
char arg3[MAXARGSZ + 1], *p3 = NULL;
|
|
|
|
char arg4[MAXARGSZ + 1], *p4 = NULL;
|
2020-01-14 20:18:47 +00:00
|
|
|
#ifdef __USEP5P6__
|
2017-08-09 18:09:55 +00:00
|
|
|
char *p5 = NULL;
|
|
|
|
char *p6 = NULL;
|
2020-01-14 20:18:47 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
/* cmd, internal, rotctld */
|
2020-01-15 05:36:01 +00:00
|
|
|
#ifdef HAVE_LIBREADLINE
|
2020-02-23 17:26:09 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(interactive && prompt && have_rl))
|
2020-01-15 05:36:01 +00:00
|
|
|
#endif
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
|
|
|
if (interactive)
|
|
|
|
{
|
2019-12-24 21:12:05 +00:00
|
|
|
static int last_was_ret = 1;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "\nRotator command: ");
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (scanfc(fin, "%c", &cmd) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extended response protocol requested with leading '+' on command
|
|
|
|
* string--rotctld only!
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
if (cmd == '+' && !prompt)
|
|
|
|
{
|
2019-08-29 13:27:22 +00:00
|
|
|
ext_resp = 1;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (scanfc(fin, "%c", &cmd) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (cmd == '+' && prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd != '\\'
|
2019-11-30 16:19:08 +00:00
|
|
|
&& cmd != '_'
|
|
|
|
&& cmd != '#'
|
|
|
|
&& ispunct(cmd)
|
|
|
|
&& !prompt)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2019-08-29 13:27:22 +00:00
|
|
|
ext_resp = 1;
|
|
|
|
resp_sep = cmd;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (scanfc(fin, "%c", &cmd) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (cmd != '\\'
|
|
|
|
&& cmd != '?'
|
|
|
|
&& cmd != '_'
|
|
|
|
&& cmd != '#'
|
|
|
|
&& ispunct(cmd)
|
|
|
|
&& prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* command by name */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (cmd == '\\')
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
unsigned char cmd_name[MAXNAMSIZ], *pcmd = cmd_name;
|
|
|
|
int c_len = MAXNAMSIZ;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (scanfc(fin, "%c", pcmd) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
while (c_len-- && (isalnum(*pcmd) || *pcmd == '_'))
|
|
|
|
{
|
|
|
|
if (scanfc(fin, "%c", ++pcmd) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcmd = '\0';
|
|
|
|
cmd = parse_arg((char *) cmd_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (cmd == 0x0a || cmd == 0x0d)
|
|
|
|
{
|
|
|
|
if (last_was_ret)
|
|
|
|
{
|
|
|
|
if (prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "? for help, q to quit.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_was_ret = 1;
|
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
while (cmd == 0x0a || cmd == 0x0d);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
last_was_ret = 0;
|
|
|
|
|
|
|
|
/* comment line */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (cmd == '#')
|
|
|
|
{
|
|
|
|
while (cmd != '\n' && cmd != '\r')
|
|
|
|
{
|
|
|
|
if (scanfc(fin, "%c", &cmd) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (cmd == 'Q' || cmd == 'q')
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (cmd == '?')
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
usage_rot(fout);
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/* parse rest of command line */
|
|
|
|
retcode = next_word(command, argc, argv, 1);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (EOF == retcode)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return 1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (retcode < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return retcode;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if ('\0' == command[1])
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
cmd = command[0];
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
cmd = parse_arg(command);
|
|
|
|
}
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
cmd_entry = find_cmd_entry(cmd);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!cmd_entry)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(stderr, "Command '%c' not found!\n", cmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cmd_entry->flags & ARG_IN_LINE)
|
2019-11-30 16:19:08 +00:00
|
|
|
&& (cmd_entry->flags & ARG_IN1)
|
|
|
|
&& cmd_entry->arg1)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
char *nl;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "%s: ", cmd_entry->arg1);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (fgets(arg1, MAXARGSZ, fin) == NULL)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (arg1[0] == 0xa)
|
|
|
|
{
|
|
|
|
if (fgets(arg1, MAXARGSZ, fin) == NULL)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nl = strchr(arg1, 0xa);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (nl)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
*nl = '\0'; /* chomp */
|
|
|
|
}
|
|
|
|
|
|
|
|
p1 = arg1[0] == ' ' ? arg1 + 1 : arg1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
retcode = next_word(arg1, argc, argv, 0);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (EOF == retcode)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid arg for command '%s'\n",
|
|
|
|
cmd_entry->name);
|
|
|
|
return 1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (retcode < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
p1 = arg1;
|
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1)
|
|
|
|
{
|
|
|
|
if (interactive)
|
|
|
|
{
|
|
|
|
if (prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "%s: ", cmd_entry->arg1);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (scanfc(fin, "%s", arg1) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p1 = arg1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
retcode = next_word(arg1, argc, argv, 0);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (EOF == retcode)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid arg for command '%s'\n",
|
|
|
|
cmd_entry->name);
|
|
|
|
return 1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (retcode < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
p1 = arg1;
|
|
|
|
}
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
if (p1
|
2019-11-30 16:19:08 +00:00
|
|
|
&& p1[0] != '?'
|
|
|
|
&& (cmd_entry->flags & ARG_IN2)
|
|
|
|
&& cmd_entry->arg2)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive)
|
|
|
|
{
|
|
|
|
if (prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "%s: ", cmd_entry->arg2);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (scanfc(fin, "%s", arg2) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p2 = arg2;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
retcode = next_word(arg2, argc, argv, 0);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (EOF == retcode)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid arg for command '%s'\n",
|
|
|
|
cmd_entry->name);
|
|
|
|
return 1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (retcode < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
p2 = arg2;
|
|
|
|
}
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
if (p1
|
2019-11-30 16:19:08 +00:00
|
|
|
&& p1[0] != '?'
|
|
|
|
&& (cmd_entry->flags & ARG_IN3)
|
|
|
|
&& cmd_entry->arg3)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive)
|
|
|
|
{
|
|
|
|
if (prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "%s: ", cmd_entry->arg3);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (scanfc(fin, "%s", arg3) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p3 = arg3;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
retcode = next_word(arg3, argc, argv, 0);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (EOF == retcode)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid arg for command '%s'\n",
|
|
|
|
cmd_entry->name);
|
|
|
|
return 1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (retcode < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
p3 = arg3;
|
|
|
|
}
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
if (p1
|
2019-11-30 16:19:08 +00:00
|
|
|
&& p1[0] != '?'
|
|
|
|
&& (cmd_entry->flags & ARG_IN4)
|
|
|
|
&& cmd_entry->arg4)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive)
|
|
|
|
{
|
|
|
|
if (prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "%s: ", cmd_entry->arg4);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (scanfc(fin, "%s", arg4) < 1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
p4 = arg4;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
retcode = next_word(arg4, argc, argv, 0);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (EOF == retcode)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Invalid arg for command '%s'\n",
|
|
|
|
cmd_entry->name);
|
|
|
|
return 1;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (retcode < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return retcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
p4 = arg4;
|
|
|
|
}
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2013-02-22 23:18:30 +00:00
|
|
|
#ifdef HAVE_LIBREADLINE
|
2020-02-23 17:26:09 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive && prompt && have_rl)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int j, x;
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
/* Minimum space for 32+1+128+1+128+1+128+1+128+1+128+1+128+1 = 807
|
|
|
|
* chars, so allocate 896 chars cleared to zero for safety.
|
|
|
|
*/
|
|
|
|
rp_hist_buf = (char *)calloc(896, sizeof(char));
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
rp_getline("\nRotator command: ");
|
|
|
|
|
|
|
|
/* EOF (Ctl-D) received on empty input line, bail out gracefully. */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!input_line)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Q or q to quit */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strncasecmp(input_line, "q", 1)))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '?' for help */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strncmp(input_line, "?", 1)))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
usage_rot(fout);
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '#' for comment */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strncmp(input_line, "#", 1)))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Blank line entered */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strcmp(input_line, "")))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "? for help, q to quit.\n");
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_BUG, "%s: input_line: %s\n", __func__, input_line);
|
|
|
|
|
|
|
|
/* Split input_line on any number of spaces to get the command token
|
|
|
|
* Tabs are intercepted by readline for completion and a newline
|
|
|
|
* causes readline to return the typed text. If more than one
|
|
|
|
* argument is given, it will be parsed out later.
|
|
|
|
*/
|
|
|
|
result = strtok(input_line, " ");
|
|
|
|
|
|
|
|
/* parsed_input stores pointers into input_line where the token strings
|
|
|
|
* start.
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[0] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/* Oops! Invoke GDB!! */
|
|
|
|
fprintf_flush(fout, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* At this point parsed_input contains the typed text of the command
|
|
|
|
* with surrounding space characters removed. If Readline History is
|
|
|
|
* available, copy the command string into a history buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Single character command */
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((strlen(parsed_input[0]) == 1) && (*parsed_input[0] != '\\'))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
cmd = *parsed_input[0];
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
/* Store what is typed, not validated, for history. */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
strncpy(rp_hist_buf, parsed_input[0], 1);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
/* Test the command token, parsed_input[0] */
|
2017-10-06 23:58:42 +00:00
|
|
|
else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) > 1))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
char cmd_name[MAXNAMSIZ];
|
|
|
|
|
|
|
|
/* if there is no terminating '\0' character in the source string,
|
|
|
|
* srncpy() doesn't add one even if the supplied length is less
|
|
|
|
* than the destination array. Truncate the source string here.
|
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
if (strlen(parsed_input[0] + 1) >= MAXNAMSIZ)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
*(parsed_input[0] + MAXNAMSIZ) = '\0';
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
strncpy(rp_hist_buf, parsed_input[0], MAXNAMSIZ);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
/* The starting position of the source string is the first
|
2018-07-30 02:38:54 +00:00
|
|
|
* character past the initial '\'.
|
2017-08-09 18:09:55 +00:00
|
|
|
*/
|
2018-11-06 02:07:34 +00:00
|
|
|
snprintf(cmd_name, sizeof(cmd_name), "%s", parsed_input[0] + 1);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
/* Sanity check as valid multiple character commands consist of
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 07:02:12 +00:00
|
|
|
* alphanumeric characters and the underscore ('_') character.
|
2017-08-09 18:09:55 +00:00
|
|
|
*/
|
2017-10-06 23:58:42 +00:00
|
|
|
for (j = 0; cmd_name[j] != '\0'; j++)
|
|
|
|
{
|
|
|
|
if (!(isalnum((int)cmd_name[j]) || cmd_name[j] == '_'))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr,
|
Fix spelling errors
Fixed using the following command:
codespell --write-changes --summary --skip=*.m4 --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
codespell --write-changes --summary --skip=aclocal.m4,lib --ignore-words-list="develope,get's,quitt,setts,som,ue,vektor"
Codespell home page: https://github.com/codespell-project/codespell
2020-07-24 07:02:12 +00:00
|
|
|
"Valid multiple character command names contain alphanumeric characters plus '_'\n");
|
2017-08-09 18:09:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = parse_arg(cmd_name);
|
|
|
|
}
|
|
|
|
/* Single '\' entered, prompt again */
|
2017-10-06 23:58:42 +00:00
|
|
|
else if ((*parsed_input[0] == '\\') && (strlen(parsed_input[0]) == 1))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Multiple characters but no leading '\' */
|
2017-10-06 23:58:42 +00:00
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr, "Precede multiple character command names with '\\'\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_entry = find_cmd_entry(cmd);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!cmd_entry)
|
|
|
|
{
|
|
|
|
if (cmd == '\0')
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr, "Command '%s' not found!\n", parsed_input[0]);
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(stderr, "Command '%c' not found!\n", cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* \send_cmd */
|
|
|
|
if ((cmd_entry->flags & ARG_IN_LINE)
|
2019-11-30 16:19:08 +00:00
|
|
|
&& (cmd_entry->flags & ARG_IN1)
|
|
|
|
&& cmd_entry->arg1)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
/* Check for a non-existent delimiter so as to not break up
|
|
|
|
* remaining line into separate tokens (spaces OK).
|
|
|
|
*/
|
|
|
|
result = strtok(NULL, "\0");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
x = 1;
|
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
char pmptstr[(strlen(cmd_entry->arg1) + 3)];
|
2019-12-09 23:12:13 +00:00
|
|
|
x = 0;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
strcpy(pmptstr, cmd_entry->arg1);
|
|
|
|
strcat(pmptstr, ": ");
|
|
|
|
|
|
|
|
rp_getline(pmptstr);
|
|
|
|
|
2019-12-24 21:12:05 +00:00
|
|
|
if (input_line == NULL)
|
|
|
|
{
|
|
|
|
fprintf_flush(fout, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
/* Blank line entered */
|
2019-12-24 21:12:05 +00:00
|
|
|
else if (!(strcmp(input_line, "")))
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "? for help, q to quit.\n");
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
else
|
|
|
|
{
|
2019-12-24 21:12:05 +00:00
|
|
|
parsed_input[x] = input_line;
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The arg1 array size is MAXARGSZ + 1 so truncate it to fit if larger. */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (strlen(parsed_input[x]) > MAXARGSZ)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x][MAXARGSZ] = '\0';
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2018-04-16 03:54:27 +00:00
|
|
|
strncat(rp_hist_buf, " ", 2);
|
2017-08-09 18:09:55 +00:00
|
|
|
strncat(rp_hist_buf, parsed_input[x], MAXARGSZ);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
strcpy(arg1, parsed_input[x]);
|
|
|
|
p1 = arg1;
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
/* Normal argument parsing. */
|
2017-10-06 23:58:42 +00:00
|
|
|
else if ((cmd_entry->flags & ARG_IN1) && cmd_entry->arg1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
result = strtok(NULL, " ");
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
x = 1;
|
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
char pmptstr[(strlen(cmd_entry->arg1) + 3)];
|
2019-12-09 23:12:13 +00:00
|
|
|
x = 0;
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
strcpy(pmptstr, cmd_entry->arg1);
|
|
|
|
strcat(pmptstr, ": ");
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
rp_getline(pmptstr);
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strcmp(input_line, "")))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "? for help, q to quit.\n");
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
result = strtok(input_line, " ");
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (strlen(parsed_input[x]) > MAXARGSZ)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x][MAXARGSZ] = '\0';
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2018-04-16 03:54:27 +00:00
|
|
|
strncat(rp_hist_buf, " ", 2);
|
2017-08-09 18:09:55 +00:00
|
|
|
strncat(rp_hist_buf, parsed_input[x], MAXARGSZ);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
strcpy(arg1, parsed_input[x]);
|
|
|
|
p1 = arg1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p1
|
2019-11-30 16:19:08 +00:00
|
|
|
&& p1[0] != '?'
|
|
|
|
&& (cmd_entry->flags & ARG_IN2)
|
|
|
|
&& cmd_entry->arg2)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
result = strtok(NULL, " ");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
x = 2;
|
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
char pmptstr[(strlen(cmd_entry->arg2) + 3)];
|
2019-12-09 23:12:13 +00:00
|
|
|
x = 0;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
strcpy(pmptstr, cmd_entry->arg2);
|
|
|
|
strcat(pmptstr, ": ");
|
|
|
|
|
|
|
|
rp_getline(pmptstr);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strcmp(input_line, "")))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "? for help, q to quit.\n");
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = strtok(input_line, " ");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (strlen(parsed_input[x]) > MAXARGSZ)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x][MAXARGSZ] = '\0';
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2018-04-16 03:54:27 +00:00
|
|
|
strncat(rp_hist_buf, " ", 2);
|
2017-08-09 18:09:55 +00:00
|
|
|
strncat(rp_hist_buf, parsed_input[x], MAXARGSZ);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
strcpy(arg2, parsed_input[x]);
|
|
|
|
p2 = arg2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p1
|
2019-11-30 16:19:08 +00:00
|
|
|
&& p1[0] != '?'
|
|
|
|
&& (cmd_entry->flags & ARG_IN3)
|
|
|
|
&& cmd_entry->arg3)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
result = strtok(NULL, " ");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
x = 3;
|
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
char pmptstr[(strlen(cmd_entry->arg3) + 3)];
|
2019-12-09 23:12:13 +00:00
|
|
|
x = 0;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
strcpy(pmptstr, cmd_entry->arg3);
|
|
|
|
strcat(pmptstr, ": ");
|
|
|
|
|
|
|
|
rp_getline(pmptstr);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strcmp(input_line, "")))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "? for help, q to quit.\n");
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = strtok(input_line, " ");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (strlen(parsed_input[x]) > MAXARGSZ)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x][MAXARGSZ] = '\0';
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2018-04-16 03:54:27 +00:00
|
|
|
strncat(rp_hist_buf, " ", 2);
|
2017-08-09 18:09:55 +00:00
|
|
|
strncat(rp_hist_buf, parsed_input[x], MAXARGSZ);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
strcpy(arg3, parsed_input[x]);
|
|
|
|
p3 = arg3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p1
|
2019-11-30 16:19:08 +00:00
|
|
|
&& p1[0] != '?'
|
|
|
|
&& (cmd_entry->flags & ARG_IN4)
|
|
|
|
&& cmd_entry->arg4)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
result = strtok(NULL, " ");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
x = 4;
|
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
char pmptstr[(strlen(cmd_entry->arg4) + 3)];
|
2019-12-09 23:12:13 +00:00
|
|
|
x = 0;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
strcpy(pmptstr, cmd_entry->arg4);
|
|
|
|
strcat(pmptstr, ": ");
|
|
|
|
|
|
|
|
rp_getline(pmptstr);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!(strcmp(input_line, "")))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "? for help, q to quit.\n");
|
|
|
|
fflush(fout);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = strtok(input_line, " ");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (result)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x] = result;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf_flush(fout, "\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (strlen(parsed_input[x]) > MAXARGSZ)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
parsed_input[x][MAXARGSZ] = '\0';
|
|
|
|
}
|
2013-02-22 23:18:30 +00:00
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2018-04-16 03:54:27 +00:00
|
|
|
strncat(rp_hist_buf, " ", 2);
|
2017-08-09 18:09:55 +00:00
|
|
|
strncat(rp_hist_buf, parsed_input[x], MAXARGSZ);
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
strcpy(arg4, parsed_input[x]);
|
|
|
|
p4 = arg4;
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#ifdef HAVE_READLINE_HISTORY
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (rp_hist_buf)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
add_history(rp_hist_buf);
|
|
|
|
free(rp_hist_buf);
|
|
|
|
rp_hist_buf = (char *)NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-23 01:09:50 +00:00
|
|
|
#endif
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
2020-02-23 17:26:09 +00:00
|
|
|
|
2020-01-15 23:05:31 +00:00
|
|
|
#endif // HAVE_LIBREADLINE
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
/*
|
|
|
|
* mutex locking needed because rotctld is multithreaded
|
|
|
|
* and hamlib is not MT-safe
|
|
|
|
*/
|
2008-09-12 22:55:10 +00:00
|
|
|
#ifdef HAVE_PTHREAD
|
2017-08-09 18:09:55 +00:00
|
|
|
pthread_mutex_lock(&rot_mutex);
|
2008-09-12 22:55:10 +00:00
|
|
|
#endif
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
if (!prompt)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE,
|
|
|
|
"rotctl(d): %c '%s' '%s' '%s' '%s'\n",
|
|
|
|
cmd,
|
|
|
|
p1 ? p1 : "",
|
|
|
|
p2 ? p2 : "",
|
|
|
|
p3 ? p3 : "",
|
|
|
|
p4 ? p4 : "");
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Extended Response protocol: output received command name and arguments
|
|
|
|
* response.
|
|
|
|
*/
|
2019-08-29 13:27:22 +00:00
|
|
|
if (interactive && ext_resp && !prompt)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2019-05-22 16:15:30 +00:00
|
|
|
char a1[MAXARGSZ + 2];
|
|
|
|
char a2[MAXARGSZ + 2];
|
|
|
|
char a3[MAXARGSZ + 2];
|
|
|
|
char a4[MAXARGSZ + 2];
|
2010-02-14 22:18:00 +00:00
|
|
|
|
|
|
|
p1 == NULL ? a1[0] = '\0' : snprintf(a1, sizeof(a1), " %s", p1);
|
|
|
|
p2 == NULL ? a2[0] = '\0' : snprintf(a2, sizeof(a2), " %s", p2);
|
|
|
|
p3 == NULL ? a3[0] = '\0' : snprintf(a3, sizeof(a3), " %s", p3);
|
|
|
|
p4 == NULL ? a4[0] = '\0' : snprintf(a4, sizeof(a4), " %s", p4);
|
|
|
|
|
2019-08-29 13:27:22 +00:00
|
|
|
fprintf(fout, "%s:%s%s%s%s%c", cmd_entry->name, a1, a2, a3, a4, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
retcode = (*cmd_entry->rot_routine)(my_rot,
|
|
|
|
fout,
|
|
|
|
interactive,
|
2019-08-25 07:58:19 +00:00
|
|
|
prompt,
|
|
|
|
send_cmd_term,
|
2019-08-29 13:27:22 +00:00
|
|
|
ext_resp,
|
|
|
|
resp_sep,
|
2017-08-09 18:09:55 +00:00
|
|
|
cmd_entry,
|
|
|
|
p1,
|
|
|
|
p2 ? p2 : "",
|
|
|
|
p3 ? p3 : "",
|
|
|
|
p4 ? p4 : "",
|
2020-01-14 20:18:47 +00:00
|
|
|
#ifdef __USEP5P6__
|
2017-08-09 18:09:55 +00:00
|
|
|
p5 ? p5 : "",
|
|
|
|
p6 ? p6 : "");
|
2020-01-14 20:18:47 +00:00
|
|
|
#else
|
|
|
|
"",
|
|
|
|
"");
|
|
|
|
#endif
|
2008-09-12 22:55:10 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PTHREAD
|
2017-08-09 18:09:55 +00:00
|
|
|
pthread_mutex_unlock(&rot_mutex);
|
2008-09-12 22:55:10 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (retcode == RIG_EIO) { return retcode; }
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retcode != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/* only for rotctld */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive && !prompt)
|
|
|
|
{
|
2020-11-23 14:46:15 +00:00
|
|
|
rot_debug(RIG_DEBUG_TRACE, "%s: NETROTCTL_RET %d\n", __func__, retcode);
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, NETROTCTL_RET "%d\n", retcode);
|
2020-01-15 05:36:01 +00:00
|
|
|
// ext_resp = 0; // not used ?
|
2019-08-29 13:27:22 +00:00
|
|
|
resp_sep = '\n';
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-23 17:26:09 +00:00
|
|
|
if (cmd_entry->name != NULL)
|
|
|
|
{
|
2020-01-14 20:18:47 +00:00
|
|
|
fprintf(fout, "%s: error = %s\n", cmd_entry->name, rigerror(retcode));
|
2019-12-03 22:15:33 +00:00
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/* only for rotctld */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive && !prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/* netrotctl RIG_OK */
|
2019-08-29 13:27:22 +00:00
|
|
|
if (!(cmd_entry->flags & ARG_OUT) && !ext_resp)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2020-11-23 14:46:15 +00:00
|
|
|
rot_debug(RIG_DEBUG_TRACE, "%s: NETROTCTL_RET 0\n", __func__);
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, NETROTCTL_RET "0\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extended Response protocol */
|
2019-08-29 13:27:22 +00:00
|
|
|
else if (ext_resp && cmd != 0xf0)
|
2017-10-06 23:58:42 +00:00
|
|
|
{
|
2020-11-23 14:46:15 +00:00
|
|
|
rot_debug(RIG_DEBUG_TRACE, "%s: NETROTCTL_RET 0\n", __func__);
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, NETROTCTL_RET "0\n");
|
2019-08-29 13:27:22 +00:00
|
|
|
resp_sep = '\n';
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fflush(fout);
|
|
|
|
|
|
|
|
return retcode != RIG_OK ? 2 : 0;
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void version()
|
|
|
|
{
|
2021-03-20 03:56:18 +00:00
|
|
|
printf("rotctl(d), %s\n\n", hamlib_version2);
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("%s\n", hamlib_copyright);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
void usage_rot(FILE *fout)
|
|
|
|
{
|
2019-12-24 21:12:05 +00:00
|
|
|
int i;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
fprintf(fout, "Commands (some may not be available for this rotator):\n");
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
for (i = 0; test_list[i].cmd != 0; i++)
|
|
|
|
{
|
2019-12-24 21:12:05 +00:00
|
|
|
int nbspaces;
|
2017-10-06 23:58:42 +00:00
|
|
|
fprintf(fout,
|
|
|
|
"%c: %-12s(",
|
|
|
|
isprint(test_list[i].cmd) ? test_list[i].cmd : '?',
|
|
|
|
test_list[i].name);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
nbspaces = 16;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (test_list[i].arg1 && (test_list[i].flags & ARG_IN1))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
nbspaces -= fprintf(fout, "%s", test_list[i].arg1);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (test_list[i].arg2 && (test_list[i].flags & ARG_IN2))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
nbspaces -= fprintf(fout, ", %s", test_list[i].arg2);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (test_list[i].arg3 && (test_list[i].flags & ARG_IN3))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
nbspaces -= fprintf(fout, ", %s", test_list[i].arg3);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (test_list[i].arg4 && (test_list[i].flags & ARG_IN4))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
nbspaces -= fprintf(fout, ", %s", test_list[i].arg4);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, ")\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout,
|
|
|
|
"\n\nIn interactive mode prefix long command names with '\\', e.g. '\\dump_state'\n\n"
|
|
|
|
"The special command '-' is used to read further commands from standard input\n"
|
|
|
|
"Commands and arguments read from standard input must be white space separated,\n"
|
|
|
|
"comments are allowed, comments start with the # character and continue to the\n"
|
|
|
|
"end of the line.\n");
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
int print_conf_list(const struct confparams *cfp, rig_ptr_t data)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
ROT *rot = (ROT *) data;
|
|
|
|
int i;
|
|
|
|
char buf[128] = "";
|
|
|
|
|
|
|
|
rot_get_conf(rot, cfp->token, buf);
|
|
|
|
printf("%s: \"%s\"\n" "\tDefault: %s, Value: %s\n",
|
|
|
|
cfp->name,
|
|
|
|
cfp->tooltip,
|
|
|
|
cfp->dflt,
|
|
|
|
buf);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
switch (cfp->type)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
case RIG_CONF_NUMERIC:
|
|
|
|
printf("\tRange: %.1f..%.1f, step %.1f\n",
|
|
|
|
cfp->u.n.min,
|
|
|
|
cfp->u.n.max,
|
|
|
|
cfp->u.n.step);
|
|
|
|
break;
|
|
|
|
|
2020-03-10 22:00:44 +00:00
|
|
|
case RIG_CONF_CHECKBUTTON:
|
|
|
|
printf("\tCheckbox: 0,1\n");
|
|
|
|
break;
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
case RIG_CONF_COMBO:
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!cfp->u.c.combostr[0])
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\tCombo: %s", cfp->u.c.combostr[0]);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
printf(", %s", cfp->u.c.combostr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
break;
|
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
default:
|
2017-08-09 18:09:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return 1; /* != 0, we want them all ! */
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
static int hash_model_list(const struct rot_caps *caps, void *data)
|
2008-09-12 22:55:10 +00:00
|
|
|
{
|
2012-02-13 20:29:35 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
hash_add_model(caps->rot_model,
|
|
|
|
caps->mfg_name,
|
|
|
|
caps->model_name,
|
|
|
|
caps->version,
|
2020-03-06 05:48:14 +00:00
|
|
|
rig_strstatus(caps->status),
|
|
|
|
caps->macro_name);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
return 1; /* !=0, we want them all ! */
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2012-02-13 20:29:35 +00:00
|
|
|
void print_model_list()
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
struct mod_lst *s;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
for (s = models; s != NULL; s = (struct mod_lst *)(s->hh.next))
|
|
|
|
{
|
2020-03-06 05:48:14 +00:00
|
|
|
printf("%6d %-23s%-24s%-16s%-14s%s\n",
|
2017-08-09 18:09:55 +00:00
|
|
|
s->id,
|
|
|
|
s->mfg_name,
|
|
|
|
s->model_name,
|
|
|
|
s->version,
|
2020-03-06 05:48:14 +00:00
|
|
|
s->status,
|
|
|
|
s->macro_name);
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
2012-02-13 20:29:35 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2008-09-12 22:55:10 +00:00
|
|
|
void list_models()
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int status;
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
rot_load_all_backends();
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2020-03-06 05:48:14 +00:00
|
|
|
printf(" Rot # Mfg Model Version Status Macro\n");
|
2017-08-09 18:09:55 +00:00
|
|
|
status = rot_list_foreach(hash_model_list, NULL);
|
2012-02-13 20:29:35 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
printf("rot_list_foreach: error = %s \n", rigerror(status));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
hash_sort_by_model_id();
|
|
|
|
print_model_list();
|
|
|
|
hash_delete_all();
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int set_conf(ROT *my_rot, char *conf_parms)
|
|
|
|
{
|
2019-12-24 21:12:05 +00:00
|
|
|
char *p;
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
|
2017-08-09 18:09:55 +00:00
|
|
|
p = conf_parms;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
while (p && *p != '\0')
|
|
|
|
{
|
2019-12-24 21:12:05 +00:00
|
|
|
int ret;
|
|
|
|
char *q, *n = NULL;
|
2017-08-09 18:09:55 +00:00
|
|
|
/* FIXME: left hand value of = cannot be null */
|
|
|
|
q = strchr(p, '=');
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!q)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return RIG_EINVAL;
|
2020-03-10 13:43:42 +00:00
|
|
|
}
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2020-03-10 13:43:42 +00:00
|
|
|
*q++ = '\0';
|
|
|
|
n = strchr(q, ',');
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2020-03-10 13:43:42 +00:00
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
*n++ = '\0';
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: token=%s, val=%s\n", __func__, p, q);
|
2017-08-09 18:09:55 +00:00
|
|
|
ret = rot_set_conf(my_rot, rot_token_lookup(my_rot, p), q);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (ret != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* static int (f)(ROT *rot, int interactive, const void *arg1, const void *arg2, const void *arg3, const void *arg4)
|
|
|
|
*/
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'P' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(set_position)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
azimuth_t az;
|
|
|
|
elevation_t el;
|
2020-11-14 07:56:37 +00:00
|
|
|
char *comma_pos;
|
|
|
|
|
|
|
|
/* Fixing args with an invalid decimal separator. */
|
|
|
|
comma_pos = strchr(arg1, ',');
|
|
|
|
|
|
|
|
if (comma_pos)
|
|
|
|
{
|
|
|
|
*comma_pos = '.';
|
|
|
|
}
|
|
|
|
|
|
|
|
comma_pos = strchr(arg2, ',');
|
|
|
|
|
|
|
|
if (comma_pos)
|
|
|
|
{
|
|
|
|
*comma_pos = '.';
|
|
|
|
}
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%f", &az));
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%f", &el));
|
2020-12-03 19:40:34 +00:00
|
|
|
return rot_set_position(rot, az, el);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'p' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(get_position)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int status;
|
|
|
|
azimuth_t az;
|
|
|
|
elevation_t el;
|
|
|
|
|
|
|
|
status = rot_get_position(rot, &az, &el);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg1);
|
|
|
|
}
|
|
|
|
|
2019-11-24 05:11:27 +00:00
|
|
|
fprintf(fout, "%.2f%c", az, resp_sep);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
2019-11-24 05:11:27 +00:00
|
|
|
fprintf(fout, "%.2f%c", el, resp_sep);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
return status;
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'S' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(stop)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return rot_stop(rot);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'K' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(park)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return rot_park(rot);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'R' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(reset)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
rot_reset_t reset;
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%d", &reset));
|
|
|
|
return rot_reset(rot, reset);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* '_' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(get_info)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
const char *s;
|
|
|
|
|
|
|
|
s = rot_get_info(rot);
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg1);
|
|
|
|
}
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s%c", s ? s : "None", resp_sep);
|
|
|
|
|
2020-12-03 19:40:34 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 's' */
|
|
|
|
declare_proto_rot(get_status)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
rot_status_t status;
|
|
|
|
char s[SPRINTF_MAX_SIZE];
|
|
|
|
|
|
|
|
result = rot_get_status(rot, &status);
|
|
|
|
|
|
|
|
if (result != RIG_OK)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
|
|
|
fprintf(fout, "%s: ", cmd->arg1);
|
|
|
|
}
|
|
|
|
|
2021-03-03 14:03:18 +00:00
|
|
|
rot_sprintf_status(s, sizeof(s), status);
|
2020-12-03 19:40:34 +00:00
|
|
|
fprintf(fout, "%s%c", s, resp_sep);
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return RIG_OK;
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'M' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(move)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int direction;
|
|
|
|
int speed;
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!strcmp(arg1, "LEFT") || !strcmp(arg1, "CCW"))
|
|
|
|
{
|
2010-04-25 17:29:53 +00:00
|
|
|
direction = ROT_MOVE_LEFT;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(arg1, "RIGHT") || !strcmp(arg1, "CW"))
|
|
|
|
{
|
2010-04-25 17:29:53 +00:00
|
|
|
direction = ROT_MOVE_RIGHT;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(arg1, "UP"))
|
|
|
|
{
|
2010-04-25 17:29:53 +00:00
|
|
|
direction = ROT_MOVE_UP;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else if (!strcmp(arg1, "DOWN"))
|
|
|
|
{
|
2010-04-25 17:29:53 +00:00
|
|
|
direction = ROT_MOVE_DOWN;
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%d", &direction));
|
|
|
|
}
|
2010-04-25 17:29:53 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &speed));
|
|
|
|
return rot_move(rot, direction, speed);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2020-11-24 19:51:10 +00:00
|
|
|
/*
|
|
|
|
* 'V'
|
|
|
|
*/
|
|
|
|
declare_proto_rot(set_level)
|
|
|
|
{
|
|
|
|
setting_t level;
|
|
|
|
value_t val;
|
|
|
|
|
|
|
|
if (!strcmp(arg1, "?"))
|
|
|
|
{
|
|
|
|
char s[SPRINTF_MAX_SIZE];
|
2021-03-03 14:03:18 +00:00
|
|
|
rot_sprintf_level(s, sizeof(s), rot->state.has_set_level);
|
2020-11-24 19:51:10 +00:00
|
|
|
fputs(s, fout);
|
|
|
|
|
|
|
|
if (rot->caps->set_ext_level)
|
|
|
|
{
|
2021-03-03 14:03:18 +00:00
|
|
|
sprintf_level_ext(s, sizeof(s), rot->caps->extlevels);
|
2020-11-24 19:51:10 +00:00
|
|
|
fputs(s, fout);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('\n', fout);
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = rot_parse_level(arg1);
|
|
|
|
|
|
|
|
if (!rot_has_set_level(rot, level))
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
cfp = rot_ext_lookup(rot, arg1);
|
|
|
|
|
|
|
|
if (!cfp)
|
|
|
|
{
|
|
|
|
return -RIG_ENAVAIL; /* no such parameter */
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cfp->type)
|
|
|
|
{
|
|
|
|
case RIG_CONF_BUTTON:
|
|
|
|
/* arg is ignored */
|
|
|
|
val.i = 0; // avoid passing uninitialized data
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_CHECKBUTTON:
|
|
|
|
case RIG_CONF_COMBO:
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_NUMERIC:
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_STRING:
|
|
|
|
val.cs = arg2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_ECONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rot_set_ext_level(rot, cfp->token, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ROT_LEVEL_IS_FLOAT(level))
|
|
|
|
{
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return rot_set_level(rot, level, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 'v' */
|
|
|
|
declare_proto_rot(get_level)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
setting_t level;
|
|
|
|
value_t val;
|
|
|
|
|
|
|
|
if (!strcmp(arg1, "?"))
|
|
|
|
{
|
|
|
|
char s[SPRINTF_MAX_SIZE];
|
2021-03-03 14:03:18 +00:00
|
|
|
rot_sprintf_level(s, sizeof(s), rot->state.has_get_level);
|
2020-11-24 19:51:10 +00:00
|
|
|
fputs(s, fout);
|
|
|
|
|
|
|
|
if (rot->caps->get_ext_level)
|
|
|
|
{
|
2021-03-03 14:03:18 +00:00
|
|
|
sprintf_level_ext(s, sizeof(s), rot->caps->extlevels);
|
2020-11-24 19:51:10 +00:00
|
|
|
fputs(s, fout);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('\n', fout);
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = rot_parse_level(arg1);
|
|
|
|
|
|
|
|
if (!rot_has_get_level(rot, level))
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
cfp = rot_ext_lookup(rot, arg1);
|
|
|
|
|
|
|
|
if (!cfp)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL; /* no such parameter */
|
|
|
|
}
|
|
|
|
|
|
|
|
status = rot_get_ext_level(rot, cfp->token, &val);
|
|
|
|
|
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive && prompt)
|
|
|
|
{
|
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cfp->type)
|
|
|
|
{
|
|
|
|
case RIG_CONF_BUTTON:
|
|
|
|
/* there's no sense in retrieving value of stateless button */
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
|
|
|
|
case RIG_CONF_CHECKBUTTON:
|
|
|
|
case RIG_CONF_COMBO:
|
|
|
|
fprintf(fout, "%d\n", val.i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_NUMERIC:
|
|
|
|
fprintf(fout, "%f\n", val.f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_STRING:
|
|
|
|
fprintf(fout, "%s\n", val.s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_ECONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = rot_get_level(rot, level, &val);
|
|
|
|
|
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive && prompt)
|
|
|
|
{
|
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ROT_LEVEL_IS_FLOAT(level))
|
|
|
|
{
|
|
|
|
fprintf(fout, "%f\n", val.f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(fout, "%d\n", val.i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 'U' */
|
|
|
|
declare_proto_rot(set_func)
|
|
|
|
{
|
|
|
|
setting_t func;
|
|
|
|
int func_stat;
|
|
|
|
|
|
|
|
if (!strcmp(arg1, "?"))
|
|
|
|
{
|
|
|
|
char s[SPRINTF_MAX_SIZE];
|
2021-03-03 14:03:18 +00:00
|
|
|
rot_sprintf_func(s, sizeof(s), rot->state.has_set_func);
|
2020-11-24 19:51:10 +00:00
|
|
|
fprintf(fout, "%s\n", s);
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
func = rot_parse_func(arg1);
|
|
|
|
|
|
|
|
if (!rot_has_set_func(rot, func))
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
cfp = rot_ext_lookup(rot, arg1);
|
|
|
|
|
|
|
|
if (!cfp)
|
|
|
|
{
|
|
|
|
return -RIG_ENAVAIL; /* no such parameter */
|
|
|
|
}
|
|
|
|
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &func_stat));
|
|
|
|
|
|
|
|
return rot_set_ext_func(rot, cfp->token, func_stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &func_stat));
|
|
|
|
return rot_set_func(rot, func, func_stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 'u' */
|
|
|
|
declare_proto_rot(get_func)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
setting_t func;
|
|
|
|
int func_stat;
|
|
|
|
|
|
|
|
if (!strcmp(arg1, "?"))
|
|
|
|
{
|
|
|
|
char s[SPRINTF_MAX_SIZE];
|
2021-03-03 14:03:18 +00:00
|
|
|
rot_sprintf_func(s, sizeof(s), rot->state.has_get_func);
|
2020-11-24 19:51:10 +00:00
|
|
|
fprintf(fout, "%s\n", s);
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
func = rot_parse_func(arg1);
|
|
|
|
|
|
|
|
if (!rot_has_get_func(rot, func))
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
cfp = rot_ext_lookup(rot, arg1);
|
|
|
|
|
|
|
|
if (!cfp)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL; /* no such parameter */
|
|
|
|
}
|
|
|
|
|
|
|
|
status = rot_get_ext_func(rot, cfp->token, &func_stat);
|
|
|
|
|
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive && prompt)
|
|
|
|
{
|
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d\n", func_stat);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = rot_get_func(rot, func, &func_stat);
|
|
|
|
|
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive && prompt)
|
|
|
|
{
|
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d\n", func_stat);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 'R' */
|
|
|
|
declare_proto_rot(set_parm)
|
|
|
|
{
|
|
|
|
setting_t parm;
|
|
|
|
value_t val;
|
|
|
|
|
|
|
|
if (!strcmp(arg1, "?"))
|
|
|
|
{
|
|
|
|
char s[SPRINTF_MAX_SIZE];
|
2021-03-03 14:03:18 +00:00
|
|
|
rot_sprintf_parm(s, sizeof(s), rot->state.has_set_parm);
|
2020-11-24 19:51:10 +00:00
|
|
|
fprintf(fout, "%s\n", s);
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
parm = rot_parse_parm(arg1);
|
|
|
|
|
|
|
|
if (!rot_has_set_parm(rot, parm))
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
cfp = rot_ext_lookup(rot, arg1);
|
|
|
|
|
|
|
|
if (!cfp)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL; /* no such parameter */
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cfp->type)
|
|
|
|
{
|
|
|
|
case RIG_CONF_BUTTON:
|
|
|
|
/* arg is ignored */
|
|
|
|
val.i = 0; // avoid passing uninitialized data
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_CHECKBUTTON:
|
|
|
|
case RIG_CONF_COMBO:
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_NUMERIC:
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_STRING:
|
|
|
|
val.cs = arg2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_BINARY:
|
|
|
|
val.b.d = (unsigned char *)arg2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_ECONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rot_set_ext_parm(rot, cfp->token, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ROT_PARM_IS_FLOAT(parm))
|
|
|
|
{
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return rot_set_parm(rot, parm, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 'r' */
|
|
|
|
declare_proto_rot(get_parm)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
setting_t parm;
|
|
|
|
value_t val;
|
|
|
|
char buffer[RIG_BIN_MAX];
|
|
|
|
|
|
|
|
if (!strcmp(arg1, "?"))
|
|
|
|
{
|
|
|
|
char s[SPRINTF_MAX_SIZE];
|
2021-03-03 14:03:18 +00:00
|
|
|
rot_sprintf_parm(s, sizeof(s), rot->state.has_get_parm);
|
2020-11-24 19:51:10 +00:00
|
|
|
fprintf(fout, "%s\n", s);
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
parm = rot_parse_parm(arg1);
|
|
|
|
|
|
|
|
if (!rot_has_get_parm(rot, parm))
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
cfp = rot_ext_lookup(rot, arg1);
|
|
|
|
|
|
|
|
if (!cfp)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL; /* no such parameter */
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cfp->type)
|
|
|
|
{
|
|
|
|
case RIG_CONF_STRING:
|
|
|
|
memset(buffer, '0', sizeof(buffer));
|
|
|
|
buffer[sizeof(buffer) - 1] = 0;
|
|
|
|
val.s = buffer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_BINARY:
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
val.b.d = (unsigned char *)buffer;
|
|
|
|
val.b.l = RIG_BIN_MAX;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = rot_get_ext_parm(rot, cfp->token, &val);
|
|
|
|
|
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive && prompt)
|
|
|
|
{
|
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cfp->type)
|
|
|
|
{
|
|
|
|
case RIG_CONF_BUTTON:
|
|
|
|
/* there's not sense in retrieving value of stateless button */
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
|
|
|
|
case RIG_CONF_CHECKBUTTON:
|
|
|
|
case RIG_CONF_COMBO:
|
|
|
|
fprintf(fout, "%d\n", val.i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_NUMERIC:
|
|
|
|
fprintf(fout, "%f\n", val.f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_STRING:
|
|
|
|
fprintf(fout, "%s\n", val.s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RIG_CONF_BINARY:
|
|
|
|
dump_hex((unsigned char *)buffer, val.b.l);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_ECONF;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = rot_get_parm(rot, parm, &val);
|
|
|
|
|
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive && prompt)
|
|
|
|
{
|
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ROT_PARM_IS_FLOAT(parm))
|
|
|
|
{
|
|
|
|
fprintf(fout, "%f\n", val.f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(fout, "%d\n", val.i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'C' */
|
2008-09-12 22:55:10 +00:00
|
|
|
declare_proto_rot(inter_set_conf)
|
|
|
|
{
|
2019-12-09 23:12:13 +00:00
|
|
|
char buf[256];
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__);
|
2008-09-12 22:55:10 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (!arg2 || arg2[0] == '\0')
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rot_debug(RIG_DEBUG_ERR, "%s: arg1=='%s', arg2=='%s'\n", __func__, arg1, arg2);
|
2019-11-24 05:11:27 +00:00
|
|
|
|
2010-04-25 17:29:53 +00:00
|
|
|
return -RIG_EINVAL;
|
2017-08-09 18:09:55 +00:00
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
sprintf(buf, "%s=%s", arg1, arg2);
|
2019-11-24 05:11:27 +00:00
|
|
|
return set_conf(rot, buf);
|
2008-09-12 22:55:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* '1' */
|
|
|
|
declare_proto_rot(dump_caps)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
dumpcaps_rot(rot, fout);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return RIG_OK;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* For rotctld internal use
|
|
|
|
* '0x8f'
|
|
|
|
*/
|
2008-09-21 19:27:54 +00:00
|
|
|
declare_proto_rot(dump_state)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
struct rot_state *rs = &rot->state;
|
2008-09-21 19:27:54 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
/*
|
|
|
|
* - Protocol version
|
|
|
|
*/
|
2008-09-21 19:27:54 +00:00
|
|
|
#define ROTCTLD_PROT_VER 0
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "rotctld Protocol Ver: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d%c", ROTCTLD_PROT_VER, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "Rotor Model: ");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d%c", rot->caps->rot_model, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "Minimum Azimuth: ");
|
|
|
|
}
|
|
|
|
|
2020-03-10 12:07:21 +00:00
|
|
|
fprintf(fout, "%lf%c", rs->min_az + rot->state.az_offset, resp_sep);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "Maximum Azimuth: ");
|
|
|
|
}
|
|
|
|
|
2020-03-10 12:07:21 +00:00
|
|
|
fprintf(fout, "%lf%c", rs->max_az + rot->state.az_offset, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "Minimum Elevation: ");
|
|
|
|
}
|
2008-09-21 19:27:54 +00:00
|
|
|
|
2020-03-10 12:07:21 +00:00
|
|
|
fprintf(fout, "%lf%c", rs->min_el + rot->state.el_offset, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "Maximum Elevation: ");
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2020-03-10 12:07:21 +00:00
|
|
|
fprintf(fout, "%lf%c", rs->max_el + rot->state.el_offset, resp_sep);
|
2008-09-21 19:27:54 +00:00
|
|
|
|
2019-11-24 05:11:27 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
|
|
|
fprintf(fout, "South Zero: ");
|
|
|
|
}
|
2019-11-30 16:19:08 +00:00
|
|
|
|
2019-11-24 05:11:27 +00:00
|
|
|
fprintf(fout, "%d%c", rs->south_zero, resp_sep);
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return RIG_OK;
|
2008-09-21 19:27:54 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2008-09-21 19:27:54 +00:00
|
|
|
/*
|
2017-08-09 18:09:55 +00:00
|
|
|
* Special debugging purpose send command display reply until there's a
|
|
|
|
* timeout.
|
2008-09-21 19:27:54 +00:00
|
|
|
*
|
|
|
|
* 'w'
|
|
|
|
*/
|
|
|
|
declare_proto_rot(send_cmd)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int retval;
|
|
|
|
struct rot_state *rs;
|
|
|
|
int backend_num, cmd_len;
|
2008-09-21 19:27:54 +00:00
|
|
|
#define BUFSZ 128
|
2017-08-09 18:09:55 +00:00
|
|
|
char bufcmd[BUFSZ];
|
|
|
|
char buf[BUFSZ];
|
|
|
|
char eom_buf[4] = { 0xa, 0xd, 0, 0 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* binary protocols enter values as \0xZZ\0xYY..
|
|
|
|
*
|
|
|
|
* Rem: no binary protocol for rotator as of now
|
|
|
|
*/
|
|
|
|
backend_num = ROT_BACKEND_NUM(rot->caps->rot_model);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (send_cmd_term == -1 || backend_num == -1)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
const char *p = arg1, *pp = NULL;
|
|
|
|
int i;
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
for (i = 0; i < BUFSZ - 1 && p != pp; i++)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
pp = p + 1;
|
|
|
|
bufcmd[i] = strtol(p + 1, (char **) &p, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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';
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/* text protocol */
|
|
|
|
strncpy(bufcmd, arg1, BUFSZ);
|
|
|
|
bufcmd[BUFSZ - 2] = '\0';
|
|
|
|
|
|
|
|
cmd_len = strlen(bufcmd);
|
|
|
|
|
|
|
|
/* Automatic termination char */
|
2017-10-06 23:58:42 +00:00
|
|
|
if (send_cmd_term != 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
bufcmd[cmd_len++] = send_cmd_term;
|
|
|
|
}
|
|
|
|
|
|
|
|
eom_buf[2] = send_cmd_term;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs = &rot->state;
|
|
|
|
|
2020-06-23 13:39:11 +00:00
|
|
|
rig_flush(&rs->rotport);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
|
|
|
retval = write_block(&rs->rotport, bufcmd, cmd_len);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retval != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (interactive && prompt)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
do
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
/*
|
|
|
|
* assumes CR or LF is end of line char
|
|
|
|
* for all ascii protocols
|
|
|
|
*/
|
2021-11-24 19:02:39 +00:00
|
|
|
retval = read_string(&rs->rotport, buf, BUFSZ, eom_buf, strlen(eom_buf), 0, 1);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retval < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retval < BUFSZ)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
buf[retval] = '\0';
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
buf[BUFSZ - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%s\n", buf);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
}
|
|
|
|
while (retval > 0);
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (retval > 0 || retval == -RIG_ETIMEOUT)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
retval = RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
2008-09-21 19:27:54 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'L' */
|
|
|
|
declare_proto_rot(lonlat2loc)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
unsigned char loc[MAXARGSZ + 1];
|
|
|
|
double lat, lon;
|
|
|
|
int err, pair;
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%lf", &lon));
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%lf", &lat));
|
|
|
|
CHKSCN1ARG(sscanf(arg3, "%d", &pair));
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
pair /= 2;
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
err = longlat2locator(lon, lat, (char *)&loc, pair);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return err;
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg4);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%s%c", loc, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return err;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'l' */
|
|
|
|
declare_proto_rot(loc2lonlat)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
unsigned char loc[MAXARGSZ + 1];
|
|
|
|
double lat, lon;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
CHKSCN1ARG(sscanf(arg1, "%s", (char *)&loc));
|
|
|
|
|
|
|
|
status = locator2longlat(&lon, &lat, (const char *)loc);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (status != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%f%c", lon, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg3);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%f%c", lat, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return status;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'D' */
|
|
|
|
declare_proto_rot(d_m_s2dec)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int deg, min, sw;
|
|
|
|
double sec, dec_deg;
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%d", °));
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%d", &min));
|
|
|
|
CHKSCN1ARG(sscanf(arg3, "%lf", &sec));
|
|
|
|
CHKSCN1ARG(sscanf(arg4, "%d", &sw));
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
dec_deg = dms2dec(deg, min, sec, sw);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg5);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%lf%c", dec_deg, resp_sep);
|
|
|
|
|
|
|
|
return RIG_OK;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'd' */
|
|
|
|
declare_proto_rot(dec2d_m_s)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int deg, min, sw, err;
|
|
|
|
double sec, dec_deg;
|
|
|
|
|
|
|
|
CHKSCN1ARG(sscanf(arg1, "%lf", &dec_deg));
|
|
|
|
|
|
|
|
err = dec2dms(dec_deg, °, &min, &sec, &sw);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d%c", deg, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg3);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d%c", min, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg4);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%lf%c", sec, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg5);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d%c", sw, resp_sep);
|
|
|
|
|
|
|
|
return err;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'E' */
|
|
|
|
declare_proto_rot(d_mm2dec)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int deg, sw;
|
|
|
|
double dec_deg, min;
|
|
|
|
|
|
|
|
CHKSCN1ARG(sscanf(arg1, "%d", °));
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%lf", &min));
|
|
|
|
CHKSCN1ARG(sscanf(arg3, "%d", &sw));
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2020-06-10 03:37:03 +00:00
|
|
|
dec_deg = dmmm2dec(deg, min, sw,
|
|
|
|
0.0); // we'll add real seconds when somebody asks for it
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg4);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%lf%c", dec_deg, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return RIG_OK;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'e' */
|
|
|
|
declare_proto_rot(dec2d_mm)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
int deg, sw, err;
|
|
|
|
double min, dec_deg;
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%lf", &dec_deg));
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
err = dec2dmmm(dec_deg, °, &min, &sw);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return err;
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%d%c", deg, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg3);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%lf%c", min, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg4);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fout, "%d%c", sw, resp_sep);
|
|
|
|
|
|
|
|
return err;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'B' */
|
|
|
|
declare_proto_rot(coord2qrb)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
double lon1, lat1, lon2, lat2, dist, az;
|
|
|
|
int err;
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%lf", &lon1));
|
|
|
|
CHKSCN1ARG(sscanf(arg2, "%lf", &lat1));
|
|
|
|
CHKSCN1ARG(sscanf(arg3, "%lf", &lon2));
|
|
|
|
CHKSCN1ARG(sscanf(arg4, "%lf", &lat2));
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
err = qrb(lon1, lat1, lon2, lat2, &dist, &az);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg5);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%lf%c", dist, resp_sep);
|
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg6);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%lf%c", az, resp_sep);
|
|
|
|
|
|
|
|
return err;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'A' */
|
|
|
|
declare_proto_rot(az_sp2az_lp)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
double az_sp, az_lp;
|
|
|
|
|
|
|
|
CHKSCN1ARG(sscanf(arg1, "%lf", &az_sp));
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
az_lp = azimuth_long_path(az_sp);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if (az_lp < 0)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%lf%c", az_lp, resp_sep);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
return RIG_OK;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2010-02-14 22:18:00 +00:00
|
|
|
/* 'a' */
|
|
|
|
declare_proto_rot(dist_sp2dist_lp)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
double dist_sp, dist_lp;
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
CHKSCN1ARG(sscanf(arg1, "%lf", &dist_sp));
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
dist_lp = distance_long_path(dist_sp);
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-10-06 23:58:42 +00:00
|
|
|
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%s: ", cmd->arg2);
|
|
|
|
}
|
2010-02-14 22:18:00 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
fprintf(fout, "%lf%c", dist_lp, resp_sep);
|
|
|
|
|
|
|
|
return RIG_OK;
|
2010-02-14 22:18:00 +00:00
|
|
|
}
|
2014-05-02 18:44:29 +00:00
|
|
|
|
2017-08-09 18:09:55 +00:00
|
|
|
|
2014-05-02 18:44:29 +00:00
|
|
|
/* '0x8c'--pause processing */
|
|
|
|
declare_proto_rot(pause)
|
|
|
|
{
|
2017-08-09 18:09:55 +00:00
|
|
|
unsigned seconds;
|
|
|
|
CHKSCN1ARG(sscanf(arg1, "%u", &seconds));
|
|
|
|
sleep(seconds);
|
|
|
|
return RIG_OK;
|
2014-05-02 18:44:29 +00:00
|
|
|
}
|