Logo Search packages:      
Sourcecode: hamlib version File versions

int HAMLIB_API rig_set_trn ( RIG rig,
int  trn 
)

control the transceive mode

Parameters:
rig The rig handle
trn The transceive status to set to
Enable/disable the transceive handling of a rig and kick off async mode.

Returns:
RIG_OK if the operation has been sucessful, otherwise a negative value if an error occured (in which case, cause is set appropriately).
See also:
rig_get_trn()

Definition at line 546 of file event.c.

References caps, rig_state::poll_interval, rig_debug(), RIG_DEBUG_ERR, RIG_ECONF, RIG_EINTERNAL, RIG_EINVAL, RIG_ENAVAIL, RIG_OK, rig_caps::set_trn, state, rig_state::transceive, and rig_caps::transceive.

{
      const struct rig_caps *caps;
      int retcode;

      if (CHECK_RIG_ARG(rig))
            return -RIG_EINVAL;

      caps = rig->caps;

      if (trn == RIG_TRN_RIG) {
            if (caps->transceive != RIG_TRN_RIG)
                  return -RIG_ENAVAIL;

            if (rig->state.transceive == RIG_TRN_OFF) {
                  retcode = add_trn_rig(rig);
                  if (retcode == RIG_OK && caps->set_trn) {
                        retcode = caps->set_trn(rig, RIG_TRN_RIG);
                  }
            } else {
                  return -RIG_ECONF;
            }
      } else if (trn == RIG_TRN_POLL) {
#ifdef HAVE_SETITIMER
            struct itimerval value;

            add_trn_poll_rig(rig);

            /* install handler here */
            value.it_value.tv_sec = 0;
            value.it_value.tv_usec = rig->state.poll_interval*1000;
            value.it_interval.tv_sec = 0;
            value.it_interval.tv_usec = rig->state.poll_interval*1000;
            retcode = setitimer(ITIMER_REAL, &value, NULL);
            if (retcode == -1) {
                  rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
                              __FUNCTION__,
                              strerror(errno));
                  remove_trn_rig(rig);
                  return -RIG_EINTERNAL;
            }
#else
            return -RIG_ENAVAIL;
#endif
      } else if (trn == RIG_TRN_OFF) {
            if (rig->state.transceive == RIG_TRN_POLL) {
#ifdef HAVE_SETITIMER
                  struct itimerval value;

                  retcode = remove_trn_rig(rig);

                  value.it_value.tv_sec = 0;
                  value.it_value.tv_usec = 0;
                  value.it_interval.tv_sec = 0;
                  value.it_interval.tv_usec = 0;

                  retcode = setitimer(ITIMER_REAL, &value, NULL);
                  if (retcode == -1) {
                        rig_debug(RIG_DEBUG_ERR, "%s: setitimer: %s\n",
                              __FUNCTION__,
                              strerror(errno));
                        return -RIG_EINTERNAL;
                  }
#else
            return -RIG_ENAVAIL;
#endif
            } else {
                  retcode = remove_trn_rig(rig);
                  if (caps->set_trn && caps->transceive == RIG_TRN_RIG) {
                        retcode = caps->set_trn(rig, RIG_TRN_OFF);
                  }
            }
      } else {
            return -RIG_EINVAL;
      }

      if (retcode == RIG_OK)
            rig->state.transceive = trn;
      return retcode;
}


Generated by  Doxygen 1.6.0   Back to index