/// <summary>
        /// 任务流
        /// </summary>
        /// <returns></returns>
        private int TestTaskFlow()
        {
            int    ret     = -1;
            string pattern = null;

            eidRead = "NULL";

            if (readWriteIdHandle.IsTimeOut)
            {
                frmMain.DisplayLog("测试超时\r\n");
                return(ret);
            }

            ProductionInfo.SystemType systemType = ProductionInfo.Type;

            //使用do..while(false)的原因,是为了当测试流程为fail时,使用break跳出该结构,仍然执行结果上报
            do
            {
                //从芯片获取eid
                //eidRead = "081603FFFFF35293" + eidlast.ToString("X").PadLeft(4,'0');
                //int readRet = 1;
                eidRead = readWriteIdHandle.ReadId(ATReadCmd.ReadIdType.EidRead);
                pattern = @"[0-9A-Z]{20}";
                if (string.IsNullOrEmpty(eidRead) || !Regex.IsMatch(eidRead, pattern))
                {
                    frmMain.DisplayLog("EID读取失败\r\n");
                    break;
                }
                frmMain.DisplayLog(string.Format("已获取模块EID:{0}\r\n", eidRead));
                frmMain.SetText(AllForms.EnumControlWidget.txtEid.ToString(), eidRead, false);


                //从芯片读出SN
                snRead  = readWriteIdHandle.ReadId(ATReadCmd.ReadIdType.SnRead);
                pattern = @"^[0-9A-Z]{16}$";
                if (string.IsNullOrEmpty(snRead))
                {
                    frmMain.DisplayLog("SN为空读取失败\r\n");
                    break;
                }
                if (!Regex.IsMatch(snRead, pattern))
                {
                    frmMain.DisplayLog("SN合法性检查:SN不合法败\r\n");
                    break;
                }
                frmMain.DisplayLog(string.Format("已获取模块合法SN:{0}\r\n", snRead));
                frmMain.SetText(AllForms.EnumControlWidget.txtSn.ToString(), snRead, false);

                //从芯片读出IMEI
                imeiRead = readWriteIdHandle.ReadId(ATReadCmd.ReadIdType.ImeiRead);
                pattern  = @"\d{15}";
                if (string.IsNullOrEmpty(imeiRead) || !Regex.IsMatch(imeiRead, pattern))
                {
                    frmMain.DisplayLog("IMEI读取失败\r\n");
                    break;
                }
                frmMain.DisplayLog(string.Format("已获取模块IMEI:{0}\r\n", imeiRead));
                frmMain.SetText(AllForms.EnumControlWidget.txtImei.ToString(), imeiRead, false);


                //从芯片获取iccid
                iccidRead = readWriteIdHandle.ReadId(ATReadCmd.ReadIdType.IccidRead);
                pattern   = @"[0-9A-Z]{20}";
                if (string.IsNullOrEmpty(iccidRead) || !Regex.IsMatch(iccidRead, pattern))
                {
                    frmMain.DisplayLog("ICCID读取失败\r\n");
                    break;
                }
                frmMain.DisplayLog(string.Format("已获取模块ICCID:{0}\r\n", iccidRead));
                frmMain.SetText(AllForms.EnumControlWidget.txtIccid.ToString(), iccidRead, false);


                //从芯片获取Verson
                versonRead = readWriteIdHandle.ReadId(ATReadCmd.ReadIdType.VersonRead);
                if (string.IsNullOrEmpty(iccidRead))
                {
                    frmMain.DisplayLog("版本号读取失败 FAIL\r\n");
                    break;
                }
                frmMain.DisplayLog(string.Format("已获取版本号:{0}\r\n", versonRead));
                if (versonRead != VersonIni.ToUpper())
                {
                    frmMain.DisplayLog(string.Format("读出的版本号:{0} 与 配置的版本号:{1} 不一致 FAIL\r\n", versonRead, VersonIni));
                    break;
                    //ret = -1;
                    //return ret;
                }
                else
                {
                    frmMain.DisplayLog(string.Format("读出的版本号:{0} 与 配置的版本号:{1} 一致 PASS\r\n", versonRead, VersonIni));
                }


                //判断IMEI与标签IMEI是否一致
                if (labelImei == imeiRead)
                {
                    frmMain.DisplayLog(string.Format("标签IMEI:{0}与模块IMEI:{1}对比一致 PASS\r\n", labelImei, imeiRead));
                }
                else
                {
                    frmMain.DisplayLog(string.Format("标签IMEI:{0}与模块IMEI:{1}对比不一致 FAIL\r\n", labelImei, imeiRead));
                    break;
                }

                //eid与iccid的后6位对比
                if (CompareEidIccid == 1)//要对比
                {
                    string lastSixIccid = iccidRead.Substring(iccidRead.Length - 6);
                    string lastSixEid   = eidRead.Substring(eidRead.Length - 6);
                    if (JudgeStandard == 0)
                    {
                        //一样 FAIL
                        if (lastSixIccid == lastSixEid)
                        {
                            frmMain.DisplayLog(string.Format("空中写号检查:未做。详细:后6位的eid:{0} 与 iccid:{1} 完全一致 FAIL\r\n", lastSixEid, lastSixIccid));
                            break;
                            //ret = -1;
                            //return ret;
                        }
                        else
                        {
                            frmMain.DisplayLog(string.Format("空中写号检查:通过。详细:后6位的eid:{0} 与 iccid:{1}不一致 PASS\r\n", lastSixEid, lastSixIccid));
                        }
                    }
                    else if (JudgeStandard == 1)
                    {
                        //一样 PASS
                        if (lastSixIccid != lastSixEid)
                        {
                            frmMain.DisplayLog(string.Format("空中写号检查:未做。详细:后6位的eid:{0} 与 iccid:{1} 不一致 FAIL\r\n", lastSixEid, lastSixIccid));
                            break;
                            //ret = -1;
                            //return ret;
                        }
                        else
                        {
                            frmMain.DisplayLog(string.Format("空中写号检查:通过。详细:后6位的eid:{0} 与 iccid:{1}完全一致 PASS\r\n", lastSixEid, lastSixIccid));
                        }
                    }
                }
                //离线查重IMEI
                if (ProductionInfo.Type == ProductionInfo.SystemType.Offline)
                {
                    JiaHao.ExcelHelp.ExcelHelper excel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance();
                    ret = excel.SearchImei(imeiRead);
                    if (ret != 0)
                    {
                        frmMain.DisplayLog(string.Format("IMEI查重: {0} 重复 FAIL\r\n", imeiRead));
                        return(ret);
                    }
                    else
                    {
                        frmMain.DisplayLog(string.Format("IMEI查重: {0} 本机查重 PASS\r\n", imeiRead));
                    }
                }

                #region
                if (systemType == ProductionInfo.SystemType.iMES)
                {
                    //调用打印接口下拉eid相关信息rep,为了生成Log作准备
                    Production.Server.NewHttpImeiPrint.ResponseInfo rep;
                    string errorInfo;
                    ret = ToImesInterface.ImeiPrint(out rep, imeiRead, out errorInfo);
                    //ImeiPrint(out rep);
                    if (ret != 0)
                    {
                        //显示结果:下拉失败,并改变颜色
                        frmMain.DisplayLog("从IMES下拉信息失败" + errorInfo + "\r\n");
                        break;
                    }
                    frmMain.DisplayLog("从IMES下拉信息成功\r\n");
                    //模组读出的和IMES下拉的是否相同
                    //IMEI,PUBLICSN,ICCID,IMSI,EID,IMEIBINDINGSN,DATE
                    //"sn":123456789012345,AI18082202000001,,,,,8822
                    string[] idNumber = rep.sn.ToUpper().Split(',');
                    #region 比对
                    #region IMEI
                    if (idNumber[0] == "")
                    {
                        frmMain.DisplayLog(string.Format("服务器IMEI获取为空 FAIL\r\n"));
                        ret = -1;
                        break;
                    }
                    if (idNumber[0] != imeiRead.ToUpper())
                    {
                        frmMain.DisplayLog(string.Format("服务器IMEI:{0} 与 模块IMEI:{1} 不一致 FAIL\r\n", idNumber[0], imeiRead));
                        ret = -1;
                        break;
                    }
                    else
                    {
                        frmMain.DisplayLog(string.Format("服务器IMEI:{0} 与 模块IMEI:{1} 一致 PASS\r\n", idNumber[0], imeiRead));
                    }
                    #endregion
                    #region SN
                    if (idNumber[1] != snRead.ToUpper())
                    {
                        frmMain.DisplayLog(string.Format("服务器SN:{0} 与 模块SN:{1} 不一致 FAIL\r\n", idNumber[1], snRead));
                        ret = -1;
                        break;
                    }
                    else
                    {
                        frmMain.DisplayLog(string.Format("服务器SN:{0} 与 模块SN:{1} 一致 PASS\r\n", idNumber[1], snRead));
                    }
                    #endregion

                    #region ICCID
                    if (idNumber[2] != iccidRead.ToUpper())
                    {
                        frmMain.DisplayLog(string.Format("服务器ICCID:{0} 与 模块ICCID:{1} 不一致 FAIL\r\n", idNumber[2], iccidRead));
                        ret = -1;
                        break;
                    }
                    else
                    {
                        frmMain.DisplayLog(string.Format("服务器ICCID:{0} 与 模块ICCID:{1} 一致 PASS\r\n", idNumber[2], iccidRead));
                    }
                    #endregion

                    #region EID
                    if (idNumber[4] != eidRead.ToUpper())
                    {
                        frmMain.DisplayLog(string.Format("服务器EID:{0} 与 模块EID:{1} 不一致 FAIL\r\n", idNumber[4], eidRead));
                        ret = -1;
                        break;
                    }
                    else
                    {
                        frmMain.DisplayLog(string.Format("服务器EID:{0} 与 模块EID:{1} 一致 PASS\r\n", idNumber[4], eidRead));
                    }
                    #endregion

                    #endregion
                }

                if (systemType == ProductionInfo.SystemType.GSMMES)
                {
                    //EID合法性检查
                    ret = EidVerify();
                    if (ret != 0)
                    {
                        break;
                    }
                }
                #endregion

                if (systemType == ProductionInfo.SystemType.GSMMES)
                {
                    //EID合法性检查
                    ret = CheckAllNumber();
                    if (ret != 0)//失败就直接上报测试结果
                    {
                        break;
                    }
                }
            } while (false);

            if (systemType == ProductionInfo.SystemType.GSMMES)
            {
                frmMain.DisplayLog("测试数据上报服务器\r\n");
                //EID/IMEI/SN上报服务器
                int    resultUpload = ret == 0 ? 1 : 2;
                string testDada     = string.Empty;
                string log          = frmMain.ReadLog();

                ret = EidUpload(resultUpload, log);
                if (ret != 0)
                {
                    frmMain.DisplayLog("过站失败\r\n");
                    return(ret);
                }
            }
            #region 离线 记录到Excel
            if (ProductionInfo.Type == ProductionInfo.SystemType.Offline)
            {
                if (ret == 0)
                {
                    JiaHao.ExcelHelp.ExcelHelper excel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance();
                    excel.ExportExcelOneByOne(new JiaHao.ExcelHelp.ExcelHelper.TrayInfoInExcel()
                    {
                        num          = 1,
                        sn           = snRead,
                        imei         = imeiRead,
                        eid          = eidRead,
                        iccid        = iccidRead,
                        cuatomerName = "中移物联"
                    });
                    frmMain.DisplayLog("写入Excel成功\r\n");
                }
            }
            #endregion
            return(ret);
        }
