kopia lustrzana https://github.com/Hamlib/Hamlib
emulate rotator slowly rotating
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2640 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.9
rodzic
53b4c788b0
commit
f209f2757b
|
@ -2,6 +2,7 @@
|
||||||
lib_LTLIBRARIES = hamlib-dummy.la
|
lib_LTLIBRARIES = hamlib-dummy.la
|
||||||
hamlib_dummy_la_SOURCES = dummy.c rot_dummy.c netrigctl.c netrotctl.c
|
hamlib_dummy_la_SOURCES = dummy.c rot_dummy.c netrigctl.c netrotctl.c
|
||||||
hamlib_dummy_la_LDFLAGS = -no-undefined -module -avoid-version
|
hamlib_dummy_la_LDFLAGS = -no-undefined -module -avoid-version
|
||||||
hamlib_dummy_la_LIBADD = $(top_builddir)/src/libhamlib.la
|
hamlib_dummy_la_LIBADD = $(top_builddir)/src/libhamlib.la \
|
||||||
|
@MATH_LIBS@
|
||||||
|
|
||||||
noinst_HEADERS = dummy.h rot_dummy.h
|
noinst_HEADERS = dummy.h rot_dummy.h
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Hamlib Dummy backend - main file
|
* Hamlib Dummy backend - main file
|
||||||
* Copyright (c) 2001-2008 by Stephane Fillod
|
* Copyright (c) 2001-2009 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: rot_dummy.c,v 1.7 2008-09-21 19:34:16 fillods Exp $
|
* $Id: rot_dummy.c,v 1.8 2009-02-18 20:56:36 fillods Exp $
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -28,6 +28,8 @@
|
||||||
#include <string.h> /* String function definitions */
|
#include <string.h> /* String function definitions */
|
||||||
#include <unistd.h> /* UNIX standard function definitions */
|
#include <unistd.h> /* UNIX standard function definitions */
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "hamlib/rotator.h"
|
#include "hamlib/rotator.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
@ -37,8 +39,12 @@
|
||||||
#include "rot_dummy.h"
|
#include "rot_dummy.h"
|
||||||
|
|
||||||
struct dummy_rot_priv_data {
|
struct dummy_rot_priv_data {
|
||||||
azimuth_t az;
|
azimuth_t az;
|
||||||
elevation_t el;
|
elevation_t el;
|
||||||
|
|
||||||
|
struct timeval tv; /* time last az/el update */
|
||||||
|
azimuth_t target_az;
|
||||||
|
elevation_t target_el;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,17 +60,19 @@ static int dummy_rot_init(ROT *rot)
|
||||||
return -RIG_ENOMEM;
|
return -RIG_ENOMEM;
|
||||||
rot->state.priv = (void*)priv;
|
rot->state.priv = (void*)priv;
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
rot->state.rotport.type.rig = RIG_PORT_NONE;
|
rot->state.rotport.type.rig = RIG_PORT_NONE;
|
||||||
|
|
||||||
priv->az = priv->el = 0;
|
priv->az = priv->el = 0;
|
||||||
|
|
||||||
|
priv->target_az = priv->target_el = 0;
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dummy_rot_cleanup(ROT *rot)
|
static int dummy_rot_cleanup(ROT *rot)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
if (rot->state.priv)
|
if (rot->state.priv)
|
||||||
free(rot->state.priv);
|
free(rot->state.priv);
|
||||||
|
@ -76,14 +84,14 @@ static int dummy_rot_cleanup(ROT *rot)
|
||||||
|
|
||||||
static int dummy_rot_open(ROT *rot)
|
static int dummy_rot_open(ROT *rot)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dummy_rot_close(ROT *rot)
|
static int dummy_rot_close(ROT *rot)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
@ -92,31 +100,93 @@ static int dummy_rot_set_position(ROT *rot, azimuth_t az, elevation_t el)
|
||||||
{
|
{
|
||||||
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %f %f\n", __FUNCTION__,
|
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %.2f %.2f\n", __func__,
|
||||||
az, el);
|
az, el);
|
||||||
priv->az = az;
|
|
||||||
priv->el = el;
|
priv->target_az = az;
|
||||||
|
priv->target_el = el;
|
||||||
|
|
||||||
|
gettimeofday(&priv->tv, NULL);
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get position of rotor, simulating slow rotation
|
||||||
|
*/
|
||||||
static int dummy_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
|
static int dummy_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
|
||||||
{
|
{
|
||||||
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
|
||||||
|
struct timeval tv;
|
||||||
|
unsigned elapsed; /* ms */
|
||||||
|
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
|
if (priv->az == priv->target_az &&
|
||||||
|
priv->el == priv->target_el)
|
||||||
|
{
|
||||||
|
*az = priv->az;
|
||||||
|
*el = priv->el;
|
||||||
|
return RIG_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
|
elapsed = (tv.tv_sec - priv->tv.tv_sec) * 1000 +
|
||||||
|
(tv.tv_usec - priv->tv.tv_usec) / 1000;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Simulate rotation speed of 360 deg per minute
|
||||||
|
*/
|
||||||
|
#define DEG_PER_MS (360./60/1000)
|
||||||
|
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;
|
*az = priv->az;
|
||||||
*el = priv->el;
|
*el = priv->el;
|
||||||
|
|
||||||
|
priv->tv = tv;
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int dummy_rot_stop(ROT *rot)
|
static int dummy_rot_stop(ROT *rot)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
|
||||||
|
azimuth_t az;
|
||||||
|
elevation_t el;
|
||||||
|
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
|
dummy_rot_get_position(rot, &az, &el);
|
||||||
|
|
||||||
|
priv->target_az = priv->az = az;
|
||||||
|
priv->target_el = priv->el = el;
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
@ -124,30 +194,52 @@ static int dummy_rot_stop(ROT *rot)
|
||||||
|
|
||||||
static int dummy_rot_park(ROT *rot)
|
static int dummy_rot_park(ROT *rot)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
|
/* Assume home is 0,0 */
|
||||||
|
dummy_rot_set_position(rot, 0, 0);
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dummy_rot_reset(ROT *rot, rot_reset_t reset)
|
static int dummy_rot_reset(ROT *rot, rot_reset_t reset)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dummy_rot_move(ROT *rot, int direction, int speed)
|
static int dummy_rot_move(ROT *rot, int direction, int speed)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
|
||||||
|
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
|
switch(direction) {
|
||||||
|
case ROT_MOVE_UP:
|
||||||
|
return dummy_rot_set_position(rot, priv->target_az, 90);
|
||||||
|
|
||||||
|
case ROT_MOVE_DOWN:
|
||||||
|
return dummy_rot_set_position(rot, priv->target_az, 0);
|
||||||
|
|
||||||
|
case ROT_MOVE_CCW:
|
||||||
|
return dummy_rot_set_position(rot, -180, priv->target_el);
|
||||||
|
|
||||||
|
case ROT_MOVE_CW:
|
||||||
|
return dummy_rot_set_position(rot, 180, priv->target_el);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return -RIG_EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *dummy_rot_get_info(ROT *rot)
|
static const char *dummy_rot_get_info(ROT *rot)
|
||||||
{
|
{
|
||||||
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __FUNCTION__);
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
||||||
|
|
||||||
return "";
|
return "Dummy rotator";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,9 +252,9 @@ const struct rot_caps dummy_rot_caps = {
|
||||||
.rot_model = ROT_MODEL_DUMMY,
|
.rot_model = ROT_MODEL_DUMMY,
|
||||||
.model_name = "Dummy",
|
.model_name = "Dummy",
|
||||||
.mfg_name = "Hamlib",
|
.mfg_name = "Hamlib",
|
||||||
.version = "0.1",
|
.version = "0.2",
|
||||||
.copyright = "LGPL",
|
.copyright = "LGPL",
|
||||||
.status = RIG_STATUS_ALPHA,
|
.status = RIG_STATUS_BETA,
|
||||||
.rot_type = ROT_TYPE_OTHER,
|
.rot_type = ROT_TYPE_OTHER,
|
||||||
.port_type = RIG_PORT_NONE,
|
.port_type = RIG_PORT_NONE,
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue