Logo Search packages:      
Sourcecode: hamlib version File versions

RIG* HAMLIB_API rig_init ( rig_model_t  rig_model  ) 

allocate a new RIG handle

Parameters:
rig_model The rig model for this new handle
Allocates a new RIG handle and initializes the associated data for rig_model.

Returns:
a pointer to the RIG handle otherwise NULL if memory allocation failed or rig_model is unknown (e.g. backend autoload failed).
See also:
rig_cleanup(), rig_open()

Definition at line 240 of file rig.c.

References rig_caps::announces, rig_state::announces, rig_caps::attenuator, rig_state::attenuator, caps, rig_caps::chan_list, rig_state::chan_list, rig_state::comm_state, rig_state::current_vfo, hamlib_port_t::dcd, rig_caps::dcd_type, rig_state::dcdport, hamlib_port_t::fd, rig_caps::filters, rig_state::filters, rig_caps::has_get_func, rig_state::has_get_func, rig_caps::has_get_level, rig_state::has_get_level, rig_caps::has_get_parm, rig_state::has_get_parm, rig_caps::has_set_func, rig_state::has_set_func, rig_caps::has_set_level, rig_state::has_set_level, rig_caps::has_set_parm, rig_state::has_set_parm, rig_state::itu_region, rig_caps::level_gran, rig_state::level_gran, rig_caps::max_ifshift, rig_state::max_ifshift, rig_caps::max_rit, rig_state::max_rit, rig_caps::max_xit, rig_state::max_xit, hamlib_port_t::parm, rig_caps::parm_gran, rig_state::parm_gran, hamlib_port_t::pathname, rig_state::poll_interval, rig_caps::port_type, rig_caps::post_write_delay, hamlib_port_t::post_write_delay, rig_caps::preamp, rig_state::preamp, hamlib_port_t::ptt, rig_caps::ptt_type, rig_state::pttport, rig_caps::retry, hamlib_port_t::retry, hamlib_port_t::rig, rig_debug(), RIG_DEBUG_VERBOSE, rig_caps::rig_init, RIG_LEVEL_RAWSTR, RIG_LEVEL_STRENGTH, RIG_OK, RIG_PORT_PARALLEL, RIG_PORT_SERIAL, RIG_VFO_CURR, rig_state::rigport, rig_state::rx_range_list, rig_caps::rx_range_list1, rig_caps::rx_range_list2, hamlib_port_t::serial, rig_caps::serial_data_bits, rig_caps::serial_handshake, rig_caps::serial_parity, rig_caps::serial_rate_max, rig_caps::serial_stop_bits, state, rig_caps::str_cal, rig_state::str_cal, rig_caps::timeout, hamlib_port_t::timeout, rig_state::transceive, rig_caps::tuning_steps, rig_state::tuning_steps, rig_state::tx_range_list, rig_caps::tx_range_list1, rig_caps::tx_range_list2, hamlib_port_t::type, freq_range_list::vfo, rig_state::vfo_comp, rig_state::vfo_list, rig_caps::write_delay, and hamlib_port_t::write_delay.

