Merge pull request #453 from mikaelnousiainen/rotator-speed-control-and-status

Rotator API: Add funcs/levels/parms, implement speed control, add status flags
pull/457/head
Michael Black 2020-12-03 16:13:18 -06:00 zatwierdzone przez GitHub
commit 1f7ad94438
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
36 zmienionych plików z 3978 dodań i 317 usunięć

Wyświetl plik

@ -388,11 +388,10 @@ is an integer or keyword defined as \(oq2\(cq = UP, \(oq4\(cq = DOWN, \(oq8\(cq
and \(oq16\(cq = RIGHT or CW
.IP
.RI \(aq Speed \(aq
is an integer between 1 and 100.
is an integer between 1 and 100. Use -1 for no change to current speed.
.IP
.BR Note :
Not all backends that implement the move command use the Speed value. At this
time only the gs232a utilizes the Speed parameter.
Not all backends that implement the move command use the Speed value.
.
.TP
.BR S ", " stop

Wyświetl plik

@ -326,11 +326,10 @@ is an integer defined as \(oq2\(cq = Up, \(oq4\(cq = Down, \(oq8\(cq = Left,
and \(oq16\(cq = Right.
.IP
.RI \(aq Speed \(aq
is an integer between 1 and 100.
is an integer between 1 and 100. Use -1 for no change to current speed.
.IP
.BR Note :
Not all backends that implement the move command use the Speed value. At this
time only the gs232a utilizes the Speed parameter.
Not all backends that implement the move command use the Speed value.
.
.TP
.BR S ", " stop

Wyświetl plik

@ -397,6 +397,10 @@ extern HAMLIB_EXPORT(const char *) amp_strlevel(setting_t);
extern HAMLIB_EXPORT(const struct confparams *)
rig_ext_lookup HAMLIB_PARAMS((RIG *rig,
const char *name));
extern HAMLIB_EXPORT(setting_t) amp_parse_level(const char *s);
extern HAMLIB_EXPORT(const char *) amp_strlevel(setting_t);
//! @endcond

Wyświetl plik

@ -996,11 +996,11 @@ typedef uint64_t setting_t;
/*
* The C standard dictates that an enum constant is a 32 bit signed integer.
* Setting a constant's bit 31 created a negative value that on amd64 had the
* upper 32 bits set as well when assigned to the misc.c:func_str structure.
* upper 32 bits set as well when assigned to the misc.c:rig_func_str structure.
* This caused misc.c:rig_strfunc() to fail its comparison for RIG_FUNC_XIT
* on amd64 (x86_64). To use bit 31 as an unsigned long, preprocessor macros
* have been used instead as a 'const unsigned long' which cannot be used to
* initialize the func_str.func members. TNX KA6MAL, AC6SL. - N0NB
* initialize the rig_func_str.func members. TNX KA6MAL, AC6SL. - N0NB
*/
#define RIG_FUNC_NONE 0 /*!< '' -- No Function */
#define RIG_FUNC_FAGC CONSTANT_64BIT_FLAG (0) /*!< \c FAGC -- Fast AGC */
@ -2781,7 +2781,6 @@ extern HAMLIB_EXPORT(rmode_t) rig_parse_mode(const char *s);
extern HAMLIB_EXPORT(vfo_t) rig_parse_vfo(const char *s);
extern HAMLIB_EXPORT(setting_t) rig_parse_func(const char *s);
extern HAMLIB_EXPORT(setting_t) rig_parse_level(const char *s);
extern HAMLIB_EXPORT(setting_t) amp_parse_level(const char *s);
extern HAMLIB_EXPORT(setting_t) rig_parse_parm(const char *s);
extern HAMLIB_EXPORT(vfo_op_t) rig_parse_vfo_op(const char *s);
extern HAMLIB_EXPORT(scan_t) rig_parse_scan(const char *s);

Wyświetl plik

@ -196,6 +196,101 @@ typedef enum {
#define ROT_MOVE_CW ROT_MOVE_RIGHT
/**
* \brief Rotator status flags
*/
typedef enum {
ROT_STATUS_NONE = 0,
ROT_STATUS_BUSY = (1 << 0), /*!< Rotator is busy, not accepting commands */
ROT_STATUS_MOVING = (1 << 1), /*!< Rotator is currently moving (direction type not specified) */
ROT_STATUS_MOVING_AZ = (1 << 2), /*!< Azimuth rotator is currently moving (direction not specified) */
ROT_STATUS_MOVING_LEFT = (1 << 3), /*!< Azimuth rotator is currently moving left */
ROT_STATUS_MOVING_RIGHT = (1 << 4), /*!< Azimuth rotator is currently moving right */
ROT_STATUS_MOVING_EL = (1 << 5), /*!< Elevation rotator is currently moving (direction not specified) */
ROT_STATUS_MOVING_UP = (1 << 6), /*!< Elevation rotator is currently moving up */
ROT_STATUS_MOVING_DOWN = (1 << 7), /*!< Elevation rotator is currently moving down */
ROT_STATUS_LIMIT_UP = (1 << 8), /*!< The elevation rotator has reached its limit to move up */
ROT_STATUS_LIMIT_DOWN = (1 << 9), /*!< The elevation rotator has reached its limit to move down */
ROT_STATUS_LIMIT_LEFT = (1 << 10), /*!< The azimuth rotator has reached its limit to move left (CCW) */
ROT_STATUS_LIMIT_RIGHT = (1 << 11), /*!< The azimuth rotator has reached its limit to move right (CW) */
ROT_STATUS_OVERLAP_UP = (1 << 12), /*!< The elevation rotator has rotated up past 360 degrees */
ROT_STATUS_OVERLAP_DOWN = (1 << 13), /*!< The elevation rotator has rotated down past 0 degrees */
ROT_STATUS_OVERLAP_LEFT = (1 << 14), /*!< The azimuth rotator has rotated left (CCW) past 0 degrees */
ROT_STATUS_OVERLAP_RIGHT = (1 << 16), /*!< The azimuth rotator has rotated right (CW) past 360 degrees */
} rot_status_t;
#define ROT_STATUS_N(n) (1u<<(n))
/**
* \brief Macro for not changing the rotator speed with move() function
*/
#define ROT_SPEED_NOCHANGE (-1)
/**
* \brief Rotator Level Settings
*
* Various operating levels supported by a rotator.\n
* \c STRING used in rotctl
*
* \sa rot_parse_level(), rot_strlevel()
*/
enum rot_level_e {
ROT_LEVEL_NONE = 0, /*!< '' -- No Level */
ROT_LEVEL_SPEED = (1 << 0), /*!< \c SPEED -- Rotation speed, arg int (default range 1-100 if not specified) */
ROT_LEVEL_63 = CONSTANT_64BIT_FLAG(63), /*!< \c Future use, last level */
};
//! @cond Doxygen_Suppress
#define ROT_LEVEL_FLOAT_LIST (0)
#define ROT_LEVEL_READONLY_LIST (0)
#define ROT_LEVEL_IS_FLOAT(l) ((l)&ROT_LEVEL_FLOAT_LIST)
#define ROT_LEVEL_SET(l) ((l)&~ROT_LEVEL_READONLY_LIST)
//! @endcond
/**
* \brief Rotator Parameters
*
* Parameters are settings that are not related to core rotator functionality (= antenna rotation).\n
* \c STRING used in rotctl
*
* \sa rot_parse_parm(), rot_strparm()
*/
enum rot_parm_e {
ROT_PARM_NONE = 0, /*!< '' -- No Parm */
};
//! @cond Doxygen_Suppress
#define ROT_PARM_FLOAT_LIST (0)
#define ROT_PARM_READONLY_LIST (0)
#define ROT_PARM_IS_FLOAT(l) ((l)&ROT_PARM_FLOAT_LIST)
#define ROT_PARM_SET(l) ((l)&~ROT_PARM_READONLY_LIST)
//! @endcond
/**
* \brief Rotator Function Settings
*
* Various operating functions supported by a rotator.\n
* \c STRING used in rotctl/rotctld
*
* \sa rot_parse_func(), rot_strfunc()
*/
#define ROT_FUNC_NONE 0 /*!< '' -- No Function */
#ifndef SWIGLUAHIDE
/* Hide the top 32 bits from the old Lua binding as they can't be represented */
#define ROT_FUNC_BIT63 CONSTANT_64BIT_FLAG (63) /*!< \c available for future ROT_FUNC items */
/* 63 is this highest bit number that can be used */
#endif
/* Basic rot type, can store some useful info about different rotators. Each
* lib must be able to populate this structure, so we can make useful
* enquiries about capabilities.
@ -215,7 +310,7 @@ typedef enum {
* sharing the struct rot_caps of the backend, while keeping their own
* customized data.
*
* mdblack: Careful movinf fields around, as the backends depend on it when
* mdblack: Careful moving fields around, as the backends depend on it when
* initializing their caps in shared libraries and dlls.
*/
@ -243,7 +338,23 @@ struct rot_caps {
int post_write_delay; /*!< Post-write delay. */
int timeout; /*!< Timeout. */
int retry; /*!< Number of retry if command fails. */
setting_t has_get_func; /*!< List of get functions */
setting_t has_set_func; /*!< List of set functions */
setting_t has_get_level; /*!< List of get level */
setting_t has_set_level; /*!< List of set level */
setting_t has_get_parm; /*!< List of get parm */
setting_t has_set_parm; /*!< List of set parm */
rot_status_t has_status; /*!< Supported status flags */
gran_t level_gran[RIG_SETTING_MAX]; /*!< level granularity (i.e. steps) */
gran_t parm_gran[RIG_SETTING_MAX]; /*!< parm granularity (i.e. steps) */
const struct confparams *extparms; /*!< Extension parm list, \sa ext.c */
const struct confparams *extlevels; /*!< Extension level list, \sa ext.c */
const struct confparams *extfuncs; /*!< Extension func list, \sa ext.c */
int *ext_tokens; /*!< Extension token list */
/*
* Movement range, az is relative to North
@ -257,7 +368,7 @@ struct rot_caps {
max_el; /*!< Upper limit for elevation. */
const struct confparams *cfgparams; /*!< Configuration parametres. */
const struct confparams *cfgparams; /*!< Configuration parameters. */
const rig_ptr_t priv; /*!< Private data. */
/*
@ -289,8 +400,27 @@ struct rot_caps {
/* get firmware info, etc. */
const char * (*get_info)(ROT *rot);
int (*set_level)(ROT *rot, setting_t level, value_t val);
int (*get_level)(ROT *rot, setting_t level, value_t *val);
int (*set_func)(ROT *rot, setting_t func, int status);
int (*get_func)(ROT *rot, setting_t func, int *status);
int (*set_parm)(ROT *rot, setting_t parm, value_t val);
int (*get_parm)(ROT *rot, setting_t parm, value_t *val);
int (*set_ext_level)(ROT *rot, token_t token, value_t val);
int (*get_ext_level)(ROT *rot, token_t token, value_t *val);
int (*set_ext_func)(ROT *rot, token_t token, int status);
int (*get_ext_func)(ROT *rot, token_t token, int *status);
int (*set_ext_parm)(ROT *rot, token_t token, value_t val);
int (*get_ext_parm)(ROT *rot, token_t token, value_t *val);
int (*get_status)(ROT *rot, rot_status_t *status);
const char *macro_name; /*!< Macro name. */
/* more to come... */
};
//! @endcond
@ -318,6 +448,18 @@ struct rot_state {
azimuth_t az_offset; /*!< Offset to be applied to azimuth */
elevation_t el_offset; /*!< Offset to be applied to elevation */
setting_t has_get_func; /*!< List of get functions */
setting_t has_set_func; /*!< List of set functions */
setting_t has_get_level; /*!< List of get level */
setting_t has_set_level; /*!< List of set level */
setting_t has_get_parm; /*!< List of get parm */
setting_t has_set_parm; /*!< List of set parm */
rot_status_t has_status; /*!< Supported status flags */
gran_t level_gran[RIG_SETTING_MAX]; /*!< level granularity */
gran_t parm_gran[RIG_SETTING_MAX]; /*!< parm granularity */
/*
* non overridable fields, internal use
*/
@ -327,6 +469,7 @@ struct rot_state {
rig_ptr_t priv; /*!< Pointer to private rotator state data. */
rig_ptr_t obj; /*!< Internal use by hamlib++ for event handling. */
int current_speed; /*!< Current speed 1-100, to be used when no change to speed is requested */
/* etc... */
};
@ -401,9 +544,88 @@ rot_move HAMLIB_PARAMS((ROT *rot,
int direction,
int speed));
extern HAMLIB_EXPORT(setting_t)
rot_has_get_level HAMLIB_PARAMS((ROT *rot,
setting_t level));
extern HAMLIB_EXPORT(setting_t)
rot_has_set_level HAMLIB_PARAMS((ROT *rot,
setting_t level));
extern HAMLIB_EXPORT(setting_t)
rot_has_get_parm HAMLIB_PARAMS((ROT *rot,
setting_t parm));
extern HAMLIB_EXPORT(setting_t)
rot_has_set_parm HAMLIB_PARAMS((ROT *rot,
setting_t parm));
extern HAMLIB_EXPORT(setting_t)
rot_has_get_func HAMLIB_PARAMS((ROT *rot,
setting_t func));
extern HAMLIB_EXPORT(setting_t)
rot_has_set_func HAMLIB_PARAMS((ROT *rot,
setting_t func));
extern HAMLIB_EXPORT(int)
rot_set_func HAMLIB_PARAMS((ROT *rot,
setting_t func,
int status));
extern HAMLIB_EXPORT(int)
rot_get_func HAMLIB_PARAMS((ROT *rot,
setting_t func,
int *status));
extern HAMLIB_EXPORT(int)
rot_set_level HAMLIB_PARAMS((ROT *rig,
setting_t level,
value_t val));
extern HAMLIB_EXPORT(int)
rot_get_level HAMLIB_PARAMS((ROT *rig,
setting_t level,
value_t *val));
extern HAMLIB_EXPORT(int)
rot_set_parm HAMLIB_PARAMS((ROT *rig,
setting_t parm,
value_t val));
extern HAMLIB_EXPORT(int)
rot_get_parm HAMLIB_PARAMS((ROT *rig,
setting_t parm,
value_t *val));
extern HAMLIB_EXPORT(int)
rot_set_ext_level HAMLIB_PARAMS((ROT *rig,
token_t token,
value_t val));
extern HAMLIB_EXPORT(int)
rot_get_ext_level HAMLIB_PARAMS((ROT *rig,
token_t token,
value_t *val));
extern HAMLIB_EXPORT(int)
rot_set_ext_func HAMLIB_PARAMS((ROT *rig,
token_t token,
int status));
extern HAMLIB_EXPORT(int)
rot_get_ext_func HAMLIB_PARAMS((ROT *rig,
token_t token,
int *status));
extern HAMLIB_EXPORT(int)
rot_set_ext_parm HAMLIB_PARAMS((ROT *rig,
token_t token,
value_t val));
extern HAMLIB_EXPORT(int)
rot_get_ext_parm HAMLIB_PARAMS((ROT *rig,
token_t token,
value_t *val));
extern HAMLIB_EXPORT(const char *)
rot_get_info HAMLIB_PARAMS((ROT *rot));
extern HAMLIB_EXPORT(int)
rot_get_status HAMLIB_PARAMS((ROT *rot,
rot_status_t *status));
extern HAMLIB_EXPORT(int)
rot_register HAMLIB_PARAMS((const struct rot_caps *caps));
@ -441,6 +663,36 @@ extern HAMLIB_EXPORT(token_t)
rot_token_lookup HAMLIB_PARAMS((ROT *rot,
const char *name));
extern HAMLIB_EXPORT(int)
rot_ext_func_foreach HAMLIB_PARAMS((ROT *rot,
int (*cfunc)(ROT *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data));
extern HAMLIB_EXPORT(int)
rot_ext_level_foreach HAMLIB_PARAMS((ROT *rot,
int (*cfunc)(ROT *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data));
extern HAMLIB_EXPORT(int)
rot_ext_parm_foreach HAMLIB_PARAMS((ROT *rot,
int (*cfunc)(ROT *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data));
extern HAMLIB_EXPORT(const struct confparams *)
rot_ext_lookup HAMLIB_PARAMS((ROT *rot,
const char *name));
extern HAMLIB_EXPORT(const struct confparams *)
rot_ext_lookup_tok HAMLIB_PARAMS((ROT *rot,
token_t token));
extern HAMLIB_EXPORT(token_t)
rot_ext_token_lookup HAMLIB_PARAMS((ROT *rot,
const char *name));
extern HAMLIB_EXPORT(const struct rot_caps *)
rot_get_caps HAMLIB_PARAMS((rot_model_t rot_model));
@ -494,6 +746,14 @@ dmmm2dec HAMLIB_PARAMS((int degrees,
double seconds,
int sw));
extern HAMLIB_EXPORT(setting_t) rot_parse_func(const char *s);
extern HAMLIB_EXPORT(setting_t) rot_parse_level(const char *s);
extern HAMLIB_EXPORT(setting_t) rot_parse_parm(const char *s);
extern HAMLIB_EXPORT(const char *) rot_strfunc(setting_t);
extern HAMLIB_EXPORT(const char *) rot_strlevel(setting_t);
extern HAMLIB_EXPORT(const char *) rot_strparm(setting_t);
extern HAMLIB_EXPORT(const char *) rot_strstatus(rot_status_t);
//! @endcond
/**

Wyświetl plik

@ -261,6 +261,10 @@
#define ROT_MODEL_GS232 ROT_MAKE_MODEL(ROT_GS232A, 6) /* Not A or B */
#define ROT_MODEL_LVB ROT_MAKE_MODEL(ROT_GS232A, 7)
#define ROT_MODEL_ST2 ROT_MAKE_MODEL(ROT_GS232A, 8)
#define ROT_MODEL_GS232A_AZ ROT_MAKE_MODEL(ROT_GS232A, 9)
#define ROT_MODEL_GS232A_EL ROT_MAKE_MODEL(ROT_GS232A, 10)
#define ROT_MODEL_GS232B_AZ ROT_MAKE_MODEL(ROT_GS232A, 11)
#define ROT_MODEL_GS232B_EL ROT_MAKE_MODEL(ROT_GS232A, 12)
/**
* \def ROT_MODEL_PCROTOR

Wyświetl plik

@ -1,4 +1,4 @@
DUMMYSRC = dummy.c dummy.h rot_dummy.c rot_dummy.h netrigctl.c netrotctl.c flrig.c flrig.h trxmanager.c trxmanager.h amp_dummy.c amp_dummy.h netampctl.c
DUMMYSRC = dummy_common.c dummy_common.h dummy.c dummy.h rot_dummy.c rot_dummy.h netrigctl.c netrotctl.c flrig.c flrig.h trxmanager.c trxmanager.h amp_dummy.c amp_dummy.h netampctl.c
noinst_LTLIBRARIES = libhamlib-dummy.la
libhamlib_dummy_la_SOURCES = $(DUMMYSRC)

Wyświetl plik

@ -37,6 +37,7 @@
#include <time.h>
#include "hamlib/rig.h"
#include "dummy_common.h"
#include "serial.h"
#include "parallel.h"
#include "cm108.h"
@ -188,47 +189,6 @@ static void copy_chan(channel_t *dest, const channel_t *src)
dest->ext_levels = saved_ext_levels;
}
static struct ext_list *alloc_init_ext(const struct confparams *cfp)
{
struct ext_list *elp;
int i, nb_ext;
for (nb_ext = 0; !RIG_IS_EXT_END(cfp[nb_ext]); nb_ext++)
;
elp = calloc((nb_ext + 1), sizeof(struct ext_list));
if (!elp)
{
return NULL;
}
for (i = 0; !RIG_IS_EXT_END(cfp[i]); i++)
{
elp[i].token = cfp[i].token;
/* value reset already by calloc */
}
/* last token in array is set to 0 by calloc */
return elp;
}
static struct ext_list *find_ext(struct ext_list *elp, token_t token)
{
int i;
for (i = 0; elp[i].token != 0; i++)
{
if (elp[i].token == token)
{
return &elp[i];
}
}
return NULL;
}
static int dummy_init(RIG *rig)
{
struct dummy_priv_data *priv;

Wyświetl plik

@ -0,0 +1,72 @@
/*
* Hamlib Dummy backend - shared routines
* Copyright (c) 2001-2010 by Stephane Fillod
* Copyright (c) 2010 by Nate Bargmann
* Copyright (c) 2020 by Mikael Nousiainen
*
* 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
// cppcheck-suppress *
#include <stdlib.h>
// cppcheck-suppress *
#include <string.h> /* String function definitions */
#include "hamlib/rig.h"
struct ext_list *alloc_init_ext(const struct confparams *cfp)
{
struct ext_list *elp;
int i, nb_ext;
for (nb_ext = 0; !RIG_IS_EXT_END(cfp[nb_ext]); nb_ext++)
;
elp = calloc((nb_ext + 1), sizeof(struct ext_list));
if (!elp)
{
return NULL;
}
for (i = 0; !RIG_IS_EXT_END(cfp[i]); i++)
{
elp[i].token = cfp[i].token;
/* value reset already by calloc */
}
/* last token in array is set to 0 by calloc */
return elp;
}
struct ext_list *find_ext(struct ext_list *elp, token_t token)
{
int i;
for (i = 0; elp[i].token != 0; i++)
{
if (elp[i].token == token)
{
return &elp[i];
}
}
return NULL;
}

Wyświetl plik

@ -0,0 +1,30 @@
/*
* Hamlib Dummy backend - shared routines
* Copyright (c) 2020 by Mikael Nousiainen
*
*
* 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
*
*/
#ifndef _DUMMY_COMMON_H
#define _DUMMY_COMMON_H 1
#include "hamlib/rig.h"
struct ext_list *alloc_init_ext(const struct confparams *cfp);
struct ext_list *find_ext(struct ext_list *elp, token_t token);
#endif /* _DUMMY_H */

Wyświetl plik

@ -25,18 +25,24 @@
#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 "dummy_common.h"
#include "register.h"
#include "idx_builtin.h"
#include "rot_dummy.h"
#define DUMMY_ROT_FUNC 0
#define DUMMY_ROT_LEVEL ROT_LEVEL_SPEED
#define DUMMY_ROT_PARM 0
#define DUMMY_ROT_STATUS (ROT_STATUS_MOVING | ROT_STATUS_MOVING_AZ | ROT_STATUS_MOVING_LEFT | ROT_STATUS_MOVING_RIGHT | \
ROT_STATUS_MOVING_EL | ROT_STATUS_MOVING_UP | ROT_STATUS_MOVING_DOWN | \
ROT_STATUS_LIMIT_UP | ROT_STATUS_LIMIT_DOWN | ROT_STATUS_LIMIT_LEFT | ROT_STATUS_LIMIT_RIGHT)
struct dummy_rot_priv_data
{
azimuth_t az;
@ -45,8 +51,67 @@ struct dummy_rot_priv_data
struct timeval tv; /* time last az/el update */
azimuth_t target_az;
elevation_t target_el;
rot_status_t status;
setting_t funcs;
value_t levels[RIG_SETTING_MAX];
value_t parms[RIG_SETTING_MAX];
struct ext_list *ext_funcs;
struct ext_list *ext_levels;
struct ext_list *ext_parms;
char *magic_conf;
};
static const struct confparams dummy_ext_levels[] =
{
{
TOK_EL_ROT_MAGICLEVEL, "MGL", "Magic level", "Magic level, as an example",
NULL, RIG_CONF_NUMERIC, { .n = { 0, 1, .001 } }
},
{
TOK_EL_ROT_MAGICFUNC, "MGF", "Magic func", "Magic function, as an example",
NULL, RIG_CONF_CHECKBUTTON
},
{
TOK_EL_ROT_MAGICOP, "MGO", "Magic Op", "Magic Op, as an example",
NULL, RIG_CONF_BUTTON
},
{
TOK_EL_ROT_MAGICCOMBO, "MGC", "Magic combo", "Magic combo, as an example",
"VALUE1", RIG_CONF_COMBO, { .c = { .combostr = { "VALUE1", "VALUE2", "NONE", NULL } } }
},
{ RIG_CONF_END, NULL, }
};
static const struct confparams dummy_ext_funcs[] =
{
{
TOK_EL_ROT_MAGICEXTFUNC, "MGEF", "Magic ext func", "Magic ext function, as an example",
NULL, RIG_CONF_CHECKBUTTON
},
{ RIG_CONF_END, NULL, }
};
static const struct confparams dummy_ext_parms[] =
{
{
TOK_EP_ROT_MAGICPARM, "MGP", "Magic parm", "Magic parameter, as an example",
NULL, RIG_CONF_NUMERIC, { .n = { 0, 1, .001 } }
},
{ RIG_CONF_END, NULL, }
};
/* cfgparams are configuration item generally used by the backend's open() method */
static const struct confparams dummy_cfg_params[] =
{
{
TOK_CFG_ROT_MAGICCONF, "mcfg", "Magic conf", "Magic parameter, as an example",
"ROTATOR", RIG_CONF_STRING, { }
},
{ RIG_CONF_END, NULL, }
};
static int dummy_rot_init(ROT *rot)
@ -65,19 +130,50 @@ static int dummy_rot_init(ROT *rot)
priv = rot->state.priv;
priv->ext_funcs = alloc_init_ext(dummy_ext_funcs);
if (!priv->ext_funcs)
{
return -RIG_ENOMEM;
}
priv->ext_levels = alloc_init_ext(dummy_ext_levels);
if (!priv->ext_levels)
{
return -RIG_ENOMEM;
}
priv->ext_parms = alloc_init_ext(dummy_ext_parms);
if (!priv->ext_parms)
{
return -RIG_ENOMEM;
}
rot->state.rotport.type.rig = RIG_PORT_NONE;
priv->az = priv->el = 0;
priv->target_az = priv->target_el = 0;
priv->magic_conf = strdup("ROTATOR");
return RIG_OK;
}
static int dummy_rot_cleanup(ROT *rot)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)
rot->state.priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
free(priv->ext_funcs);
free(priv->ext_levels);
free(priv->ext_parms);
free(priv->magic_conf);
if (rot->state.priv)
{
free(rot->state.priv);
@ -102,6 +198,51 @@ static int dummy_rot_close(ROT *rot)
return RIG_OK;
}
static int dummy_set_conf(ROT *rot, token_t token, const char *val)
{
struct dummy_rot_priv_data *priv;
priv = (struct dummy_rot_priv_data *)rot->state.priv;
switch (token)
{
case TOK_CFG_ROT_MAGICCONF:
if (val)
{
free(priv->magic_conf);
priv->magic_conf = strdup(val);
}
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
static int dummy_get_conf(ROT *rot, token_t token, char *val)
{
struct dummy_rot_priv_data *priv;
priv = (struct dummy_rot_priv_data *)rot->state.priv;
switch (token)
{
case TOK_CFG_ROT_MAGICCONF:
strcpy(val, priv->magic_conf);
break;
default:
return -RIG_EINVAL;
}
return RIG_OK;
}
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 *)
@ -118,27 +259,13 @@ static int dummy_rot_set_position(ROT *rot, azimuth_t az, elevation_t el)
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 void dummy_rot_simulate_rotation(ROT *rot)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)
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", __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 +
@ -153,16 +280,19 @@ static int dummy_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
{
/* target reached */
priv->az = priv->target_az;
priv->status &= ~(ROT_STATUS_MOVING_AZ | ROT_STATUS_MOVING_LEFT | ROT_STATUS_MOVING_RIGHT);
}
else
{
if (priv->az < priv->target_az)
{
priv->az += (azimuth_t)elapsed * DEG_PER_MS;
priv->status |= ROT_STATUS_MOVING_AZ | ROT_STATUS_MOVING_RIGHT;
}
else
{
priv->az -= (azimuth_t)elapsed * DEG_PER_MS;
priv->status |= ROT_STATUS_MOVING_AZ | ROT_STATUS_MOVING_LEFT;
}
}
@ -170,23 +300,54 @@ static int dummy_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
{
/* target reached */
priv->el = priv->target_el;
priv->status &= ~(ROT_STATUS_MOVING_EL | ROT_STATUS_MOVING_UP | ROT_STATUS_MOVING_DOWN);
}
else
{
if (priv->el < priv->target_el)
{
priv->el += (elevation_t)elapsed * DEG_PER_MS;
priv->status |= ROT_STATUS_MOVING_EL | ROT_STATUS_MOVING_UP;
}
else
{
priv->el -= (elevation_t)elapsed * DEG_PER_MS;
priv->status |= ROT_STATUS_MOVING_EL | ROT_STATUS_MOVING_DOWN;
}
}
*az = priv->az;
*el = priv->el;
if (priv->status & (ROT_STATUS_MOVING_AZ | ROT_STATUS_MOVING_EL)) {
priv->status |= ROT_STATUS_MOVING;
} else {
priv->status &= ~(ROT_STATUS_MOVING);
}
priv->tv = tv;
}
/*
* 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;
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;
}
dummy_rot_simulate_rotation(rot);
*az = priv->az;
*el = priv->el;
return RIG_OK;
}
@ -264,18 +425,466 @@ static const char *dummy_rot_get_info(ROT *rot)
return "Dummy rotator";
}
static int dummy_set_func(ROT *rot, setting_t func, int status)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s %d\n", __func__,
rot_strfunc(func), status);
if (status)
{
priv->funcs |= func;
}
else
{
priv->funcs &= ~func;
}
return RIG_OK;
}
static int dummy_get_func(ROT *rot, setting_t func, int *status)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
*status = (priv->funcs & func) ? 1 : 0;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__,
rot_strfunc(func));
return RIG_OK;
}
static int dummy_set_level(ROT *rot, setting_t level, value_t val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
int idx;
char lstr[32];
idx = rig_setting2idx(level);
if (idx >= RIG_SETTING_MAX)
{
return -RIG_EINVAL;
}
priv->levels[idx] = val;
if (ROT_LEVEL_IS_FLOAT(level))
{
sprintf(lstr, "%f", val.f);
}
else
{
sprintf(lstr, "%d", val.i);
}
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s %s\n", __func__,
rot_strlevel(level), lstr);
return RIG_OK;
}
static int dummy_get_level(ROT *rot, setting_t level, value_t *val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
int idx;
idx = rig_setting2idx(level);
if (idx >= RIG_SETTING_MAX)
{
return -RIG_EINVAL;
}
*val = priv->levels[idx];
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__,
rot_strlevel(level));
return RIG_OK;
}
static int dummy_set_ext_level(ROT *rot, token_t token, value_t val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
char lstr[64];
const struct confparams *cfp;
struct ext_list *elp;
cfp = rot_ext_lookup_tok(rot, token);
if (!cfp)
{
return -RIG_EINVAL;
}
switch (token)
{
case TOK_EL_ROT_MAGICLEVEL:
case TOK_EL_ROT_MAGICFUNC:
case TOK_EL_ROT_MAGICOP:
case TOK_EL_ROT_MAGICCOMBO:
break;
default:
return -RIG_EINVAL;
}
switch (cfp->type)
{
case RIG_CONF_STRING:
strcpy(lstr, val.s);
break;
case RIG_CONF_COMBO:
sprintf(lstr, "%d", val.i);
break;
case RIG_CONF_NUMERIC:
sprintf(lstr, "%f", val.f);
break;
case RIG_CONF_CHECKBUTTON:
sprintf(lstr, "%s", val.i ? "ON" : "OFF");
break;
case RIG_CONF_BUTTON:
lstr[0] = '\0';
break;
default:
return -RIG_EINTERNAL;
}
elp = find_ext(priv->ext_levels, token);
if (!elp)
{
return -RIG_EINTERNAL;
}
/* store value */
elp->val = val;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s %s\n", __func__,
cfp->name, lstr);
return RIG_OK;
}
static int dummy_get_ext_level(ROT *rot, token_t token, value_t *val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
const struct confparams *cfp;
struct ext_list *elp;
cfp = rot_ext_lookup_tok(rot, token);
if (!cfp)
{
return -RIG_EINVAL;
}
switch (token)
{
case TOK_EL_ROT_MAGICLEVEL:
case TOK_EL_ROT_MAGICFUNC:
case TOK_EL_ROT_MAGICOP:
case TOK_EL_ROT_MAGICCOMBO:
break;
default:
return -RIG_EINVAL;
}
elp = find_ext(priv->ext_levels, token);
if (!elp)
{
return -RIG_EINTERNAL;
}
/* load value */
*val = elp->val;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__,
cfp->name);
return RIG_OK;
}
static int dummy_set_ext_func(ROT *rot, token_t token, int status)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
const struct confparams *cfp;
struct ext_list *elp;
cfp = rot_ext_lookup_tok(rot, token);
if (!cfp)
{
return -RIG_EINVAL;
}
switch (token)
{
case TOK_EL_ROT_MAGICEXTFUNC:
break;
default:
return -RIG_EINVAL;
}
switch (cfp->type)
{
case RIG_CONF_CHECKBUTTON:
break;
case RIG_CONF_BUTTON:
break;
default:
return -RIG_EINTERNAL;
}
elp = find_ext(priv->ext_funcs, token);
if (!elp)
{
return -RIG_EINTERNAL;
}
/* store value */
elp->val.i = status;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s %d\n", __func__,
cfp->name, status);
return RIG_OK;
}
static int dummy_get_ext_func(ROT *rot, token_t token, int *status)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
const struct confparams *cfp;
struct ext_list *elp;
cfp = rot_ext_lookup_tok(rot, token);
if (!cfp)
{
return -RIG_EINVAL;
}
switch (token)
{
case TOK_EL_ROT_MAGICEXTFUNC:
break;
default:
return -RIG_EINVAL;
}
elp = find_ext(priv->ext_funcs, token);
if (!elp)
{
return -RIG_EINTERNAL;
}
/* load value */
*status = elp->val.i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__,
cfp->name);
return RIG_OK;
}
static int dummy_set_parm(ROT *rot, setting_t parm, value_t val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
int idx;
char pstr[32];
idx = rig_setting2idx(parm);
if (idx >= RIG_SETTING_MAX)
{
return -RIG_EINVAL;
}
if (ROT_PARM_IS_FLOAT(parm))
{
sprintf(pstr, "%f", val.f);
}
else
{
sprintf(pstr, "%d", val.i);
}
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s %s\n", __func__,
rig_strparm(parm), pstr);
priv->parms[idx] = val;
return RIG_OK;
}
static int dummy_get_parm(ROT *rot, setting_t parm, value_t *val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
int idx;
idx = rig_setting2idx(parm);
if (idx >= RIG_SETTING_MAX)
{
return -RIG_EINVAL;
}
*val = priv->parms[idx];
rig_debug(RIG_DEBUG_VERBOSE, "%s called %s\n", __func__,
rig_strparm(parm));
return RIG_OK;
}
static int dummy_set_ext_parm(ROT *rot, token_t token, value_t val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
char lstr[64];
const struct confparams *cfp;
struct ext_list *epp;
cfp = rot_ext_lookup_tok(rot, token);
if (!cfp)
{
return -RIG_EINVAL;
}
switch (token)
{
case TOK_EP_ROT_MAGICPARM:
break;
default:
return -RIG_EINVAL;
}
switch (cfp->type)
{
case RIG_CONF_STRING:
strcpy(lstr, val.s);
break;
case RIG_CONF_COMBO:
sprintf(lstr, "%d", val.i);
break;
case RIG_CONF_NUMERIC:
sprintf(lstr, "%f", val.f);
break;
case RIG_CONF_CHECKBUTTON:
sprintf(lstr, "%s", val.i ? "ON" : "OFF");
break;
case RIG_CONF_BUTTON:
lstr[0] = '\0';
break;
default:
return -RIG_EINTERNAL;
}
epp = find_ext(priv->ext_parms, token);
if (!epp)
{
return -RIG_EINTERNAL;
}
/* store value */
epp->val = val;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s %s\n", __func__,
cfp->name, lstr);
return RIG_OK;
}
static int dummy_get_ext_parm(ROT *rot, token_t token, value_t *val)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
const struct confparams *cfp;
struct ext_list *epp;
cfp = rot_ext_lookup_tok(rot, token);
if (!cfp)
{
return -RIG_EINVAL;
}
switch (token)
{
case TOK_EP_ROT_MAGICPARM:
break;
default:
return -RIG_EINVAL;
}
epp = find_ext(priv->ext_parms, token);
if (!epp)
{
return -RIG_EINTERNAL;
}
/* load value */
*val = epp->val;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__,
cfp->name);
return RIG_OK;
}
static int dummy_rot_get_status(ROT *rot, rot_status_t *status)
{
struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *)rot->state.priv;
dummy_rot_simulate_rotation(rot);
*status = priv->status;
return RIG_OK;
}
/*
* Dummy rotator capabilities.
*/
const struct rot_caps dummy_rot_caps =
{
ROT_MODEL(ROT_MODEL_DUMMY),
.model_name = "Dummy",
.mfg_name = "Hamlib",
.version = "20200310.0",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_AZEL,
@ -288,13 +897,29 @@ const struct rot_caps dummy_rot_caps =
.priv = NULL, /* priv */
.has_get_func = DUMMY_ROT_FUNC,
.has_set_func = DUMMY_ROT_FUNC,
.has_get_level = DUMMY_ROT_LEVEL,
.has_set_level = ROT_LEVEL_SET(DUMMY_ROT_LEVEL),
.has_get_parm = DUMMY_ROT_PARM,
.has_set_parm = ROT_PARM_SET(DUMMY_ROT_PARM),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.extlevels = dummy_ext_levels,
.extfuncs = dummy_ext_funcs,
.extparms = dummy_ext_parms,
.cfgparams = dummy_cfg_params,
.has_status = DUMMY_ROT_STATUS,
.rot_init = dummy_rot_init,
.rot_cleanup = dummy_rot_cleanup,
.rot_open = dummy_rot_open,
.rot_close = dummy_rot_close,
.set_conf = rot_set_conf,
.get_conf = rot_get_conf,
.set_conf = dummy_set_conf,
.get_conf = dummy_get_conf,
.set_position = dummy_rot_set_position,
.get_position = dummy_rot_get_position,
@ -303,7 +928,22 @@ const struct rot_caps dummy_rot_caps =
.reset = dummy_rot_reset,
.move = dummy_rot_move,
.get_info = dummy_rot_get_info,
.set_func = dummy_set_func,
.get_func = dummy_get_func,
.set_level = dummy_set_level,
.get_level = dummy_get_level,
.set_parm = dummy_set_parm,
.get_parm = dummy_get_parm,
.set_ext_func = dummy_set_ext_func,
.get_ext_func = dummy_get_ext_func,
.set_ext_level = dummy_set_ext_level,
.get_ext_level = dummy_get_ext_level,
.set_ext_parm = dummy_set_ext_parm,
.get_ext_parm = dummy_get_ext_parm,
.get_info = dummy_rot_get_info,
.get_status = dummy_rot_get_status,
};
DECLARE_INITROT_BACKEND(dummy)

Wyświetl plik

@ -22,6 +22,19 @@
#ifndef _ROT_DUMMY_H
#define _ROT_DUMMY_H 1
#include "token.h"
/* backend conf */
#define TOK_CFG_ROT_MAGICCONF TOKEN_BACKEND(1)
#define TOK_CFG_ROT_STATIC_DATA TOKEN_BACKEND(2)
/* ext_level's and ext_parm's tokens */
#define TOK_EL_ROT_MAGICLEVEL TOKEN_BACKEND(1)
#define TOK_EL_ROT_MAGICFUNC TOKEN_BACKEND(2)
#define TOK_EL_ROT_MAGICOP TOKEN_BACKEND(3)
#define TOK_EP_ROT_MAGICPARM TOKEN_BACKEND(4)
#define TOK_EL_ROT_MAGICCOMBO TOKEN_BACKEND(5)
#define TOK_EL_ROT_MAGICEXTFUNC TOKEN_BACKEND(6)
extern const struct rot_caps dummy_rot_caps;
extern const struct rot_caps netrotctl_caps;

Wyświetl plik

@ -35,9 +35,12 @@
#include "serial.h"
#include "misc.h"
#include "register.h"
#include "idx_builtin.h"
#include "easycomm.h"
#define EASYCOMM3_LEVELS ROT_LEVEL_SPEED
/* ************************************************************************* */
/**
* easycomm_transaction
@ -247,37 +250,46 @@ easycomm_rot_move(ROT *rot, int direction, int speed)
return RIG_OK;
}
static int
easycomm_rot_move_velocity(ROT *rot, int direction, int speed)
static int easycomm_rot_move_velocity(ROT *rot, int direction, int speed)
{
struct rot_state *rs = &rot->state;
char cmdstr[24];
int retval;
int easycomm_speed;
rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__);
if (speed < 0 || speed > 9999)
{
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value!(0-9999) (%d)\n", __func__,
speed);
return -RIG_EINVAL;
if (speed == ROT_SPEED_NOCHANGE) {
easycomm_speed = rs->current_speed;
} else {
if (speed < 1 || speed > 100)
{
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value (1-100)! (%d)\n", __func__,
speed);
return -RIG_EINVAL;
}
easycomm_speed = ((speed - 1) * 100);
rs->current_speed = easycomm_speed;
}
/* Speed for EasyComm 3 */
switch (direction)
{
case ROT_MOVE_UP: /* Elevation increase */
sprintf(cmdstr, "VU%04d\n", speed);
sprintf(cmdstr, "VU%04d\n", easycomm_speed);
break;
case ROT_MOVE_DOWN: /* Elevation decrease */
sprintf(cmdstr, "VD%04d\n", speed);
sprintf(cmdstr, "VD%04d\n", easycomm_speed);
break;
case ROT_MOVE_LEFT: /* Azimuth decrease */
sprintf(cmdstr, "VL%04d\n", speed);
sprintf(cmdstr, "VL%04d\n", easycomm_speed);
break;
case ROT_MOVE_RIGHT: /* Azimuth increase */
sprintf(cmdstr, "VR%04d\n", speed);
sprintf(cmdstr, "VR%04d\n", easycomm_speed);
break;
default:
@ -296,6 +308,49 @@ easycomm_rot_move_velocity(ROT *rot, int direction, int speed)
return RIG_OK;
}
static int easycomm_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));
switch (level) {
case ROT_LEVEL_SPEED:
val->i = rs->current_speed;
break;
default:
return -RIG_ENAVAIL;
}
return RIG_OK;
}
static int easycomm_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));
switch (level) {
case ROT_LEVEL_SPEED: {
int speed = val.i;
if (speed < 0) {
speed = 0;
} else if (speed > 9999) {
speed = 9999;
}
rs->current_speed = speed;
break;
}
default:
return -RIG_ENAVAIL;
}
return RIG_OK;
}
/*
* Get Info
* returns the model name string
@ -431,6 +486,19 @@ static int easycomm_rot_set_conf(ROT *rot, token_t token, const char *val)
return RIG_OK;
}
static int easycomm_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 = 5000;
return RIG_OK;
}
/* ************************************************************************* */
/*
* Easycomm rotator capabilities.
@ -527,7 +595,7 @@ const struct rot_caps easycomm3_rot_caps =
ROT_MODEL(ROT_MODEL_EASYCOMM3),
.model_name = "EasycommIII",
.mfg_name = "Hamlib",
.version = "20191206.0",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_ALPHA,
.rot_type = ROT_TYPE_OTHER,
@ -550,7 +618,12 @@ const struct rot_caps easycomm3_rot_caps =
.priv = NULL, /* priv */
.rot_init = NULL,
.has_get_level = EASYCOMM3_LEVELS,
.has_set_level = ROT_LEVEL_SET(EASYCOMM3_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 0 }, .max = { .i = 9999 }, .step = { .i = 1 } } },
.rot_init = easycomm_rot_init,
.rot_cleanup = NULL,
.rot_open = NULL,
.rot_close = NULL,
@ -561,6 +634,8 @@ const struct rot_caps easycomm3_rot_caps =
.park = easycomm_rot_park,
.reset = easycomm_rot_reset,
.move = easycomm_rot_move_velocity,
.get_level = easycomm_rot_get_level,
.set_level = easycomm_rot_set_level,
.set_conf = easycomm_rot_set_conf,
.get_conf = easycomm_rot_get_conf,
.get_info = easycomm_rot_get_info,

