Fix and document rig_cookie;

Example in doxygen was wrong.
Description of parameters was wrong; we return an int so we cannot return
a NULL.
NULL check for cookies is needed for all 3 commands so move it up, fixing the
missing one.
Length check was wrong; cookie needs to be at least as large as
HAMLIB_COOKIE_SIZE otherwise subsequent checks will always faila
Document the 3 cookie commands a bit.
pull/801/head
Wouter van Gulik 2021-09-19 22:52:41 +02:00
rodzic 82785f81dc
commit d9e1f5aac4
2 zmienionych plików z 50 dodań i 40 usunięć

Wyświetl plik

@ -98,7 +98,7 @@
constant from a constant number literal using ull */
// #define CONSTANT_64BIT_FLAG(BIT) (1 << (BIT))
// #define SWIGLUAHIDE
/* But this appears to have been fixed so we'll use the correct one now
/* But this appears to have been fixed so we'll use the correct one now
If you have the older version of SWIG comment out this line and use
the two above */
// This 1ul definition works on swig 4.0.1 and lua 5.3.5
@ -774,7 +774,7 @@ typedef enum {
/**
* \brief Antenna number
* \def RIG_ANT_NONE
* No antenna set yet or unknown
* No antenna set yet or unknown
*/
/**
* \brief Antenna conversion macro
@ -1000,9 +1000,9 @@ enum rig_parm_e {
*
*/
enum cookie_e {
RIG_COOKIE_GET,
RIG_COOKIE_RELEASE,
RIG_COOKIE_RENEW,
RIG_COOKIE_GET, /*!< Setup a cookie */
RIG_COOKIE_RELEASE, /*!< Release a cookie */
RIG_COOKIE_RENEW, /*!< Renew a cookie */
};
/**
@ -1769,7 +1769,7 @@ struct rig_caps {
// As of 2020-02-12 we know of 5 models from Icom USA, EUR, ITR, TPE, KOR for the IC-9700
// So we currently have 5 ranges we need to deal with
// The backend for the model should fill in the label field to explain what model it is
// The the IC-9700 in ic7300.c for an example
// The the IC-9700 in ic7300.c for an example
freq_range_t rx_range_list1[HAMLIB_FRQRANGESIZ]; /*!< Receive frequency range list #1 */
freq_range_t tx_range_list1[HAMLIB_FRQRANGESIZ]; /*!< Transmit frequency range list #1 */
freq_range_t rx_range_list2[HAMLIB_FRQRANGESIZ]; /*!< Receive frequency range list #2 */
@ -2210,7 +2210,7 @@ typedef enum {
/**
* \brief Rig cache data
*
*
* This struct contains all the items we cache at the highest level
*/
struct rig_cache {
@ -2230,7 +2230,7 @@ struct rig_cache {
freq_t freqSubA; // VFO_SUBA -- only for rigs with dual Sub VFOs
freq_t freqSubB; // VFO_SUBB -- only for rigs with dual Sub VFOs
freq_t freqSubC; // VFO_SUBC -- only for rigs with 3 Sub VFOs
freq_t freqMem; // VFO_MEM -- last MEM channel
freq_t freqMem; // VFO_MEM -- last MEM channel
rmode_t modeMainA;
rmode_t modeMainB;
rmode_t modeMainC;
@ -2347,7 +2347,7 @@ struct rig_state {
pbwidth_t current_width; /*!< Passband width currently set */
vfo_t tx_vfo; /*!< Tx VFO currently set */
rmode_t mode_list; /*!< Complete list of modes for this rig */
// mode_list is used by some
// mode_list is used by some
// so anything added to this structure must be below here
int transmit; /*!< rig should be transmitting i.e. hard
wired PTT asserted - used by rigs that
@ -2501,10 +2501,10 @@ rig_get_vfo HAMLIB_PARAMS((RIG *rig,
extern HAMLIB_EXPORT(int)
rig_get_vfo_info HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
freq_t *freq,
rmode_t *mode,
pbwidth_t *width,
vfo_t vfo,
freq_t *freq,
rmode_t *mode,
pbwidth_t *width,
split_t *split,
int *satmode));
@ -2904,30 +2904,30 @@ rig_has_scan HAMLIB_PARAMS((RIG *rig,
scan_t scan));
extern HAMLIB_EXPORT(int)
rig_set_channel HAMLIB_PARAMS((RIG *rig,
rig_set_channel HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
const channel_t *chan)); /* mem */
extern HAMLIB_EXPORT(int)
rig_get_channel HAMLIB_PARAMS((RIG *rig,
rig_get_channel HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
channel_t *chan, int read_only));
extern HAMLIB_EXPORT(int)
rig_set_chan_all HAMLIB_PARAMS((RIG *rig,
rig_set_chan_all HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
const channel_t chans[]));
extern HAMLIB_EXPORT(int)
rig_get_chan_all HAMLIB_PARAMS((RIG *rig,
rig_get_chan_all HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
channel_t chans[]));
extern HAMLIB_EXPORT(int)
rig_set_chan_all_cb HAMLIB_PARAMS((RIG *rig,
rig_set_chan_all_cb HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
chan_cb_t chan_cb,
rig_ptr_t));
extern HAMLIB_EXPORT(int)
rig_get_chan_all_cb HAMLIB_PARAMS((RIG *rig,
rig_get_chan_all_cb HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
chan_cb_t chan_cb,
rig_ptr_t));
@ -2939,7 +2939,7 @@ rig_set_mem_all_cb HAMLIB_PARAMS((RIG *rig,
confval_cb_t parm_cb,
rig_ptr_t));
extern HAMLIB_EXPORT(int)
rig_get_mem_all_cb HAMLIB_PARAMS((RIG *rig,
rig_get_mem_all_cb HAMLIB_PARAMS((RIG *rig,
vfo_t vfo,
chan_cb_t chan_cb,
confval_cb_t parm_cb,

Wyświetl plik

@ -6763,17 +6763,27 @@ const char *HAMLIB_API rig_copyright()
/**
* \brief get a cookie to grab rig control
* \param rig Not used
* \param cookie_cmd The command to execute on \a cookie.
* \param cookie The cookie to operate on, cannot be NULL or RIG_EINVAL will be returned.
* \param cookie_len The length of the cookie, must be #HAMLIB_COOKIE_SIZE or larger.
*
* #RIG_COOKIE_GET will set \a cookie with a cookie.
* #RIG_COOKIE_RENEW will update the timeout with 1 second.
* #RIG_COOKIE_RELEASE will release the cookie and allow a new one to be grabbed.
*
* RIG_COOKIE_GET must have cookie=NULL or NULL returned
* RIG_COOKIE_RENEW must have cookie!=NULL or NULL returned
* RIG_COOKIE_RELEASE must have cookie!=NULL or NULL returned;
* Cookies should only be used when needed to keep commands sequenced correctly
* For example, when setting both VFOA and VFOB frequency and mode
* Example to wait for cookie, do rig commands, and release
* while((cookie=rig_cookie(NULL, RIG_COOKIE_GET)) == NULL) hl_usleep(10*1000);
* set_freq A;set mode A;set freq B;set modeB;
* rig_cookie(cookie,RIG_COOKIE_RELEASE);
* if wait!=0 rig_cookie with RIG_COOKIE_GET will wait for the cookie to become available
* \code
* while((rig_cookie(NULL, RIG_COOKIE_GET, cookie, sizeof(cookie))) != RIG_OK)
* hl_usleep(10*1000);
*
* //Pseudo code
* set_freq A;set mode A;set freq B;set modeB;
*
* rig_cookie(NULL, RIG_COOKIE_RELEASE, cookie, sizeof(cookie)));
* \endcode
*/
int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
int cookie_len)
@ -6791,27 +6801,27 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
static pthread_mutex_t cookie_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
if (cookie_len < 27)
if (cookie_len < HAMLIB_COOKIE_SIZE)
{
rig_debug(RIG_DEBUG_ERR, "%s(%d): cookie_len < 32 so returning NULL!!\n",
__FILE__, __LINE__);
return -RIG_EINTERNAL;
rig_debug(RIG_DEBUG_ERR, "%s(%d): cookie_len < %d\n",
__FILE__, __LINE__, HAMLIB_COOKIE_SIZE);
return -RIG_EINVAL;
}
if (!cookie)
{
rig_debug(RIG_DEBUG_ERR, "%s(%d): cookie == NULL\n",
__FILE__, __LINE__);
return -RIG_EINVAL; // nothing to do
}
switch (cookie_cmd)
{
case RIG_COOKIE_RELEASE:
if (cookie == NULL)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): coookie NULL so nothing to do\n",
__FILE__, __LINE__);
return -RIG_EINVAL; // nothing to do
}
if (cookie_save[0] != 0
&& strcmp(cookie, cookie_save) == 0) // matching cookie so we'll clear it
{
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): %s coookie released\n",
rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): %s cookie released\n",
__FILE__, __LINE__, cookie_save);
memset(cookie_save, 0, sizeof(cookie_save));
return RIG_OK;
@ -6894,7 +6904,7 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
break;
}
rig_debug(RIG_DEBUG_ERR, "%s(%d): unknown condition!!\n'", __FILE__, __LINE__);
rig_debug(RIG_DEBUG_ERR, "%s(%d): unknown cmd!!\n'", __FILE__, __LINE__);
return -RIG_EPROTO;
}