2001-07-21 12:55:04 +00:00
|
|
|
/*
|
|
|
|
* Hamlib Interface - configuration interface
|
|
|
|
* Copyright (c) 2000,2001 by Stephane Fillod and Frank Singleton
|
|
|
|
*
|
2001-12-20 07:47:53 +00:00
|
|
|
* $Id: conf.c,v 1.4 2001-12-20 07:47:53 fillods Exp $
|
2001-07-21 12:55:04 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 "conf.h"
|
|
|
|
|
2001-07-25 21:58:15 +00:00
|
|
|
|
|
|
|
#define TOK_RIG_PATHNAME RIG_TOKEN_FRONTEND(10)
|
|
|
|
#define TOK_WRITE_DELAY RIG_TOKEN_FRONTEND(12)
|
|
|
|
#define TOK_POST_WRITE_DELAY RIG_TOKEN_FRONTEND(13)
|
|
|
|
#define TOK_TIMEOUT RIG_TOKEN_FRONTEND(14)
|
|
|
|
#define TOK_RETRY RIG_TOKEN_FRONTEND(15)
|
|
|
|
#define TOK_ITU_REGION RIG_TOKEN_FRONTEND(20)
|
2001-07-21 12:55:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Place holder for now. Here will be defined all the configuration
|
|
|
|
* options available in the rig->state struct.
|
|
|
|
*/
|
|
|
|
static const struct confparams frontend_cfg_params[] = {
|
2001-07-25 21:58:15 +00:00
|
|
|
{ TOK_RIG_PATHNAME, "rig_pathname", "Rig path name",
|
|
|
|
"Path name to the device file of the rig",
|
|
|
|
"/dev/rig", RIG_CONF_STRING,
|
|
|
|
},
|
|
|
|
{ TOK_WRITE_DELAY, "write_delay", "Write delay",
|
|
|
|
"Delay in ms between each byte sent out",
|
|
|
|
"0", RIG_CONF_NUMERIC, { n: { 0, 1000, 1 } }
|
|
|
|
},
|
|
|
|
{ TOK_POST_WRITE_DELAY, "post_write_delay", "Post write delay",
|
|
|
|
"Delay in ms between each command sent out",
|
|
|
|
"0", RIG_CONF_NUMERIC, { n: { 0, 1000, 1 } }
|
|
|
|
},
|
|
|
|
{ TOK_TIMEOUT, "timeout", "Timeout", "Timeout in ms",
|
|
|
|
"0", RIG_CONF_NUMERIC, { n: { 0, 10000, 1 } }
|
|
|
|
},
|
|
|
|
{ TOK_RETRY, "retry", "Retry", "Max number of retry",
|
|
|
|
"0", RIG_CONF_NUMERIC, { n: { 0, 10, 1 } }
|
|
|
|
},
|
|
|
|
{ TOK_ITU_REGION, "itu_region", "ITU region",
|
|
|
|
"ITU region this rig has been manufactured for (freq. band plan)",
|
|
|
|
"0", RIG_CONF_NUMERIC, { n: { 1, 3, 1 } }
|
2001-07-21 12:55:04 +00:00
|
|
|
},
|
|
|
|
{ RIG_CONF_END, NULL, }
|
|
|
|
};
|
|
|
|
|
2001-07-25 21:58:15 +00:00
|
|
|
/*
|
|
|
|
* frontend_set_conf
|
|
|
|
* assumes rig!=NULL, val!=NULL
|
|
|
|
* TODO: check format of val before doing atoi().
|
|
|
|
*/
|
2001-07-21 12:55:04 +00:00
|
|
|
int frontend_set_conf(RIG *rig, token_t token, const char *val)
|
|
|
|
{
|
2001-07-25 21:58:15 +00:00
|
|
|
const struct rig_caps *caps;
|
|
|
|
struct rig_state *rs;
|
|
|
|
|
|
|
|
caps = rig->caps;
|
|
|
|
rs = &rig->state;
|
|
|
|
|
|
|
|
switch(token) {
|
|
|
|
case TOK_RIG_PATHNAME:
|
|
|
|
strcpy(rs->rigport.pathname, val);
|
|
|
|
break;
|
|
|
|
case TOK_WRITE_DELAY:
|
|
|
|
rs->rigport.write_delay = atoi(val);
|
|
|
|
break;
|
|
|
|
case TOK_POST_WRITE_DELAY:
|
|
|
|
rs->rigport.post_write_delay = atoi(val);
|
|
|
|
break;
|
|
|
|
case TOK_TIMEOUT:
|
|
|
|
rs->rigport.timeout = atoi(val);
|
|
|
|
break;
|
|
|
|
case TOK_RETRY:
|
|
|
|
rs->rigport.retry = atoi(val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TOK_ITU_REGION:
|
|
|
|
rs->itu_region = atoi(val);
|
|
|
|
switch(rs->itu_region) {
|
|
|
|
case RIG_ITU_REGION1:
|
|
|
|
memcpy(rs->tx_range_list, caps->tx_range_list1,
|
|
|
|
sizeof(struct freq_range_list)*FRQRANGESIZ);
|
|
|
|
memcpy(rs->rx_range_list, caps->rx_range_list1,
|
|
|
|
sizeof(struct freq_range_list)*FRQRANGESIZ);
|
|
|
|
break;
|
|
|
|
case RIG_ITU_REGION2:
|
|
|
|
case RIG_ITU_REGION3:
|
|
|
|
default:
|
|
|
|
memcpy(rs->tx_range_list, caps->tx_range_list2,
|
|
|
|
sizeof(struct freq_range_list)*FRQRANGESIZ);
|
|
|
|
memcpy(rs->rx_range_list, caps->rx_range_list2,
|
|
|
|
sizeof(struct freq_range_list)*FRQRANGESIZ);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
return RIG_OK;
|
2001-07-21 12:55:04 +00:00
|
|
|
}
|
|
|
|
|
2001-07-25 21:58:15 +00:00
|
|
|
/*
|
|
|
|
* frontend_get_conf
|
|
|
|
* assumes rig!=NULL, val!=NULL
|
|
|
|
*/
|
2001-07-21 12:55:04 +00:00
|
|
|
int frontend_get_conf(RIG *rig, token_t token, char *val)
|
|
|
|
{
|
2001-07-25 21:58:15 +00:00
|
|
|
const struct rig_caps *caps;
|
|
|
|
struct rig_state *rs;
|
|
|
|
|
|
|
|
caps = rig->caps;
|
|
|
|
rs = &rig->state;
|
|
|
|
|
|
|
|
switch(token) {
|
|
|
|
case TOK_RIG_PATHNAME:
|
|
|
|
strcpy(val, rs->rigport.pathname);
|
|
|
|
break;
|
|
|
|
case TOK_WRITE_DELAY:
|
|
|
|
sprintf(val, "%d", rs->rigport.write_delay);
|
|
|
|
break;
|
|
|
|
case TOK_POST_WRITE_DELAY:
|
|
|
|
sprintf(val, "%d", rs->rigport.post_write_delay);
|
|
|
|
break;
|
|
|
|
case TOK_TIMEOUT:
|
|
|
|
sprintf(val, "%d", rs->rigport.timeout);
|
|
|
|
break;
|
|
|
|
case TOK_RETRY:
|
|
|
|
sprintf(val, "%d", rs->rigport.retry);
|
|
|
|
break;
|
|
|
|
case TOK_ITU_REGION:
|
|
|
|
sprintf(val, "%d",
|
|
|
|
rs->itu_region == 1 ? RIG_ITU_REGION1 : RIG_ITU_REGION2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RIG_OK;
|
2001-07-21 12:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-12-20 07:47:53 +00:00
|
|
|
* rig_token_foreach
|
|
|
|
* executes cfunc on all the elements stored in the conf table
|
|
|
|
* start first with backend conf table, then finish with frontend table
|
|
|
|
*/
|
|
|
|
int rig_token_foreach(RIG *rig, int (*cfunc)(const struct confparams *, rig_ptr_t), rig_ptr_t data)
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
if (!rig || !rig->caps || !cfunc)
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
|
|
|
|
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++)
|
|
|
|
if ((*cfunc)(cfp, data) == 0)
|
|
|
|
return RIG_OK;
|
|
|
|
for (cfp = frontend_cfg_params; cfp->name; cfp++)
|
|
|
|
if ((*cfunc)(cfp, data) == 0)
|
|
|
|
return RIG_OK;
|
|
|
|
return RIG_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lookup backend config table first, then fall back to frontend
|
2001-07-21 12:55:04 +00:00
|
|
|
* should use Lex to speed it up, strcmp hurts!
|
|
|
|
*/
|
|
|
|
const struct confparams *rig_confparam_lookup(RIG *rig, const char *name)
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
2001-12-20 07:47:53 +00:00
|
|
|
if (!rig || !rig->caps)
|
2001-07-21 12:55:04 +00:00
|
|
|
return NULL;
|
2001-12-20 07:47:53 +00:00
|
|
|
for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++)
|
|
|
|
if (!strcmp(cfp->name, name))
|
|
|
|
return cfp;
|
|
|
|
for (cfp = frontend_cfg_params; cfp->name; cfp++)
|
2001-07-21 12:55:04 +00:00
|
|
|
if (!strcmp(cfp->name, name))
|
|
|
|
return cfp;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
token_t rig_token_lookup(RIG *rig, const char *name)
|
|
|
|
{
|
|
|
|
const struct confparams *cfp;
|
|
|
|
|
|
|
|
cfp = rig_confparam_lookup(rig, name);
|
|
|
|
if (!cfp)
|
|
|
|
return RIG_CONF_END;
|
|
|
|
|
|
|
|
return cfp->token;
|
|
|
|
}
|
|
|
|
|
2001-12-20 07:47:53 +00:00
|
|
|
|
|
|
|
|