Exemplo n.º 1
0
        private void button8_Click(object sender, EventArgs e)
        {
            ACMD_MCS datainfo = BCApp.SCApplication.CMDBLL.LoadCmdData().First();

            #region 新增OHT命令
            ACMD_OHTC cmdohtc = new ACMD_OHTC
            {
                CMD_ID                = datainfo.CMD_ID,
                CARRIER_ID            = datainfo.CARRIER_ID,
                BOX_ID                = datainfo.BOX_ID,
                VH_ID                 = comboBox12.Text,
                CMD_ID_MCS            = datainfo.CMD_ID,
                CMD_TPYE              = 0,
                PRIORITY              = 50,
                SOURCE                = datainfo.HOSTSOURCE,
                DESTINATION           = datainfo.HOSTDESTINATION,
                CMD_STAUS             = 0,
                CMD_PROGRESS          = 0,
                ESTIMATED_EXCESS_TIME = 0,
                REAL_CMP_TIME         = 0,
                ESTIMATED_TIME        = 50
            };

            BCApp.SCApplication.CMDBLL.creatCommand_OHTC(cmdohtc);
            #endregion
        }
        public ACMD_OHTC GetCmd_OhtcByID(string cmdID)
        {
            ACMD_OHTC cmd = null;

            using (DBConnection_EF con = DBConnection_EF.GetUContext())
            {
                cmd = cmd_ohtcDAO.getByID(con, cmdID);
            }
            return(cmd);
        }
        public override void doShareMemoryInit(BCFAppConstants.RUN_LEVEL runLevel)
        {
            try
            {
                switch (runLevel)
                {
                case BCFAppConstants.RUN_LEVEL.ZERO:
                    //scApp.MapBLL.addVehicle(eqpt.VEHICLE_ID);
                    //eqpt.VID_Collection.VID_70_VehicleID.VEHILCE_ID = eqpt.VEHICLE_ID;
                    if (eqpt != null)
                    {
                        if (!SCUtility.isEmpty(eqpt.OHTC_CMD))
                        {
                            ACMD_OHTC     aCMD_OHTC      = scApp.CMDBLL.getExcuteCMD_OHTCByCmdID(eqpt.OHTC_CMD);
                            string[]      PredictPath    = scApp.CMDBLL.loadPassSectionByCMDID(eqpt.OHTC_CMD);
                            List <string> segments       = new List <string>();
                            string        pre_segment_id = null;
                            foreach (string section_id in PredictPath)
                            {
                                ASECTION section = scApp.SectionBLL.cache.GetSection(section_id);
                                if (!SCUtility.isMatche(pre_segment_id, section.SEG_NUM))
                                {
                                    segments.Add(section.SEG_NUM.Trim());
                                    pre_segment_id = section.SEG_NUM;
                                }
                            }
                            scApp.CMDBLL.setVhExcuteCmdToShow(aCMD_OHTC, this.eqpt, segments, PredictPath, null,
                                                              new List <string>(), new List <string>());
                        }
                    }

                    //先讓車子一開始都當作是"VehicleInstall"的狀態
                    //之後要從DB得知上次的狀態,是否為Remove
                    eqpt.VehicleInstall();

                    break;

                case BCFAppConstants.RUN_LEVEL.ONE:
                    break;

                case BCFAppConstants.RUN_LEVEL.TWO:
                    break;

                case BCFAppConstants.RUN_LEVEL.NINE:
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exection:");
            }
        }
Exemplo n.º 4
0
 public void DeleteCmdData(DBConnection_EF conn, ACMD_OHTC cmddata)
 {
     try
     {
         conn.ACMD_OHTC.Remove(cmddata);
         conn.SaveChanges();
     }
     catch (Exception ex)
     {
         //logger.Warn(ex);
         throw;
     }
 }
Exemplo n.º 5
0
        private void button30_Click(object sender, EventArgs e)
        {
            var       OHT        = BCApp.SCApplication.CMDBLL.GetOHTCmd();
            ACMD_OHTC ohtCmdData = OHT.First();

            BCApp.SCApplication.TransferService.OHT_TransferStatus(ohtCmdData.CMD_ID, comboBox12.Text.Trim(), ohtStatus[comboBox6.SelectedIndex]);

            if (ohtStatus[comboBox6.SelectedIndex] == ACMD_MCS.COMMAND_STATUS_BIT_INDEX_COMMNAD_FINISH)
            {
                BCApp.SCApplication.CMDBLL.DeleteOHTCmd(ohtCmdData.CMD_ID);
                comboBox6.SelectedIndex = 1;
            }
            else
            {
                comboBox6.SelectedIndex = comboBox6.SelectedIndex + 1;
            }
        }
Exemplo n.º 6
0
 public void setCommandToFlexsimDB(ACMD_OHTC cmd)
 {
     //switch (cmd.CMD_TPYE)
     //{
     //    case E_CMD_TYPE.Move:
     //    case E_CMD_TYPE.Move_Park:
     //    case E_CMD_TYPE.Move_MTPort:
     //        setCommandToFlexsimDB(cmd.VH_ID, cmd.DESTINATION, "0",
     //                                         cmd.DESTINATION, "0",
     //                                         cmd.CARRIER_ID);
     //        break;
     //    default:
     //        setCommandToFlexsimDB(cmd.VH_ID, cmd.SOURCE, "1",
     //                                         cmd.DESTINATION, "1",
     //                                         cmd.CARRIER_ID);
     //        break;
     //}
 }
Exemplo n.º 7
0
        /// <summary>
        /// Does the share memory initialize.
        /// </summary>
        /// <param name="runLevel">The run level.</param>
        public override void doShareMemoryInit(BCFAppConstants.RUN_LEVEL runLevel)
        {
            try
            {
                switch (runLevel)
                {
                case BCFAppConstants.RUN_LEVEL.ZERO:
                    //scApp.MapBLL.addVehicle(eqpt.VEHICLE_ID);
                    //eqpt.VID_Collection.VID_70_VehicleID.VEHILCE_ID = eqpt.VEHICLE_ID;
                    if (eqpt != null)
                    {
                        if (!SCUtility.isEmpty(eqpt.OHTC_CMD))
                        {
                            ACMD_OHTC aCMD_OHTC   = scApp.CMDBLL.getExcuteCMD_OHTCByCmdID(eqpt.OHTC_CMD);
                            string[]  PredictPath = scApp.CMDBLL.loadPassSectionByCMDID(eqpt.OHTC_CMD);
                            scApp.CMDBLL.setVhExcuteCmdToShow(aCMD_OHTC, this.eqpt, PredictPath, null);
                        }
                    }
                    //先讓車子一開始都當作是"VehicleInstall"的狀態
                    //之後要從DB得知上次的狀態,是否為Remove
                    if (eqpt.IS_INSTALLED)
                    {
                        eqpt.VehicleInstall();
                    }

                    break;

                case BCFAppConstants.RUN_LEVEL.ONE:
                    break;

                case BCFAppConstants.RUN_LEVEL.TWO:
                    break;

                case BCFAppConstants.RUN_LEVEL.NINE:
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exection:");
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Does the share memory initialize.
        /// </summary>
        /// <param name="runLevel">The run level.</param>
        public override void doShareMemoryInit(BCFAppConstants.RUN_LEVEL runLevel)
        {
            try
            {
                switch (runLevel)
                {
                case BCFAppConstants.RUN_LEVEL.ZERO:
                    if (eqpt != null)
                    {
                        if (!SCUtility.isEmpty(eqpt.OHTC_CMD))
                        {
                            ACMD_OHTC aCMD_OHTC   = scApp.CMDBLL.getExcuteCMD_OHTCByCmdID(eqpt.OHTC_CMD);
                            string[]  PredictPath = scApp.CMDBLL.loadPassSectionByCMDID(eqpt.OHTC_CMD);
                            scApp.CMDBLL.setVhExcuteCmdToShow(aCMD_OHTC, this.eqpt, PredictPath, null, null, null);
                        }
                    }
                    if (eqpt.IS_INSTALLED)
                    {
                        eqpt.VehicleInstall();
                    }

                    break;

                case BCFAppConstants.RUN_LEVEL.ONE:
                    break;

                case BCFAppConstants.RUN_LEVEL.TWO:
                    break;

                case BCFAppConstants.RUN_LEVEL.NINE:
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exection:");
            }
        }
Exemplo n.º 9
0
        public void ProcessOHCVAbnormallyScenario(ANODE node)
        {
            if (node == null)
            {
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(RoadControlService), Device: "OHxC",
                              Data: $"Start process ohcv node abnormally scenario, but ohcv node object is null.");
                return;
            }

            string segment_location = node.SegmentLocation;

            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                          Data: $"Start process ohcv node id:{node?.NODE_ID} abnormal scenario...",
                          VehicleID: node?.NODE_ID);
            //直接將該段Segment封閉
            doEnableDisableSegment(segment_location, E_PORT_STATUS.OutOfService, ASEGMENT.DisableType.Safety, Data.SECS.CSOT.SECSConst.LANECUTTYPE_LaneCutOnHMI);

            //當CV的門突然被開啟時,要即將經過該CV所在的VH下達Pause的命令
            List <string> will_be_pass_cmd_ids = null;
            bool          has_cmd_will_pass    = CMDBLL.HasCmdWillPassSegment(segment_location, out will_be_pass_cmd_ids);

            if (has_cmd_will_pass)
            {
                foreach (string cmd_id in will_be_pass_cmd_ids)
                {
                    ACMD_OHTC cmd_obj = CMDBLL.getExcuteCMD_OHTCByCmdID(cmd_id);
                    if (cmd_obj != null)
                    {
                        //要改成一直下達pause命令,直到OHT回復成功為止。
                        Task.Run(() => ProcessUrgentPauseBySafty(cmd_obj.VH_ID));
                    }
                }
            }
            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                          Data: $"End process ohcv node id:{node?.NODE_ID} abnormal scenario.",
                          VehicleID: node?.NODE_ID);
        }
Exemplo n.º 10
0
 public void add(DBConnection_EF con, ACMD_OHTC blockObj)
 {
     blockObj.CMD_INSER_TIME = DateTime.Now;
     con.ACMD_OHTC.Add(blockObj);
     con.SaveChanges();
 }
Exemplo n.º 11
0
 public void update(DBConnection_EF con, ACMD_OHTC ohtCmd)
 {
     con.SaveChanges();
 }
        private void RegisterVehilceEvent()
        {
            Get["AVEHICLES/{ID}"] = (p) =>
            {
                string   vh_id    = p.ID;
                AVEHICLE vh       = SCApplication.getInstance().VehicleBLL.getVehicleByID(vh_id);
                var      response = (Response)vh.ToString();
                response.ContentType = restfulContentType;

                return(response);
            };
            Get["AVEHICLES"] = (p) =>
            {
                string          vh_id    = p.ID;
                List <AVEHICLE> vhs      = SCApplication.getInstance().getEQObjCacheManager().getAllVehicle();
                var             response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };
            //Get["AVEHICLES/(?<all>)"] = (p) =>
            Get["AVEHICLES/_search"] = (p) =>
            {
                List <AVEHICLE> vhs = null;

                foreach (string name in Request.Query)
                {
                    switch (name)
                    {
                    case "SectionID":
                        string sec_id = Request.Query[name] ?? string.Empty;
                        vhs = SCApplication.getInstance().VehicleBLL.loadVehicleBySEC_ID(sec_id);
                        break;
                    }
                }
                var response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["metrics"] = (p) =>
            {
                int total_idle_vh_clean        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Clean);
                int total_idle_vh_Dirty        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Dirty);
                int total_cmd_is_queue_count   = SCApplication.getInstance().CMDBLL.getCMD_MCSIsQueueCount();
                int total_cmd_is_running_count = SCApplication.getInstance().CMDBLL.getCMD_MCSIsRunningCount();

                string ohxc_excute_info = string.Empty;

                StringBuilder sb = new StringBuilder();
                setOhxCContent(sb, nameof(total_idle_vh_clean), total_idle_vh_clean, "current idle clean car");
                setOhxCContent(sb, nameof(total_idle_vh_Dirty), total_idle_vh_Dirty, "current idle dirty car");
                setOhxCContent(sb, nameof(total_cmd_is_queue_count), total_cmd_is_queue_count, "cmd number being queued");
                setOhxCContent(sb, nameof(total_cmd_is_running_count), total_cmd_is_running_count, "cmd number being executed");

                var response = (Response)sb.ToString();
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ViewerUpdate"] = (p) =>
            {
                SCApplication   scApp = SCApplication.getInstance();
                List <AVEHICLE> vhs   = scApp.getEQObjCacheManager().getAllVehicle();

                //foreach (AVEHICLE vh in vhs)
                //{
                //    scApp.VehicleService.PublishVhInfo(vh, null);
                //    SpinWait.SpinUntil(() => false, 10);
                //}

                var response = (Response)"OK";
                response.ContentType = restfulContentType;
                return(response);
            };

            //Post["api/io/T2STK100T01/waitin/CST01"] = (p) =>
            //{

            //    var response = (Response)"OK";
            //    response.ContentType = restfulContentType;
            //    return response;
            //};


            Post["AVEHICLES/SendCommand"] = (p) =>
            {
                var        scApp        = SCApplication.getInstance();
                bool       isSuccess    = true;
                string     vh_id        = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string     carrier_id   = Request.Query.carrier_id.Value ?? Request.Form.carrier_id.Value ?? string.Empty;
                string     from_port_id = Request.Query.from_port_id.Value ?? Request.Form.from_port_id.Value ?? string.Empty;
                string     to_port_id   = Request.Query.to_port_id.Value ?? Request.Form.to_port_id.Value ?? string.Empty;
                E_CMD_TYPE e_cmd_type   = default(E_CMD_TYPE);
                string     cmd_type     = Request.Query.cmd_type.Value ?? Request.Form.cmd_type.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    ACMD_OHTC cmd_obj  = null;
                    AVEHICLE  assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;
                    if (isSuccess)
                    {
                        isSuccess = Enum.TryParse(cmd_type, out e_cmd_type);
                        if (isSuccess)
                        {
                            switch (e_cmd_type)
                            {
                            case E_CMD_TYPE.Move:
                            case E_CMD_TYPE.Load:
                            case E_CMD_TYPE.Unload:
                            case E_CMD_TYPE.LoadUnload:
                            case E_CMD_TYPE.MoveToMTL:
                            case E_CMD_TYPE.SystemOut:
                                string from_adr = from_port_id;
                                string to_adr   = to_port_id;
                                //scApp.MapBLL.getAddressID(from_port_id, out from_adr);
                                //scApp.MapBLL.getAddressID(to_port_id, out to_adr);
                                scApp.CMDBLL.doCreatTransferCommand(vh_id, out cmd_obj,
                                                                    cmd_type: e_cmd_type,
                                                                    source: from_adr,
                                                                    destination: to_adr,
                                                                    carrier_id: carrier_id,
                                                                    gen_cmd_type: SCAppConstants.GenOHxCCommandType.Manual);
                                sc.BLL.CMDBLL.OHTCCommandCheckResult check_result_info =
                                    sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.OHTCCommandCheckResult>
                                        (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT);
                                isSuccess = check_result_info.IsSuccess;
                                result    = check_result_info.ToString();
                                if (isSuccess)
                                {
                                    isSuccess = scApp.VehicleService.doSendOHxCCmdToVh(assignVH, cmd_obj);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command to vehicle failed!";
                                    }
                                }
                                else
                                {
                                    result = "Command create failed!";
                                    //bcf.App.BCFApplication.onWarningMsg(this, new bcf.Common.LogEventArgs("Command create fail.", check_result_info.Num));
                                }
                                break;

                            case E_CMD_TYPE.Home:
                                string cmd_id = scApp.SequenceBLL.getCommandID(SCAppConstants.GenOHxCCommandType.Manual);
                                isSuccess = scApp.VehicleService.TransferRequset(vh_id, cmd_id, ActiveType.Home,
                                                                                 "", new string[0], new string[0], "", "");
                                break;

                            case E_CMD_TYPE.Teaching:
                                isSuccess = scApp.VehicleService.TeachingRequest(vh_id, from_port_id, to_port_id);
                                break;
                            }
                        }
                        else
                        {
                            result = $"Try parse Command Type:[{cmd_type}] failed!";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendReset"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string result    = string.Empty;
                try
                {
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(VehicleInfo), Device: "OHTC",
                                  Data: $"Process vh:{vh_id} position reset request from viewer...",
                                  VehicleID: vh_id);
                    AVEHICLE assignVH = null;
                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;
                    //確認要求的VH,是否存在
                    if (isSuccess)
                    {
                        if (assignVH == null)
                        {
                            isSuccess = false;
                            result    = $"vh:{vh_id} is not exist.";
                        }
                    }
                    //確認是否還是連線著,如果是,則不能夠進行位置的重置
                    if (isSuccess)
                    {
                        if (assignVH.isTcpIpConnect)
                        {
                            isSuccess = false;
                            result    = $"vh:{vh_id} current is connect. can't excute reset.";
                        }
                    }
                    //確認該Vh是否還有Block,如果有也不能重置
                    if (isSuccess)
                    {
                        var non_release_block = scApp.MapBLL.loadNonReleaseBlockQueueByCarID(vh_id);
                        if (non_release_block != null && non_release_block.Count > 0)
                        {
                            isSuccess = false;
                            result    = $"vh:{vh_id} current has blocking zone, can't excute. please check block management.";
                        }
                    }
                    if (isSuccess)
                    {
                        //isSuccess = scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                        isSuccess = scApp.VehicleService.VhPositionReset(vh_id);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "excute reset failed.";
                        }
                    }
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(VehicleInfo), Device: "OHTC",
                                  Data: $"End process vh:{vh_id} position reset request from viewer. is success:{isSuccess} result:{result}",
                                  VehicleID: vh_id);
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendCancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    AVEHICLE assignVH = null;

                    assignVH = scApp.VehicleBLL.getVehicleByID(vh_id);

                    isSuccess = assignVH != null;

                    if (isSuccess)
                    {
                        string mcs_cmd_id = assignVH.MCS_CMD;
                        if (!string.IsNullOrWhiteSpace(mcs_cmd_id))
                        {
                            ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                            if (mcs_cmd == null)
                            {
                                result = $"Can't find MCS command:[{mcs_cmd_id}] in database.";
                            }
                            else
                            {
                                CMDCancelType actType = default(CMDCancelType);
                                if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                                {
                                    actType   = CMDCancelType.CmdCancel;
                                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command cancel/abort failed.";
                                    }
                                }
                                else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                                {
                                    actType   = CMDCancelType.CmdAbort;
                                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command cancel/abort failed.";
                                    }
                                }
                                else
                                {
                                    result = $"MCS command:[{mcs_cmd_id}] can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                                }
                            }
                        }
                        else
                        {
                            string ohtc_cmd_id = assignVH.OHTC_CMD;
                            if (string.IsNullOrWhiteSpace(ohtc_cmd_id))
                            {
                                result = $"Vehicle:[{vh_id}] do not have command.";
                            }
                            else
                            {
                                ACMD_OHTC ohtc_cmd = scApp.CMDBLL.getCMD_OHTCByID(ohtc_cmd_id);
                                if (ohtc_cmd == null)
                                {
                                    result = $"Can't find vehicle command:[{ohtc_cmd_id}] in database.";
                                }
                                else
                                {
                                    CMDCancelType actType = ohtc_cmd.CMD_STAUS >= E_CMD_STATUS.Execution ? CMDCancelType.CmdAbort : CMDCancelType.CmdCancel;
                                    isSuccess = scApp.VehicleService.doAbortCommand(assignVH, ohtc_cmd_id, actType);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send vehicle status request failed.";
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseEvent"] = (p) =>
            {
                bool          isSuccess  = false;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                PauseEvent    pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(event_type, out pauseEvent);
                if (isSuccess)
                {
                    isSuccess = scApp.VehicleService.PauseRequest
                                    (vh_id, pauseEvent, SCAppConstants.OHxCPauseType.Normal);
                }

                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };


            Post["AVEHICLES/PauseStatusChange"] = (p) =>
            {
                bool          isSuccess  = false;
                string        result     = string.Empty;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        pauseType  = Request.Query.pauseType.Value ?? Request.Form.pauseType.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                SCAppConstants.OHxCPauseType pause_type = default(SCAppConstants.OHxCPauseType);
                PauseEvent pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(pauseType, out pause_type);

                if (isSuccess)
                {
                    isSuccess = Enum.TryParse(event_type, out pauseEvent);

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.PauseRequest
                                        (vh_id, pauseEvent, pause_type);
                        if (isSuccess)
                        {
                            //AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            //vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Send pause request to vehicle:{vh_id} failed.";
                        }
                    }
                    else
                    {
                        result = $"Can't recognize Pause Event:{event_type}.";
                    }
                }
                else
                {
                    result = $"Can't recognize Pause Type:{pauseType}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ModeStatusChange"] = (p) =>
            {
                bool          isSuccess   = false;
                string        result      = string.Empty;
                SCApplication scApp       = SCApplication.getInstance();
                string        vh_id       = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        modeStatus  = Request.Query.modeStatus.Value ?? Request.Form.modeStatus.Value ?? string.Empty;
                VHModeStatus  mode_status = default(VHModeStatus);
                isSuccess = Enum.TryParse(modeStatus, out mode_status);

                if (isSuccess)
                {
                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleBLL.updataVehicleMode(vh_id, mode_status);
                        if (isSuccess)
                        {
                            AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Update vehicle:{vh_id} mode status failed.";
                        }
                    }
                }
                else
                {
                    result = $"Can't recognize mode status:{modeStatus}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ResetAlarm"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["Engineer/ForceCmdFinish"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                bool   isSuccess = scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                if (isSuccess)
                {
                    var vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                    vh.NotifyVhExcuteCMDStatusChange();
                }
                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };
        }
        private void RegisterVehilceEvent()
        {
            Get["AVEHICLES/{ID}"] = (p) =>
            {
                string   vh_id    = p.ID;
                AVEHICLE vh       = SCApplication.getInstance().VehicleBLL.getVehicleByID(vh_id);
                var      response = (Response)vh.ToString();
                response.ContentType = restfulContentType;

                return(response);
            };
            Get["AVEHICLES"] = (p) =>
            {
                string          vh_id    = p.ID;
                List <AVEHICLE> vhs      = SCApplication.getInstance().getEQObjCacheManager().getAllVehicle();
                var             response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };
            //Get["AVEHICLES/(?<all>)"] = (p) =>
            Get["AVEHICLES/_search"] = (p) =>
            {
                List <AVEHICLE> vhs = null;

                foreach (string name in Request.Query)
                {
                    switch (name)
                    {
                    case "SectionID":
                        string sec_id = Request.Query[name] ?? string.Empty;
                        vhs = SCApplication.getInstance().VehicleBLL.loadVehicleBySEC_ID(sec_id);
                        break;
                    }
                }
                var response = (Response)JsonConvert.SerializeObject(vhs);
                response.ContentType = restfulContentType;

                return(response);
            };

            Get["metrics"] = (p) =>
            {
                int total_idle_vh_clean        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Clean);
                int total_idle_vh_Dirty        = SCApplication.getInstance().VehicleBLL.getNoExcuteMcsCmdVhCount(E_VH_TYPE.Dirty);
                int total_cmd_is_queue_count   = SCApplication.getInstance().CMDBLL.getCMD_MCSIsQueueCount();
                int total_cmd_is_running_count = SCApplication.getInstance().CMDBLL.getCMD_MCSIsRunningCount();

                string ohxc_excute_info = string.Empty;

                StringBuilder sb = new StringBuilder();
                setOhxCContent(sb, nameof(total_idle_vh_clean), total_idle_vh_clean, "current idle clean car");
                setOhxCContent(sb, nameof(total_idle_vh_Dirty), total_idle_vh_Dirty, "current idle dirty car");
                setOhxCContent(sb, nameof(total_cmd_is_queue_count), total_cmd_is_queue_count, "cmd number being queued");
                setOhxCContent(sb, nameof(total_cmd_is_running_count), total_cmd_is_running_count, "cmd number being executed");

                var response = (Response)sb.ToString();
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ViewerUpdate"] = (p) =>
            {
                SCApplication   scApp = SCApplication.getInstance();
                List <AVEHICLE> vhs   = scApp.getEQObjCacheManager().getAllVehicle();

                //foreach (AVEHICLE vh in vhs)
                //{
                //    scApp.VehicleService.PublishVhInfo(vh, null);
                //    SpinWait.SpinUntil(() => false, 10);
                //}

                var response = (Response)"OK";
                response.ContentType = restfulContentType;
                return(response);
            };

            //Post["api/io/T2STK100T01/waitin/CST01"] = (p) =>
            //{
            //    var response = (Response)"OK";
            //    response.ContentType = restfulContentType;
            //    return response;
            //};

            Post["AVEHICLES/SendCommand"] = (p) =>
            {
                var        scApp        = SCApplication.getInstance();
                bool       isSuccess    = true;
                string     vh_id        = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string     cst_id       = Request.Query.cst_id.Value ?? Request.Form.cst_id.Value ?? string.Empty;
                string     box_id       = Request.Query.box_id.Value ?? Request.Form.box_id.Value ?? string.Empty;
                string     lot_id       = Request.Query.lot_id.Value ?? Request.Form.lot_id.Value ?? string.Empty;
                string     from_port_id = Request.Query.from_port_id.Value ?? Request.Form.from_port_id.Value ?? string.Empty;
                string     to_port_id   = Request.Query.to_port_id.Value ?? Request.Form.to_port_id.Value ?? string.Empty;
                E_CMD_TYPE e_cmd_type   = default(E_CMD_TYPE);
                string     cmd_type     = Request.Query.cmd_type.Value ?? Request.Form.cmd_type.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    ACMD_OHTC cmd_obj  = null;
                    AVEHICLE  assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;
                    if (isSuccess)
                    {
                        isSuccess = Enum.TryParse(cmd_type, out e_cmd_type);
                        if (isSuccess)
                        {
                            switch (e_cmd_type)
                            {
                            case E_CMD_TYPE.Move:
                            case E_CMD_TYPE.Scan:
                            case E_CMD_TYPE.Load:
                            case E_CMD_TYPE.Unload:
                            case E_CMD_TYPE.LoadUnload:
                            case E_CMD_TYPE.MoveToMTL:
                            case E_CMD_TYPE.SystemOut:
                                string from_adr = "";
                                string to_adr   = "";
                                scApp.MapBLL.getAddressID(from_port_id, out from_adr);
                                scApp.MapBLL.getAddressID(to_port_id, out to_adr);

                                scApp.CMDBLL.doCreatTransferCommand(vh_id, out cmd_obj,
                                                                    cmd_type: e_cmd_type,
                                                                    source: from_port_id,
                                                                    destination: to_port_id,
                                                                    cst_id: cst_id,
                                                                    box_id: box_id,
                                                                    lot_id: lot_id,
                                                                    source_address: from_adr,
                                                                    destination_address: to_adr,
                                                                    gen_cmd_type: SCAppConstants.GenOHxCCommandType.Manual);
                                sc.BLL.CMDBLL.OHTCCommandCheckResult check_result_info =
                                    sc.BLL.CMDBLL.getCallContext <sc.BLL.CMDBLL.OHTCCommandCheckResult>
                                        (sc.BLL.CMDBLL.CALL_CONTEXT_KEY_WORD_OHTC_CMD_CHECK_RESULT);
                                isSuccess = check_result_info.IsSuccess;
                                result    = check_result_info.ToString();
                                if (isSuccess)
                                {
                                    isSuccess = scApp.VehicleService.doSendOHxCCmdToVh(assignVH, cmd_obj);
                                    if (isSuccess)
                                    {
                                        result = "OK";
                                    }
                                    else
                                    {
                                        result = "Send command to vehicle failed!";
                                    }
                                }
                                else
                                {
                                    result = "Command create failed!";
                                    //bcf.App.BCFApplication.onWarningMsg(this, new bcf.Common.LogEventArgs("Command create fail.", check_result_info.Num));
                                }
                                break;

                            case E_CMD_TYPE.Home:
                                string cmd_id = scApp.SequenceBLL.getCommandID(SCAppConstants.GenOHxCCommandType.Manual);
                                //isSuccess = scApp.VehicleService.TransferRequset(vh_id, cmd_id, ActiveType.Home,
                                //                                    "", "", "", new string[0], new string[0], new string[0], new string[0],
                                //                                    "", "", "", "");
                                break;

                            case E_CMD_TYPE.Teaching:
                                isSuccess = scApp.VehicleService.TeachingRequest(vh_id, from_port_id, to_port_id);
                                break;
                            }
                        }
                        else
                        {
                            result = $"Try parse Command Type:[{cmd_type}] failed!";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendReset"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                try
                {
                    AVEHICLE assignVH = null;

                    assignVH  = scApp.VehicleBLL.getVehicleByID(vh_id);
                    isSuccess = assignVH != null;

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                        if (isSuccess)
                        {
                            result = "OK";
                        }
                        else
                        {
                            result = "Send vehicle status request failed.";
                        }
                    }
                    else
                    {
                        result = $"Vehicle :[{vh_id}] not found!";
                    }
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/SendCancelAbort"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                string result = string.Empty;
                //try
                //{
                //    AVEHICLE assignVH = null;

                //    assignVH = scApp.VehicleBLL.getVehicleByID(vh_id);

                //    isSuccess = assignVH != null;

                //    if (isSuccess)
                //    {
                //        string mcs_cmd_id = assignVH.MCS_CMD;
                //        if (!string.IsNullOrWhiteSpace(mcs_cmd_id))
                //        {
                //            ACMD_MCS mcs_cmd = scApp.CMDBLL.getCMD_MCSByID(mcs_cmd_id);
                //            if (mcs_cmd == null)
                //            {
                //                result = $"Can't find MCS command:[{mcs_cmd_id}] in database.";
                //            }
                //            else
                //            {
                //                CMDCancelType actType = default(CMDCancelType);
                //                if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Transferring)
                //                {
                //                    actType = CMDCancelType.CmdCancel;
                //                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                //                    if (isSuccess) result = "OK";
                //                    else result = "Send command cancel/abort failed.";
                //                }
                //                else if (mcs_cmd.TRANSFERSTATE < sc.E_TRAN_STATUS.Canceling)
                //                {
                //                    actType = CMDCancelType.CmdAbort;
                //                    isSuccess = scApp.VehicleService.doCancelOrAbortCommandByMCSCmdID(mcs_cmd_id, actType);
                //                    if (isSuccess) result = "OK";
                //                    else result = "Send command cancel/abort failed.";
                //                }
                //                else
                //                {
                //                    result = $"MCS command:[{mcs_cmd_id}] can't excute cancel / abort,\r\ncurrent state:{mcs_cmd.TRANSFERSTATE}";
                //                }
                //            }
                //        }
                //        else
                //        {
                //            string ohtc_cmd_id = assignVH.OHTC_CMD;
                //            if (string.IsNullOrWhiteSpace(ohtc_cmd_id))
                //            {
                //                result = $"Vehicle:[{vh_id}] do not have command.";
                //            }
                //            else
                //            {
                //                ACMD_OHTC ohtc_cmd = scApp.CMDBLL.getCMD_OHTCByID(ohtc_cmd_id);
                //                if (ohtc_cmd == null)
                //                {
                //                    result = $"Can't find vehicle command:[{ohtc_cmd_id}] in database.";
                //                }
                //                else
                //                {
                //                    CMDCancelType actType = ohtc_cmd.CMD_STAUS >= E_CMD_STATUS.Execution ? CMDCancelType.CmdAbort : CMDCancelType.CmdCancel;
                //                    isSuccess = scApp.VehicleService.doAbortCommand(assignVH, ohtc_cmd_id, actType);
                //                    if (isSuccess)
                //                    {
                //                        result = "OK";
                //                    }
                //                    else
                //                    {
                //                        result = "Send vehicle status request failed.";
                //                    }
                //                }
                //            }
                //        }
                //    }
                //    else
                //    {
                //        result = $"Vehicle :[{vh_id}] not found!";
                //    }
                //}
                //catch (Exception ex)
                //{
                //    isSuccess = false;
                //    result = "Execption happend!";
                //    logger.Error(ex, "Execption:");
                //}
                (isSuccess, result) = scApp.VehicleService.ProcessVhCmdCancelAbortRequest(vh_id);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseEvent"] = (p) =>
            {
                bool          isSuccess  = false;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                PauseEvent    pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(event_type, out pauseEvent);
                if (isSuccess)
                {
                    isSuccess = scApp.VehicleService.PauseRequest
                                    (vh_id, pauseEvent, SCAppConstants.OHxCPauseType.Normal);
                }

                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/PauseStatusChange"] = (p) =>
            {
                bool          isSuccess  = false;
                string        result     = string.Empty;
                SCApplication scApp      = SCApplication.getInstance();
                string        vh_id      = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        pauseType  = Request.Query.pauseType.Value ?? Request.Form.pauseType.Value ?? string.Empty;
                string        event_type = Request.Query.event_type.Value ?? Request.Form.event_type.Value ?? string.Empty;
                SCAppConstants.OHxCPauseType pause_type = default(SCAppConstants.OHxCPauseType);
                PauseEvent pauseEvent = default(PauseEvent);
                isSuccess = Enum.TryParse(pauseType, out pause_type);

                if (isSuccess)
                {
                    isSuccess = Enum.TryParse(event_type, out pauseEvent);

                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleService.PauseRequest
                                        (vh_id, pauseEvent, pause_type);
                        if (isSuccess)
                        {
                            //AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            //vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Send pause request to vehicle:{vh_id} failed.";
                        }
                    }
                    else
                    {
                        result = $"Can't recognize Pause Event:{event_type}.";
                    }
                }
                else
                {
                    result = $"Can't recognize Pause Type:{pauseType}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ModeStatusChange"] = (p) =>
            {
                bool          isSuccess   = false;
                string        result      = string.Empty;
                SCApplication scApp       = SCApplication.getInstance();
                string        vh_id       = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                string        modeStatus  = Request.Query.modeStatus.Value ?? Request.Form.modeStatus.Value ?? string.Empty;
                VHModeStatus  mode_status = default(VHModeStatus);
                isSuccess = Enum.TryParse(modeStatus, out mode_status);

                if (isSuccess)
                {
                    if (isSuccess)
                    {
                        isSuccess = scApp.VehicleBLL.updataVehicleMode(vh_id, mode_status);
                        if (isSuccess)
                        {
                            AVEHICLE vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                            vh.NotifyVhStatusChange();
                            result = "OK";
                        }
                        else
                        {
                            result = $"Update vehicle:{vh_id} mode status failed.";
                        }
                    }
                }
                else
                {
                    result = $"Can't recognize mode status:{modeStatus}.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ResetAlarm"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string result    = string.Empty;
                bool   isSuccess = true;
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                try
                {
                    //isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    isSuccess = scApp.TransferService.OHBC_AlarmAllCleared(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/Debug_Function"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                string result     = string.Empty;
                bool   isSuccess  = true;
                string resuleJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resuleJson = reader.ReadToEnd();
                    }
                }
                var     fun_enable         = JsonConvert.DeserializeObject(resuleJson);
                JObject jo                 = JObject.Parse(resuleJson);
                dynamic dyna               = fun_enable as dynamic;
                var     func_num           = dyna.Func_Num?.Value ?? 0;
                string  func_name          = dyna.Func_Name?.Value ?? string.Empty;
                string  vh_id              = dyna.VH_ID?.Value ?? string.Empty;
                string  cst_id             = dyna.Cst_ID?.Value ?? string.Empty;
                string  from_adr           = dyna.From_Adr?.Value ?? string.Empty;
                string  to_adr             = dyna.To_Adr?.Value ?? string.Empty;
                var     operatingMode      = dyna.OperatingMode?.Value ?? null;
                var     operatingPowerMode = dyna.OperatingPowerMode?.Value ?? null;
                var     abort_type         = dyna.Abort_Type?.Value ?? null;
                var     pauseEvent         = dyna.PauseEvent?.Value ?? null;
                var     pauseType          = dyna.PauseType?.Value ?? null;
                var     blockzoneQueue     = dyna.BlockZoneQueue?.Value ?? null;
                var     pauseFirst         = dyna.PauseFirst?.Value ?? null;
                var     seg_id             = dyna.Seg_ID?.Value ?? null;
                //string vh_id = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;

                var noticeCar = scApp.getEQObjCacheManager().getVehicletByVHID(vh_id);
                try
                {
                    if (func_num != 0)
                    {
                        if (func_num is Int64 i)
                        {
                            switch (i)
                            {
                            case 1:
                                asyExecuteAction(scApp.VehicleService.HostBasicVersionReport, vh_id);
                                break;

                            case 2:
                                asyExecuteAction(scApp.VehicleService.HostBasicVersionReport, vh_id);
                                break;

                            case 11:
                                asyExecuteAction(scApp.VehicleService.BasicInfoReport, vh_id);
                                break;

                            case 13:
                                asyExecuteAction(scApp.VehicleService.TavellingDataReport, vh_id);
                                break;

                            case 15:
                                asyExecuteAction(scApp.VehicleService.SectionDataReport, vh_id);
                                break;

                            case 17:
                                asyExecuteAction(scApp.VehicleService.AddressDataReport, vh_id);
                                break;

                            case 19:
                                asyExecuteAction(scApp.VehicleService.ScaleDataReport, vh_id);
                                break;

                            case 21:
                                asyExecuteAction(scApp.VehicleService.ControlDataReport, vh_id);
                                break;

                            case 23:
                                asyExecuteAction(scApp.VehicleService.GuideDataReport, vh_id);
                                break;

                            case 35:
                                scApp.VehicleService.CarrierIDRenameRequset(vh_id, noticeCar.CST_ID, cst_id);
                                break;

                            case 71:
                                scApp.VehicleService.TeachingRequest(vh_id, from_adr, to_adr);
                                break;

                            case 41:
                                OperatingVHMode vhMode = (OperatingVHMode)operatingMode;
                                scApp.VehicleService.ModeChangeRequest(vh_id, vhMode);
                                break;

                            case 45:
                                OperatingPowerMode powerMode = (OperatingPowerMode)operatingPowerMode;
                                scApp.VehicleService.PowerOperatorRequest(vh_id, operatingPowerMode);
                                break;

                            case 37:
                                CMDCancelType cmdCancelType = (CMDCancelType)abort_type;
                                noticeCar.sned_Str37(noticeCar.OHTC_CMD, abort_type);
                                break;

                            case 39:
                                PauseEvent _pauseEvent = (PauseEvent)pauseEvent;
                                PauseType  _pauseType  = (PauseType)pauseType;
                                scApp.VehicleService.PauseRequest(vh_id, _pauseEvent, pauseType);
                                break;

                            case 61:
                                asyExecuteAction(scApp.VehicleService.IndividualUploadRequest, vh_id);
                                break;

                            case 63:
                                asyExecuteAction(scApp.VehicleService.IndividualChangeRequest, vh_id);
                                break;

                            case 91:
                                asyExecuteAction(scApp.VehicleService.AlarmResetRequest, vh_id);
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    else if (!string.IsNullOrEmpty(func_name))
                    {
                        if (func_name is string str)
                        {
                            switch (str)
                            {
                            case "btn_SendAll":
                                asyExecuteAction(scApp.VehicleService.doDataSysc, vh_id);
                                break;

                            case "btn_reset_teach_result":
                                List <ASECTION> sections = scApp.CatchDataFromDB_Section;
                                foreach (var sec in sections)
                                {
                                    if (scApp.MapBLL.resetSecTechingTime(sec.SEC_ID))
                                    {
                                        sec.LAST_TECH_TIME = null;
                                    }
                                }
                                break;

                            case "btn_cmd_override_test":
                                scApp.VehicleService.VhicleChangeThePath(vh_id, pauseFirst);
                                break;

                            case "btn_Force_FinishCmd":
                                scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                                break;

                            case "btn_Refresh_Vh_Status":
                                scApp.VehicleService.VehicleStatusRequest(vh_id, true);
                                break;

                            case "btn_forceReleaseAllBlock":
                                scApp.VehicleService.forceReleaseBlockControl(vh_id);
                                break;

                            case "btn_open_tcp_port":
                                scApp.VehicleService.startVehicleTcpIpServer(vh_id);
                                break;

                            case "btn_close_tcp_port":
                                scApp.VehicleService.stopVehicleTcpIpServer(vh_id);
                                break;

                            case "btn_changeToRemove":
                                if (!noticeCar.IS_INSTALLED)
                                {
                                    result = ($"{vh_id} is removed ready!");
                                    break;
                                }
                                scApp.VehicleService.Remove(vh_id);
                                result = $"{vh_id} remove ok";
                                break;

                            case "btn_changeToInstall":
                                if (noticeCar.IS_INSTALLED)
                                {
                                    result = ($"{vh_id} is install ready!");
                                    break;
                                }
                                scApp.VehicleService.Install(vh_id);
                                result = $"{vh_id} install ok";
                                break;

                            case "btn_changeToAutoRemote":
                                scApp.VehicleService.VehicleAutoModeCahnge(vh_id, VHModeStatus.AutoRemote);
                                break;

                            case "btn_changeToAutoLocal":
                                scApp.VehicleService.VehicleAutoModeCahnge(vh_id, VHModeStatus.AutoLocal);
                                break;

                            case "btn_forceReleaseALLBlock":
                                scApp.VehicleService.forceReleaseBlockControl();
                                break;

                            case "btn_release_block":
                                scApp.VehicleService.reCheckBlockControl(blockzoneQueue);
                                break;

                            case "btn_refresh_vh_order_in_seg":
                                var seg_obj = scApp.SegmentBLL.cache.GetSegment(seg_id);
                                seg_obj.RefreshVhOrder(scApp.VehicleBLL, scApp.SectionBLL);
                                break;

                            case "btn_portInServeice":

                                break;

                            case "btn_portOutOfServeice":

                                break;

                            default:
                                break;
                            }
                        }
                    }

                    isSuccess = scApp.VehicleService.AlarmResetRequest(vh_id);
                    if (isSuccess)
                    {
                        result = "OK";
                    }
                    else
                    {
                        result = "Reset alarm failed.";
                    }
                }
                catch (Exception ex)
                {
                    result = "Reset alarm failedwith exception happened.";
                }

                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["Engineer/ForceCmdFinish"] = (p) =>
            {
                var    scApp     = SCApplication.getInstance();
                string vh_id     = Request.Query.vh_id.Value ?? Request.Form.vh_id.Value ?? string.Empty;
                bool   isSuccess = scApp.CMDBLL.forceUpdataCmdStatus2FnishByVhID(vh_id);
                if (isSuccess)
                {
                    var vh = scApp.VehicleBLL.getVehicleByID(vh_id);
                    vh.NotifyVhExcuteCMDStatusChange();
                }
                var response = (Response)(isSuccess ? "OK" : "NG");
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ScanSelected/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                //string action = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic d = JsonConvert.DeserializeObject(resultJson);
                //string shelf_id = d.shelf_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "ScanSelected",
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    var shelf = d.shelf;
                    foreach (string item in shelf)
                    {
                        if (scApp.TransferService.isShelfPort(item))
                        {
                            scApp.TransferService.SetScanCmd("", "", item);
                        }
                    }
                    //foreach (var v in )
                    //{
                    //	if (isShelfPort(v.Carrier_LOC))
                    //	{
                    //		SetScanCmd("", "", v.Carrier_LOC);
                    //	}
                    //}
                    //bool enable = d.enable?.Value;
                    //string s = scApp.TransferService.Manual_ShelfEnable(shelf_id, enable);
                    isSuccess = true;
                    result    = isSuccess ? "OK" : "Update Shlef Enable failed.";
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };

            Post["AVEHICLES/ScanAll/{UserID}"] = (p) =>
            {
                var    scApp      = SCApplication.getInstance();
                bool   isSuccess  = true;
                bool   allSuccess = true;
                string result     = string.Empty;
                //string action = p.Action.Value;
                string userid     = p.UserID.Value;
                string resultJson = string.Empty;
                using (Stream stream = Request.Body)
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("UTF-8")))
                    {
                        resultJson = reader.ReadToEnd();
                    }
                }
                dynamic d = JsonConvert.DeserializeObject(resultJson);
                //string shelf_id = d.shelf_id?.Value;
                UserOperationLog userOperationLog = new UserOperationLog()
                {
                    Action     = "ScanAll",
                    UserID     = userid,
                    ActionTime = DateTime.Now,
                };
                try
                {
                    scApp.TransferService.ScanALL();
                    isSuccess = true;
                    result    = isSuccess ? "OK" : "Update Shlef Enable failed.";
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Execption happend!";
                    logger.Error(ex, "Execption:");
                }
                SCUtility.UserOperationLog(userOperationLog);
                var response = (Response)result;
                response.ContentType = restfulContentType;
                return(response);
            };
        }
 public void add(DBConnection_EF con, ACMD_OHTC blockObj)
 {
     con.ACMD_OHTC.Add(blockObj);
     con.SaveChanges();
 }
        public void carOutRequestCancle(IMaintainDevice mtx, bool isForceFinish)
        {
            LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(MTLService), Device: SCAppConstants.DeviceName.DEVICE_NAME_MTx,
                          Data: $"Process car out cancel request. mtx:{mtx.DeviceID}, pre car out vh:{mtx.PreCarOutVhID}, is force finish:{isForceFinish}",
                          XID: mtx.DeviceID);
            //將原本的在等待Carout的Vh改回AutoRemote
            mtx.CancelCarOutRequest = true;
            //if (!SCUtility.isEmpty(carOutVhID))
            //{
            //    VehicleService.doRecoverModeStatusToAutoRemote(carOutVhID);
            //}
            //carOutVhID = "";
            if (!SCUtility.isEmpty(mtx.PreCarOutVhID))
            {
                VehicleService.doRecoverModeStatusToAutoRemote(mtx.PreCarOutVhID);
                AVEHICLE pre_car_out_vh = vehicleBLL.cache.getVhByID(mtx.PreCarOutVhID);
                if (!SCUtility.isEmpty(pre_car_out_vh?.OHTC_CMD))
                {
                    ACMD_OHTC cmd = scApp.CMDBLL.getCMD_OHTCByID(pre_car_out_vh.OHTC_CMD);
                    if (cmd != null)
                    {
                        if (cmd.CMD_TPYE == E_CMD_TYPE.MoveToMTL || cmd.CMD_TPYE == E_CMD_TYPE.SystemOut ||
                            cmd.CMD_TPYE == E_CMD_TYPE.SystemIn || cmd.CMD_TPYE == E_CMD_TYPE.MTLHome)
                        {
                            //如果是強制被取消(Safety check突然關閉)的時候,要先下一次暫停給車子
                            if (isForceFinish)
                            {
                                VehicleService.PauseRequest
                                    (pre_car_out_vh.VEHICLE_ID, PauseEvent.Pause, SCAppConstants.OHxCPauseType.Normal);
                            }
                            VehicleService.doAbortCommand
                                (pre_car_out_vh, pre_car_out_vh.OHTC_CMD, ProtocolFormat.OHTMessage.CMDCancelType.CmdCancel);
                        }
                    }
                    else
                    {
                        if (cmd.CMD_TPYE == E_CMD_TYPE.MoveToMTL || cmd.CMD_TPYE == E_CMD_TYPE.SystemOut ||
                            cmd.CMD_TPYE == E_CMD_TYPE.SystemIn || cmd.CMD_TPYE == E_CMD_TYPE.MTLHome)
                        {
                            //如果是強制被取消(Safety check突然關閉)的時候,要先下一次暫停給車子
                            if (isForceFinish)
                            {
                                VehicleService.PauseRequest
                                    (pre_car_out_vh.VEHICLE_ID, PauseEvent.Pause, SCAppConstants.OHxCPauseType.Normal);
                            }
                            VehicleService.doAbortCommand
                                (pre_car_out_vh, pre_car_out_vh.OHTC_CMD, ProtocolFormat.OHTMessage.CMDCancelType.CmdCancel);
                        }
                    }
                }
                //如果OHT已經在MTS/MTL的Segment上時,
                //就不能將他的對應訊號關閉
                if (SCUtility.isMatche(mtx.DeviceSegment, pre_car_out_vh.CUR_SEG_ID))
                {
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(MTLService), Device: SCAppConstants.DeviceName.DEVICE_NAME_MTx,
                                  Data: $"Process car out cancel request. mtx:{mtx.DeviceID}, pre car out vh:{mtx.PreCarOutVhID}, is force finish:{isForceFinish}," +
                                  $"But vh current section is in MTL segment:{mtx.DeviceSegment} .can't trun off car out single ",
                                  XID: mtx.DeviceID);
                    return;
                }
            }

            //mtx.SetCarOutInterlock(false);
            //mtx.PreCarOutVhID = "";

            mtx.PreCarOutVhID = "";
            if (mtx is MaintainLift)
            {
                CarOutFinish(mtx as MaintainLift);
            }
            else if (mtx is MaintainSpace)
            {
                CarOutFinish(mtx as MaintainSpace);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Timer Action的執行動作
        /// </summary>
        /// <param name="obj">The object.</param>
        //public override void doProcess(object obj)
        //{
        //    if (!SystemParameter.AutoOverride)
        //    {
        //        LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(DeadlockCheck), Device: "AGVC",
        //           Data: $"auto override is:{SystemParameter.AutoOverride}.");
        //        return;
        //    }
        //    if (System.Threading.Interlocked.Exchange(ref checkSyncPoint, 1) == 0)
        //    {
        //        try
        //        {
        //            //1.找出發生Reserve要不到而停止的車子,找到以後在找是否有下一台車子也是要不到Reserve的
        //            //發現以後再透過兩台車所要不到的Address找出互卡的是哪段Section,接著將其section所屬的Segment Banned後在執行override
        //            var vhs = scApp.VehicleBLL.cache.loadAllVh();
        //            var vhs_ReserveStop = vhs.Where(v => v.IsReservePause)
        //                                  .OrderBy(v => v.VEHICLE_ID)
        //                                  .ToList();
        //            foreach (var vh_active in vhs_ReserveStop)
        //            {
        //                foreach (var vh_passive in vhs_ReserveStop)
        //                {
        //                    if (vh_active == vh_passive) continue;
        //                    if (!vh_active.IsReservePause || !vh_active.IsReservePause) continue;
        //                    //if (SCUtility.isEmpty(vh_active.OHTC_CMD) || SCUtility.isEmpty(vh_passive.OHTC_CMD)) continue;
        //                    if ((vh_active.CanNotReserveInfo != null && vh_passive.CanNotReserveInfo != null) &&
        //                        SCUtility.isMatche(vh_active.CanNotReserveInfo.ReservedVhID, vh_passive.VEHICLE_ID) &&
        //                        SCUtility.isMatche(vh_passive.CanNotReserveInfo.ReservedVhID, vh_active.VEHICLE_ID))
        //                    //if ((vh_active.CanNotReserveInfo != null && vh_passive.CanNotReserveInfo != null))
        //                    {
        //                        if (vh_active.CurrentFailOverrideTimes >= AVEHICLE.MAX_FAIL_OVERRIDE_TIMES_IN_ONE_CASE &&
        //                            vh_passive.CurrentFailOverrideTimes >= AVEHICLE.MAX_FAIL_OVERRIDE_TIMES_IN_ONE_CASE)
        //                        {
        //                            scApp.VehicleService.onDeadLockProcessFail(vh_active, vh_passive);

        //                            string xid = DateTime.Now.ToString(SCAppConstants.TimestampFormat_19);
        //                            string message = $"dead lock happend ,but dead of vehicles:{vh_active.VEHICLE_ID} and {vh_passive.VEHICLE_ID} has been override more than {AVEHICLE.MAX_FAIL_OVERRIDE_TIMES_IN_ONE_CASE} times, stop auto override." +
        //                                             $"please excute manual avoid.";
        //                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(DeadlockCheck), Device: "AGVC",
        //                               Data: message,
        //                               XID: xid,
        //                               VehicleID: $"{ vh_active.VEHICLE_ID},{ vh_passive.VEHICLE_ID}",
        //                               CarrierID: $"{ SCUtility.Trim(vh_active.CST_ID, true)},{ SCUtility.Trim(vh_passive.CST_ID, true)}");
        //                            BCFApplication.onErrorMsg(this, new bcf.Common.LogEventArgs(message, xid));
        //                            System.Threading.SpinWait.SpinUntil(() => false, 5000);//等待觸發把Auto override關掉。
        //                            return;
        //                        }
        //                        //如果符合上述條件,代表著死結發生了
        //                        List<AVEHICLE> sort_vhs = new List<AVEHICLE>() { vh_active, vh_passive };
        //                        sort_vhs.Sort(SortOverrideOfVehicle);
        //                        foreach (AVEHICLE avoid_vh in sort_vhs)
        //                        {
        //                            if (avoid_vh.CurrentFailOverrideTimes >= AVEHICLE.MAX_FAIL_OVERRIDE_TIMES_IN_ONE_CASE)
        //                            {
        //                                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
        //                                   Data: $"dead lock happend ,but vh:{avoid_vh.VEHICLE_ID} has been override more than {AVEHICLE.MAX_FAIL_OVERRIDE_TIMES_IN_ONE_CASE} times, continue next vh.",
        //                                   VehicleID: avoid_vh.VEHICLE_ID,
        //                                   CarrierID: avoid_vh.CST_ID);
        //                                continue;
        //                            }

        //                            if (avoid_vh.VhAvoidInfo != null)
        //                            {
        //                                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
        //                                   Data: $"dead lock happend ,but vh:{avoid_vh.VEHICLE_ID} has been avoid command , continue next vh." +
        //                                         $"blocked section:{avoid_vh.VhAvoidInfo.BlockedSectionID} blocked vh id:{avoid_vh.VhAvoidInfo.BlockedVehicleID}",
        //                                   VehicleID: avoid_vh.VEHICLE_ID,
        //                                   CarrierID: avoid_vh.CST_ID);
        //                                continue;
        //                            }

        //                            //string current_section_id = selected_vh.CUR_SEC_ID;
        //                            //var check_is_in_traffic_control_section = scApp.TrafficControlBLL.cache.IsTrafficControlSection(current_section_id);
        //                            //if (check_is_in_traffic_control_section.isTrafficControlInfo)
        //                            //{
        //                            //    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
        //                            //       Data: $"dead lock happend ,but vh:{selected_vh.VEHICLE_ID} is in traffic control section,traffic control id:{check_is_in_traffic_control_section.trafficControlInfo.ID}" +
        //                            //             $"don't excute override",
        //                            //       VehicleID: selected_vh.VEHICLE_ID,
        //                            //       CarrierID: selected_vh.CST_ID);
        //                            //    continue;
        //                            //}
        //                            AVEHICLE keep_going_vh = avoid_vh == vh_active ? vh_passive : vh_active;
        //                            if (avoid_vh.isTcpIpConnect)
        //                            {
        //                                ACMD_OHTC cmd_ohtc = scApp.CMDBLL.GetCMD_OHTCByID(avoid_vh.OHTC_CMD);
        //                                LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(DeadlockCheck), Device: "AGVC",
        //                                   Data: $"dead lock happend ,ask vh:{avoid_vh.VEHICLE_ID} chnage path.",
        //                                   VehicleID: avoid_vh.VEHICLE_ID,
        //                                   CarrierID: avoid_vh.CST_ID);

        //                                //if (scApp.VehicleService.doSendOverrideCommandToVh(vh_active, cmd_ohtc, vh_active.CanNotReserveInfo.ReservedAdrID))
        //                                //bool is_override_success = scApp.VehicleService.trydoOverrideCommandToVh(selected_vh, cmd_ohtc, selected_vh.CanNotReserveInfo.ReservedSectionID);
        //                                bool is_override_success = scApp.VehicleService.trydoAvoidCommandToVh(avoid_vh, keep_going_vh);
        //                                if (is_override_success)
        //                                {
        //                                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
        //                                       Data: $"dead lock happend ,ask vh:{avoid_vh.VEHICLE_ID} chnage path success.",
        //                                       VehicleID: avoid_vh.VEHICLE_ID,
        //                                       CarrierID: avoid_vh.CST_ID);
        //                                    System.Threading.SpinWait.SpinUntil(() => false, 15000);
        //                                    return;
        //                                }
        //                                else
        //                                {

        //                                    avoid_vh.CurrentFailOverrideTimes++;
        //                                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
        //                                       Data: $"dead lock happend ,ask vh:{avoid_vh.VEHICLE_ID} chnage path fail, fail times:{avoid_vh.CurrentFailOverrideTimes}.",
        //                                       VehicleID: avoid_vh.VEHICLE_ID,
        //                                       CarrierID: avoid_vh.CST_ID);
        //                                }
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            logger.Error(ex, "Exection:");
        //        }
        //        finally
        //        {

        //            System.Threading.Interlocked.Exchange(ref checkSyncPoint, 0);

        //        }
        //    }
        //}
        public override void doProcess(object obj)
        {
            if (!SystemParameter.AutoOverride)
            {
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(DeadlockCheck), Device: "OHBC",
                              Data: $"auto override is:{SystemParameter.AutoOverride}.");
                return;
            }
            if (System.Threading.Interlocked.Exchange(ref checkSyncPoint, 1) == 0)
            {
                try
                {
                    //找出發生Reserve要不到而停止的車子,如果兩台都剛好是因為對方的關係拿不路權
                    //就可以開始準備對其中一台車進行Override
                    var vhs             = scApp.VehicleBLL.cache.loadVhs();
                    var vhs_ReserveStop = vhs.Where(v => v.IsReservePause)
                                          .OrderBy(v => v.VEHICLE_ID)
                                          .ToList();
                    foreach (var vh_active in vhs_ReserveStop)
                    {
                        foreach (var vh_passive in vhs_ReserveStop)
                        {
                            if (vh_active == vh_passive)
                            {
                                continue;
                            }
                            if (!vh_active.IsReservePause || !vh_active.IsReservePause)
                            {
                                continue;
                            }
                            if ((vh_active.CanNotReserveInfo != null && vh_passive.CanNotReserveInfo != null))
                            {
                                List <AVEHICLE> sort_vhs = new List <AVEHICLE>()
                                {
                                    vh_active, vh_passive
                                };

                                //將找出來的vh進行排序,用來幫忙決定要讓哪一台車進行退避
                                //比條件有
                                //1.是否有執行MCS命令(沒執行的會先避車)
                                //2.是否有搬送CST(沒載CST的會先避車)
                                sort_vhs.Sort(SortOverrideOfVehicle);
                                foreach (AVEHICLE avoid_vh in sort_vhs)
                                {
                                    if (avoid_vh.CurrentFailOverrideTimes >= AVEHICLE.MAX_FAIL_OVERRIDE_TIMES_IN_ONE_CASE)
                                    {
                                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
                                                      Data: $"dead lock happend ,but vh:{avoid_vh.VEHICLE_ID} has been override more than {AVEHICLE.MAX_FAIL_OVERRIDE_TIMES_IN_ONE_CASE} times, continue next vh.",
                                                      VehicleID: avoid_vh.VEHICLE_ID,
                                                      CarrierID: avoid_vh.CST_ID);
                                        continue;
                                    }

                                    if (avoid_vh.VhAvoidInfo != null)
                                    {
                                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
                                                      Data: $"dead lock happend ,but vh:{avoid_vh.VEHICLE_ID} has been avoid command , continue next vh." +
                                                      $"blocked section:{avoid_vh.VhAvoidInfo.BlockedSectionID} blocked vh id:{avoid_vh.VhAvoidInfo.BlockedVehicleID}",
                                                      VehicleID: avoid_vh.VEHICLE_ID,
                                                      CarrierID: avoid_vh.CST_ID);
                                        continue;
                                    }
                                    AVEHICLE pass_vh = avoid_vh == vh_active ? vh_passive : vh_active;


                                    var key_blocked_vh = findTheKeyBlockVhID(avoid_vh, pass_vh);
                                    if (key_blocked_vh == null)
                                    {
                                        continue;
                                    }
                                    if (avoid_vh.isTcpIpConnect)
                                    {
                                        ACMD_OHTC cmd_ohtc = scApp.CMDBLL.getCMD_OHTCByID(avoid_vh.OHTC_CMD);
                                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(DeadlockCheck), Device: "AGVC",
                                                      Data: $"dead lock happend ,ask vh:{avoid_vh.VEHICLE_ID} chnage path.",
                                                      VehicleID: avoid_vh.VEHICLE_ID,
                                                      CarrierID: avoid_vh.CST_ID);

                                        bool is_override_success = scApp.VehicleService.trydoAvoidCommandToVh(avoid_vh, key_blocked_vh);
                                        if (is_override_success)
                                        {
                                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
                                                          Data: $"dead lock happend ,ask vh:{avoid_vh.VEHICLE_ID} chnage path success.",
                                                          VehicleID: avoid_vh.VEHICLE_ID,
                                                          CarrierID: avoid_vh.CST_ID);
                                            System.Threading.SpinWait.SpinUntil(() => false, 15000);
                                            return;
                                        }
                                        else
                                        {
                                            avoid_vh.CurrentFailOverrideTimes++;
                                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(DeadlockCheck), Device: "AGVC",
                                                          Data: $"dead lock happend ,ask vh:{avoid_vh.VEHICLE_ID} chnage path fail, fail times:{avoid_vh.CurrentFailOverrideTimes}.",
                                                          VehicleID: avoid_vh.VEHICLE_ID,
                                                          CarrierID: avoid_vh.CST_ID);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Exection:");
                }
                finally
                {
                    System.Threading.Interlocked.Exchange(ref checkSyncPoint, 0);
                }
            }
        }