예제 #1
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            AccessToMacProperties config = properties as AccessToMacProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            //string moudleBtMac = configGv.Get("MAC_BT");
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!response.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                        }
                    }
                }
            }
            if (!response.Contains("BLE MAC:"))
            {
                throw new BaseException("不包含BLE MAC:信息");
            }


            if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            {
                string pattern    = Parse_r_n(config.GlobalVariblesKeyPattern);
                Match  matchValue = Regex.Match(response, pattern);
                if (!matchValue.Success)
                {
                    //ble mac为空
                    //log.Info("BLE未写过MAC");
                    throw new BaseException("BLE未写过MAC,请在前面工序写BLE MAC");
                }
                else
                {
                    string value = matchValue.Groups[1].ToString();
                    if (value == "000000000000")
                    {
                        log.Info(string.Format("BLE未写过MAC:{0}", value));
                        throw new BaseException("BLE未写过MAC,请在前面工序写BLE MAC");
                        //configGv.Add(GlobalVaribles.MAC_BT, value);
                    }
                    else
                    {
                        log.Info(string.Format("BLE已写过MAC:{0}", value));
                        //预检查{MoudleBtMac}

                        Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);//this.pattern
                        if (!matchKey.Success)
                        {
                            throw new BaseException("read info key fail");
                        }

                        string key = matchKey.Groups[1].ToString();
                        //预检查
                        MesProcess.PreCheck(value);

                        //赋值BT MAC,WIFI MAC,取消取号
                        configGv.Add(key, value);
                        //configGv.Add(GlobalVaribles.MAC_BT, value);
                        UInt64 macUInt64 = Convert.ToUInt64(value, 16);
                        string macWifi   = string.Format("{0:X}", macUInt64 - 1).PadLeft(12, '0');
                        configGv.Add(GlobalVaribles.MAC, macWifi);

                        log.Info(string.Format("自动计算WIFI MAC号:{0}", macWifi));
                    }
                }
            }
        }
예제 #2
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            IsitWrittenToTheBtMacProperties config = properties as IsitWrittenToTheBtMacProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            //string moudleBtMac = configGv.Get("MAC_BT");
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!response.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                        }
                    }
                }
            }
            if (!response.Contains("BLE MAC:"))
            {
                if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                {
                    throw new BaseException("不包含BLE MAC:信息,未能获取到BLE MAC");
                }
                else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                {
                    log.Info("不包含BLE MAC:信息,未能获取到BLE MAC");
                    return;
                }
            }


            if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            {
                string pattern    = Parse_r_n(config.GlobalVariblesKeyPattern);
                Match  matchValue = Regex.Match(response, pattern);
                if (!matchValue.Success)
                {
                    if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                    {
                        throw new BaseException("回复信息不匹配正则表达式,BLE未写过MAC");
                    }
                    else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                    {
                        log.Info("回复信息不匹配正则表达式,BLE未写过MAC");
                    }
                }
                else
                {
                    string value = matchValue.Groups[1].ToString();
                    if (value == "000000000000")
                    {
                        if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                        {
                            throw new BaseException(string.Format("BLE未写过MAC:{0}", value));
                        }
                        else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                        {
                            log.Info(string.Format("BLE未写过MAC:{0}", value));
                        }
                    }
                    else
                    {
                        log.Info(string.Format("BLE已写过MAC:{0}", value));
                        //预检查{MoudleBtMac}

                        Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);//this.pattern
                        if (!matchKey.Success)
                        {
                            if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption)
                            {
                                throw new BaseException("read info key fail");
                            }
                            else if (config.ResultType == AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.SKIP)
                            {
                                log.Info("read info key fail");
                            }
                        }

                        string key = matchKey.Groups[1].ToString();
                        //预检查
                        if (config.ImesPreCheck)
                        {
                            MesProcess.PreCheck(value);
                        }
                        //{MoudleBtMac}
                        configGv.Add(key, value);
                        configGv.Add(key, value);
                    }
                }
            }
        }
예제 #3
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            AutoToUserModeProperties config     = properties as AutoToUserModeProperties;
            List <ComDut>            comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }



            //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            List <OpenPhoneProperties> configList      = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>;
            OpenPhoneProperties        configOpenPhone = null;

            foreach (var item in configList)
            {
                if (item.PortName == config.PortName)
                {
                    configOpenPhone = item;
                    break;
                }
            }
            if (configOpenPhone == null)
            {
                throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName));
            }

            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            //if (config.CommandType == AtCommandProperties.EnumCommandType.String)
            string response = configGv.Get("PowerOnLog");
            {
                string atCommand = PreTranslateAtCommand(config.AtCommand);

                //Thread.Sleep(config.AtCommandInterval);
                //string response = comDut.ReadExisting();
                //comDut.DtrEnable = false;
                //comDut.RtsEnable = false;

                log.Info("PowerOnLog=" + response);

                if (!response.Contains("The driver is for MP"))
                {
                    log.Info("无需转换模式");
                    return;
                }
                //包含的话,需要转模式

                log.Info("AT Commond=" + atCommand);

                comDut.DtrEnable = configOpenPhone.Dtr;
                comDut.RtsEnable = configOpenPhone.Rts;
                comDut.Write(atCommand + endLine);

                Thread.Sleep(config.AtCommandInterval);
                response         = comDut.ReadExisting();
                comDut.DtrEnable = false;
                comDut.RtsEnable = false;
                log.Info("AT Response=" + response);


                if (!string.IsNullOrEmpty(config.AtCommandError))
                {
                    if (response.Contains(config.AtCommandError))
                    {
                        throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                    }
                }

                if (!string.IsNullOrEmpty(config.AtCommandOk))
                {
                    if (!response.Contains(config.AtCommandOk))
                    {
                        throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                    }
                }

                if (config.CheckInfo != null)
                {
                    for (int i = 0; i < config.CheckInfo.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                        {
                            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                            if (!response.Contains(checkInfo))
                            {
                                throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                            }
                            log.Info(string.Format("contain check info=[{0}]", checkInfo));
                        }
                    }
                }

                if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
                {
                    if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length)
                    {
                        throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在");
                    }
                    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                    {
                        string pattern    = Parse_r_n(config.GlobalVariblesKeyPattern[i]);
                        Match  matchValue = Regex.Match(response, pattern);
                        if (!matchValue.Success)
                        {
                            throw new BaseException("read info value fail");
                        }

                        string value = matchValue.Groups[1].ToString();

                        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                        if (!matchKey.Success)
                        {
                            throw new BaseException("read info key fail");
                        }

                        string key = matchKey.Groups[1].ToString();

                        configGv.Add(key, value);
                    }
                }
            }
            //else if (config.CommandType == AtCommandProperties.EnumCommandType.Hex)
            //{
            //    byte[] atCommand = strToToHexByte(config.AtCommand);
            //    //string atCommand = PreTranslateAtCommand(config.AtCommand);
            //    log.Info("AT Commond=" + config.AtCommand);

            //    comDut.DtrEnable = configOpenPhone.Dtr;
            //    comDut.RtsEnable = configOpenPhone.Rts;
            //    comDut.Write(atCommand, 0, atCommand.Length);
            //    log.Info("Tx:" + config.AtCommand);

            //    Thread.Sleep(config.AtCommandInterval);
            //    int length = comDut.ReadBufferSize;
            //    byte[] byteArray = new byte[length];
            //    comDut.Read(byteArray, 0, length);

            //    string hexStr = byteToHexStr(byteArray);
            //    log.Info("Rx:" + hexStr);
            //    string response = System.Text.Encoding.ASCII.GetString(byteArray);
            //    response = response.Replace("\0", "~");
            //    //string response = comDut.ReadExisting();
            //    //byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(response);
            //    configGv.Add("RetBytes", byteArray);

            //    comDut.DtrEnable = false;
            //    comDut.RtsEnable = false;

            //    log.Info("Response:\r\n" + response);

            //    if (!string.IsNullOrEmpty(config.AtCommandError))
            //    {
            //        if (response.Contains(config.AtCommandError))
            //        {
            //            throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
            //        }
            //    }

            //    if (!string.IsNullOrEmpty(config.AtCommandOk))
            //    {
            //        if (!response.Contains(config.AtCommandOk))
            //        {
            //            throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
            //        }
            //    }

            //    if (config.CheckInfo != null)
            //    {
            //        for (int i = 0; i < config.CheckInfo.Length; i++)
            //        {
            //            if (!string.IsNullOrEmpty(config.CheckInfo[i]))
            //            {
            //                string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
            //                if (!response.Contains(checkInfo))
            //                {
            //                    throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
            //                }
            //            }
            //        }
            //    }

            //    if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
            //    {
            //        if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length)
            //        {
            //            throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在");
            //        }
            //        for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //        {
            //            string pattern = "-([0-9]{2}) ";
            //            Match matchValue = Regex.Match(response, pattern);
            //            if (!matchValue.Success)
            //            {
            //                throw new BaseException("read info value fail");
            //            }

            //            string value = matchValue.Groups[1].ToString();

            //            Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //            if (!matchKey.Success)
            //            {
            //                throw new BaseException("read info key fail");
            //            }

            //            string key = matchKey.Groups[1].ToString();

            //            configGv.Add(key, value);
            //        }
            //    }
            //}
        }
예제 #4
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            SKGControlCommandProperties config = properties as SKGControlCommandProperties;
            List <ComDut> comDutList           = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }



            //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            List <OpenPhoneProperties> configList      = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>;
            OpenPhoneProperties        configOpenPhone = null;

            foreach (var item in configList)
            {
                if (item.PortName == config.PortName)
                {
                    configOpenPhone = item;
                    break;
                }
            }
            if (configOpenPhone == null)
            {
                throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName));
            }

            log      = globalDic[typeof(ILog).ToString()] as ILog;
            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            comDut.Parity = configOpenPhone.Parity;
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string command = "";

            command += config.Head;

            //int型的处理-转2字节byte,连接到16进制字符串中
            int allLength = 9 + 17; //config.DataLength

            byte[] byteTemp    = new byte[2];
            byte[] oneByteTemp = new byte[1];

            byteTemp = intToBytes(allLength);
            command += byteToHexStr(byteTemp);

            command += config.ReservedWord;
            command += config.CommandWord;

            //DataContent部分
            //枚举类的处理
            int intTemp = (int)config.PowerOnOffSetting;//开关机设置

            if (config.PowerOnOffSetting != 0)
            {
                log.Info(string.Format("开关机设置:{0}", config.PowerOnOffSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.LedModeSetting;
            if (config.LedModeSetting != 0)
            {
                log.Info(string.Format("LED 模式设置:{0}", config.LedModeSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.EmsTestSwitch;
            if (config.EmsTestSwitch != 0)
            {
                log.Info(string.Format("EMS 测试开关设置:{0}", config.EmsTestSwitch));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            //int型的处理
            byteTemp = intToBytes(config.EmsPWSetting);
            if (config.EmsPWSetting != 0)
            {
                log.Info(string.Format("EMS 脉宽设置:{0}uS", config.EmsPWSetting));
            }
            command += byteToHexStr(byteTemp);

            byteTemp = intToBytes(config.EmsFreqSetting);
            if (config.EmsFreqSetting != 0)
            {
                log.Info(string.Format("EMS 频率设置:{0}Hz", config.EmsFreqSetting));
            }
            command += byteToHexStr(byteTemp);

            byteTemp = intToBytes(config.EmsAmplitudeSetting);
            if (config.EmsAmplitudeSetting != 0)
            {
                log.Info(string.Format("EMS 幅度设置:{0}mV", config.EmsAmplitudeSetting));
            }

            command += byteToHexStr(byteTemp);

            //枚举类的处理
            intTemp = (int)config.HeatingGearControl;
            if (config.HeatingGearControl != 0)
            {
                log.Info(string.Format("加热档位控制:{0}", config.HeatingGearControl));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp  = (int)config.VoiceControl;
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.WritePcbaFinishFlag;
            if (config.WritePcbaFinishFlag != 0)
            {
                log.Info(string.Format("PCBA 测试完成标志:{0}", config.WritePcbaFinishFlag));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.WholeMachineFinishFlag;
            if (config.WholeMachineFinishFlag != 0)
            {
                log.Info(string.Format("PCBA 测试完成标志:{0}", config.WholeMachineFinishFlag));
            }

            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.BtTestOnOffSetting;
            if (config.BtTestOnOffSetting != 0)
            {
                log.Info(string.Format("蓝牙模块测试:{0}", config.BtTestOnOffSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.MotorControl;
            if (config.MotorControl != 0)
            {
                log.Info(string.Format("电机控制:{0}", config.MotorControl));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            intTemp = (int)config.AginTestOnOffSetting;
            if (config.AginTestOnOffSetting != 0)
            {
                log.Info(string.Format("老化测试开关:{0}", config.AginTestOnOffSetting));
            }
            command += intTemp.ToString().PadLeft(2, '0');

            //int型的处理-转为1字节byte
            oneByteTemp = intToOneBytes(config.AginTestTime);
            if (config.AginTestTime != 0)
            {
                log.Info(string.Format("老化测试时间:{0}分钟", config.AginTestTime * 10));
            }
            command += byteToHexStr(oneByteTemp);
            #region 多路振动控制
            //高位在前,第16位,为第16个电机
            if (true)
            {
                //int bit1 = (int)config.VibrationControl16;
                //bit1 = bit1 << 7;

                //int bit2 = (int)config.VibrationControl15;
                //bit2 = bit2 << 6;

                //int bit3 = (int)config.VibrationControl14;
                //bit3 = bit3 << 5;

                //int bit4 = (int)config.VibrationControl13;
                //bit4 = bit4 << 4;

                //int bit5 = (int)config.VibrationControl12;
                //bit5 = bit5 << 3;

                //int bit6 = (int)config.VibrationControl11;
                //bit6 = bit6 << 2;

                //int bit7 = (int)config.VibrationControl10;
                //bit7 = bit7 << 1;

                //int bit8 = (int)config.VibrationControl9;

                //int byte2 = bit1 | bit2 | bit3 | bit4 | bit5 | bit6 | bit7 | bit8;
                //command += byte2.ToString("X");//.PadLeft(2, '0')

                //bit1 = (int)config.VibrationControl8;
                //bit1 = bit1 << 7;

                //bit2 = (int)config.VibrationControl7;
                //bit2 = bit2 << 6;

                //bit3 = (int)config.VibrationControl6;
                //bit3 = bit3 << 5;

                //bit4 = (int)config.VibrationControl5;
                //bit4 = bit4 << 4;

                //bit5 = (int)config.VibrationControl4;
                //bit5 = bit5 << 3;

                //bit6 = (int)config.VibrationControl3;
                //bit6 = bit6 << 2;

                //bit7 = (int)config.VibrationControl2;
                //bit7 = bit7 << 1;

                //bit8 = (int)config.VibrationControl1;

                //int byte1 = bit1 | bit2 | bit3 | bit4 | bit5 | bit6 | bit7 | bit8;

                //command += byte1.ToString("X").PadLeft(2, '0');
            }
            #endregion
            #region 640nm 红光控制,G7 新增功能
            if (true)
            {
                //intTemp = (int)config.RedLightControl640nm;
                //command += intTemp.ToString("X").PadLeft(2, '0');//
            }
            #endregion
            //在加校验位
            byte[] exceptXor = strToToHexByte(command);
            byte   xor       = ByteToXOR(exceptXor);
            command += xor.ToString("X").PadLeft(2, '0');

            //发送完整控制命令
            byte[] atCommand = strToToHexByte(command);

            //string atCommand = PreTranslateAtCommand(config.AtCommand);
            UartDisplay(atCommand, "T");

            //log.Info("AT Commond=" + config.AtCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand, 0, atCommand.Length);
            Thread.Sleep(config.AtCommandInterval);

            #region
            //DateTime start = DateTime.Now;
            //DateTime now = DateTime.Now;
            //TimeSpan timeSpan = now - start;
            //while (timeSpan.TotalMilliseconds <= config.Timeout)
            //{
            //    try
            //    {
            //        comDut.Write(atCommand, 0, atCommand.Length);
            //        Thread.Sleep(config.AtCommandInterval);

            //        int n = comDut.BytesToRead;
            //        byte[] buf = new byte[n];
            //        comDut.Read(buf, 0, n);
            //        //解析是否收到正确的包,包头,命令,校验位

            //        //如果收到的包正确
            //        if (true)
            //        {
            //            break;
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e);
            //    }

            //    Thread.Sleep(100);
            //    now = DateTime.Now;
            //    timeSpan = now - start;
            //}

            //if (timeSpan.TotalMilliseconds > config.Timeout)
            //{
            //    throw new BaseException("超时:");
            //}
            #endregion

            TimeUtils.Execute(() =>
            {
                int n = comDut.BytesToRead;
                //if (n == 0 )
                //{
                //    //继续循环执行
                //    return false;
                //}
                log.Info(string.Format("接收的长度:{0}", n));
                if (n != 0)
                {
                    byte[] buf = new byte[n];
                    comDut.Read(buf, 0, n);
                    UartDisplay(buf, "R");

                    buffer.Clear();
                    buffer.AddRange(buf);
                }
                //byte[] buf = new byte[n];
                //comDut.Read(buf, 0, n);
                //buffer.AddRange(buf);

                if (buffer.Count > 9)
                {
                    if (buffer[0] == 0xA5)
                    {
                        //throw new BaseException(string.Format("Head Error"));
                        //if (&& buf[1] == 0xC3))
                        //{

                        //}
                        if (buffer[1] == 0xC3)
                        {
                            byte high        = buffer[2];
                            byte low         = buffer[3];
                            int iTotalLength = (high & 0xFF) << 8 | low;

                            if (buffer.Count < iTotalLength) //数据区尚未接收完整
                            {
                                //继续循环执行
                                log.Info(string.Format("数据尚未接收完整,已接收:{0},总长度:{1}", buffer.Count, iTotalLength));
                                return(false);
                            }
                            byte[] oneFrameBytes = new byte[iTotalLength];
                            buffer.CopyTo(0, oneFrameBytes, 0, iTotalLength);
                            buffer.RemoveRange(0, iTotalLength);

                            UartDisplay(oneFrameBytes, "R");

                            #region //开始校验-命令字
                            if (config.CommandType == SKGControlCommandProperties.EnumCommandType.查询指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x37))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.控制指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x40))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.发授权)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x23))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else
                            {
                                log.Info(string.Format("非法指令类型"));
                                //继续循环执行
                                return(false);
                            }

                            //异或校验 1字节
                            byte[] bufOutOxr = new byte[oneFrameBytes.Length - 1];
                            Array.Copy(oneFrameBytes, 0, bufOutOxr, 0, oneFrameBytes.Length - 1);
                            byte retXor = ByteToXOR(bufOutOxr);

                            if (oneFrameBytes[iTotalLength - 1] != retXor)
                            {
                                log.Info(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], retXor));
                                //继续循环执行
                                return(false);
                            }
                            log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], retXor));

                            //数据内容 32个字节——长度是不固定的
                            byte[] dataArry = new byte[iTotalLength - 9];                //config.DataLength
                            Array.Copy(oneFrameBytes, 8, dataArry, 0, iTotalLength - 9); //config.DataLength

                            //添加到全局变量中
                            if (config.GlobalVariblesKey != null)
                            {
                                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                                {
                                    Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                                    if (!matchKey.Success)
                                    {
                                        throw new BaseException("read info key fail");
                                    }

                                    string key = matchKey.Groups[1].ToString();

                                    configGv.Add(key, dataArry);
                                    log.Info("应答报文格式检查PASS");
                                }
                            }

                            //跳出循环执行
                            return(true);

                            #endregion
                        }
                        else
                        {
                            log.Info(string.Format("头部不是0xA5,0xC3,buffer.RemoveAt:{0:X2},{1:X2}", buffer[0], buffer[1]));

                            buffer.RemoveRange(0, 2);
                            //继续循环执行
                            return(false);
                        }
                    }
                    else
                    {
                        log.Info(string.Format("头部不是0xA5,buffer.RemoveAt:{0:X2}", buffer[0]));

                        buffer.RemoveAt(0);
                        //继续循环执行
                        return(false);
                    }
                }
                else
                {
                    log.Info(string.Format("buffer.Count:{0}小于最小长度9", buffer.Count));
                    //继续循环执行
                    return(false);
                }
            }, config.Timeout);

            #region 原发送命令后等待一固定时间,再接收数据,对应不上则重试

            ////解析是否收到正确的包,包头,命令,校验位
            ////起始标志 数据长度 保留字     命令字     数据内容    异或校验码
            ////0XA5C3    9+N     0x0000      0x0037      Data        异或
            ////2 字节  2 字节    2 字节      2 字节      N 字节     1 字节
            //UartDisplay(buf, "R");
            //if (buf.Length < 9)
            //{
            //    throw new BaseException(string.Format("Response Length Not enough"));
            //}
            ////包头
            //if (!(buf[0] == 0xA5 && buf[1] == 0xC3))
            //{
            //    throw new BaseException(string.Format("Response Head Error"));
            //}
            ////长度 2字节
            //byte high = buf[2];
            //byte low = buf[3];
            //int iTotalLength = (high & 0xFF) << 8 | low;

            //if (iTotalLength != n)
            //{
            //    throw new BaseException(string.Format("Response Length Error,长度位:{0},实际长度:{1}", iTotalLength, n));
            //}

            ////命令字
            //if (config.CommandType == SKGControlCommandProperties.EnumCommandType.查询指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x37))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.控制指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x40))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGControlCommandProperties.EnumCommandType.下发授权)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x23))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else
            //{
            //    throw new BaseException(string.Format("Response为非法指令类型"));
            //}


            ////异或校验 1字节
            //byte[] bufOutOxr = new byte[buf.Length - 1];
            //Array.Copy(buf, 0, bufOutOxr, 0, buf.Length - 1);
            //byte retXor = ByteToXOR(bufOutOxr);

            //if (buf[n - 1] != retXor)
            //{
            //    throw new BaseException(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], retXor));
            //}
            //log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], retXor));


            ////数据内容 32个字节
            ////byte[] dataArry = new byte[config.DataLength];
            ////Array.Copy(buf, 8, dataArry, 0, config.DataLength);

            //byte[] dataArry = new byte[iTotalLength - 9];//config.DataLength
            //Array.Copy(buf, 8, dataArry, 0, iTotalLength - 9);//config.DataLength

            ////添加到全局变量中
            //if (config.GlobalVariblesKey != null)
            //{
            //    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //    {
            //        //string pattern = "-([0-9]{2}) ";
            //        //Match matchValue = Regex.Match(response, pattern);
            //        //if (!matchValue.Success)
            //        //{
            //        //    throw new BaseException("read info value fail");
            //        //}

            //        //string value = matchValue.Groups[1].ToString();

            //        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //        if (!matchKey.Success)
            //        {
            //            throw new BaseException("read info key fail");
            //        }

            //        string key = matchKey.Groups[1].ToString();

            //        configGv.Add(key, dataArry);
            //        log.Info("应答报文格式检查PASS");
            //    }
            //}
            #endregion
            //检查是否有效果!!!
            //通过另外一个AT口,去获取电流值



            ////如果收到的包正确
            //string str = byteToHexStr(buf);


            //string response = comDut.ReadExisting();
            //comDut.DtrEnable = false;
            //comDut.RtsEnable = false;

            //log.Info("AT Response=" + response);

            //if (!string.IsNullOrEmpty(config.AtCommandError))
            //{
            //    if (response.Contains(config.AtCommandError))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
            //    }
            //}

            //if (!string.IsNullOrEmpty(config.AtCommandOk))
            //{
            //    if (!response.Contains(config.AtCommandOk))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
            //    }
            //}

            //if (config.CheckInfo != null)
            //{
            //    for (int i = 0; i < config.CheckInfo.Length; i++)
            //    {
            //        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
            //        {
            //            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
            //            if (!response.Contains(checkInfo))
            //            {
            //                throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
            //            }
            //        }
            //    }
            //}

            //if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
            //{
            //    if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length)
            //    {
            //        throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在");
            //    }
            //    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //    {
            //        string pattern = "-([0-9]{2}) ";
            //        Match matchValue = Regex.Match(response, pattern);
            //        if (!matchValue.Success)
            //        {
            //            throw new BaseException("read info value fail");
            //        }

            //        string value = matchValue.Groups[1].ToString();

            //        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //        if (!matchKey.Success)
            //        {
            //            throw new BaseException("read info key fail");
            //        }

            //        string key = matchKey.Groups[1].ToString();

            //        configGv.Add(key, value);
            //    }
            //}
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ParseLabelProperties properties = new ParseLabelProperties()
            {
                MacLocation = 1,
                //ImeiLocation = 1,
                //SnLocation = 2,
            };
            TaskItemManager taskItemManager = new TaskItemManager(properties);

            taskItemManager.MesPreCheckProperties.EnableCheckMac = true;
            taskItemManager.TaskItemParseLabel.Enable            = true;
            //生成log
            taskItemManager.DeinitProperties.LogType = LogType.MAC;


            //打开WIFI UART
            OpenPhoneProperties configOpenWifiUart = new OpenPhoneProperties();

            configOpenWifiUart.PortName              = "COM5";
            configOpenWifiUart.BaudRate              = 115200;
            configOpenWifiUart.Dtr                   = true;
            configOpenWifiUart.Rts                   = true;
            configOpenWifiUart.EndLine               = "\\r\\n";
            configOpenWifiUart.Timeout               = 10 * 1000;
            configOpenWifiUart.RetryCount            = 0;
            configOpenWifiUart.AtType                = AtType.Manual;
            configOpenWifiUart.SleepTimeAfterFindDut = 1000;
            TaskItem openWifiUartItem = new TaskItem();

            openWifiUartItem.Enable           = true;
            openWifiUartItem.Item             = "打开AT指令串口";//Open Wifi Uart
            openWifiUartItem.CommonProperties = configOpenWifiUart;
            openWifiUartItem.Executer         = new OpenPhoneExecutor();
            taskItemManager.Put(openWifiUartItem);

            //发现设备
            TaskItem findDevice = new TaskItem();

            findDevice.Enable           = true;
            findDevice.Item             = "发现设备";//Find Device
            findDevice.CommonProperties = new FindDeviceProperties()
            {
                TestPowerOnAT     = "",
                AtCommandInterval = 1000,
                EndLine           = "\r\n",  //\r\n
                AtCommandOk       = "ERROR", //+NOTICE:SCANFINISH
                Timeout           = 10 * 1000,
                RetryCount        = 0,
                SleepTimeBefore   = 200,
            };
            findDevice.Executer = new FindDeviceExecuter();
            taskItemManager.Put(findDevice);

            //读取License文件至内存
            if (true)
            {
                TaskItem readBinItem = new TaskItem();
                readBinItem.Enable           = true;
                readBinItem.Item             = "读取License文件";//Read MAP From File
                readBinItem.CommonProperties = new ReadMapProperties()
                {
                    BinFolderPath = "./bin",
                    RetryCount    = 0,
                };
                readBinItem.Executer = new ReadMapExecuter();
                taskItemManager.Put(readBinItem);
            }

            //发AT+LIC?命令
            if (true)
            {
                TaskItem getLicenseItem = new TaskItem();
                getLicenseItem.Enable           = true;
                getLicenseItem.Item             = "检查产品License";//Check BT MAC
                getLicenseItem.CommonProperties = new GetLicenseProperties()
                {
                    RetryCount = 0,

                    AtCommand         = "AT+LIC?",
                    EndLine           = "\r\n",//\r\n
                    AtCommandOk       = "OK",
                    AtCommandError    = "ERROR",
                    CheckInfo         = new string[] { "{BinFileString}" },
                    AtCommandInterval = 2000,

                    IsToUpper = true,
                    PortName  = "COM25",
                    BaudRate  = 115200,
                    Dtr       = false,
                    Rts       = false,
                };

                getLicenseItem.Executer = new GetLicenseExecuter();
                taskItemManager.Put(getLicenseItem);
            }

            //关闭WIFI UART
            TaskItem closeWifiUartItem = new TaskItem();

            closeWifiUartItem.Enable           = true;
            closeWifiUartItem.Item             = "关闭WIFI串口";//Close WIFI Uart
            closeWifiUartItem.Executer         = new ClosePhoneExecutor();
            closeWifiUartItem.CommonProperties = new CommonProperties()
            {
                ExecuteCondition = ExecuteCondition.ALWAYS,
                RetryCount       = 0,
            };
            taskItemManager.Put(closeWifiUartItem);

            ////打开BT
            //OpenPhoneProperties configOpenPhone = new OpenPhoneProperties();
            //configOpenPhone.PortName = "COM17";
            //configOpenPhone.BaudRate = 2400;
            //configOpenPhone.Dtr = true;
            //configOpenPhone.Rts = true;
            //configOpenPhone.EndLine = "\\r\\n";
            //configOpenPhone.Timeout = 10 * 1000;
            //configOpenPhone.RetryCount = 0;
            //configOpenPhone.AtType = AtType.Manual;
            //configOpenPhone.SleepTimeAfterFindDut = 1000;
            //TaskItem openPhoneItem = new TaskItem();
            //openPhoneItem.Enable = true;
            //openPhoneItem.Item = "打开BT串口";//Open BT Uart
            //openPhoneItem.CommonProperties = configOpenPhone;
            //openPhoneItem.Executer = new OpenPhoneExecutor();
            //taskItemManager.Put(openPhoneItem);

            ////读BT MAC,若读到则放到 MAC_BT中即可,后续fetch sn将自动+1,而不是取。若未读到,则info一下即可
            //if (true)
            //{

            //    TaskItem isitWrittenMac = new TaskItem();
            //    isitWrittenMac.Enable = true;
            //    isitWrittenMac.Item = "BT MAC预读";//Check BT MAC
            //    isitWrittenMac.CommonProperties = new IsitWrittenToTheBtMacProperties()
            //    {
            //        ResultType = AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption,
            //        ImesPreCheck = true,

            //        Timeout = 3 * 1000,
            //        RetryCount = 0,

            //        AtCommand = "AT+GETBLEMAC",
            //        AtCommandError = "ERROR",

            //        GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})",
            //        GlobalVariblesKey = "{MAC_BT}",

            //        AtCommandInterval = 1000,
            //        SleepTimeBefore = 1500,
            //    };

            //    isitWrittenMac.Executer = new IsitWrittenToTheBtMacExecuter();
            //    taskItemManager.Put(isitWrittenMac);
            //}


            ////写BT 固件
            //TaskItem writeBtBin = new TaskItem();
            //writeBtBin.Enable = true;
            //writeBtBin.Item = "写BT固件";//Write BT Bin
            //writeBtBin.CommonProperties = new WriteBtBinProperties()
            //{
            //    EraseCmd = "nrfjprog.exe --eraseall -f NRF52",
            //    ProgramCmd = "nrfjprog.exe --program {0} --verify -f NRF52",
            //    BinFileFullPath = " ./bin/whole.hex",
            //    ResetCmd = "nrfjprog.exe --reset -f NRF52",
            //    CmdCommandInterval = 500,

            //    Timeout = 10 * 1000,
            //    RetryCount = 0,
            //    SleepTimeBefore = 100,
            //};
            //writeBtBin.Executer = new WriteBtBinExecuter();
            //taskItemManager.Put(writeBtBin);

            ////BT版本号检查
            //if (true)
            //{
            //    TaskItem checkBtVersionItem = new TaskItem();
            //    checkBtVersionItem.Enable = true;
            //    checkBtVersionItem.Item = "BLE固件版本号检查";//Write BT MAC
            //    AtCommandProperties checkBtVersionProperties = new AtCommandProperties();
            //    checkBtVersionProperties.AtCommand = "AT+GETINFO";

            //    checkBtVersionProperties.AtCommandOk = "GET INFO OK";
            //    checkBtVersionProperties.AtCommandError = "ERROR";
            //    checkBtVersionProperties.CheckInfo = new string[] { "AI_WRIST_V1.15", "Apr  9 2020 18:58:47" };

            //    checkBtVersionProperties.AtCommandInterval = 1000;
            //    checkBtVersionProperties.SleepTimeBefore = 800;

            //    checkBtVersionItem.CommonProperties = checkBtVersionProperties;
            //    checkBtVersionItem.Executer = new AtCommandExecuter();
            //    taskItemManager.Put(checkBtVersionItem);
            //}

            //////读BT MAC,判断是否要取号
            ////if (true)
            ////{
            ////    //读BT MAC
            ////    TaskItem getBTMacItem = new TaskItem();
            ////    getBTMacItem.Enable = true;
            ////    getBTMacItem.Item = "读BT MAC";//GET BT MAC
            ////    AtCommandProperties configGetBtMac = new AtCommandProperties();
            ////    configGetBtMac.AtCommand = "AT+GETBLEMAC";

            ////    configGetBtMac.AtCommandOk = "OK";
            ////    configGetBtMac.AtCommandError = "ERROR";

            ////    configGetBtMac.GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})";//KBLE MAC:112233445566OK
            ////    configGetBtMac.GlobalVariblesKey = "{MoudleBtMac}";

            ////    configGetBtMac.AtCommandInterval = 800;
            ////    configGetBtMac.SleepTimeBefore = 800;
            ////    getBTMacItem.CommonProperties = configGetBtMac;
            ////    getBTMacItem.Executer = new AtCommandExecuter();
            ////    taskItemManager.Put(getBTMacItem);
            ////}

            ////判断是否要取号,不取则+1赋值,并通知不从imes取号
            ////if (true)
            ////{
            ////    TaskItem isFetchMac = new TaskItem();
            ////    isFetchMac.Enable = true;
            ////    isFetchMac.Item = "取MAC号方式自动判断";//Check BT MAC
            ////    isFetchMac.CommonProperties = new AccessToMacProperties()
            ////    {
            ////        Timeout = 3 * 1000,
            ////        RetryCount = 0,

            ////        AtCommand = "AT+GETBLEMAC",
            ////        AtCommandError = "ERROR",

            ////        GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})",
            ////        GlobalVariblesKey = "{MoudleBtMac}",

            ////        AtCommandInterval = 800,
            ////        SleepTimeBefore = 800,
            ////    };

            ////    isFetchMac.Executer = new AccessToMacExecuter();
            ////    taskItemManager.Put(isFetchMac);
            ////}

            ////从IMES取wifi MAC,bt mac会自动放入全局变量
            //if (true)
            //{
            //    MesFetchSnProperties mesFetchSnProperties = new MesFetchSnProperties();
            //    mesFetchSnProperties.RetryCount = 0;
            //    mesFetchSnProperties.IsNeedInc1 = true;
            //    taskItemManager.AppendMesFetchSn(mesFetchSnProperties);

            //}


            ////写BT MAC
            //TaskItem writeBTMacItem = new TaskItem();
            //writeBTMacItem.Enable = true;
            //writeBTMacItem.Item = "写BT MAC";//Write BT MAC
            //AtCommandProperties configWriteBtMac = new AtCommandProperties();
            //configWriteBtMac.AtCommand = "AT+SETBLEMAC={MAC_BT}";

            //configWriteBtMac.AtCommandOk = "reboot system";
            //configWriteBtMac.AtCommandError = "ERROR";
            //configWriteBtMac.AtCommandInterval = 800;
            //configWriteBtMac.SleepTimeBefore = 3000;
            //writeBTMacItem.CommonProperties = configWriteBtMac;
            //writeBTMacItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(writeBTMacItem);

            ////读BT MAC
            //if (true)
            //{
            //    TaskItem getBTMacItem = new TaskItem();
            //    getBTMacItem.Enable = true;
            //    getBTMacItem.Item = "读BT MAC";//GET BT MAC
            //    AtCommandProperties configGetBtMac = new AtCommandProperties();
            //    configGetBtMac.AtCommand = "AT+GETBLEMAC";

            //    configGetBtMac.AtCommandOk = "OK";
            //    configGetBtMac.AtCommandError = "ERROR";

            //    configGetBtMac.GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})";//KBLE MAC:112233445566OK
            //    configGetBtMac.GlobalVariblesKey = "{MoudleBtMac}";

            //    configGetBtMac.AtCommandInterval = 800;
            //    getBTMacItem.CommonProperties = configGetBtMac;
            //    getBTMacItem.Executer = new AtCommandExecuter();
            //    taskItemManager.Put(getBTMacItem);
            //}
            ////生成BT MAC二维码
            //if (true)
            //{
            //    TaskItem showBtMacQrCodeItem = new TaskItem();
            //    showBtMacQrCodeItem.Enable = true;
            //    showBtMacQrCodeItem.Item = "展示BT MAC二维码";//Check BT RSSI
            //    showBtMacQrCodeItem.CommonProperties = new ShowBtMacQrCodeProperties()
            //    {
            //        RetryCount = 3,
            //        StrQrcode = "http://www.baidu.com",
            //        ShowTime = 8000,
            //    };
            //    showBtMacQrCodeItem.Executer = new ShowBtMacQrCodeExecuter();
            //    taskItemManager.Put(showBtMacQrCodeItem);
            //}

            ////校验BT MAC
            ////************待补充:来自IMES的BtMac应存在全局变量中*************
            //TaskItem checkBtMac = new TaskItem();
            //checkBtMac.Enable = true;
            //checkBtMac.Item = "校验BT MAC";//Check BT MAC
            //checkBtMac.CommonProperties = new CheckBtMacProperties()
            //{
            //    Timeout = 3 * 1000,
            //    RetryCount = 0,
            //};
            //checkBtMac.Executer = new CheckBtMacExecuter();
            //taskItemManager.Put(checkBtMac);

            ////设置BT FACMODE
            //TaskItem setBtFacModeItem = new TaskItem();
            //setBtFacModeItem.Enable = true;
            //setBtFacModeItem.Item = "设置BT 进入工厂模式";//Set Bt FactoryMode
            //AtCommandProperties configSetBtFacMode = new AtCommandProperties();
            //configSetBtFacMode.AtCommand = "AT+SETFACMODE=1";

            //configSetBtFacMode.AtCommandOk = "OK";
            //configSetBtFacMode.AtCommandError = "ERROR";
            //configSetBtFacMode.AtCommandInterval = 800;
            //configSetBtFacMode.SleepTimeAfter = 7000;
            //setBtFacModeItem.CommonProperties = configSetBtFacMode;
            //setBtFacModeItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(setBtFacModeItem);
            ////BT串口发WIFI 软断电电指令
            //TaskItem wifiPowerOff = new TaskItem();
            //wifiPowerOff.Enable = true;
            //wifiPowerOff.Item = "Wifi 断电";//Wifi PowerOff
            //AtCommandProperties configWifiPowerOff = new AtCommandProperties();
            //configWifiPowerOff.AtCommand = "AT+SETGPSWIFIPWR=0";

            //configWifiPowerOff.AtCommandOk = "OK";
            //configWifiPowerOff.AtCommandError = "ERROR";
            //configWifiPowerOff.CheckInfo = new string[] { "wifi power off" };
            //configWifiPowerOff.AtCommandInterval = 3000;
            ////configWifiPowerOff.SleepTimeBefore = 6000;
            //configWifiPowerOff.Timeout = 12000;
            //configWifiPowerOff.RetryCount = 3;
            //wifiPowerOff.CommonProperties = configWifiPowerOff;
            //wifiPowerOff.Executer = new AtCommandExecuter();
            //taskItemManager.Put(wifiPowerOff);

            ////BT串口发WIFI 软上电指令
            //TaskItem wifiPowerOn = new TaskItem();
            //wifiPowerOn.Enable = true;
            //wifiPowerOn.Item = "Wifi 上电";//Wifi PowerOn
            //AtCommandProperties configWifiPowerOn = new AtCommandProperties();
            //configWifiPowerOn.AtCommand = "AT+SETGPSWIFIPWR=1";

            //configWifiPowerOn.AtCommandOk = "OK";
            //configWifiPowerOn.AtCommandError = "ERROR";
            //configWifiPowerOn.CheckInfo = new string[] { "wifi power on" };
            //configWifiPowerOn.AtCommandInterval = 2000;
            //configWifiPowerOn.Timeout = 3000;
            //configWifiPowerOff.RetryCount = 3;
            //wifiPowerOn.CommonProperties = configWifiPowerOn;
            //wifiPowerOn.Executer = new AtCommandExecuter();
            //taskItemManager.Put(wifiPowerOn);

            ////BT发检查BT广播命令
            //TaskItem btBroadcastItem = new TaskItem();
            //btBroadcastItem.Enable = true;
            //btBroadcastItem.Item = "BT 开始广播";//BT Broadcast
            //AtCommandProperties configBtBroadcast = new AtCommandProperties();
            //configBtBroadcast.AtCommand = "AT+OPENBLEADV";

            //configBtBroadcast.AtCommandOk = "OK";
            //configBtBroadcast.AtCommandError = "ERROR";
            //configBtBroadcast.AtCommandInterval = 600;
            //configBtBroadcast.Timeout = 2000;
            //configBtBroadcast.RetryCount = 3;
            //btBroadcastItem.CommonProperties = configBtBroadcast;
            //btBroadcastItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(btBroadcastItem);

            ////关闭BT UART
            //TaskItem closePhoneItem = new TaskItem();
            //closePhoneItem.Enable = true;
            //closePhoneItem.Item = "关闭BT 串口";//Close BT Uart
            //closePhoneItem.Executer = new ClosePhoneExecutor();
            //closePhoneItem.CommonProperties = new CommonProperties()
            //{
            //    ExecuteCondition = ExecuteCondition.ALWAYS,
            //    RetryCount = 0,
            //};
            //taskItemManager.Put(closePhoneItem);

            //#region BT扫描工具
            ////打开蓝牙扫描工具 UART
            //OpenPhoneProperties configOpentToolUart = new OpenPhoneProperties();
            //configOpentToolUart.PortName = "COM21";
            //configOpentToolUart.BaudRate = 115200;
            //configOpentToolUart.Dtr = true;
            //configOpentToolUart.Rts = true;
            //configOpentToolUart.EndLine = "\\r\\n";
            //configOpentToolUart.Timeout = 10 * 1000;
            //configOpentToolUart.RetryCount = 0;
            //configOpentToolUart.AtType = AtType.Manual;
            //configOpentToolUart.SleepTimeAfterFindDut = 1000;
            //TaskItem configOpentToolUartTtem = new TaskItem();
            //configOpentToolUartTtem.Enable = true;
            //configOpentToolUartTtem.Item = "打开蓝牙扫描工具的串口";//Open Scan Tool Uart
            //configOpentToolUartTtem.CommonProperties = configOpentToolUart;
            //configOpentToolUartTtem.Executer = new OpenPhoneExecutor();
            //taskItemManager.Put(configOpentToolUartTtem);

            ////发送开始扫描命令并获取BT RSSI
            //TaskItem getBtRssiItem = new TaskItem();
            //getBtRssiItem.Enable = true;
            //getBtRssiItem.Item = "开始扫描BT广播包并获取BT RSSI";//Satrt Scan And Get BT RSSI
            //GetBtRssiAtCommandProperties configGetBtRssiPro = new GetBtRssiAtCommandProperties();//GetBtRssiAtCommandProperties
            //configGetBtRssiPro.AtCommand = "AT+INQ";

            //configGetBtRssiPro.AtCommandOk = "OK";
            //configGetBtRssiPro.AtCommandError = "ERROR";
            //configGetBtRssiPro.CheckInfo = new string[] { "INQS" };
            ////********************************************正则表达式中存在变量的情况:该产品的蓝牙MAC后的值*****************************************
            //configGetBtRssiPro.GlobalVariblesKeyPattern = ":RSSI:([0-9-]{3,4})[:]";//"BLE MAC->([0-9A-F:]{17})";
            //configGetBtRssiPro.GlobalVariblesKey = "{MoudleBtRssi}";

            //configGetBtRssiPro.AtCommandInterval = 7000;
            //configGetBtRssiPro.Timeout = 7000;
            //configGetBtRssiPro.RetryCount = 2;
            //getBtRssiItem.CommonProperties = configGetBtRssiPro;
            //getBtRssiItem.Executer = new GetBtRssiAtCommandExecuter();//GetBtRssiAtCommandExecuter
            //taskItemManager.Put(getBtRssiItem);

            ////检查BT RSSI
            //if (true)
            //{
            //    TaskItem checkBtRssiItem = new TaskItem();
            //    checkBtRssiItem.Enable = true;
            //    checkBtRssiItem.Item = "检查BT RSSI";//Check BT RSSI
            //    checkBtRssiItem.CommonProperties = new CheckBtRssiProperties()
            //    {
            //        MaxValue = -10,
            //        MinValue = -90,
            //        Timeout = 2 * 1000,
            //        RetryCount = 0,
            //    };
            //    checkBtRssiItem.Executer = new CheckBtRssiExecuter();
            //    taskItemManager.Put(checkBtRssiItem);
            //}

            ////停止扫描
            //TaskItem stopScanBtRssiItem = new TaskItem();
            //stopScanBtRssiItem.Enable = true;
            //stopScanBtRssiItem.Item = "停止扫描";//Stop Scan BT RSSI
            //AtCommandProperties configStopScanBtRssiPro = new AtCommandProperties();
            //configStopScanBtRssiPro.AtCommand = "AT+SINQ";

            //configStopScanBtRssiPro.AtCommandOk = "INQE";
            //configStopScanBtRssiPro.AtCommandError = "ERROR";
            //configStopScanBtRssiPro.ExecuteCondition = ExecuteCondition.ALWAYS;

            //configStopScanBtRssiPro.AtCommandInterval = 800;
            //configStopScanBtRssiPro.Timeout = 2000;
            //configStopScanBtRssiPro.RetryCount = 0;
            //stopScanBtRssiItem.CommonProperties = configStopScanBtRssiPro;
            //stopScanBtRssiItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(stopScanBtRssiItem);

            ////关闭蓝牙扫描工具 UART
            //TaskItem closeScanToolItem = new TaskItem();
            //closeScanToolItem.Enable = true;
            //closeScanToolItem.Item = "关闭BT扫描工具串口";//Close Scan Tool Uart
            //closeScanToolItem.Executer = new ClosePhoneExecutor();
            //closeScanToolItem.CommonProperties = new CommonProperties()
            //{
            //    ExecuteCondition = ExecuteCondition.ALWAYS,
            //    RetryCount = 0,
            //};
            //taskItemManager.Put(closeScanToolItem);
            //#endregion

            ////打开WIFI UART
            ////OpenPhoneProperties configOpenWifiUart = new OpenPhoneProperties();
            ////configOpenWifiUart.PortName = "COM18";
            ////configOpenWifiUart.BaudRate = 115200;
            ////configOpenWifiUart.Dtr = true;
            ////configOpenWifiUart.Rts = true;
            ////configOpenWifiUart.EndLine = "\\r\\n";
            ////configOpenWifiUart.Timeout = 10 * 1000;
            ////configOpenWifiUart.RetryCount = 0;
            ////configOpenWifiUart.AtType = AtType.Manual;
            ////configOpenWifiUart.SleepTimeAfterFindDut = 1000;
            ////TaskItem openWifiUartItem = new TaskItem();
            ////openWifiUartItem.Enable = true;
            ////openWifiUartItem.Item = "Open Wifi Uart";
            ////openWifiUartItem.CommonProperties = configOpenWifiUart;
            ////openWifiUartItem.Executer = new OpenPhoneExecutor();
            //taskItemManager.Put(openWifiUartItem);


            ////读取WIFI MAP文件至内存********并更新MAC至内存*************
            ////if (true)
            ////{
            ////    TaskItem readMapItem = new TaskItem();
            ////    readMapItem.Enable = true;
            ////    readMapItem.Item = "读取WIFI MAP文件并更新MAC至内存";//Read MAP From File
            ////    readMapItem.CommonProperties = new ReadMapProperties()
            ////    {
            ////        MapFilePath = "./Map/8710BX.map",
            ////        Timeout = 2 * 1000,
            ////        RetryCount = 0,
            ////    };
            ////    readMapItem.Executer = new ReadMapExecuter();
            ////    taskItemManager.Put(readMapItem);
            ////}


            ////写WIFI MAP  使用comdut自定义来写
            //TaskItem writeWifiMapItem = new TaskItem();
            //writeWifiMapItem.Enable = true;
            //writeWifiMapItem.Item = "写WIFI MAP";//
            //writeWifiMapItem.CommonProperties = new WriteWifiMapProperties()
            //{
            //    //取MAC文件一行一行的写(16个字节)
            //    WriteMapAtCommand = "iwpriv config_set wmap,{0},{1}",
            //    Address = "0x00",
            //    AtCommandInterval = 50,
            //    AtCommandOk = "[MEM] After do cmd",
            //    AtCommandError = "unknown command",

            //    Timeout = 20 * 1000,//5
            //    RetryCount = 0,
            //    RetryInterval = 50,
            //};
            //writeWifiMapItem.Executer = new WriteWifiMapExecuter();
            //taskItemManager.Put(writeWifiMapItem);



            ////写WIFI MAC
            ////TaskItem writeWifiMacItem = new TaskItem();
            ////writeWifiMacItem.Enable = true;
            ////writeWifiMacItem.Item = "Write WIFI MAC";
            ////AtCommandProperties configWriteWifiMac = new AtCommandProperties();
            ////configWriteWifiMac.AtCommand = "iwpriv config_set wmap,0x0a,{MAC}";

            ////configWriteWifiMac.AtCommandOk = "Private Message: 0x";
            ////configWriteWifiMac.AtCommandError = "unknown command";
            ////configWriteWifiMac.AtCommandInterval = 800;
            ////writeWifiMacItem.CommonProperties = configWriteWifiMac;
            ////writeWifiMacItem.Executer = new AtCommandExecuter();
            ////taskItemManager.Put(writeWifiMacItem);

            //////读并校验WIFI MAC


            ////读并WIFI MAP
            //TaskItem getWifiMoudleMapItem = new TaskItem();
            //getWifiMoudleMapItem.Enable = true;
            //getWifiMoudleMapItem.Item = "读产品内部WIFI Map";//Get Wifi Moudle Map
            //AtCommandProperties configGetWifiMoudleMap = new AtCommandProperties();
            //configGetWifiMoudleMap.AtCommand = "iwpriv config_get rmap,00,512";

            //configGetWifiMoudleMap.AtCommandOk = "Private Message: 0x";
            //configGetWifiMoudleMap.AtCommandError = "unknown command";

            //configGetWifiMoudleMap.GlobalVariblesKeyPattern = "Private Message: ([0-9A-Fx ]{2560})";//"BLE MAC->([0-9A-F:]{17})";
            //configGetWifiMoudleMap.GlobalVariblesKey = "{MoudleWifiMap}";

            //configGetWifiMoudleMap.AtCommandInterval = 800;
            //configGetWifiMoudleMap.RetryCount = 5;
            //getWifiMoudleMapItem.CommonProperties = configGetWifiMoudleMap;
            //getWifiMoudleMapItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getWifiMoudleMapItem);


            ////校验WIFI MAP
            //TaskItem checkWifiMapItem = new TaskItem();
            //checkWifiMapItem.Enable = true;
            //checkWifiMapItem.Item = "校验WIFI Map";//Check Wifi Map
            //checkWifiMapItem.CommonProperties = new CheckWifiMapProperties()
            //{
            //    Timeout = 3 * 1000,
            //    RetryCount = 0,
            //};
            //checkWifiMapItem.Executer = new CheckWifiMapExecuter();
            //taskItemManager.Put(checkWifiMapItem);



            ////WIFI退出MP模式,进入用户模式
            //TaskItem wifiIntoUserMode = new TaskItem();
            //wifiIntoUserMode.Enable = true;
            //wifiIntoUserMode.Item = "WIFI进入用户模式";//Wifi Into User Mode
            //AtCommandProperties configWifiIntoUserProperties = new AtCommandProperties();
            //configWifiIntoUserProperties.AtCommand = "ATSC";
            ////****************************进入用户模式是否回复OK?***********************
            //configWifiIntoUserProperties.AtCommandOk = "Enter Image 2 ";
            //configWifiIntoUserProperties.AtCommandError = "ERROR";
            ////configWifiIntoUserProperties.CheckInfo = new string[] { "[ATSC]:", "AT_SYSTEM_CLEAR_OTA_SIGNATURE" };
            //configWifiIntoUserProperties.AtCommandInterval = 4000;
            //wifiIntoUserMode.CommonProperties = configWifiIntoUserProperties;
            //wifiIntoUserMode.Executer = new AtCommandExecuter();
            //taskItemManager.Put(wifiIntoUserMode);


            ////检查WIFI版本号 关键字
            //TaskItem getWifiVersionItem = new TaskItem();
            //getWifiVersionItem.Enable = true;
            //getWifiVersionItem.Item = "检查WIFI版本号";//Get Wifi Version
            //AtCommandProperties configGetWifiVersionProperties = new AtCommandProperties();
            //configGetWifiVersionProperties.AtCommand = "ATS?";
            //configGetWifiVersionProperties.AtCommandOk = "[ATS?]: SW VERSION:";
            //configGetWifiVersionProperties.AtCommandError = "unknown command";
            //configGetWifiVersionProperties.CheckInfo = new string[] { "SW VERSION: v.3.4" };
            ////configGetWifiVersionProperties.GlobalVariblesKeyPattern = "SW VERSION: ([v0-9.]{5})";//"BLE MAC->([0-9A-F:]{17})";
            ////configGetWifiVersionProperties.GlobalVariblesKey = "{MoudleWifiVersion}";


            //configGetWifiVersionProperties.AtCommandInterval = 800;
            //configGetWifiVersionProperties.RetryCount = 3;
            //getWifiVersionItem.CommonProperties = configGetWifiVersionProperties;
            //getWifiVersionItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getWifiVersionItem);



            ////关闭WIFI UART
            ////TaskItem closeWifiUartItem = new TaskItem();
            ////closeWifiUartItem.Enable = true;
            ////closeWifiUartItem.Item = "Close WIFI Uart";
            ////closeWifiUartItem.Executer = new ClosePhoneExecutor();
            ////closeWifiUartItem.CommonProperties = new CommonProperties()
            ////{
            ////    ExecuteCondition = ExecuteCondition.ALWAYS,
            ////    RetryCount = 0,
            ////};
            //taskItemManager.Put(closeWifiUartItem);



            ////打开BT UART->版本号检查->信号强度检查->心率检查
            ////OpenPhoneProperties configOpenBtUart = new OpenPhoneProperties();
            ////configOpenBtUart.PortName = "COM17";
            ////configOpenBtUart.BaudRate = 2400;
            ////configOpenBtUart.Dtr = true;
            ////configOpenBtUart.Rts = true;
            ////configOpenBtUart.EndLine = "\\r\\n";
            ////configOpenBtUart.Timeout = 10 * 1000;
            ////configOpenBtUart.RetryCount = 0;
            ////configOpenBtUart.AtType = AtType.Manual;
            ////configOpenBtUart.SleepTimeAfterFindDut = 1000;
            ////TaskItem openBtUartItem = new TaskItem();
            ////openBtUartItem.Enable = true;
            ////openBtUartItem.Item = "Open BT Uart";
            ////openBtUartItem.CommonProperties = configOpenBtUart;
            ////openBtUartItem.Executer = new OpenPhoneExecutor();
            ////taskItemManager.Put(openBtUartItem);
            //taskItemManager.Put(openPhoneItem);

            ////NB 软件版本号检查 AT+CGMR 关键字
            //TaskItem nbSoftVersionCheck = new TaskItem();
            //nbSoftVersionCheck.Enable = true;
            //nbSoftVersionCheck.Item = "检查NB软件版本号";//NB Soft Version Check
            //AtCommandProperties configNbSoftVersionCheck = new AtCommandProperties();
            //configNbSoftVersionCheck.AtCommand = "AT+CGMR";

            //configNbSoftVersionCheck.AtCommandOk = "OK";
            //configNbSoftVersionCheck.AtCommandError = "ERROR";
            //configNbSoftVersionCheck.CheckInfo = new string[] { "SOTFWAREVER:AI_LITEOS_NB15_B300SP5_V1.9_20200229" };
            //configNbSoftVersionCheck.AtCommandInterval = 1500;
            //configNbSoftVersionCheck.SleepTimeBefore = 500;
            //nbSoftVersionCheck.CommonProperties = configNbSoftVersionCheck;
            //nbSoftVersionCheck.Executer = new AtCommandExecuter();
            //taskItemManager.Put(nbSoftVersionCheck);

            //# region NB IMEI号等
            ////在IMEI等号之前先发AT+CFUN=1
            //TaskItem nbAtCfun = new TaskItem();
            //nbAtCfun.Enable = true;
            //nbAtCfun.Item = "设置BT CFUN为1";//AT CFUN
            //AtCommandProperties confignbAtCfun = new AtCommandProperties();
            //confignbAtCfun.AtCommand = "AT+CFUN=1";

            //confignbAtCfun.AtCommandOk = "OK";
            //confignbAtCfun.AtCommandError = "ERROR";
            //confignbAtCfun.AtCommandInterval = 4000;
            //confignbAtCfun.RetryCount = 3;
            //confignbAtCfun.SleepTimeBefore = 200;
            //nbAtCfun.CommonProperties = confignbAtCfun;
            //nbAtCfun.Executer = new AtCommandExecuter();
            //taskItemManager.Put(nbAtCfun);

            ////获取IMEI
            //TaskItem getNbImeiItem = new TaskItem();
            //getNbImeiItem.Enable = true;
            //getNbImeiItem.Item = "获取NB IMEI";//Get NB IMEI
            //AtCommandProperties configGetNbImeiItem = new AtCommandProperties();
            //configGetNbImeiItem.AtCommand = "AT+CGSN=1";
            //configGetNbImeiItem.AtCommandOk = "OK";
            //configGetNbImeiItem.AtCommandError = "ERROR";

            //configGetNbImeiItem.GlobalVariblesKeyPattern = "CGSN:([0-9]{15})";//"Private Message: ([0-9A-Fx ]{2560})";//"BLE MAC->([0-9A-F:]{17})";
            //configGetNbImeiItem.GlobalVariblesKey = "{NBIMEI}";

            //configGetNbImeiItem.AtCommandInterval = 800;
            //configGetNbImeiItem.RetryCount = 3;
            //getNbImeiItem.CommonProperties = configGetNbImeiItem;
            //getNbImeiItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getNbImeiItem);

            ////检查IMEI标签与内部一致性
            //TaskItem checkNbImei = new TaskItem();
            //checkNbImei.Enable = true;
            //checkNbImei.Item = "检查NB IMEI内部与标签一致性";//Check NB IMEI
            //checkNbImei.CommonProperties = new CheckNbImeiProperties()
            //{
            //    Timeout = 2 * 1000,
            //    RetryCount = 0,
            //};
            //checkNbImei.Executer = new CheckNbImeiExecuter();
            //taskItemManager.Put(checkNbImei);


            ////打印标签的IMEI 设置为NB IMEI
            //TaskItem printLabelImeiChangetToNbImeiItem = new TaskItem();
            //printLabelImeiChangetToNbImeiItem.Enable = true;
            //printLabelImeiChangetToNbImeiItem.Item = "打印标签IMEI设置为NB IMEI";//LOG MAC CHANGE TO BT MAC
            //printLabelImeiChangetToNbImeiItem.CommonProperties = new PrintLabelImeiChangetToNbImeiProperties()
            //{
            //    RetryCount = 0,
            //};
            //printLabelImeiChangetToNbImeiItem.Executer = new PrintLabelImeiChangetToNbImeiExecuter();
            //taskItemManager.Put(printLabelImeiChangetToNbImeiItem);

            ////
            //TaskItem getNbImsiItem = new TaskItem();
            //getNbImsiItem.Enable = true;
            //getNbImsiItem.Item = "获取NB IMSI";//Get NB IMSI
            //AtCommandProperties configGetNbImsiItem = new AtCommandProperties();
            //configGetNbImsiItem.AtCommand = "AT+CIMI";
            //configGetNbImsiItem.AtCommandOk = "OK";
            //configGetNbImsiItem.AtCommandError = "ERROR";

            //configGetNbImsiItem.GlobalVariblesKeyPattern = "\r\n([0-9]{15})";
            //configGetNbImsiItem.GlobalVariblesKey = "{IMSI}";

            //configGetNbImsiItem.AtCommandInterval = 800;
            //configGetNbImsiItem.RetryCount = 3;
            //getNbImsiItem.CommonProperties = configGetNbImsiItem;
            //getNbImsiItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getNbImsiItem);

            ////获取ICCID
            //TaskItem getNbIccidItem = new TaskItem();
            //getNbIccidItem.Enable = true;
            //getNbIccidItem.Item = "获取NB ICCID";//Get NB ICCID
            //AtCommandProperties configGetNbIccidItem = new AtCommandProperties();
            //configGetNbIccidItem.AtCommand = "AT+NCCID";

            //configGetNbIccidItem.AtCommandOk = "OK";
            //configGetNbIccidItem.AtCommandError = "ERROR";

            //configGetNbIccidItem.GlobalVariblesKeyPattern = "NCCID:([0-9]{20})";
            //configGetNbIccidItem.GlobalVariblesKey = "{ICCID}";

            //configGetNbIccidItem.AtCommandInterval = 800;
            //configGetNbIccidItem.RetryCount = 3;
            //getNbIccidItem.CommonProperties = configGetNbIccidItem;
            //getNbIccidItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getNbIccidItem);
            //#endregion



            //#region BT/NB 功能检查
            ////附网,AT+CGATT=1
            ////*********************返回什么为PASS????  : OK************************
            //TaskItem nbClingNetItem = new TaskItem();
            //nbClingNetItem.Enable = true;
            //nbClingNetItem.Item = "NB 附网";//NB Cling Net
            //AtCommandProperties configNbClingNetProperties = new AtCommandProperties();
            //configNbClingNetProperties.AtCommand = "AT+CGATT=1";

            //configNbClingNetProperties.AtCommandOk = "OK";
            //configNbClingNetProperties.AtCommandError = "ERROR";
            ////configNbNetCheckProperties.CheckInfo = new string[] { "...1" };
            //configNbClingNetProperties.AtCommandInterval = 2000;
            //configNbClingNetProperties.SleepTimeBefore = 100;
            //nbClingNetItem.CommonProperties = configNbClingNetProperties;
            //nbClingNetItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(nbClingNetItem);

            ////附网检查 AT+CGATT?  检查是否为1
            ////*********************返回什么为PASS????  :1 ************************
            //TaskItem nbNetCheckItem = new TaskItem();
            //nbNetCheckItem.Enable = true;
            //nbNetCheckItem.Item = "NB附网检查";//B Net CheckN
            //AtCommandProperties configNbNetCheckProperties = new AtCommandProperties();
            //configNbNetCheckProperties.AtCommand = "AT+CGATT?";

            //configNbNetCheckProperties.AtCommandOk = "OK";
            //configNbNetCheckProperties.AtCommandError = "ERROR";
            //configNbNetCheckProperties.CheckInfo = new string[] { "CGATT:1" };
            //configNbNetCheckProperties.AtCommandInterval = 5000;
            //configNbNetCheckProperties.SleepTimeBefore = 100;
            //nbNetCheckItem.CommonProperties = configNbNetCheckProperties;
            //nbNetCheckItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(nbNetCheckItem);



            ////信号强度CSQ获取
            //TaskItem getCsqItem = new TaskItem();
            //getCsqItem.Enable = true;
            //getCsqItem.Item = "获取NB信号强度";//Get NB CSQ
            //AtCommandProperties configGetCsqProperties = new AtCommandProperties();
            //configGetCsqProperties.AtCommand = "AT+CSQ";
            //configGetCsqProperties.AtCommandOk = "OK";
            //configGetCsqProperties.AtCommandError = "ERROR";

            //configGetCsqProperties.GlobalVariblesKeyPattern = "CSQ:([0-9]{1,2})[,]";
            //configGetCsqProperties.GlobalVariblesKey = "{NBCSQ}";

            //configGetCsqProperties.AtCommandInterval = 1000;
            //configGetCsqProperties.RetryCount = 3;
            //getCsqItem.CommonProperties = configGetCsqProperties;
            //getCsqItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getCsqItem);

            ////检查信号强度
            //TaskItem checkCsqItem = new TaskItem();
            //checkCsqItem.Enable = true;
            //checkCsqItem.Item = "检查NB信号强度";//Check Csq
            //checkCsqItem.CommonProperties = new CheckCsqProperties()
            //{
            //    MaxValue = 100,
            //    MinValue = 1,
            //    Timeout = 2 * 1000,
            //    RetryCount = 0,
            //};
            //checkCsqItem.Executer = new CheckCsqExecuter();
            //taskItemManager.Put(checkCsqItem);


            ////获取WIFI探针值
            //TaskItem getWifiProbeItem = new TaskItem();
            //getWifiProbeItem.Enable = true;
            //getWifiProbeItem.Item = "获取WIFI探针-信号强度值";//Get WIFI PROBE
            //AtCommandProperties configGetWifiProbeProperties = new AtCommandProperties();
            //configGetWifiProbeProperties.AtCommand = "AT+AIGPSWIFI=WIFI,2";
            //configGetWifiProbeProperties.AtCommandOk = "OK";
            //configGetWifiProbeProperties.AtCommandError = "ERROR";

            //configGetWifiProbeProperties.GlobalVariblesKeyPattern = "7405a58fa8cb:([0-9-]{1,3}),";

            ////configCheckWifiProbeProperties.GlobalVariblesKeyPattern = "[0-9,:]]*]";
            //configGetWifiProbeProperties.GlobalVariblesKey = "{NBWIFIPROBE}";

            //configGetWifiProbeProperties.AtCommandInterval = 5000;
            //configGetWifiProbeProperties.RetryCount = 3;
            //getWifiProbeItem.CommonProperties = configGetWifiProbeProperties;
            //getWifiProbeItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getWifiProbeItem);

            ////WIFI探针检查
            //TaskItem checkWifiProbeItem = new TaskItem();
            //checkWifiProbeItem.Enable = true;
            //checkWifiProbeItem.Item = "WIFI探针-信号强度检查";
            //checkWifiProbeItem.CommonProperties = new CheckWifiProbeProperties()
            //{
            //    MaxValue = -10,
            //    MinValue = -90,
            //    Timeout = 2 * 1000,
            //    RetryCount = 0,
            //};
            //checkWifiProbeItem.Executer = new CheckWifiProbeExecuter();
            //taskItemManager.Put(checkWifiProbeItem);



            ////计步器检查
            //TaskItem checkPedometer = new TaskItem();
            //checkPedometer.Enable = true;
            //checkPedometer.Item = "计步器检查";
            //AtCommandProperties configCheckPedometer = new AtCommandProperties();
            //configCheckPedometer.AtCommand = "AT+PEDOTEST";//AT+PEDOTEST

            //configCheckPedometer.AtCommandOk = "OK";
            //configCheckPedometer.AtCommandError = "ERROR";
            //configCheckPedometer.AtCommandInterval = 1000;
            //checkPedometer.CommonProperties = configCheckPedometer;
            //checkPedometer.Executer = new AtCommandExecuter();
            //taskItemManager.Put(checkPedometer);


            ////温度传感器值获取
            //TaskItem getTemp = new TaskItem();
            //getTemp.Enable = true;
            //getTemp.Item = "温度传感器值获取";//Get Temp
            //AtCommandProperties configGetTemp = new AtCommandProperties();
            //configGetTemp.AtCommand = "AT+TEMPTEST";//

            //configGetTemp.AtCommandOk = "OK";
            //configGetTemp.AtCommandError = "ERROR";
            //configGetTemp.GlobalVariblesKeyPattern = "TEMP:([0-9.]*)[\r\n]";//TEMP:1519.7\r\n
            //configGetTemp.GlobalVariblesKey = "{NBTemp}";
            //configGetTemp.AtCommandInterval = 2000;
            //getTemp.CommonProperties = configGetTemp;
            //getTemp.Executer = new AtCommandExecuter();
            //taskItemManager.Put(getTemp);

            ////温度传感器检查
            //TaskItem checkTempItem = new TaskItem();
            //checkTempItem.Enable = true;
            //checkTempItem.Item = "温度传感器检查";//Check Temp
            //checkTempItem.CommonProperties = new CheckTempProperties()
            //{
            //    MaxValue = 5000,
            //    MinValue = 5,
            //    Timeout = 2 * 1000,
            //    RetryCount = 0,
            //};
            //checkTempItem.Executer = new CheckTempExecuter();
            //taskItemManager.Put(checkTempItem);

            ////射频获取
            //TaskItem taskItem10 = new TaskItem();
            //taskItem10.Enable = true;
            //taskItem10.Item = "射频获取";//Get Signal Power
            //AtCommandProperties config10 = new AtCommandProperties();
            //config10.AtCommand = "AT+NUESTATS";
            //config10.AtCommandOk = "OK";
            //config10.AtCommandError = "ERROR";
            //config10.AtCommandInterval = 1000;
            //config10.GlobalVariblesKey = "{SIGNAL_POWER}";
            //config10.GlobalVariblesKeyPattern = "Signal power\\:([0-9\\-]+)\\r\\n";
            //taskItem10.CommonProperties = config10;
            //taskItem10.Executer = new AtCommandExecuter();
            //taskItemManager.Put(taskItem10);

            ////射频对比
            //TaskItem comparePower = new TaskItem();
            //comparePower.Enable = true;
            //comparePower.Item = "射频检查";//Compare Signal Power
            //ConditionProperties configComparePower = new ConditionProperties()
            //{
            //    RetryCount = 0
            //};
            //configComparePower.ConditionItems = new ConditionItem[]{
            //    new ConditionItem()
            //    {
            //        Key = "{SIGNAL_POWER}",
            //        Condition = Condition.GREATER_EQUAL,
            //        Value = "-1000"
            //    }
            //};
            //comparePower.CommonProperties = configComparePower;
            //comparePower.Executer = new ConditionExecuter();
            //taskItemManager.Put(comparePower);
            ////AT+HRMTEST

            ////BT 退出工厂模式
            //TaskItem btOutFactoryModeItem = new TaskItem();
            //btOutFactoryModeItem.Enable = true;
            //btOutFactoryModeItem.Item = "BT 退出工厂模式";//Get Signal Power
            //AtCommandProperties configBtOutFactoryMode = new AtCommandProperties();
            //configBtOutFactoryMode.AtCommand = "AT+SETFACMODE=0";
            //configBtOutFactoryMode.AtCommandOk = "OK";
            //configBtOutFactoryMode.AtCommandError = "ERROR";
            //configBtOutFactoryMode.AtCommandInterval = 1000;
            //btOutFactoryModeItem.CommonProperties = configBtOutFactoryMode;
            //btOutFactoryModeItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(btOutFactoryModeItem);


            ////进入出厂状态
            //TaskItem btInDefaultModeItem = new TaskItem();
            //btInDefaultModeItem.Enable = true;
            //btInDefaultModeItem.Item = "进入出厂状态";//Get Signal Power
            //AtCommandProperties configInDefaultMode = new AtCommandProperties();
            //configInDefaultMode.AtCommand = "AT+FACOUT";
            //configInDefaultMode.AtCommandOk = "OK";
            //configInDefaultMode.AtCommandError = "ERROR";
            //configInDefaultMode.AtCommandInterval = 1000;
            //btInDefaultModeItem.CommonProperties = configInDefaultMode;
            //btInDefaultModeItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(btInDefaultModeItem);

            ////出厂状态检查
            //if (true)
            //{
            //    TaskItem taskItem = new TaskItem();
            //    taskItem.Enable = true;
            //    taskItem.Item = "出厂状态检查";//Write BT MAC
            //    AtCommandProperties atCommandProperties = new AtCommandProperties();
            //    atCommandProperties.AtCommand = "AT+GETINFO";

            //    atCommandProperties.AtCommandOk = "GET INFO OK";
            //    atCommandProperties.AtCommandError = "ERROR";
            //    atCommandProperties.CheckInfo = new string[] { "FACOUT:1" };

            //    atCommandProperties.AtCommandInterval = 1000;

            //    taskItem.CommonProperties = atCommandProperties;
            //    taskItem.Executer = new AtCommandExecuter();
            //    taskItemManager.Put(taskItem);
            //}


            //#endregion


            ////关闭BT UART
            ////TaskItem closeBTUartItem = new TaskItem();
            ////closeBTUartItem.Enable = true;
            ////closeBTUartItem.Item = "Close BT Uart";
            ////closeBTUartItem.Executer = new ClosePhoneExecutor();
            ////closeBTUartItem.CommonProperties = new CommonProperties()
            ////{
            ////    ExecuteCondition = ExecuteCondition.ALWAYS,
            ////    RetryCount = 0,
            ////};
            ////taskItemManager.Put(closeBTUartItem);
            //taskItemManager.Put(closePhoneItem);


            ////LOG MAC CHANGE TO BT MAC
            //TaskItem logMacChangeToBtMacItem = new TaskItem();
            //logMacChangeToBtMacItem.Enable = true;
            //logMacChangeToBtMacItem.Item = "LOG MAC为BT MAC";//LOG MAC CHANGE TO BT MAC
            //logMacChangeToBtMacItem.CommonProperties = new LogMacChangeToBtMacProperties()
            //{
            //    RetryCount = 0,
            //    ExecuteCondition = ExecuteCondition.ALWAYS,
            //};
            //logMacChangeToBtMacItem.Executer = new LogMacChangeToBtMacExecuter();
            //taskItemManager.Put(logMacChangeToBtMacItem);


            ////TaskItem writeImeiItem = new TaskItem();
            ////writeImeiItem.Enable = true;
            ////writeImeiItem.Item = "Write Imei";
            ////AtCommandProperties configWriteBtMac = new AtCommandProperties();
            ////configWriteBtMac.AtCommand = "AT^IMEI={IMEI}";
            ////configWriteBtMac.AtCommandOk = "OK";
            ////configWriteBtMac.AtCommandError = "ERROR";
            ////configWriteBtMac.AtCommandInterval = 100;
            ////writeImeiItem.CommonProperties = configWriteBtMac;
            ////writeImeiItem.Executer = new AtCommandExecuter();
            ////taskItemManager.Put(writeImeiItem);


            ////标签打印
            //if (true)
            //{
            //    PrintLabelProperties printLabelProperties = new PrintLabelProperties()
            //    {
            //        RetryCount = 0,
            //        Timeout = 8000,
            //        SleepTimeAfter = 5000,
            //    };
            //    taskItemManager.AppendPrintLabel(printLabelProperties);
            //}


            //StringBuilder jtsFileName = new StringBuilder();
            //jtsFileName.Append("Hi3861Check");

            string jtsFileName = "Hi3861Check";

            taskItemManager.Save2Jts(this, 1, jtsFileName);

            //jtsFileName.Append(".jts");
            //JtsUtils.SaveJsonFile(jtsFileName.ToString(), taskItemList);

            Box.ShowInfoOk(jtsFileName + "\r\n成功");


            //OpenPhoneExecutor
            //OpenPhoneProperties

            //    AtCommandExecuter
            //    AtCommandProperties

            //    ClosePhoneExecutor
        }
