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

int HAMLIB_API rig_open ( RIG rig  ) 

open the communication to the rig

Parameters:
rig The 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_EINVAL rig is NULL or unconsistent.
RIG_ENIMPL port type communication is not implemented yet.
See also:
rig_init(), rig_close()

Definition at line 398 of file rig.c.

References rig::caps, rig_state::comm_state, rig_state::current_vfo, hamlib_port_t::dcd, rig_state::dcdport, hamlib_port_t::fd, hamlib_port_t::parm, hamlib_port_t::pathname, 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_get_vfo(), RIG_HANDSHAKE_HARDWARE, rig_caps::rig_open, RIG_PORT_DEVICE, RIG_PORT_NETWORK, RIG_PORT_NONE, RIG_PORT_PARALLEL, RIG_PORT_RPC, RIG_PORT_SERIAL, RIG_PTT_NONE, RIG_PTT_PARALLEL, RIG_PTT_RIG, RIG_PTT_SERIAL_DTR, RIG_PTT_SERIAL_RTS, RIG_SIGNAL_ON, RIG_SIGNAL_UNSET, rig_state::rigport, hamlib_port_t::serial, rig::state, rig_state::transceive, and hamlib_port_t::type.

{
            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;

            switch(rs->rigport.type.rig) {
            case RIG_PORT_SERIAL:
                        status = serial_open(&rs->rigport);
                        if (status < 0)
                                    return status;
                        if (rs->rigport.parm.serial.rts_state != RIG_SIGNAL_UNSET &&
                                    rs->rigport.type.ptt != RIG_PTT_SERIAL_RTS &&
                                    rs->rigport.parm.serial.handshake != RIG_HANDSHAKE_HARDWARE) {
                              status = ser_set_rts(&rs->rigport, 
                                          rs->rigport.parm.serial.rts_state == RIG_SIGNAL_ON);
                        }
                        if (status != 0)
                              return status;
                        if (rs->rigport.parm.serial.dtr_state != RIG_SIGNAL_UNSET &&
                                    rs->rigport.type.ptt != RIG_PTT_SERIAL_DTR) {
                              status = ser_set_dtr(&rs->rigport, 
                                          rs->rigport.parm.serial.dtr_state == RIG_SIGNAL_ON);
                        }
                        if (status != 0)
                              return status;
                        break;

            case RIG_PORT_PARALLEL:
                        status = par_open(&rs->rigport);
                        if (status < 0)
                              return status;
                        break;

            case RIG_PORT_DEVICE:
                        status = open(rs->rigport.pathname, O_RDWR, 0);
                        if (status < 0)
                                    return -RIG_EIO;
                        rs->rigport.fd = status;
                        break;

            case RIG_PORT_NONE:
            case RIG_PORT_RPC:
                        break;      /* ez :) */

            case RIG_PORT_NETWORK:  /* not implemented yet! */
                        return -RIG_ENIMPL;
            default:
                        return -RIG_EINVAL;
            }

            /*
             * 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:
                        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);
                        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);
                        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:
                        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
             */
        rig_get_vfo(rig, &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;
}


Generated by  Doxygen 1.6.0   Back to index