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

int HAMLIB_API rig_open ( RIG rig )

open the communication to the rig

Parameters:
rigThe RIG handle of the radio to be opened

Opens communication to a radio which RIG handle has been passed by argument.

Returns:
RIG_OK if the operation has been sucessful, otherwise a negative value if an error occured (in which case, cause is set appropriately).
Return values:
RIG_EINVALrig is NULL or unconsistent.
RIG_ENIMPLport type communication is not implemented yet.
See also:
rig_init(), rig_close()

Definition at line 425 of file rig.c.

References caps, rig_state::comm_state, rig_state::current_vfo, hamlib_port_t::dcd, rig_state::dcdport, hamlib_port_t::fd, par_open(), par_ptt_set(), hamlib_port_t::parm, hamlib_port_t::pathname, port_open(), hamlib_port_t::ptt, rig_state::pttport, hamlib_port_t::rig, RIG_DCD_NONE, RIG_DCD_PARALLEL, RIG_DCD_RIG, RIG_DCD_SERIAL_CAR, RIG_DCD_SERIAL_CTS, RIG_DCD_SERIAL_DSR, rig_debug(), RIG_DEBUG_ERR, RIG_DEBUG_VERBOSE, RIG_ECONF, RIG_EINVAL, rig_get_trn(), rig_get_vfo(), RIG_HANDSHAKE_HARDWARE, RIG_OK, RIG_PORT_SERIAL, RIG_PTT_NONE, RIG_PTT_OFF, RIG_PTT_PARALLEL, RIG_PTT_RIG, RIG_PTT_SERIAL_DTR, RIG_PTT_SERIAL_RTS, RIG_SIGNAL_UNSET, rig_state::rigport, ser_open(), ser_set_dtr(), ser_set_rts(), hamlib_port_t::serial, state, rig_state::transceive, and rig_state::tx_vfo.

{
      const struct rig_caps *caps;
      struct rig_state *rs;
      int status;

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

      if (!rig || !rig->caps)
            return -RIG_EINVAL;

      caps = rig->caps;
      rs = &rig->state;

      if (rs->comm_state)
            return -RIG_EINVAL;

      rs->rigport.fd = -1;

      if (rs->rigport.type.rig == RIG_PORT_SERIAL) {

            if (rs->rigport.parm.serial.rts_state != RIG_SIGNAL_UNSET &&
                        (rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS ||
                        rs->rigport.parm.serial.handshake == RIG_HANDSHAKE_HARDWARE)) {

                  rig_debug(RIG_DEBUG_ERR, "Cannot set RTS with PTT by RTS or hardware handshare \"%s\"\n",
                                    rs->rigport.pathname);
            return -RIG_ECONF;
            }
            if (rs->rigport.parm.serial.dtr_state != RIG_SIGNAL_UNSET &&
                        rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR) {
                  rig_debug(RIG_DEBUG_ERR, "Cannot set DTR with PTT by DTR\"%s\"\n",
                                    rs->rigport.pathname);
            return -RIG_ECONF;
            }
    }

    status = port_open(&rs->rigport);
    if (status < 0)
        return status;


      /*
       * FIXME: what to do if PTT open fails or PTT unsupported?
       *                fail rig_open?  remember unallocating..
       */
      switch(rs->pttport.type.ptt) {
      case RIG_PTT_NONE:
      case RIG_PTT_RIG:
            break;
      case RIG_PTT_SERIAL_RTS:
      case RIG_PTT_SERIAL_DTR:
            if (rs->pttport.pathname[0] == '\0' &&
                        rs->rigport.type.rig == RIG_PORT_SERIAL)
                  strcpy(rs->pttport.pathname, rs->rigport.pathname);
            rs->pttport.fd = ser_open(&rs->pttport);
            if (rs->pttport.fd < 0)
                  rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n",
                                    rs->pttport.pathname);
        else {
                  /* Needed on Linux because the kernel forces RTS/DTR at open */
                  if (rs->pttport.type.ptt == RIG_PTT_SERIAL_DTR)
                        ser_set_dtr(&rs->pttport, RIG_PTT_OFF);
                  else if (rs->pttport.type.ptt == RIG_PTT_SERIAL_RTS)
                        ser_set_rts(&rs->pttport, RIG_PTT_OFF);
            }
            break;
      case RIG_PTT_PARALLEL:
            rs->pttport.fd = par_open(&rs->pttport);
            if (rs->pttport.fd < 0)
                  rig_debug(RIG_DEBUG_ERR, "Cannot open PTT device \"%s\"\n",
                                    rs->pttport.pathname);
        else
                  par_ptt_set(&rs->pttport, RIG_PTT_OFF);
            break;
      default:
            rig_debug(RIG_DEBUG_ERR, "Unsupported PTT type %d\n",
                                    rs->pttport.type.ptt);
      }

      switch(rs->dcdport.type.dcd) {
      case RIG_DCD_NONE:
      case RIG_DCD_RIG:
            break;
      case RIG_DCD_SERIAL_DSR:
      case RIG_DCD_SERIAL_CTS:
      case RIG_DCD_SERIAL_CAR:
            if (rs->dcdport.pathname[0] == '\0' &&
                        rs->rigport.type.rig == RIG_PORT_SERIAL)
                  strcpy(rs->dcdport.pathname, rs->rigport.pathname);
            rs->dcdport.fd = ser_open(&rs->dcdport);
            if (rs->dcdport.fd < 0)
                  rig_debug(RIG_DEBUG_ERR, "Cannot open DCD device \"%s\"\n",
                                    rs->dcdport.pathname);
            break;
      case RIG_DCD_PARALLEL:
            rs->dcdport.fd = par_open(&rs->dcdport);
            if (rs->dcdport.fd < 0)
                  rig_debug(RIG_DEBUG_ERR, "Cannot open DCD device \"%s\"\n",
                                    rs->dcdport.pathname);
            break;
      default:
            rig_debug(RIG_DEBUG_ERR, "Unsupported DCD type %d\n",
                                    rs->dcdport.type.dcd);
      }

      add_opened_rig(rig);

      rs->comm_state = 1;

      /*
       * Maybe the backend has something to initialize
       * In case of failure, just close down and report error code.
       */
      if (caps->rig_open != NULL) {
            status = caps->rig_open(rig);
            if (status != RIG_OK) {
                  return status;
            }
      }

      /*
       * trigger state->current_vfo first retrieval
       */
        if (rig_get_vfo(rig, &rs->current_vfo) == RIG_OK)
            rs->tx_vfo = rs->current_vfo;

#if 0
        /*
         * Check the current tranceive state of the rig
         */
        if (rs->transceive == RIG_TRN_RIG) {
            int retval, trn;
            retval = rig_get_trn(rig, &trn);
            if (retval == RIG_OK && trn == RIG_TRN_RIG)
                add_trn_rig(rig);
        }
#endif
      return RIG_OK;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index