예제 #6
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            SKGProperties config     = properties as SKGProperties;
            List <ComDut> comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }



            //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            List <OpenPhoneProperties> configList      = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>;
            OpenPhoneProperties        configOpenPhone = null;

            foreach (var item in configList)
            {
                if (item.PortName == config.PortName)
                {
                    configOpenPhone = item;
                    break;
                }
            }
            if (configOpenPhone == null)
            {
                throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName));
            }

            log      = globalDic[typeof(ILog).ToString()] as ILog;
            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            comDut.Parity = configOpenPhone.Parity;
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            byte[] atCommand = strToToHexByte(config.AtCommand);
            //string atCommand = PreTranslateAtCommand(config.AtCommand);
            UartDisplay(atCommand, "T");

            //log.Info("AT Commond=" + config.AtCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand, 0, atCommand.Length);
            Thread.Sleep(config.AtCommandInterval);

            #region
            //DateTime start = DateTime.Now;
            //DateTime now = DateTime.Now;
            //TimeSpan timeSpan = now - start;
            //while (timeSpan.TotalMilliseconds <= config.Timeout)
            //{
            //    try
            //    {
            //        comDut.Write(atCommand, 0, atCommand.Length);
            //        Thread.Sleep(config.AtCommandInterval);

            //        int n = comDut.BytesToRead;
            //        byte[] buf = new byte[n];
            //        comDut.Read(buf, 0, n);
            //        //解析是否收到正确的包,包头,命令,校验位

            //        //如果收到的包正确
            //        if (true)
            //        {
            //            break;
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e);
            //    }

            //    Thread.Sleep(100);
            //    now = DateTime.Now;
            //    timeSpan = now - start;
            //}

            //if (timeSpan.TotalMilliseconds > config.Timeout)
            //{
            //    throw new BaseException("超时:");
            //}
            #endregion
            //发命令后一直循环接收->检验->拼接,超过500ms还没检验通过则超时FAIL
            TimeUtils.Execute(() =>
            {
                int n = comDut.BytesToRead;
                //if (n==0)
                //{
                //    //继续循环执行
                //    return false;
                //}
                log.Info(string.Format("接收的长度:{0}", n));
                if (n > 0)
                {
                    byte[] buf = new byte[n];
                    comDut.Read(buf, 0, n);
                    UartDisplay(buf, "R");

                    buffer.Clear();
                    buffer.AddRange(buf);
                }

                //byte[] buf = new byte[n];
                //comDut.Read(buf, 0, n);
                //buffer.AddRange(buf);

                if (buffer.Count > 9)
                {
                    if (buffer[0] == 0xA5)
                    {
                        //throw new BaseException(string.Format("Head Error"));
                        //if (&& buf[1] == 0xC3))
                        //{

                        //}
                        if (buffer[1] == 0xC3)
                        {
                            byte high        = buffer[2];
                            byte low         = buffer[3];
                            int iTotalLength = (high & 0xFF) << 8 | low;

                            if (buffer.Count < iTotalLength) //数据区尚未接收完整
                            {
                                //继续循环执行
                                log.Info(string.Format("数据尚未接收完整,已接收:{0},总长度:{1}", buffer.Count, iTotalLength));
                                return(false);
                            }
                            byte[] oneFrameBytes = new byte[iTotalLength];
                            buffer.CopyTo(0, oneFrameBytes, 0, iTotalLength);
                            buffer.RemoveRange(0, iTotalLength);

                            UartDisplay(oneFrameBytes, "R");

                            #region //开始校验-命令字
                            if (config.CommandType == SKGProperties.EnumCommandType.查询指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x37))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGProperties.EnumCommandType.控制指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x40))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGProperties.EnumCommandType.发授权)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x23))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else
                            {
                                log.Info(string.Format("非法指令类型"));
                                //继续循环执行
                                return(false);
                            }

                            //异或校验 1字节
                            byte[] bufOutOxr = new byte[oneFrameBytes.Length - 1];
                            Array.Copy(oneFrameBytes, 0, bufOutOxr, 0, oneFrameBytes.Length - 1);
                            byte xor = ByteToXOR(bufOutOxr);

                            if (oneFrameBytes[iTotalLength - 1] != xor)
                            {
                                log.Info(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));
                                //继续循环执行
                                return(false);
                            }
                            log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));

                            //数据内容 32个字节——长度是不固定的
                            byte[] dataArry = new byte[iTotalLength - 9];                //config.DataLength
                            Array.Copy(oneFrameBytes, 8, dataArry, 0, iTotalLength - 9); //config.DataLength

                            //添加到全局变量中
                            if (config.GlobalVariblesKey != null)
                            {
                                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                                {
                                    Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                                    if (!matchKey.Success)
                                    {
                                        throw new BaseException("read info key fail");
                                    }

                                    string key = matchKey.Groups[1].ToString();

                                    configGv.Add(key, dataArry);
                                    log.Info("应答报文格式检查PASS");
                                }
                            }

                            //跳出循环执行
                            return(true);

                            #endregion
                        }
                        else
                        {
                            log.Info(string.Format("头部不是0xA5,0xC3,buffer.RemoveAt:{0:X2},{1:X2}", buffer[0], buffer[1]));

                            buffer.RemoveRange(0, 2);
                            //继续循环执行
                            return(false);
                        }
                    }
                    else
                    {
                        log.Info(string.Format("头部不是0xA5,buffer.RemoveAt:{0:X2}", buffer[0]));
                        buffer.RemoveAt(0);
                        //继续循环执行
                        return(false);
                    }
                }
                else
                {
                    //继续循环执行
                    log.Info(string.Format("buffer.Count:{0}小于最小长度9", buffer.Count));

                    return(false);
                }
            }, config.Timeout);

            //int n = comDut.BytesToRead;
            //byte[] buf = new byte[n];
            //comDut.Read(buf, 0, n);
            #region
            ////1.缓存数据
            //buffer.AddRange(buf);

            //if (!flagCmdHandle)
            //{
            //    //如果接受到的上一帧数据未处理,软件只接受数据进buffer,不提取指令
            //    return;
            //}

            //2.完整性判断
            //while (buffer.Count >= 9) //至少包含帧头(2字节)、长度(1字节)、校验位(1字节);根据设计不同而不同
            //{
            //    //2.1 查找数据头
            //    if (buffer[0] == 0xAA) //传输数据有帧头1,用于判断
            //    {
            //        //if (buffer[1] == 0xFF) //传输数据有帧头2,用于判断
            //        //{
            //        int iDataLength = buffer[1];

            //        int iTotalLength = iDataLength + 1;//前两个与最后一个

            //        int cnt = 0;
            //        //for (int i = 0; i < buffer.Count; i++)
            //        //{
            //        //    if (buffer[i] == 0x55 && buffer[i - 1] == 0xFF)
            //        //    {
            //        //        cnt++;
            //        //    }
            //        //}

            //        //if (buffer.Count>)
            //        //{

            //        //}

            //        if (buffer.Count < iTotalLength + cnt) //数据区尚未接收完整
            //        {
            //            break;
            //        }

            //        //得到完整的数据,复制到rawBytes中进行校验

            //        iTotalLength = buffer.Count;

            //        byte[] rawBytes = new byte[iTotalLength];
            //        buffer.CopyTo(0, rawBytes, 0, iTotalLength);
            //        buffer.Clear();

            //        //if (buffer[10] == 0x01)
            //        //{

            //        //    byte[] rawBytes = { 0xFF, 0xFF, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA5, 0x01, 0x04, 0x09, 0xE0, 0xB6, 0xF5, 0x18, 0x8D, 0x40, 0x13, 0x78, 0x0D, 0xE4, 0xDE, 0xE1, 0x15, 0x96, 0x4A, 0x3E, 0xDC, 0x1C, 0xE1, 0xAA, 0xFF, 0x55, 0x85, 0xDB, 0xC6, 0xFD, 0x76, 0x32, 0x39, 0x6F, 0x8E, 0x67, 0xFA };
            //        //}

            //        byte checksum = 0; //开始校验

            //        //if (rawBytes[rawBytes.Length - 1] == 0x55 && rawBytes[rawBytes.Length - 2] == 0xFF)
            //        //{
            //        //    for (int i = 2; i < rawBytes.Length - 2; i++)
            //        //    {
            //        //        checksum += rawBytes[i];
            //        //    }

            //        //    if (checksum != rawBytes[rawBytes.Length - 2]) //校验失败,最后一个字节是校验位
            //        //    {
            //        //        UartDisplay("Rx Error\r\n");
            //        //        continue;
            //        //    }
            //        //}
            //        //else
            //        //{
            //        for (int i = 1; i < rawBytes.Length - 1; i++)
            //        {
            //            checksum += rawBytes[i];
            //        }
            //        checksum = (byte)~checksum;
            //        checksum += 0x01;
            //        if (checksum != rawBytes[rawBytes.Length - 1]) //校验失败,最后一个字节是校验位
            //        {
            //            UartDisplay("Rx Error\r\n");
            //            continue;
            //        }
            //        //}

            //        UartDisplay(rawBytes, "R");


            //        //ReceiveBytes = new byte[rawBytes.Length];
            //        //rawBytes.CopyTo(ReceiveBytes, 0);
            //        flagCmdHandle = false;
            //        RecCmd_AC(rawBytes);
            //        //}
            //        rawBytes = null;
            //        flagCmdHandle = true;
            //    }
            //    else //帧头1不正确时,记得清除
            //    {
            //        buffer.RemoveAt(0);
            //    }
            //}
            #endregion

            #region
            ////解析是否收到正确的包,包头,命令,校验位
            ////起始标志 数据长度 保留字     命令字     数据内容    异或校验码
            ////0XA5C3    9+N     0x0000      0x0037      Data        异或
            ////2 字节  2 字节    2 字节      2 字节      N 字节     1 字节
            //UartDisplay(buf,"R");
            //if (buf.Length < 9)
            //{
            //    throw new BaseException(string.Format("Length Not enough"));
            //}
            ////包头
            //if (!(buf[0]==0xA5 && buf[1]==0xC3))
            //{
            //    throw new BaseException(string.Format("Head Error"));
            //}
            ////长度 2字节
            //byte high = buf[2];
            //byte low = buf[3];
            //int iTotalLength = (high & 0xFF) << 8 | low;

            //if (iTotalLength != n)
            //{
            //    throw new BaseException(string.Format("Length Error,长度位:{0},实际长度:{1}", iTotalLength,n));
            //}

            ////命令字
            //if (config.CommandType==SKGProperties.EnumCommandType.查询指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x37))
            //    {
            //        throw new BaseException(string.Format("CMD Type Error"));
            //    }
            //}
            //else if(config.CommandType == SKGProperties.EnumCommandType.控制指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x40))
            //    {
            //        throw new BaseException(string.Format("CMD Type Error"));
            //    }
            //}
            //else if(config.CommandType == SKGProperties.EnumCommandType.下发授权)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x23))
            //    {
            //        throw new BaseException(string.Format("CMD Type Error"));
            //    }
            //}
            //else
            //{
            //    throw new BaseException(string.Format("非法指令类型"));
            //}


            ////异或校验 1字节
            //byte[] bufOutOxr = new byte[buf.Length - 1];
            //Array.Copy(buf, 0, bufOutOxr, 0, buf.Length - 1);
            //byte xor = ByteToXOR(bufOutOxr);

            //if (buf[n-1] != xor)
            //{
            //    throw new BaseException(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));
            //}
            //log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));



            ////数据内容 32个字节——长度是不固定的
            //byte[] dataArry = new byte[iTotalLength-9];//config.DataLength
            //Array.Copy(buf, 8, dataArry, 0, iTotalLength - 9);//config.DataLength

            ////添加到全局变量中
            //if (config.GlobalVariblesKey != null)
            //{
            //    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //    {
            //        //string pattern = "-([0-9]{2}) ";
            //        //Match matchValue = Regex.Match(response, pattern);
            //        //if (!matchValue.Success)
            //        //{
            //        //    throw new BaseException("read info value fail");
            //        //}

            //        //string value = matchValue.Groups[1].ToString();

            //        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //        if (!matchKey.Success)
            //        {
            //            throw new BaseException("read info key fail");
            //        }

            //        string key = matchKey.Groups[1].ToString();

            //        configGv.Add(key, dataArry);
            //        log.Info("应答报文格式检查PASS");
            //    }
            //}
            #endregion


            ////如果收到的包正确
            //string str = byteToHexStr(buf);


            //string response = comDut.ReadExisting();
            //comDut.DtrEnable = false;
            //comDut.RtsEnable = false;

            //log.Info("AT Response=" + response);

            //if (!string.IsNullOrEmpty(config.AtCommandError))
            //{
            //    if (response.Contains(config.AtCommandError))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
            //    }
            //}

            //if (!string.IsNullOrEmpty(config.AtCommandOk))
            //{
            //    if (!response.Contains(config.AtCommandOk))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
            //    }
            //}

            //if (config.CheckInfo != null)
            //{
            //    for (int i = 0; i < config.CheckInfo.Length; i++)
            //    {
            //        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
            //        {
            //            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
            //            if (!response.Contains(checkInfo))
            //            {
            //                throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
            //            }
            //        }
            //    }
            //}

            //if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
            //{
            //    if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length)
            //    {
            //        throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在");
            //    }
            //    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //    {
            //        string pattern = "-([0-9]{2}) ";
            //        Match matchValue = Regex.Match(response, pattern);
            //        if (!matchValue.Success)
            //        {
            //            throw new BaseException("read info value fail");
            //        }

            //        string value = matchValue.Groups[1].ToString();

            //        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //        if (!matchKey.Success)
            //        {
            //            throw new BaseException("read info key fail");
            //        }

            //        string key = matchKey.Groups[1].ToString();

            //        configGv.Add(key, value);
            //    }
            //}
        }
