2019-06-12 20:52:35 +00:00
|
|
|
/*
|
|
|
|
* Hamlib Interface - extra parameter interface for amplifiers
|
|
|
|
* Copyright (c) 2000-2008 by Stephane Fillod
|
|
|
|
* Derived from ext.c
|
|
|
|
* Copyright (c) 2019 by Michael Black W9MDB
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-02-11 09:09:17 +00:00
|
|
|
* \addtogroup amplifier
|
2019-06-12 20:52:35 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-02-12 18:46:01 +00:00
|
|
|
* \file extamp.c
|
|
|
|
* \brief Amplifier extension parameters and levels interface.
|
2021-02-21 19:07:45 +00:00
|
|
|
*
|
2021-02-12 18:46:01 +00:00
|
|
|
* \author Michael Black
|
|
|
|
* \date 2019
|
2019-06-12 20:52:35 +00:00
|
|
|
*
|
|
|
|
* An open-ended set of extension parameters and levels are available for each
|
2021-02-12 18:46:01 +00:00
|
|
|
* amplifier, as provided in the amp_caps::extparms and amp_caps::extlevels
|
|
|
|
* lists. These provide a way to work with amplifier-specific functions that
|
|
|
|
* don't fit into the basic "virtual amplifier" of Hamlib. See
|
|
|
|
* `amplifiers/elecraft/kpa.c` for an example.
|
2019-06-12 20:52:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# 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 <hamlib/amplifier.h>
|
|
|
|
|
|
|
|
#include "token.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-21 19:07:45 +00:00
|
|
|
* \brief Executes \a cfunc on all the elements stored in the amp_caps::extlevels
|
|
|
|
* extension levels table.
|
2021-02-12 18:46:01 +00:00
|
|
|
*
|
|
|
|
* \param amp The #AMP handle.
|
|
|
|
* \param cfunc Callback function of each amp_caps::extlevels.
|
|
|
|
* \param data Cookie to be passed to the callback function \a cfunc.
|
|
|
|
*
|
|
|
|
* The callback function \a cfunc is called until it returns a value which is
|
|
|
|
* not strictly positive.
|
|
|
|
*
|
2021-02-21 19:07:45 +00:00
|
|
|
* \returns A zero value which means a normal end of iteration, or a
|
|
|
|
* **negative value** which means an abnormal end,
|
2021-02-12 18:46:01 +00:00
|
|
|
*
|
|
|
|
* \retval RIG_OK All extension levels elements successfully processed.
|
|
|
|
* \retval RIG_EINVAL \a amp or \a cfunc is NULL or inconsistent.
|
2019-06-12 20:52:35 +00:00
|
|
|
*/
|
|
|
|
int HAMLIB_API amp_ext_level_foreach(AMP *amp,
|
|
|
|
int (*cfunc)(AMP *,
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams *,
|
|
|
|
amp_ptr_t),
|
2019-06-12 20:52:35 +00:00
|
|
|
amp_ptr_t data)
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
if (!amp || !amp->caps || !cfunc)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = amp->caps->extlevels; cfp && cfp->name; cfp++)
|
|
|
|
{
|
2019-12-08 22:36:45 +00:00
|
|
|
int ret = (*cfunc)(amp, cfp, data);
|
2019-06-12 20:52:35 +00:00
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-12 18:46:01 +00:00
|
|
|
* \brief Executes \a cfunc on all the elements stored in the
|
|
|
|
* amp_caps::extparms extension parameters table.
|
|
|
|
*
|
|
|
|
* \param amp The #AMP handle.
|
|
|
|
* \param cfunc Callback function of each amp_caps::extparms.
|
|
|
|
* \param data Cookie to be passed to the callback function \a cfunc.
|
|
|
|
*
|
|
|
|
* The callback function \a cfunc is called until it returns a value which is not
|
|
|
|
* strictly positive.
|
|
|
|
*
|
|
|
|
* \returns A zero value which means a normal end of iteration, or a
|
2021-02-21 19:07:45 +00:00
|
|
|
* **negative value** which means an abnormal end.
|
2021-02-12 18:46:01 +00:00
|
|
|
*
|
|
|
|
* \retval RIG_OK All extension parameters elements successfully processed.
|
|
|
|
* \retval RIG_EINVAL \a amp or \a cfunc is NULL or inconsistent.
|
2019-06-12 20:52:35 +00:00
|
|
|
*/
|
|
|
|
int HAMLIB_API amp_ext_parm_foreach(AMP *amp,
|
|
|
|
int (*cfunc)(AMP *,
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams *,
|
|
|
|
amp_ptr_t),
|
2019-06-12 20:52:35 +00:00
|
|
|
amp_ptr_t data)
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
if (!amp || !amp->caps || !cfunc)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = amp->caps->extparms; cfp && cfp->name; cfp++)
|
|
|
|
{
|
2019-12-08 22:36:45 +00:00
|
|
|
int ret = (*cfunc)(amp, cfp, data);
|
2019-06-12 20:52:35 +00:00
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-12 18:46:01 +00:00
|
|
|
* \brief Lookup an extension levels or parameters token by its name and return
|
|
|
|
* a pointer to the containing #confparams structure member.
|
|
|
|
*
|
|
|
|
* \param amp The #AMP handle.
|
|
|
|
* \param name The extension levels or parameters token name.
|
2019-06-12 20:52:35 +00:00
|
|
|
*
|
2021-02-21 19:07:45 +00:00
|
|
|
* Searches the amp_caps::extlevels table and then the amp_caps::extparms
|
|
|
|
* table for the token by its name.
|
|
|
|
*
|
|
|
|
* \note As this function is called by amp_ext_token_lookup(), it can be
|
|
|
|
* considered a lower level API.
|
2019-06-12 20:52:35 +00:00
|
|
|
*
|
2021-02-12 18:46:01 +00:00
|
|
|
* \return A pointer to the containing #confparams structure member or NULL if
|
2021-02-15 21:38:20 +00:00
|
|
|
* nothing found or if \a amp is NULL or inconsistent.
|
2019-06-12 20:52:35 +00:00
|
|
|
*
|
2021-02-12 18:46:01 +00:00
|
|
|
* \sa amp_ext_token_lookup()
|
|
|
|
*
|
2021-02-21 19:07:45 +00:00
|
|
|
* \todo Should use Lex to speed it up, strcmp() hurts!
|
2019-06-12 20:52:35 +00:00
|
|
|
*/
|
|
|
|
const struct confparams *HAMLIB_API amp_ext_lookup(AMP *amp, const char *name)
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
if (!amp || !amp->caps)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = amp->caps->extlevels; cfp && cfp->name; cfp++)
|
|
|
|
{
|
|
|
|
if (!strcmp(cfp->name, name))
|
|
|
|
{
|
|
|
|
return cfp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = amp->caps->extparms; cfp && cfp->name; cfp++)
|
|
|
|
{
|
|
|
|
if (!strcmp(cfp->name, name))
|
|
|
|
{
|
|
|
|
return cfp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-21 19:07:45 +00:00
|
|
|
* \brief Search for an extension levels or parameters token by its constant
|
|
|
|
* value and return a pointer to the #confparams structure member.
|
2021-02-12 18:46:01 +00:00
|
|
|
*
|
|
|
|
* \param amp The #AMP handle.
|
|
|
|
* \param token The token value (constant).
|
2019-06-12 20:52:35 +00:00
|
|
|
*
|
2021-02-21 19:07:45 +00:00
|
|
|
* Searches the amp_caps::extlevels table first and then the
|
|
|
|
* amp_caps::extparms for the token by its constant value.
|
2019-06-12 20:52:35 +00:00
|
|
|
*
|
2021-02-12 18:46:01 +00:00
|
|
|
* \return A pointer to the containing #confparams structure member or NULL if
|
2021-02-15 21:38:20 +00:00
|
|
|
* nothing found or if \a amp is NULL or inconsistent.
|
2019-06-12 20:52:35 +00:00
|
|
|
*/
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct confparams *HAMLIB_API amp_ext_lookup_tok(AMP *amp, token_t token)
|
2019-06-12 20:52:35 +00:00
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
if (!amp || !amp->caps)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = amp->caps->extlevels; cfp && cfp->token; cfp++)
|
|
|
|
{
|
|
|
|
if (cfp->token == token)
|
|
|
|
{
|
|
|
|
return cfp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cfp = amp->caps->extparms; cfp && cfp->token; cfp++)
|
|
|
|
{
|
|
|
|
if (cfp->token == token)
|
|
|
|
{
|
|
|
|
return cfp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-21 19:07:45 +00:00
|
|
|
* \brief Simple search returning the extension token ID associated with
|
|
|
|
* \a name.
|
2021-02-12 18:46:01 +00:00
|
|
|
*
|
|
|
|
* \param amp The #AMP handle.
|
2021-02-21 19:07:45 +00:00
|
|
|
* \param name The token name string to search.
|
|
|
|
*
|
|
|
|
* \note As this function calls amp_ext_lookup(), it can be considered a
|
|
|
|
* higher level API.
|
2021-02-12 18:46:01 +00:00
|
|
|
*
|
|
|
|
* \return The token ID or RIG_CONF_END if there is a lookup failure.
|
|
|
|
*
|
|
|
|
* \sa amp_ext_lookup()
|
2019-06-12 20:52:35 +00:00
|
|
|
*/
|
|
|
|
token_t HAMLIB_API amp_ext_token_lookup(AMP *amp, const char *name)
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
cfp = amp_ext_lookup(amp, name);
|
|
|
|
|
|
|
|
if (!cfp)
|
|
|
|
{
|
|
|
|
return RIG_CONF_END;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfp->token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @} */
|