{
      RIG *rig;
      const struct rig_caps *caps;
      struct rig_state *rs;
      int i, retcode;

      rig_debug(RIG_DEBUG_VERBOSE,"rig:rig_init called \n");

      rig_check_backend(rig_model);

      caps = rig_get_caps(rig_model);
      if (!caps)
            return NULL;

      /*
       * okay, we've found it. Allocate some memory and set it to zeros,
       * and especially the initialize the callbacks 
       */ 
      rig = calloc(1, sizeof(RIG));
      if (rig == NULL) {
            /*
             * FIXME: how can the caller know it's a memory shortage,
             *            and not "rig not found" ?
             */
            return NULL;
      }

        /* caps is const, so we need to tell compiler
           that we now what we are doing */
      rig->caps = (struct rig_caps *) caps;

      /*
       * populate the rig->state
       * TODO: read the Preferences here! 
       */

      rs = &rig->state;

      rs->comm_state = 0;
      rs->rigport.type.rig = caps->port_type; /* default from caps */

      switch (caps->port_type) {
      case RIG_PORT_SERIAL:
      strncpy(rs->rigport.pathname, DEFAULT_SERIAL_PORT, FILPATHLEN);
      rs->rigport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */
      rs->rigport.parm.serial.data_bits = caps->serial_data_bits;
      rs->rigport.parm.serial.stop_bits = caps->serial_stop_bits;
      rs->rigport.parm.serial.parity = caps->serial_parity;
      rs->rigport.parm.serial.handshake = caps->serial_handshake;
      break;

      case RIG_PORT_PARALLEL:
      strncpy(rs->rigport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);
      break;

      default:
      strncpy(rs->rigport.pathname, "", FILPATHLEN);
      }

      rs->rigport.write_delay = caps->write_delay;
      rs->rigport.post_write_delay = caps->post_write_delay;
      rs->rigport.timeout = caps->timeout;
      rs->rigport.retry = caps->retry;
      rs->pttport.type.ptt = caps->ptt_type;
      rs->dcdport.type.dcd = caps->dcd_type;

      rs->vfo_comp = 0.0;     /* override it with preferences */
      rs->current_vfo = RIG_VFO_CURR;     /* we don't know yet! */
      rs->transceive = RIG_TRN_OFF;
      rs->poll_interval = 500;
      /* should it be a parameter to rig_init ? --SF */
      rs->itu_region = RIG_ITU_REGION2;

      switch(rs->itu_region) {
            case RIG_ITU_REGION1:
                  memcpy(rs->tx_range_list, caps->tx_range_list1, 
                              sizeof(struct freq_range_list)*FRQRANGESIZ);
                  memcpy(rs->rx_range_list, caps->rx_range_list1, 
                              sizeof(struct freq_range_list)*FRQRANGESIZ);
                  break;
            case RIG_ITU_REGION2:
            case RIG_ITU_REGION3:
            default:
                  memcpy(rs->tx_range_list, caps->tx_range_list2, 
                              sizeof(struct freq_range_list)*FRQRANGESIZ);
                  memcpy(rs->rx_range_list, caps->rx_range_list2, 
                              sizeof(struct freq_range_list)*FRQRANGESIZ);
                  break;
      }

      rs->vfo_list = 0;
      for (i=0; i<FRQRANGESIZ && !RIG_IS_FRNG_END(rs->rx_range_list[i]); i++) {
                  rs->vfo_list |= rs->rx_range_list[i].vfo;
      }
      for (i=0; i<FRQRANGESIZ && !RIG_IS_FRNG_END(rs->tx_range_list[i]); i++) {
                  rs->vfo_list |= rs->tx_range_list[i].vfo;
      }

      memcpy(rs->preamp, caps->preamp, sizeof(int)*MAXDBLSTSIZ);
      memcpy(rs->attenuator, caps->attenuator, sizeof(int)*MAXDBLSTSIZ);
      memcpy(rs->tuning_steps, caps->tuning_steps, 
                        sizeof(struct tuning_step_list)*TSLSTSIZ);
      memcpy(rs->filters, caps->filters, 
                        sizeof(struct filter_list)*FLTLSTSIZ);
      memcpy(&rs->str_cal, &caps->str_cal, 
                        sizeof(cal_table_t));

      memcpy(rs->chan_list, caps->chan_list, sizeof(chan_t)*CHANLSTSIZ);

      rs->has_get_func = caps->has_get_func;
      rs->has_set_func = caps->has_set_func;
      rs->has_get_level = caps->has_get_level;
      rs->has_set_level = caps->has_set_level;
      rs->has_get_parm = caps->has_get_parm;
      rs->has_set_parm = caps->has_set_parm;

      /* emulation by frontend */
      if ((caps->has_get_level & RIG_LEVEL_STRENGTH) == 0 &&
            (caps->has_get_level & RIG_LEVEL_RAWSTR) == RIG_LEVEL_RAWSTR)
            rs->has_get_level |= RIG_LEVEL_STRENGTH;

      memcpy(rs->level_gran, caps->level_gran, sizeof(gran_t)*RIG_SETTING_MAX);
      memcpy(rs->parm_gran, caps->parm_gran, sizeof(gran_t)*RIG_SETTING_MAX);

      rs->max_rit = caps->max_rit;
      rs->max_xit = caps->max_xit;
      rs->max_ifshift = caps->max_ifshift;
      rs->announces = caps->announces;

      rs->rigport.fd = rs->pttport.fd = rs->dcdport.fd = -1;

      /* 
       * let the backend a chance to setup his private data
       * This must be done only once defaults are setup,
       * so the backend init can override rig_state.
       */
      if (caps->rig_init != NULL) {
            retcode = caps->rig_init(rig);
            if (retcode != RIG_OK) {
                  rig_debug(RIG_DEBUG_VERBOSE,"rig:backend_init failed!\n");
                  /* cleanup and exit */
                  free(rig);
                  return NULL;
            }
      }

      return rig;
}


Generated by  Doxygen 1.6.0   Back to index