예제 #7
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            GetBtRssiAtCommandProperties config = properties as GetBtRssiAtCommandProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            string moudleBtMac = configGv.Get("MoudleBtMac");
            string endLine     = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!response.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            {
                string pattern = Parse_r_n(config.GlobalVariblesKeyPattern);//"E000E64CCACE:RSSI:([0-9-]{3,4})[:]"     E000E64CCACE:RSSI:-052:
                pattern = moudleBtMac + pattern;
                Match matchValue = Regex.Match(response, pattern);
                if (!matchValue.Success)
                {
                    throw new BaseException("read info value fail");
                }

                string value = matchValue.Groups[1].ToString();

                Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);
                if (!matchKey.Success)
                {
                    throw new BaseException("read info key fail");
                }

                string key = matchKey.Groups[1].ToString();

                configGv.Add(key, value);
            }
        }
예제 #8
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            GetLicenseProperties config = properties as GetLicenseProperties;

            ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            SerialPort comlog = new SerialPort();

            comlog.PortName = config.PortName;
            comlog.DataBits = 8;
            comlog.StopBits = StopBits.One;
            comlog.Parity   = Parity.None;
            comlog.BaudRate = config.BaudRate;
            //comlog.DtrEnable = config.Dtr;
            //comlog.RtsEnable = config.Rts;
            comlog.Open();

            //string moudleBtMac = configGv.Get("MAC_BT");
            string endLine = config.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string atCommand = PreTranslateAtCommand(config.AtCommand);

            log.Info("AT Commond=" + atCommand);

            comDut.Write(atCommand + endLine);
            Thread.Sleep(config.AtCommandInterval);
            string response = comDut.ReadExisting();

            comDut.DtrEnable = false;
            comDut.RtsEnable = false;

            log.Info("AT Response=" + response);

            if (!string.IsNullOrEmpty(config.AtCommandError))
            {
                if (response.Contains(config.AtCommandError))
                {
                    throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
                }
            }

            if (!string.IsNullOrEmpty(config.AtCommandOk))
            {
                if (!response.Contains(config.AtCommandOk))
                {
                    throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
                }
            }

            //log口获取接收
            string responseLog = comlog.ReadExisting();

            if (config.IsToUpper)
            {
                responseLog = responseLog.ToUpper();
            }
            responseLog = responseLog.Replace("\r\n", "");

            if (config.CheckInfo != null)
            {
                for (int i = 0; i < config.CheckInfo.Length; i++)
                {
                    if (!string.IsNullOrEmpty(config.CheckInfo[i]))
                    {
                        string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
                        if (!responseLog.Contains(checkInfo))
                        {
                            throw new BaseException(string.Format("responseLog =\r\n{0} \r\n不包含License文件:\r\n{1}", responseLog, checkInfo));
                        }
                    }
                }
            }
            log.Info("LOG Response:\r\n" + responseLog);

            if (comlog.IsOpen)
            {
                comlog.Close();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ParseLabelProperties properties = new ParseLabelProperties()
            {
                ImeiLocation = 1,
                SnLocation   = 2,
            };
            TaskItemManager taskItemManager = new TaskItemManager(properties);

            taskItemManager.MesPreCheckProperties.EnableCheckMac = true;
            taskItemManager.TaskItemParseLabel.Enable            = true;
            //生成log
            taskItemManager.DeinitProperties.LogType = LogType.MAC;


            //打开WIFI UART
            OpenPhoneProperties configOpenWifiUart = new OpenPhoneProperties();

            configOpenWifiUart.PortName              = "COM18";
            configOpenWifiUart.BaudRate              = 115200;
            configOpenWifiUart.Dtr                   = true;
            configOpenWifiUart.Rts                   = true;
            configOpenWifiUart.EndLine               = "\\r\\n";
            configOpenWifiUart.Timeout               = 10 * 1000;
            configOpenWifiUart.RetryCount            = 0;
            configOpenWifiUart.AtType                = AtType.Manual;
            configOpenWifiUart.SleepTimeAfterFindDut = 1000;
            TaskItem openWifiUartItem = new TaskItem();

            openWifiUartItem.Enable           = true;
            openWifiUartItem.Item             = "打开WIFI串口";//Open Wifi Uart
            openWifiUartItem.CommonProperties = configOpenWifiUart;
            openWifiUartItem.Executer         = new OpenPhoneExecutor();
            taskItemManager.Put(openWifiUartItem);

            //发现设备
            TaskItem findDevice = new TaskItem();

            findDevice.Enable           = true;
            findDevice.Item             = "发现设备";//Find Device
            findDevice.CommonProperties = new FindDeviceProperties()
            {
                TestPowerOnAT     = "",
                AtCommandInterval = 1000,
                EndLine           = "\r\n",
                AtCommandOk       = "WIFI initialized",
                Timeout           = 10 * 1000,
                RetryCount        = 0,
                SleepTimeBefore   = 200,
            };
            findDevice.Executer = new FindDeviceExecuter();
            taskItemManager.Put(findDevice);

            //关闭WIFI UART
            TaskItem closeWifiUartItem = new TaskItem();

            closeWifiUartItem.Enable           = true;
            closeWifiUartItem.Item             = "关闭WIFI串口";//Close WIFI Uart
            closeWifiUartItem.Executer         = new ClosePhoneExecutor();
            closeWifiUartItem.CommonProperties = new CommonProperties()
            {
                ExecuteCondition = ExecuteCondition.ALWAYS,
                RetryCount       = 0,
            };
            taskItemManager.Put(closeWifiUartItem);

            //打开BT
            OpenPhoneProperties configOpenPhone = new OpenPhoneProperties();

            configOpenPhone.PortName              = "COM17";
            configOpenPhone.BaudRate              = 2400;
            configOpenPhone.Dtr                   = true;
            configOpenPhone.Rts                   = true;
            configOpenPhone.EndLine               = "\\r\\n";
            configOpenPhone.Timeout               = 10 * 1000;
            configOpenPhone.RetryCount            = 0;
            configOpenPhone.AtType                = AtType.Manual;
            configOpenPhone.SleepTimeAfterFindDut = 1000;
            TaskItem openPhoneItem = new TaskItem();

            openPhoneItem.Enable           = true;
            openPhoneItem.Item             = "打开BT串口";//Open BT Uart
            openPhoneItem.CommonProperties = configOpenPhone;
            openPhoneItem.Executer         = new OpenPhoneExecutor();
            taskItemManager.Put(openPhoneItem);

            //读BT MAC,若读到则放到 MAC_BT中即可,后续fetch sn将自动+1,而不是取。若未读到,则info一下即可
            if (true)
            {
                TaskItem isitWrittenMac = new TaskItem();
                isitWrittenMac.Enable           = true;
                isitWrittenMac.Item             = "BT MAC预读";//Check BT MAC
                isitWrittenMac.CommonProperties = new IsitWrittenToTheBtMacProperties()
                {
                    ResultType   = AILinkFactoryAuto.Task.SmartBracelet.Property.IsitWrittenToTheBtMacProperties.GetBtMacRetType.ThrowExcption,
                    ImesPreCheck = true,

                    Timeout    = 3 * 1000,
                    RetryCount = 0,

                    AtCommand      = "AT+GETBLEMAC",
                    AtCommandError = "ERROR",

                    GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})",
                    GlobalVariblesKey        = "{MAC_BT}",

                    AtCommandInterval = 1000,
                    SleepTimeBefore   = 1500,
                };

                isitWrittenMac.Executer = new IsitWrittenToTheBtMacExecuter();
                taskItemManager.Put(isitWrittenMac);
            }


            //写BT 固件
            TaskItem writeBtBin = new TaskItem();

            writeBtBin.Enable           = true;
            writeBtBin.Item             = "写BT固件";//Write BT Bin
            writeBtBin.CommonProperties = new WriteBtBinProperties()
            {
                EraseCmd           = "nrfjprog.exe --eraseall -f NRF52",
                ProgramCmd         = "nrfjprog.exe --program {0} --verify -f NRF52",
                BinFileFullPath    = " ./bin/whole.hex",
                ResetCmd           = "nrfjprog.exe --reset -f NRF52",
                CmdCommandInterval = 500,

                Timeout         = 10 * 1000,
                RetryCount      = 0,
                SleepTimeBefore = 100,
            };
            writeBtBin.Executer = new WriteBtBinExecuter();
            taskItemManager.Put(writeBtBin);

            //BT版本号检查
            if (true)
            {
                TaskItem checkBtVersionItem = new TaskItem();
                checkBtVersionItem.Enable = true;
                checkBtVersionItem.Item   = "BLE固件版本号检查";//Write BT MAC
                AtCommandProperties checkBtVersionProperties = new AtCommandProperties();
                checkBtVersionProperties.AtCommand = "AT+GETINFO";

                checkBtVersionProperties.AtCommandOk    = "GET INFO OK";
                checkBtVersionProperties.AtCommandError = "ERROR";
                checkBtVersionProperties.CheckInfo      = new string[] { "AI_WRIST_V1.15", "Apr  9 2020 18:58:47" };

                checkBtVersionProperties.AtCommandInterval = 1000;
                checkBtVersionProperties.SleepTimeBefore   = 800;

                checkBtVersionItem.CommonProperties = checkBtVersionProperties;
                checkBtVersionItem.Executer         = new AtCommandExecuter();
                taskItemManager.Put(checkBtVersionItem);
            }

            ////读BT MAC,判断是否要取号
            //if (true)
            //{
            //    //读BT MAC
            //    TaskItem getBTMacItem = new TaskItem();
            //    getBTMacItem.Enable = true;
            //    getBTMacItem.Item = "读BT MAC";//GET BT MAC
            //    AtCommandProperties configGetBtMac = new AtCommandProperties();
            //    configGetBtMac.AtCommand = "AT+GETBLEMAC";

            //    configGetBtMac.AtCommandOk = "OK";
            //    configGetBtMac.AtCommandError = "ERROR";

            //    configGetBtMac.GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})";//KBLE MAC:112233445566OK
            //    configGetBtMac.GlobalVariblesKey = "{MoudleBtMac}";

            //    configGetBtMac.AtCommandInterval = 800;
            //    configGetBtMac.SleepTimeBefore = 800;
            //    getBTMacItem.CommonProperties = configGetBtMac;
            //    getBTMacItem.Executer = new AtCommandExecuter();
            //    taskItemManager.Put(getBTMacItem);
            //}

            //判断是否要取号,不取则+1赋值,并通知不从imes取号
            //if (true)
            //{
            //    TaskItem isFetchMac = new TaskItem();
            //    isFetchMac.Enable = true;
            //    isFetchMac.Item = "取MAC号方式自动判断";//Check BT MAC
            //    isFetchMac.CommonProperties = new AccessToMacProperties()
            //    {
            //        Timeout = 3 * 1000,
            //        RetryCount = 0,

            //        AtCommand = "AT+GETBLEMAC",
            //        AtCommandError = "ERROR",

            //        GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})",
            //        GlobalVariblesKey = "{MoudleBtMac}",

            //        AtCommandInterval = 800,
            //        SleepTimeBefore = 800,
            //    };

            //    isFetchMac.Executer = new AccessToMacExecuter();
            //    taskItemManager.Put(isFetchMac);
            //}

            //从IMES取wifi MAC,bt mac会自动放入全局变量
            if (true)
            {
                MesFetchSnProperties mesFetchSnProperties = new MesFetchSnProperties();
                mesFetchSnProperties.RetryCount = 0;
                mesFetchSnProperties.IsNeedInc1 = true;
                taskItemManager.AppendMesFetchSn(mesFetchSnProperties);
            }


            //写BT MAC
            TaskItem writeBTMacItem = new TaskItem();

            writeBTMacItem.Enable = true;
            writeBTMacItem.Item   = "写BT MAC";//Write BT MAC
            AtCommandProperties configWriteBtMac = new AtCommandProperties();

            configWriteBtMac.AtCommand = "AT+SETBLEMAC={MAC_BT}";

            configWriteBtMac.AtCommandOk       = "reboot system";
            configWriteBtMac.AtCommandError    = "ERROR";
            configWriteBtMac.AtCommandInterval = 800;
            configWriteBtMac.SleepTimeBefore   = 3000;
            writeBTMacItem.CommonProperties    = configWriteBtMac;
            writeBTMacItem.Executer            = new AtCommandExecuter();
            taskItemManager.Put(writeBTMacItem);

            //读BT MAC
            if (true)
            {
                TaskItem getBTMacItem = new TaskItem();
                getBTMacItem.Enable = true;
                getBTMacItem.Item   = "读BT MAC";//GET BT MAC
                AtCommandProperties configGetBtMac = new AtCommandProperties();
                configGetBtMac.AtCommand = "AT+GETBLEMAC";

                configGetBtMac.AtCommandOk    = "OK";
                configGetBtMac.AtCommandError = "ERROR";

                configGetBtMac.GlobalVariblesKeyPattern = "BLE MAC:([0-9A-F]{12})";//KBLE MAC:112233445566OK
                configGetBtMac.GlobalVariblesKey        = "{MoudleBtMac}";

                configGetBtMac.AtCommandInterval = 800;
                getBTMacItem.CommonProperties    = configGetBtMac;
                getBTMacItem.Executer            = new AtCommandExecuter();
                taskItemManager.Put(getBTMacItem);
            }
            //生成BT MAC二维码
            if (true)
            {
                TaskItem showBtMacQrCodeItem = new TaskItem();
                showBtMacQrCodeItem.Enable           = true;
                showBtMacQrCodeItem.Item             = "展示BT MAC二维码";//Check BT RSSI
                showBtMacQrCodeItem.CommonProperties = new ShowBtMacQrCodeProperties()
                {
                    RetryCount = 3,
                    StrQrcode  = "http://www.baidu.com",
                    ShowTime   = 8000,
                };
                showBtMacQrCodeItem.Executer = new ShowBtMacQrCodeExecuter();
                taskItemManager.Put(showBtMacQrCodeItem);
            }

            //校验BT MAC
            //************待补充:来自IMES的BtMac应存在全局变量中*************
            TaskItem checkBtMac = new TaskItem();

            checkBtMac.Enable           = true;
            checkBtMac.Item             = "校验BT MAC";//Check BT MAC
            checkBtMac.CommonProperties = new CheckBtMacProperties()
            {
                Timeout    = 3 * 1000,
                RetryCount = 0,
            };
            checkBtMac.Executer = new CheckBtMacExecuter();
            taskItemManager.Put(checkBtMac);

            //设置BT FACMODE
            TaskItem setBtFacModeItem = new TaskItem();

            setBtFacModeItem.Enable = true;
            setBtFacModeItem.Item   = "设置BT 进入工厂模式";//Set Bt FactoryMode
            AtCommandProperties configSetBtFacMode = new AtCommandProperties();

            configSetBtFacMode.AtCommand = "AT+SETFACMODE=1";

            configSetBtFacMode.AtCommandOk       = "OK";
            configSetBtFacMode.AtCommandError    = "ERROR";
            configSetBtFacMode.AtCommandInterval = 800;
            configSetBtFacMode.SleepTimeAfter    = 7000;
            setBtFacModeItem.CommonProperties    = configSetBtFacMode;
            setBtFacModeItem.Executer            = new AtCommandExecuter();
            taskItemManager.Put(setBtFacModeItem);
            //BT串口发WIFI 软断电电指令
            TaskItem wifiPowerOff = new TaskItem();

            wifiPowerOff.Enable = true;
            wifiPowerOff.Item   = "Wifi 断电";//Wifi PowerOff
            AtCommandProperties configWifiPowerOff = new AtCommandProperties();

            configWifiPowerOff.AtCommand = "AT+SETGPSWIFIPWR=0";

            configWifiPowerOff.AtCommandOk       = "OK";
            configWifiPowerOff.AtCommandError    = "ERROR";
            configWifiPowerOff.CheckInfo         = new string[] { "wifi power off" };
            configWifiPowerOff.AtCommandInterval = 3000;
            //configWifiPowerOff.SleepTimeBefore = 6000;
            configWifiPowerOff.Timeout    = 12000;
            configWifiPowerOff.RetryCount = 3;
            wifiPowerOff.CommonProperties = configWifiPowerOff;
            wifiPowerOff.Executer         = new AtCommandExecuter();
            taskItemManager.Put(wifiPowerOff);

            //BT串口发WIFI 软上电指令
            TaskItem wifiPowerOn = new TaskItem();

            wifiPowerOn.Enable = true;
            wifiPowerOn.Item   = "Wifi 上电";//Wifi PowerOn
            AtCommandProperties configWifiPowerOn = new AtCommandProperties();

            configWifiPowerOn.AtCommand = "AT+SETGPSWIFIPWR=1";

            configWifiPowerOn.AtCommandOk       = "OK";
            configWifiPowerOn.AtCommandError    = "ERROR";
            configWifiPowerOn.CheckInfo         = new string[] { "wifi power on" };
            configWifiPowerOn.AtCommandInterval = 2000;
            configWifiPowerOn.Timeout           = 3000;
            configWifiPowerOff.RetryCount       = 3;
            wifiPowerOn.CommonProperties        = configWifiPowerOn;
            wifiPowerOn.Executer = new AtCommandExecuter();
            taskItemManager.Put(wifiPowerOn);

            //BT发检查BT广播命令
            TaskItem btBroadcastItem = new TaskItem();

            btBroadcastItem.Enable = true;
            btBroadcastItem.Item   = "BT 开始广播";//BT Broadcast
            AtCommandProperties configBtBroadcast = new AtCommandProperties();

            configBtBroadcast.AtCommand = "AT+OPENBLEADV";

            configBtBroadcast.AtCommandOk       = "OK";
            configBtBroadcast.AtCommandError    = "ERROR";
            configBtBroadcast.AtCommandInterval = 600;
            configBtBroadcast.Timeout           = 2000;
            configBtBroadcast.RetryCount        = 3;
            btBroadcastItem.CommonProperties    = configBtBroadcast;
            btBroadcastItem.Executer            = new AtCommandExecuter();
            taskItemManager.Put(btBroadcastItem);

            //关闭BT UART
            TaskItem closePhoneItem = new TaskItem();

            closePhoneItem.Enable           = true;
            closePhoneItem.Item             = "关闭BT 串口";//Close BT Uart
            closePhoneItem.Executer         = new ClosePhoneExecutor();
            closePhoneItem.CommonProperties = new CommonProperties()
            {
                ExecuteCondition = ExecuteCondition.ALWAYS,
                RetryCount       = 0,
            };
            taskItemManager.Put(closePhoneItem);

            #region BT扫描工具
            //打开蓝牙扫描工具 UART
            OpenPhoneProperties configOpentToolUart = new OpenPhoneProperties();
            configOpentToolUart.PortName              = "COM21";
            configOpentToolUart.BaudRate              = 115200;
            configOpentToolUart.Dtr                   = true;
            configOpentToolUart.Rts                   = true;
            configOpentToolUart.EndLine               = "\\r\\n";
            configOpentToolUart.Timeout               = 10 * 1000;
            configOpentToolUart.RetryCount            = 0;
            configOpentToolUart.AtType                = AtType.Manual;
            configOpentToolUart.SleepTimeAfterFindDut = 1000;
            TaskItem configOpentToolUartTtem = new TaskItem();
            configOpentToolUartTtem.Enable           = true;
            configOpentToolUartTtem.Item             = "打开蓝牙扫描工具的串口";//Open Scan Tool Uart
            configOpentToolUartTtem.CommonProperties = configOpentToolUart;
            configOpentToolUartTtem.Executer         = new OpenPhoneExecutor();
            taskItemManager.Put(configOpentToolUartTtem);

            //发送开始扫描命令并获取BT RSSI
            TaskItem getBtRssiItem = new TaskItem();
            getBtRssiItem.Enable = true;
            getBtRssiItem.Item   = "开始扫描BT广播包并获取BT RSSI";                                         //Satrt Scan And Get BT RSSI
            GetBtRssiAtCommandProperties configGetBtRssiPro = new GetBtRssiAtCommandProperties(); //GetBtRssiAtCommandProperties
            configGetBtRssiPro.AtCommand = "AT+INQ";

            configGetBtRssiPro.AtCommandOk    = "OK";
            configGetBtRssiPro.AtCommandError = "ERROR";
            configGetBtRssiPro.CheckInfo      = new string[] { "INQS" };
            //********************************************正则表达式中存在变量的情况:该产品的蓝牙MAC后的值*****************************************
            configGetBtRssiPro.GlobalVariblesKeyPattern = ":RSSI:([0-9-]{3,4})[:]";//"BLE MAC->([0-9A-F:]{17})";
            configGetBtRssiPro.GlobalVariblesKey        = "{MoudleBtRssi}";

            configGetBtRssiPro.AtCommandInterval = 7000;
            configGetBtRssiPro.Timeout           = 7000;
            configGetBtRssiPro.RetryCount        = 2;
            getBtRssiItem.CommonProperties       = configGetBtRssiPro;
            getBtRssiItem.Executer = new GetBtRssiAtCommandExecuter();//GetBtRssiAtCommandExecuter
            taskItemManager.Put(getBtRssiItem);

            //检查BT RSSI
            if (true)
            {
                TaskItem checkBtRssiItem = new TaskItem();
                checkBtRssiItem.Enable           = true;
                checkBtRssiItem.Item             = "检查BT RSSI";//Check BT RSSI
                checkBtRssiItem.CommonProperties = new CheckBtRssiProperties()
                {
                    MaxValue   = -10,
                    MinValue   = -90,
                    Timeout    = 2 * 1000,
                    RetryCount = 0,
                };
                checkBtRssiItem.Executer = new CheckBtRssiExecuter();
                taskItemManager.Put(checkBtRssiItem);
            }

            //停止扫描
            TaskItem stopScanBtRssiItem = new TaskItem();
            stopScanBtRssiItem.Enable = true;
            stopScanBtRssiItem.Item   = "停止扫描";//Stop Scan BT RSSI
            AtCommandProperties configStopScanBtRssiPro = new AtCommandProperties();
            configStopScanBtRssiPro.AtCommand = "AT+SINQ";

            configStopScanBtRssiPro.AtCommandOk      = "INQE";
            configStopScanBtRssiPro.AtCommandError   = "ERROR";
            configStopScanBtRssiPro.ExecuteCondition = ExecuteCondition.ALWAYS;

            configStopScanBtRssiPro.AtCommandInterval = 800;
            configStopScanBtRssiPro.Timeout           = 2000;
            configStopScanBtRssiPro.RetryCount        = 0;
            stopScanBtRssiItem.CommonProperties       = configStopScanBtRssiPro;
            stopScanBtRssiItem.Executer = new AtCommandExecuter();
            taskItemManager.Put(stopScanBtRssiItem);

            //关闭蓝牙扫描工具 UART
            TaskItem closeScanToolItem = new TaskItem();
            closeScanToolItem.Enable           = true;
            closeScanToolItem.Item             = "关闭BT扫描工具串口";//Close Scan Tool Uart
            closeScanToolItem.Executer         = new ClosePhoneExecutor();
            closeScanToolItem.CommonProperties = new CommonProperties()
            {
                ExecuteCondition = ExecuteCondition.ALWAYS,
                RetryCount       = 0,
            };
            taskItemManager.Put(closeScanToolItem);
            #endregion

            //打开WIFI UART
            //OpenPhoneProperties configOpenWifiUart = new OpenPhoneProperties();
            //configOpenWifiUart.PortName = "COM18";
            //configOpenWifiUart.BaudRate = 115200;
            //configOpenWifiUart.Dtr = true;
            //configOpenWifiUart.Rts = true;
            //configOpenWifiUart.EndLine = "\\r\\n";
            //configOpenWifiUart.Timeout = 10 * 1000;
            //configOpenWifiUart.RetryCount = 0;
            //configOpenWifiUart.AtType = AtType.Manual;
            //configOpenWifiUart.SleepTimeAfterFindDut = 1000;
            //TaskItem openWifiUartItem = new TaskItem();
            //openWifiUartItem.Enable = true;
            //openWifiUartItem.Item = "Open Wifi Uart";
            //openWifiUartItem.CommonProperties = configOpenWifiUart;
            //openWifiUartItem.Executer = new OpenPhoneExecutor();
            taskItemManager.Put(openWifiUartItem);


            //读取WIFI MAP文件至内存********并更新MAC至内存*************
            TaskItem readMapItem = new TaskItem();
            readMapItem.Enable           = true;
            readMapItem.Item             = "读取WIFI MAP文件并更新MAC至内存";//Read MAP From File
            readMapItem.CommonProperties = new ReadMapProperties()
            {
                MapFilePath = "./Map/8710BX.map",
                Timeout     = 2 * 1000,
                RetryCount  = 0,
            };
            readMapItem.Executer = new ReadMapExecuter();
            taskItemManager.Put(readMapItem);


            //写WIFI MAP  使用comdut自定义来写
            TaskItem writeWifiMapItem = new TaskItem();
            writeWifiMapItem.Enable           = true;
            writeWifiMapItem.Item             = "写WIFI MAP";//
            writeWifiMapItem.CommonProperties = new WriteWifiMapProperties()
            {
                //取MAC文件一行一行的写(16个字节)
                WriteMapAtCommand = "iwpriv config_set wmap,{0},{1}",
                Address           = "0x00",
                AtCommandInterval = 50,
                AtCommandOk       = "[MEM] After do cmd",
                AtCommandError    = "unknown command",

                Timeout       = 20 * 1000,//5
                RetryCount    = 0,
                RetryInterval = 50,
            };
            writeWifiMapItem.Executer = new WriteWifiMapExecuter();
            taskItemManager.Put(writeWifiMapItem);



            //写WIFI MAC
            //TaskItem writeWifiMacItem = new TaskItem();
            //writeWifiMacItem.Enable = true;
            //writeWifiMacItem.Item = "Write WIFI MAC";
            //AtCommandProperties configWriteWifiMac = new AtCommandProperties();
            //configWriteWifiMac.AtCommand = "iwpriv config_set wmap,0x0a,{MAC}";

            //configWriteWifiMac.AtCommandOk = "Private Message: 0x";
            //configWriteWifiMac.AtCommandError = "unknown command";
            //configWriteWifiMac.AtCommandInterval = 800;
            //writeWifiMacItem.CommonProperties = configWriteWifiMac;
            //writeWifiMacItem.Executer = new AtCommandExecuter();
            //taskItemManager.Put(writeWifiMacItem);

            ////读并校验WIFI MAC


            //读并WIFI MAP
            TaskItem getWifiMoudleMapItem = new TaskItem();
            getWifiMoudleMapItem.Enable = true;
            getWifiMoudleMapItem.Item   = "读产品内部WIFI Map";//Get Wifi Moudle Map
            AtCommandProperties configGetWifiMoudleMap = new AtCommandProperties();
            configGetWifiMoudleMap.AtCommand = "iwpriv config_get rmap,00,512";

            configGetWifiMoudleMap.AtCommandOk    = "Private Message: 0x";
            configGetWifiMoudleMap.AtCommandError = "unknown command";

            configGetWifiMoudleMap.GlobalVariblesKeyPattern = "Private Message: ([0-9A-Fx ]{2560})";//"BLE MAC->([0-9A-F:]{17})";
            configGetWifiMoudleMap.GlobalVariblesKey        = "{MoudleWifiMap}";

            configGetWifiMoudleMap.AtCommandInterval = 800;
            configGetWifiMoudleMap.RetryCount        = 5;
            getWifiMoudleMapItem.CommonProperties    = configGetWifiMoudleMap;
            getWifiMoudleMapItem.Executer            = new AtCommandExecuter();
            taskItemManager.Put(getWifiMoudleMapItem);


            //校验WIFI MAP
            TaskItem checkWifiMapItem = new TaskItem();
            checkWifiMapItem.Enable           = true;
            checkWifiMapItem.Item             = "校验WIFI Map";//Check Wifi Map
            checkWifiMapItem.CommonProperties = new CheckWifiMapProperties()
            {
                Timeout    = 3 * 1000,
                RetryCount = 0,
            };
            checkWifiMapItem.Executer = new CheckWifiMapExecuter();
            taskItemManager.Put(checkWifiMapItem);



            //WIFI退出MP模式,进入用户模式
            TaskItem wifiIntoUserMode = new TaskItem();
            wifiIntoUserMode.Enable = true;
            wifiIntoUserMode.Item   = "WIFI进入用户模式";//Wifi Into User Mode
            AtCommandProperties configWifiIntoUserProperties = new AtCommandProperties();
            configWifiIntoUserProperties.AtCommand = "ATSC";
            //****************************进入用户模式是否回复OK?***********************
            configWifiIntoUserProperties.AtCommandOk    = "Enter Image 2 ";
            configWifiIntoUserProperties.AtCommandError = "ERROR";
            //configWifiIntoUserProperties.CheckInfo = new string[] { "[ATSC]:", "AT_SYSTEM_CLEAR_OTA_SIGNATURE" };
            configWifiIntoUserProperties.AtCommandInterval = 4000;
            wifiIntoUserMode.CommonProperties = configWifiIntoUserProperties;
            wifiIntoUserMode.Executer         = new AtCommandExecuter();
            taskItemManager.Put(wifiIntoUserMode);


            //检查WIFI版本号 关键字
            TaskItem getWifiVersionItem = new TaskItem();
            getWifiVersionItem.Enable = true;
            getWifiVersionItem.Item   = "检查WIFI版本号";//Get Wifi Version
            AtCommandProperties configGetWifiVersionProperties = new AtCommandProperties();
            configGetWifiVersionProperties.AtCommand      = "ATS?";
            configGetWifiVersionProperties.AtCommandOk    = "[ATS?]: SW VERSION:";
            configGetWifiVersionProperties.AtCommandError = "unknown command";
            configGetWifiVersionProperties.CheckInfo      = new string[] { "SW VERSION: v.3.4" };
            //configGetWifiVersionProperties.GlobalVariblesKeyPattern = "SW VERSION: ([v0-9.]{5})";//"BLE MAC->([0-9A-F:]{17})";
            //configGetWifiVersionProperties.GlobalVariblesKey = "{MoudleWifiVersion}";


            configGetWifiVersionProperties.AtCommandInterval = 800;
            configGetWifiVersionProperties.RetryCount        = 3;
            getWifiVersionItem.CommonProperties = configGetWifiVersionProperties;
            getWifiVersionItem.Executer         = new AtCommandExecuter();
            taskItemManager.Put(getWifiVersionItem);



            //关闭WIFI UART
            //TaskItem closeWifiUartItem = new TaskItem();
            //closeWifiUartItem.Enable = true;
            //closeWifiUartItem.Item = "Close WIFI Uart";
            //closeWifiUartItem.Executer = new ClosePhoneExecutor();
            //closeWifiUartItem.CommonProperties = new CommonProperties()
            //{
            //    ExecuteCondition = ExecuteCondition.ALWAYS,
            //    RetryCount = 0,
            //};
            taskItemManager.Put(closeWifiUartItem);



            //打开BT UART->版本号检查->信号强度检查->心率检查
            //OpenPhoneProperties configOpenBtUart = new OpenPhoneProperties();
            //configOpenBtUart.PortName = "COM17";
            //configOpenBtUart.BaudRate = 2400;
            //configOpenBtUart.Dtr = true;
            //configOpenBtUart.Rts = true;
            //configOpenBtUart.EndLine = "\\r\\n";
            //configOpenBtUart.Timeout = 10 * 1000;
            //configOpenBtUart.RetryCount = 0;
            //configOpenBtUart.AtType = AtType.Manual;
            //configOpenBtUart.SleepTimeAfterFindDut = 1000;
            //TaskItem openBtUartItem = new TaskItem();
            //openBtUartItem.Enable = true;
            //openBtUartItem.Item = "Open BT Uart";
            //openBtUartItem.CommonProperties = configOpenBtUart;
            //openBtUartItem.Executer = new OpenPhoneExecutor();
            //taskItemManager.Put(openBtUartItem);
            taskItemManager.Put(openPhoneItem);

            //NB 软件版本号检查 AT+CGMR 关键字
            TaskItem nbSoftVersionCheck = new TaskItem();
            nbSoftVersionCheck.Enable = true;
            nbSoftVersionCheck.Item   = "检查NB软件版本号";//NB Soft Version Check
            AtCommandProperties configNbSoftVersionCheck = new AtCommandProperties();
            configNbSoftVersionCheck.AtCommand = "AT+CGMR";

            configNbSoftVersionCheck.AtCommandOk       = "OK";
            configNbSoftVersionCheck.AtCommandError    = "ERROR";
            configNbSoftVersionCheck.CheckInfo         = new string[] { "SOTFWAREVER:AI_LITEOS_NB15_B300SP5_V1.9_20200229" };
            configNbSoftVersionCheck.AtCommandInterval = 1500;
            configNbSoftVersionCheck.SleepTimeBefore   = 500;
            nbSoftVersionCheck.CommonProperties        = configNbSoftVersionCheck;
            nbSoftVersionCheck.Executer = new AtCommandExecuter();
            taskItemManager.Put(nbSoftVersionCheck);

            # region NB IMEI号等