Wyświetl plik

@ -35,12 +35,15 @@
#include "serial.h"
#include "misc.h"
#include "register.h"
#include "idx_builtin.h"
#include "ether6.h"
#define CMD_MAX 32
#define BUF_MAX 64
#define ETHER_LEVELS ROT_LEVEL_SPEED
/*
* Helper function with protocol return code parsing
*/
@ -263,19 +266,34 @@ static int ether_rot_reset(ROT *rot, rot_reset_t reset)
*/
static int ether_rot_move(ROT *rot, int direction, int speed)
{
struct rot_state *rs = &rot->state;
int ret, len;
char cmd[CMD_MAX];
char buf[BUF_MAX];
int ether_speed;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (speed == ROT_SPEED_NOCHANGE) {
ether_speed = rs->current_speed;
} else {
if (speed < 1 || speed > 100)
{
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value (1-100)! (%d)\n", __func__, speed);
return -RIG_EINVAL;
}
rs->current_speed = speed;
ether_speed = speed;
}
if (direction == 0)
{
len = sprintf(cmd, "rotor cw %d\n", speed);
len = sprintf(cmd, "rotor cw %d\n", ether_speed);
}
else
{
len = sprintf(cmd, "rotor ccw %d\n", speed);
len = sprintf(cmd, "rotor ccw %d\n", ether_speed);
}
ret = ether_transaction(rot, cmd, len, buf);
@ -291,6 +309,51 @@ static int ether_rot_move(ROT *rot, int direction, int speed)
}
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));
switch (level) {
case ROT_LEVEL_SPEED:
val->i = rs->current_speed;
break;
default:
return -RIG_ENAVAIL;
}
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));
switch (level) {
case ROT_LEVEL_SPEED: {
int speed = val.i;
if (speed < 1) {
speed = 1;
} else if (speed > 100) {
speed = 100;
}
rs->current_speed = speed;
break;
}
default:
return -RIG_ENAVAIL;
}
return RIG_OK;
}
static const char *ether_rot_get_info(ROT *rot)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
@ -299,6 +362,18 @@ static const char *ether_rot_get_info(ROT *rot)
}
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;
}
/*
* Dummy rotator capabilities.
@ -309,7 +384,7 @@ const struct rot_caps ether6_rot_caps =
ROT_MODEL(ROT_MODEL_ETHER6),
.model_name = "Ether6 (via ethernet)",
.mfg_name = "DG9OAA",
.version = "20200106.0",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_BETA,
.rot_type = ROT_FLAG_AZIMUTH,
@ -324,8 +399,13 @@ const struct rot_caps ether6_rot_caps =
.priv = NULL, /* priv */
/* .rot_init = ether_rot_init, */
/* .rot_cleanup = ether_rot_cleanup, */
.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,
.rot_open = ether_rot_open,
.rot_close = ether_rot_close,
@ -336,6 +416,8 @@ const struct rot_caps ether6_rot_caps =
.stop = ether_rot_stop,
.reset = ether_rot_reset,
.move = ether_rot_move,
.get_level = ether_rot_get_level,
.set_level = ether_rot_set_level,
.get_info = ether_rot_get_info,
};

