diff --git a/src/conf.c b/src/conf.c index cfbc2f5fb..f17d97d9a 100644 --- a/src/conf.c +++ b/src/conf.c @@ -7,13 +7,12 @@ * \file src/conf.c * \brief Rig configuration interface * \author Stephane Fillod - * \date 2000-2009 + * \date 2000-2010 */ /* * Hamlib Interface - configuration interface - * Copyright (c) 2000-2009 by Stephane Fillod + * Copyright (c) 2000-2010 by Stephane Fillod * - * $Id: conf.c,v 1.18 2009-01-25 14:25:46 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -45,8 +44,7 @@ #include "token.h" /* - * Place holder for now. Here will be defined all the configuration - * options available in the rig->state struct. + * Configuration options available in the rig->state struct. */ static const struct confparams frontend_cfg_params[] = { { TOK_PATHNAME, "rig_pathname", "Rig path name", @@ -72,38 +70,10 @@ static const struct confparams frontend_cfg_params[] = { "0", RIG_CONF_NUMERIC, { .n = { 1, 3, 1 } } }, - { TOK_SERIAL_SPEED, "serial_speed", "Serial speed", - "Serial port baud rate", - "0", RIG_CONF_NUMERIC, { .n = { 300, 115200, 1 } } - }, - { TOK_DATA_BITS, "data_bits", "Serial data bits", - "Serial port data bits", - "8", RIG_CONF_NUMERIC, { .n = { 5, 8, 1 } } - }, - { TOK_STOP_BITS, "stop_bits", "Serial stop bits", - "Serial port stop bits", - "1", RIG_CONF_NUMERIC, { .n = { 0, 3, 1 } } - }, - { TOK_PARITY, "serial_parity", "Serial parity", - "Serial port parity", - "None", RIG_CONF_COMBO, { .c = {{ "None", "Odd", "Even", NULL }} } - }, - { TOK_HANDSHAKE, "serial_handshake", "Serial handshake", - "Serial port handshake", - "None", RIG_CONF_COMBO, { .c = {{ "None", "XONXOFF", "Hardware", NULL }} } - }, { TOK_VFO_COMP, "vfo_comp", "VFO compensation", "VFO compensation in ppm", "0", RIG_CONF_NUMERIC, { .n = { 0.0, 1000.0, .001 } } }, - { TOK_RTS_STATE, "rts_state", "RTS state", - "Serial port set state of RTS signal for external powering", - "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } - }, - { TOK_DTR_STATE, "dtr_state", "DTR state", - "Serial port set state of DTR signal for external powering", - "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } - }, { TOK_POLL_INTERVAL, "poll_interval", "Polling interval", "Polling interval in millisecond for transceive emulation", "500", RIG_CONF_NUMERIC, { .n = { 0, 1000000, 1 } } @@ -128,6 +98,41 @@ static const struct confparams frontend_cfg_params[] = { { RIG_CONF_END, NULL, } }; + +static const struct confparams frontend_serial_cfg_params[] = { + { TOK_SERIAL_SPEED, "serial_speed", "Serial speed", + "Serial port baud rate", + "0", RIG_CONF_NUMERIC, { .n = { 300, 115200, 1 } } + }, + { TOK_DATA_BITS, "data_bits", "Serial data bits", + "Serial port data bits", + "8", RIG_CONF_NUMERIC, { .n = { 5, 8, 1 } } + }, + { TOK_STOP_BITS, "stop_bits", "Serial stop bits", + "Serial port stop bits", + "1", RIG_CONF_NUMERIC, { .n = { 0, 3, 1 } } + }, + { TOK_PARITY, "serial_parity", "Serial parity", + "Serial port parity", + "None", RIG_CONF_COMBO, { .c = {{ "None", "Odd", "Even", NULL }} } + }, + { TOK_HANDSHAKE, "serial_handshake", "Serial handshake", + "Serial port handshake", + "None", RIG_CONF_COMBO, { .c = {{ "None", "XONXOFF", "Hardware", NULL }} } + }, + + { TOK_RTS_STATE, "rts_state", "RTS state", + "Serial port set state of RTS signal for external powering", + "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } + }, + { TOK_DTR_STATE, "dtr_state", "DTR state", + "Serial port set state of DTR signal for external powering", + "Unset", RIG_CONF_COMBO, { .c = {{ "Unset", "ON", "OFF", NULL }} } + }, + + { RIG_CONF_END, NULL, } +}; + /* * frontend_set_conf * assumes rig!=NULL, val!=NULL @@ -455,11 +460,17 @@ int HAMLIB_API rig_token_foreach(RIG *rig, int (*cfunc)(const struct confparams if (!rig || !rig->caps || !cfunc) return -RIG_EINVAL; - for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) + for (cfp = frontend_cfg_params; cfp->name; cfp++) if ((*cfunc)(cfp, data) == 0) return RIG_OK; - for (cfp = frontend_cfg_params; cfp->name; cfp++) + if (rig->caps->port_type == RIG_PORT_SERIAL) { + for (cfp = frontend_serial_cfg_params; cfp->name; cfp++) + if ((*cfunc)(cfp, data) == 0) + return RIG_OK; + } + + for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) if ((*cfunc)(cfp, data) == 0) return RIG_OK; @@ -479,18 +490,28 @@ int HAMLIB_API rig_token_foreach(RIG *rig, int (*cfunc)(const struct confparams const struct confparams * HAMLIB_API rig_confparam_lookup(RIG *rig, const char *name) { const struct confparams *cfp; + token_t token; if (!rig || !rig->caps) return NULL; + /* 0 returned for invalid format */ + token = strtol(name, NULL, 0); + for (cfp = rig->caps->cfgparams; cfp && cfp->name; cfp++) - if (!strcmp(cfp->name, name)) + if (!strcmp(cfp->name, name) || token == cfp->token) return cfp; for (cfp = frontend_cfg_params; cfp->name; cfp++) - if (!strcmp(cfp->name, name)) + if (!strcmp(cfp->name, name) || token == cfp->token) return cfp; + if (rig->caps->port_type == RIG_PORT_SERIAL) { + for (cfp = frontend_serial_cfg_params; cfp->name; cfp++) + if (!strcmp(cfp->name, name) || token == cfp->token) + return cfp; + } + return NULL; } @@ -533,6 +554,16 @@ int HAMLIB_API rig_set_conf(RIG *rig, token_t token, const char *val) if (!rig || !rig->caps) return -RIG_EINVAL; + if (rig_need_debug(RIG_DEBUG_VERBOSE)) { + const struct confparams *cfp; + char tokenstr[12]; + sprintf(tokenstr, "%ld", token); + cfp = rig_confparam_lookup(rig, tokenstr); + if (!cfp) + return -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val); + } + if (IS_TOKEN_FRONTEND(token)) return frontend_set_conf(rig, token, val); diff --git a/src/rot_conf.c b/src/rot_conf.c index cb2f3d382..ea832892f 100644 --- a/src/rot_conf.c +++ b/src/rot_conf.c @@ -1,8 +1,7 @@ /* * Hamlib Interface - rotator configuration interface - * Copyright (c) 2000-2009 by Stephane Fillod + * Copyright (c) 2000-2010 by Stephane Fillod * - * $Id: rot_conf.c,v 1.8 2009-01-25 15:39:19 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -47,8 +46,7 @@ /* - * Place holder for now. Here will be defined all the configuration - * options available in the rot->state struct. + * Configuration options available in the rot->state struct. */ static const struct confparams rotfrontend_cfg_params[] = { { TOK_PATHNAME, "rot_pathname", "Rig path name", @@ -70,6 +68,27 @@ static const struct confparams rotfrontend_cfg_params[] = { "0", RIG_CONF_NUMERIC, { .n = { 0, 10, 1 } } }, + { TOK_MIN_AZ, "min_az", "Minimum azimuth", + "Minimum rotator azimuth in degrees", + "-180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } + }, + { TOK_MAX_AZ, "max_az", "Maximum azimuth", + "Maximum rotator azimuth in degrees", + "180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } + }, + { TOK_MIN_EL, "min_el", "Minimum elevation", + "Minimum rotator elevation in degrees", + "0", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } + }, + { TOK_MAX_EL, "max_el", "Maximum elevation", + "Maximum rotator elevation in degrees", + "90", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } + }, + + { RIG_CONF_END, NULL, } +}; + +static const struct confparams rotfrontend_serial_cfg_params[] = { { TOK_SERIAL_SPEED, "serial_speed", "Serial speed", "Serial port baud rate", "0", RIG_CONF_NUMERIC, { .n = { 300, 115200, 1 } } @@ -91,23 +110,6 @@ static const struct confparams rotfrontend_cfg_params[] = { "None", RIG_CONF_COMBO, { .c = {{ "None", "XONXOFF", "Hardware", NULL }} } }, - { TOK_MIN_AZ, "min_az", "Minimum azimuth", - "Minimum rotator azimuth in degrees", - "-180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } - }, - { TOK_MAX_AZ, "max_az", "Maximum azimuth", - "Maximum rotator azimuth in degrees", - "180", RIG_CONF_NUMERIC, { .n = { -360, 360, .001 } } - }, - { TOK_MIN_EL, "min_el", "Minimum elevation", - "Minimum rotator elevation in degrees", - "0", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } - }, - { TOK_MAX_EL, "max_el", "Maximum elevation", - "Maximum rotator elevation in degrees", - "90", RIG_CONF_NUMERIC, { .n = { -90, 180, .001 } } - }, - { RIG_CONF_END, NULL, } }; @@ -321,12 +323,20 @@ int HAMLIB_API rot_token_foreach(ROT *rot, int (*cfunc)(const struct confparams if (!rot || !rot->caps || !cfunc) return -RIG_EINVAL; - for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) - if ((*cfunc)(cfp, data) == 0) - return RIG_OK; for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) if ((*cfunc)(cfp, data) == 0) return RIG_OK; + + if (rot->caps->port_type == RIG_PORT_SERIAL) { + for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) + if ((*cfunc)(cfp, data) == 0) + return RIG_OK; + } + + for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) + if ((*cfunc)(cfp, data) == 0) + return RIG_OK; + return RIG_OK; } @@ -343,15 +353,25 @@ int HAMLIB_API rot_token_foreach(ROT *rot, int (*cfunc)(const struct confparams const struct confparams * HAMLIB_API rot_confparam_lookup(ROT *rot, const char *name) { const struct confparams *cfp; + token_t token; if (!rot || !rot->caps) return NULL; + + /* 0 returned for invalid format */ + token = strtol(name, NULL, 0); + for (cfp = rot->caps->cfgparams; cfp && cfp->name; cfp++) - if (!strcmp(cfp->name, name)) + if (!strcmp(cfp->name, name) || token == cfp->token) return cfp; for (cfp = rotfrontend_cfg_params; cfp->name; cfp++) - if (!strcmp(cfp->name, name)) + if (!strcmp(cfp->name, name) || token == cfp->token) return cfp; + if (rot->caps->port_type == RIG_PORT_SERIAL) { + for (cfp = rotfrontend_serial_cfg_params; cfp->name; cfp++) + if (!strcmp(cfp->name, name) || token == cfp->token) + return cfp; + } return NULL; } @@ -372,4 +392,70 @@ token_t HAMLIB_API rot_token_lookup(ROT *rot, const char *name) return cfp->token; } +/** + * \brief set a rotator configuration parameter + * \param rot The rot handle + * \param token The parameter + * \param val The value to set the parameter to + * + * Sets a configuration parameter. + * + * \return RIG_OK if the operation has been sucessful, otherwise + * a negative value if an error occured (in which case, cause is + * set appropriately). + * + * \sa rot_get_conf() + */ +int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val) +{ + if (!rot || !rot->caps) + return -RIG_EINVAL; + + if (rig_need_debug(RIG_DEBUG_VERBOSE)) { + const struct confparams *cfp; + char tokenstr[12]; + sprintf(tokenstr, "%ld", token); + cfp = rot_confparam_lookup(rot, tokenstr); + if (!cfp) + return -RIG_EINVAL; + rig_debug(RIG_DEBUG_VERBOSE, "%s: %s='%s'\n", __func__, cfp->name, val); + } + + if (IS_TOKEN_FRONTEND(token)) + return frontrot_set_conf(rot, token, val); + + if (rot->caps->set_conf == NULL) + return -RIG_ENAVAIL; + + return rot->caps->set_conf(rot, token, val); +} + +/** + * \brief get the value of a configuration parameter + * \param rot The rot handle + * \param token The parameter + * \param val The location where to store the value of config \a token + * + * Retrieves the value of a configuration paramter associated with \a token. + * + * \return RIG_OK if the operation has been sucessful, otherwise + * a negative value if an error occured (in which case, cause is + * set appropriately). + * + * \sa rot_set_conf() + */ +int HAMLIB_API rot_get_conf(ROT *rot, token_t token, char *val) +{ + if (!rot || !rot->caps || !val) + return -RIG_EINVAL; + + if (IS_TOKEN_FRONTEND(token)) + return frontrot_get_conf(rot, token, val); + + if (rot->caps->get_conf == NULL) + return -RIG_ENAVAIL; + + return rot->caps->get_conf(rot, token, val); +} + /** @} */ diff --git a/src/rotator.c b/src/rotator.c index 040932787..3dc26b886 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -3,7 +3,6 @@ * Copyright (c) 2000-2010 by Stephane Fillod * Copyright (c) 2000-2003 by Frank Singleton * - * $Id: rotator.c,v 1.27 2009-02-20 12:26:13 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -465,63 +464,6 @@ int HAMLIB_API rot_cleanup(ROT *rot) return RIG_OK; } - -/** - * \brief set a rotator configuration parameter - * \param rot The rot handle - * \param token The parameter - * \param val The value to set the parameter to - * - * Sets a configuration parameter. - * - * \return RIG_OK if the operation has been sucessful, otherwise - * a negative value if an error occured (in which case, cause is - * set appropriately). - * - * \sa rot_get_conf() - */ -int HAMLIB_API rot_set_conf(ROT *rot, token_t token, const char *val) -{ - if (!rot || !rot->caps) - return -RIG_EINVAL; - - if (IS_TOKEN_FRONTEND(token)) - return frontrot_set_conf(rot, token, val); - - if (rot->caps->set_conf == NULL) - return -RIG_ENAVAIL; - - return rot->caps->set_conf(rot, token, val); -} - -/** - * \brief get the value of a configuration parameter - * \param rot The rot handle - * \param token The parameter - * \param val The location where to store the value of config \a token - * - * Retrieves the value of a configuration paramter associated with \a token. - * - * \return RIG_OK if the operation has been sucessful, otherwise - * a negative value if an error occured (in which case, cause is - * set appropriately). - * - * \sa rot_set_conf() - */ -int HAMLIB_API rot_get_conf(ROT *rot, token_t token, char *val) -{ - if (!rot || !rot->caps || !val) - return -RIG_EINVAL; - - if (IS_TOKEN_FRONTEND(token)) - return frontrot_get_conf(rot, token, val); - - if (rot->caps->get_conf == NULL) - return -RIG_ENAVAIL; - - return rot->caps->get_conf(rot, token, val); -} - /** * \brief set the azimuth and elevation of the rotator * \param rot The rot handle