예제 #10
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            config = properties as CheckHexUartPowerOnProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;
            List <ComDut> comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }



            //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            List <OpenPhoneProperties> configList      = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>;
            OpenPhoneProperties        configOpenPhone = null;

            foreach (var item in configList)
            {
                if (item.PortName == config.PortName)
                {
                    configOpenPhone = item;
                    break;
                }
            }
            if (configOpenPhone == null)
            {
                throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName));
            }


            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            //byte[] atCommand = strToToHexByte(config.AtCommand);
            ////string atCommand = PreTranslateAtCommand(config.AtCommand);
            //log.Info("AT Commond=" + config.AtCommand);

            //comDut.DtrEnable = configOpenPhone.Dtr;
            //comDut.RtsEnable = configOpenPhone.Rts;
            //comDut.Parity = System.IO.Ports.Parity.Even;

            TimeUtils.Execute(() =>
            {
                Thread.Sleep(config.AtCommandInterval);
                int length       = comDut.ReadBufferSize;
                byte[] byteArray = new byte[length];
                comDut.Read(byteArray, 0, length);
                configGv.Add("RetBytes", byteArray);

                byte[] retArray = configGv.GetObject("RetBytes") as byte[];
                for (int i = 0; i < retArray.Length; i++)
                {//55 AA 03
                    if (retArray[i] == 0x55 &&
                        retArray[i + 1] == 0xAA &&
                        retArray[i + 2] == 0x03
                        )
                    {
                        //flageRightRes = true;
                        //startIndex = i;
                        //break;
                        log.Info(string.Format("检测到产品上电,55 AA 03"));
                        //跳出循环执行
                        return(true);
                    }
                }
                //继续循环执行
                return(false);
            }, config.Timeout);
        }