Wyświetl plik

@ -38,6 +38,7 @@
#include "serial.h"
#include "misc.h"
#include "register.h"
#include "idx_builtin.h"
#include "gs232a.h"
@ -46,6 +47,8 @@
#define BUFSZ 64
#define GS232A_LEVELS ROT_LEVEL_SPEED
/**
* gs232a_transaction
*
@ -236,25 +239,85 @@ gs232a_rot_stop(ROT *rot)
}
static int
gs232a_rot_move(ROT *rot, int direction, int speed)
static int gs232a_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));
switch (level) {
case ROT_LEVEL_SPEED:
val->i = rs->current_speed;
break;
default:
return -RIG_ENAVAIL;
}
return RIG_OK;
}
static int gs232a_rot_set_level(ROT *rot, setting_t level, value_t val)
{
struct rot_state *rs = &rot->state;
char cmdstr[24];
int retval;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__, rot_strlevel(level));
switch (level) {
case ROT_LEVEL_SPEED: {
int speed = val.i;
if (speed < 1) {
speed = 1;
} else if (speed > 4) {
speed = 4;
}
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, speed);
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1);
if (retval != RIG_OK) {
return retval;
}
rs->current_speed = speed;
break;
}
default:
return -RIG_ENAVAIL;
}
return RIG_OK;
}
static int gs232a_rot_move(ROT *rot, int direction, int speed)
{
char cmdstr[24];
int retval;
unsigned x_speed;
rig_debug(RIG_DEBUG_TRACE, "%s called %d %d\n", __func__,
direction, speed);
x_speed = (3 * speed) / 100 + 1;
if (speed != ROT_SPEED_NOCHANGE) {
value_t gs232a_speed;
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1);
if (speed < 1 || speed > 100)
{
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value (1-100)! (%d)\n", __func__, speed);
return -RIG_EINVAL;
}
if (retval != RIG_OK)
{
return retval;
gs232a_speed.i = (3 * speed) / 100 + 1;
retval = gs232a_rot_set_level(rot, ROT_LEVEL_SPEED, gs232a_speed);
if (retval != RIG_OK)
{
return retval;
}
}
switch (direction)
@ -291,6 +354,20 @@ gs232a_rot_move(ROT *rot, int direction, int speed)
return RIG_OK;
}
static int gs232a_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 = 3;
return RIG_OK;
}
/* ************************************************************************* */
/*
* Generic GS23 rotator capabilities.
@ -301,7 +378,7 @@ const struct rot_caps gs23_rot_caps =
ROT_MODEL(ROT_MODEL_GS23),
.model_name = "GS-23",
.mfg_name = "Yaesu/Kenpro",
.version = "20201202.0",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_AZEL,
@ -322,9 +399,17 @@ const struct rot_caps gs23_rot_caps =
.min_el = 0.0,
.max_el = 180.0,
.has_get_level = GS232A_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232A_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.rot_init = gs232a_rot_init,
.get_position = gs232a_rot_get_position,
.set_position = gs232a_rot_set_position,
.stop = gs232a_rot_stop,
.stop = gs232a_rot_stop,
.get_level = gs232a_rot_get_level,
.set_level = gs232a_rot_set_level,
};
/* ************************************************************************* */
@ -337,7 +422,7 @@ const struct rot_caps gs232_rot_caps =
ROT_MODEL(ROT_MODEL_GS232),
.model_name = "GS-232",
.mfg_name = "Yaesu/Kenpro",
.version = "20201202.0",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_AZEL,
@ -358,9 +443,17 @@ const struct rot_caps gs232_rot_caps =
.min_el = 0.0,
.max_el = 180.0,
.has_get_level = GS232A_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232A_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.rot_init = gs232a_rot_init,
.get_position = gs232a_rot_get_position,
.set_position = gs232a_rot_set_position,
.stop = gs232a_rot_stop,
.stop = gs232a_rot_stop,
.get_level = gs232a_rot_get_level,
.set_level = gs232a_rot_set_level,
};
/* ************************************************************************* */
@ -373,10 +466,10 @@ const struct rot_caps gs232a_rot_caps =
ROT_MODEL(ROT_MODEL_GS232A),
.model_name = "GS-232A",
.mfg_name = "Yaesu",
.version = "20201205.0",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_BETA,
.rot_type = ROT_TYPE_OTHER,
.rot_type = ROT_TYPE_AZEL,
.port_type = RIG_PORT_SERIAL,
.serial_rate_min = 150,
.serial_rate_max = 9600,
@ -394,26 +487,125 @@ const struct rot_caps gs232a_rot_caps =
.min_el = 0.0,
.max_el = 180.0, /* requires G-5400B, G-5600B, G-5500, or G-500/G-550 */
.has_get_level = GS232A_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232A_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.rot_init = gs232a_rot_init,
.get_position = gs232a_rot_get_position,
.set_position = gs232a_rot_set_position,
.stop = gs232a_rot_stop,
.stop = gs232a_rot_stop,
.move = gs232a_rot_move,
.get_level = gs232a_rot_get_level,
.set_level = gs232a_rot_set_level,
};
/* ************************************************************************* */
/*
* Generic GS232A azimuth rotator capabilities.
*/
const struct rot_caps gs232a_az_rot_caps =
{
ROT_MODEL(ROT_MODEL_GS232A_AZ),
.model_name = "GS-232A azimuth",
.mfg_name = "Yaesu",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_BETA,
.rot_type = ROT_TYPE_AZIMUTH,
.port_type = RIG_PORT_SERIAL,
.serial_rate_min = 150,
.serial_rate_max = 9600,
.serial_data_bits = 8,
.serial_stop_bits = 1,
.serial_parity = RIG_PARITY_NONE,
.serial_handshake = RIG_HANDSHAKE_NONE,
.write_delay = 0,
.post_write_delay = 50,
.timeout = 400,
.retry = 3,
.min_az = -180.0,
.max_az = 450.0, /* vary according to rotator type */
.min_el = 0.0,
.max_el = 0.0,
.rot_init = gs232a_rot_init,
.has_get_level = GS232A_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232A_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.get_position = gs232a_rot_get_position,
.set_position = gs232a_rot_set_position,
.stop = gs232a_rot_stop,
.move = gs232a_rot_move,
.get_level = gs232a_rot_get_level,
.set_level = gs232a_rot_set_level,
};
/* ************************************************************************* */
/*
* Generic GS232A elevation rotator capabilities.
*/
const struct rot_caps gs232a_el_rot_caps =
{
ROT_MODEL(ROT_MODEL_GS232A_EL),
.model_name = "GS-232A elevation",
.mfg_name = "Yaesu",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_BETA,
.rot_type = ROT_TYPE_ELEVATION,
.port_type = RIG_PORT_SERIAL,
.serial_rate_min = 150,
.serial_rate_max = 9600,
.serial_data_bits = 8,
.serial_stop_bits = 1,
.serial_parity = RIG_PARITY_NONE,
.serial_handshake = RIG_HANDSHAKE_NONE,
.write_delay = 0,
.post_write_delay = 50,
.timeout = 400,
.retry = 3,
.min_az = 0.0,
.max_az = 0.0,
.min_el = 0.0,
.max_el = 180.0, /* requires G-5400B, G-5600B, G-5500, or G-500/G-550 */
.has_get_level = GS232A_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232A_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.rot_init = gs232a_rot_init,
.get_position = gs232a_rot_get_position,
.set_position = gs232a_rot_set_position,
.stop = gs232a_rot_stop,
.move = gs232a_rot_move,
.get_level = gs232a_rot_get_level,
.set_level = gs232a_rot_set_level,
};
/* ************************************************************************* */
DECLARE_INITROT_BACKEND(gs232a)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rot_register(&gs232a_rot_caps);
rot_register(&gs232a_az_rot_caps);
rot_register(&gs232a_el_rot_caps);
rot_register(&gs232_generic_rot_caps);
rot_register(&gs232b_rot_caps);
rot_register(&gs232b_az_rot_caps);
rot_register(&gs232b_el_rot_caps);
rot_register(&f1tetracker_rot_caps);
rot_register(&gs23_rot_caps);
rot_register(&gs232_rot_caps);

