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

📄 simplevm.java

📁 著名的dialogic电话语音卡的java驱动程序,已经验证可用。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// simpleVM: a simple EWD app for a voice mail

/*
 * Copyright (c) 1999 Carlos G Mendioroz.
 *
 *  This file is part of D4J.
 *
 *  D4J is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  D4J is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA  02111-1307, USA.
 *
 * Report problems and direct all questions to:
 *
 *  tron@acm.org
 */

import local.dialogic.*;
import java.util.*;
import java.io.*;

public class simpleVM implements Application {
    Call call;
    Properties props;
    Voice vdev;
    String home, folder;
    long code = 99999;
    TPT tptDigit, tptRectime, tptNone;

    public void handleCall(Call call, Properties props)
    {

        this.call = call;
        this.props = props;
        vdev = call.channel().getVoice();
        EVT evt;

        call.accept(4);

    /* Read config from props */
        try {
            home = (String)props.getProperty("HOME");
        } catch (Exception e) {}
        if (home == null)
            home = ".";
        home += File.separator;
        try {
            folder = (String)props.getProperty("FOLDER");
        } catch (Exception e) {}
        if (folder == null)
            folder = ".";
        folder = home + folder + File.separator;
        try {
            code = Long.parseLong((String)props.getProperty("CODE"));
        } catch (Exception e) {}

    /* Set up some TPTs */

        // Record message TPT: max 30s, or 2 secs silence, 4 seconds at start
        tptRectime = new TPT(TPT.MAXSIL, 20, TPT.EDGE|TPT.USE|TPT.SETINIT, 40);
        tptRectime.add(TPT.MAXTIME, 300, 0, 0);

        // See if code is tried while playing prompt
        tptDigit = new TPT(TPT.DIGMASK, 0xffff, TPT.LEVEL, 0);

        // while playing messages, terminate only by EOF
        tptNone = new TPT();

    /* Do the work */

        // See if we have Caller-ID and if so display it
        if (call.channel() instanceof AnalogChannel) {
            AnalogChannel ac = (AnalogChannel) call.channel();
            if (ac.getCallerIdEnabled()) {
                try {
                    System.out.print("Caller-ID ");
                    System.out.println("is <" + call.ani() + ">");

                    int frameType = ac.callerIdFrameType();
                    switch (frameType) {
                        // Enable the appropriate section of code below depending on the line technology
                        //* Caller-ID handling
                        case Dialogic.CLASSFRAME_MDM:
                            System.out.println("Frame type is CLASS MDM");
                            System.out.print("time ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MCLASS_DATETIME) + ">");
                            System.out.print(" DN ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MCLASS_DN) + ">");
                            System.out.print(" DDN ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MCLASS_DDN) + ">");
                            System.out.print(" name ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MCLASS_NAME) + ">");
                            System.out.print(" rdir ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MCLASS_REDIRECT) + ">");
                            System.out.print(" qual ");
                            System.out.println("<" + ac.callerIdExtended(Dialogic.MCLASS_QUALIFIER) + ">");
                            break;

                        case Dialogic.CLASSFRAME_SDM:
                            System.out.println("Frame type is CLASS SDM");
                            System.out.println("Submessages not available");
                            break;
                        //*/

                        /* CLIP handling
                        case Dialogic.CLIPFRAME_MDM:
                            System.out.println("Frame type is CLIP MDM");
                            System.out.print("time ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.CLIP_DATETIME) + ">");
                            System.out.print(" DN ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.CLIP_DN) + ">");
                            System.out.print(" DDN ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.CLIP_DDN) + ">");
                            System.out.print(" name ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.CLIP_NAME) + ">");
                            System.out.print(" type ");
                            System.out.println("<" + ac.callerIdExtended(Dialogic.CLIP_CALLTYPE) + ">");
                            break;
                        //*/

                        /* ACLIP Handling
                        case Dialogic.ACLIPFRAME_MDM:
                            System.out.println("Frame type is ACLIP MDM");
                            System.out.print("time ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MACLIP_DATETIME) + ">");
                            System.out.print(" DN ");
                            System.out.print("is <" + ac.callerIdExtended(Dialogic.MACLIP_DN) + ">");
                            System.out.print(" DDN ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MACLIP_DDN) + ">");
                            System.out.print(" name ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.MACLIP_NAME) + ">");
                            System.out.print("rdir ");
                            System.out.println("<" + ac.callerIdExtended(Dialogic.MACLIP_REDIRECT) + ">");
                            break;

                        case Dialogic.ACLIPFRAME_SDM:
                            System.out.println("Frame type is ACLIP SDM");
                            System.out.println("Submessages not available");
                            break;
                        //*/

                        /* JCLIP Handling
                        case Dialogic.JCLIPFRAME_MDM:
                            System.out.println("Frame type is JCLIP MDM");
                            System.out.print("time ");
                            System.out.print("<" + ac.callerIdExtended(Dialogic.JCLIP_DN) + ">");
                            System.out.print("DDN ");
                            System.out.println("<" + ac.callerIdExtended(Dialogic.JCLIP_DDN) + ">");
                            break;
                        //*/

                    }
                    System.out.println("End of Caller-ID information.");
                } catch (RuntimeException e) {
                    System.out.println();
                    System.out.println(e);
                }
            }
        }

        // Play prompt
        play(folder+"prompt.vox", tptDigit);
        if ((call.channel().lastEvent().termmsk & EVT.TM_DIGIT) != 0) {
            // dtmf, i.e. code try
            if (authenticate())
                tellmessages();
            return;
        }

        // Record message. Name derived from time!
        File message = null;
        try {
            message = newFile(folder);
            vdev.record(new IOTT(message.getPath(), true),
                    tptRectime, Dialogic.SR_8|Dialogic.RM_TONE);
        } catch (IOException ioe) {
            System.out.println("Message error: "+ioe + " (" + message.getPath() + ")");
            //if (message != null && message.exists())
            //    message.delete();
            return;
        }
        try {
            vdev.waitIdle();
        } catch (ChannelException ce) {
            // Ok to hangup after leaving message
        };
        // Erase if too short, usually some that calls and hangs up on beep.
        if (message.length() < 4000)
            message.delete();
    }

    /**
     * authenticate() : check credentials.
     */
    private boolean authenticate() {
        int tries = 0;
        while (tries++ < 3) {
            long code = getNumber(vdev, 4, 4, false);

⌨️ 快捷键说明

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