예제 #11
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            config = properties as CheckHexUartProperties;
            ILog log = globalDic[typeof(ILog).ToString()] as ILog;

            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;
            List <ComDut> comDutList = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }



            //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            List <OpenPhoneProperties> configList      = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>;
            OpenPhoneProperties        configOpenPhone = null;

            foreach (var item in configList)
            {
                if (item.PortName == config.PortName)
                {
                    configOpenPhone = item;
                    break;
                }
            }
            if (configOpenPhone == null)
            {
                throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName));
            }


            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }
            byte[] atCommand = strToToHexByte(config.AtCommand);
            //string atCommand = PreTranslateAtCommand(config.AtCommand);
            log.Info("AT Commond=" + config.AtCommand);

            //comDut.DtrEnable = configOpenPhone.Dtr;
            //comDut.RtsEnable = configOpenPhone.Rts;
            //comDut.Parity = System.IO.Ports.Parity.Even;
            comDut.Write(atCommand, 0, atCommand.Length);
            log.Info("Tx:" + config.AtCommand);

            Thread.Sleep(config.AtCommandInterval);
            int length = comDut.ReadBufferSize;

            byte[] byteArray = new byte[length];
            comDut.Read(byteArray, 0, length);
            #region
            //string hexStr = byteToHexStr(byteArray);
            ////log.Info("Rx:" + hexStr);
            //string response = System.Text.Encoding.ASCII.GetString(byteArray);
            ////response = response.Replace("\0", "~");
            ////string response = comDut.ReadExisting();
            ////byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(response);
            configGv.Add("RetBytes", byteArray);

            //comDut.DtrEnable = false;
            //comDut.RtsEnable = false;

            ////log.Info("Response:\r\n" + response);

            //if (!string.IsNullOrEmpty(config.AtCommandError))
            //{
            //    if (response.Contains(config.AtCommandError))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
            //    }
            //}

            //if (!string.IsNullOrEmpty(config.AtCommandOk))
            //{
            //    if (!response.Contains(config.AtCommandOk))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
            //    }
            //}

            //if (config.CheckInfo != null)
            //{
            //    for (int i = 0; i < config.CheckInfo.Length; i++)
            //    {
            //        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
            //        {
            //            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
            //            if (!response.Contains(checkInfo))
            //            {
            //                throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
            //            }
            //        }
            //    }
            //}

            //if (!string.IsNullOrEmpty(config.GlobalVariblesKey) && !string.IsNullOrEmpty(config.GlobalVariblesKeyPattern))
            //{
            //    string pattern = Parse_r_n(config.GlobalVariblesKeyPattern);
            //    Match matchValue = Regex.Match(response, pattern);
            //    if (!matchValue.Success)
            //    {
            //        throw new BaseException("read info value fail");
            //    }

            //    string value = matchValue.Groups[1].ToString();

            //    Match matchKey = Regex.Match(config.GlobalVariblesKey, this.pattern);
            //    if (!matchKey.Success)
            //    {
            //        throw new BaseException("read info key fail");
            //    }

            //    string key = matchKey.Groups[1].ToString();

            //    configGv.Add(key, value);
            //}
            #endregion


            byte[] retArray   = configGv.GetObject("RetBytes") as byte[];
            int    startIndex = -1;
            //bool flageRightRes = false;
            for (int i = 0; i < retArray.Length; i++)
            {
                if (retArray[i] == 0xA6 &&
                    retArray[i + 1] == 0xA6)
                {
                    //flageRightRes = true;
                    startIndex = i;
                    break;

                    ////记录i的位置
                    //////核验校验位
                    ////sum += byteArray[i];
                }
            }

            //byte[] dataArray = new byte[6];

            //Array.Copy(retArray, startIndex, dataArray, 0, 6);
            //hexStr = byteToHexStr(dataArray);

            //log.Info(string.Format("收到7A 7A 21 D1 1B的回复:{0}\r\n", hexStr));

            //log.Info(string.Format("收到7e 7e 03 bc 94 53的回复:{0}\r\n", hexStr));


            if (startIndex == -1)
            {
                throw new BaseException("没有发现A6 A6 的回复");
            }


            byte[] versionBtyes = new byte[3];
            Array.Copy(retArray, startIndex + 3, versionBtyes, 0, 3);


            string strVersion = versionBtyes[2].ToString() + "." + versionBtyes[1].ToString() + "." + versionBtyes[0].ToString();
            configGv.Add("VERSION", strVersion);
            log.Info(string.Format("版本号:{0}", strVersion));


            byte[] wifiMacBtyes = new byte[12];
            Array.Copy(retArray, startIndex + 6, wifiMacBtyes, 0, 12);
            string strImei = System.Text.Encoding.ASCII.GetString(wifiMacBtyes);
            configGv.Add("DevWifi_MAC", strImei);
            log.Info("WIFI MAC:" + strImei);

            byte[] softNumberBtyes = new byte[9];
            Array.Copy(retArray, startIndex + 18, softNumberBtyes, 0, 9);
            string strSoftNumber = System.Text.Encoding.ASCII.GetString(softNumberBtyes);
            configGv.Add("SoftNumber", strSoftNumber);
            log.Info("软件编号:" + strSoftNumber);


            byte[] resultBtyes = new byte[4];
            Array.Copy(retArray, startIndex + 27, resultBtyes, 0, 4);
            string strResult = System.Text.Encoding.ASCII.GetString(resultBtyes);
            configGv.Add("RESULT", strResult);
            log.Info("联网测试结果:" + strResult);


            byte[] btMacBtyes = new byte[12];
            Array.Copy(retArray, startIndex + 31, btMacBtyes, 0, 12);
            string strBtMac = System.Text.Encoding.ASCII.GetString(btMacBtyes);
            log.Info("BT MAC:" + strBtMac);
            configGv.Add("DevBt_MAC", strBtMac);

            byte[] rssiBtyes = new byte[1];
            Array.Copy(retArray, startIndex + 43, rssiBtyes, 0, 1);

            string strRssi = "-" + rssiBtyes[0].ToString();

            log.Info("信号强度:" + strRssi);
            configGv.Add("RSSI", strRssi);


            //////byte[] iccidBtyes = new byte[20];
            //////Array.Copy(retArray, startIndex + 88, iccidBtyes, 0, 20);
            //////string strIccid = System.Text.Encoding.ASCII.GetString(iccidBtyes);

            //////log.Info("ICCID:" + strIccid);
            //////if (strImsi == "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")
            //////{
            //////    throw new BaseException("ICCID为空,获取失败");
            //////}
            //////configGv.Add("ICCID", strIccid);
        }
