2002-07-09 20:36:07 +00:00
|
|
|
/*
|
2020-11-24 19:51:10 +00:00
|
|
|
* Hamlib Interface - rig ext parameter interface
|
2008-04-11 14:12:26 +00:00
|
|
|
* Copyright (c) 2000-2008 by Stephane Fillod
|
2002-07-09 20:36:07 +00:00
|
|
|
*
|
|
|
|
*
|
2011-08-22 01:07:57 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2002-07-09 20:36:07 +00:00
|
|
|
*
|
2011-08-22 01:07:57 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2002-07-09 20:36:07 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-08-22 01:07:57 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2002-07-09 20:36:07 +00:00
|
|
|
*
|
2011-08-22 01:07:57 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2002-07-09 20:36:07 +00:00
|
|
|
* License along with this library; if not, write to the Free Software
|
2011-08-22 01:07:57 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-07-09 20:36:07 +00:00
|
|
|
*
|
|
|
|
*/
|
2017-08-05 14:09:12 +00:00
|
|
|
|
2006-10-15 00:27:52 +00:00
|
|
|
/**
|
2006-10-28 03:49:46 +00:00
|
|
|
* \addtogroup rig
|
|
|
|
* @{
|
2006-10-15 00:27:52 +00:00
|
|
|
*/
|
|
|
|
|
2006-10-28 03:49:46 +00:00
|
|
|
/**
|
|
|
|
* \file ext.c
|
|
|
|
* \brief Extension request parameter interface
|
|
|
|
*
|
2020-02-11 09:48:13 +00:00
|
|
|
* An open-ended set of extension parameters, functions and levels are available
|
|
|
|
* for each rig, as provided in the rigcaps extparms, extfuncs and extlevels lists.
|
|
|
|
* These provide a way to work with rig-specific functions that don't fit into the
|
2017-10-05 02:32:08 +00:00
|
|
|
* basic "virtual rig" of Hamlib. See icom/ic746.c for an example.
|
2006-10-28 03:49:46 +00:00
|
|
|
*/
|
2002-07-09 20:36:07 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2017-10-05 02:32:08 +00:00
|
|
|
# include "config.h"
|
2002-07-09 20:36:07 +00:00
|
|
|
#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 <hamlib/rig.h>
|
|
|
|
|
|
|
|
#include "token.h"
|
|
|
|
|
2020-09-16 15:10:35 +00:00
|
|
|
static int rig_has_ext_token(RIG *rig, token_t token)
|
|
|
|
{
|
|
|
|
int *ext_tokens = rig->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++)
|
|
|
|
{
|
2020-10-02 03:51:31 +00:00
|
|
|
if (ext_tokens[i] == token)
|
|
|
|
{
|
2020-09-16 15:10:35 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \param rig The rig 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
|
|
|
|
* rig_ext_func_foreach.
|
|
|
|
*/
|
|
|
|
int HAMLIB_API rig_ext_func_foreach(RIG *rig,
|
2020-10-02 03:51:31 +00:00
|
|
|
int (*cfunc)(RIG *,
|
|
|
|
const struct confparams *,
|
|
|
|
rig_ptr_t),
|
|
|
|
rig_ptr_t data)
|
2020-09-16 15:10:35 +00:00
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
if (!rig || !rig->caps || !cfunc)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = rig->caps->extfuncs; cfp && cfp->name; cfp++)
|
|
|
|
{
|
2020-10-02 03:51:31 +00:00
|
|
|
if (!rig_has_ext_token(rig, cfp->token))
|
|
|
|
{
|
2020-09-16 15:10:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = (*cfunc)(rig, cfp, data);
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2006-10-28 03:49:46 +00:00
|
|
|
/**
|
2008-04-11 14:12:26 +00:00
|
|
|
* \param rig The rig 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
|
2017-10-05 02:32:08 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* rig_ext_level_foreach.
|
2008-04-11 14:12:26 +00:00
|
|
|
*/
|
2017-08-05 14:09:12 +00:00
|
|
|
int HAMLIB_API rig_ext_level_foreach(RIG *rig,
|
|
|
|
int (*cfunc)(RIG *,
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams *,
|
|
|
|
rig_ptr_t),
|
2017-08-05 14:09:12 +00:00
|
|
|
rig_ptr_t data)
|
2002-07-09 20:36:07 +00:00
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (!rig || !rig->caps || !cfunc)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++)
|
|
|
|
{
|
2020-10-02 03:51:31 +00:00
|
|
|
if (!rig_has_ext_token(rig, cfp->token))
|
|
|
|
{
|
2020-09-16 15:10:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-08 22:35:55 +00:00
|
|
|
int ret = (*cfunc)(rig, cfp, data);
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (ret == 0)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
2002-07-09 20:36:07 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 14:09:12 +00:00
|
|
|
|
2006-10-28 03:49:46 +00:00
|
|
|
/**
|
2008-04-11 14:12:26 +00:00
|
|
|
* \param rig The rig handle
|
|
|
|
* \param cfunc callback function of each extparm
|
|
|
|
* \param data cookie to be passed to \a cfunc callback
|
2006-10-28 03:49:46 +00:00
|
|
|
* \brief Executes cfunc on all the elements stored in the extparms table
|
2017-10-05 02:32:08 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* rig_ext_parm_foreach.
|
2002-07-09 20:36:07 +00:00
|
|
|
*/
|
2017-08-05 14:09:12 +00:00
|
|
|
int HAMLIB_API rig_ext_parm_foreach(RIG *rig,
|
|
|
|
int (*cfunc)(RIG *,
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams *,
|
|
|
|
rig_ptr_t),
|
2017-08-05 14:09:12 +00:00
|
|
|
rig_ptr_t data)
|
2002-07-09 20:36:07 +00:00
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
const struct confparams *cfp;
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-08-05 14:09:12 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (!rig || !rig->caps || !cfunc)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
|
|
|
|
{
|
2020-10-02 03:51:31 +00:00
|
|
|
if (!rig_has_ext_token(rig, cfp->token))
|
|
|
|
{
|
2020-09-16 15:10:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-08 22:35:55 +00:00
|
|
|
int ret = (*cfunc)(rig, cfp, data);
|
2017-08-05 14:09:12 +00:00
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (ret == 0)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
2002-07-09 20:36:07 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 14:09:12 +00:00
|
|
|
|
2006-10-28 03:49:46 +00:00
|
|
|
/**
|
|
|
|
* \param rig
|
|
|
|
* \param name
|
|
|
|
* \brief lookup ext token by its name, return pointer to confparams struct.
|
2002-07-09 20:36:07 +00:00
|
|
|
*
|
2020-02-11 09:48:13 +00:00
|
|
|
* Lookup extlevels table, then extfuncs, then extparms.
|
2002-07-09 20:36:07 +00:00
|
|
|
*
|
|
|
|
* Returns NULL if nothing found
|
2006-10-28 03:49:46 +00:00
|
|
|
*
|
2002-07-09 20:36:07 +00:00
|
|
|
* TODO: should use Lex to speed it up, strcmp hurts!
|
|
|
|
*/
|
2017-10-05 02:32:08 +00:00
|
|
|
const struct confparams *HAMLIB_API rig_ext_lookup(RIG *rig, const char *name)
|
2002-07-09 20:36:07 +00:00
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (!rig || !rig->caps)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++)
|
2017-10-05 02:32:08 +00:00
|
|
|
{
|
|
|
|
if (!strcmp(cfp->name, name))
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return cfp;
|
|
|
|
}
|
2017-10-05 02:32:08 +00:00
|
|
|
}
|
2017-08-05 14:09:12 +00:00
|
|
|
|
2020-02-11 09:48:13 +00:00
|
|
|
for (cfp = rig->caps->extfuncs; cfp && cfp->name; cfp++)
|
|
|
|
{
|
|
|
|
if (!strcmp(cfp->name, name))
|
|
|
|
{
|
|
|
|
return cfp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 14:09:12 +00:00
|
|
|
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
|
2017-10-05 02:32:08 +00:00
|
|
|
{
|
|
|
|
if (!strcmp(cfp->name, name))
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return cfp;
|
|
|
|
}
|
2017-10-05 02:32:08 +00:00
|
|
|
}
|
2017-08-05 14:09:12 +00:00
|
|
|
|
|
|
|
return NULL;
|
2002-07-09 20:36:07 +00:00
|
|
|
}
|
|
|
|
|
2006-10-28 03:49:46 +00:00
|
|
|
/**
|
|
|
|
* \param rig
|
|
|
|
* \param token
|
|
|
|
* \brief lookup ext token, return pointer to confparams struct.
|
2006-09-22 19:55:59 +00:00
|
|
|
*
|
2020-09-16 15:10:35 +00:00
|
|
|
* lookup extlevels table first, then extfuncs, then fall back to extparms.
|
2006-09-22 19:55:59 +00:00
|
|
|
*
|
|
|
|
* Returns NULL if nothing found
|
|
|
|
*/
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams *HAMLIB_API rig_ext_lookup_tok(RIG *rig, token_t token)
|
2006-09-22 19:55:59 +00:00
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (!rig || !rig->caps)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++)
|
2017-10-05 02:32:08 +00:00
|
|
|
{
|
|
|
|
if (cfp->token == token)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return cfp;
|
|
|
|
}
|
2017-10-05 02:32:08 +00:00
|
|
|
}
|
2017-08-05 14:09:12 +00:00
|
|
|
|
2020-09-16 15:10:35 +00:00
|
|
|
for (cfp = rig->caps->extfuncs; cfp && cfp->token; cfp++)
|
|
|
|
{
|
|
|
|
if (cfp->token == token)
|
|
|
|
{
|
|
|
|
return cfp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-05 14:09:12 +00:00
|
|
|
for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++)
|
2017-10-05 02:32:08 +00:00
|
|
|
{
|
|
|
|
if (cfp->token == token)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return cfp;
|
|
|
|
}
|
2017-10-05 02:32:08 +00:00
|
|
|
}
|
2017-08-05 14:09:12 +00:00
|
|
|
|
|
|
|
return NULL;
|
2006-09-22 19:55:59 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 14:09:12 +00:00
|
|
|
|
2006-10-28 03:49:46 +00:00
|
|
|
/**
|
|
|
|
* \param rig
|
|
|
|
* \param name
|
2020-09-16 15:10:35 +00:00
|
|
|
* \brief Simple lookup returning token id associated with name
|
2002-07-09 20:36:07 +00:00
|
|
|
*/
|
2004-10-02 10:32:09 +00:00
|
|
|
token_t HAMLIB_API rig_ext_token_lookup(RIG *rig, const char *name)
|
2002-07-09 20:36:07 +00:00
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
cfp = rig_ext_lookup(rig, name);
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-10-05 02:32:08 +00:00
|
|
|
if (!cfp)
|
|
|
|
{
|
2017-08-05 14:09:12 +00:00
|
|
|
return RIG_CONF_END;
|
|
|
|
}
|
2002-07-09 20:36:07 +00:00
|
|
|
|
2017-08-05 14:09:12 +00:00
|
|
|
return cfp->token;
|
2002-07-09 20:36:07 +00:00
|
|
|
}
|
|
|
|
|
2006-10-28 03:49:46 +00:00
|
|
|
/** @} */
|