[go: up one dir, main page]

Menu

[073328]: / src / ext.c  Maximize  Restore  History

Download this file

177 lines (151 with data), 4.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Hamlib Interface - extrq parameter interface
* Copyright (c) 2000-2008 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
*
*/
/**
* \addtogroup rig
* @{
*/
/**
* \file ext.c
* \brief Extension request parameter interface
*
* An open-ended set of extension parameters and levels are available for each rig,
* as provided in the rigcaps extparms and extlevels lists. These provide a way
* to work with rig-specific functions that don't fit into the basic "virtual rig" of
* Hamlib. See icom/ic746.c for an example.
*/
#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/rig.h>
#include "token.h"
/**
* \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
* 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.
*/
int HAMLIB_API rig_ext_level_foreach(RIG *rig, int (*cfunc)(RIG *, const struct confparams *, rig_ptr_t), rig_ptr_t data)
{
const struct confparams *cfp;
int ret;
if (!rig || !rig->caps || !cfunc)
return -RIG_EINVAL;
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++) {
ret = (*cfunc)(rig, cfp, data);
if (ret == 0)
return RIG_OK;
if (ret < 0)
return ret;
}
return RIG_OK;
}
/**
* \param rig The rig 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 rig_ext_parm_foreach.
*/
int HAMLIB_API rig_ext_parm_foreach(RIG *rig, int (*cfunc)(RIG *, const struct confparams *, rig_ptr_t), rig_ptr_t data)
{
const struct confparams *cfp;
int ret;
if (!rig || !rig->caps || !cfunc)
return -RIG_EINVAL;
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++) {
ret = (*cfunc)(rig, cfp, data);
if (ret == 0)
return RIG_OK;
if (ret < 0)
return ret;
}
return RIG_OK;
}
/**
* \param rig
* \param name
* \brief lookup ext token by its name, return pointer to confparams struct.
*
* Lookup extlevels table first, then fall back to extparms.
*
* Returns NULL if nothing found
*
* TODO: should use Lex to speed it up, strcmp hurts!
*/
const struct confparams * HAMLIB_API rig_ext_lookup(RIG *rig, const char *name)
{
const struct confparams *cfp;
if (!rig || !rig->caps)
return NULL;
for (cfp = rig->caps->extlevels; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name))
return cfp;
for (cfp = rig->caps->extparms; cfp && cfp->name; cfp++)
if (!strcmp(cfp->name, name))
return cfp;
return NULL;
}
/**
* \param rig
* \param token
* \brief lookup ext token, return pointer to confparams struct.
*
* lookup extlevels table first, then fall back to extparms.
*
* Returns NULL if nothing found
*/
const struct confparams * HAMLIB_API rig_ext_lookup_tok(RIG *rig, token_t token)
{
const struct confparams *cfp;
if (!rig || !rig->caps)
return NULL;
for (cfp = rig->caps->extlevels; cfp && cfp->token; cfp++)
if (cfp->token == token)
return cfp;
for (cfp = rig->caps->extparms; cfp && cfp->token; cfp++)
if (cfp->token == token)
return cfp;
return NULL;
}
/**
* \param rig
* \param name
* \brief Simple lookup returning token id assicated with name
*/
token_t HAMLIB_API rig_ext_token_lookup(RIG *rig, const char *name)
{
const struct confparams *cfp;
cfp = rig_ext_lookup(rig, name);
if (!cfp)
return RIG_CONF_END;
return cfp->token;
}
/** @} */