Wyświetl plik

@ -23,8 +23,12 @@
#define _ROT_GS232A_H 1
extern const struct rot_caps gs232a_rot_caps;
extern const struct rot_caps gs232a_az_rot_caps;
extern const struct rot_caps gs232a_el_rot_caps;
extern const struct rot_caps gs232_generic_rot_caps;
extern const struct rot_caps gs232b_rot_caps;
extern const struct rot_caps gs232b_az_rot_caps;
extern const struct rot_caps gs232b_el_rot_caps;
extern const struct rot_caps f1tetracker_rot_caps;
extern const struct rot_caps gs23_rot_caps;
extern const struct rot_caps gs232_rot_caps;

Wyświetl plik

@ -27,26 +27,22 @@
// cppcheck-suppress *
#include <stdio.h>
// cppcheck-suppress *
#include <stdlib.h>
// cppcheck-suppress *
#include <string.h> /* String function definitions */
// cppcheck-suppress *
#include <unistd.h> /* UNIX standard function definitions */
// cppcheck-suppress *
#include <math.h>
#include "hamlib/rotator.h"
#include "serial.h"
#include "misc.h"
#include "register.h"
#include "gs232a.h"
#include "idx_builtin.h"
#define EOM "\r"
#define REPLY_EOM "\n"
#define BUFSZ 64
#define GS232B_LEVELS ROT_LEVEL_SPEED
/**
* gs232b_transaction
*
@ -274,25 +270,85 @@ gs232b_rot_stop(ROT *rot)
}
static int
gs232b_rot_move(ROT *rot, int direction, int speed)
static int gs232b_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));
switch (level) {
case ROT_LEVEL_SPEED:
val->i = rs->current_speed;
break;
default:
return -RIG_ENAVAIL;
}
return RIG_OK;
}
static int gs232b_rot_set_level(ROT *rot, setting_t level, value_t val)
{
struct rot_state *rs = &rot->state;
char cmdstr[24];
int retval;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %s\n", __func__, rot_strlevel(level));
switch (level) {
case ROT_LEVEL_SPEED: {
int speed = val.i;
if (speed < 1) {
speed = 1;
} else if (speed > 4) {
speed = 4;
}
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, speed);
retval = gs232b_transaction(rot, cmdstr, NULL, 0, 1);
if (retval != RIG_OK) {
return retval;
}
rs->current_speed = speed;
break;
}
default:
return -RIG_ENAVAIL;
}
return RIG_OK;
}
static int gs232b_rot_move(ROT *rot, int direction, int speed)
{
char cmdstr[24];
int retval;
unsigned x_speed;
rig_debug(RIG_DEBUG_TRACE, "%s called %d %d\n", __func__,
direction, speed);
x_speed = (3 * speed) / 100 + 1;
if (speed != ROT_SPEED_NOCHANGE) {
value_t gs232b_speed;
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232b_transaction(rot, cmdstr, NULL, 0, 1);
if (speed < 1 || speed > 100)
{
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value (1-100)! (%d)\n", __func__, speed);
return -RIG_EINVAL;
}
if (retval != RIG_OK)
{
return retval;
gs232b_speed.i = (3 * speed) / 100 + 1;
retval = gs232b_rot_set_level(rot, ROT_LEVEL_SPEED, gs232b_speed);
if (retval != RIG_OK)
{
return retval;
}
}
switch (direction)
@ -329,6 +385,20 @@ gs232b_rot_move(ROT *rot, int direction, int speed)
return RIG_OK;
}
static int gs232b_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 = 3;
return RIG_OK;
}
/* ************************************************************************* */
/*
* Generic GS232B rotator capabilities.
@ -339,10 +409,10 @@ const struct rot_caps gs232b_rot_caps =
ROT_MODEL(ROT_MODEL_GS232B),
.model_name = "GS-232B",
.mfg_name = "Yaesu",
.version = "20201202.0",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_OTHER,
.rot_type = ROT_TYPE_AZEL,
.port_type = RIG_PORT_SERIAL,
.serial_rate_min = 1200,
.serial_rate_max = 9600,
@ -360,10 +430,110 @@ const struct rot_caps gs232b_rot_caps =
.min_el = 0.0,
.max_el = 180.0, /* requires G-5400B, G-5600B, G-5500, or G-500/G-550 */
.has_get_level = GS232B_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232B_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.rot_init = gs232b_rot_init,
.get_position = gs232b_rot_get_position,
.set_position = gs232b_rot_set_position,
.stop = gs232b_rot_stop,
.move = gs232b_rot_move,
.get_level = gs232b_rot_get_level,
.set_level = gs232b_rot_set_level,
};
/* ************************************************************************* */
/*
* Generic GS232B azimuth rotator capabilities.
*/
const struct rot_caps gs232b_az_rot_caps =
{
ROT_MODEL(ROT_MODEL_GS232B_AZ),
.model_name = "GS-232B azimuth",
.mfg_name = "Yaesu",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_AZIMUTH,
.port_type = RIG_PORT_SERIAL,
.serial_rate_min = 1200,
.serial_rate_max = 9600,
.serial_data_bits = 8,
.serial_stop_bits = 1,
.serial_parity = RIG_PARITY_NONE,
.serial_handshake = RIG_HANDSHAKE_NONE,
.write_delay = 0,
.post_write_delay = 50,
.timeout = 400,
.retry = 3,
.min_az = -180.0,
.max_az = 450.0, /* vary according to rotator type */
.min_el = 0.0,
.max_el = 0.0,
.has_get_level = GS232B_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232B_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.rot_init = gs232b_rot_init,
.get_position = gs232b_rot_get_position,
.set_position = gs232b_rot_set_position,
.stop = gs232b_rot_stop,
.move = gs232b_rot_move,
.get_level = gs232b_rot_get_level,
.set_level = gs232b_rot_set_level,
};
/* ************************************************************************* */
/*
* Generic GS232B elevation rotator capabilities.
*/
const struct rot_caps gs232b_el_rot_caps =
{
ROT_MODEL(ROT_MODEL_GS232B_EL),
.model_name = "GS-232B elevation",
.mfg_name = "Yaesu",
.version = "20201203.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_ELEVATION,
.port_type = RIG_PORT_SERIAL,
.serial_rate_min = 1200,
.serial_rate_max = 9600,
.serial_data_bits = 8,
.serial_stop_bits = 1,
.serial_parity = RIG_PARITY_NONE,
.serial_handshake = RIG_HANDSHAKE_NONE,
.write_delay = 0,
.post_write_delay = 50,
.timeout = 400,
.retry = 3,
.min_az = 0.0,
.max_az = 0.0,
.min_el = 0.0,
.max_el = 180.0, /* requires G-5400B, G-5600B, G-5500, or G-500/G-550 */
.has_get_level = GS232B_LEVELS,
.has_set_level = ROT_LEVEL_SET(GS232B_LEVELS),
.level_gran = { [ROT_LVL_SPEED] = { .min = { .i = 1 }, .max = { .i = 4 }, .step = { .i = 1 } } },
.rot_init = gs232b_rot_init,
.get_position = gs232b_rot_get_position,
.set_position = gs232b_rot_set_position,
.stop = gs232b_rot_stop,
.move = gs232b_rot_move,
.get_level = gs232b_rot_get_level,
.set_level = gs232b_rot_set_level,
};
/* end of file */

Wyświetl plik

@ -2,10 +2,10 @@
RIGSRC = rig.c serial.c serial.h misc.c misc.h register.c register.h event.c \
event.h cal.c cal.h conf.c tones.c tones.h rotator.c locator.c rot_reg.c \
rot_conf.c rot_conf.h iofunc.c iofunc.h ext.c mem.c settings.c \
rot_conf.c rot_conf.h rot_settings.c rot_ext.c iofunc.c iofunc.h ext.c mem.c settings.c \
parallel.c parallel.h usb_port.c usb_port.h debug.c network.c network.h \
cm108.c cm108.h gpio.c gpio.h idx_builtin.h token.h par_nt.h microham.c microham.h \
amplifier.c amp_reg.c amp_conf.c amp_conf.h extamp.c sleep.c sleep.h
amplifier.c amp_reg.c amp_conf.c amp_conf.h amp_settings.c extamp.c sleep.c sleep.h
lib_LTLIBRARIES = libhamlib.la
libhamlib_la_SOURCES = $(RIGSRC)

74
src/amp_settings.c 100644
Wyświetl plik

@ -0,0 +1,74 @@
/**
* \addtogroup amplifier
* @{
*/
/**
* \file amp_settings.c
* \brief amplifiter func/level/parm interface
* \author Stephane Fillod
* \date 2000-2010
*
* Hamlib interface is a frontend implementing wrapper functions.
*/
/*
* Hamlib Interface - amplifier func/level/parm
* Copyright (c) 2000-2010 by Stephane Fillod
*
*
* 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 <stdio.h>
#include <hamlib/rig.h>
#include <hamlib/amplifier.h>
/**
* \brief check retrieval ability of level settings
* \param amp The amp handle
* \param level The level settings
*
* Checks if an amp is capable of *getting* a level setting.
* Since the \a level is an OR'ed bitwise argument, more than
* one level can be checked at the same time.
*
* EXAMPLE: if (amp_has_get_level(my_amp, AMP_LVL_SWR)) disp_SWR();
*
* \return a bit map of supported level settings that can be retrieved,
* otherwise 0 if none supported.
*
* \sa amp_has_set_level(), amp_get_level()
*/
setting_t HAMLIB_API amp_has_get_level(AMP *amp, setting_t level)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!amp || !amp->caps)
{
return 0;
}
return (amp->state.has_get_level & level);
}
/*! @} */

Wyświetl plik

@ -50,8 +50,6 @@
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <hamlib/amplifier.h>
@ -59,7 +57,6 @@
#include "parallel.h"
#include "usb_port.h"
#include "network.h"
#include "amp_conf.h"
#include "token.h"
//! @cond Doxygen_Suppress

Wyświetl plik

@ -1,5 +1,5 @@
/*
* Hamlib Interface - extrq parameter interface
* Hamlib Interface - rig ext parameter interface
* Copyright (c) 2000-2008 by Stephane Fillod
*
*

Wyświetl plik

@ -23,6 +23,7 @@
#define _IDX_BUILTIN_H 1
#include <hamlib/rig.h>
#include <hamlib/rotator.h>
/*
* only for Hamlib internal use (backend caps)
@ -185,5 +186,9 @@
#define PARM_BAT setting2idx_builtin(RIG_PARM_BAT)
#define PARM_KEYLIGHT setting2idx_builtin(RIG_PARM_KEYLIGHT)
/* Rotator levels */
#define ROT_LVL_SPEED setting2idx_builtin(ROT_LEVEL_SPEED)
#endif /* _IDX_BUILTIN_H */

Wyświetl plik

