Esempio n. 1
0
        private void DataProcess(byte[] receivedData)
        {
            //思路:数据的接收与发送主体是控制器,应将收到的数据放在控制器类中进行处理
            //1.初始化未知控制器处理类
            //2.将协议集成进控制器处理类中,用控制器处理类中的协议解析收到的数据
            m_BufferManager.Add(receivedData);
            byte[]         package = m_BufferManager.Pop();
            ProtocolDriver driver  = new ProtocolDriver();

            log.Info("Poped" + driver.ByteToHex(package));

            if (package == null)
            {
                package = m_BufferManager.PopUploadedMessage();
            }

            if (package == null)
            {
                return;
            }

            ProcessCommand procCMD = new ProcessCommand();

            byte[] charCmd = new byte[] { m_protocolDriver.GetCommand(package) };

            SetControllerType();

            ICommand cmd = null;

            switch (m_protocolDriver.ByteToHex(charCmd).Trim())
            {
            case "CA":    //巡检命令
                cmd = new CommandCA(TheControllerType);
                break;

            case "66":    //确认命令
                cmd = new Command66(TheControllerType);
                break;

            case "C8":    //获取控制器类型
                TheControllerType.CurrentPackage = package;
                cmd = new CommandC8(TheControllerType);
                SetControllerType();
                break;

            case "C9":    //准备上传数据
                TheControllerType.CurrentPackage = package;
                cmd = new CommandC9(TheControllerType);
                break;

            case "CC":    //上传器件信息
                if (TheControllerType.ControllerType != ControllerType.NONE)
                {
                    TheControllerType.CurrentPackage = package;
                    TheControllerType.ReceiveDeviceInfo();
                    cmd = new CommandCC(TheControllerType);
                }
                break;

            case "CD":    //标准组态信息上传
                if (TheControllerType.ControllerType != ControllerType.NONE)
                {
                    TheControllerType.CurrentPackage = package;
                    TheControllerType.ReceiveStandardLinkageInfo();
                    cmd = new CommandCD(TheControllerType);
                }
                break;

            case "BD":    //上传混合组态
                if (TheControllerType.ControllerType != ControllerType.NONE)
                {
                    TheControllerType.CurrentPackage = package;
                    TheControllerType.ReceiveMixedLinkageInfo();
                    cmd = new CommandBD(TheControllerType);
                }
                break;

            case "BE":    //上传通用组态
                TheControllerType.CurrentPackage = package;
                TheControllerType.ReceiveGeneralLinkageInfo();
                cmd = new CommandBE(TheControllerType);
                break;

            case "BF":    //上传网络手动盘信息
                if (TheControllerType.ControllerType != ControllerType.NONE)
                {
                    TheControllerType.CurrentPackage = package;
                    TheControllerType.ReceiveManualControlBoardInfo();
                    cmd = new CommandBF(TheControllerType);
                }
                break;

            case "CF":    //所有信息上传结束
                if (TheControllerType.ControllerType != ControllerType.NONE)
                {
                    TheControllerType.CurrentPackage = package;
                    cmd = new CommandCF(TheControllerType);
                    //需要增加各控制器类型的判断
                    ControllerType enumCurrentControllerType = ControllerType.NONE;
                    if (TheControllerType != null)
                    {
                        enumCurrentControllerType = TheControllerType.ControllerType;
                    }
                    switch (enumCurrentControllerType)
                    {
                    case ControllerType.NT8001:         //未测试
                    {
                        ((ControllerType8001)TheControllerType).GetControllerUploadedInfo();
                        if (AllDataUploadedEvent != null)
                        {
                            AllDataUploadedEvent(TheControllerType.ControllerModel);
                        }
                    }
                    break;

                    case ControllerType.NT8036:        //未测试
                    {
                        ((ControllerType8036)TheControllerType).GetControllerUploadedInfo();
                        if (AllDataUploadedEvent != null)
                        {
                            AllDataUploadedEvent(TheControllerType.ControllerModel);
                        }
                    }
                    break;

                    case ControllerType.NT8007:
                    {
                        ((ControllerType8007)TheControllerType).GetControllerUploadedInfo();
                        if (AllDataUploadedEvent != null)
                        {
                            AllDataUploadedEvent(TheControllerType.ControllerModel);
                            ((ControllerType8007)TheControllerType).UploadedDeviceInfoAccumulatedAmountInCurrentLoop = 0;
                            ((ControllerType8007)TheControllerType).UploadedDeviceInfoTotalAmountInCurrentLoop       = 0;
                            ((ControllerType8007)TheControllerType).UploadedStandardLinkageConfigAccumulatedAmount   = 0;
                            ((ControllerType8007)TheControllerType).UploadedStandardLinkageConfigTotalAmount         = 0;
                        }
                    }
                    break;

                    case ControllerType.FT8003:
                    {
                        ((ControllerType8003)TheControllerType).GetControllerUploadedInfo();
                        if (AllDataUploadedEvent != null)
                        {
                            AllDataUploadedEvent(TheControllerType.ControllerModel);
                            ((ControllerType8003)TheControllerType).UploadedDeviceInfoAccumulatedAmountInCurrentLoop = 0;
                            ((ControllerType8003)TheControllerType).UploadedDeviceInfoTotalAmountInCurrentLoop       = 0;
                            ((ControllerType8003)TheControllerType).UploadedStandardLinkageConfigAccumulatedAmount   = 0;
                            ((ControllerType8003)TheControllerType).UploadedStandardLinkageConfigTotalAmount         = 0;
                        }
                    }
                    break;

                    case ControllerType.FT8000:
                    {
                        ((ControllerType8000)TheControllerType).GetControllerUploadedInfo();
                        if (AllDataUploadedEvent != null)
                        {
                            AllDataUploadedEvent(TheControllerType.ControllerModel);
                        }
                    }
                    break;

                    case ControllerType.NT8021:         //未测试
                    {
                        ((ControllerType8021)TheControllerType).GetControllerUploadedInfo();
                        if (AllDataUploadedEvent != null)
                        {
                            AllDataUploadedEvent(TheControllerType.ControllerModel);
                        }
                    }
                    break;

                    case ControllerType.NT8053:
                    {
                        ((ControllerType8053)TheControllerType).GetControllerUploadedInfo();
                        if (AllDataUploadedEvent != null)
                        {
                            AllDataUploadedEvent(TheControllerType.ControllerModel);
                        }
                    }
                    break;
                    }
                    //((ControllerType8007)TheControllerType).GetControllerUploadedInfo();
                    //if (AllDataUploadedEvent != null)
                    //{
                    //    AllDataUploadedEvent(TheControllerType.ControllerModel);
                    //}
                }
                break;

            default:
                cmd = null;
                break;
            }
            if (cmd != null)
            {
                procCMD.Run(cmd);
            }
        }