2013-07-12 14:24:02 +00:00
|
|
|
/*
|
|
|
|
* Hamlib Ether6 backend - main file
|
|
|
|
* Copyright (c) 2001-2009 by Stephane Fillod
|
|
|
|
* Copyright (c) 2013 by Jonny Röker <Jonny.Roeker@t-online.de>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 <sys/time.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <hamlib/rotator.h>
|
|
|
|
#include "serial.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "register.h"
|
2020-12-03 21:07:08 +00:00
|
|
|
#include "idx_builtin.h"
|
2013-07-12 14:24:02 +00:00
|
|
|
|
|
|
|
#include "ether6.h"
|
|
|
|
|
|
|
|
#define CMD_MAX 32
|
|
|
|
#define BUF_MAX 64
|
|
|
|
|
2020-12-03 21:07:08 +00:00
|
|
|
#define ETHER_LEVELS ROT_LEVEL_SPEED
|
|
|
|
|
2013-07-12 14:24:02 +00:00
|
|
|
/*
|
|
|
|
* Helper function with protocol return code parsing
|
|
|
|
*/
|
|
|
|
static int ether_transaction(ROT *rot, char *cmd, int len, char *buf)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = write_block(&rot->state.rotport, cmd, len);
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "function %s(1): ret=%d || send=%s\n", __func__,
|
|
|
|
ret, cmd);
|
|
|
|
|
|
|
|
if (ret != RIG_OK)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = read_string(&rot->state.rotport, buf, BUF_MAX, "\n", sizeof("\n"));
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "function %s(2): ret=%d || receive=%s\n", __func__,
|
|
|
|
ret, buf);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!memcmp(buf, ROTORCTL_RET, strlen(ROTORCTL_RET)))
|
|
|
|
{
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "function %s(2a): receive=%s\n", __func__, buf);
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!memcmp(buf, NETROTCTL_RET, strlen(NETROTCTL_RET)))
|
|
|
|
{
|
|
|
|
int rv = atoi(buf + strlen(NETROTCTL_RET));
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "function %s(2): ret=%d || receive=%d\n", __func__,
|
|
|
|
ret, rv);
|
|
|
|
return atoi(buf + strlen(NETROTCTL_RET));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ether_rot_open(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
int sval;
|
|
|
|
float min_az, max_az, min_el, max_el;
|
|
|
|
struct rot_state *rs = &rot->state;
|
|
|
|
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
/* elevation not need */
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "rotor state\n");
|
|
|
|
/*-180/180 0/90*/
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = ether_transaction(rot, cmd, len, buf);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
sval = sscanf(buf, "%f/%f %f/%f", &min_az, &max_az, &min_el, &max_el);
|
|
|
|
rs->min_az = min_az;
|
|
|
|
rs->max_az = max_az;
|
|
|
|
rs->min_el = min_el;
|
|
|
|
rs->max_el = max_el;
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "ret(%d)%f/%f %f/%f\n", sval, rs->min_az,
|
|
|
|
rs->max_az, rs->min_el, rs->max_el);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ether_rot_close(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
/* clean signoff, no read back */
|
|
|
|
write_block(&rot->state.rotport, "\n", 1);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ether_rot_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];
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %f %f\n", __func__,
|
|
|
|
az, el);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "rotor move %d %d\n", (int)az, (int)el);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = ether_transaction(rot, cmd, len, buf);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ether_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len, sval, speed, adv;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
2020-01-06 13:35:00 +00:00
|
|
|
char mv[5];
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
len = sprintf(cmd, "rotor status\n");
|
|
|
|
|
|
|
|
ret = ether_transaction(rot, cmd, len, buf);
|
|
|
|
|
|
|
|
if (ret <= 0)
|
|
|
|
{
|
|
|
|
return (ret < 0) ? ret : -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// example "hold,az=87,el=0,v=8,ad0=346"
|
|
|
|
sval = sscanf(buf, "%4s az=%f el=%f v=%d ad0=%d", mv, az, el, &speed, &adv);
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "az=%f el=%f mv=%s ad(az)=%d\n", *az, *el, mv,
|
|
|
|
adv);
|
|
|
|
|
|
|
|
if (sval == 5)
|
|
|
|
{
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stop the rotor
|
|
|
|
*/
|
|
|
|
static int ether_rot_stop(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "rotor stop\n");
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = ether_transaction(rot, cmd, len, buf);
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* park the rotor
|
|
|
|
*/
|
|
|
|
static int ether_rot_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__);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
len = sprintf(cmd, "rotor park\n");
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = ether_transaction(rot, cmd, len, buf);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ether_rot_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];
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
// orig len = sprintf(cmd, "R %d\n", reset);
|
|
|
|
len = sprintf(cmd, "reset\n");
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
ret = ether_transaction(rot, cmd, len, buf);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* call rotor cw or rotor ccw
|
|
|
|
* if direction value 0 turn cw and if direction value 1 turn ccw
|
|
|
|
*/
|
|
|
|
static int ether_rot_move(ROT *rot, int direction, int speed)
|
|
|
|
{
|
2020-11-24 19:51:10 +00:00
|
|
|
struct rot_state *rs = &rot->state;
|
2019-11-30 16:19:08 +00:00
|
|
|
int ret, len;
|
|
|
|
char cmd[CMD_MAX];
|
|
|
|
char buf[BUF_MAX];
|
2020-11-24 19:51:10 +00:00
|
|
|
int ether_speed;
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
2020-12-17 21:07:04 +00:00
|
|
|
if (speed == ROT_SPEED_NOCHANGE)
|
|
|
|
{
|
2020-11-24 19:51:10 +00:00
|
|
|
ether_speed = rs->current_speed;
|
2020-12-17 21:07:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-24 19:51:10 +00:00
|
|
|
if (speed < 1 || speed > 100)
|
|
|
|
{
|
2020-12-17 21:07:04 +00:00
|
|
|
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value (1-100)! (%d)\n", __func__,
|
|
|
|
speed);
|
2020-11-24 19:51:10 +00:00
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->current_speed = speed;
|
|
|
|
ether_speed = speed;
|
|
|
|
}
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (direction == 0)
|
|
|
|
{
|
2020-11-24 19:51:10 +00:00
|
|
|
len = sprintf(cmd, "rotor cw %d\n", ether_speed);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-24 19:51:10 +00:00
|
|
|
len = sprintf(cmd, "rotor ccw %d\n", ether_speed);
|
2019-11-30 16:19:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = ether_transaction(rot, cmd, len, buf);
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
return -RIG_EPROTO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 21:07:08 +00:00
|
|
|
static int ether_rot_get_level(ROT *rot, setting_t level, value_t *val)
|
|
|
|
{
|
|
|
|
struct rot_state *rs = &rot->state;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__, rot_strlevel(level));
|
|
|
|
|
2020-12-17 21:07:04 +00:00
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case ROT_LEVEL_SPEED:
|
|
|
|
val->i = rs->current_speed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_ENAVAIL;
|
2020-12-03 21:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int ether_rot_set_level(ROT *rot, setting_t level, value_t val)
|
|
|
|
{
|
|
|
|
struct rot_state *rs = &rot->state;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__, rot_strlevel(level));
|
|
|
|
|
2020-12-17 21:07:04 +00:00
|
|
|
switch (level)
|
|
|
|
{
|
|
|
|
case ROT_LEVEL_SPEED:
|
|
|
|
{
|
|
|
|
int speed = val.i;
|
|
|
|
|
|
|
|
if (speed < 1)
|
|
|
|
{
|
|
|
|
speed = 1;
|
|
|
|
}
|
|
|
|
else if (speed > 100)
|
|
|
|
{
|
|
|
|
speed = 100;
|
2020-12-03 21:07:08 +00:00
|
|
|
}
|
2020-12-17 21:07:04 +00:00
|
|
|
|
|
|
|
rs->current_speed = speed;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_ENAVAIL;
|
2020-12-03 21:07:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-07-12 14:24:02 +00:00
|
|
|
static const char *ether_rot_get_info(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return "ip rotator via ethersex";
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 21:07:08 +00:00
|
|
|
static int ether_rot_init(ROT *rot)
|
|
|
|
{
|
|
|
|
struct rot_state *rs = &rot->state;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
// Set default speed to half of maximum
|
|
|
|
rs->current_speed = 00;
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:24:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy rotator capabilities.
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct rot_caps ether6_rot_caps =
|
|
|
|
{
|
2020-03-06 05:48:14 +00:00
|
|
|
ROT_MODEL(ROT_MODEL_ETHER6),
|
2019-11-30 16:19:08 +00:00
|
|
|
.model_name = "Ether6 (via ethernet)",
|
|
|
|
.mfg_name = "DG9OAA",
|
2020-12-03 21:07:08 +00:00
|
|
|
.version = "20201203.0",
|
2019-11-30 16:19:08 +00:00
|
|
|
.copyright = "LGPL",
|
|
|
|
.status = RIG_STATUS_BETA,
|
|
|
|
.rot_type = ROT_FLAG_AZIMUTH,
|
|
|
|
.port_type = RIG_PORT_NETWORK,
|
|
|
|
.timeout = 5000,
|
|
|
|
.retry = 3,
|
|
|
|
|
|
|
|
.min_az = 0.,
|
|
|
|
.max_az = 360,
|
|
|
|
.min_el = 0,
|
|
|
|
.max_el = 90,
|
|
|
|
|
|
|
|
.priv = NULL, /* priv */
|
|
|
|
|
2020-12-03 21:07:08 +00:00
|
|
|
.has_get_level = ETHER_LEVELS,
|
|
|
|
.has_set_level = ROT_LEVEL_SET(ETHER_LEVELS),
|
|
|
|
|
|
|
|
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 0 }, .max = { .i = 9999 }, .step = { .i = 1 } } },
|
|
|
|
|
|
|
|
.rot_init = ether_rot_init,
|
|
|
|
.rot_cleanup = NULL,
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
.rot_open = ether_rot_open,
|
|
|
|
.rot_close = ether_rot_close,
|
|
|
|
|
|
|
|
.set_position = ether_rot_set_position,
|
|
|
|
.get_position = ether_rot_get_position,
|
|
|
|
.park = ether_rot_park,
|
|
|
|
.stop = ether_rot_stop,
|
|
|
|
.reset = ether_rot_reset,
|
|
|
|
.move = ether_rot_move,
|
2020-12-03 21:07:08 +00:00
|
|
|
.get_level = ether_rot_get_level,
|
|
|
|
.set_level = ether_rot_set_level,
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
.get_info = ether_rot_get_info,
|
2013-07-12 14:24:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_INITROT_BACKEND(ether6)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: _init called\n", __func__);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot_register(ðer6_rot_caps);
|
2013-07-12 14:24:02 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2013-07-12 14:24:02 +00:00
|
|
|
}
|