2001-12-28 20:34:30 +00:00
|
|
|
/*
|
|
|
|
* Hamlib Dummy backend - main file
|
2009-02-18 20:56:45 +00:00
|
|
|
* Copyright (c) 2001-2009 by Stephane Fillod
|
2001-12-28 20:34:30 +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.
|
2001-12-28 20:34:30 +00:00
|
|
|
*
|
2011-08-20 23:37:17 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2001-12-28 20:34:30 +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.
|
2001-12-28 20:34:30 +00:00
|
|
|
*
|
2011-08-20 23:37:17 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2001-12-28 20:34:30 +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
|
2001-12-28 20:34:30 +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>
|
2009-02-18 20:56:45 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <time.h>
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2003-04-07 22:42:11 +00:00
|
|
|
#include "hamlib/rotator.h"
|
|
|
|
#include "serial.h"
|
|
|
|
#include "misc.h"
|
2003-04-16 22:30:43 +00:00
|
|
|
#include "register.h"
|
2001-12-28 20:34:30 +00:00
|
|
|
|
|
|
|
#include "rot_dummy.h"
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
struct dummy_rot_priv_data
|
|
|
|
{
|
|
|
|
azimuth_t az;
|
|
|
|
elevation_t el;
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
struct timeval tv; /* time last az/el update */
|
|
|
|
azimuth_t target_az;
|
|
|
|
elevation_t target_el;
|
2001-12-28 20:34:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int dummy_rot_init(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct dummy_rot_priv_data *priv;
|
|
|
|
|
|
|
|
priv = (struct dummy_rot_priv_data *)
|
|
|
|
malloc(sizeof(struct dummy_rot_priv_data));
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!priv)
|
|
|
|
{
|
|
|
|
return -RIG_ENOMEM;
|
|
|
|
}
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot->state.priv = (void *)priv;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
rot->state.rotport.type.rig = RIG_PORT_NONE;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->az = priv->el = 0;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->target_az = priv->target_el = 0;
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dummy_rot_cleanup(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (rot->state.priv)
|
|
|
|
{
|
|
|
|
free(rot->state.priv);
|
|
|
|
}
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot->state.priv = NULL;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dummy_rot_open(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dummy_rot_close(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dummy_rot_set_position(ROT *rot, azimuth_t az, elevation_t el)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)
|
|
|
|
rot->state.priv;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %.2f %.2f\n", __func__,
|
|
|
|
az, el);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->target_az = az;
|
|
|
|
priv->target_el = el;
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
gettimeofday(&priv->tv, NULL);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-18 20:56:45 +00:00
|
|
|
/*
|
|
|
|
* Get position of rotor, simulating slow rotation
|
|
|
|
*/
|
2001-12-28 20:34:30 +00:00
|
|
|
static int dummy_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)
|
|
|
|
rot->state.priv;
|
|
|
|
struct timeval tv;
|
|
|
|
unsigned elapsed; /* ms */
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (priv->az == priv->target_az &&
|
|
|
|
priv->el == priv->target_el)
|
|
|
|
{
|
|
|
|
*az = priv->az;
|
|
|
|
*el = priv->el;
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
gettimeofday(&tv, NULL);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
elapsed = (tv.tv_sec - priv->tv.tv_sec) * 1000 +
|
|
|
|
(tv.tv_usec - priv->tv.tv_usec) / 1000;
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
/*
|
|
|
|
* Simulate rotation speed of 360 deg per minute
|
|
|
|
*/
|
2009-02-18 20:56:45 +00:00
|
|
|
#define DEG_PER_MS (360./60/1000)
|
2019-11-30 16:19:08 +00:00
|
|
|
|
|
|
|
if (fabs(priv->target_az - priv->az) / DEG_PER_MS <= elapsed)
|
|
|
|
{
|
|
|
|
/* target reached */
|
|
|
|
priv->az = priv->target_az;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (priv->az < priv->target_az)
|
|
|
|
{
|
|
|
|
priv->az += (azimuth_t)elapsed * DEG_PER_MS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->az -= (azimuth_t)elapsed * DEG_PER_MS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fabs(priv->target_el - priv->el) / DEG_PER_MS <= elapsed)
|
|
|
|
{
|
|
|
|
/* target reached */
|
|
|
|
priv->el = priv->target_el;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (priv->el < priv->target_el)
|
|
|
|
{
|
|
|
|
priv->el += (elevation_t)elapsed * DEG_PER_MS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->el -= (elevation_t)elapsed * DEG_PER_MS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*az = priv->az;
|
|
|
|
*el = priv->el;
|
|
|
|
|
|
|
|
priv->tv = tv;
|
|
|
|
|
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dummy_rot_stop(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)
|
|
|
|
rot->state.priv;
|
|
|
|
azimuth_t az;
|
|
|
|
elevation_t el;
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
dummy_rot_get_position(rot, &az, &el);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->target_az = priv->az = az;
|
|
|
|
priv->target_el = priv->el = el;
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int dummy_rot_park(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
/* Assume home is 0,0 */
|
|
|
|
dummy_rot_set_position(rot, 0, 0);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dummy_rot_reset(ROT *rot, rot_reset_t reset)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
2002-01-16 16:52:33 +00:00
|
|
|
static int dummy_rot_move(ROT *rot, int direction, int speed)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)
|
|
|
|
rot->state.priv;
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: Direction = %d, Speed = %d\n", __func__,
|
|
|
|
direction, speed);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case ROT_MOVE_UP:
|
|
|
|
return dummy_rot_set_position(rot, priv->target_az, 90);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case ROT_MOVE_DOWN:
|
|
|
|
return dummy_rot_set_position(rot, priv->target_az, 0);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case ROT_MOVE_CCW:
|
|
|
|
return dummy_rot_set_position(rot, -180, priv->target_el);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
case ROT_MOVE_CW:
|
|
|
|
return dummy_rot_set_position(rot, 180, priv->target_el);
|
2009-02-18 20:56:45 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2002-01-16 16:52:33 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2002-01-16 16:52:33 +00:00
|
|
|
}
|
2001-12-28 20:34:30 +00:00
|
|
|
|
|
|
|
static const char *dummy_rot_get_info(ROT *rot)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return "Dummy rotator";
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dummy rotator capabilities.
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct rot_caps dummy_rot_caps =
|
|
|
|
{
|
|
|
|
.rot_model = ROT_MODEL_DUMMY,
|
|
|
|
.model_name = "Dummy",
|
|
|
|
.mfg_name = "Hamlib",
|
|
|
|
.version = "0.2",
|
|
|
|
.copyright = "LGPL",
|
|
|
|
.status = RIG_STATUS_BETA,
|
|
|
|
.rot_type = ROT_TYPE_AZEL,
|
|
|
|
.port_type = RIG_PORT_NONE,
|
|
|
|
|
|
|
|
.min_az = -180.,
|
|
|
|
.max_az = 180.,
|
|
|
|
.min_el = 0.,
|
|
|
|
.max_el = 90.,
|
|
|
|
|
|
|
|
.priv = NULL, /* priv */
|
|
|
|
|
|
|
|
.rot_init = dummy_rot_init,
|
|
|
|
.rot_cleanup = dummy_rot_cleanup,
|
|
|
|
.rot_open = dummy_rot_open,
|
|
|
|
.rot_close = dummy_rot_close,
|
|
|
|
|
|
|
|
.set_position = dummy_rot_set_position,
|
|
|
|
.get_position = dummy_rot_get_position,
|
|
|
|
.park = dummy_rot_park,
|
|
|
|
.stop = dummy_rot_stop,
|
|
|
|
.reset = dummy_rot_reset,
|
|
|
|
.move = dummy_rot_move,
|
|
|
|
|
|
|
|
.get_info = dummy_rot_get_info,
|
2001-12-28 20:34:30 +00:00
|
|
|
};
|
|
|
|
|
2003-04-16 22:30:43 +00:00
|
|
|
DECLARE_INITROT_BACKEND(dummy)
|
2001-12-28 20:34:30 +00:00
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: _init called\n", __func__);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot_register(&dummy_rot_caps);
|
|
|
|
rot_register(&netrotctl_caps);
|
2001-12-28 20:34:30 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2001-12-28 20:34:30 +00:00
|
|
|
}
|