Implement funcs, levels and parms + the ext variants for rotators. Add option to not change rotator speed when using the move command. Add rotator status flags. Work in progress.

pull/453/head
Mikael Nousiainen 2020-11-24 21:51:10 +02:00
rodzic ac2892913c
commit a48f149955
31 zmienionych plików z 3129 dodań i 222 usunięć

Wyświetl plik

@ -388,11 +388,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

@ -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

@ -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 */
@ -2770,13 +2770,22 @@ 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);
extern HAMLIB_EXPORT(rptr_shift_t) rig_parse_rptr_shift(const char *s);
extern HAMLIB_EXPORT(chan_type_t) rig_parse_mtype(const char *s);
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(setting_t) amp_parse_level(const char *s);
extern HAMLIB_EXPORT(const char *) amp_strlevel(setting_t);
extern HAMLIB_EXPORT(const char *) rig_license HAMLIB_PARAMS(());
extern HAMLIB_EXPORT(const char *) rig_version HAMLIB_PARAMS(());
extern HAMLIB_EXPORT(const char *) rig_copyright HAMLIB_PARAMS(());

Wyświetl plik

@ -196,6 +196,94 @@ typedef enum {
#define ROT_MOVE_CW ROT_MOVE_RIGHT
/**
* \brief Rotator status flags
*/
typedef enum {
ROT_STATUS_BUSY = (1 << 1), /*!< Rotator is busy, not accepting commands */
ROT_STATUS_MOVING = (1 << 2), /*!< Rotator is currently moving (direction type not specified) */
ROT_STATUS_MOVING_AZ = (1 << 3), /*!< Azimuth rotator is currently moving */
ROT_STATUS_MOVING_EL = (1 << 4), /*!< Elevation rotator is currently moving */
ROT_STATUS_UP_LIMIT = (1 << 5), /*!< The elevation rotator has reached its limit to move up */
ROT_STATUS_DOWN_LIMIT = (1 << 6), /*!< The elevation rotator has reached its limit to move down */
ROT_STATUS_LEFT_LIMIT = (1 << 7), /*!< The azimuth rotator has reached its limit to move left (CCW) */
ROT_STATUS_RIGHT_LIMIT = (1 << 8), /*!< The azimuth rotator has reached its limit to move right (CW) */
ROT_STATUS_UP_OVERLAP = (1 << 9), /*!< The elevation rotator has rotated up past 360 degrees */
ROT_STATUS_DOWN_OVERLAP = (1 << 10), /*!< The elevation rotator has rotated down past 0 degrees */
ROT_STATUS_LEFT_OVERLAP = (1 << 11), /*!< The azimuth rotator has rotated left (CCW) past 0 degrees */
ROT_STATUS_RIGHT_OVERLAP = (1 << 12), /*!< The azimuth rotator has rotated right (CW) past 360 degrees */
} rot_status_t;
/**
* \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 (1-100) */
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 +303,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 +331,21 @@ 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 */
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 +359,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,7 +391,29 @@ 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);
const char *macro_name; /*!< Macro name. */
rot_status_t status_caps; /*!< Supported status flags */
rot_status_t (*get_status)(ROT *rot);
/* more to come... */
};
//! @endcond
@ -318,6 +442,16 @@ 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 */
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 +461,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,6 +536,81 @@ 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));
@ -441,6 +651,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));

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 - shard 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,19 @@
#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 "rot_dummy.h"
#define DUMMY_ROT_FUNC 0
#define DUMMY_ROT_LEVEL ROT_LEVEL_SPEED
#define DUMMY_ROT_PARM 0
struct dummy_rot_priv_data
{
azimuth_t az;
@ -45,8 +46,66 @@ struct dummy_rot_priv_data
struct timeval tv; /* time last az/el update */
azimuth_t target_az;
elevation_t target_el;
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 +124,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 +192,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 *)
@ -264,6 +399,443 @@ 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;
}
/*
@ -288,13 +860,27 @@ 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_LEVEL_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,
.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,6 +889,20 @@ const struct rot_caps dummy_rot_caps =
.reset = dummy_rot_reset,
.move = dummy_rot_move,
.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,
};

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

@ -250,34 +250,44 @@ easycomm_rot_move(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 - 1) * 100);
} 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;
easycomm_speed = ((speed - 1) * 100);
}
/* 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:
@ -527,7 +537,7 @@ const struct rot_caps easycomm3_rot_caps =
ROT_MODEL(ROT_MODEL_EASYCOMM3),
.model_name = "EasycommIII",
.mfg_name = "Hamlib",
.version = "20191206.0",
.version = "20201118.0",
.copyright = "LGPL",
.status = RIG_STATUS_ALPHA,
.rot_type = ROT_TYPE_OTHER,

Wyświetl plik

@ -263,19 +263,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);

Wyświetl plik

@ -230,6 +230,7 @@ gs232a_rot_stop(ROT *rot)
static int
gs232a_rot_move(ROT *rot, int direction, int speed)
{
struct rot_state *rs = &rot->state;
char cmdstr[24];
int retval;
unsigned x_speed;
@ -237,15 +238,25 @@ gs232a_rot_move(ROT *rot, int direction, int 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) {
if (speed < 1 || speed > 100)
{
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value (1-100)! (%d)\n", __func__, speed);
return -RIG_EINVAL;
}
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1);
x_speed = (3 * speed) / 100 + 1;
if (retval != RIG_OK)
{
return retval;
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1);
if (retval != RIG_OK)
{
return retval;
}
rs->current_speed = speed;
}
switch (direction)

Wyświetl plik

@ -267,6 +267,7 @@ gs232b_rot_stop(ROT *rot)
static int
gs232b_rot_move(ROT *rot, int direction, int speed)
{
struct rot_state *rs = &rot->state;
char cmdstr[24];
int retval;
unsigned x_speed;
@ -274,15 +275,25 @@ gs232b_rot_move(ROT *rot, int direction, int 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) {
if (speed < 1 || speed > 100)
{
rig_debug(RIG_DEBUG_ERR, "%s: Invalid speed value (1-100)! (%d)\n", __func__, speed);
return -RIG_EINVAL;
}
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232b_transaction(rot, cmdstr, NULL, 0, 1);
x_speed = (3 * speed) / 100 + 1;
if (retval != RIG_OK)
{
return retval;
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232b_transaction(rot, cmdstr, NULL, 0, 1);
if (retval != RIG_OK)
{
return retval;
}
rs->current_speed = speed;
}
switch (direction)

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

@ -52,6 +52,7 @@
#include <math.h>
#include <hamlib/rig.h>
#include <hamlib/rotator.h>
#include <hamlib/amplifier.h>
#include "misc.h"
@ -572,7 +573,7 @@ static struct
{
setting_t func;
const char *str;
} func_str[] =
} rig_func_str[] =
{
{ RIG_FUNC_FAGC, "FAGC" },
{ RIG_FUNC_NB, "NB" },
@ -618,6 +619,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 +652,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 +664,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 +708,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 +755,7 @@ static struct
{
setting_t level;
const char *str;
} level_str[] =
} rig_level_str[] =
{
{ RIG_LEVEL_PREAMP, "PREAMP" },
{ RIG_LEVEL_ATT, "ATT" },
@ -730,11 +798,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 +841,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 +892,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 +927,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 +987,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 +1003,7 @@ static struct
{
setting_t parm;
const char *str;
} parm_str[] =
} rig_parm_str[] =
{
{ RIG_PARM_ANN, "ANN" },
{ RIG_PARM_APO, "APO" },
@ -880,6 +1017,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 +1040,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 +1052,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 +1095,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;
}
}

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,20 @@ 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;
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,

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

@ -328,16 +328,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 +356,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 +368,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 +386,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 +398,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 +408,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 +610,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 +642,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);
}
@ -883,17 +883,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

@ -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,6 +180,12 @@ 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(inter_set_conf); /* interactive mode set_conf */
declare_proto_rot(send_cmd);
@ -207,6 +216,12 @@ 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" },
{ 'w', "send_cmd", ACTION(send_cmd), ARG_IN1 | ARG_IN_LINE | ARG_OUT2, "Cmd", "Reply" },
@ -1823,6 +1838,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,7 @@ int sprintf_scan(char *str, scan_t rscan)
return len;
}
char *get_rig_conf_type(enum rig_conf_e type)
{
switch (type)

Wyświetl plik

@ -28,18 +28,23 @@
__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 char *get_rig_conf_type(enum rig_conf_e type);
__END_DECLS