Logo Search packages:      
Sourcecode: hamlib version File versions  Download package

int HAMLIB_API rig_get_channel ( RIG rig,
channel_t chan 
)

get channel data

Parameters:
rigThe rig handle
chanThe location where to store the channel data

Retrieves the data associated with a channel. This channel can either be the state of a VFO specified by chan->vfo, or a memory channel specified with chan->vfo = RIG_VFO_MEM and chan->channel_num. See channel_t for more information.

Example:

  channel_t chan;
  int err;

  chan->vfo = RIG_VFO_MEM;
  chan->channel_num = 10;
  err = rig_get_channel(rig, &chan);
  if (err != RIG_OK)
      error("get_channel failed: %s", rigerror(err));

The rig_get_channel is supposed to have no impact on the current VFO and memory number selected. Depending on backend and rig capabilities, the chan struct may not be filled in completely.

Note: chan->ext_levels is a pointer to a newly mallocated memory. This is the responsability of the caller to manage and eventually free it.

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_set_channel()

Definition at line 626 of file mem.c.

References caps, channel::channel_num, rig_state::current_vfo, RIG_EINVAL, RIG_ENAVAIL, RIG_ENTARGET, rig_get_mem(), rig_has_vfo_op(), RIG_OK, RIG_OP_TO_VFO, rig_set_mem(), rig_set_vfo(), RIG_VFO_CURR, RIG_VFO_MEM, rig_vfo_op(), state, channel::vfo, and rig_state::vfo_list.

{
      struct rig_caps *rc;
      int curr_chan_num, get_mem_status = RIG_OK;
      vfo_t curr_vfo;
      vfo_t vfo;  /* requested vfo */
      int retcode;
      int can_emulate_by_vfo_mem, can_emulate_by_vfo_op;
#ifdef PARANOID_CHANNEL_HANDLING
      channel_t curr_chan;
#endif

      if (CHECK_RIG_ARG(rig) || !chan)
            return -RIG_EINVAL;

      /*
       * TODO: check validity of chan->channel_num
       */

      rc = rig->caps;

      if (rc->get_channel)
            return rc->get_channel(rig, chan);

      /*
       * if not available, emulate it
       * Optional: get_vfo, set_vfo
       * TODO: check return codes
       */
      vfo = chan->vfo;
      if (vfo == RIG_VFO_CURR)
            return generic_save_channel(rig, chan);

      /* any emulation requires set_mem() */
      if (vfo == RIG_VFO_MEM && !rc->set_mem)
            return -RIG_ENAVAIL;

      can_emulate_by_vfo_mem = rc->set_vfo &&
            ((rig->state.vfo_list & RIG_VFO_MEM) == RIG_VFO_MEM);

      can_emulate_by_vfo_op = rc->vfo_op &&
            rig_has_vfo_op(rig, RIG_OP_TO_VFO);

      if (!can_emulate_by_vfo_mem && !can_emulate_by_vfo_op)
            return -RIG_ENTARGET;

      curr_vfo = rig->state.current_vfo;
      /* may be needed if the restore_channel has some side effects */
#ifdef PARANOID_CHANNEL_HANDLING
      generic_save_channel(rig, &curr_chan);
#endif

      if (vfo == RIG_VFO_MEM)
            get_mem_status = rig_get_mem(rig, RIG_VFO_CURR, &curr_chan_num);

      if (can_emulate_by_vfo_mem && curr_vfo != vfo) {
            retcode = rig_set_vfo(rig, vfo);
            if (retcode != RIG_OK)
                  return retcode;
      }

      if (vfo == RIG_VFO_MEM)
            rig_set_mem(rig, RIG_VFO_CURR, chan->channel_num);

      if (!can_emulate_by_vfo_mem && can_emulate_by_vfo_op) {
            retcode = rig_vfo_op(rig, RIG_VFO_CURR, RIG_OP_TO_VFO);
            if (retcode != RIG_OK)
                  return retcode;
      }

      retcode = generic_save_channel(rig, chan);

      /* restore current memory number */
      if (vfo == RIG_VFO_MEM && get_mem_status == RIG_OK)
            rig_set_mem(rig, RIG_VFO_CURR, curr_chan_num);

      if (can_emulate_by_vfo_mem)
            rig_set_vfo(rig, curr_vfo);

#ifdef PARANOID_CHANNEL_HANDLING
      generic_restore_channel(rig, &curr_chan);
#endif
      return retcode;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index