From 7bf3972b308cf37f1d03cd836d76defe808b994b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Tue, 9 Jul 2002 22:17:14 +0000 Subject: [PATCH] - removed rig_save_channel and rig_restore_channel from API - rig_set_channel and rig_get_channel can now target VFO, besides memories - emulation of set_channel and get_channel has been kept in generic routines. Added in these routines the support for ext_levels. git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1113 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- c++/rigclass.cc | 12 +- include/hamlib/rig.h | 6 +- include/hamlib/rigclass.h | 4 +- src/rig.c | 242 ++++++++++++++++++++++---------------- 4 files changed, 146 insertions(+), 118 deletions(-) diff --git a/c++/rigclass.cc b/c++/rigclass.cc index 29bd9d2e9..b0ee62faa 100644 --- a/c++/rigclass.cc +++ b/c++/rigclass.cc @@ -11,7 +11,7 @@ * Hamlib C++ bindings - main file * Copyright (c) 2001 by Stephane Fillod * - * $Id: rigclass.cc,v 1.8 2002-02-27 23:25:42 fillods Exp $ + * $Id: rigclass.cc,v 1.9 2002-07-09 22:17:14 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 @@ -634,16 +634,6 @@ int Rig::getMem (vfo_t vfo = RIG_VFO_CURR) return mem; } -void Rig::saveChannel (channel_t *chan) -{ - CHECK_RIG( rig_save_channel(theRig, chan) ); -} - -void Rig::restoreChannel (const channel_t *chan) -{ - CHECK_RIG( rig_restore_channel(theRig, chan) ); -} - void Rig::setChannel (const channel_t *chan) { CHECK_RIG( rig_set_channel(theRig, chan) ); diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index 655439be1..d3f75a308 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -2,7 +2,7 @@ * Hamlib Interface - API header * Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton * - * $Id: rig.h,v 1.67 2002-07-09 20:40:28 fillods Exp $ + * $Id: rig.h,v 1.68 2002-07-09 22:17: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 @@ -927,7 +927,7 @@ struct rig_caps { * Convenience Functions */ - int (*set_channel) (RIG * rig, channel_t * chan); + int (*set_channel) (RIG * rig, const channel_t * chan); int (*get_channel) (RIG * rig, channel_t * chan); /* get firmware info, etc. */ @@ -1222,8 +1222,6 @@ extern HAMLIB_EXPORT(vfo_op_t) rig_has_vfo_op HAMLIB_PARAMS((RIG *rig, vfo_op_t extern HAMLIB_EXPORT(int) rig_scan HAMLIB_PARAMS((RIG *rig, vfo_t vfo, scan_t scan, int ch)); extern HAMLIB_EXPORT(scan_t) rig_has_scan HAMLIB_PARAMS((RIG *rig, scan_t scan)); -extern HAMLIB_EXPORT(int) rig_restore_channel HAMLIB_PARAMS((RIG *rig, const channel_t *chan)); /* curr VFO */ -extern HAMLIB_EXPORT(int) rig_save_channel HAMLIB_PARAMS((RIG *rig, channel_t *chan)); extern HAMLIB_EXPORT(int) rig_set_channel HAMLIB_PARAMS((RIG *rig, const channel_t *chan)); /* mem */ extern HAMLIB_EXPORT(int) rig_get_channel HAMLIB_PARAMS((RIG *rig, channel_t *chan)); diff --git a/include/hamlib/rigclass.h b/include/hamlib/rigclass.h index f0c159f92..e3fc79dd6 100644 --- a/include/hamlib/rigclass.h +++ b/include/hamlib/rigclass.h @@ -2,7 +2,7 @@ * Hamlib C++ bindings - API header * Copyright (c) 2001 by Stephane Fillod * - * $Id: rigclass.h,v 1.9 2002-02-27 23:22:31 fillods Exp $ + * $Id: rigclass.h,v 1.10 2002-07-09 22:17: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 @@ -122,8 +122,6 @@ public: void setMem (int ch, vfo_t vfo = RIG_VFO_CURR); int getMem (vfo_t vfo = RIG_VFO_CURR); - void restoreChannel (const channel_t *chan); - void saveChannel (channel_t *chan); void setChannel (const channel_t *chan); void getChannel (channel_t *chan); diff --git a/src/rig.c b/src/rig.c index ab632c93a..3414460a9 100644 --- a/src/rig.c +++ b/src/rig.c @@ -13,7 +13,7 @@ * Hamlib Interface - main file * Copyright (c) 2000-2002 by Stephane Fillod and Frank Singleton * - * $Id: rig.c,v 1.59 2002-07-09 20:40:28 fillods Exp $ + * $Id: rig.c,v 1.60 2002-07-09 22:17: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 @@ -3605,23 +3605,36 @@ int rig_set_bank(RIG *rig, vfo_t vfo, int bank) return retcode; } -/** - * \brief save all the data associated with current VFO - * \param rig The rig handle - * \param chan The location where to store the channel data - * - * Gets all the data associated with current VFO. - * See #channel_t for more information. - * - * \return RIG_OK if the operation has been sucessful, otherwise - * a negative value if an error occured (in which case, cause is - * set appropriately). - * - * \todo return code checking - * \sa rig_get_channel() +/* + * call on every ext_levels of a rig */ +static int generic_retr_extl(RIG *rig, const struct confparams *cfp, rig_ptr_t ptr) +{ + channel_t *chan = (channel_t *)ptr; + struct ext_list *p; + unsigned el_size = 0; -int rig_save_channel(RIG *rig, channel_t *chan) + if (chan->ext_levels == NULL) + p = chan->ext_levels = malloc(2*sizeof(struct ext_list)); + else { + for (p = chan->ext_levels; !RIG_IS_EXT_END(*p); p++) + el_size += sizeof(struct ext_list); + chan->ext_levels = realloc(chan->ext_levels, + el_size+sizeof(struct ext_list)); + } + + p->token = cfp->token; + rig_get_ext_level(rig, RIG_VFO_CURR, p->token, &p->val); + p++; + p->token = 0; /* RIG_EXT_END */ + + return 1; /* process them all */ +} + +/* + * stores current VFO state into chan by emulating rig_get_channel + */ +int generic_save_channel(RIG *rig, channel_t *chan) { int i; int chan_num; @@ -3672,28 +3685,19 @@ int rig_save_channel(RIG *rig, channel_t *chan) rig_get_dcs_sql(rig, RIG_VFO_CURR, &chan->dcs_sql); /* rig_get_mem_name(rig, RIG_VFO_CURR, chan->channel_desc); */ - return RIG_OK; + rig_ext_level_foreach(rig, generic_retr_extl, (rig_ptr_t)chan); + + return RIG_OK; } -/** - * \brief restore all the data associated with current VFO - * \param rig The rig handle - * \param chan The location where to store the channel data - * - * Sets all the data associated with current VFO. - * See #channel_t for more information. - * - * \return RIG_OK if the operation has been sucessful, otherwise - * a negative value if an error occured (in which case, cause is - * set appropriately). - * - * \todo return code checking - * \sa rig_get_channel() - */ -int rig_restore_channel(RIG *rig, const channel_t *chan) +/* + * Restores chan into current VFO state by emulating rig_set_channel + */ +int generic_restore_channel(RIG *rig, const channel_t *chan) { int i; + struct ext_list *p; if (CHECK_RIG_ARG(rig) || !chan) return -RIG_EINVAL; @@ -3726,7 +3730,10 @@ int rig_restore_channel(RIG *rig, const channel_t *chan) rig_set_dcs_sql(rig, RIG_VFO_CURR, chan->dcs_sql); /* rig_set_mem_name(rig, RIG_VFO_CURR, chan->channel_desc); */ - return RIG_OK; + for (p = chan->ext_levels; !RIG_IS_EXT_END(*p); p++) + rig_set_ext_level(rig, RIG_VFO_CURR, p->token, p->val); + + return RIG_OK; } @@ -3735,7 +3742,9 @@ int rig_restore_channel(RIG *rig, const channel_t *chan) * \param rig The rig handle * \param chan The location of data to set for this channel * - * Sets the data associated with a channel. + * Sets the data associated with a channel. This channel can either + * be the state of a VFO specified by \a chan->vfo, or a memory channel + * specified with \a chan->vfo = RIG_VFO_MEM and \a chan->channel_num. * See #channel_t for more information. * The rig_set_channel is supposed to have no impact on the current VFO * and memory number selected. Depending on backend and rig capabilities, @@ -3750,57 +3759,71 @@ int rig_restore_channel(RIG *rig, const channel_t *chan) int rig_set_channel(RIG *rig, const channel_t *chan) { - struct rig_caps *rc; - int curr_chan_num, get_mem_status; - vfo_t curr_vfo; + struct rig_caps *rc; + int curr_chan_num, get_mem_status = RIG_OK; + vfo_t curr_vfo; + vfo_t vfo; /* requested vfo */ + int retcode; #ifdef PARANOID_CHANNEL_HANDLING - channel_t curr_chan; + channel_t curr_chan; #endif - if (CHECK_RIG_ARG(rig) || !chan) - return -RIG_EINVAL; + if (CHECK_RIG_ARG(rig) || !chan) + return -RIG_EINVAL; - /* - * TODO: check chan->channel_num is valid - */ + /* + * TODO: check chan->channel_num is valid + */ - rc = rig->caps; + rc = rig->caps; - if (!rc->set_channel) - return rc->set_channel(rig, chan); + if (rc->set_channel) + return rc->set_channel(rig, chan); - /* - * if not available, emulate it - * Optional: get_vfo, set_vfo, - * TODO: check return codes - */ - if (!rc->set_mem) - return -RIG_ENAVAIL; + /* + * if not available, emulate it + * Optional: get_vfo, set_vfo, + * TODO: check return codes + */ - /* may be needed if the restore_channel has some side effects */ + vfo = chan->vfo; + if (vfo == RIG_VFO_MEM && !rc->set_mem) + return -RIG_ENAVAIL; + + if (vfo == RIG_VFO_CURR) + return generic_restore_channel(rig, chan); + + if (!rc->set_vfo) + return -RIG_ENTARGET; + + curr_vfo = rig->state.current_vfo; + /* may be needed if the restore_channel has some side effects */ #ifdef PARANOID_CHANNEL_HANDLING - rig_save_channel(rig, &curr_chan); + generic_save_channel(rig, &curr_chan); #endif - if (rig_get_vfo(rig, &curr_vfo) != RIG_OK) - curr_vfo = rig->state.current_vfo; - rig_set_vfo(rig, RIG_VFO_MEM); + if (vfo == RIG_VFO_MEM) get_mem_status = rig_get_mem(rig, RIG_VFO_CURR, &curr_chan_num); + retcode = rc->set_vfo(rig, vfo); + if (retcode != RIG_OK) + return retcode; + + if (vfo == RIG_VFO_MEM) rig_set_mem(rig, RIG_VFO_CURR, chan->channel_num); - rig_restore_channel(rig, chan); - /* restore current memory number */ - if (get_mem_status == RIG_OK) - rig_set_mem(rig, RIG_VFO_CURR, curr_chan_num); + retcode = generic_restore_channel(rig, chan); - rig_set_vfo(rig, curr_vfo); + /* restore current memory number */ + if (vfo == RIG_VFO_MEM && get_mem_status == RIG_OK) + rig_set_mem(rig, RIG_VFO_CURR, curr_chan_num); + + rig_set_vfo(rig, curr_vfo); #ifdef PARANOID_CHANNEL_HANDLING - rig_restore_channel(rig, &curr_chan); + generic_restore_channel(rig, &curr_chan); #endif - - return RIG_OK; + return retcode; } /** @@ -3808,12 +3831,18 @@ int rig_set_channel(RIG *rig, const channel_t *chan) * \param rig The rig handle * \param chan The location where to store the channel data * - * Retrieves the data associated with the channel \a chan->channel_num. + * Retrieves the data associated with a channel. This channel can either + * be the state of a VFO specified by \a chan->vfo, or a memory channel + * specified with \a chan->vfo = RIG_VFO_MEM and \a chan->channel_num. * See #channel_t for more information. * The rig_get_channel is supposed to have no impact on the current VFO * and memory number selected. Depending on backend and rig capabilities, * the chan struct may not be filled in completely. * + * Note: chan->ext_levels is a pointer to a newly mallocated memory. + * This is the responsability of the caller to manage and eventually + * free it. + * * \return RIG_OK if the operation has been sucessful, otherwise * a negative value if an error occured (in which case, cause is * set appropriately). @@ -3822,57 +3851,70 @@ int rig_set_channel(RIG *rig, const channel_t *chan) */ int rig_get_channel(RIG *rig, channel_t *chan) { - struct rig_caps *rc; - int curr_chan_num, get_mem_status; - vfo_t curr_vfo; + struct rig_caps *rc; + int curr_chan_num, get_mem_status = RIG_OK; + vfo_t curr_vfo; + vfo_t vfo; /* requested vfo */ + int retcode; #ifdef PARANOID_CHANNEL_HANDLING - channel_t curr_chan; + channel_t curr_chan; #endif - if (CHECK_RIG_ARG(rig) || !chan) - return -RIG_EINVAL; + if (CHECK_RIG_ARG(rig) || !chan) + return -RIG_EINVAL; - /* - * TODO: check chan->channel_num is valid - */ + /* + * TODO: check chan->channel_num is valid + */ - rc = rig->caps; + rc = rig->caps; - if (rc->get_channel) - return rc->get_channel(rig, chan); + if (rc->get_channel) + return rc->get_channel(rig, chan); - /* - * if not available, emulate it - * Optional: get_vfo, set_vfo - * TODO: check return codes - */ - if (!rc->set_mem) - return -RIG_ENAVAIL; + /* + * if not available, emulate it + * Optional: get_vfo, set_vfo + * TODO: check return codes + */ + vfo = chan->vfo; + if (vfo == RIG_VFO_MEM && !rc->set_mem) + return -RIG_ENAVAIL; - /* may be needed if the restore_channel has some side effects */ + if (vfo == RIG_VFO_CURR) + return generic_restore_channel(rig, chan); + + if (!rc->set_vfo) + return -RIG_ENTARGET; + + curr_vfo = rig->state.current_vfo; + /* may be needed if the restore_channel has some side effects */ #ifdef PARANOID_CHANNEL_HANDLING - rig_save_channel(rig, &curr_chan); + generic_save_channel(rig, &curr_chan); #endif - if (rig_get_vfo(rig, &curr_vfo) != RIG_OK) - curr_vfo = rig->state.current_vfo; - rig_set_vfo(rig, RIG_VFO_MEM); + if (vfo == RIG_VFO_MEM) get_mem_status = rig_get_mem(rig, RIG_VFO_CURR, &curr_chan_num); + retcode = rc->set_vfo(rig, vfo); + if (retcode != RIG_OK) + return retcode; + + if (vfo == RIG_VFO_MEM) rig_set_mem(rig, RIG_VFO_CURR, chan->channel_num); - rig_save_channel(rig, chan); - /* restore current memory number */ - if (get_mem_status == RIG_OK) - rig_set_mem(rig, RIG_VFO_CURR, curr_chan_num); + retcode = generic_save_channel(rig, chan); - rig_set_vfo(rig, curr_vfo); + /* restore current memory number */ + if (vfo == RIG_VFO_MEM && get_mem_status == RIG_OK) + rig_set_mem(rig, RIG_VFO_CURR, curr_chan_num); + + rig_set_vfo(rig, curr_vfo); #ifdef PARANOID_CHANNEL_HANDLING - rig_restore_channel(rig, &curr_chan); + generic_restore_channel(rig, &curr_chan); #endif - - return RIG_OK; + return retcode; } /**