Beispiel #1
0
 private void RoadControlService_SegmentListChanged(object sender, ASEGMENT e)
 {
     Adapter.Invoke((obj) =>
     {
         RefreshMapColor();
     }, null);
 }
            public bool IsInMaintainDeviceRangeOfAddress(BLL.SegmentBLL segmentBLL, string adrID)
            {
                string adr_id          = SCUtility.Trim(adrID, true);
                var    maintain_device = eqObjCacheManager.getAllEquipment().
                                         Where(device => device is IMaintainDevice).
                                         ToList();

                foreach (IMaintainDevice device in maintain_device)
                {
                    ASEGMENT device_segment = segmentBLL.cache.GetSegment(device.DeviceSegment);
                    //除了第一段的from address以外其他要屬於該Segment的Address
                    string[] segment_of_section_from_address = device_segment.Sections.
                                                               Where(sec => sec != device_segment.Sections.First()).
                                                               Select(section => section.FROM_ADR_ID.Trim()).ToArray();
                    //除了最後一段的to address以外其他要屬於該Segment的Address
                    string[] segment_of_section_to_address = device_segment.Sections.
                                                             Where(sec => sec != device_segment.Sections.Last()).
                                                             Select(section => section.TO_ADR_ID.Trim()).ToArray();

                    string[] segment_include_address = segment_of_section_from_address.Concat(segment_of_section_to_address).ToArray();
                    if (segment_include_address.Contains(adr_id))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        public ASEGMENT EnableSegment(string seg_num)
        {
            ASEGMENT seg = null;

            try
            {
                using (DBConnection_EF con = DBConnection_EF.GetUContext())
                {
                    seg = segmentDAO.getByID(con, seg_num);
                    if (seg != null)
                    {
                        seg.PRE_DISABLE_FLAG = false;
                        seg.PRE_DISABLE_TIME = null;
                        seg.DISABLE_TIME     = null;
                        seg.STATUS           = E_SEG_STATUS.Active;
                    }
                    segmentDAO.Update(con, seg);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
            return(seg);
        }
Beispiel #4
0
        public (bool isSuccess, string reason) RecoverCVEnable(string segmentID)
        {
            bool   is_success = true;
            string reason     = "";

            try
            {
                ASEGMENT seg_vo = SegmentBLL.cache.GetSegment(segmentID);
                List <sc.Data.VO.OHCV> ohcvs = app.EquipmentBLL.cache.loadOHCVDevicesBySegmentLocation(segmentID);
                if (ohcvs == null || ohcvs.Count == 0)
                {
                    reason     = $"Segment ID:{segmentID} not is cv of segemnt.";
                    is_success = false;;
                    return(is_success, reason);
                }
                if (!seg_vo.DISABLE_FLAG_SAFETY)
                {
                    reason     = $"Segment ID:{segmentID} of safty flag already off.";
                    is_success = false;;
                    return(is_success, reason);
                }
                foreach (sc.Data.VO.OHCV ohcv in ohcvs)
                {
                    if (!ohcv.DoorClosed)
                    {
                        reason     = $"ohcv ID:{ohcv.EQPT_ID} of door closed:{ohcv.DoorClosed} ,can't enable segment.";
                        is_success = false;
                        return(is_success, reason);
                    }
                    if (!ohcv.Is_Eq_Alive)
                    {
                        reason     = $"ohcv ID:{ohcv.EQPT_ID} of alive:{ohcv.Is_Eq_Alive} ,can't enable segment.";
                        is_success = false;
                        return(is_success, reason);
                    }
                }
                //取得CV所在的Node,By Segment ID
                string seg_id = SCUtility.Trim(segmentID, true);
                ANODE  node   = NodeBLL.OperateCatch.getNodeBySegment(seg_id);
                doEnableDisableSegment(seg_id,
                                       E_PORT_STATUS.InService, ASEGMENT.DisableType.Safety,
                                       sc.Data.SECS.CSOT.SECSConst.LANECUTTYPE_LaneCutOnHMI);

                foreach (var ohcv in node.getSubEqptList())
                {
                    LineService.ProcessAlarmReport(
                        ohcv.NODE_ID, ohcv.EQPT_ID, ohcv.Real_ID, "",
                        SCAppConstants.SystemAlarmCode.OHCV_Issue.CVALLAlarmReset,
                        ProtocolFormat.OHTMessage.ErrorStatus.ErrReset);
                }
                return(is_success, reason);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception:");
                reason     = $"{ex}-Exception";
                is_success = false;
                return(is_success, reason);
            }
        }
        public ASEGMENT getSegmentByNum(string segment_num)
        {
            ASEGMENT segment = objCacheManager.GetSegments().
                               Where(value => value.SEG_NUM?.Trim() == segment_num?.Trim()).
                               SingleOrDefault();

            return(segment);
        }
            public void EnableSegment(string segID)
            {
                ASEGMENT seg = CommObjCacheManager.getSegments().Where(s => s.SEG_ID.Trim() == segID.Trim())
                               .FirstOrDefault();

                seg.PRE_DISABLE_FLAG = false;
                seg.PRE_DISABLE_TIME = null;
                seg.DISABLE_TIME     = null;
                seg.STATUS           = E_SEG_STATUS.Active;
            }
        public ASEGMENT getSegmentByID(string segment_id)
        {
            ASEGMENT segment = null;

            using (DBConnection_EF con = new DBConnection_EF())
            {
                segment = segmentDAO.getByID(con, segment_id);
            }
            return(segment);
        }
        private async void btn_segment_enable_cv_Click(object sender, EventArgs e)
        {
            try
            {
                btn_segment_enable_cv.Enabled = false;
                DataGridViewRow row = dgv_segment.SelectedRows.Count > 0 ? dgv_segment.SelectedRows[0] : null;
                if (row == null)
                {
                    return;
                }
                ASEGMENT Seg = segment_List[row.Index];
                List <sc.Data.VO.OHCV> ohcvs = bcApp.SCApplication.EquipmentBLL.cache.loadOHCVDevicesBySegmentLocation(Seg.SEG_NUM);
                if (ohcvs == null || ohcvs.Count == 0)
                {
                    MessageBox.Show($"Segment ID:{Seg.SEG_NUM} not is cv of segemnt.", "fail.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!Seg.DISABLE_FLAG_SAFETY)
                {
                    MessageBox.Show($"Segment ID:{Seg.SEG_NUM} of safty flag already off.", "fail.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                foreach (sc.Data.VO.OHCV ohcv in ohcvs)
                {
                    if (!ohcv.DoorClosed)
                    {
                        MessageBox.Show($"ohcv ID:{ohcv.EQPT_ID} of door closed:{ohcv.DoorClosed} ,can't enable segment.", "fail.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (!ohcv.Is_Eq_Alive)
                    {
                        MessageBox.Show($"ohcv ID:{ohcv.EQPT_ID} of alive:{ohcv.Is_Eq_Alive} ,can't enable segment.", "fail.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
                bool is_success = false;
                await Task.Run(() =>
                               //bcApp.SCApplication.RoadControlService.doEnableDisableSegment
                               //                  (Seg.SEG_NUM.Trim(),
                               //                  E_PORT_STATUS.InService, ASEGMENT.DisableType.Safety,
                               //                  sc.Data.SECS.CSOT.SECSConst.LANECUTTYPE_LaneCutOnHMI)

                               is_success = bcApp.SCApplication.RoadControlService.RecoverCVEnable(Seg.SEG_NUM).isSuccess
                               );

                string s_is_success = is_success ? "Success" : "Fail";
                MessageBox.Show($"Segment enable is:{s_is_success}", s_is_success, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch { }
            finally
            {
                btn_segment_enable_cv.Enabled = true;
            }
        }
Beispiel #9
0
            public bool IsSegmentActive(string seg_num)
            {
                bool     isActive = false;
                ASEGMENT seg      = GetSegment(seg_num);

                if (seg != null)
                {
                    isActive = !seg.PRE_DISABLE_FLAG && seg.STATUS == E_SEG_STATUS.Active;
                }
                return(isActive);
            }
        public void updateSegments()
        {
            var segments_do = app.SegmentBLL.OperateDB.loadSegments();

            foreach (var segment_do in segments_do)
            {
                ASEGMENT seg_vo = SEGMENTs.
                                  Where(s => s.SEG_NUM.Trim() == segment_do.SEG_NUM.Trim()).
                                  FirstOrDefault();
                seg_vo.set(segment_do);
            }

            SegmentsUpdateComplete?.Invoke(this, EventArgs.Empty);
        }
Beispiel #11
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 BidingRailPointAndGroupForRail()
        {
            bool bRet = false;
            List <AGROUPRAILS> listGroup = mainForm.BCApp.SCApplication.MapBLL.loadAllGroupRail();

            for (int i = 0; i < listGroup.Count - 1; i++)
            {
                if (!BCFUtility.isMatche(listGroup[i].SECTION_ID, listGroup[i + 1].SECTION_ID))
                {
                    continue;
                }
                findMatchRailPoint(listGroup[i].RAIL_ID, listGroup[i + 1].RAIL_ID);
            }

            foreach (AGROUPRAILS group_rail in listGroup)
            {
                uctlRail railTemp   = null;
                string   section_id = group_rail.SECTION_ID.Trim();
                railTemp = m_objItemRail.Where(r => r.p_ID.Trim() == group_rail.RAIL_ID.Trim()).FirstOrDefault();
                if (railTemp == null)
                {
                    continue;
                }
                if (!m_DicSectionGroupRails.ContainsKey(section_id))
                {
                    ASECTION ASEC_ObJ = mainForm.BCApp.SCApplication.MapBLL.getSectiontByID(section_id);
                    ASEGMENT ASEG_ObJ = mainForm.BCApp.SCApplication.MapBLL.getSegmentByID(ASEC_ObJ.SEG_NUM);
                    m_DicSectionGroupRails.Add(group_rail.SECTION_ID.Trim(), new GroupRails(group_rail.SECTION_ID, ASEC_ObJ.SEC_DIS, group_rail.DIR
                                                                                            , ASEG_ObJ.SEG_NUM, ASEG_ObJ.DIR));
                }
                m_DicSectionGroupRails[section_id].uctlRails.Add(new KeyValuePair <uctlRail, E_RAIL_DIR>(railTemp, group_rail.DIR));
            }

            foreach (GroupRails group in m_DicSectionGroupRails.Values)
            {
                group.RefreshDistance();
                group.DecisionFirstAndLastPoint(true);
            }

            List <ASEGMENT> listSegment = mainForm.BCApp.SCApplication.MapBLL.loadAllSegments();

            foreach (ASEGMENT seg in listSegment)
            {
                List <GroupRails> segSections = m_DicSectionGroupRails.Values
                                                .Where(group => group.Segment_Num.Trim() == seg.SEG_NUM.Trim()).ToList();
                m_DicSegmentGroupRails.Add(seg.SEG_NUM.Trim(), segSections);
            }
            return(bRet);
        }
        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);
            }
        }
Beispiel #14
0
        //private long checkSyncPoint = 0;
        //private void checkSegmentStatus()
        //{
        //    if (Interlocked.Exchange(ref checkSyncPoint, 1) == 0)
        //    {
        //        try
        //        {
        //            bool hasPrepare = false;
        //            bcApp.SCApplication.LineBLL.BegingOrEndSegmentPreDisableExcute(true);
        //            do
        //            {

        //                foreach (ASEGMENT seg in segment_List)
        //                {
        //                    if (seg.PRE_DISABLE_FLAG)
        //                    {
        //                        bool canDisable = false;
        //                        //1.確認是否有在Disable前的命令還沒執行完
        //                        canDisable = bcApp.SCApplication.CMDBLL.getCMD_MCSIsRunningCount(seg.PRE_DISABLE_TIME.Value) == 0;
        //                        //2.確認是否還有命令還會通過這裡
        //                        if (canDisable)
        //                        {
        //                            List<string> will_be_pass_cmd_ids = null;
        //                            canDisable = !bcApp.SCApplication.CMDBLL.HasCmdWillPassSegment(seg.SEG_NUM, out will_be_pass_cmd_ids);
        //                        }
        //                        //3.確認是否還有VH在管制道路上
        //                        if (canDisable)
        //                        {
        //                            List<AVEHICLE> listVH = bcApp.SCApplication.getEQObjCacheManager().getAllVehicle();
        //                            foreach (AVEHICLE vh in listVH)
        //                            {
        //                                ASECTION vh_current_sec = bcApp.SCApplication.MapBLL.getSectiontByID(vh.CUR_SEC_ID);
        //                                if (vh_current_sec != null && SCUtility.isMatche(vh_current_sec.SEG_NUM, seg.SEG_NUM))
        //                                {
        //                                    if (vh.ACT_STATUS != sc.ProtocolFormat.OHTMessage.VHActionStatus.NoCommand)
        //                                        canDisable = false;
        //                                    break;
        //                                }
        //                            }
        //                        }

        //                        if (canDisable)
        //                        {
        //                            int index = segment_List.IndexOf(seg);
        //                            string seg_num = seg.SEG_NUM;
        //                            var newSeg = bcApp.SCApplication.RouteGuide.CloseSegment(seg_num.Trim());
        //                            var orderSeg = segment_List[index];
        //                            BCFUtility.setValueToPropety(ref newSeg, ref orderSeg);
        //                            Adapter.Invoke((obj) =>
        //                            {
        //                                dgv_segment.Refresh();
        //                                RefreshMapColor();
        //                            }, null);
        //                            hasPrepare = false;
        //                        }
        //                        else
        //                        {
        //                            hasPrepare = true;

        //                        }
        //                    }
        //                }
        //                SpinWait.SpinUntil(() => false, 1000);
        //            }
        //            while (hasPrepare);
        //        }
        //        catch (Exception ex)
        //        {
        //            logger.Error(ex, "Exection:");
        //        }
        //        finally
        //        {
        //            Interlocked.Exchange(ref checkSyncPoint, 0);
        //            bcApp.SCApplication.LineBLL.BegingOrEndSegmentPreDisableExcute(false);
        //        }
        //    }
        //}

        private void SegmentSelectOnMap(object sender, EventArgs _args)
        {
            var      args    = _args as Components.SelectedRailEventArgs;
            ASEGMENT seg_obj = segment_List.Where(seg => seg.SEG_NUM.Trim() == args.Segment_Num.Trim()).FirstOrDefault();

            if (seg_obj == null)
            {
                return;
            }
            int index = segment_List.IndexOf(seg_obj);

            dgv_segment.FirstDisplayedScrollingRowIndex = index;
            dgv_segment.Rows[index].Selected            = true;
            RefreshMapColor();
        }
        public ASEGMENT getSegmentBySectionID(string id)
        {
            ASEGMENT segment = null;

            using (DBConnection_EF con = new DBConnection_EF())
            {
                //ASECTION section = sectionDAO.getByID(con, id);
                ASECTION section = sectionDAO.getByID(commObjCacheManager, id);
                if (section != null)
                {
                    segment = segmentDAO.getByID(con, section.SEG_NUM);
                }
            }

            return(segment);
        }
Beispiel #16
0
 private void disableSegment(string laneCutTypeg)
 {
     foreach (DataGridViewRow row in dgv_segment.SelectedRows)
     {
         ASEGMENT selectSeg = segment_List[row.Index];
         if (!selectSeg.DISABLE_FLAG_USER &&
             !selectSeg.PRE_DISABLE_FLAG)
         {
             //segment_List[row.Index] = bcApp.SCApplication.MapBLL.PreDisableSegment(selectSeg.SEG_NUM.Trim());
             //segment_List[row.Index] = bcApp.SCApplication.VehicleService.doEnableDisableSegment(selectSeg.SEG_NUM.Trim(), E_PORT_STATUS.OutOfService, laneCutTypeg);
             //segment_List[row.Index] = bcApp.SCApplication.RoadControlService.doEnableDisableSegment
             //    (selectSeg.SEG_NUM.Trim(), E_PORT_STATUS.OutOfService, ASEGMENT.DisableType.User, laneCutTypeg);
             bcApp.SCApplication.RoadControlService.doEnableDisableSegment
                 (selectSeg.SEG_NUM.Trim(), E_PORT_STATUS.OutOfService, ASEGMENT.DisableType.User, laneCutTypeg);
         }
     }
 }
Beispiel #17
0
 private void enableSegment()
 {
     foreach (DataGridViewRow row in dgv_segment.SelectedRows)
     {
         ASEGMENT selectSeg = segment_List[row.Index];
         if (selectSeg.DISABLE_FLAG_USER)
         {
             //  segment_List[row.Index] = bcApp.SCApplication.RouteGuide.OpenSegment(selectSeg.SEG_NUM.Trim());
             //segment_List[row.Index] = bcApp.SCApplication.VehicleService.doEnableDisableSegment
             /*segment_List[row.Index] =*/
             bcApp.SCApplication.RoadControlService.doEnableDisableSegment
                 (selectSeg.SEG_NUM.Trim(),
                 E_PORT_STATUS.InService, ASEGMENT.DisableType.User,
                 sc.Data.SECS.CSOT.SECSConst.LANECUTTYPE_LaneCutOnHMI);
         }
     }
 }
Beispiel #18
0
            public bool IsInMaintainDeviceRangeOfSection(BLL.SegmentBLL segmentBLL, string sectionID)
            {
                string sectiin_id      = SCUtility.Trim(sectionID, true);
                var    maintain_device = eqObjCacheManager.getAllEquipment().
                                         Where(device => device is IMaintainDevice).
                                         ToList();

                foreach (IMaintainDevice device in maintain_device)
                {
                    ASEGMENT device_segment     = segmentBLL.cache.GetSegment(device.DeviceSegment);
                    string[] segment_of_section = device_segment.Sections.Select(section => section.SEC_ID.Trim()).ToArray();
                    if (segment_of_section.Contains(sectiin_id))
                    {
                        return(true);
                    }
                }
                return(false);
            }
        private void btn_enable_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgv_segment.SelectedRows)
            {
                ASEGMENT selectSeg = segment_List[row.Index];
                if (selectSeg.STATUS == E_SEG_STATUS.Closed)
                {
                    //  segment_List[row.Index] = bcApp.SCApplication.RouteGuide.OpenSegment(selectSeg.SEG_NUM.Trim());

                    var ban_result = bcApp.SCApplication.VehicleService.doEnableDisableSegment(selectSeg.SEG_ID.Trim(), E_PORT_STATUS.InService);
                    if (ban_result.isSuccess)
                    {
                        selectSeg.DISABLE_TIME = ban_result.segment.DISABLE_TIME;
                        selectSeg.STATUS       = ban_result.segment.STATUS;
                    }
                }
            }
            dgv_segment.Refresh();
            RefreshMapColor();
        }
        public bool IsSegmentActive(string seg_num)
        {
            bool isActive = false;

            try
            {
                ASEGMENT seg = null;
                using (DBConnection_EF con = DBConnection_EF.GetUContext())
                {
                    seg = segmentDAO.getByID(con, seg_num);
                }
                if (seg != null)
                {
                    isActive = !seg.PRE_DISABLE_FLAG && seg.STATUS == E_SEG_STATUS.Active;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
            return(isActive);
        }
 private void btn_disable_Click(object sender, EventArgs e)
 {
     foreach (DataGridViewRow row in dgv_segment.SelectedRows)
     {
         ASEGMENT selectSeg = segment_List[row.Index];
         if (selectSeg.STATUS == E_SEG_STATUS.Active &&
             !selectSeg.PRE_DISABLE_FLAG)
         {
             //segment_List[row.Index] = bcApp.SCApplication.MapBLL.PreDisableSegment(selectSeg.SEG_NUM.Trim());
             //segment_List[row.Index] = bcApp.SCApplication.VehicleService.doEnableDisableSegment(selectSeg.SEG_ID.Trim(), E_PORT_STATUS.OutOfService);
             var ban_result = bcApp.SCApplication.VehicleService.doEnableDisableSegment(selectSeg.SEG_ID.Trim(), E_PORT_STATUS.OutOfService);
             if (ban_result.isSuccess)
             {
                 selectSeg.DISABLE_TIME = ban_result.segment.DISABLE_TIME;
                 selectSeg.STATUS       = ban_result.segment.STATUS;
             }
         }
     }
     dgv_segment.Refresh();
     RefreshMapColor();
     // Task.Run(() => checkSegmentStatus());
 }
        public bool updateSegStatus(string id, E_SEG_STATUS status)
        {
            ASEGMENT segment = null;

            try
            {
                using (DBConnection_EF con = new DBConnection_EF())
                {
                    segment        = segmentDAO.getByID(con, id);
                    segment.STATUS = status;
                    //bool isDetached = con.Entry(segment).State == EntityState.Modified;
                    //if (isDetached)
                    segmentDAO.Update(con, segment);
                }
                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
                return(false);
            }
        }
 private void btn_cancel_Click(object sender, EventArgs e)
 {
     foreach (DataGridViewRow row in dgv_segment.SelectedRows)
     {
         ASEGMENT selectSeg = segment_List[row.Index];
         if (selectSeg.STATUS == E_SEG_STATUS.Active &&
             selectSeg.PRE_DISABLE_FLAG)
         {
             // segment_List[row.Index] = bcApp.SCApplication.RouteGuide.OpenSegment(Seg.SEG_NUM.Trim());
             //segment_List[row.Index] = bcApp.SCApplication.VehicleService.doEnableDisableSegment(Seg.SEG_ID.Trim(), E_PORT_STATUS.InService);
             var ban_result = bcApp.SCApplication.VehicleService.doEnableDisableSegment(selectSeg.SEG_ID.Trim(), E_PORT_STATUS.InService);
             if (ban_result.isSuccess)
             {
                 selectSeg.DISABLE_TIME = ban_result.segment.DISABLE_TIME;
                 selectSeg.STATUS       = ban_result.segment.STATUS;
             }
         }
     }
     bcApp.SCApplication.GuideBLL.clearAllDirGuideQuickSearchInfo();
     dgv_segment.Refresh();
     RefreshMapColor();
 }
        public ASEGMENT PreDisableSegment(string seg_num)
        {
            ASEGMENT seg = null;

            try
            {
                using (DBConnection_EF con = DBConnection_EF.GetUContext())
                {
                    seg = segmentDAO.getByID(con, seg_num);
                    if (seg != null)
                    {
                        seg.PRE_DISABLE_FLAG = true;
                        seg.PRE_DISABLE_TIME = DateTime.Now;
                        seg.DISABLE_TIME     = null;
                    }
                    segmentDAO.Update(con, seg);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
            return(seg);
        }
Beispiel #25
0
        private bool couplerSafetyHandler(SCAppConstants.CouplerHPSafety safety, CouplerAddress coupler_address)
        {
            bool result = false;

            if (coupler_address != null)
            {
                if (safety == SCAppConstants.CouplerHPSafety.Safety)
                {
                    scApp.ReserveBLL.RemoveVehicle(unit.UNIT_ID + coupler_address.CouplerNum + "_v_car");
                    foreach (string seg_id in coupler_address.TrafficControlSegment)
                    {
                        ASEGMENT selectSeg = scApp.SegmentBLL.cache.GetSegment(seg_id);
                        if (selectSeg.STATUS == E_SEG_STATUS.Closed)
                        {
                            var ban_result = scApp.VehicleService.doEnableDisableSegment(selectSeg.SEG_ID.Trim(), E_PORT_STATUS.InService);
                            if (ban_result.isSuccess)
                            {
                                selectSeg.DISABLE_TIME = ban_result.segment.DISABLE_TIME;
                                selectSeg.STATUS       = ban_result.segment.STATUS;
                            }
                        }
                    }
                }
                else if (coupler_address.hasVh(scApp.VehicleBLL))
                {
                    //do nothing
                }
                else
                {
                    string msg = $"The coupler position Address{coupler_address.ADR_ID} is not safe ,begin coupler safe handle process.";
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(SubChargerValueDefMapAction), Device: Service.VehicleService.DEVICE_NAME_AGV,
                                  Data: msg);
                    bcf.App.BCFApplication.onErrorMsg(msg);
                    foreach (string seg_id in coupler_address.TrafficControlSegment)
                    {
                        ASEGMENT selectSeg = scApp.SegmentBLL.cache.GetSegment(seg_id);
                        if (selectSeg.STATUS == E_SEG_STATUS.Active && !selectSeg.PRE_DISABLE_FLAG)
                        {
                            var ban_result = scApp.VehicleService.doEnableDisableSegment(selectSeg.SEG_ID.Trim(), E_PORT_STATUS.OutOfService);
                            if (ban_result.isSuccess)
                            {
                                selectSeg.DISABLE_TIME = ban_result.segment.DISABLE_TIME;
                                selectSeg.STATUS       = ban_result.segment.STATUS;
                            }
                        }
                    }
                    var update_result = scApp.ReserveBLL.TryAddVehicleOrUpdate(unit.UNIT_ID + coupler_address.CouplerNum + "_v_car", coupler_address.ADR_ID, 90, Mirle.Hlts.Utils.HltDirection.NS);

                    if (!update_result.OK)
                    {
                        string message = $"The coupler position Address{coupler_address.ADR_ID} is not safe, vh:{update_result.VehicleID} need to stop";
                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(SubChargerValueDefMapAction), Device: Service.VehicleService.DEVICE_NAME_AGV,
                                      Data: message,
                                      Details: update_result.Description,
                                      VehicleID: update_result.VehicleID);

                        AVEHICLE will_bumped_vh = scApp.VehicleBLL.cache.getVehicle(update_result.VehicleID);

                        //如果發生碰撞或踩入別人預約的不是虛擬車的話,則就要對兩台車下達EMS
                        if (!update_result.VehicleID.StartsWith(Service.VehicleService.VehicleVirtualSymbol))
                        {
                            //string cmd_id = will_bumped_vh.OHTC_CMD;
                            //if (!string.IsNullOrWhiteSpace(cmd_id))
                            //{
                            //    ACMD_OHTC cmd = scApp.CMDBLL.GetCMD_OHTCByID(cmd_id);
                            //    string cmdSourceAdr = cmd.SOURCE;
                            //    if (!string.IsNullOrWhiteSpace(cmdSourceAdr))
                            //    {
                            //        if(SCUtility.isMatche( cmd_id, coupler_address.))
                            //    }
                            //}


                            bcf.App.BCFApplication.onErrorMsg(message);
                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(SubChargerValueDefMapAction), Device: Service.VehicleService.DEVICE_NAME_AGV,
                                          Data: $"The vehicles bumped coupler will happend. send pause to {update_result.VehicleID}",
                                          VehicleID: update_result.VehicleID);
                            scApp.VehicleService.doAbortCommand(will_bumped_vh, will_bumped_vh.OHTC_CMD, ProtocolFormat.OHTMessage.CMDCancelType.CmdEms);
                            //doAbortCommand(assign_vh, ohtc_cmd_id, actType); ;
                            //scApp.VehicleService.PauseRequest(will_bumped_vh.VEHICLE_ID, ProtocolFormat.OHTMessage.PauseEvent.Pause, SCAppConstants.OHxCPauseType.Safty);
                        }
                    }

                    result = true;
                }
            }

            return(result);
        }
Beispiel #26
0
        private void Pre_control_segment_ControlComplete(object sender, EventArgs e)
        {
            ASEGMENT control_complete_segment = sender as ASEGMENT;

            try
            {
                //再次確認是否Safety check=true、door closed=true、alive=true
                if (!eqpt.SafetyCheckRequest)
                {
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(OHCVValueDefMapAction), Device: DEVICE_NAME_OHCV,
                                  Data: $"want to notify cv:{eqpt.EQPT_ID} segment id:{control_complete_segment.SEG_NUM} is control complete," +
                                  $"but cv:{eqpt.EQPT_ID} of {nameof(eqpt.SafetyCheckRequest)} is {eqpt.SafetyCheckRequest}",
                                  VehicleID: eqpt.EQPT_ID);
                    return;
                }

                if (!eqpt.DoorClosed)
                {
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(OHCVValueDefMapAction), Device: DEVICE_NAME_OHCV,
                                  Data: $"want to notify cv:{eqpt.EQPT_ID} segment id:{control_complete_segment.SEG_NUM} is control complete," +
                                  $"but cv:{eqpt.EQPT_ID} of {nameof(eqpt.DoorClosed)} is {eqpt.DoorClosed}",
                                  VehicleID: eqpt.EQPT_ID);
                    return;
                }
                if (!eqpt.Is_Eq_Alive)
                {
                    LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(OHCVValueDefMapAction), Device: DEVICE_NAME_OHCV,
                                  Data: $"want to notify cv:{eqpt.EQPT_ID} segment id:{control_complete_segment.SEG_NUM} is control complete," +
                                  $"but cv:{eqpt.EQPT_ID} of {nameof(eqpt.Is_Eq_Alive)} is {eqpt.Is_Eq_Alive}",
                                  VehicleID: eqpt.EQPT_ID);
                    return;
                }


                //foreach (var cv in node.getSubEqptList())
                //{
                //    if (!cv.DoorClosed)
                //    {
                //        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(OHCVValueDefMapAction), Device: DEVICE_NAME_OHCV,
                //                 Data: $"want to notify cv:{eqpt.EQPT_ID} segment id:{control_complete_segment.SEG_NUM} is control complete," +
                //                       $"but cv:{cv.EQPT_ID} of {nameof(cv.DoorClosed)} is {cv.DoorClosed}",
                //                 VehicleID: eqpt.EQPT_ID);
                //        return;
                //    }
                //    if (!cv.Is_Eq_Alive)
                //    {
                //        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(OHCVValueDefMapAction), Device: DEVICE_NAME_OHCV,
                //                 Data: $"want to notify cv:{eqpt.EQPT_ID} segment id:{control_complete_segment.SEG_NUM} is control complete," +
                //                       $"but cv:{cv.EQPT_ID} of {nameof(cv.Is_Eq_Alive)} is {cv.Is_Eq_Alive}",
                //                 VehicleID: eqpt.EQPT_ID);
                //        return;
                //    }
                //}


                bool completeNotifyResult = sendRoadControlCompleteNotify(); //disable路段後發出Complete Notify
                if (completeNotifyResult)
                {
                    //do nothing
                }
                else
                {
                    BCFApplication.onWarningMsg($"OHTC send road control complete notify to OHCV:[{eqpt.EQPT_ID}] with error happend.");
                    //return;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exection:");
            }
            finally
            {
                control_complete_segment.ControlComplete -= Pre_control_segment_ControlComplete;
            }
        }
        private void checkSegmentStatus()
        {
            if (Interlocked.Exchange(ref checkSyncPoint, 1) == 0)
            {
                try
                {
                    bool hasPrepare = false;
                    bcApp.SCApplication.LineBLL.BegingOrEndSegmentPreDisableExcute(true);
                    do
                    {
                        foreach (ASEGMENT seg in segment_List)
                        {
                            if (seg.PRE_DISABLE_FLAG)
                            {
                                bool canDisable = false;
                                //1.確認是否有在Disable前的命令還沒執行完
                                canDisable = bcApp.SCApplication.CMDBLL.getCMD_MCSIsRunningCount(seg.PRE_DISABLE_TIME.Value) == 0;
                                //2.確認是否還有命令還會通過這裡
                                if (canDisable)
                                {
                                    List <string> will_be_pass_cmd_ids = null;
                                    canDisable = !bcApp.SCApplication.CMDBLL.HasCmdWillPassSegment(seg.SEG_ID, out will_be_pass_cmd_ids);
                                }
                                //3.確認是否還有VH在管制道路上
                                if (canDisable)
                                {
                                    List <AVEHICLE> listVH = bcApp.SCApplication.getEQObjCacheManager().getAllVehicle();
                                    foreach (AVEHICLE vh in listVH)
                                    {
                                        ASECTION vh_current_sec = bcApp.SCApplication.MapBLL.getSectiontByID(vh.CUR_SEC_ID);
                                        if (vh_current_sec != null && SCUtility.isMatche(vh_current_sec.SEG_NUM, seg.SEG_ID))
                                        {
                                            if (vh.ACT_STATUS != sc.ProtocolFormat.OHTMessage.VHActionStatus.NoCommand)
                                            {
                                                canDisable = false;
                                            }
                                            break;
                                        }
                                    }
                                }

                                if (canDisable)
                                {
                                    int      index    = segment_List.IndexOf(seg);
                                    string   seg_num  = seg.SEG_ID;
                                    ASEGMENT newSeg   = null;/* bcApp.SCApplication.RouteGuide.CloseSegment(seg_num.Trim());*/
                                    var      orderSeg = segment_List[index];
                                    BCFUtility.setValueToPropety(ref newSeg, ref orderSeg);
                                    Adapter.Invoke((obj) =>
                                    {
                                        dgv_segment.Refresh();
                                        RefreshMapColor();
                                    }, null);
                                    hasPrepare = false;
                                }
                                else
                                {
                                    hasPrepare = true;
                                }
                            }
                        }
                        SpinWait.SpinUntil(() => false, 1000);
                    }while (hasPrepare);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Exection:");
                }
                finally
                {
                    Interlocked.Exchange(ref checkSyncPoint, 0);
                    bcApp.SCApplication.LineBLL.BegingOrEndSegmentPreDisableExcute(false);
                }
            }
        }
Beispiel #28
0
 public SegmentViewObj(ASEGMENT myDatabaseObject)
 {
     this.segment = myDatabaseObject;
 }
 public void Update(DBConnection_EF con, ASEGMENT seg)
 {
     //bool isDetached = con.Entry(seg).State == EntityState.Modified;
     //if (isDetached)
     con.SaveChanges();
 }
Beispiel #30
0
        public virtual void SafetyCheckRequestChange(object sender, ValueChangedEventArgs args)
        {
            try
            {
                string   pre_control_segment_id = eqpt.SegmentLocation;
                ASEGMENT pre_control_segment    = scApp.SegmentBLL.cache.GetSegment(pre_control_segment_id);

                var recevie_function = scApp.getFunBaseObj <OHCVToOHxC_SafetyCheckRequest>(eqpt.EQPT_ID) as OHCVToOHxC_SafetyCheckRequest;
                recevie_function.Read(bcfApp, eqpt.EqptObjectCate, eqpt.EQPT_ID);
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(OHCVValueDefMapAction), Device: DEVICE_NAME_OHCV,
                              Data: recevie_function.ToString(),
                              VehicleID: eqpt.EQPT_ID);
                eqpt.SafetyCheckRequest = recevie_function.SafetyCheckRequest;
                if (recevie_function.SafetyCheckRequest)
                {
                    //if (!node.DoorClosed)//檢查安全門是不是關閉的
                    if (!eqpt.DoorClosed)//檢查安全門是不是關閉的
                    {
                        BCFApplication.onWarningMsg($"OHCV:[{eqpt.EQPT_ID}] send safety check request to OHTC,but door is open now.");
                        return;
                    }
                    //if (!node.Is_Alive)//檢查Alive有沒有變化
                    if (!eqpt.Is_Eq_Alive)//檢查Alive有沒有變化
                    {
                        BCFApplication.onWarningMsg($"OHCV:[{eqpt.EQPT_ID}] send safety check request to OHTC,but OHCV alive is not changing.");
                        return;
                    }

                    bool initNotifyResult = sendRoadControlInitialNotify();

                    if (initNotifyResult)
                    {
                        if (eqpt.SafetyCheckRequest)//沒有被取消
                        {
                            //如果現在這組CV的狀態是DISABLE而且是由SAFETY_DISABLE而且有通知這組CV已經可以開啟,
                            //就可以直接回覆Complete
                            if (pre_control_segment.DISABLE_FLAG_SAFETY &&
                                pre_control_segment.STATUS == E_SEG_STATUS.Closed &&
                                node.SafetyCheckComplete)
                            {
                                Pre_control_segment_ControlComplete(pre_control_segment, null);
                            }
                            else
                            {
                                //註冊該segment control complete的事件
                                pre_control_segment.ControlComplete += Pre_control_segment_ControlComplete;

                                //開始處理CV的OP in request時,要處理的事項
                                //1.predisable 該CV所在路段 Todo by Kevin
                                //2.確認無車輛會再過該CV路段 Todo by Kevin
                                //3.disable 該CV所在路段 Todo by Kevin
                                //4.當上述條件成功時,會觸發"ControlComplete"的事件
                                scApp.RoadControlService.ProcessCVOpInRequest(eqpt);
                            }
                            //bool completeNotifyResult = sendRoadControlCompleteNotify(); //disable路段後發出Complete Notify
                            //if (completeNotifyResult)
                            //{
                            //    //do nothing
                            //}
                            //else
                            //{
                            //    BCFApplication.onWarningMsg($"OHTC send road control complete notify to OHCV:[{eqpt.EQPT_ID}] with error happend.");
                            //    return;
                            //}
                        }
                        else//被中途取消了
                        {
                            //do nothing
                        }
                    }
                    else
                    {
                        BCFApplication.onWarningMsg($"OHTC send road control initial notify to OHCV:[{eqpt.EQPT_ID}] with error happend.");
                        return;
                    }
                }
                else//SafetyCheckRequest訊號OFF
                {
                    //當SafetyCheckRequest關閉後,就再次取消註冊的Control complete事件,確保已經不會再收到控制完成的通知。
                    pre_control_segment.ControlComplete -= Pre_control_segment_ControlComplete;

                    if (eqpt.SafetyCheckComplete)
                    {
                        //donothing
                    }
                    else
                    {
                        cancelSafetyCheckRequest();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
        }