예제 #12
0
        public void Run(IProperties properties, GlobalDic <string, object> globalDic)
        {
            SKGAuthorizeCommandProperties config = properties as SKGAuthorizeCommandProperties;
            List <ComDut> comDutList             = globalDic[typeof(List <ComDut>).ToString()] as List <ComDut>;
            //ComDut comDut = globalDic[typeof(ComDut).ToString()] as ComDut;
            ComDut comDut = null;

            foreach (var item in comDutList)
            {
                if (item.PortName == config.PortName)
                {
                    comDut = item;
                    break;
                }
            }
            if (comDut == null)
            {
                throw new BaseException(string.Format("ComDut No PortName:{0}", config.PortName));
            }



            //OpenPhoneProperties configOpenPhone = globalDic[typeof(OpenPhoneProperties).ToString()] as OpenPhoneProperties;
            List <OpenPhoneProperties> configList      = globalDic[typeof(List <OpenPhoneProperties>).ToString()] as List <OpenPhoneProperties>;
            OpenPhoneProperties        configOpenPhone = null;

            foreach (var item in configList)
            {
                if (item.PortName == config.PortName)
                {
                    configOpenPhone = item;
                    break;
                }
            }
            if (configOpenPhone == null)
            {
                throw new BaseException(string.Format("OpenPhoneProperties No PortName:{0}", config.PortName));
            }

            log      = globalDic[typeof(ILog).ToString()] as ILog;
            configGv = globalDic[typeof(GlobalVaribles).ToString()] as GlobalVaribles;

            comDut.Parity = configOpenPhone.Parity;
            string endLine = configOpenPhone.EndLine;

            if (!string.IsNullOrEmpty(endLine))
            {
                endLine = Parse_r_n(endLine);
            }

            string command = "";

            command += config.Head;

            //int型的处理-转2字节byte,连接到16进制字符串中
            int allLength = 9 + 26;//config.DataLength

            byte[] byteTemp    = new byte[2];
            byte[] oneByteTemp = new byte[1];
            byteTemp = intToBytes(allLength);
            command += byteToHexStr(byteTemp);

            command += config.ReservedWord;
            command += config.CommandWord;

            //DataContent部分
            //枚举类的处理
            int intTemp = (int)config.AuthorizeEvent;

            command += intTemp.ToString().PadLeft(2, '0');

            //int型处理
            string snPcbaId = configGv.Get(GlobalVaribles.LABEL_SN);


            if (config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.SN_授权 ||
                config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.PCBA_ID授权
                )
            {
                #region //扫描的SN/PCBA码是直接16进制的连接
                //int effectiveLength = snPcbaId.Length / 2;
                //command += effectiveLength.ToString("X2");
                //command += snPcbaId.PadRight(48, '0');
                #endregion

                #region //扫描的SN/PCBA码是字符型,ASCII码的方式
                byte[] bytesSnPcba = System.Text.Encoding.ASCII.GetBytes(snPcbaId);
                command += bytesSnPcba.Length.ToString("X2");
                command += byteToHexStr(bytesSnPcba).PadRight(48, '0');
                #endregion
            }
            else if (config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.授权写入蓝牙广播报信息)
            {
                //V16版的协议不写蓝牙广播
                byte[] bytesSnPcba = System.Text.Encoding.ASCII.GetBytes(config.BleBroadcastName);
                command += bytesSnPcba.Length.ToString("X2");
                command += byteToHexStr(bytesSnPcba).PadRight(17, '0');

                command += config.DeviceType;
                command += config.ReservedWord1;
                command += config.ReservedWord2;
            }
            else if (config.AuthorizeEvent == SKGAuthorizeCommandProperties.EnumAuthorizeEvent.解锁SWD)
            {
                byte[] seroArry = new byte[25];
                command += byteToHexStr(seroArry);
            }


            #region
            //SN / PCBAID 需要填满 24 字节,不够 长的在后面补 0x00(例:SN 有效长度 为 16 字 节 则 第 17-24 字 节 填 充 0x00)
            //command += config.Sn_PCBA_ID.PadRight(48,'0');

            //intTemp = (int)config.LedModeSetting;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.EmsTestSwitch;
            //command += intTemp.ToString().PadLeft(2, '0');

            ////int型的处理
            //byteTemp = intToBytes(config.EmsPWSetting);
            //command += byteToHexStr(byteTemp);

            //byteTemp = intToBytes(config.EmsFreqSetting);
            //command += byteToHexStr(byteTemp);

            //byteTemp = intToBytes(config.EmsAmplitudeSetting);
            //command += byteToHexStr(byteTemp);

            ////枚举类的处理
            //intTemp = (int)config.HeatingGearControl;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VoiceControl;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.WritePcbaFinishFlag;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.WholeMachineFinishFlag;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.BtTestOnOffSetting;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.MotorControl;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.AginTestOnOffSetting;
            //command += intTemp.ToString().PadLeft(2, '0');

            ////int型的处理-转为1字节byte
            //oneByteTemp = intToOneBytes(config.AginTestTime);
            //command += byteToHexStr(byteTemp);
            //#region 多路振动控制
            //intTemp = (int)config.VibrationControl1;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl2;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl3;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl4;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl5;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl6;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl7;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl8;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl9;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl10;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl11;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl12;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl13;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl4;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl5;
            //command += intTemp.ToString().PadLeft(2, '0');

            //intTemp = (int)config.VibrationControl6;
            //command += intTemp.ToString().PadLeft(2, '0');
            //#endregion
            //intTemp = (int)config.RedLightControl640nm;
            //command += intTemp.ToString().PadLeft(2, '0');

            #endregion
            //byteToHexStr();

            //byte[] atCommand = strToToHexByte(config.AtCommand);

            //计算校验位
            byte[] atCommandOutXor = strToToHexByte(command);
            byte[] atCommand       = new byte[atCommandOutXor.Length + 1];

            byte byteXor = ByteToXOR(atCommandOutXor);

            Array.Copy(atCommandOutXor, 0, atCommand, 0, atCommandOutXor.Length);
            //赋值最后一个校验位
            atCommand[atCommandOutXor.Length] = byteXor;

            //string atCommand = PreTranslateAtCommand(config.AtCommand);
            UartDisplay(atCommand, "T");

            //log.Info("AT Commond=" + config.AtCommand);

            comDut.DtrEnable = configOpenPhone.Dtr;
            comDut.RtsEnable = configOpenPhone.Rts;
            comDut.Write(atCommand, 0, atCommand.Length);
            Thread.Sleep(config.AtCommandInterval);

            //发命令后一直循环接收->检验->拼接,超过500ms还没检验通过则超时FAIL
            TimeUtils.Execute(() =>
            {
                int n = comDut.BytesToRead;
                //if (n == 0)
                //{
                //    //继续循环执行
                //    return false;
                //}
                //byte[] buf = new byte[n];
                //comDut.Read(buf, 0, n);
                //buffer.AddRange(buf);
                log.Info(string.Format("接收的长度:{0}", n));

                if (n != 0)
                {
                    byte[] buf = new byte[n];
                    comDut.Read(buf, 0, n);
                    UartDisplay(buf, "R");

                    buffer.Clear();
                    buffer.AddRange(buf);
                }


                if (buffer.Count > 9)
                {
                    if (buffer[0] == 0xA5)
                    {
                        //throw new BaseException(string.Format("Head Error"));
                        //if (&& buf[1] == 0xC3))
                        //{

                        //}
                        if (buffer[1] == 0xC3)
                        {
                            byte high        = buffer[2];
                            byte low         = buffer[3];
                            int iTotalLength = (high & 0xFF) << 8 | low;

                            if (buffer.Count < iTotalLength) //数据区尚未接收完整
                            {
                                log.Info(string.Format("数据尚未接收完整,已接收:{0},总长度:{1}", buffer.Count, iTotalLength));
                                //继续循环执行
                                return(false);
                            }
                            byte[] oneFrameBytes = new byte[iTotalLength];
                            buffer.CopyTo(0, oneFrameBytes, 0, iTotalLength);
                            buffer.RemoveRange(0, iTotalLength);

                            UartDisplay(oneFrameBytes, "R");

                            #region //开始校验-命令字
                            if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.查询指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x37))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.控制指令)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x40))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.发授权)
                            {
                                if (!(oneFrameBytes[6] == 0xA0 && oneFrameBytes[7] == 0x23))
                                {
                                    log.Info(string.Format("CMD Type Error"));
                                    //继续循环执行
                                    return(false);
                                }
                            }
                            else
                            {
                                log.Info(string.Format("非法指令类型"));
                                //继续循环执行
                                return(false);
                            }

                            //异或校验 1字节
                            byte[] bufOutOxr = new byte[oneFrameBytes.Length - 1];
                            Array.Copy(oneFrameBytes, 0, bufOutOxr, 0, oneFrameBytes.Length - 1);
                            byte xor = ByteToXOR(bufOutOxr);

                            if (oneFrameBytes[iTotalLength - 1] != xor)
                            {
                                log.Fail(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));
                                //继续循环执行
                                return(false);
                            }
                            log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", oneFrameBytes[iTotalLength - 1], xor));

                            //数据内容 32个字节——长度是不固定的
                            byte[] dataArrys = new byte[iTotalLength - 9];                //config.DataLength
                            Array.Copy(oneFrameBytes, 8, dataArrys, 0, iTotalLength - 9); //config.DataLength

                            //添加到全局变量中
                            if (config.GlobalVariblesKey != null)
                            {
                                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                                {
                                    Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                                    if (!matchKey.Success)
                                    {
                                        //throw new BaseException("read info key fail");
                                        log.Info("read info key fail");
                                        //继续循环执行
                                        return(false);
                                    }

                                    string key = matchKey.Groups[1].ToString();

                                    configGv.Add(key, dataArrys);
                                    log.Info("应答报文格式检查PASS");
                                }
                            }
                            //跳出循环执行
                            return(true);

                            #endregion
                        }
                        else
                        {
                            log.Info(string.Format("头部不是0xA5,0xC3,buffer.RemoveAt:{0:X2},{1:X2}", buffer[0], buffer[1]));

                            buffer.RemoveRange(0, 2);
                            //继续循环执行
                            return(false);
                        }
                    }
                    else
                    {
                        log.Info(string.Format("头部不是0xA5,buffer.RemoveAt:{0:X2}", buffer[0]));

                        buffer.RemoveAt(0);
                        //继续循环执行
                        return(false);
                    }
                }
                else
                {
                    log.Info(string.Format("buffer.Count:{0}小于最小长度9", buffer.Count));
                    //继续循环执行
                    return(false);
                }
            }, config.Timeout);

            //返回的数据部分处理
            byte[] dataArry = null;
            if (config.GlobalVariblesKey != null)
            {
                for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
                {
                    Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
                    if (!matchKey.Success)
                    {
                        throw new BaseException("read info key fail");
                        //log.Info("read info key fail");
                        ////继续循环执行
                        //return false;
                    }

                    string key = matchKey.Groups[1].ToString();

                    dataArry = (byte[])configGv.GetObject(key);
                }
            }
            if (dataArry == null)
            {
                throw new BaseException("未获取到回复的数据部分");
            }
            string revAuthorizeContent  = byteToHexStr(dataArry).Substring(4, 48);
            string sendAuthorizeContent = command.Substring(20, 48);
            if (revAuthorizeContent != sendAuthorizeContent)
            {
                throw new BaseException(string.Format("授权失败\r\n回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n不一致", revAuthorizeContent, sendAuthorizeContent));
                //log.Fail(string.Format("授权失败\r\n回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n不一致", revAuthorizeContent, sendAuthorizeContent));
                ////继续循环执行
                //return false;
            }
            log.Info(string.Format("回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n一致", revAuthorizeContent, sendAuthorizeContent));
            //MCU ID
            byte[] dataMcuId = new byte[12];
            Array.Copy(dataArry, 26, dataMcuId, 0, 12);
            string strDataMcuId = byteToHexStr(dataMcuId);
            log.Info(string.Format("MCU ID:{0}", strDataMcuId));
            if (strDataMcuId.Contains("00000000000000000000"))
            {
                throw new BaseException(string.Format("授权失败,数据为00的MCUID"));
                //log.Fail(string.Format("授权失败,数据为00的MCUID"));
                ////继续循环执行
                //return false;
            }
            //BLE MAC
            byte[] dataBleMac = new byte[6];
            Array.Copy(dataArry, 38, dataBleMac, 0, 6);
            //ASCII码的方式
            //string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId);
            //BLE MAC:1F39A109,低位在前0x09,0xA1的直接16进制拼接方式
            string strDataBleMac = byteToHexStrReverse(dataBleMac);
            log.Info(string.Format("BLE MAC:{0}", strDataBleMac));
            log.Info(string.Format("授权成功"));



            #region
            //DateTime start = DateTime.Now;
            //DateTime now = DateTime.Now;
            //TimeSpan timeSpan = now - start;
            //while (timeSpan.TotalMilliseconds <= config.Timeout)
            //{
            //    try
            //    {
            //        comDut.Write(atCommand, 0, atCommand.Length);
            //        Thread.Sleep(config.AtCommandInterval);

            //        int n = comDut.BytesToRead;
            //        byte[] buf = new byte[n];
            //        comDut.Read(buf, 0, n);
            //        //解析是否收到正确的包,包头,命令,校验位

            //        //如果收到的包正确
            //        if (true)
            //        {
            //            break;
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //        Console.WriteLine(e);
            //    }

            //    Thread.Sleep(100);
            //    now = DateTime.Now;
            //    timeSpan = now - start;
            //}

            //if (timeSpan.TotalMilliseconds > config.Timeout)
            //{
            //    throw new BaseException("超时:");
            //}
            #endregion
            //

            #region 原发送命令后等待一固定时间,再接收数据,对应不上则重试
            //int n = comDut.BytesToRead;
            //byte[] buf = new byte[n];
            //comDut.Read(buf, 0, n);
            ////解析是否收到正确的包,包头,命令,校验位
            ////起始标志 数据长度 保留字     命令字     数据内容    异或校验码
            ////0XA5C3    9+N     0x0000      0x0037      Data        异或
            ////2 字节  2 字节    2 字节      2 字节      N 字节     1 字节
            //UartDisplay(buf, "R");
            //if (buf.Length < 9)
            //{
            //    throw new BaseException(string.Format("Response Length Not enough"));
            //}
            ////包头
            //if (!(buf[0] == 0xA5 && buf[1] == 0xC3))
            //{
            //    throw new BaseException(string.Format("Response Head Error"));
            //}
            ////长度 2字节
            //byte high = buf[2];
            //byte low = buf[3];
            //int iTotalLength = (high & 0xFF) << 8 | low;

            //if (iTotalLength != n)
            //{
            //    throw new BaseException(string.Format("Response Length Error,长度位:{0},实际长度:{1}", iTotalLength, n));
            //}

            ////命令字
            //if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.查询指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x37))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.控制指令)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x40))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else if (config.CommandType == SKGAuthorizeCommandProperties.EnumCommandType.下发授权)
            //{
            //    if (!(buf[6] == 0xA0 && buf[7] == 0x23))
            //    {
            //        throw new BaseException(string.Format("Response Command Type Error"));
            //    }
            //}
            //else
            //{
            //    throw new BaseException(string.Format("Response为非法指令类型"));
            //}


            ////异或校验 1字节
            //byte[] bufOutOxr = new byte[buf.Length-1];
            //Array.Copy(buf, 0, bufOutOxr, 0, buf.Length - 1);
            //byte xor = ByteToXOR(bufOutOxr);

            //if (buf[n - 1] != xor)
            //{
            //    throw new BaseException(string.Format("核验RX的校验位:错误,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));
            //}
            //log.Info(string.Format("核验RX的校验位:正确,返回校验位:{0:X2},计算校验位:{1:X2}", buf[n - 1], xor));



            ////数据内容 32个字节
            ////byte[] dataArry = new byte[config.DataLength];
            ////Array.Copy(buf, 8, dataArry, 0, config.DataLength);

            //byte[] dataArry = new byte[iTotalLength - 9];//config.DataLength
            //Array.Copy(buf, 8, dataArry, 0, iTotalLength - 9);//config.DataLength

            ////添加到全局变量中
            //if (config.GlobalVariblesKey != null)
            //{
            //    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //    {
            //        //string pattern = "-([0-9]{2}) ";
            //        //Match matchValue = Regex.Match(response, pattern);
            //        //if (!matchValue.Success)
            //        //{
            //        //    throw new BaseException("read info value fail");
            //        //}

            //        //string value = matchValue.Groups[1].ToString();

            //        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //        if (!matchKey.Success)
            //        {
            //            throw new BaseException("read info key fail");
            //        }

            //        string key = matchKey.Groups[1].ToString();

            //        configGv.Add(key, dataArry);
            //        log.Info("应答报文格式检查PASS");
            //    }
            //}
            #endregion
            //检查是否授权正确:
            //授权事件确认检查

            //string revAuthorizeContent = byteToHexStr(dataArry).Substring(4, 48);
            //string sendAuthorizeContent = command.Substring(20, 48);
            //if (revAuthorizeContent!= sendAuthorizeContent)
            //{
            //    throw new BaseException(string.Format("授权失败\r\n回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n不一致", revAuthorizeContent, sendAuthorizeContent));
            //}
            //log.Info(string.Format("回复的授权内容:{0}\r\n发送的授权内容:{1}\r\n一致", revAuthorizeContent, sendAuthorizeContent));
            ////MCU ID
            //byte[] dataMcuId = new byte[12];
            //Array.Copy(dataArry, 26, dataMcuId, 0, 12);
            ////ASCII码的方式
            ////string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId);
            ////MCU ID:1F39A109高位在前1F,39的直接16进制拼接方式
            //string strDataMcuId = byteToHexStr(dataMcuId);
            //log.Info(string.Format("MCU ID:{0}", strDataMcuId));
            //if (strDataMcuId.Contains("00000000000000000000"))
            //{
            //    throw new BaseException(string.Format("授权失败,数据为00的MCUID"));
            //}
            ////BLE MAC
            //byte[] dataBleMac = new byte[6];
            //Array.Copy(dataArry, 38, dataBleMac, 0, 6);
            ////ASCII码的方式
            ////string strDataMcuId = System.Text.Encoding.ASCII.GetString(dataMcuId);
            ////BLE MAC:1F39A109,低位在前0x09,0xA1的直接16进制拼接方式
            //string strDataBleMac = byteToHexStrReverse(dataBleMac);
            //log.Info(string.Format("BLE MAC:{0}", strDataBleMac));
            //log.Info(string.Format("授权成功"));



            ////如果收到的包正确
            //string str = byteToHexStr(buf);


            //string response = comDut.ReadExisting();
            //comDut.DtrEnable = false;
            //comDut.RtsEnable = false;

            //log.Info("AT Response=" + response);

            //if (!string.IsNullOrEmpty(config.AtCommandError))
            //{
            //    if (response.Contains(config.AtCommandError))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] contain error=[{1}]", response, config.AtCommandError));
            //    }
            //}

            //if (!string.IsNullOrEmpty(config.AtCommandOk))
            //{
            //    if (!response.Contains(config.AtCommandOk))
            //    {
            //        throw new BaseException(string.Format("AT response=[{0}] not contain error=[{1}]", response, config.AtCommandOk));
            //    }
            //}

            //if (config.CheckInfo != null)
            //{
            //    for (int i = 0; i < config.CheckInfo.Length; i++)
            //    {
            //        if (!string.IsNullOrEmpty(config.CheckInfo[i]))
            //        {
            //            string checkInfo = PreTranslateCheckInfo(config.CheckInfo[i]);
            //            if (!response.Contains(checkInfo))
            //            {
            //                throw new BaseException(string.Format("AT response=[{0}] not contain check info=[{1}]", response, checkInfo));
            //            }
            //        }
            //    }
            //}

            //if (config.GlobalVariblesKey != null && config.GlobalVariblesKeyPattern != null)
            //{
            //    if (config.GlobalVariblesKey.Length != config.GlobalVariblesKeyPattern.Length)
            //    {
            //        throw new BaseException("请保持GlobalVariblesKey与GlobalVariblesKeyPattern成对存在");
            //    }
            //    for (int i = 0; i < config.GlobalVariblesKey.Length; i++)
            //    {
            //        string pattern = "-([0-9]{2}) ";
            //        Match matchValue = Regex.Match(response, pattern);
            //        if (!matchValue.Success)
            //        {
            //            throw new BaseException("read info value fail");
            //        }

            //        string value = matchValue.Groups[1].ToString();

            //        Match matchKey = Regex.Match(config.GlobalVariblesKey[i], this.pattern);
            //        if (!matchKey.Success)
            //        {
            //            throw new BaseException("read info key fail");
            //        }

            //        string key = matchKey.Groups[1].ToString();

            //        configGv.Add(key, value);
            //    }
            //}
        }