kopia lustrzana https://github.com/Hamlib/Hamlib
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
rodzic
82785f81dc
commit
d9e1f5aac4
|
@ -98,7 +98,7 @@
|
||||||
constant from a constant number literal using ull */
|
constant from a constant number literal using ull */
|
||||||
// #define CONSTANT_64BIT_FLAG(BIT) (1 << (BIT))
|
// #define CONSTANT_64BIT_FLAG(BIT) (1 << (BIT))
|
||||||
// #define SWIGLUAHIDE
|
// #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
|
If you have the older version of SWIG comment out this line and use
|
||||||
the two above */
|
the two above */
|
||||||
// This 1ul definition works on swig 4.0.1 and lua 5.3.5
|
// This 1ul definition works on swig 4.0.1 and lua 5.3.5
|
||||||
|
@ -774,7 +774,7 @@ typedef enum {
|
||||||
/**
|
/**
|
||||||
* \brief Antenna number
|
* \brief Antenna number
|
||||||
* \def RIG_ANT_NONE
|
* \def RIG_ANT_NONE
|
||||||
* No antenna set yet or unknown
|
* No antenna set yet or unknown
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* \brief Antenna conversion macro
|
* \brief Antenna conversion macro
|
||||||
|
@ -1000,9 +1000,9 @@ enum rig_parm_e {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
enum cookie_e {
|
enum cookie_e {
|
||||||
RIG_COOKIE_GET,
|
RIG_COOKIE_GET, /*!< Setup a cookie */
|
||||||
RIG_COOKIE_RELEASE,
|
RIG_COOKIE_RELEASE, /*!< Release a cookie */
|
||||||
RIG_COOKIE_RENEW,
|
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
|
// 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
|
// 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 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 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 tx_range_list1[HAMLIB_FRQRANGESIZ]; /*!< Transmit frequency range list #1 */
|
||||||
freq_range_t rx_range_list2[HAMLIB_FRQRANGESIZ]; /*!< Receive frequency range list #2 */
|
freq_range_t rx_range_list2[HAMLIB_FRQRANGESIZ]; /*!< Receive frequency range list #2 */
|
||||||
|
@ -2210,7 +2210,7 @@ typedef enum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Rig cache data
|
* \brief Rig cache data
|
||||||
*
|
*
|
||||||
* This struct contains all the items we cache at the highest level
|
* This struct contains all the items we cache at the highest level
|
||||||
*/
|
*/
|
||||||
struct rig_cache {
|
struct rig_cache {
|
||||||
|
@ -2230,7 +2230,7 @@ struct rig_cache {
|
||||||
freq_t freqSubA; // VFO_SUBA -- only for rigs with dual Sub VFOs
|
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 freqSubB; // VFO_SUBB -- only for rigs with dual Sub VFOs
|
||||||
freq_t freqSubC; // VFO_SUBC -- only for rigs with 3 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 modeMainA;
|
||||||
rmode_t modeMainB;
|
rmode_t modeMainB;
|
||||||
rmode_t modeMainC;
|
rmode_t modeMainC;
|
||||||
|
@ -2347,7 +2347,7 @@ struct rig_state {
|
||||||
pbwidth_t current_width; /*!< Passband width currently set */
|
pbwidth_t current_width; /*!< Passband width currently set */
|
||||||
vfo_t tx_vfo; /*!< Tx VFO currently set */
|
vfo_t tx_vfo; /*!< Tx VFO currently set */
|
||||||
rmode_t mode_list; /*!< Complete list of modes for this rig */
|
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
|
// so anything added to this structure must be below here
|
||||||
int transmit; /*!< rig should be transmitting i.e. hard
|
int transmit; /*!< rig should be transmitting i.e. hard
|
||||||
wired PTT asserted - used by rigs that
|
wired PTT asserted - used by rigs that
|
||||||
|
@ -2501,10 +2501,10 @@ rig_get_vfo HAMLIB_PARAMS((RIG *rig,
|
||||||
|
|
||||||
extern HAMLIB_EXPORT(int)
|
extern HAMLIB_EXPORT(int)
|
||||||
rig_get_vfo_info HAMLIB_PARAMS((RIG *rig,
|
rig_get_vfo_info HAMLIB_PARAMS((RIG *rig,
|
||||||
vfo_t vfo,
|
vfo_t vfo,
|
||||||
freq_t *freq,
|
freq_t *freq,
|
||||||
rmode_t *mode,
|
rmode_t *mode,
|
||||||
pbwidth_t *width,
|
pbwidth_t *width,
|
||||||
split_t *split,
|
split_t *split,
|
||||||
int *satmode));
|
int *satmode));
|
||||||
|
|
||||||
|
@ -2904,30 +2904,30 @@ rig_has_scan HAMLIB_PARAMS((RIG *rig,
|
||||||
scan_t scan));
|
scan_t scan));
|
||||||
|
|
||||||
extern HAMLIB_EXPORT(int)
|
extern HAMLIB_EXPORT(int)
|
||||||
rig_set_channel HAMLIB_PARAMS((RIG *rig,
|
rig_set_channel HAMLIB_PARAMS((RIG *rig,
|
||||||
vfo_t vfo,
|
vfo_t vfo,
|
||||||
const channel_t *chan)); /* mem */
|
const channel_t *chan)); /* mem */
|
||||||
extern HAMLIB_EXPORT(int)
|
extern HAMLIB_EXPORT(int)
|
||||||
rig_get_channel HAMLIB_PARAMS((RIG *rig,
|
rig_get_channel HAMLIB_PARAMS((RIG *rig,
|
||||||
vfo_t vfo,
|
vfo_t vfo,
|
||||||
channel_t *chan, int read_only));
|
channel_t *chan, int read_only));
|
||||||
|
|
||||||
extern HAMLIB_EXPORT(int)
|
extern HAMLIB_EXPORT(int)
|
||||||
rig_set_chan_all HAMLIB_PARAMS((RIG *rig,
|
rig_set_chan_all HAMLIB_PARAMS((RIG *rig,
|
||||||
vfo_t vfo,
|
vfo_t vfo,
|
||||||
const channel_t chans[]));
|
const channel_t chans[]));
|
||||||
extern HAMLIB_EXPORT(int)
|
extern HAMLIB_EXPORT(int)
|
||||||
rig_get_chan_all HAMLIB_PARAMS((RIG *rig,
|
rig_get_chan_all HAMLIB_PARAMS((RIG *rig,
|
||||||
vfo_t vfo,
|
vfo_t vfo,
|
||||||
channel_t chans[]));
|
channel_t chans[]));
|
||||||
|
|
||||||
extern HAMLIB_EXPORT(int)
|
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,
|
vfo_t vfo,
|
||||||
chan_cb_t chan_cb,
|
chan_cb_t chan_cb,
|
||||||
rig_ptr_t));
|
rig_ptr_t));
|
||||||
extern HAMLIB_EXPORT(int)
|
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,
|
vfo_t vfo,
|
||||||
chan_cb_t chan_cb,
|
chan_cb_t chan_cb,
|
||||||
rig_ptr_t));
|
rig_ptr_t));
|
||||||
|
@ -2939,7 +2939,7 @@ rig_set_mem_all_cb HAMLIB_PARAMS((RIG *rig,
|
||||||
confval_cb_t parm_cb,
|
confval_cb_t parm_cb,
|
||||||
rig_ptr_t));
|
rig_ptr_t));
|
||||||
extern HAMLIB_EXPORT(int)
|
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,
|
vfo_t vfo,
|
||||||
chan_cb_t chan_cb,
|
chan_cb_t chan_cb,
|
||||||
confval_cb_t parm_cb,
|
confval_cb_t parm_cb,
|
||||||
|
|
50
src/rig.c
50
src/rig.c
|
@ -6763,17 +6763,27 @@ const char *HAMLIB_API rig_copyright()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief get a cookie to grab rig control
|
* \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
|
* Cookies should only be used when needed to keep commands sequenced correctly
|
||||||
* For example, when setting both VFOA and VFOB frequency and mode
|
* For example, when setting both VFOA and VFOB frequency and mode
|
||||||
* Example to wait for cookie, do rig commands, and release
|
* Example to wait for cookie, do rig commands, and release
|
||||||
* while((cookie=rig_cookie(NULL, RIG_COOKIE_GET)) == NULL) hl_usleep(10*1000);
|
* \code
|
||||||
* set_freq A;set mode A;set freq B;set modeB;
|
* while((rig_cookie(NULL, RIG_COOKIE_GET, cookie, sizeof(cookie))) != RIG_OK)
|
||||||
* rig_cookie(cookie,RIG_COOKIE_RELEASE);
|
* hl_usleep(10*1000);
|
||||||
* if wait!=0 rig_cookie with RIG_COOKIE_GET will wait for the cookie to become available
|
*
|
||||||
|
* //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 HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
|
||||||
int cookie_len)
|
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;
|
static pthread_mutex_t cookie_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
#endif
|
#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",
|
rig_debug(RIG_DEBUG_ERR, "%s(%d): cookie_len < %d\n",
|
||||||
__FILE__, __LINE__);
|
__FILE__, __LINE__, HAMLIB_COOKIE_SIZE);
|
||||||
return -RIG_EINTERNAL;
|
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)
|
switch (cookie_cmd)
|
||||||
{
|
{
|
||||||
case RIG_COOKIE_RELEASE:
|
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
|
if (cookie_save[0] != 0
|
||||||
&& strcmp(cookie, cookie_save) == 0) // matching cookie so we'll clear it
|
&& 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);
|
__FILE__, __LINE__, cookie_save);
|
||||||
memset(cookie_save, 0, sizeof(cookie_save));
|
memset(cookie_save, 0, sizeof(cookie_save));
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
|
@ -6894,7 +6904,7 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie,
|
||||||
break;
|
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;
|
return -RIG_EPROTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue