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

📄 r2caschannel.java

📁 著名的dialogic电话语音卡的java驱动程序,已经验证可用。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        } else
            voiceDev.r2_sendb(Voice.SIGA_6, r2tone);
        // Accept end: forward cat off & back done
        while (true) {
            evt = serviceWaitEvent();
            if (evt.type == EVT.TDX_PLAYTONE ||
                (evt.type == EVT.TDX_CST && evt.cstevt == EVT.DE_TONEOFF)) {
                if (acceptOne) {
                    try {
                        Thread.sleep(R2ConnDelayIn);
                    } catch (InterruptedException ie) {
                        //nah, catch it elsewhere
                        Thread.currentThread().interrupt();
                    };
                    break;
                }
                acceptOne = true;
            } else {
       	        abortIcall("Unexpected " + evt );
       	    }
        }
       	voiceDev.r2_fdisable();
        ringsSent = 0;
       	linestate = RINGS;
       	voiceDev.playtone(ringLead, stdTPT);
        ringPhase = true;
        ringerEvt = null;
		Runnable r = new Runnable() {
		     public void run() {
		     		try { 
						ringerEvt = serviceWaitEvent();
		     		} catch (ChannelException ce) {}
					ringer = null;
					if ((Dialogic.debug & Dialogic.DEBUG_CHANNEL) != 0)
						System.out.println(R2CASChannel.this.toString() + ": ringer off");
			}
		};
        ringer = new Thread(r, this.toString() + " ringer");
        ringer.start();
        } finally {
            endService();
        }
    }

    void answer(int rings) {
        if (linestate == ICALL)
            accept();
        if (linestate != RINGS)
            throw new ChannelException("answer(): wrong state");
        
        // Ring cycle
        long now = System.currentTimeMillis();
        long conn = call.startTime() + rings * 3000; // 3 secs each
        if (conn > now && ringer != null)
        	try { 
                ringer.join(conn - now);
        	} catch (InterruptedException ie) {}
		if (linestate != RINGS) {
			linestate = RESET;
			setState(OOS);
			throw new ChannelException("answer(): " + ringerEvt);
		}
		linestate = IN;
		if (ringer != null) {
			Thread r = ringer; // Ringer clears its reference!
			r.interrupt();
			try { 
				r.join();
			} catch (InterruptedException ie) {}
		} 
        voiceDev.stop();
        dtiDev.setsig(xa = false, xb = true);
    }

    void reject(int reason) {
        if (linestate != ICALL)
            throw new ChannelException("reject(): wrong state");

        try {
        	linestate = IN; // Actually rejecting, but different from ICALL.
	        setState(OOS);
	        int bsig = Voice.SIGA_4;
	        EVT evt;
	
	        switch(reason) {
	        case BUSY:
	            bsig = Voice.SIGB_3;
	            break;
	        case BADNUMBER:
	            bsig = Voice.SIGB_5;
	            break;
	        case NOTINSERVICE:
	            bsig = Voice.SIGB_8;
	            break;
	        case CONGESTION:
	        default:
	            bsig = Voice.SIGA_4;
	        }
	        
	        if (bsig != Voice.SIGA_4) {
	            // Switch to B
	            voiceDev.r2_sendb(Voice.SIGA_3, r2tone);
	            while (true) {
	                evt = serviceWaitEvent(R2InterDigit);
	                if (evt == null) {
	                    // Timeout in incomming dial
	       	            abortRings("Reject interDigit timeout");
	       	            clear();
	       	            return;
	       	        }
	   	            if (evt.type == EVT.TDX_CST 
	   	                && evt.cstevt == EVT.DE_TONEON) {
	   	                r2tone = evt.cstdata; // category
	   	                break;
	                } else if (evt.type == EVT.TDX_CST &&
	   	                        evt.cstevt == EVT.DE_TONEOFF) {
	   	                // Ignore, forward off
	                } else if (evt.type == EVT.TDX_PLAYTONE) {
	   	                // Ignore, backward completed
	                } else {
	       	            abortRings("Reject unexpected " + evt);
	       	            clear();
	       	            return;
	   	            }
	   	        }
	        } 
	        voiceDev.r2_sendb(bsig, r2tone);
	        
	        do {
	            evt = serviceWaitEvent();
	        } while (!ra && evt.type != EVT.TDX_PLAYTONE);
        	clear();
        } finally {
            endService();
        }
    }

    void dial(Call call, String number) {
        if (linestate != IDLE)
            throw new ChannelException("dial(): wrong state");
        try {
        linestate = OFFH;
        if (serviceThread != null) {
            Channel.stopGroup(this);
            serviceThread.interrupt();
            /* Service thread will normally die, 
             * but simultaneous seizure may prevent that from happening... */
            try {
                serviceThread.join(500);
            }
            catch(InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
            // Give up if it did not quit...
            if (serviceThread.isAlive()) {
                System.err.println("Seizure failure: service not quitting");
                throw new ChannelException("dial(): seizure failure");
            }
            serviceThread = null;
        }
        this.call = call;
        setState(OUTGOING);
        EVT evt = null;
        // Here we go...
        dtiDev.setsig(xa = false, xb = false); // line seizure
        evt = serviceWaitEvent(R2OHDelay);

       	// event should be BON, and state DIAL
       	if (linestate != DIAL) {
       	    if (evt != null && evt.type == EVT.DTEV_SIG && !ra) {
       	        // Simultaneous seizure...
       	        System.err.println("Simultaneous seizure");
       	        setState(OOS);
                try {
                    Thread.sleep(R2SimSeizureDelay);
                } catch (InterruptedException ie) {
                    //nah, catch it elsewhere
                    Thread.currentThread().interrupt();
                };
       	    } else if (evt != null) {
       	        System.err.println("Seizure failure: " + evt);
       	        setState(OOS);
       	    } else {
       	        System.err.println("Seizure failure: timeout");
       	        setState(OOS);
       	    }
      	    throw new ChannelException("dial(): seizure failure");
       	}
       	// Dial...
        voiceDev.r2_benable();
       	int dnisp = 0;
       	int r2tone = 0;
       	boolean phaseB = false;
       	int anip = 0;

       	sendDigit(number, 0, false);
       	sendDnis:
       	while (true) {
       	    evt = serviceWaitEvent(R2InterDigit);
       	    if (evt == null) {
       	        // Timeout 
           	    throw new ChannelException("dial(): dial timeout");
           	}
       	    if (evt.type == EVT.TDX_CST 
       	        && evt.cstevt == EVT.DE_TONEOFF) {
       	        r2tone = evt.cstdata;
       	        
       	        // Reset ANI pointer
                if (r2tone != Voice.SIGA_5)
                    anip = 0;
                if (!phaseB) {
                    switch(r2tone) {
                    case Voice.SIGA_1: // next
       	                dnisp++;
       	                break;
                    case Voice.SIGA_2: // previous
       	                dnisp--;
       	                if (dnisp < 0) dnisp = 0;
       	                break;
                    case Voice.SIGA_7: // prev^2
       	                dnisp-= 2;
       	                if (dnisp < 0) dnisp = 0;
       	                break;
                    case Voice.SIGA_8: // prev^3
       	                dnisp-= 3;
       	                if (dnisp < 0) dnisp = 0;
       	                break;
                    case Voice.SIGA_9: // last (again)
       	                break;
                    case Voice.SIGA_10: // start over
       	                dnisp = 0;
       	                break;
                           	            
                    case Voice.SIGA_3: // Categ/go B
                        voiceDev.r2_sendf(Voice.SIGII_1); // Abo std
                        phaseB = true;
                        continue sendDnis;
                    case Voice.SIGA_4: // Congestion
       	                throw new BusyException("dial(): Congestion");
                    case Voice.SIGA_5: // Categ/ANI
                        if (anip == 0) 
                            voiceDev.r2_sendf(Voice.SIGII_1); // Abo std
                        else
                            voiceDev.r2_sendf(Voice.SIGII_12); // no ANI
                        anip++;
       	                continue sendDnis;
                    case Voice.SIGA_6: // Accept
                        linestate = DIALOK;
       	                break sendDnis;
       	            default:
           	            // Unexpected backward signal
               	        throw new ChannelException("dial(): Unexpected backward" + evt);
                    } // backward tone off case
                    sendDigit(number, dnisp, false);
                } else {
                    // phase B
                    switch(r2tone) {
                    case Voice.SIGA_3: // Congestion
       	                throw new BusyException("dial(): Busy");
                    case Voice.SIGA_4: // Congestion
       	                throw new BusyException("dial(): B Congestion");
                    case Voice.SIGA_5: // Categ/ANI
                        if (anip == 0) 
                            voiceDev.r2_sendf(Voice.SIGII_1); // Abo std
                        else
                            voiceDev.r2_sendf(Voice.SIGII_12); // no ANI
                        anip++;
       	                continue sendDnis;
                    case Voice.SIGA_6: // Accept
                        linestate = DIALOK;
       	                break sendDnis;
                    case Voice.SIGA_7: // Free Accept
                        linestate = DIALOK;
                        pulses = -1; // will compensate with pulses++ at connect
       	                break sendDnis;
       	            default:
           	            // Unexpected backward signal
               	        throw new ChannelException("dial(): Unexpected backward B " + evt);
                    }
                }
       	    } else if (evt.type == EVT.TDX_CST &&
       	                evt.cstevt == EVT.DE_TONEON) {
       	        // Ignore, backward on
            } else if (evt.type == EVT.TDX_PLAYTONE) {
       	        // Ignore, forward completed
            } else {
                throw new ChannelException("dial(): Unexpected " + evt);
       	    }
       	} // SendDnis
       	// We are in DIALOK state, let user wait for connect (OUT state)
        voiceDev.r2_bdisable();
        while (serviceWaitEvent(R2ConnDelayOut) != null) {}
        } finally {
            endService();
        }
    }
    
    private void sendDigit(String number, int index, boolean sendI15) {
       	if (index >= number.length()) {
       	    // XXX protocol dependent ? 
       	    if (sendI15)
       	        voiceDev.r2_sendf(Voice.SIGI_15);
       	    // Stay silent and wait for pulsed answer...        
       	} else {
       	    switch(number.charAt(index)) {
       	    case '0':
       	        voiceDev.r2_sendf(Voice.SIGI_10);
       	        break;
       	    case '1':
       	        voiceDev.r2_sendf(Voice.SIGI_1);
       	        break;
       	    case '2':
       	        voiceDev.r2_sendf(Voice.SIGI_2);
       	        break;
       	    case '3':
       	        voiceDev.r2_sendf(Voice.SIGI_3);
       	        break;
       	    case '4':
       	        voiceDev.r2_sendf(Voice.SIGI_4);
       	        break;
       	    case '5':
       	        voiceDev.r2_sendf(Voice.SIGI_5);
       	        break;
       	    case '6':
       	        voiceDev.r2_sendf(Voice.SIGI_6);
       	        break;
       	    case '7':
       	        voiceDev.r2_sendf(Voice.SIGI_7);
       	        break;
       	    case '8':
       	        voiceDev.r2_sendf(Voice.SIGI_8);
       	        break;
       	    case '9':
       	        voiceDev.r2_sendf(Voice.SIGI_9);
       	        break;
       	    default:
       	        throw new ChannelException("dial(): invalid number (" 
       	            + number + ")");
       	    }
       	}
    }

    String ani() {

⌨️ 快捷键说明

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