@ -48,10 +48,10 @@
# include <sys/time.h>
#endif
#include <unistd.h>
#include <math.h>
#include <hamlib/rig.h>
#include <hamlib/rotator.h>
#include <hamlib/amplifier.h>
#include "misc.h"
@ -572,7 +572,7 @@ static struct
{
setting_t func;
const char *str;
} func_str[] =
} rig_func_str[] =
{
{ RIG_FUNC_FAGC, "FAGC" },
{ RIG_FUNC_NB, "NB" },
@ -618,6 +618,17 @@ static struct
{ RIG_FUNC_NONE, "" },
};
static struct
{
setting_t func;
const char *str;
} rot_func_str[] =
{
{ ROT_FUNC_NONE, "" },
};
/**
* utility function to convert index to bit value
*
@ -640,11 +651,11 @@ setting_t HAMLIB_API rig_parse_func(const char *s)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; func_str[i].str[0] != '\0'; i++)
for (i = 0 ; rig_func_str[i].str[0] != '\0'; i++)
{
if (!strcmp(s, func_str[i].str))
if (!strcmp(s, rig_func_str[i].str))
{
return func_str[i].func;
return rig_func_str[i].func;
}
}
@ -652,6 +663,31 @@ setting_t HAMLIB_API rig_parse_func(const char *s)
}
/**
* \brief Convert alpha string to enum ROT_FUNC_...
* \param s input alpha string
* \return ROT_FUNC_...
*
* \sa rot_func_e()
*/
setting_t HAMLIB_API rot_parse_func(const char *s)
{
int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; rot_func_str[i].str[0] != '\0'; i++)
{
if (!strcmp(s, rot_func_str[i].str))
{
return rot_func_str[i].func;
}
}
return ROT_FUNC_NONE;
}
/**
* \brief Convert enum RIG_FUNC_... to alpha string
* \param func RIG_FUNC_...
@ -671,11 +707,42 @@ const char *HAMLIB_API rig_strfunc(setting_t func)
return "";
}
for (i = 0; func_str[i].str[0] != '\0'; i++)
for (i = 0; rig_func_str[i].str[0] != '\0'; i++)
{
if (func == func_str[i].func)
if (func == rig_func_str[i].func)
{
return func_str[i].str;
return rig_func_str[i].str;
}
}
return "";
}
/**
* \brief Convert enum ROT_FUNC_... to alpha string
* \param func ROT_FUNC_...
* \return alpha string
*
* \sa rot_func_e()
*/
const char *HAMLIB_API rot_strfunc(setting_t func)
{
int i;
// too verbose to keep on unless debugging this in particular
//rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (func == ROT_FUNC_NONE)
{
return "";
}
for (i = 0; rot_func_str[i].str[0] != '\0'; i++)
{
if (func == rot_func_str[i].func)
{
return rot_func_str[i].str;
}
}
@ -687,7 +754,7 @@ static struct
{
setting_t level;
const char *str;
} level_str[] =
} rig_level_str[] =
{
{ RIG_LEVEL_PREAMP, "PREAMP" },
{ RIG_LEVEL_ATT, "ATT" },
@ -730,11 +797,23 @@ static struct
{ RIG_LEVEL_NONE, "" },
};
static struct
{
setting_t level;
const char *str;
} levelamp_str[] =
} rot_level_str[] =
{
{ ROT_LEVEL_SPEED, "SPEED" },
{ ROT_LEVEL_NONE, "" },
};
static struct
{
setting_t level;
const char *str;
} amp_level_str[] =
{
{ AMP_LEVEL_SWR, "SWR" },
{ AMP_LEVEL_NH, "NH" },
@ -761,17 +840,43 @@ setting_t HAMLIB_API rig_parse_level(const char *s)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; level_str[i].str[0] != '\0'; i++)
for (i = 0 ; rig_level_str[i].str[0] != '\0'; i++)
{
if (!strcmp(s, level_str[i].str))
if (!strcmp(s, rig_level_str[i].str))
{
return level_str[i].level;
return rig_level_str[i].level;
}
}
return RIG_LEVEL_NONE;
}
/**
* \brief Convert alpha string to enum ROT_LEVEL_...
* \param s input alpha string
* \return ROT_LEVEL_...
*
* \sa rot_level_e()
*/
setting_t HAMLIB_API rot_parse_level(const char *s)
{
int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; rot_level_str[i].str[0] != '\0'; i++)
{
if (!strcmp(s, rot_level_str[i].str))
{
return rot_level_str[i].level;
}
}
return ROT_LEVEL_NONE;
}
/**
* \brief Convert alpha string to enum AMP_LEVEL_...
* \param s input alpha string
@ -786,20 +891,20 @@ setting_t HAMLIB_API amp_parse_level(const char *s)
rig_debug(RIG_DEBUG_VERBOSE, "%s called level=%s\n", __func__, s);
rig_debug(RIG_DEBUG_VERBOSE, "%s called str=%s\n", __func__,
levelamp_str[0].str);
amp_level_str[0].str);
for (i = 0 ; levelamp_str[i].str[0] != '\0'; i++)
for (i = 0 ; amp_level_str[i].str[0] != '\0'; i++)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called checking=%s\n", __func__,
levelamp_str[i].str);
amp_level_str[i].str);
if (!strcmp(s, levelamp_str[i].str))
if (!strcmp(s, amp_level_str[i].str))
{
return levelamp_str[i].level;
return amp_level_str[i].level;
}
}
return RIG_LEVEL_NONE;
return AMP_LEVEL_NONE;
}
@ -821,17 +926,48 @@ const char *HAMLIB_API rig_strlevel(setting_t level)
return "";
}
for (i = 0; level_str[i].str[0] != '\0'; i++)
for (i = 0; rig_level_str[i].str[0] != '\0'; i++)
{
if (level == level_str[i].level)
if (level == rig_level_str[i].level)
{
return level_str[i].str;
return rig_level_str[i].str;
}
}
return "";
}
/**
* \brief Convert enum ROT_LEVEL_... to alpha string
* \param level ROT_LEVEL_...
* \return alpha string
*
* \sa rot_level_e()
*/
const char *HAMLIB_API rot_strlevel(setting_t level)
{
int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (level == ROT_LEVEL_NONE)
{
return "";
}
for (i = 0; rot_level_str[i].str[0] != '\0'; i++)
{
if (level == rot_level_str[i].level)
{
return rot_level_str[i].str;
}
}
return "";
}
/**
* \brief Convert enum AMP_LEVEL_... to alpha string
* \param level AMP_LEVEL_...
@ -850,11 +986,11 @@ const char *HAMLIB_API amp_strlevel(setting_t level)
return "";
}
for (i = 0; levelamp_str[i].str[0] != '\0'; i++)
for (i = 0; amp_level_str[i].str[0] != '\0'; i++)
{
if (level == levelamp_str[i].level)
if (level == amp_level_str[i].level)
{
return levelamp_str[i].str;
return amp_level_str[i].str;
}
}
@ -866,7 +1002,7 @@ static struct
{
setting_t parm;
const char *str;
} parm_str[] =
} rig_parm_str[] =
{
{ RIG_PARM_ANN, "ANN" },
{ RIG_PARM_APO, "APO" },
@ -880,6 +1016,16 @@ static struct
};
static struct
{
setting_t parm;
const char *str;
} rot_parm_str[] =
{
{ ROT_PARM_NONE, "" },
};
/**
* \brief Convert alpha string to RIG_PARM_...
* \param s input alpha string
@ -893,11 +1039,11 @@ setting_t HAMLIB_API rig_parse_parm(const char *s)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; parm_str[i].str[0] != '\0'; i++)
for (i = 0 ; rig_parm_str[i].str[0] != '\0'; i++)
{
if (!strcmp(s, parm_str[i].str))
if (!strcmp(s, rig_parm_str[i].str))
{
return parm_str[i].parm;
return rig_parm_str[i].parm;
}
}
@ -905,6 +1051,31 @@ setting_t HAMLIB_API rig_parse_parm(const char *s)
}
/**
* \brief Convert alpha string to ROT_PARM_...
* \param s input alpha string
* \return ROT_PARM_...
*
* \sa rot_parm_e()
*/
setting_t HAMLIB_API rot_parse_parm(const char *s)
{
int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
for (i = 0 ; rot_parm_str[i].str[0] != '\0'; i++)
{
if (!strcmp(s, rot_parm_str[i].str))
{
return rot_parm_str[i].parm;
}
}
return ROT_PARM_NONE;
}
/**
* \brief Convert enum RIG_PARM_... to alpha string
* \param parm RIG_PARM_...
@ -923,11 +1094,41 @@ const char *HAMLIB_API rig_strparm(setting_t parm)
return "";
}
for (i = 0; parm_str[i].str[0] != '\0'; i++)
for (i = 0; rig_parm_str[i].str[0] != '\0'; i++)
{
if (parm == parm_str[i].parm)
if (parm == rig_parm_str[i].parm)
{
return parm_str[i].str;
return rig_parm_str[i].str;
}
}
return "";
}
/**
* \brief Convert enum ROT_PARM_... to alpha string
* \param parm ROT_PARM_...
* \return alpha string
*
* \sa rot_parm_e()
*/
const char *HAMLIB_API rot_strparm(setting_t parm)
{
int i;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (parm == ROT_PARM_NONE)
{
return "";
}
for (i = 0; rot_parm_str[i].str[0] != '\0'; i++)
{
if (parm == rot_parm_str[i].parm)
{
return rot_parm_str[i].str;
}
}
@ -1557,6 +1758,54 @@ int HAMLIB_API rig_flush(hamlib_port_t *port)
return serial_flush(port); // we must be on serial port
}
static struct
{
rot_status_t status;
const char *str;
} rot_status_str[] =
{
{ ROT_STATUS_BUSY, "BUSY" },
{ ROT_STATUS_MOVING, "MOVING" },
{ ROT_STATUS_MOVING_AZ, "MOVING_AZ" },
{ ROT_STATUS_MOVING_LEFT, "MOVING_LEFT" },
{ ROT_STATUS_MOVING_RIGHT, "MOVING_RIGHT" },
{ ROT_STATUS_MOVING_EL, "MOVING_EL" },
{ ROT_STATUS_MOVING_UP, "MOVING_UP" },
{ ROT_STATUS_MOVING_DOWN, "MOVING_DOWN" },
{ ROT_STATUS_LIMIT_UP, "LIMIT_UP" },
{ ROT_STATUS_LIMIT_DOWN, "LIMIT_DOWN" },
{ ROT_STATUS_LIMIT_LEFT, "LIMIT_LEFT" },
{ ROT_STATUS_LIMIT_RIGHT, "LIMIT_RIGHT" },
{ ROT_STATUS_OVERLAP_UP, "OVERLAP_UP" },
{ ROT_STATUS_OVERLAP_DOWN, "OVERLAP_DOWN" },
{ ROT_STATUS_OVERLAP_LEFT, "OVERLAP_LEFT" },
{ ROT_STATUS_OVERLAP_RIGHT, "OVERLAP_RIGHT" },
{ 0xffffff, "" },
};
/**
* \brief Convert enum ROT_STATUS_... to a string
* \param status ROT_STATUS_...
* \return the corresponding string value
*/
const char *HAMLIB_API rot_strstatus(rot_status_t status)
{
int i;
for (i = 0 ; rot_status_str[i].str[0] != '\0'; i++)
{
if (status == rot_status_str[i].status)
{
return rot_status_str[i].str;
}
}
return "";
}
//! @endcond
/** @} */

341
src/rot_ext.c 100644
Wyświetl plik

@ -0,0 +1,341 @@
/*
* Hamlib Interface - rotator ext parameter interface
* Copyright (c) 2020 by Mikael Nousiainen
*
*
* 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
*
*/
/**
* \addtogroup rotator
* @{
*/
/**
* \file rot_ext.c
* \brief Extension request parameter interface for rotators
*
* An open-ended set of extension parameters, functions and levels are available
* for each rotator, as provided in the rotcaps extparms, extfuncs and extlevels lists.
* These provide a way to work with rotator-specific functions that don't fit into the
* basic "virtual rotator" of Hamlib.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <hamlib/rig.h>
#include <hamlib/rotator.h>
#include "token.h"
static int rot_has_ext_token(ROT *rot, token_t token)
{
int *ext_tokens = rot->caps->ext_tokens;
int i;
if (ext_tokens == NULL)
{
// Assume that all listed extfuncs/extlevels/extparms are supported if
// the ext_tokens list is not defined to preserve backwards-compatibility
return 1;
}
for (i = 0; ext_tokens[i] != TOK_BACKEND_NONE; i++)
{
if (ext_tokens[i] == token)
{
return 1;
}
}
return 0;
}
/**
* \param rot The rotator handle
* \param cfunc callback function of each extfunc
* \param data cookie to be passed to \a cfunc callback
* \brief Executes cfunc on all the elements stored in the extfuncs table
*
* The callback \a cfunc is called until it returns a value which is not
* strictly positive. A zero value means a normal end of iteration, and a
* negative value an abnormal end, which will be the return value of
* rot_ext_func_foreach.
*/
int HAMLIB_API rot_ext_func_foreach(ROT *rot,
int (*cfunc)(ROT *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data)
{
const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps || !cfunc)
{
return -RIG_EINVAL;
}
for (cfp = rot->caps->extfuncs; cfp && cfp->name; cfp++)
{
if (!rot_has_ext_token(rot, cfp->token))
{
continue;
}
int ret = (*cfunc)(rot, cfp, data);
if (ret == 0)
{
return RIG_OK;
}
if (ret < 0)
{
return ret;
}
}
return RIG_OK;
}
/**
* \param rot The rotator handle
* \param cfunc callback function of each extlevel
* \param data cookie to be passed to \a cfunc callback
* \brief Executes cfunc on all the elements stored in the extlevels table
*
* The callback \a cfunc is called until it returns a value which is not
* strictly positive. A zero value means a normal end of iteration, and a
* negative value an abnormal end, which will be the return value of
* rot_ext_level_foreach.
*/
int HAMLIB_API rot_ext_level_foreach(ROT *rot,
int (*cfunc)(ROT *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data)
{
const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps || !cfunc)
{
return -RIG_EINVAL;
}
for (cfp = rot->caps->extlevels; cfp && cfp->name; cfp++)
{
if (!rot_has_ext_token(rot, cfp->token))
{
continue;
}
int ret = (*cfunc)(rot, cfp, data);
if (ret == 0)
{
return RIG_OK;
}
if (ret < 0)
{
return ret;
}
}
return RIG_OK;
}
/**
* \param rot The rotator handle
* \param cfunc callback function of each extparm
* \param data cookie to be passed to \a cfunc callback
* \brief Executes cfunc on all the elements stored in the extparms table
*
* The callback \a cfunc is called until it returns a value which is not
* strictly positive. A zero value means a normal end of iteration, and a
* negative value an abnormal end, which will be the return value of
* rot_ext_parm_foreach.
*/
int HAMLIB_API rot_ext_parm_foreach(ROT *rot,
int (*cfunc)(ROT *,
const struct confparams *,
rig_ptr_t),
rig_ptr_t data)
{
const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps || !cfunc)
{
return -RIG_EINVAL;
}
for (cfp = rot->caps->extparms; cfp && cfp->name; cfp++)
{
if (!rot_has_ext_token(rot, cfp->token))
{
continue;
}
int ret = (*cfunc)(rot, cfp, data);
if (ret == 0)
{
return RIG_OK;
}
if (ret < 0)
{
return ret;
}
}
return RIG_OK;
}
/**
* \param rot
* \param name
* \brief lookup ext token by its name, return pointer to confparams struct.
*
* Lookup extlevels table, then extfuncs, then extparms.
*
* Returns NULL if nothing found
*
* TODO: should use Lex to speed it up, strcmp hurts!
*/
const struct confparams *HAMLIB_API rot_ext_lookup(ROT *rot, const char *name)
{
const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return NULL;
}
for (cfp = rot->caps->extlevels; cfp && cfp->name; cfp++)
{
if (!strcmp(cfp->name, name))
{
return cfp;
}
}
for (cfp = rot->caps->extfuncs; cfp && cfp->name; cfp++)
{
if (!strcmp(cfp->name, name))
{
return cfp;
}
}
for (cfp = rot->caps->extparms; cfp && cfp->name; cfp++)
{
if (!strcmp(cfp->name, name))
{
return cfp;
}
}
return NULL;
}
/**
* \param rot
* \param token
* \brief lookup ext token, return pointer to confparams struct.
*
* lookup extlevels table first, then extfuncs, then fall back to extparms.
*
* Returns NULL if nothing found
*/
const struct confparams *HAMLIB_API rot_ext_lookup_tok(ROT *rot, token_t token)
{
const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return NULL;
}
for (cfp = rot->caps->extlevels; cfp && cfp->token; cfp++)
{
if (cfp->token == token)
{
return cfp;
}
}
for (cfp = rot->caps->extfuncs; cfp && cfp->token; cfp++)
{
if (cfp->token == token)
{
return cfp;
}
}
for (cfp = rot->caps->extparms; cfp && cfp->token; cfp++)
{
if (cfp->token == token)
{
return cfp;
}
}
return NULL;
}
/**
* \param rot
* \param name
* \brief Simple lookup returning token id associated with name
*/
token_t HAMLIB_API rot_ext_token_lookup(ROT *rot, const char *name)
{
const struct confparams *cfp;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
cfp = rot_ext_lookup(rot, name);
if (!cfp)
{
return RIG_CONF_END;
}
return cfp->token;
}
/** @} */

670
src/rot_settings.c 100644
Wyświetl plik

