kopia lustrzana https://github.com/Hamlib/Hamlib
- Better state transitions in rig_set_trn()
- (weakly) prevent recursion in search_rig_and_poll() git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2953 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.12
rodzic
7cfb17d67a
commit
a539c8fe0c
56
src/event.c
56
src/event.c
|
@ -1,9 +1,8 @@
|
||||||
/*
|
/*
|
||||||
* Hamlib Interface - event handling
|
* Hamlib Interface - event handling
|
||||||
* Copyright (c) 2000-2009 by Stephane Fillod
|
* Copyright (c) 2000-2010 by Stephane Fillod
|
||||||
* Copyright (c) 2000-2003 by Frank Singleton
|
* Copyright (c) 2000-2003 by Frank Singleton
|
||||||
*
|
*
|
||||||
* $Id: event.c,v 1.25 2006-10-15 00:27:51 aa6e Exp $
|
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -163,7 +162,7 @@ int add_trn_poll_rig(RIG *rig)
|
||||||
status = sigaction(SIGALRM, &act, NULL);
|
status = sigaction(SIGALRM, &act, NULL);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
rig_debug(RIG_DEBUG_ERR,"%s sigaction failed: %s\n",
|
rig_debug(RIG_DEBUG_ERR,"%s sigaction failed: %s\n",
|
||||||
__FUNCTION__,
|
__func__,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
return RIG_OK;
|
return RIG_OK;
|
||||||
|
@ -276,6 +275,8 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
|
||||||
if (rig->state.hold_decode)
|
if (rig->state.hold_decode)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
rig->state.hold_decode = 2;
|
||||||
|
|
||||||
if (rig->caps->get_vfo && rig->callbacks.vfo_event) {
|
if (rig->caps->get_vfo && rig->callbacks.vfo_event) {
|
||||||
vfo_t vfo = RIG_VFO_CURR;
|
vfo_t vfo = RIG_VFO_CURR;
|
||||||
|
|
||||||
|
@ -313,6 +314,8 @@ static int search_rig_and_poll(RIG *rig, rig_ptr_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rig->state.hold_decode = 0;
|
||||||
|
|
||||||
return 1; /* process each opened rig */
|
return 1; /* process each opened rig */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,28 +550,43 @@ int HAMLIB_API rig_set_pltune_callback(RIG *rig, pltune_cb_t cb, rig_ptr_t arg)
|
||||||
int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
||||||
{
|
{
|
||||||
const struct rig_caps *caps;
|
const struct rig_caps *caps;
|
||||||
int retcode;
|
int retcode = RIG_OK;
|
||||||
|
#ifdef HAVE_SETITIMER
|
||||||
|
struct itimerval value;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (CHECK_RIG_ARG(rig))
|
if (CHECK_RIG_ARG(rig))
|
||||||
return -RIG_EINVAL;
|
return -RIG_EINVAL;
|
||||||
|
|
||||||
caps = rig->caps;
|
caps = rig->caps;
|
||||||
|
|
||||||
if (trn == RIG_TRN_RIG) {
|
/* detect whether tranceive is active already */
|
||||||
|
if (trn != RIG_TRN_OFF && rig->state.transceive != RIG_TRN_OFF) {
|
||||||
|
if (trn == rig->state.transceive) {
|
||||||
|
return RIG_OK;
|
||||||
|
} else {
|
||||||
|
/* when going POLL<->RIG, transtition to OFF */
|
||||||
|
retcode = rig_set_trn(rig, RIG_TRN_OFF);
|
||||||
|
if (retcode != RIG_OK)
|
||||||
|
return retcode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (trn) {
|
||||||
|
case RIG_TRN_RIG:
|
||||||
if (caps->transceive != RIG_TRN_RIG)
|
if (caps->transceive != RIG_TRN_RIG)
|
||||||
return -RIG_ENAVAIL;
|
return -RIG_ENAVAIL;
|
||||||
|
|
||||||
if (rig->state.transceive == RIG_TRN_OFF) {
|
|
||||||
retcode = add_trn_rig(rig);
|
retcode = add_trn_rig(rig);
|
||||||
|
/* some protocols (e.g. CI-V's) offer no way
|
||||||
|
* to turn on/off the transceive mode */
|
||||||
if (retcode == RIG_OK && caps->set_trn) {
|
if (retcode == RIG_OK && caps->set_trn) {
|
||||||
retcode = caps->set_trn(rig, RIG_TRN_RIG);
|
retcode = caps->set_trn(rig, RIG_TRN_RIG);
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
return -RIG_ECONF;
|
|
||||||
}
|
case RIG_TRN_POLL:
|
||||||
} else if (trn == RIG_TRN_POLL) {
|
|
||||||
#ifdef HAVE_SETITIMER
|
#ifdef HAVE_SETITIMER
|
||||||
struct itimerval value;
|
|
||||||
|
|
||||||
add_trn_poll_rig(rig);
|
add_trn_poll_rig(rig);
|
||||||
|
|
||||||
|
@ -580,7 +598,7 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
||||||
retcode = setitimer(ITIMER_REAL, &value, NULL);
|
retcode = setitimer(ITIMER_REAL, &value, NULL);
|
||||||
if (retcode == -1) {
|
if (retcode == -1) {
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
|
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
|
||||||
__FUNCTION__,
|
__func__,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
remove_trn_rig(rig);
|
remove_trn_rig(rig);
|
||||||
return -RIG_EINTERNAL;
|
return -RIG_EINTERNAL;
|
||||||
|
@ -588,10 +606,11 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
||||||
#else
|
#else
|
||||||
return -RIG_ENAVAIL;
|
return -RIG_ENAVAIL;
|
||||||
#endif
|
#endif
|
||||||
} else if (trn == RIG_TRN_OFF) {
|
break;
|
||||||
|
|
||||||
|
case RIG_TRN_OFF:
|
||||||
if (rig->state.transceive == RIG_TRN_POLL) {
|
if (rig->state.transceive == RIG_TRN_POLL) {
|
||||||
#ifdef HAVE_SETITIMER
|
#ifdef HAVE_SETITIMER
|
||||||
struct itimerval value;
|
|
||||||
|
|
||||||
retcode = remove_trn_rig(rig);
|
retcode = remove_trn_rig(rig);
|
||||||
|
|
||||||
|
@ -603,25 +622,28 @@ int HAMLIB_API rig_set_trn(RIG *rig, int trn)
|
||||||
retcode = setitimer(ITIMER_REAL, &value, NULL);
|
retcode = setitimer(ITIMER_REAL, &value, NULL);
|
||||||
if (retcode == -1) {
|
if (retcode == -1) {
|
||||||
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
|
rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
|
||||||
__FUNCTION__,
|
__func__,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return -RIG_EINTERNAL;
|
return -RIG_EINTERNAL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return -RIG_ENAVAIL;
|
return -RIG_ENAVAIL;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else if (rig->state.transceive == RIG_TRN_RIG) {
|
||||||
retcode = remove_trn_rig(rig);
|
retcode = remove_trn_rig(rig);
|
||||||
if (caps->set_trn && caps->transceive == RIG_TRN_RIG) {
|
if (caps->set_trn && caps->transceive == RIG_TRN_RIG) {
|
||||||
retcode = caps->set_trn(rig, RIG_TRN_OFF);
|
retcode = caps->set_trn(rig, RIG_TRN_OFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
return -RIG_EINVAL;
|
return -RIG_EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retcode == RIG_OK)
|
if (retcode == RIG_OK)
|
||||||
rig->state.transceive = trn;
|
rig->state.transceive = trn;
|
||||||
|
|
||||||
return retcode;
|
return retcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue