예제 #1
0
        public void ProcessCVOpInRequest(Data.VO.OHCV ohcv)
        {
            if (ohcv == null)
            {
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(RoadControlService), Device: "OHxC",
                              Data: $"Start process ohcv op in request, but ohcv object is null.");
                return;
            }

            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                          Data: $"Start process ohcv:{ohcv?.EQPT_ID} op in request...",
                          VehicleID: ohcv?.EQPT_ID);
            string   segment_location       = ohcv.SegmentLocation;
            ASEGMENT pre_control_segment_vo = SegmentBLL.cache.GetSegment(segment_location);

            if (System.Threading.Interlocked.Exchange(ref pre_control_segment_vo.segment_prepare_control_SyncPoint, 1) == 0)
            {
                try
                {
                    //將segment 更新成 pre disable
                    ASEGMENT pre_control_segment_do = MapBLL.PreDisableSegment(segment_location);
                    pre_control_segment_vo.put(pre_control_segment_do);
                    segmentListChanged?.Invoke(this, pre_control_segment_vo);

                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                  Data: $"pre disable segment{segment_location} success.",
                                  VehicleID: ohcv.EQPT_ID);
                    bool is_road_clear = WaitRoadClear(pre_control_segment_vo, ohcv);
                    if (is_road_clear)
                    {
                        doEnableDisableSegment(segment_location, E_PORT_STATUS.OutOfService, ASEGMENT.DisableType.Safety, Data.SECS.CSOT.SECSConst.LANECUTTYPE_LaneCutOnHMI);
                        pre_control_segment_vo.NotifyControlComplete();
                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                      Data: $"disable segment{segment_location} success.",
                                      VehicleID: ohcv.EQPT_ID);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Exception:");
                }
                finally
                {
                    System.Threading.Interlocked.Exchange(ref pre_control_segment_vo.segment_prepare_control_SyncPoint, 0);
                }
            }
            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                          Data: $"End process ohcv:{ohcv?.EQPT_ID} op in request.",
                          VehicleID: ohcv?.EQPT_ID);
        }
        private bool WaitRoadClear(ASEGMENT preControlSegment, Data.VO.OHCV requestOHCV)
        {
            try
            {
                bool   canDisable         = true;
                string pre_disable_seg_id = preControlSegment.SEG_NUM;

                return(canDisable);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exection:");
                return(false);
            }
        }
예제 #3
0
        private bool IsOHCVNodeStatusNormal(Data.VO.OHCV requestOHCV)
        {
            ANODE ohcv_node = app.getEQObjCacheManager().getNodeByNodeID(requestOHCV.NODE_ID);

            return(ohcv_node.Is_Alive && ohcv_node.DoorClosed);
        }
