extend API to support save/load memory at once

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2025 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.5
Stéphane Fillod, F8CFE 2005-04-20 14:44:04 +00:00
rodzic 2f9eece340
commit 579823eb53
4 zmienionych plików z 272 dodań i 16 usunięć

Wyświetl plik

@ -145,8 +145,8 @@ rm -rf $RPM_BUILD_ROOT
#%doc doc/*.txt
%defattr(755, root, root, 755)
%{_libdir}/libhamlib-%{ver}.so.2
%{_libdir}/libhamlib-%{ver}.so.2.0.3
%{_libdir}/libhamlib-%{ver}.so.@ABI_VERSION@
%{_libdir}/libhamlib-%{ver}.so.@ABI_VERSION@.0.4
%{_libdir}/libhamlib.la
%{_libdir}/hamlib-alinco.so
%{_libdir}/hamlib-alinco.la

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Interface - API header
* Copyright (c) 2000-2005 by Stephane Fillod and Frank Singleton
*
* $Id: rig.h,v 1.107 2005-04-06 21:27:27 fillods Exp $
* $Id: rig.h,v 1.108 2005-04-20 14:44:01 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
@ -1004,6 +1004,9 @@ typedef struct cal_table cal_table_t;
#define EMPTY_STR_CAL { 0, { { 0, 0 }, } }
typedef int (*chan_cb_t) (RIG *, channel_t**, int, const chan_t*, rig_ptr_t);
typedef int (*confval_cb_t) (RIG *, const struct confparams *, value_t *, rig_ptr_t);
/**
* \brief Rig data structure.
*
@ -1217,6 +1220,14 @@ struct rig_caps {
const char *(*get_info) (RIG * rig);
int (*set_chan_all_cb) (RIG * rig, chan_cb_t chan_cb, rig_ptr_t);
int (*get_chan_all_cb) (RIG * rig, chan_cb_t chan_cb, rig_ptr_t);
int (*set_mem_all_cb) (RIG * rig, chan_cb_t chan_cb, confval_cb_t parm_cb, rig_ptr_t);
int (*get_mem_all_cb) (RIG * rig, chan_cb_t chan_cb, confval_cb_t parm_cb, rig_ptr_t);
const char *clone_combo_set; /*<! String describing key combination to enter load cloning mode */
const char *clone_combo_get; /*<! String describing key combination to enter save cloning mode */
};
/**
@ -1521,6 +1532,16 @@ extern HAMLIB_EXPORT(scan_t) rig_has_scan HAMLIB_PARAMS((RIG *rig, scan_t scan))
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));
extern HAMLIB_EXPORT(int) rig_set_chan_all HAMLIB_PARAMS((RIG *rig, const channel_t chans[]));
extern HAMLIB_EXPORT(int) rig_get_chan_all HAMLIB_PARAMS((RIG *rig, channel_t chans[]));
extern HAMLIB_EXPORT(int) rig_set_chan_all_cb HAMLIB_PARAMS((RIG *rig, chan_cb_t chan_cb, rig_ptr_t));
extern HAMLIB_EXPORT(int) rig_get_chan_all_cb HAMLIB_PARAMS((RIG *rig, chan_cb_t chan_cb, rig_ptr_t));
extern HAMLIB_EXPORT(int) rig_set_mem_all_cb HAMLIB_PARAMS((RIG *rig, chan_cb_t chan_cb, confval_cb_t parm_cb, rig_ptr_t));
extern HAMLIB_EXPORT(int) rig_get_mem_all_cb HAMLIB_PARAMS((RIG *rig, chan_cb_t chan_cb, confval_cb_t parm_cb, rig_ptr_t));
extern HAMLIB_EXPORT(int) rig_set_mem_all HAMLIB_PARAMS((RIG *rig, const channel_t *chan, const struct confparams *, value_t *));
extern HAMLIB_EXPORT(int) rig_get_mem_all HAMLIB_PARAMS((RIG *rig, channel_t *chan, const struct confparams *, value_t *));
extern HAMLIB_EXPORT(int) rig_set_trn HAMLIB_PARAMS((RIG *rig, int trn));
extern HAMLIB_EXPORT(int) rig_get_trn HAMLIB_PARAMS((RIG *rig, int *trn));
extern HAMLIB_EXPORT(int) rig_set_freq_callback HAMLIB_PARAMS((RIG *, freq_cb_t, rig_ptr_t));
@ -1542,7 +1563,7 @@ extern HAMLIB_EXPORT(pbwidth_t) rig_passband_wide HAMLIB_PARAMS((RIG *rig, rmode
extern HAMLIB_EXPORT(const char *) rigerror HAMLIB_PARAMS((int errnum));
extern HAMLIB_EXPORT(int) rig_setting2idx HAMLIB_PARAMS((setting_t s));
#define rig_idx2setting(i) (1ULL<<(i))
#define rig_idx2setting(i) (1UL<<(i))
/*
* Even if these functions are prefixed with "rig_", they are not rig specific

Wyświetl plik

@ -5,7 +5,7 @@ RIGSRC = rig.c serial.c misc.c register.c event.c cal.c conf.c tones.c \
lib_LTLIBRARIES = libhamlib.la
libhamlib_la_SOURCES = $(RIGSRC)
libhamlib_la_LDFLAGS = $(WINLDFLAGS) -no-undefined -release @VERSION@ -version-info @ABI_VERSION@:3:0
libhamlib_la_LDFLAGS = $(WINLDFLAGS) -no-undefined -release @VERSION@ -version-info @ABI_VERSION@:4:0
libhamlib_la_CFLAGS = -DIN_HAMLIB $(AM_CFLAGS) -DHAMLIB_MODULE_DIR=\"$(libdir)\"
libhamlib_la_LIBADD = @LIBLTDL@ $(top_builddir)/lib/libmisc.la @MATH_LIBS@

257
src/mem.c
Wyświetl plik

@ -12,7 +12,7 @@
* Hamlib Interface - mem/channel calls
* Copyright (c) 2000-2005 by Stephane Fillod
*
* $Id: mem.c,v 1.5 2005-04-03 22:33:08 fillods Exp $
* $Id: mem.c,v 1.6 2005-04-20 14:44:03 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
@ -222,23 +222,24 @@ static int generic_retr_extl(RIG *rig, const struct confparams *cfp, rig_ptr_t p
/*
* stores current VFO state into chan by emulating rig_get_channel
*/
int generic_save_channel(RIG *rig, channel_t *chan)
static int generic_save_channel(RIG *rig, channel_t *chan)
{
int i;
int i, retval;
int chan_num;
vfo_t vfo;
if (CHECK_RIG_ARG(rig) || !chan)
return -RIG_EINVAL;
chan_num = chan->channel_num;
vfo = chan->vfo;
memset(chan, 0, sizeof(channel_t));
chan->channel_num = chan_num;
chan->vfo = vfo;
retval = rig_get_freq(rig, RIG_VFO_CURR, &chan->freq);
/* empty channel ? */
if (retval == -RIG_ENAVAIL || chan->freq == RIG_FREQ_NONE)
return -RIG_ENAVAIL;
rig_get_vfo(rig, &chan->vfo);
rig_get_freq(rig, RIG_VFO_CURR, &chan->freq);
rig_get_mode(rig, RIG_VFO_CURR, &chan->mode, &chan->width);
chan->split = RIG_SPLIT_OFF;
@ -285,14 +286,11 @@ int generic_save_channel(RIG *rig, channel_t *chan)
/*
* Restores chan into current VFO state by emulating rig_set_channel
*/
int generic_restore_channel(RIG *rig, const channel_t *chan)
static 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;
rig_set_vfo(rig, chan->vfo);
rig_set_freq(rig, RIG_VFO_CURR, chan->freq);
rig_set_mode(rig, RIG_VFO_CURR, chan->mode, chan->width);
@ -523,3 +521,240 @@ int HAMLIB_API rig_get_channel(RIG *rig, channel_t *chan)
return retcode;
}
#ifndef DOC_HIDDEN
int get_chan_all_cb_generic (RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
{
int i,j,retval;
chan_t *chan_list = rig->state.chan_list;
channel_t *chan;
for (i=0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) {
/*
* setting chan to NULL means the application
* has to provide a struct where to store data
* future data for channel channel_num
*/
chan = NULL;
retval = chan_cb(rig, &chan, chan_list[i].start, chan_list, arg);
if (retval != RIG_OK)
return retval;
if (chan == NULL)
return -RIG_ENOMEM;
for (j = chan_list[i].start; j <= chan_list[i].end; j++) {
int chan_next;
chan->vfo = RIG_VFO_MEM;
chan->channel_num = j;
/*
* TODO: if doesn't have rc->get_channel, special generic
*/
retval = rig_get_channel(rig, chan);
if (retval == -RIG_ENAVAIL) {
/*
* empty channel
*
* Should it continue or call chan_cb with special arg?
*/
continue;
}
if (retval != RIG_OK)
return retval;
chan_next = j < chan_list[i].end ? j+1 : j;
chan_cb(rig, &chan, chan_next, chan_list, arg);
}
}
return RIG_OK;
}
int set_chan_all_cb_generic (RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
{
int i,j,retval;
chan_t *chan_list = rig->state.chan_list;
channel_t *chan;
for (i=0; !RIG_IS_CHAN_END(chan_list[i]) && i < CHANLSTSIZ; i++) {
for (j = chan_list[i].start; j <= chan_list[i].end; j++) {
chan_cb(rig, &chan, j, chan_list, arg);
chan->vfo = RIG_VFO_MEM;
retval = rig_set_channel(rig, chan);
if (retval != RIG_OK)
return retval;
}
}
return RIG_OK;
}
/*
* chan_cb_t to be used for non cb get/set_all
*/
static int map_chan (RIG *rig, channel_t **chan, int channel_num, const chan_t *chan_list, rig_ptr_t arg)
{
channel_t *chans = arg;
/* TODO: check channel_num within start-end of chan_list */
*chan = &chans[channel_num];
return RIG_OK;
}
#endif /* DOC_HIDDEN */
/**
* \brief set all channel data, by callback
* \param rig The rig handle
* \param chan_cb Pointer to a callback function to provide channel data
* \param arg Arbitrary argument passed back to \a chan_cb
*
* Write the data associated with a all the memory channels.
*
* \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 rig_set_chan_all(), rig_get_chan_all_cb()
*/
int HAMLIB_API rig_set_chan_all_cb (RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
{
struct rig_caps *rc;
int retval;
if (CHECK_RIG_ARG(rig) || !chan_cb)
return -RIG_EINVAL;
rc = rig->caps;
if (rc->set_chan_all_cb)
return rc->set_chan_all_cb(rig, chan_cb, arg);
/* if not available, emulate it */
retval = set_chan_all_cb_generic (rig, chan_cb, arg);
return retval;
}
/**
* \brief get all channel data, by callback
* \param rig The rig handle
* \param chan_cb Pointer to a callback function to retrieve channel data
* \param arg Arbitrary argument passed back to \a chan_cb
*
* Retrieves the data associated with a all the memory channels.
*
* \a chan_cb is called first with no data in \chan (chan equals NULL).
* This means the application has to provide a struct where to store
* future data for channel channel_num. If channel_num == chan->channel_num,
* the application does not need to provide a new allocated structure.
*
* \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 rig_get_chan_all(), rig_set_chan_all_cb()
*/
int HAMLIB_API rig_get_chan_all_cb (RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg)
{
struct rig_caps *rc;
int retval;
if (CHECK_RIG_ARG(rig) || !chan_cb)
return -RIG_EINVAL;
rc = rig->caps;
if (rc->get_chan_all_cb)
return rc->get_chan_all_cb(rig, chan_cb, arg);
/* if not available, emulate it */
retval = get_chan_all_cb_generic (rig, chan_cb, arg);
return retval;
}
/**
* \brief set all channel data
* \param rig The rig handle
* \param chan The location of data to set for all channels
*
* Write the data associated with a all the memory channels.
*
* \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 rig_set_chan_all_cb(), rig_get_chan_all()
*/
int HAMLIB_API rig_set_chan_all (RIG *rig, const channel_t chans[])
{
struct rig_caps *rc;
int retval;
if (CHECK_RIG_ARG(rig) || !chans)
return -RIG_EINVAL;
rc = rig->caps;
if (rc->set_chan_all_cb)
return rc->set_chan_all_cb(rig, map_chan, (rig_ptr_t)chans);
/* if not available, emulate it */
retval = set_chan_all_cb_generic (rig, map_chan, (rig_ptr_t)chans);
return retval;
}
/**
* \brief get all channel data
* \param rig The rig handle
* \param chan The location where to store all the channel data
*
* Retrieves the data associated with a all the memory channels.
*
* \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 rig_get_chan_all_cb(), rig_set_chan_all()
*/
int HAMLIB_API rig_get_chan_all (RIG *rig, channel_t chans[])
{
struct rig_caps *rc;
int retval;
if (CHECK_RIG_ARG(rig) || !chans)
return -RIG_EINVAL;
rc = rig->caps;
if (rc->get_chan_all_cb)
return rc->get_chan_all_cb(rig, map_chan, chans);
/*
* if not available, emulate it
*
* TODO: save_current_state, restore_current_state
*/
retval = get_chan_all_cb_generic (rig, map_chan, chans);
return retval;
}