emulate rotator slowly rotating

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2640 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.9
Stéphane Fillod, F8CFE 2009-02-18 20:56:45 +00:00
rodzic 53b4c788b0
commit f209f2757b
2 zmienionych plików z 115 dodań i 22 usunięć

Wyświetl plik

@ -2,6 +2,7 @@
lib_LTLIBRARIES = hamlib-dummy.la
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_LIBADD = $(top_builddir)/src/libhamlib.la
hamlib_dummy_la_LIBADD = $(top_builddir)/src/libhamlib.la \
@MATH_LIBS@
noinst_HEADERS = dummy.h rot_dummy.h

Wyświetl plik

@ -1,8 +1,8 @@
/*
* 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
* it under the terms of the GNU Library General Public License as
@ -28,6 +28,8 @@
#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"
@ -37,8 +39,12 @@
#include "rot_dummy.h"
struct dummy_rot_priv_data {
azimuth_t az;
elevation_t el;
azimuth_t az;
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;
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;
priv->az = priv->el = 0;
priv->target_az = priv->target_el = 0;
return RIG_OK;
}
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)
free(rot->state.priv);
@ -76,14 +84,14 @@ static int dummy_rot_cleanup(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;
}
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;
}
@ -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;
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %f %f\n", __FUNCTION__,
rig_debug(RIG_DEBUG_VERBOSE,"%s called: %.2f %.2f\n", __func__,
az, el);
priv->az = az;
priv->el = el;
priv->target_az = az;
priv->target_el = el;
gettimeofday(&priv->tv, NULL);
return RIG_OK;
}
/*
* Get position of rotor, simulating slow rotation
*/
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 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;
*el = priv->el;
priv->tv = tv;
return RIG_OK;
}
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;
}
@ -124,30 +194,52 @@ static int dummy_rot_stop(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;
}
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;
}
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;
}
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,
.model_name = "Dummy",
.mfg_name = "Hamlib",
.version = "0.1",
.copyright = "LGPL",
.status = RIG_STATUS_ALPHA,
.version = "0.2",
.copyright = "LGPL",
.status = RIG_STATUS_BETA,
.rot_type = ROT_TYPE_OTHER,
.port_type = RIG_PORT_NONE,