예제 #4
0
        private bool WaitRoadClear(ASEGMENT preControlSegment, Data.VO.OHCV requestOHCV)
        {
            try
            {
                bool   canDisable         = true;
                string pre_disable_seg_id = preControlSegment.SEG_NUM;
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                              Data: $"start wait segment:{pre_disable_seg_id} clear for ohcv:{requestOHCV.EQPT_ID} op in request...");
                do
                {
                    canDisable = true;
                    //1.確認是否有在控制完成前的命令還沒執行完
                    //canDisable = bcApp.SCApplication.CMDBLL.getCMD_MCSIsRunningCount(seg.PRE_DISABLE_TIME.Value) == 0;
                    if (canDisable)
                    {
                        List <ACMD_MCS> unfinished_mcs_cmds = CMDBLL.loadACMD_MCSIsUnfinished();
                        foreach (ACMD_MCS cmd_mcs in unfinished_mcs_cmds)
                        {
                            string source_port      = cmd_mcs.HOSTSOURCE;
                            string destination_port = cmd_mcs.HOSTDESTINATION;
                            //1.如果cmd 狀態還沒到Transferring 則判斷他的source port 是不是要到Pre disable的路段
                            //2.如果Source 不是Port的話,則應該是VH,就去看他的目的地是不是要到Pre disable的路段
                            if (cmd_mcs.TRANSFERSTATE < E_TRAN_STATUS.Transferring &&
                                PortStationBLL.OperateCatch.IsExist(source_port))
                            {
                                if (PortStationBLL.OperateCatch.IsPortInSpecifiedSegment(SectionBLL, source_port, pre_disable_seg_id))
                                {
                                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                                  Data: $"wait segment:{pre_disable_seg_id} clear,but has mcs cmd queue in here. " +
                                                  $"cmd id:{SCUtility.Trim(cmd_mcs.CMD_ID, true)} of source port:{SCUtility.Trim(source_port, true)} in segment:{pre_disable_seg_id}");
                                    canDisable = false;
                                    break;
                                }
                            }
                            else
                            {
                                if (PortStationBLL.OperateCatch.IsExist(destination_port) &&
                                    PortStationBLL.OperateCatch.IsPortInSpecifiedSegment(SectionBLL, destination_port, pre_disable_seg_id))
                                {
                                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                                  Data: $"wait segment:{pre_disable_seg_id} clear,but has mcs cmd queue in here. " +
                                                  $"cmd id:{SCUtility.Trim(cmd_mcs.CMD_ID, true)} of destination port:{SCUtility.Trim(destination_port, true)} in segment:{pre_disable_seg_id}");
                                    canDisable = false;
                                    break;
                                }
                            }
                        }
                    }
                    //2.確認是否還有命令還會通過這裡
                    if (canDisable)
                    {
                        List <string> will_be_pass_cmd_ids = null;
                        bool          has_vh_will_pass     = CMDBLL.HasCmdWillPassSegment(pre_disable_seg_id, out will_be_pass_cmd_ids);
                        if (has_vh_will_pass)
                        {
                            List <AVEHICLE> will_pass_of_vh     = VehicleBLL.cache.loadVhsByOHTCCommandIDs(will_be_pass_cmd_ids);
                            string[]        will_pass_of_vh_ids = will_pass_of_vh.Select(vh => vh.VEHICLE_ID).ToArray();
                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                          Data: $"wait segment:{pre_disable_seg_id} clear,but has vh will pass. " +
                                          $"cmd ids:{string.Join(",", will_be_pass_cmd_ids)} and vh id:{string.Join(",", will_pass_of_vh_ids)}");
                            canDisable = false;
                        }
                        //canDisable = !CMDBLL.HasCmdWillPassSegment(pre_disable_seg_id, out will_be_pass_cmd_ids);
                    }
                    //3.確認是否還有VH在即將管制道路上,如果有的話將他趕至其他停車位置上。
                    if (canDisable)
                    {
                        List <AVEHICLE> on_pre_disable_segment_of_vhs = VehicleBLL.cache.loadVhsBySegmentID(pre_disable_seg_id);
                        if (on_pre_disable_segment_of_vhs != null && on_pre_disable_segment_of_vhs.Count > 0)
                        {
                            canDisable = false;
                            foreach (AVEHICLE pre_drive_away_vh in on_pre_disable_segment_of_vhs)
                            {
                                if (!pre_drive_away_vh.isTcpIpConnect || pre_drive_away_vh.IsError || !SCUtility.isEmpty(pre_drive_away_vh.OHTC_CMD))
                                {
                                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHTC",
                                                  Data: $"vh id:{pre_drive_away_vh.VEHICLE_ID} in pre-disable segment:{pre_disable_seg_id} ,but current status not allowed drive away." +
                                                  $"is connect:{pre_drive_away_vh.isTcpIpConnect },is error:{pre_drive_away_vh.IsError }, current assign ohtc cmd id:{pre_drive_away_vh.OHTC_CMD}.");
                                    continue;
                                }
                                else
                                {
                                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                                  Data: $"wait segment:{pre_disable_seg_id} clear,but vh:{pre_drive_away_vh.VEHICLE_ID} in here. " +
                                                  $"ask it go away");
                                    canDisable = false;
                                    VehicleBLL.whenVhObstacle(pre_drive_away_vh.VEHICLE_ID);
                                }
                            }
                        }
                    }
                    if (!canDisable && requestOHCV.SafetyCheckRequest)
                    {
                        SpinWait.SpinUntil(() => false, 1000);
                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                      Data: $"Segment:{pre_disable_seg_id} continue wait road clear. because canDisable:{canDisable} " +
                                      $"and ohcv:{requestOHCV.EQPT_ID} of SafetyCheckRequest:{requestOHCV.SafetyCheckRequest}");
                    }

                    //if (!IsOHCVNodeStatusNormal(requestOHCV))
                    if (!requestOHCV.Is_Eq_Alive || !requestOHCV.DoorClosed)
                    {
                        //ANODE ohcv_node = app.getEQObjCacheManager().getNodeByNodeID(requestOHCV.NODE_ID);
                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                                      Data: $"Segment:{pre_disable_seg_id} finish wait road clear. ohcv:{requestOHCV.EQPT_ID} status abnormal ," +
                                      $"cv alive:{requestOHCV.Is_Eq_Alive} ,door closed:{requestOHCV.DoorClosed}");
                        return(false);
                    }
                }while (!canDisable && requestOHCV.SafetyCheckRequest);

                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(RoadControlService), Device: "OHxC",
                              Data: $"End wait segment:{pre_disable_seg_id} clear for ohcv:{requestOHCV.EQPT_ID} op in request." +
                              $"result:[candisable:{canDisable} , ohcv:{requestOHCV.EQPT_ID} of SafetyCheckRequest:{requestOHCV.SafetyCheckRequest}]");
                return(canDisable);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exection:");
                return(false);
            }
        }