⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analogchannel.java

📁 著名的dialogic电话语音卡的java驱动程序,已经验证可用。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            try {
                voiceDev.setCallerIdEnabled(callerIdEnabled);
                voiceDev.waitRings(minRings);
            } catch (ChannelException ie) {
                // Somebody is asking me to leave, outdial/reconfig
                if (linestate != OFFH) {
                    setState(OOS); // In the mean time
                    continue;
                }
                return;
            }
       	    call = new Call(AnalogChannel.this);
       	    call.dnis = dnis;
       	    linestate = ICALL;
       	    setState(INCOMING);
       	    if (handler != null)
       	        handler.handleCall(call);
        }
    }
    
    /**
     *  Returns the class name and the name of the asociated voice resource.
     */
     public String toString() {
        return "AnalogChannel on " + voiceDev;
    }
    
    /**
     *  Get the associated Voice resource.
     *  @return The Voice object attached to this channel.
     */
    public Voice getVoice() {
        return voiceDev;
    }

    /**
     * Get the associated Network device
     * only available on SC capable boards, used for routing.
     * @return The Device object attached to this channel.
     */
    public Device getNetwork() {
        return agLine;
    }


    /**
     *  Accept a call.
     */
    void accept() {
        if (linestate != ICALL)
            throw new ChannelException("accept(): wrong state");
        // As there is no way of signalling this, just change the linestate.
        linestate = RINGS;
    }
    
    /**
     *  Answer a call.
     */
    void answer(int rings) {
        if (linestate == ICALL)
            accept();
        if (linestate != RINGS)
            throw new ChannelException("answer(): wrong state");
        EVT evt = null;
        long now = System.currentTimeMillis();
        long conn = call.startTime() + (rings - minRings) * 3000; // 3 secs each, some already gone
        try {
            beginService();
            if (conn > now) 
                evt = serviceWaitEvent(conn - now);
            if (evt == null) {    
                voiceDev.setHook(true);
                linestate = IN;
            } else {
                linestate = RESET;
                setState(OOS);
                throw new ChannelException("accept():" + evt);
            }
        } finally {
            endService();
        }
    }

     /**
     *  Reject a call. 
     */
     void reject(int reason) {
        if (linestate != ICALL)
            throw new ChannelException("reject(): wrong state");
        linestate = RESET;
        setState(OOS);
        // As there is no way of signalling this, just leaves it ringing.
        // Wait for RingOff event upto 30 secs
        try {
            beginService();
            serviceWaitEvent(30000);
        } finally {
            endService();
        }
    }
    
    /**
     *  Places an outbound call.
     *  @see #setBlindDial
     *  @see #setPerfectCall
     *  @param call The call object to be used for this connection.
     *  @param number The number to dial
     */
    void dial(Call call, String number) {
        if (linestate != IDLE)
            throw new ChannelException("dial(): wrong state");
        linestate = OFFH;
        if (serviceThread != null) {
            Channel.stopGroup(this);
            serviceThread.interrupt();
            try {
                serviceThread.join();
            }
            catch(InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
            serviceThread = null;
        }
        this.call = call;
        setState(OUTGOING);
        if ((Dialogic.debug & Dialogic.DEBUG_CHANNEL) != 0) {
            System.out.println(this.toString() + " calling " + number);
        }
        try {
            beginService();
            if (perfectCall && !perfectCallInit) {
                  // Init PerfectCall engine
                  voiceDev.initPerfectCall();
                  perfectCallInit = true;
            }
            EVT evt = null;
            voiceDev.setHook(true);
            if (!perfectCall) {
            
                // Wait dialtone
                evt = serviceWaitEvent(3000); // 3 seconds ok ?
                // D41ESC quirk...
                if (evt == null || 
                    (evt.type != EVT.TDX_CST || evt.cstevt != EVT.DE_TONEON)) {
                    if ((Dialogic.debug & Dialogic.DEBUG_CHANNEL) != 0) {
                        System.out.println(this.toString() + " No dialtone!");
                    }
                    if (!blindDial) {
                        if (call != null) call.drop();
                        throw new ChannelException("dial(): No Dialtone");
                    }
                }
            }
        } finally {
            endService();
        }
        linestate = DIAL;
        voiceDev.setGTD(dialtone1, false, false);
        if (dialtone2 != 0) voiceDev.setGTD(dialtone2, false, false);
        
        linestate=OUT;
        voiceDev.dial(number, cap, perfectCall);
    }
    
    /**
     *  Get the phone number of the calling party, when available.
     *
     *  @returns the directory number (DN) of the caller. Returns a
     *  zero-length string if the data is not available or not supported
     *  by the underlying hardware.
     */
     String ani() {
     	// Analog ANI is Caller-ID
        return voiceDev.getAni();
    }

    /**
     *  Retrieves extended Caller-ID information, such as the time of the call.
     *  <p>
     *  Does not accept <code>Dialogic.CLIDINFO_FRAMETYPE</code> as an argument;
     *  see {@link #callerIdFrameType} to get the frame type.
     *
     *  @param infoType the type of data to be retrieved.
     *  @return The value of the requested data element. If the element is not present,
     *          a zero-length string is returned.
     *  @since 0.5
     */
    public String callerIdExtended(int infoType) {
        return voiceDev.getCallerIdExtended(infoType);
    }

    /**
     *  Gets the type of the Caller-ID data frame. The frame type defines
     *  what additional information is available, if any.
     *  @return An integer that identifies the frame type. Frame types are
     *          defined in {@link local.dialogic.Dialogic}.
     *  @since 0.5
     */
    public int callerIdFrameType() {
        return voiceDev.getCallerIdFrameType();
    }

    /**
     *  Retrievs accounting info for the current call.
     *  @return zero.
     */
    int pulses() {
        // As there is no signalling for this, just return 0.
        return 0;
    }
    
    /**
     *  Clear the channel.
     *  <p>
     *  Stops any current voice operation, sets the line on hook, flushes
     *  any DTMF in the input buffer, and resets all other channel states.
     */
	synchronized void clear() {
        if (linestate == RESET)
            return;
        /**
         * Beware of clear loop in ICALL linestate:
         * when we clear in ICALL, line is actually ringing, after we do onhook,
         * driver sends us again a RING and we are likely to clear again, and again.
         */
        if (linestate == ICALL)
            reject(0);
        super.clear();
        linestate = RESET;
        voiceDev.stop();
        voiceDev.clear();
        voiceDev.setHook(false);
        try {
            Thread.sleep(200);
        } 
        catch(InterruptedException ie) {
            Thread.currentThread().interrupt();
        }
        flush();
        if (agLine != null) {
            agLine.listen(voiceDev);
            voiceDev.listen(agLine);
        }
        voiceDev.setGTD(dialtone1, true, false);
        if (dialtone2 != 0) voiceDev.setGTD(dialtone2, true, false);
        
        if (serviceThread == null) {
            serviceThread = new Thread(group, this, mydev + " service");
            serviceThread.start();
        }
    }
    
    /**
     *  Process events to track changes in line state.
     */
     protected EVT service(EVT evt) {
        switch(evt.type) {
        case EVT.TDX_CST:
            if (linestate != RESET && linestate != IDLE && linestate != OFFH &&
                (evt.cstevt == EVT.DE_LCOF ||
                (evt.cstevt == EVT.DE_TONEON && (evt.cstdata == dialtone1 ||
                                                evt.cstdata == dialtone2)))) {
                clear();
                if (call != null) call.drop();                                 
                throw new HangUpException();
            }
            break;
        case EVT.TDX_CALLP:
            evt.data = voiceDev.callpStatus();
            if (evt.data == Dialogic.CR_CNCT) {
                voiceDev.setGTD(dialtone1, true, false);
                if (dialtone2 != 0) voiceDev.setGTD(dialtone2, true, false);
                if (call != null) call.connect();
                break;
            } else if (evt.data == Dialogic.CR_BUSY) 
                throw new BusyException("dial(): Busy");
            else 
                throw new ChannelException("dial(): error in call progress");
        }
        return evt;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -