Esempio n. 1
0
        private void TaskBuilder()
        {
            //等待信号
            mCcuEvent = new AutoResetEvent(false);
            //升级PCU Task
            this.CcuWorkTask = new System.ComponentModel.BackgroundWorker();
            this.CcuWorkTask.WorkerReportsProgress      = true;
            this.CcuWorkTask.WorkerSupportsCancellation = true;
            this.CcuWorkTask.DoWork             += new System.ComponentModel.DoWorkEventHandler(this.bk_doCcuWork);
            this.CcuWorkTask.ProgressChanged    += new System.ComponentModel.ProgressChangedEventHandler(this.bk_ProgressCcuReport);
            this.CcuWorkTask.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bk_CcuCompleted);
            //CCU 升级请求
            mUpgradeRequestTask = new SimpleSerialPortTask <CCU_UpgradeRequest, CCU_UpgradeResponse>();
            mUpgradeRequestTask.RetryMaxCnts = 2;
            mUpgradeRequestTask.Timerout     = 20 * 1000;
            mUpgradeRequestParam             = mUpgradeRequestTask.GetRequestEntity();
            mUpgradeRequestTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
            {
                SerialPortEventArgs <CCU_UpgradeResponse> mEventArgs = e as SerialPortEventArgs <CCU_UpgradeResponse>;
                if (mEventArgs.Data != null)
                {
                    if (mEventArgs.Data.UpgradeResult == Const.DO_UPGRADE)
                    {
                        mCcuEvent.Set();
                    }
                }
                else
                {
                    UpdateLviStatus(sender, "升级请求无回应", Task_Level.TASK_FAIL);
                }
            };
            //CCU 升级开始
            mUpgradeStartReqTask              = new SimpleSerialPortTask <CCU_UpgradeStartReq, CCU_UpgradeStartRsp>();
            mUpgradeStartReqParam             = mUpgradeStartReqTask.GetRequestEntity();
            mUpgradeStartReqTask.RetryMaxCnts = 2;
            mUpgradeStartReqTask.Timerout     = 1 * 1000;
            mUpgradeStartReqTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
            {
                SerialPortEventArgs <CCU_UpgradeStartRsp> mEventArgs = e as SerialPortEventArgs <CCU_UpgradeStartRsp>;
                if (mEventArgs.Data != null)
                {
                    switch (mEventArgs.Data.Result)
                    {
                    case Const.DO_NOT_UPGRADE:

                        break;

                    case Const.DO_UPGRADE:
                        mCcuEvent.Set();
                        break;

                    case Const.CONTINUE_UPGRADE:
                        mCcuEvent.Set();
                        break;
                    }
                }
                else
                {
                    UpdateLviStatus(sender, "单包开始升级无回应", Task_Level.TASK_FAIL);
                }
            };
            //CCU 升级处理
            mUpgradeProcessReqTask              = new SimpleSerialPortTask <CCU_UpgradeProcessReq, CCU_UpgradeProcessRsp>();
            mUpgradeProcessReqParam             = mUpgradeProcessReqTask.GetRequestEntity();
            mUpgradeProcessReqTask.Timerout     = 2 * 1000;
            mUpgradeProcessReqTask.RetryMaxCnts = 30;
            mUpgradeProcessReqTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
            {
                SerialPortEventArgs <CCU_UpgradeProcessRsp> mEventArgs = e as SerialPortEventArgs <CCU_UpgradeProcessRsp>;
                if (mEventArgs.Data != null)
                {
                    if (mEventArgs.Data.Result == Const.RECV_DATA_OK)
                    {
                        mCcuEvent.Set();
                    }
                    else
                    {
                        if (mEventArgs.Data.Cause == Const.RECV_DATA_FAIL)
                        {
                            UpdateLviStatus(sender, "单帧处理:接受数据错误", Task_Level.TASK_FAIL);
                        }
                    }
                }
                else
                {
                    UpdateLviStatus(sender, "单帧升级处理无回应", Task_Level.TASK_FAIL);
                }
            };
            //CCU 升级结束
            mUpgradeEndReqTask              = new SimpleSerialPortTask <CCU_UpgradeEndReq, CCU_UpgradeEndRsp>();
            mUpgradeEndReqParam             = mUpgradeEndReqTask.GetRequestEntity();
            mUpgradeEndReqTask.Timerout     = 1 * 1000;
            mUpgradeEndReqTask.RetryMaxCnts = 2;
            mUpgradeEndReqTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
            {
                SerialPortEventArgs <CCU_UpgradeEndRsp> mEventArgs = e as SerialPortEventArgs <CCU_UpgradeEndRsp>;
                if (mEventArgs.Data != null)
                {
                    if (mEventArgs.Data.Result == Const.RECV_DATA_OK)
                    {
                        mCcuEvent.Set();
                    }
                    else
                    {
                        switch (mEventArgs.Data.Cause)
                        {
                        case Const.NONE_ERROR:
                            break;

                        case Const.CRC_ERROR:
                            UpdateLviStatus(sender, "单包处理:CRC校验错误", Task_Level.TASK_FAIL);
                            break;

                        case Const.WRITE_FLASH_ERROR:
                            UpdateLviStatus(sender, "单包处理:写FLASH错误", Task_Level.TASK_FAIL);
                            break;

                        case Const.PACKAGE_ID_ERROR:
                            UpdateLviStatus(sender, "单包处理:包号错误", Task_Level.TASK_FAIL);
                            break;

                        case Const.DATA_ERROR:
                            UpdateLviStatus(sender, "单包处理:数据错误", Task_Level.TASK_FAIL);
                            break;
                        }
                    }
                }
                else
                {
                    UpdateLviStatus(sender, "单包结束升级无回应", Task_Level.TASK_FAIL);
                }
            };
            //CCU MD5校验
            mUpgradeMD5ReqTask              = new SimpleSerialPortTask <CCU_UpgradeMD5Req, CCU_UpgradeMD5Rsp>();
            mUpgradeMD5ReqParam             = mUpgradeMD5ReqTask.GetRequestEntity();
            mUpgradeMD5ReqTask.Timerout     = 2 * 1000;
            mUpgradeMD5ReqTask.RetryMaxCnts = 1;
            mUpgradeMD5ReqTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
            {
                SerialPortEventArgs <CCU_UpgradeMD5Rsp> mEventArgs = e as SerialPortEventArgs <CCU_UpgradeMD5Rsp>;
                if (mEventArgs.Data != null)
                {
                    if (mEventArgs.Data.Result == Const.ARGEE_UPGRADE)
                    {
                        mCcuEvent.Set();
                    }
                    else
                    {
                        UpdateLviStatus(sender, "MD5校验异常", Task_Level.TASK_FAIL);
                    }
                }
                else
                {
                    UpdateLviStatus(sender, "MD5校验通讯异常", Task_Level.TASK_FAIL);
                }
            };
        }
Esempio n. 2
0
        private void TaskBuilder()
        {
            //停止同步报文
            mStopSyncTask              = new SimpleSerialPortTask <pcTakeOverRsp, NullEntity>();
            mStopSyncParam             = mStopSyncTask.GetRequestEntity();
            mStopSyncTask.RetryMaxCnts = 0;
            mStopSyncTask.Timerout     = 1000;
            mStopSyncParam.DeviceType  = 0xF1;
            mStopSyncParam.HardWareID  = 0xF1;
            // mStopSyncParam.FirmID = 17;
            //mStopSyncParam.FirmID1 = 35;
//mStopSyncParam.FirmID2 = 4;
            //重启指令
            mResetEcuTask              = new SimpleSerialPortTask <ResetEcuReq, NullEntity>();
            mResetEcuParam             = mResetEcuTask.GetRequestEntity();
            mResetEcuTask.RetryMaxCnts = 0;
            mResetEcuTask.Timerout     = 1000;
            mResetEcuParam.deviceType  = 0XF1;
            mResetEcuParam.cmdCode     = 0x02;
            mResetEcuParam.param1      = 0x11223344;
            //等待同步报文
            mBroadCastTask = new SimpleSerialPortTask <NullEntity, pcTakeoverReq>();
            mBroadCastTask.RetryMaxCnts = 0;
            mBroadCastTask.Timerout     = 500;
            mBroadCastTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
            {
                SerialPortEventArgs <pcTakeoverReq> mEventArgs = e as SerialPortEventArgs <pcTakeoverReq>;
                if (mEventArgs.Data != null)
                {
                    byte hw1 = (byte)(mEventArgs.Data.hardwareID >> 24);
                    byte hw2 = (byte)(mEventArgs.Data.hardwareID >> 16);
                    byte hw3 = (byte)(mEventArgs.Data.hardwareID >> 8);

                    string softVersion = String.Format("W{0}{1:D2}.{2:D2}", (byte)(mEventArgs.Data.hardwareID >> 24),
                                                       (byte)(mEventArgs.Data.hardwareID >> 16),
                                                       (byte)(mEventArgs.Data.hardwareID >> 8));

                    mStopSyncParam.FirmID  = hw1;
                    mStopSyncParam.FirmID1 = hw2;
                    mStopSyncParam.FirmID2 = hw3;

                    //PC接管报文的响应
                    mStopSyncTask.Excute();
                    Thread.Sleep(5);
                    mStopSyncTask.Excute();
                    Thread.Sleep(5);
                    mStopSyncTask.Excute();
                    Thread.Sleep(5);
                    if (mParam.bPCU)
                    {
                        mPcuTask.ExcuteTask();//开始升级PCU
                    }
                    else if (mParam.bCCU)
                    {
                        mCcuTask.ExcuteTask();//开始升级CCU
                    }
                }
                else
                {
                    if (mParam.bPCU)
                    {
                        mPcuTask.ExcuteTask();//开始升级PCU
                    }
                    else if (mParam.bCCU)
                    {
                        //设备未上电
                        TaskArgs mArgs = new TaskArgs();
                        mArgs.msg   = "中控未上电";
                        mArgs.level = Task_Level.TASK_FAIL;
                        ccuListViewItemHandler(sender, mArgs);
                        bTaskRunning           = false;
                        mResetEcuParam.cmdCode = 0x02; //升级失败或者其他,恢复同步指令
                        mResetEcuTask.Excute();
                        Thread.Sleep(10);
                        mResetEcuTask.Excute();
                        Thread.Sleep(10);
                        mResetEcuTask.Excute();
                        Thread.Sleep(10);
                        mBroadCastTask.ClosePort();
                    }
                }
            };

            mPcuTask = new PcuTask(this.mParam.mPcuFilePath);
            //执行结束回调
            mPcuTask.TaskDoneHandler += (object sender, EventArgs e) =>
            {
                TaskArgs mArgs = e as TaskArgs;
                if (mParam.bCCU && mArgs.level == Task_Level.TASK_PASS)
                {
                    if (mCcuTask != null)
                    {
                        mCcuTask.ExcuteTask();
                    }
                }
                else
                {
                    bTaskRunning           = false;
                    mResetEcuParam.cmdCode = 0x02; //升级失败或者其他,恢复同步指令
                    mResetEcuTask.Excute();
                    Thread.Sleep(10);
                    mResetEcuTask.Excute();
                    Thread.Sleep(10);
                    mResetEcuTask.Excute();
                    Thread.Sleep(10);
                    mBroadCastTask.ClosePort();
                }
            };
            //PCU Item
            mPcuTask.PcuLviHandler += (object sender, EventArgs e) =>
            {
                pcuListViewItemHandler(sender, e);
            };
            //PCU 进度回调
            mPcuTask.pcuProgressBarHandler += (object sender, EventArgs e) =>
            {
                pcuProgressBarHandler(sender, e);
            };

            mCcuTask = new CcuTask(this.mParam.mCcuFilePath);
            //执行结束后回调
            mCcuTask.TaskDoneHandler += (object sender, EventArgs e) =>
            {
                bTaskRunning = false;
                TaskArgs mArgs = e as TaskArgs;
                if (mArgs.level == Task_Level.TASK_PASS)
                {
                    mResetEcuParam.cmdCode = 0x01; //升级成功后,进行重启
                }
                else
                {
                    mResetEcuParam.cmdCode = 0x02; //升级失败或者其他,恢复同步指令
                }
                mResetEcuTask.Excute();
                Thread.Sleep(10);
                mResetEcuTask.Excute();
                Thread.Sleep(10);
                mResetEcuTask.Excute();
                Thread.Sleep(10);
                mBroadCastTask.ClosePort();
            };
            //CCU Item
            mCcuTask.CcuLviHandler += (object sender, EventArgs e) =>
            {
                ccuListViewItemHandler(sender, e);
            };
            //CCU 进度回调
            mCcuTask.CcuProgressBarHandler += (object sender, EventArgs e) =>
            {
                ccuProgressBarHandler(sender, e);
            };
        }
Esempio n. 3
0
 private void TaskBuilder()
 {
     //等待信号
     mPcuEvent = new AutoResetEvent(false);
     //升级PCU Task
     this.pcuWorkTask = new System.ComponentModel.BackgroundWorker();
     this.pcuWorkTask.WorkerReportsProgress      = true;
     this.pcuWorkTask.WorkerSupportsCancellation = true;
     this.pcuWorkTask.DoWork             += new System.ComponentModel.DoWorkEventHandler(this.bk_doPcuWork);
     this.pcuWorkTask.ProgressChanged    += new System.ComponentModel.ProgressChangedEventHandler(this.bk_ProgressPcuReport);
     this.pcuWorkTask.RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.bk_PcuCompleted);
     //PCU 升级请求
     mPcuUpgradeStartTask = new SimpleSerialPortTask <PCU_UpgradeStartReq, PCU_UpgradeStartRsp>();
     mPcuStartParam       = mPcuUpgradeStartTask.GetRequestEntity();
     mPcuUpgradeStartTask.RetryMaxCnts = 500;
     mPcuUpgradeStartTask.Timerout     = 20;//10s超时
     mPcuStartParam.deviceType         = 0x07;
     mPcuStartParam.Param1             = 0x0;
     mPcuStartParam.Param2             = 0x11;
     mPcuStartParam.Param3             = 0x22;
     mPcuStartParam.Param4             = 0x33;
     mPcuUpgradeStartTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
     {
         SerialPortEventArgs <PCU_UpgradeStartRsp> mEventArgs = e as SerialPortEventArgs <PCU_UpgradeStartRsp>;
         if (mEventArgs.Data != null)
         {
             mPcuEvent.Set();
         }
         else
         {
             UpdateLviStatus(this, "开始升级请求无回应", Task_Level.TASK_FAIL);
         }
     };
     //PCU 升级开始
     mPcuUpgradeRequestTask = new SimpleSerialPortTask <PCU_UpgradeRequestReq, PCU_UpgradeRequestRsp>();
     mPcuRequestParam       = mPcuUpgradeRequestTask.GetRequestEntity();
     mPcuUpgradeRequestTask.RetryMaxCnts = 3;
     mPcuUpgradeRequestTask.Timerout     = 5 * 1000;//15s超时
     mPcuUpgradeRequestTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
     {
         SerialPortEventArgs <PCU_UpgradeRequestRsp> mEventArgs = e as SerialPortEventArgs <PCU_UpgradeRequestRsp>;
         if (mEventArgs.Data != null)
         {
             if (mEventArgs.Data.status == 0)
             {
                 mPcuEvent.Set();
             }
             else
             {
                 pcuWorkTask.CancelAsync();
                 Thread.Sleep(1);
                 mPcuEvent.Set();
                 UpdateLviStatus(sender, "单包升级开始失败", Task_Level.TASK_FAIL);
                 return;
             }
         }
         else
         {
             UpdateLviStatus(this, "单包升级开始无回应", Task_Level.TASK_FAIL);
         }
     };
     //PCU 升级处理
     mPcuUpgradeProcessTask = new SimpleSerialPortTask <PCU_UpgradeProcessReq, PCU_UpgradeProcessRsp>();
     mPcuProcessParam       = mPcuUpgradeProcessTask.GetRequestEntity();
     mPcuUpgradeProcessTask.RetryMaxCnts = 5;
     mPcuUpgradeProcessTask.Timerout     = 3 * 1000;//10s超时
     mPcuUpgradeProcessTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
     {
         SerialPortEventArgs <PCU_UpgradeProcessRsp> mEventArgs = e as SerialPortEventArgs <PCU_UpgradeProcessRsp>;
         if (mEventArgs.Data != null)
         {
             if (mEventArgs.Data.status == 0)
             {
                 mPcuEvent.Set();
             }
             else if (mEventArgs.Data.status == 1)
             {
                 pcuWorkTask.CancelAsync();
                 Thread.Sleep(1);
                 mPcuEvent.Set();
                 UpdateLviStatus(sender, "升级处理:校验和错误", Task_Level.TASK_FAIL);
             }
             else if (mEventArgs.Data.status == 2)
             {
                 pcuWorkTask.CancelAsync();
                 Thread.Sleep(1);
                 mPcuEvent.Set();
                 UpdateLviStatus(sender, "升级处理:写入错误", Task_Level.TASK_FAIL);
             }
         }
         else
         {
             UpdateLviStatus(sender, "单帧处理无回应", Task_Level.TASK_FAIL);
         }
     };
     //PCU 单次升级结束
     mPcuUpgradeDoneTask = new SimpleSerialPortTask <PCU_UpgradeDoneReq, PCU_UpgradeDoneRsp>();
     mPcuDoneParam       = mPcuUpgradeDoneTask.GetRequestEntity();
     mPcuUpgradeDoneTask.RetryMaxCnts = 4;
     mPcuUpgradeDoneTask.Timerout     = 3 * 1000;//10s超时
     mPcuUpgradeDoneTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
     {
         SerialPortEventArgs <PCU_UpgradeDoneRsp> mEventArgs = e as SerialPortEventArgs <PCU_UpgradeDoneRsp>;
         if (mEventArgs.Data != null)
         {
             if (mEventArgs.Data.command == 0)
             {
                 mPcuEvent.Set();
             }
             else
             {
                 UpdateLviStatus(sender, "单包升级结束失败", Task_Level.TASK_FAIL);
             }
         }
         else
         {
             UpdateLviStatus(sender, "单包升级结束无回应", Task_Level.TASK_FAIL);
         }
     };
     //PCU 跳转运行
     mPcuUpgradeRunningTask = new SimpleSerialPortTask <PCU_UpgradeRunningReq, PCU_UpgradeRunningRsp>();
     mPcuRunningParam       = mPcuUpgradeRunningTask.GetRequestEntity();
     mPcuUpgradeRunningTask.RetryMaxCnts = 10;
     mPcuUpgradeRunningTask.Timerout     = 1000;//5s超时
     mPcuRunningParam.devType            = 0x07;
     mPcuUpgradeRunningTask.SimpleSerialPortTaskOnPostExecute += (object sender, EventArgs e) =>
     {
         SerialPortEventArgs <PCU_UpgradeRunningRsp> mEventArgs = e as SerialPortEventArgs <PCU_UpgradeRunningRsp>;
         if (mEventArgs.Data != null)
         {
             mPcuEvent.Set();
         }
         else
         {
             UpdateLviStatus(sender, "跳转失败", Task_Level.TASK_FAIL);
         }
     };
 }