示例#2
0
文件: Form1.cs 项目: Hanson0/SnToBin
        private int TestFlow()
        {
            int    ret     = -1;
            string pattern = null;

            try
            {
                #region
                txtLog.Text      = "Log:\r\n";
                txtLog.BackColor = Color.White;
                txtLog.Refresh();
                //开启线程
                Thread Procedure = new Thread(new ThreadStart(procedureThread));
                Procedure.IsBackground = false;
                Procedure.Start();


                //合法性检测
                pattern = @"[0-9A-Z]{12}";
                if (string.IsNullOrEmpty(txtMac.Text) || !Regex.IsMatch(txtMac.Text, pattern))
                {
                    DisplayLog(string.Format("MAC合法性检查: {0} 不合法 FAIL\r\n", txtMac.Text));
                    return(ret);
                }
                //离线查重MAC
                if (ProductionInfo.Type == ProductionInfo.SystemType.Offline)
                {
                    JiaHao.ExcelHelp.ExcelHelper excel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance();
                    int retCheck = excel.SearchImei(txtMac.Text);
                    if (retCheck != 0)
                    {
                        DisplayLog(string.Format("MAC查重: {0} 重复 FAIL\r\n", txtMac.Text));
                        //return ret;


                        //stopWatcher1.Stop();
                        return(retCheck);
                    }
                    else
                    {
                        DisplayLog(string.Format("MAC查重: {0} 本机查重 PASS\r\n", txtMac.Text));
                    }
                }
                //分配SN
                JiaHao.ExcelHelp.ExcelHelper snExcel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance(true);

                string sn = snExcel.GetSn();//读最后一行
                if (string.IsNullOrEmpty(sn))
                {
                    DisplayLog(string.Format("分配SN: MAC:{0}分配SN失败 FAIL\r\n", txtMac.Text));
                    ret = -1;
                    return(ret);
                }
                DisplayLog(string.Format("分配SN: {0}成功 PASS\r\n", sn));

                txtSn.Text = sn;
                txtSn.Refresh();

                string       strTimeNow     = DateTime.Now.ToString("yyyyMMdd_HHmmss");
                string       strBinFilePath = strBinPath + txtSn.Text.ToUpper() + "_" + strTimeNow + ".bin";
                FileStream   fs             = new FileStream(strBinFilePath, FileMode.Create);//@"C:\Users\ZJH\Desktop\test2.bin"
                BinaryWriter bw             = new BinaryWriter(fs);
                //byte[] byteArray = StringToHex(textSN.Text);

                //

                byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(txtSn.Text);

                for (int i = 0; i < byteArray.Length; i++)
                {
                    bw.Write((byte)byteArray[i]);
                }
                bw.Close();
                fs.Close();

                StringBuilder SN = new StringBuilder(256);
                string        path;

                IntPtr ptrTestSoftFormMain = FindWindow(espApplicationPath);

                IntPtr ptrChild1 = Win32API.FindWindowEx(ptrTestSoftFormMain, IntPtr.Zero, null, null);//
                Win32API.SendMessage(ptrChild1, Win32API.WM_GETTEXT, 100, SN);
                path = SN.ToString();

                IntPtr ptrChild1_1 = Win32API.FindWindowEx(ptrChild1, IntPtr.Zero, null, null);//
                Win32API.SendMessage(ptrChild1_1, Win32API.WM_GETTEXT, 100, SN);
                path = SN.ToString();

                IntPtr ptrChild1_2 = Win32API.FindWindowEx(ptrChild1, ptrChild1_1, null, null);//
                Win32API.SendMessage(ptrChild1_2, Win32API.WM_GETTEXT, 100, SN);
                path = SN.ToString();


                IntPtr ptrChild1_3S = Win32API.FindWindowEx(ptrChild1, ptrChild1_2, null, null);                    //

                IntPtr ptrChild1_3S_1 = Win32API.FindWindowEx(ptrChild1_3S, IntPtr.Zero, null, null);               //

                IntPtr ptrChild1_3S_1_1 = Win32API.FindWindowEx(ptrChild1_3S_1, IntPtr.Zero, null, null);           //

                IntPtr ptrChild1_3S_1_1_1 = Win32API.FindWindowEx(ptrChild1_3S_1_1, IntPtr.Zero, null, null);       //

                IntPtr ptrChild3S_1_1_1_1text = Win32API.FindWindowEx(ptrChild1_3S_1_1_1, IntPtr.Zero, null, null); //

                if (ptrChild3S_1_1_1_1text.Equals(IntPtr.Zero))
                {
                    DisplayLog("烧录软件检查: 无法抓取到烧录软件路径栏 Edit FAIL\r\n");
                    return(ret);
                }
                Win32API.SendMessage(ptrChild3S_1_1_1_1text, Win32API.WM_SETTEXT, 0, strBinFilePath);

                //抓取Button
                IntPtr ptrChild1_3S_3 = Win32API.FindWindowEx(ptrChild1_3S, IntPtr.Zero, null, "ESP FLASH DOWNLOAD TOOL V0.9.7");//
                Win32API.SendMessage(ptrChild1_3S_3, Win32API.WM_GETTEXT, 100, SN);
                path = SN.ToString();

                IntPtr ptrChild1_3S_3_1 = Win32API.FindWindowEx(ptrChild1_3S_3, IntPtr.Zero, null, null);//
                Win32API.SendMessage(ptrChild1_3S_3_1, Win32API.WM_GETTEXT, 100, SN);
                path = SN.ToString();

                IntPtr ptrChild1_3S_3_1_1 = Win32API.FindWindowEx(ptrChild1_3S_3_1, IntPtr.Zero, null, null);//
                Win32API.SendMessage(ptrChild1_3S_3_1_1, Win32API.WM_GETTEXT, 100, SN);
                path = SN.ToString();

                IntPtr ptrChild1_3S_3_1_1_5start = Win32API.FindWindowEx(ptrChild1_3S_3_1_1, IntPtr.Zero, null, "START");//
                Win32API.SendMessage(ptrChild1_3S_3_1_1_5start, Win32API.WM_GETTEXT, 100, SN);
                path = SN.ToString();

                if (ptrChild1_3S_3_1_1_5start.Equals(IntPtr.Zero))
                {
                    //MessageBox.Show("未抓取到START按键");
                    DisplayLog("烧录软件检查: 无法抓取到START按键 FAIL\r\n");
                    return(ret);
                }
                if (CheckSn == 1)
                {
                    DisplayLog(string.Format("等待{0}s ....,请上电进入下载模式 进行查询SN\r\n", WaitintTime / 1000));
                    //扫码等待5s后,查询SN
                    Thread.Sleep(WaitintTime);
                    #region 查询产品是否有SN
                    // 读取SN生产bin文件
                    string strCmdReturn1;
                    DisplayLog("开始读取芯片0xc1000地址...\r\n");

                    int retCmd1 = cmdProcess.ExeCommand(ReadToolFolderName, ReadToolAppName, ComPort, out strCmdReturn1);
                    //使用工具读取addr并生成bin成功
                    if (retCmd1 != 0)
                    {
                        Process[] processes = Process.GetProcesses();  //创建并实例化一个操作进程的类:Process
                        foreach (var item in processes)
                        {
                            if (item.ProcessName == "read_bin_addr")
                            {
                                item.Close();
                                //item.Kill();
                                break;
                            }
                        }
                        DisplayLog("SN查询:读取地址失败 FAIL,提示:超过等待时间,设备需3次进入下载模式\r\n");
                        return(retCmd1);
                        //goto END;//END 处理收尾:显示烧写结果,清空
                    }
                    DisplayLog("读取芯片0xc1000地址生成bin成功\r\n");
                    DisplayLog("开始读取bin中的SN...\r\n");
                    //获取bin文件路径
                    int    po;
                    string idKeySubstr1 = "save data to : ";

                    if ((po = strCmdReturn1.IndexOf(idKeySubstr1)) >= 0)
                    {
                        string createdBinPath = strCmdReturn1.Substring(po + idKeySubstr1.Length);
                        //读取bin文件,前7个字节
                        createdBinPath = createdBinPath.Replace("./", "./" + ReadToolFolderName + "/");
                        byte[] readHex = ReadFile(createdBinPath);
                        //将读取与写入对比,一致则写入成功
                        string strRead = Encoding.UTF8.GetString(readHex);
                        //if (strRead != "")
                        //{

                        //}
                        DisplayLog("读取bin中的SN成功\r\n");

                        for (int i = 0; i < readHex.Length; i++)
                        {
                            if (readHex[i] != 0xFF)
                            {
                                hasSn = true;
                            }
                        }
                        if (hasSn)
                        {
                            hasSn = false;
                            DisplayLog("SN查询:" + string.Format("产品中已有SN:{0} FAIL\r\n", strRead));
                            return(ret);
                        }
                        DisplayLog("SN查询:" + "产品中未写过SN PASS\r\n");
                    }
                    #endregion
                }

                DisplayLog(string.Format("等待{0}s ....,请上电进入下载模式,进行下载\r\n", WaitintTime / 1000));
                //扫码等待5s后点击Start按键
                Thread.Sleep(WaitintTime);
                //点击START按键
                Win32API.SendMessage(ptrChild1_3S_3_1_1_5start, Win32API.BM_CLICK, 0, "0");
                //需等烧录完成后,并按板子进入烧录模式,再启动读取软件,读取数据


                DisplayLog(string.Format("等待{0}s ....,请在下载完成后再次上电进入下载模式,进行校验\r\n", WaitintTime / 1000));
                Thread.Sleep(WaitintTime);
                // 读取SN生产bin文件
                #region
                DisplayLog("开始读取芯片0xc1000地址...\r\n");
                string strCmdReturn;
                int    retCmd = cmdProcess.ExeCommand(ReadToolFolderName, ReadToolAppName, ComPort, out strCmdReturn);
                //使用工具读取addr并生成bin成功
                if (retCmd != 0)
                {
                    Process[] processes = Process.GetProcesses();  //创建并实例化一个操作进程的类:Process
                    foreach (var item in processes)
                    {
                        if (item.ProcessName == "read_bin_addr")
                        {
                            item.Close();
                            //item.Kill();
                            break;
                        }
                    }
                    DisplayLog("SN校验:校验失败,提示:超过等待时间,设备需2次进入下载模式\r\n");
                    return(retCmd);
                    //goto END;//END 处理收尾:显示烧写结果,清空
                }
                DisplayLog("读取芯片0xc1000地址生成bin成功\r\n");
                DisplayLog("开始读取bin中的SN...\r\n");
                #endregion
                //获取bin文件路径
                int    positon;
                string idKeySubstr = "save data to : ";

                if ((positon = strCmdReturn.IndexOf(idKeySubstr)) >= 0)
                {
                    string createdBinPath = strCmdReturn.Substring(positon + idKeySubstr.Length);
                    //读取bin文件,前7个字节
                    createdBinPath = createdBinPath.Replace("./", "./" + ReadToolFolderName + "/");
                    byte[] readHex = ReadFile(createdBinPath);

                    //将读取与写入对比,一致则写入成功
                    for (int i = 0; i < readHex.Length; i++)
                    {
                        if (readHex[i] != byteArray[i])
                        {
                            isDiff = true;
                        }
                    }
                    DisplayLog("读取bin中的SN成功\r\n");

                    if (isDiff)
                    {
                        isDiff = false;
                        DisplayLog("SN校验:" + txtSn.Text + "  写入错误,写入失败 FAIL\r\n");
                        return(ret);
                    }
                    DisplayLog("SN校验:" + txtSn.Text + "  写入正确 PASS\r\n");

                    #region 离线 记录到Excel
                    if (ProductionInfo.Type == ProductionInfo.SystemType.Offline)
                    {
                        JiaHao.ExcelHelp.ExcelHelper excel = JiaHao.ExcelHelp.ExcelHelper.GetExcelHelperInstance();
                        excel.ExportExcelOneByOne(new JiaHao.ExcelHelp.ExcelHelper.TrayInfoInExcel()
                        {
                            num          = 1,
                            mac          = txtMac.Text,
                            sn           = txtSn.Text,
                            cuatomerName = "厦门阳光"
                        });
                        //Log添加 写入Excel成功
                        DisplayLog("写入过站记录表: MAC:" + txtMac.Text + " SN:" + txtSn.Text + " PASS\r\n");

                        //删除最后一行SN
                        ret = snExcel.DeleteLastRow();
                        if (ret != 0)
                        {
                            DisplayLog(string.Format("删除SN: MAC({0})删除最后一行SN失败  FAIL\r\n", txtMac.Text));
                            return(ret);
                        }
                        else
                        {
                            DisplayLog(string.Format("删除SN: MAC({0})删除最后一行SN成功  PASS\r\n", txtMac.Text));
                        }
                    }
                    #endregion
                    ret = 0;
                }

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(txtSn.Text + ex.Message);
                txtSn.Text = "";
                return(ret);
            }
            return(ret);
        }