2008-09-21 19:34:16 +00:00
|
|
|
/*
|
|
|
|
* Hamlib Netrotctl backend - main file
|
2009-02-17 23:01:11 +00:00
|
|
|
* Copyright (c) 2001-2009 by Stephane Fillod
|
2008-09-21 19:34:16 +00:00
|
|
|
*
|
|
|
|
*
|
2011-08-20 23:37:17 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2008-09-21 19:34:16 +00:00
|
|
|
*
|
2011-08-20 23:37:17 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2008-09-21 19:34:16 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-08-20 23:37:17 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2008-09-21 19:34:16 +00:00
|
|
|
*
|
2011-08-20 23:37:17 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2008-09-21 19:34:16 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2011-08-20 23:37:17 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-09-21 19:34:16 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h> /* String function definitions */
|
|
|
|
#include <unistd.h> /* UNIX standard function definitions */
|
|
|
|
#include <math.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "hamlib/rotator.h"
|
|
|
|
#include "iofunc.h"
|
|
|
|
#include "misc.h"
|
2020-05-28 17:03:18 +00:00
|
|
|
#include "network.h"
|
|
|
|
#include "serial.h"
|
2008-09-21 19:34:16 +00:00
|
|
|
|
|
|
|
#include "rot_dummy.h"
|
|
|
|
|
|
|
|
#define CMD_MAX 32
|
|
|
|
#define BUF_MAX 64
|
2008-10-27 22:23:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function with protocol return code parsing
|
|
|
|
*/
|
|
|
|
static int netrotctl_transaction(ROT *rot, char *cmd, int len, char *buf)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret;
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2020-05-28 17:03:18 +00:00
|
|
|
/* flush anything in the read buffer before command is sent */
|
2020-06-23 13:27:45 +00:00
|
|
|
rig_flush(&rot->state.rotport);
|
2020-05-28 17:03:18 +00:00
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = write_block(&rot->state.rotport, (unsigned char *) cmd, len);
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret != RIG_OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1);
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!memcmp(buf, NETROTCTL_RET, strlen(NETROTCTL_RET)))
|
|
|
|
{
|
|
|
|
return atoi(buf + strlen(NETROTCTL_RET));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2008-10-27 22:23:36 +00:00
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
|
|
|
|
static int netrotctl_open(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
struct rot_state *rs = &rot->state;
|
|
|
|
int prot_ver;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "\\dump_state\n");
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
prot_ver = atoi(buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
#define ROTCTLD_PROT_VER 0
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (prot_ver < ROTCTLD_PROT_VER)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1);
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->min_az = atof(buf);
|
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1);
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rs->max_az = atof(buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1);
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rs->min_el = atof(buf);
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
2008-10-27 22:23:36 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rs->max_el = atof(buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netrotctl_close(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
/* clean signoff, no read back */
|
2021-12-18 21:49:45 +00:00
|
|
|
write_block(&rot->state.rotport, (unsigned char *) "q\n", 2);
|
2008-11-02 17:32:37 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netrotctl_set_position(ROT *rot, azimuth_t az, elevation_t el)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %f %f\n", __func__,
|
|
|
|
az, el);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "P %f %f\n", az, el);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netrotctl_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
len = sprintf(cmd, "p\n");
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
*az = atof(buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2021-12-18 21:49:45 +00:00
|
|
|
ret = read_string(&rot->state.rotport, (unsigned char *) buf, BUF_MAX, "\n", sizeof("\n"), 0, 1);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
*el = atof(buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int netrotctl_stop(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "S\n");
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int netrotctl_park(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "K\n");
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netrotctl_reset(ROT *rot, rot_reset_t reset)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "R %d\n", reset);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netrotctl_move(ROT *rot, int direction, int speed)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "M %d %d\n", direction, speed);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *netrotctl_get_info(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
static char buf[BUF_MAX];
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "_\n");
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = netrotctl_transaction(rot, cmd, len, buf);
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-09-21 19:34:16 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
buf [ret] = '\0';
|
|
|
|
|
|
|
|
return buf;
|
2008-09-21 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NET rotctl capabilities.
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct rot_caps netrotctl_caps =
|
|
|
|
{
|
2020-03-06 05:48:14 +00:00
|
|
|
ROT_MODEL(ROT_MODEL_NETROTCTL),
|
2019-11-30 16:19:08 +00:00
|
|
|
.model_name = "NET rotctl",
|
|
|
|
.mfg_name = "Hamlib",
|
2020-06-08 21:13:08 +00:00
|
|
|
.version = "20200528.0",
|
2019-11-30 16:19:08 +00:00
|
|
|
.copyright = "LGPL",
|
2020-06-08 21:13:08 +00:00
|
|
|
.status = RIG_STATUS_STABLE,
|
2019-11-30 16:19:08 +00:00
|
|
|
.rot_type = ROT_TYPE_OTHER,
|
|
|
|
.port_type = RIG_PORT_NETWORK,
|
|
|
|
.timeout = 2000,
|
|
|
|
.retry = 3,
|
|
|
|
|
|
|
|
.min_az = -180.,
|
|
|
|
.max_az = 180.,
|
|
|
|
.min_el = 0.,
|
|
|
|
.max_el = 90.,
|
|
|
|
|
|
|
|
.priv = NULL, /* priv */
|
|
|
|
|
|
|
|
/* .rot_init = netrotctl_init, */
|
|
|
|
/* .rot_cleanup = netrotctl_cleanup, */
|
|
|
|
.rot_open = netrotctl_open,
|
|
|
|
.rot_close = netrotctl_close,
|
|
|
|
|
|
|
|
.set_position = netrotctl_set_position,
|
|
|
|
.get_position = netrotctl_get_position,
|
|
|
|
.park = netrotctl_park,
|
|
|
|
.stop = netrotctl_stop,
|
|
|
|
.reset = netrotctl_reset,
|
|
|
|
.move = netrotctl_move,
|
|
|
|
|
|
|
|
.get_info = netrotctl_get_info,
|
2008-09-21 19:34:16 +00:00
|
|
|
};
|
|
|
|
|