@ -0,0 +1,670 @@
/**
* \addtogroup rotator
* @{
*/
/**
* \file rot_settings.c
* \brief rotator func/level/parm interface
* \author Mikael Nousiainen
* \date 2020
*
* Hamlib interface is a frontend implementing wrapper functions.
*/
/*
* Hamlib Interface - rotator func/level/parm
* Copyright (c) 2020 by Mikael Nousiainen
*
*
* 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>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <hamlib/rig.h>
#include <hamlib/rotator.h>
#include "cal.h"
#ifndef DOC_HIDDEN
# define CHECK_ROT_ARG(r) (!(r) || !(r)->caps || !(r)->state.comm_state)
#endif /* !DOC_HIDDEN */
/**
* \brief set a rotator level setting
* \param rig The rotator handle
* \param level The level setting
* \param val The value to set the level setting to
*
* Sets the level of a setting.
* The level value \a val can be a float or an integer. See #value_t
* for more information.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_has_set_level(), rot_get_level()
*/
int HAMLIB_API rot_set_level(ROT *rot, setting_t level, value_t val)
{
const struct rot_caps *caps;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->set_level == NULL || !rot_has_set_level(rot, level))
{
return -RIG_ENAVAIL;
}
return caps->set_level(rot, level, val);
}
/**
* \brief get the value of a level
* \param rig The rotator handle
* \param level The level setting
* \param val The location where to store the value of \a level
*
* Retrieves the value of a \a level.
* The level value \a val can be a float or an integer. See #value_t
* for more information.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_has_get_level(), rot_set_level()
*/
int HAMLIB_API rot_get_level(ROT *rot, setting_t level, value_t *val)
{
const struct rot_caps *caps;
// too verbose
//rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot) || !val)
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->get_level == NULL || !rot_has_get_level(rot, level))
{
return -RIG_ENAVAIL;
}
return caps->get_level(rot, level, val);
}
/**
* \brief set a rotator parameter
* \param rig The rotator handle
* \param parm The parameter
* \param val The value to set the parameter
*
* Sets a parameter.
* The parameter value \a val can be a float or an integer. See #value_t
* for more information.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_has_set_parm(), rot_get_parm()
*/
int HAMLIB_API rot_set_parm(ROT *rot, setting_t parm, value_t val)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL;
}
if (rot->caps->set_parm == NULL || !rot_has_set_parm(rot, parm))
{
return -RIG_ENAVAIL;
}
return rot->caps->set_parm(rot, parm, val);
}
/**
* \brief get the value of a parameter
* \param rig The rotator handle
* \param parm The parameter
* \param val The location where to store the value of \a parm
*
* Retrieves the value of a \a parm.
* The parameter value \a val can be a float or an integer. See #value_t
* for more information.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_has_get_parm(), rot_set_parm()
*/
int HAMLIB_API rot_get_parm(ROT *rot, setting_t parm, value_t *val)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot) || !val)
{
return -RIG_EINVAL;
}
if (rot->caps->get_parm == NULL || !rot_has_get_parm(rot, parm))
{
return -RIG_ENAVAIL;
}
return rot->caps->get_parm(rot, parm, val);
}
/**
* \brief check retrieval ability of level settings
* \param rig The rotator handle
* \param level The level settings
*
* Checks if a rotator is capable of *getting* a level setting.
* Since the \a level is an OR'ed bitwise argument, more than
* one level can be checked at the same time.
*
* EXAMPLE: if (rot_has_get_level(my_rig, RIG_LEVEL_SPEED))
*
* \return a bit map of supported level settings that can be retrieved,
* otherwise 0 if none supported.
*
* \sa rot_has_set_level(), rot_get_level()
*/
setting_t HAMLIB_API rot_has_get_level(ROT *rot, setting_t level)
{
// too verbose
//rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return 0;
}
return (rot->state.has_get_level & level);
}
/**
* \brief check settable ability of level settings
* \param rig The rotator handle
* \param level The level settings
*
* Checks if a rotator can *set* a level setting.
* Since the \a level is an OR'ed bitwise argument, more than
* one level can be check at the same time.
*
* EXAMPLE: if (rot_has_set_level(my_rig, ROT_LEVEL_SPEED))
*
* \return a bit map of supported level settings that can be set,
* otherwise 0 if none supported.
*
* \sa rot_has_get_level(), rot_set_level()
*/
setting_t HAMLIB_API rot_has_set_level(ROT *rot, setting_t level)
{
// too verbose
//rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return 0;
}
return (rot->state.has_set_level & level);
}
/**
* \brief check retrieval ability of parameter settings
* \param rig The rotator handle
* \param parm The parameter settings
*
* Checks if a rotator is capable of *getting* a parm setting.
* Since the \a parm is an OR'ed bitwise argument, more than
* one parameter can be checked at the same time.
*
* EXAMPLE: if (rot_has_get_parm(my_rig, ROT_PARM_NONE))
*
* \return a bit map of supported parameter settings that can be retrieved,
* otherwise 0 if none supported.
*
* \sa rot_has_set_parm(), rot_get_parm()
*/
setting_t HAMLIB_API rot_has_get_parm(ROT *rot, setting_t parm)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return 0;
}
return (rot->state.has_get_parm & parm);
}
/**
* \brief check settable ability of parameter settings
* \param rig The rotator handle
* \param parm The parameter settings
*
* Checks if a rotator can *set* a parameter setting.
* Since the \a parm is an OR'ed bitwise argument, more than
* one parameter can be check at the same time.
*
* EXAMPLE: if (rot_has_set_parm(my_rig, RIG_PARM_NONE))
*
* \return a bit map of supported parameter settings that can be set,
* otherwise 0 if none supported.
*
* \sa rot_has_get_parm(), rot_set_parm()
*/
setting_t HAMLIB_API rot_has_set_parm(ROT *rot, setting_t parm)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return 0;
}
return (rot->state.has_set_parm & parm);
}
/**
* \brief check ability of rotator functions
* \param rig The rotator handle
* \param func The functions
*
* Checks if a rotator supports a set of functions.
* Since the \a func is an OR'ed bitwise argument, more than
* one function can be checked at the same time.
*
* EXAMPLE: if (rot_has_get_func(my_rig, RIG_FUNC_NONE))
*
* \return a bit map of supported functions,
* otherwise 0 if none supported.
*
* \sa rot_has_set_func(), rot_get_func()
*/
setting_t HAMLIB_API rot_has_get_func(ROT *rot, setting_t func)
{
// too verbose
//rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return 0;
}
return (rot->state.has_get_func & func);
}
/**
* \brief check ability of rotator functions
* \param rig The rotator handle
* \param func The functions
*
* Checks if a rotator supports a set of functions.
* Since the \a func is an OR'ed bitwise argument, more than
* one function can be checked at the same time.
*
* EXAMPLE: if (rot_has_set_func(my_rig, RIG_FUNC_NONE))
*
* \return a bit map of supported functions,
* otherwise 0 if none supported.
*
* \sa rot_set_func(), rot_has_get_func()
*/
setting_t HAMLIB_API rot_has_set_func(ROT *rot, setting_t func)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!rot || !rot->caps)
{
return 0;
}
return (rot->state.has_set_func & func);
}
/**
* \brief activate/de-activate functions of rotator
* \param rig The rotator handle
* \param func The function to activate
* \param status The status (on or off) to set to
*
* Activate/de-activate a function of the radio.
*
* The \a status argument is a non null value for "activate",
* "de-activate" otherwise, much as TRUE/FALSE definitions in C language.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_get_func()
*/
int HAMLIB_API rot_set_func(ROT *rot, setting_t func, int status)
{
const struct rot_caps *caps;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->set_func == NULL || !rot_has_set_func(rot, func))
{
return -RIG_ENAVAIL;
}
return caps->set_func(rot, func, status);
}
/**
* \brief get the status of functions of the rotator
* \param rig The rotator handle
* \param func The function to get the status
* \param status The location where to store the function status
*
* Retrieves the status (on/off) of a function of the rotator.
* Upon return, \a status will hold the status of the function,
* The value pointer to by the \a status argument is a non null
* value for "on", "off" otherwise, much as TRUE/FALSE
* definitions in C language.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_set_func()
*/
int HAMLIB_API rot_get_func(ROT *rot, setting_t func, int *status)
{
const struct rot_caps *caps;
// too verbose
//rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot) || !func)
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->get_func == NULL || !rot_has_get_func(rot, func))
{
return -RIG_ENAVAIL;
}
return caps->get_func(rot, func, status);
}
/**
* \brief set a rotator level extra parameter
* \param rig The rotator handle
* \param token The parameter
* \param val The value to set the parameter to
*
* Sets an level extra parameter.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_get_ext_level()
*/
int HAMLIB_API rot_set_ext_level(ROT *rot, token_t token, value_t val)
{
const struct rot_caps *caps;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->set_ext_level == NULL)
{
return -RIG_ENAVAIL;
}
return caps->set_ext_level(rot, token, val);
}
/**
* \brief get the value of a level extra parameter
* \param rig The rotator handle
* \param token The parameter
* \param val The location where to store the value of \a token
*
* Retrieves the value of a level extra parameter associated with \a token.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_set_ext_level()
*/
int HAMLIB_API rot_get_ext_level(ROT *rot, token_t token, value_t *val)
{
const struct rot_caps *caps;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot) || !val)
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->get_ext_level == NULL)
{
return -RIG_ENAVAIL;
}
return caps->get_ext_level(rot, token, val);
}
/**
* \brief set a rotator function extra parameter
* \param rig The rotator handle
* \param token The parameter
* \param status The value to set the parameter to
*
* Sets a function extra parameter.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_get_ext_func()
*/
int HAMLIB_API rot_set_ext_func(ROT *rot, token_t token, int status)
{
const struct rot_caps *caps;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->set_ext_func == NULL)
{
return -RIG_ENAVAIL;
}
return caps->set_ext_func(rot, token, status);
}
/**
* \brief get the value of a function extra parameter
* \param rig The rotator handle
* \param token The parameter
* \param status The location where to store the value of \a token
*
* Retrieves the value of a function extra parameter associated with \a token.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_set_ext_func()
*/
int HAMLIB_API rot_get_ext_func(ROT *rot, token_t token, int *status)
{
const struct rot_caps *caps;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot) || !status)
{
return -RIG_EINVAL;
}
caps = rot->caps;
if (caps->get_ext_func == NULL)
{
return -RIG_ENAVAIL;
}
return caps->get_ext_func(rot, token, status);
}
/**
* \brief set a rotator parm extra parameter
* \param rig The rotator handle
* \param token The parameter
* \param val The value to set the parameter to
*
* Sets an parm extra parameter.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_get_ext_parm()
*/
int HAMLIB_API rot_set_ext_parm(ROT *rot, token_t token, value_t val)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL;
}
if (rot->caps->set_ext_parm == NULL)
{
return -RIG_ENAVAIL;
}
return rot->caps->set_ext_parm(rot, token, val);
}
/**
* \brief get the value of a parm extra parameter
* \param rig The rotator handle
* \param token The parameter
* \param val The location where to store the value of \a token
*
* Retrieves the value of a parm extra parameter associated with \a token.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*
* \sa rot_set_ext_parm()
*/
int HAMLIB_API rot_get_ext_parm(ROT *rot, token_t token, value_t *val)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot) || !val)
{
return -RIG_EINVAL;
}
if (rot->caps->get_ext_parm == NULL)
{
return -RIG_ENAVAIL;
}
return rot->caps->get_ext_parm(rot, token, val);
}
/*! @} */

Wyświetl plik

@ -272,9 +272,22 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
rs->max_el = caps->max_el;
rs->min_az = caps->min_az;
rs->max_az = caps->max_az;
rs->current_speed = 50; // Set default speed to 50%
rs->rotport.fd = -1;
rs->has_get_func = caps->has_get_func;
rs->has_set_func = caps->has_set_func;
rs->has_get_level = caps->has_get_level;
rs->has_set_level = caps->has_set_level;
rs->has_get_parm = caps->has_get_parm;
rs->has_set_parm = caps->has_set_parm;
rs->has_status = caps->has_status;
memcpy(rs->level_gran, caps->level_gran, sizeof(gran_t)*RIG_SETTING_MAX);
memcpy(rs->parm_gran, caps->parm_gran, sizeof(gran_t)*RIG_SETTING_MAX);
/*
* let the backend a chance to setup his private data
* This must be done only once defaults are setup,
@ -586,6 +599,9 @@ int HAMLIB_API rot_set_position(ROT *rot,
return -RIG_EINVAL;
}
azimuth += rot->state.az_offset;
elevation += rot->state.el_offset;
caps = rot->caps;
rs = &rot->state;
@ -637,6 +653,8 @@ int HAMLIB_API rot_get_position(ROT *rot,
{
const struct rot_caps *caps;
const struct rot_state *rs;
azimuth_t az;
elevation_t el;
int retval;
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
@ -654,19 +672,21 @@ int HAMLIB_API rot_get_position(ROT *rot,
return -RIG_ENAVAIL;
}
retval = caps->get_position(rot, azimuth, elevation);
retval = caps->get_position(rot, &az, &el);
if (retval != RIG_OK) { return retval; }
rot_debug(RIG_DEBUG_VERBOSE, "%s: got az=%.2f, el=%.2f\n", __func__, *azimuth,
*elevation);
rot_debug(RIG_DEBUG_VERBOSE, "%s: got az=%.2f, el=%.2f\n", __func__, az, el);
if (rs->south_zero)
{
*azimuth += *azimuth >= 180 ? -180 : 180;
rot_debug(RIG_DEBUG_VERBOSE, "%s: south adj to az=%.2f\n", __func__, *azimuth);
az += az >= 180 ? -180 : 180;
rot_debug(RIG_DEBUG_VERBOSE, "%s: south adj to az=%.2f\n", __func__, az);
}
*azimuth = az - rot->state.az_offset;
*elevation = el - rot->state.el_offset;
return RIG_OK;
}
@ -830,4 +850,33 @@ const char *HAMLIB_API rot_get_info(ROT *rot)
return rot->caps->get_info(rot);
}
/**
* \brief get status flags from the rotator
* \param rot The rot handle
* \param status a pointer to a rot_status_t variable that will receive the status flags
*
* Gets the active status flags from the rotator.
*
* \return RIG_OK if the operation has been successful, otherwise
* a negative value if an error occurred (in which case, cause is
* set appropriately).
*/
int HAMLIB_API rot_get_status(ROT *rot, rot_status_t *status)
{
rot_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (CHECK_ROT_ARG(rot))
{
return -RIG_EINVAL;
}
if (rot->caps->get_status == NULL)
{
return -RIG_ENAVAIL;
}
return rot->caps->get_status(rot, status);
}
/*! @} */

Wyświetl plik

@ -37,16 +37,10 @@
# include "config.h"
#endif
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <hamlib/rig.h>
#include <hamlib/amplifier.h>
#include "cal.h"
@ -313,35 +307,6 @@ setting_t HAMLIB_API rig_has_get_level(RIG *rig, setting_t level)
}
/**
* \brief check retrieval ability of level settings
* \param amp The amp handle
* \param level The level settings
*
* Checks if an amp is capable of *getting* a level setting.
* Since the \a level is an OR'ed bitwise argument, more than
* one level can be checked at the same time.
*
* EXAMPLE: if (amp_has_get_level(my_amp, AMP_LVL_SWR)) disp_SWR();
*
* \return a bit map of supported level settings that can be retrieved,
* otherwise 0 if none supported.
*
* \sa amp_has_set_level(), amp_get_level()
*/
setting_t HAMLIB_API amp_has_get_level(AMP *amp, setting_t level)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (!amp || !amp->caps)
{
return 0;
}
return (amp->state.has_get_level & level);
}
/**
* \brief check settable ability of level settings
* \param rig The rig handle

Wyświetl plik

@ -13,7 +13,7 @@ bin_PROGRAMS = rigctl rigctld rigmem rigsmtr rigswr rotctl rotctld rigctlcom amp
check_PROGRAMS = dumpmem testrig testtrn testbcd testfreq listrigs testloc rig_bench cachetest cachetest2
RIGCOMMONSRC = rigctl_parse.c rigctl_parse.h dumpcaps.c sprintflst.c sprintflst.h uthash.h hamlibdatetime.h
ROTCOMMONSRC = rotctl_parse.c rotctl_parse.h dumpcaps_rot.c uthash.h hamlibdatetime.h
ROTCOMMONSRC = rotctl_parse.c rotctl_parse.h dumpcaps_rot.c sprintflst.c sprintflst.h uthash.h hamlibdatetime.h
AMPCOMMONSRC = ampctl_parse.c ampctl_parse.h dumpcaps_amp.c sprintflst.c sprintflst.h uthash.h hamlibdatetime.h
rigctl_SOURCES = rigctl.c $(RIGCOMMONSRC)

Wyświetl plik

@ -1674,7 +1674,7 @@ declare_proto_amp(get_level)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_level_amp(s, amp->state.has_get_level);
amp_sprintf_level(s, amp->state.has_get_level);
fputs(s, fout);

Wyświetl plik

@ -33,12 +33,15 @@
#include "sprintflst.h"
#include "rigctl_parse.h"
static int print_ext(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr);
void range_print(FILE *fout, const struct freq_range_list range_list[], int rx);
int range_sanity_check(const struct freq_range_list range_list[], int rx);
int ts_sanity_check(const struct tuning_step_list tuning_step[]);
static void dump_chan_caps(const channel_cap_t *chan, FILE *fout);
static int print_ext(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr)
{
return print_ext_param(cfp, ptr);
}
/*
* the rig may be in rig_init state, but not opened
@ -328,16 +331,16 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "\n");
sprintf_func(prntbuf, caps->has_get_func);
rig_sprintf_func(prntbuf, caps->has_get_func);
fprintf(fout, "Get functions: %s\n", prntbuf);
sprintf_func(prntbuf, caps->has_set_func);
rig_sprintf_func(prntbuf, caps->has_set_func);
fprintf(fout, "Set functions: %s\n", prntbuf);
fprintf(fout, "Extra functions:\n");
rig_ext_func_foreach(rig, print_ext, fout);
sprintf_level_gran(prntbuf, caps->has_get_level, caps->level_gran);
rig_sprintf_level_gran(prntbuf, caps->has_get_level, caps->level_gran);
fprintf(fout, "Get level: %s\n", prntbuf);
if ((caps->has_get_level & RIG_LEVEL_SQLSTAT))
@ -356,7 +359,7 @@ int dumpcaps(RIG *rig, FILE *fout)
backend_warnings++;
}
sprintf_level_gran(prntbuf, caps->has_set_level, caps->level_gran);
rig_sprintf_level_gran(prntbuf, caps->has_set_level, caps->level_gran);
fprintf(fout, "Set level: %s\n", prntbuf);
if (caps->has_set_level & RIG_LEVEL_READONLY_LIST)
@ -368,10 +371,10 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "Extra levels:\n");
rig_ext_level_foreach(rig, print_ext, fout);
sprintf_parm_gran(prntbuf, caps->has_get_parm, caps->parm_gran);
rig_sprintf_parm_gran(prntbuf, caps->has_get_parm, caps->parm_gran);
fprintf(fout, "Get parameters: %s\n", prntbuf);
sprintf_parm_gran(prntbuf, caps->has_set_parm, caps->parm_gran);
rig_sprintf_parm_gran(prntbuf, caps->has_set_parm, caps->parm_gran);
fprintf(fout, "Set parameters: %s\n", prntbuf);
if (caps->has_set_parm & RIG_PARM_READONLY_LIST)
@ -386,7 +389,7 @@ int dumpcaps(RIG *rig, FILE *fout)
if (rig->state.mode_list != 0)
{
sprintf_mode(prntbuf, rig->state.mode_list);
rig_sprintf_mode(prntbuf, rig->state.mode_list);
}
else
{
@ -398,7 +401,7 @@ int dumpcaps(RIG *rig, FILE *fout)
if (rig->state.vfo_list != 0)
{
sprintf_vfo(prntbuf, rig->state.vfo_list);
rig_sprintf_vfo(prntbuf, rig->state.vfo_list);
}
else
{
@ -408,10 +411,10 @@ int dumpcaps(RIG *rig, FILE *fout)
fprintf(fout, "VFO list: %s\n", prntbuf);
sprintf_vfop(prntbuf, caps->vfo_ops);
rig_sprintf_vfop(prntbuf, caps->vfo_ops);
fprintf(fout, "VFO Ops: %s\n", prntbuf);
sprintf_scan(prntbuf, caps->scan_ops);
rig_sprintf_scan(prntbuf, caps->scan_ops);
fprintf(fout, "Scan Ops: %s\n", prntbuf);
fprintf(fout, "Number of banks:\t%d\n", caps->bank_qty);
@ -610,7 +613,7 @@ int dumpcaps(RIG *rig, FILE *fout)
sprintf_freq(freqbuf, caps->tuning_steps[i].ts);
}
sprintf_mode(prntbuf, caps->tuning_steps[i].modes);
rig_sprintf_mode(prntbuf, caps->tuning_steps[i].modes);
fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf);
}
@ -642,7 +645,7 @@ int dumpcaps(RIG *rig, FILE *fout)
sprintf_freq(freqbuf, caps->filters[i].width);
}
sprintf_mode(prntbuf, caps->filters[i].modes);
rig_sprintf_mode(prntbuf, caps->filters[i].modes);
fprintf(fout, "\n\t%s: \t%s", freqbuf, prntbuf);
}
@ -832,41 +835,6 @@ int dumpcaps(RIG *rig, FILE *fout)
return backend_warnings;
}
static int print_ext(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr)
{
int i;
fprintf((FILE *)ptr, "\t%s\n", cfp->name);
fprintf((FILE *)ptr, "\t\tType: %s\n", get_rig_conf_type(cfp->type));
fprintf((FILE *)ptr, "\t\tDefault: %s\n", cfp->dflt != NULL ? cfp->dflt : "");
fprintf((FILE *)ptr, "\t\tLabel: %s\n", cfp->label != NULL ? cfp->label : "");
fprintf((FILE *)ptr, "\t\tTooltip: %s\n",
cfp->tooltip != NULL ? cfp->tooltip : "");
switch (cfp->type)
{
case RIG_CONF_NUMERIC:
fprintf((FILE *)ptr, "\t\tRange: %g..%g/%g\n", cfp->u.n.min, cfp->u.n.max,
cfp->u.n.step);
break;
case RIG_CONF_COMBO:
fprintf((FILE *)ptr, "\t\tValues:");
for (i = 0; i < RIG_COMBO_MAX && cfp->u.c.combostr[i] != NULL; i++)
{
fprintf((FILE *)ptr, " %d=\"%s\"", i, cfp->u.c.combostr[i]);
}
fprintf((FILE *)ptr, "\n");
break;
default:
break;
}
return 1; /* process them all */
}
void range_print(FILE *fout, const struct freq_range_list range_list[], int rx)
{
int i;
@ -883,17 +851,17 @@ void range_print(FILE *fout, const struct freq_range_list range_list[], int rx)
range_list[i].endf);
fprintf(fout, "\t\tVFO list: ");
sprintf_vfo(prntbuf, range_list[i].vfo);
rig_sprintf_vfo(prntbuf, range_list[i].vfo);
fprintf(fout, "%s", prntbuf);
fprintf(fout, "\n");
fprintf(fout, "\t\tMode list: ");
sprintf_mode(prntbuf, range_list[i].modes);
rig_sprintf_mode(prntbuf, range_list[i].modes);
fprintf(fout, "%s", prntbuf);
fprintf(fout, "\n");
fprintf(fout, "\t\tAntenna list: ");
sprintf_ant(prntbuf, range_list[i].ant);
rig_sprintf_ant(prntbuf, range_list[i].ant);
fprintf(fout, "%s", prntbuf);
fprintf(fout, "\n");

