RingDetect() private method

private RingDetect ( ushort wChnlNo ) : bool
wChnlNo ushort
return bool
示例#1
0
        //主工作方法
        public void yzDoWork(LineInfo line)
        {
            int tmpCode;
            //通道对应的连接通道号
            int tmpCTL = line.ConnectToLine;

            //根据类型处理
            switch (line.Type)
            {
            //内线
            case (int)type.CHTYPE_USER:
                //未摘机 ,不是空闲,不是响铃
                if (!line.IsKey && !InvokeVcDll.OffHookDetect(line.Number) && line.State != (int)state.CH_FREE && line.State != (int)state.CH_RINGING)
                {
                    switch (line.State)
                    {
                    case (int)state.CH_WAITONHOOK:
                        log.Debug("内线" + line.Number + "waitonhook时挂机");
                        InvokeVcDll.StopRecordFile((ushort)line.Number);
                        ResetLine(line.Number);
                        break;

                    case (int)state.CH_CHECKSIG:
                        log.Debug("内线" + line.Number + "checksig等待连接时挂机");
                        InvokeVcDll.FeedPower((ushort)tmpCTL);
                        ResetLine(line.ConnectToLine);
                        ResetLine(line.Number);
                        break;

                    case (int)state.CH_CONNECTED:
                        log.Debug("内线" + line.Number + "连接时挂断");
                        InvokeVcDll.StopRecordFile((ushort)line.Number);
                        int duan = InvokeVcDll.ClearLink(line.Number, (ushort)tmpCTL);
                        log.Debug("断开连接返回值:" + duan);
                        ResetLineInner(line.Number);
                        ResetLine(tmpCTL);
                        break;

                    default:
                        break;
                    }
                }
                break;

            case (int)type.CHTYPE_TRUNK:
                if (InvokeVcDll.Sig_CheckBusy(line.Number) == 1)
                {
                    switch (line.State)
                    {
                    case (int)state.CH_DIALING:
                        log.Debug("外线" + line.Number + "dialing响铃时时挂断");
                        ResetLine(line.Number);
                        break;

                    case (int)state.CH_CHECKSIG:
                        log.Debug("外线" + line.Number + "checksig等待连接时挂断");
                        this.stopWelcome(line.Number);
                        InvokeVcDll.FeedPower((ushort)line.ConnectToLine);
                        ResetLine(line.ConnectToLine);
                        ResetLine(line.Number);
                        break;

                    case (int)state.CH_CONNECTED:
                        log.Debug("外线" + line.Number + "连接时挂断");
                        InvokeVcDll.StopRecordFile((ushort)line.ConnectToLine);
                        int duan = InvokeVcDll.ClearLink((ushort)tmpCTL, line.Number);
                        log.Debug("通话时挂断返回值:" + duan);
                        int inerline = line.ConnectToLine;
                        ResetLine(line.Number);
                        this.ResetLineInner(inerline);
                        break;

                    case (int)state.CH_GETCAllNUM:
                        int nx = line.ConnectToLine;
                        ResetLine(line.Number);
                        if (nx != -1)
                        {
                            ResetLine(nx);
                        }
                        break;

                    //播放欢迎语音
                    case (int)state.CH_PlAYWELCOME:
                        int nx1 = line.ConnectToLine;
                        ResetLine(line.Number);
                        if (nx1 != -1)
                        {
                            ResetLine(nx1);
                        }
                        break;

                    //播放工号
                    case (int)state.CH_PLAYGONGHAO:
                        int nx2 = line.ConnectToLine;
                        ResetLine(line.Number);
                        if (nx2 != -1)
                        {
                            ResetLine(nx2);
                        }
                        break;

                    //外拨
                    case (int)state.CH_CALLPHONE:
                        log.Debug("内线" + line.ConnectToLine + "外拨" + line.Number + "时,外线拨号时挂断");
                        InvokeVcDll.FeedPower((ushort)line.ConnectToLine);
                        ResetLine(line.Number);
                        break;

                    default:
                        break;
                    }
                }
                break;

            default:
                break;
            }
            //根据状态处理(实际电话处理)
            switch (line.State)
            {
            //空闲状态
            case (int)state.CH_FREE:
                //监听响铃
                if (InvokeVcDll.RingDetect(line.Number))
                {
                    //如果是内线,播放忙音,状态改为摘机
                    if (line.Type == (int)type.CHTYPE_USER)
                    {
                        if (line.State == (int)state.CH_FREE)
                        {
                            log.Debug("内线" + line.Number + "摘机");
                            InvokeVcDll.InitDtmfBuf(line.Number);
                            line.State = (int)state.CH_DETECT;
                        }
                        ;
                    }
                    //如果是外线
                    else if (line.Type == (int)type.CHTYPE_TRUNK)
                    {
                        log.Debug("外线" + line.Number + "电话打入");
                        InvokeVcDll.StartSigCheck(line.Number);
                        InvokeVcDll.ResetCallerIDBuffer(line.Number);
                        line.State = (int)state.CH_GETCAllNUM;
                        //设置来电时间
                        line.Comingtime = System.DateTime.Now;
                        //id在comingcall方法内部产生
                        LineRecordHelper.ComingCall(line, null);
                    }
                }
                break;

            case (int)state.CH_GETCAllNUM:
                bool bOffHook = false;
                if (line.Callertime > 1000)
                {
                    bOffHook = true;
                }
                if (bOffHook)
                {
                    string zhujiao = getCaller(line);
                    line.State = (int)state.CH_PlAYWELCOME;
                    LineRecordHelper.ComingCall(line, null);
                }
                else
                {
                    line.Callertime += 70;
                }
                break;

            //播放欢迎语音
            case (int)state.CH_PlAYWELCOME:
                InvokeVcDll.OffHook(line.Number);
                this.playWelcome(line.Number);
                line.State = (int)state.CH_DIALING;
                break;

            //查找内线连接
            case (int)state.CH_DIALING:
                tmpCTL = this.GetFreeUser(line);
                if (tmpCTL == -1)
                {
                    //欢迎语音结束,播放坐席忙录音
                    if (InvokeVcDll.CheckPlayEnd(line.Number))
                    {
                        log.Debug("欢迎语音播放完成,播放忙音");
                        this.stopWelcome(line.Number);
                        string weladd = Environment.CurrentDirectory + "\\busy1";
                        InvokeVcDll.StartPlayFile(line.Number, weladd, 0);
                        line.State = (int)state.CH_PLAYBUSY;
                    }
                    break;
                }
                Lines[tmpCTL].CallerPhone = line.CallerPhone;
                InvokeVcDll.FeedRealRing((ushort)tmpCTL);
                line.ConnectToLine          = tmpCTL;
                Lines[tmpCTL].ConnectToLine = line.Number;
                line.State          = (int)state.CH_CHECKSIG;
                Lines[tmpCTL].State = (int)state.CH_RINGING;
                log.Debug("外线" + line.Number + "打入,连接内线" + tmpCTL);
                LineRecordHelper.ComingCall(line, Lines[tmpCTL]);
                break;

            //坐席全忙
            case (int)state.CH_PLAYBUSY:
                if (InvokeVcDll.CheckPlayEnd(line.Number))
                {
                    log.Debug(line.Number + "忙音播放完,断开");
                    InvokeVcDll.StopPlayFile(line.Number);
                    this.ResetLine(line.Number);
                }
                break;

            //等待连接状态
            case (int)state.CH_CHECKSIG:
                tmpCTL = line.ConnectToLine;
                //检测内线摘机
                if (InvokeVcDll.OffHookDetect((ushort)tmpCTL) || Lines[tmpCTL].IsKey)
                {
                    log.Debug("内线" + tmpCTL + "摘机,与外线" + line.Number + "连通");
                    this.stopWelcome(line.Number);
                    //播放工号
                    log.Debug("播放工号");
                    string weladd = Environment.CurrentDirectory + "\\" + Lines[tmpCTL].Gonghao;
                    InvokeVcDll.StartPlayFile(line.Number, weladd, 0);
                    line.State = (int)state.CH_PLAYGONGHAO;
                    break;
                }
                else
                {
                    LineRecordHelper.ComingCall(line, Lines[tmpCTL]);
                }
                break;

            case (int)state.CH_PLAYGONGHAO:
                tmpCTL = line.ConnectToLine;
                //检测内线摘机
                if (InvokeVcDll.OffHookDetect((ushort)tmpCTL) || Lines[tmpCTL].IsKey)
                {
                    log.Debug("内线" + tmpCTL + "摘机,与外线" + line.Number + "连通");
                    if (InvokeVcDll.CheckPlayEnd(line.Number))
                    {
                        InvokeVcDll.StopPlayFile(line.Number);
                    }
                    else
                    {
                        break;
                    }
                    InvokeVcDll.FeedPower((ushort)tmpCTL);
                    InvokeVcDll.SetLink(line.Number, (ushort)tmpCTL);
                    line.State          = (int)state.CH_CONNECTED;
                    Lines[tmpCTL].State = (int)state.CH_CONNECTED;
                    //录音
                    string guid = Guid.NewGuid().ToString();
                    string file = GetSavePath() + guid + ".wav";
                    InvokeVcDll.StartRecordFile((ushort)tmpCTL, file, 1024 * 8 * 60 * 30);
                    Lines[tmpCTL].RecordFile = guid;
                    //设置接通时间
                    line.Rectime = System.DateTime.Now;
                    line.Islink  = "yes";

                    LineRecordHelper.ComingCall(line, Lines[tmpCTL]);
                }
                else
                {
                    //  LineRecordHelper.ComingCall(line, Lines[tmpCTL]);
                }
                break;

            case (int)state.CH_RINGING:
                break;

            case (int)state.CH_CONNECTED:
                if (InvokeVcDll.CheckSendEnd(line.Number))
                {
                    InvokeVcDll.StartSigCheck(line.Number);
                }
                break;

            case (int)state.CH_WAITONHOOK:
                if (line.Type == (int)type.CHTYPE_TRUNK)
                {
                    log.Debug("外线" + line.Number + "等待挂机");
                    ResetLine(line.Number);
                }
                break;

            //摘机状态
            case (int)state.CH_DETECT:
                //如果是内线,检测是否挂机
                if (line.Type == (int)type.CHTYPE_USER)
                {
                    short code = InvokeVcDll.GetDtmfCode(line.Number);
                    if (code != -1)
                    {
                        log.Debug("内线" + line.Number + "按键" + code);
                        if (line.ListenNum != -1)
                        {
                            InvokeVcDll.ClearOneFromAnother((ushort)line.Number, (ushort)line.ListenNum);
                        }
                        line.ListenNum = ConvertDtmf(code);
                    }
                    InvokeVcDll.StartHangUpDetect(line.Number);
                    if (InvokeVcDll.HangUpDetect(line.Number) == 2)
                    {
                        InvokeVcDll.ClearOneFromAnother((ushort)line.Number, (ushort)line.ListenNum);
                        log.Debug("内线" + line.Number + "挂机111");
                        int num = line.ConnectToLine;
                        ResetLine(line.Number);
                        if (num != -1)
                        {
                            ResetLine(num);
                        }
                    }
                }
                break;

            //外拨
            case (int)state.CH_CALLPHONE:
                //拨号完成后,建立通道
                if (InvokeVcDll.CheckSendEnd((ushort)line.Number))
                {
                    InvokeVcDll.StartSigCheck((ushort)line.Number);
                    InvokeVcDll.StartSigCheck((ushort)line.ConnectToLine);
                    InvokeVcDll.SetLink((ushort)line.Number, (ushort)line.ConnectToLine);
                    //设置为接通
                    line.State = (int)state.CH_CONNECTED;
                    Lines[line.ConnectToLine].State = (int)state.CH_CONNECTED;
                }
                break;

            default:
                break;
            }
        }