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

ROT* HAMLIB_API rot_init ( rot_model_t  rot_model )

allocate a new ROT handle

rot_modelThe rot model for this new handle

Allocates a new ROT handle and initializes the associated data for rot_model.

a pointer to the ROT handle otherwise NULL if memory allocation failed or rot_model is unknown (e.g. backend autoload failed).
See also:
rot_cleanup(), rot_open()

Definition at line 175 of file rotator.c.

References rot::caps, rot_state::comm_state, hamlib_port_t::fd, rot_caps::max_az, rot_state::max_az, rot_caps::max_el, rot_state::max_el, rot_caps::min_az, rot_state::min_az, rot_caps::min_el, rot_state::min_el, hamlib_port_t::parm, hamlib_port_t::pathname, rot_caps::port_type, rot_caps::post_write_delay, hamlib_port_t::post_write_delay, rot_caps::retry, hamlib_port_t::retry, hamlib_port_t::rig, RIG_DEBUG_VERBOSE, RIG_OK, RIG_PORT_NETWORK, RIG_PORT_PARALLEL, RIG_PORT_SERIAL, rot_debug, rot_state::rotport, hamlib_port_t::serial, rot_caps::serial_data_bits, rot_caps::serial_handshake, rot_caps::serial_parity, rot_caps::serial_rate_max, rot_caps::serial_stop_bits, rot::state, rot_caps::timeout, hamlib_port_t::timeout, rot_caps::write_delay, and hamlib_port_t::write_delay.

      ROT *rot;
      const struct rot_caps *caps;
      struct rot_state *rs;
      int retcode;

      rot_debug(RIG_DEBUG_VERBOSE,"rot:rot_init called \n");


      caps = rot_get_caps(rot_model);
      if (!caps)
            return NULL;

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

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

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

      rs = &rot->state;

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

      rs->rotport.write_delay = caps->write_delay;
      rs->rotport.post_write_delay = caps->post_write_delay;
      rs->rotport.timeout = caps->timeout;
      rs->rotport.retry = caps->retry;

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

      strncpy(rs->rotport.pathname, DEFAULT_PARALLEL_PORT, FILPATHLEN);

      case RIG_PORT_NETWORK:
      strncpy(rs->rotport.pathname, "", FILPATHLEN);

      strncpy(rs->rotport.pathname, "", FILPATHLEN);

      rs->min_el = caps->min_el;
      rs->max_el = caps->max_el;
      rs->min_az = caps->min_az;
      rs->max_az = caps->max_az;

      rs->rotport.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 rot_state.
      if (caps->rot_init != NULL) {
            retcode = caps->rot_init(rot);
            if (retcode != RIG_OK) {
                  rot_debug(RIG_DEBUG_VERBOSE,"rot:backend_init failed!\n");
                  /* cleanup and exit */
                  return NULL;

      return rot;

Generated by  Doxygen 1.6.0   Back to index