Wyświetl plik

@ -131,7 +131,7 @@ int dumpcaps_amp(AMP *amp, FILE *fout)
fprintf(fout, "Has priv data:\t\t%c\n", caps->priv != NULL ? 'Y' : 'N');
sprintf_level_amp(prntbuf, caps->has_get_level);
amp_sprintf_level(prntbuf, caps->has_get_level);
fprintf(fout, "Get level: %s\n", prntbuf);
/*

Wyświetl plik

@ -34,6 +34,11 @@
#include "rotctl_parse.h"
static int print_ext(ROT *rot, const struct confparams *cfp, rig_ptr_t ptr)
{
return print_ext_param(cfp, ptr);
}
/*
* the rot may be in rot_init state, but not opened
*/
@ -41,6 +46,7 @@ int dumpcaps_rot(ROT *rot, FILE *fout)
{
const struct rot_caps *caps;
int backend_warnings = 0;
static char prntbuf[1024];
if (!rot || !rot->caps)
{
@ -140,6 +146,62 @@ int dumpcaps_rot(ROT *rot, FILE *fout)
"Post Write delay:\t%dmS\n",
caps->post_write_delay);
if (rot->state.has_status != 0)
{
rot_sprintf_status(prntbuf, rot->state.has_status);
}
else
{
strcpy(prntbuf, "None\n");
}
fprintf(fout, "Status flags: %s\n", prntbuf);
rot_sprintf_func(prntbuf, caps->has_get_func);
fprintf(fout, "Get functions: %s\n", prntbuf);
rot_sprintf_func(prntbuf, caps->has_set_func);
fprintf(fout, "Set functions: %s\n", prntbuf);
fprintf(fout, "Extra functions:\n");
rot_ext_func_foreach(rot, print_ext, fout);
rot_sprintf_level_gran(prntbuf, caps->has_get_level, caps->level_gran);
fprintf(fout, "Get level: %s\n", prntbuf);
if ((caps->has_get_level & RIG_LEVEL_SQLSTAT))
{
fprintf(fout, "Warning--backend uses deprecated SQLSTAT level!\n");
backend_warnings++;
}
rot_sprintf_level_gran(prntbuf, caps->has_set_level, caps->level_gran);
fprintf(fout, "Set level: %s\n", prntbuf);
if (caps->has_set_level & ROT_LEVEL_READONLY_LIST)
{
fprintf(fout, "Warning--backend can set readonly levels!\n");
backend_warnings++;
}
fprintf(fout, "Extra levels:\n");
rot_ext_level_foreach(rot, print_ext, fout);
rot_sprintf_parm_gran(prntbuf, caps->has_get_parm, caps->parm_gran);
fprintf(fout, "Get parameters: %s\n", prntbuf);
rot_sprintf_parm_gran(prntbuf, caps->has_set_parm, caps->parm_gran);
fprintf(fout, "Set parameters: %s\n", prntbuf);
if (caps->has_set_parm & ROT_PARM_READONLY_LIST)
{
fprintf(fout, "Warning--backend can set readonly parms!\n");
backend_warnings++;
}
fprintf(fout, "Extra parameters:\n");
rot_ext_parm_foreach(rot, print_ext, fout);
fprintf(fout, "Min Azimuth:\t\t%.2f\n", caps->min_az);
fprintf(fout, "Max Azimuth:\t\t%.2f\n", caps->max_az);
@ -172,7 +234,16 @@ int dumpcaps_rot(ROT *rot, FILE *fout)
fprintf(fout, "Can Park:\t\t%c\n", caps->park != NULL ? 'Y' : 'N');
fprintf(fout, "Can Reset:\t\t%c\n", caps->reset != NULL ? 'Y' : 'N');
fprintf(fout, "Can Move:\t\t%c\n", caps->move != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Info:\t\t%c\n", caps->get_info != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Status:\t\t%c\n", caps->get_status != NULL ? 'Y' : 'N');
fprintf(fout, "Can set Func:\t%c\n", caps->set_func != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Func:\t%c\n", caps->get_func != NULL ? 'Y' : 'N');
fprintf(fout, "Can set Level:\t%c\n", caps->set_level != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Level:\t%c\n", caps->get_level != NULL ? 'Y' : 'N');
fprintf(fout, "Can set Param:\t%c\n", caps->set_parm != NULL ? 'Y' : 'N');
fprintf(fout, "Can get Param:\t%c\n", caps->get_parm != NULL ? 'Y' : 'N');
fprintf(fout, "\nOverall backend warnings: %d\n", backend_warnings);

Wyświetl plik

@ -2085,7 +2085,7 @@ declare_proto_rig(set_mode)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_mode(s, rig->state.mode_list);
rig_sprintf_mode(s, rig->state.mode_list);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -2136,7 +2136,7 @@ declare_proto_rig(set_vfo)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_vfo(s, rig->state.vfo_list);
rig_sprintf_vfo(s, rig->state.vfo_list);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -2530,7 +2530,7 @@ declare_proto_rig(set_split_mode)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_mode(s, rig->state.mode_list);
rig_sprintf_mode(s, rig->state.mode_list);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -2585,7 +2585,7 @@ declare_proto_rig(set_split_freq_mode)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_mode(s, rig->state.mode_list);
rig_sprintf_mode(s, rig->state.mode_list);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -2649,7 +2649,7 @@ declare_proto_rig(set_split_vfo)
if (!strcmp(arg2, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_vfo(s, rig->state.vfo_list);
rig_sprintf_vfo(s, rig->state.vfo_list);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -2810,7 +2810,7 @@ declare_proto_rig(set_level)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_level(s, rig->state.has_set_level);
rig_sprintf_level(s, rig->state.has_set_level);
fputs(s, fout);
if (rig->caps->set_ext_level)
@ -2886,7 +2886,7 @@ declare_proto_rig(get_level)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_level(s, rig->state.has_get_level);
rig_sprintf_level(s, rig->state.has_get_level);
fputs(s, fout);
if (rig->caps->get_ext_level)
@ -2984,7 +2984,7 @@ declare_proto_rig(set_func)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_func(s, rig->state.has_set_func);
rig_sprintf_func(s, rig->state.has_set_func);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -3022,7 +3022,7 @@ declare_proto_rig(get_func)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_func(s, rig->state.has_get_func);
rig_sprintf_func(s, rig->state.has_get_func);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -3084,7 +3084,7 @@ declare_proto_rig(set_parm)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_parm(s, rig->state.has_set_parm);
rig_sprintf_parm(s, rig->state.has_set_parm);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -3157,7 +3157,7 @@ declare_proto_rig(get_parm)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_parm(s, rig->state.has_get_parm);
rig_sprintf_parm(s, rig->state.has_get_parm);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -3312,7 +3312,7 @@ declare_proto_rig(vfo_op)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_vfop(s, rig->caps->vfo_ops);
rig_sprintf_vfop(s, rig->caps->vfo_ops);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -3337,7 +3337,7 @@ declare_proto_rig(scan)
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
sprintf_scan(s, rig->caps->scan_ops);
rig_sprintf_scan(s, rig->caps->scan_ops);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
@ -3901,7 +3901,7 @@ int dump_chan(FILE *fout, RIG *rig, channel_t *chan)
fprintf(fout, "DCS: %u.%u, ", chan->dcs_code / 10, chan->dcs_code % 10);
fprintf(fout, "DCSsql: %u.%u\n", chan->dcs_sql / 10, chan->dcs_sql % 10);
sprintf_func(prntbuf, chan->funcs);
rig_sprintf_func(prntbuf, chan->funcs);
fprintf(fout, "Functions: %s\n", prntbuf);
fprintf(fout, "Levels:");
@ -4174,7 +4174,7 @@ declare_proto_rig(get_ant)
fprintf(fout, "%s: ", cmd->arg1);
}
sprintf_ant(antbuf, ant_curr);
rig_sprintf_ant(antbuf, ant_curr);
fprintf(fout, "%s%c", antbuf, resp_sep);
//fprintf(fout, "%d%c", rig_setting2idx(ant_curr)+1, resp_sep);
@ -4190,7 +4190,7 @@ declare_proto_rig(get_ant)
fprintf(fout, "%s: ", cmd->arg3);
}
sprintf_ant(antbuf, ant_tx);
rig_sprintf_ant(antbuf, ant_tx);
fprintf(fout, "%s%c", antbuf, resp_sep);
//fprintf(fout, "%d%c", rig_setting2idx(ant_tx)+1, resp_sep);
@ -4199,7 +4199,7 @@ declare_proto_rig(get_ant)
fprintf(fout, "%s: ", cmd->arg4);
}
sprintf_ant(antbuf, ant_rx);
rig_sprintf_ant(antbuf, ant_rx);
fprintf(fout, "%s%c", antbuf, resp_sep);
//fprintf(fout, "%d%c", rig_setting2idx(ant_rx)+1, resp_sep);

Wyświetl plik

@ -24,6 +24,8 @@
*
*/
// TODO: Add "symmetric" set_conf + get_conf to rigctl+rotctl
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
@ -83,6 +85,7 @@ extern int read_history();
#endif
#include "rotctl_parse.h"
#include "sprintflst.h"
/* Hash table implementation See: http://uthash.sourceforge.net/ */
#include "uthash.h"
@ -155,7 +158,7 @@ struct test_table
#define CHKSCN1ARG(a) if ((a) != 1) return -RIG_EINVAL; else do {} while(0)
#define ACTION(f) rigctl_##f
#define ACTION(f) rotctl_##f
#define declare_proto_rot(f) static int (ACTION(f))(ROT *rot, \
FILE *fout, \
int interactive, \
@ -177,7 +180,14 @@ declare_proto_rot(stop);
declare_proto_rot(park);
declare_proto_rot(reset);
declare_proto_rot(move);
declare_proto_rot(set_level);
declare_proto_rot(get_level);
declare_proto_rot(set_func);
declare_proto_rot(get_func);
declare_proto_rot(set_parm);
declare_proto_rot(get_parm);
declare_proto_rot(get_info);
declare_proto_rot(get_status);
declare_proto_rot(inter_set_conf); /* interactive mode set_conf */
declare_proto_rot(send_cmd);
declare_proto_rot(dump_state);
@ -207,8 +217,15 @@ struct test_table test_list[] =
{ 'S', "stop", ACTION(stop), ARG_NONE, },
{ 'R', "reset", ACTION(reset), ARG_IN, "Reset" },
{ 'M', "move", ACTION(move), ARG_IN, "Direction", "Speed" },
{ 'V', "set_level", ACTION(set_level), ARG_IN, "Level", "Level Value" },
{ 'v', "get_level", ACTION(get_level), ARG_IN1 | ARG_OUT2, "Level", "Level Value" },
{ 'U', "set_func", ACTION(set_func), ARG_IN, "Func", "Func Status" },
{ 'u', "get_func", ACTION(get_func), ARG_IN1 | ARG_OUT2, "Func", "Func Status" },
{ 'X', "set_parm", ACTION(set_parm), ARG_IN, "Parm", "Parm Value" },
{ 'x', "get_parm", ACTION(get_parm), ARG_IN1 | ARG_OUT2, "Parm", "Parm Value" },
{ 'C', "set_conf", ACTION(inter_set_conf), ARG_IN, "Token", "Value" },
{ '_', "get_info", ACTION(get_info), ARG_OUT, "Info" },
{ 's', "get_status", ACTION(get_status), ARG_OUT, "Status flags" },
{ 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2, "Cmd", "Reply" },
{ '1', "dump_caps", ACTION(dump_caps), },
{ 0x8f, "dump_state", ACTION(dump_state), ARG_OUT },
@ -1714,7 +1731,7 @@ declare_proto_rot(set_position)
CHKSCN1ARG(sscanf(arg1, "%f", &az));
CHKSCN1ARG(sscanf(arg2, "%f", &el));
return rot_set_position(rot, az + rot->state.az_offset, el);
return rot_set_position(rot, az, el);
}
@ -1727,8 +1744,6 @@ declare_proto_rot(get_position)
status = rot_get_position(rot, &az, &el);
az -= rot->state.az_offset;
if (status != RIG_OK)
{
return status;
@ -1794,6 +1809,32 @@ declare_proto_rot(get_info)
}
/* 's' */
declare_proto_rot(get_status)
{
int result;
rot_status_t status;
char s[SPRINTF_MAX_SIZE];
result = rot_get_status(rot, &status);
if (result != RIG_OK)
{
return result;
}
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
{
fprintf(fout, "%s: ", cmd->arg1);
}
rot_sprintf_status(s, status);
fprintf(fout, "%s%c", s, resp_sep);
return RIG_OK;
}
/* 'M' */
declare_proto_rot(move)
{
@ -1826,6 +1867,467 @@ declare_proto_rot(move)
}
/*
* 'V'
*/
declare_proto_rot(set_level)
{
setting_t level;
value_t val;
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
rot_sprintf_level(s, rot->state.has_set_level);
fputs(s, fout);
if (rot->caps->set_ext_level)
{
sprintf_level_ext(s, rot->caps->extlevels);
fputs(s, fout);
}
fputc('\n', fout);
return RIG_OK;
}
level = rot_parse_level(arg1);
if (!rot_has_set_level(rot, level))
{
const struct confparams *cfp;
cfp = rot_ext_lookup(rot, arg1);
if (!cfp)
{
return -RIG_ENAVAIL; /* no such parameter */
}
switch (cfp->type)
{
case RIG_CONF_BUTTON:
/* arg is ignored */
val.i = 0; // avoid passing uninitialized data
break;
case RIG_CONF_CHECKBUTTON:
case RIG_CONF_COMBO:
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
break;
case RIG_CONF_NUMERIC:
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
break;
case RIG_CONF_STRING:
val.cs = arg2;
break;
default:
return -RIG_ECONF;
}
return rot_set_ext_level(rot, cfp->token, val);
}
if (ROT_LEVEL_IS_FLOAT(level))
{
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
}
else
{
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
}
return rot_set_level(rot, level, val);
}
/* 'v' */
declare_proto_rot(get_level)
{
int status;
setting_t level;
value_t val;
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
rot_sprintf_level(s, rot->state.has_get_level);
fputs(s, fout);
if (rot->caps->get_ext_level)
{
sprintf_level_ext(s, rot->caps->extlevels);
fputs(s, fout);
}
fputc('\n', fout);
return RIG_OK;
}
level = rot_parse_level(arg1);
if (!rot_has_get_level(rot, level))
{
const struct confparams *cfp;
cfp = rot_ext_lookup(rot, arg1);
if (!cfp)
{
return -RIG_EINVAL; /* no such parameter */
}
status = rot_get_ext_level(rot, cfp->token, &val);
if (status != RIG_OK)
{
return status;
}
if (interactive && prompt)
{
fprintf(fout, "%s: ", cmd->arg2);
}
switch (cfp->type)
{
case RIG_CONF_BUTTON:
/* there's no sense in retrieving value of stateless button */
return -RIG_EINVAL;
case RIG_CONF_CHECKBUTTON:
case RIG_CONF_COMBO:
fprintf(fout, "%d\n", val.i);
break;
case RIG_CONF_NUMERIC:
fprintf(fout, "%f\n", val.f);
break;
case RIG_CONF_STRING:
fprintf(fout, "%s\n", val.s);
break;
default:
return -RIG_ECONF;
}
return status;
}
status = rot_get_level(rot, level, &val);
if (status != RIG_OK)
{
return status;
}
if (interactive && prompt)
{
fprintf(fout, "%s: ", cmd->arg2);
}
if (ROT_LEVEL_IS_FLOAT(level))
{
fprintf(fout, "%f\n", val.f);
}
else
{
fprintf(fout, "%d\n", val.i);
}
return status;
}
/* 'U' */
declare_proto_rot(set_func)
{
setting_t func;
int func_stat;
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
rot_sprintf_func(s, rot->state.has_set_func);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
func = rot_parse_func(arg1);
if (!rot_has_set_func(rot, func))
{
const struct confparams *cfp;
cfp = rot_ext_lookup(rot, arg1);
if (!cfp)
{
return -RIG_ENAVAIL; /* no such parameter */
}
CHKSCN1ARG(sscanf(arg2, "%d", &func_stat));
return rot_set_ext_func(rot, cfp->token, func_stat);
}
CHKSCN1ARG(sscanf(arg2, "%d", &func_stat));
return rot_set_func(rot, func, func_stat);
}
/* 'u' */
declare_proto_rot(get_func)
{
int status;
setting_t func;
int func_stat;
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
rot_sprintf_func(s, rot->state.has_get_func);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
func = rot_parse_func(arg1);
if (!rot_has_get_func(rot, func))
{
const struct confparams *cfp;
cfp = rot_ext_lookup(rot, arg1);
if (!cfp)
{
return -RIG_EINVAL; /* no such parameter */
}
status = rot_get_ext_func(rot, cfp->token, &func_stat);
if (status != RIG_OK)
{
return status;
}
if (interactive && prompt)
{
fprintf(fout, "%s: ", cmd->arg2);
}
fprintf(fout, "%d\n", func_stat);
return status;
}
status = rot_get_func(rot, func, &func_stat);
if (status != RIG_OK)
{
return status;
}
if (interactive && prompt)
{
fprintf(fout, "%s: ", cmd->arg2);
}
fprintf(fout, "%d\n", func_stat);
return status;
}
/* 'R' */
declare_proto_rot(set_parm)
{
setting_t parm;
value_t val;
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
rot_sprintf_parm(s, rot->state.has_set_parm);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
parm = rot_parse_parm(arg1);
if (!rot_has_set_parm(rot, parm))
{
const struct confparams *cfp;
cfp = rot_ext_lookup(rot, arg1);
if (!cfp)
{
return -RIG_EINVAL; /* no such parameter */
}
switch (cfp->type)
{
case RIG_CONF_BUTTON:
/* arg is ignored */
val.i = 0; // avoid passing uninitialized data
break;
case RIG_CONF_CHECKBUTTON:
case RIG_CONF_COMBO:
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
break;
case RIG_CONF_NUMERIC:
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
break;
case RIG_CONF_STRING:
val.cs = arg2;
break;
case RIG_CONF_BINARY:
val.b.d = (unsigned char *)arg2;
break;
default:
return -RIG_ECONF;
}
return rot_set_ext_parm(rot, cfp->token, val);
}
if (ROT_PARM_IS_FLOAT(parm))
{
CHKSCN1ARG(sscanf(arg2, "%f", &val.f));
}
else
{
CHKSCN1ARG(sscanf(arg2, "%d", &val.i));
}
return rot_set_parm(rot, parm, val);
}
/* 'r' */
declare_proto_rot(get_parm)
{
int status;
setting_t parm;
value_t val;
char buffer[RIG_BIN_MAX];
if (!strcmp(arg1, "?"))
{
char s[SPRINTF_MAX_SIZE];
rot_sprintf_parm(s, rot->state.has_get_parm);
fprintf(fout, "%s\n", s);
return RIG_OK;
}
parm = rot_parse_parm(arg1);
if (!rot_has_get_parm(rot, parm))
{
const struct confparams *cfp;
cfp = rot_ext_lookup(rot, arg1);
if (!cfp)
{
return -RIG_EINVAL; /* no such parameter */
}
switch (cfp->type)
{
case RIG_CONF_STRING:
memset(buffer, '0', sizeof(buffer));
buffer[sizeof(buffer) - 1] = 0;
val.s = buffer;
break;
case RIG_CONF_BINARY:
memset(buffer, 0, sizeof(buffer));
val.b.d = (unsigned char *)buffer;
val.b.l = RIG_BIN_MAX;
break;
default:
break;
}
status = rot_get_ext_parm(rot, cfp->token, &val);
if (status != RIG_OK)
{
return status;
}
if (interactive && prompt)
{
fprintf(fout, "%s: ", cmd->arg2);
}
switch (cfp->type)
{
case RIG_CONF_BUTTON:
/* there's not sense in retrieving value of stateless button */
return -RIG_EINVAL;
case RIG_CONF_CHECKBUTTON:
case RIG_CONF_COMBO:
fprintf(fout, "%d\n", val.i);
break;
case RIG_CONF_NUMERIC:
fprintf(fout, "%f\n", val.f);
break;
case RIG_CONF_STRING:
fprintf(fout, "%s\n", val.s);
break;
case RIG_CONF_BINARY:
dump_hex((unsigned char *)buffer, val.b.l);
break;
default:
return -RIG_ECONF;
}
return status;
}
status = rot_get_parm(rot, parm, &val);
if (status != RIG_OK)
{
return status;
}
if (interactive && prompt)
{
fprintf(fout, "%s: ", cmd->arg2);
}
if (ROT_PARM_IS_FLOAT(parm))
{
fprintf(fout, "%f\n", val.f);
}
else
{
fprintf(fout, "%d\n", val.i);
}
return status;
}
/* 'C' */
declare_proto_rot(inter_set_conf)
{

Wyświetl plik

@ -24,15 +24,11 @@
# include "config.h"
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <sys/types.h>
#include <unistd.h>
#include <hamlib/rig.h>
#include <hamlib/rotator.h>
#include <hamlib/amplifier.h>
#include "sprintflst.h"
@ -41,7 +37,7 @@
/* #define DUMMY_ALL 0x7ffffffffffffffLL */
#define DUMMY_ALL ((setting_t)-1)
int sprintf_vfo(char *str, vfo_t vfo)
int rig_sprintf_vfo(char *str, vfo_t vfo)
{
unsigned int i, len = 0;
@ -68,7 +64,7 @@ int sprintf_vfo(char *str, vfo_t vfo)
}
int sprintf_mode(char *str, rmode_t mode)
int rig_sprintf_mode(char *str, rmode_t mode)
{
uint64_t i, len = 0;
@ -97,7 +93,7 @@ int sprintf_mode(char *str, rmode_t mode)
}
int sprintf_ant(char *str, ant_t ant)
int rig_sprintf_ant(char *str, ant_t ant)
{
int i, len = 0;
char *ant_name;
@ -144,7 +140,7 @@ int sprintf_ant(char *str, ant_t ant)
}
int sprintf_func(char *str, setting_t func)
int rig_sprintf_func(char *str, setting_t func)
{
uint64_t i, len = 0;
@ -173,7 +169,36 @@ int sprintf_func(char *str, setting_t func)
}
int sprintf_level(char *str, setting_t level)
int rot_sprintf_func(char *str, setting_t func)
{
uint64_t i, len = 0;
*str = '\0';
if (func == ROT_FUNC_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rot_strfunc(func & rig_idx2setting(i));
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
}
int rig_sprintf_level(char *str, setting_t level)
{
int i, len = 0;
@ -201,7 +226,37 @@ int sprintf_level(char *str, setting_t level)
return len;
}
int sprintf_level_amp(char *str, setting_t level)
int rot_sprintf_level(char *str, setting_t level)
{
int i, len = 0;
*str = '\0';
if (level == ROT_LEVEL_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rot_strlevel(level & rig_idx2setting(i));
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
}
int amp_sprintf_level(char *str, setting_t level)
{
int i, len = 0;
@ -270,7 +325,7 @@ int sprintf_level_ext(char *str, const struct confparams *extlevels)
}
int sprintf_level_gran(char *str, setting_t level, const gran_t gran[])
int rig_sprintf_level_gran(char *str, setting_t level, const gran_t *gran)
{
int i, len = 0;
@ -326,7 +381,63 @@ int sprintf_level_gran(char *str, setting_t level, const gran_t gran[])
}
int sprintf_parm(char *str, setting_t parm)
int rot_sprintf_level_gran(char *str, setting_t level, const gran_t *gran)
{
int i, len = 0;
*str = '\0';
if (level == ROT_LEVEL_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms;
if (!(level & rig_idx2setting(i)))
{
continue;
}
ms = rot_strlevel(level & rig_idx2setting(i));
if (!ms || !ms[0])
{
if (level != DUMMY_ALL && level != ROT_LEVEL_SET(DUMMY_ALL))
{
rig_debug(RIG_DEBUG_BUG, "unknown level idx %d\n", i);
}
continue;
}
if (ROT_LEVEL_IS_FLOAT(rig_idx2setting(i)))
{
len += sprintf(str + len,
"%s(%g..%g/%g) ",
ms,
gran[i].min.f,
gran[i].max.f,
gran[i].step.f);
}
else
{
len += sprintf(str + len,
"%s(%d..%d/%d) ",
ms,
gran[i].min.i,
gran[i].max.i,
gran[i].step.i);
}
}
return len;
}
int rig_sprintf_parm(char *str, setting_t parm)
{
int i, len = 0;
@ -355,7 +466,36 @@ int sprintf_parm(char *str, setting_t parm)
}
int sprintf_parm_gran(char *str, setting_t parm, const gran_t gran[])
int rot_sprintf_parm(char *str, setting_t parm)
{
int i, len = 0;
*str = '\0';
if (parm == ROT_PARM_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms = rot_strparm(parm & rig_idx2setting(i));
if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
strcat(str, ms);
strcat(str, " ");
len += strlen(ms) + 1;
}
return len;
}
int rig_sprintf_parm_gran(char *str, setting_t parm, const gran_t *gran)
{
int i, len = 0;
@ -411,7 +551,63 @@ int sprintf_parm_gran(char *str, setting_t parm, const gran_t gran[])
}
int sprintf_vfop(char *str, vfo_op_t op)
int rot_sprintf_parm_gran(char *str, setting_t parm, const gran_t *gran)
{
int i, len = 0;
*str = '\0';
if (parm == ROT_PARM_NONE)
{
return 0;
}
for (i = 0; i < RIG_SETTING_MAX; i++)
{
const char *ms;
if (!(parm & rig_idx2setting(i)))
{
continue;
}
ms = rot_strparm(parm & rig_idx2setting(i));
if (!ms || !ms[0])
{
if (parm != DUMMY_ALL && parm != ROT_PARM_SET(DUMMY_ALL))
{
rig_debug(RIG_DEBUG_BUG, "unknown parm idx %d\n", i);
}
continue;
}
if (ROT_PARM_IS_FLOAT(rig_idx2setting(i)))
{
len += sprintf(str + len,
"%s(%g..%g/%g) ",
ms,
gran[i].min.f,
gran[i].max.f,
gran[i].step.f);
}
else
{
len += sprintf(str + len,
"%s(%d..%d/%d) ",
ms,
gran[i].min.i,
gran[i].max.i,
gran[i].step.i);
}
}
return len;
}
int rig_sprintf_vfop(char *str, vfo_op_t op)
{
int i, len = 0;
@ -440,7 +636,7 @@ int sprintf_vfop(char *str, vfo_op_t op)
}
int sprintf_scan(char *str, scan_t rscan)
int rig_sprintf_scan(char *str, scan_t rscan)
{
int i, len = 0;
@ -468,6 +664,34 @@ int sprintf_scan(char *str, scan_t rscan)
return len;
}
int rot_sprintf_status(char *str, rot_status_t status)
{
int i, len = 0;
rig_debug(RIG_DEBUG_TRACE, "%s: status=%08x\n", __func__, status);
*str = '\0';
if (status == ROT_STATUS_NONE)
{
return 0;
}
for (i = 0; i < 32; i++)
{
const char *sv;
sv = rot_strstatus(status & ROT_STATUS_N(i));
if (sv && sv[0] && (strstr(sv, "None") == 0))
{
len += sprintf(str + len, "%s ", sv);
}
}
return len;
}
char *get_rig_conf_type(enum rig_conf_e type)
{
switch (type)
@ -493,3 +717,38 @@ char *get_rig_conf_type(enum rig_conf_e type)
return "UNKNOWN";
}
int print_ext_param(const struct confparams *cfp, rig_ptr_t ptr)
{
int i;
fprintf((FILE *)ptr, "\t%s\n", cfp->name);
fprintf((FILE *)ptr, "\t\tType: %s\n", get_rig_conf_type(cfp->type));
fprintf((FILE *)ptr, "\t\tDefault: %s\n", cfp->dflt != NULL ? cfp->dflt : "");
fprintf((FILE *)ptr, "\t\tLabel: %s\n", cfp->label != NULL ? cfp->label : "");
fprintf((FILE *)ptr, "\t\tTooltip: %s\n",
cfp->tooltip != NULL ? cfp->tooltip : "");
switch (cfp->type)
{
case RIG_CONF_NUMERIC:
fprintf((FILE *)ptr, "\t\tRange: %g..%g/%g\n", cfp->u.n.min, cfp->u.n.max,
cfp->u.n.step);
break;
case RIG_CONF_COMBO:
fprintf((FILE *)ptr, "\t\tValues:");
for (i = 0; i < RIG_COMBO_MAX && cfp->u.c.combostr[i] != NULL; i++)
{
fprintf((FILE *)ptr, " %d=\"%s\"", i, cfp->u.c.combostr[i]);
}
fprintf((FILE *)ptr, "\n");
break;
default:
break;
}
return 1; /* process them all */
}

Wyświetl plik

@ -23,24 +23,32 @@
#define _SPRINTFLST_H 1
#include <hamlib/rig.h>
#include <hamlib/rotator.h>
#define SPRINTF_MAX_SIZE 512
__BEGIN_DECLS
extern int sprintf_mode(char *str, rmode_t);
extern int sprintf_vfo(char *str, vfo_t);
extern int sprintf_ant(char *str, ant_t);
extern int sprintf_func(char *str, setting_t);
extern int sprintf_level(char *str, setting_t);
extern int sprintf_level_amp(char *str, setting_t);
extern int sprintf_level_ext(char *str, const struct confparams *);
extern int sprintf_level_gran(char *str, setting_t, const gran_t gran[]);
extern int sprintf_parm(char *str, setting_t);
extern int sprintf_parm_gran(char *str, setting_t, const gran_t gran[]);
extern int sprintf_vfop(char *str, vfo_op_t);
extern int sprintf_scan(char *str, scan_t);
extern int rig_sprintf_mode(char *str, rmode_t mode);
extern int rig_sprintf_vfo(char *str, vfo_t vfo);
extern int rig_sprintf_ant(char *str, ant_t ant);
extern int rig_sprintf_func(char *str, setting_t func);
extern int rot_sprintf_func(char *str, setting_t func);
extern int rig_sprintf_level(char *str, setting_t level);
extern int rot_sprintf_level(char *str, setting_t level);
extern int amp_sprintf_level(char *str, setting_t level);
extern int sprintf_level_ext(char *str, const struct confparams *extlevels);
extern int rig_sprintf_level_gran(char *str, setting_t level, const gran_t *gran);
extern int rot_sprintf_level_gran(char *str, setting_t level, const gran_t *gran);
extern int rig_sprintf_parm(char *str, setting_t parm);
extern int rot_sprintf_parm(char *str, setting_t parm);
extern int rig_sprintf_parm_gran(char *str, setting_t parm, const gran_t *gran);
extern int rot_sprintf_parm_gran(char *str, setting_t parm, const gran_t *gran);
extern int rig_sprintf_vfop(char *str, vfo_op_t op);
extern int rig_sprintf_scan(char *str, scan_t rscan);
extern int rot_sprintf_status(char *str, rot_status_t status);
extern char *get_rig_conf_type(enum rig_conf_e type);
int print_ext_param(const struct confparams *cfp, rig_ptr_t ptr);
__END_DECLS