示例#1
0
        public bool DoLocateFerry(uint id, ushort ferry_code, out string result)
        {
            if (!Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2)))
            {
                result = "稍后再试!";
                return(false);
            }
            try
            {
                FerryTask task = DevList.Find(c => c.ID == id);
                if (!CheckFerryStatus(task, out result))
                {
                    return(false);
                }

                if (!IsLoadOrEmpty(task, out result))
                {
                    return(false);
                }

                task.DoLocate(ferry_code);
                return(true);
            }
            finally
            {
                Monitor.Exit(_obj);
            }
        }
示例#2
0
        /// <summary>
        /// 定位摆渡车
        /// </summary>
        /// <param name="ferryid">摆渡车ID</param>
        /// <param name="to_track_id">定位轨道ID</param>
        /// <param name="result">结果</param>
        /// <returns></returns>
        internal bool DoLocateFerry(uint ferryid, uint to_track_id, out string result)
        {
            if (!Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2)))
            {
                result = "稍后再试!";
                return(false);
            }
            try
            {
                FerryTask task = DevList.Find(c => c.ID == ferryid);
                if (task == null)
                {
                    result = "找不到设备";
                    return(false);
                }

                if (!CheckFerryStatus(task, out result))
                {
                    return(false);
                }

                //if(!IsLoadOrEmpty(task, out result))
                //{
                //    return false;
                //}

                if (task.Status == DevFerryStatusE.停止 &&
                    (task.DevStatus.CurrentTask == task.DevStatus.FinishTask ||
                     task.DevStatus.CurrentTask == DevFerryTaskE.未知 ||
                     ((task.DevStatus.CurrentTask == DevFerryTaskE.终止 || task.DevStatus.CurrentTask == DevFerryTaskE.定位) &&
                      (task.DevStatus.FinishTask == DevFerryTaskE.未知 || task.DevStatus.FinishTask == DevFerryTaskE.定位))))
                {
                    if (task.DevStatus.TargetSite != 0 && PubMaster.Track.GetTrackId(task.DevStatus.TargetSite) != to_track_id)
                    {
                        Thread.Sleep(500);
                        task.DoStop();
                        return(false);
                    }

                    //上砖测轨道ID 或 下砖测轨道ID
                    if (task.UpTrackId == to_track_id && task.IsUpLight)
                    {
                        if (task.DevStatus.CurrentTask == DevFerryTaskE.终止)
                        {
                            return(true);
                        }
                        else
                        {
                            Thread.Sleep(500);
                            task.DoStop();
                        }

                        return(false);
                    }

                    if (task.DownTrackId == to_track_id && task.IsDownLight)
                    {
                        if (task.DevStatus.CurrentTask == DevFerryTaskE.终止)
                        {
                            return(true);
                        }
                        else
                        {
                            Thread.Sleep(500);
                            task.DoStop();
                        }

                        return(false);
                    }

                    // 定位前检查同轨道的摆渡车
                    List <AreaDevice> areatras = PubMaster.Area.GetAreaDevList(task.AreaId, task.Type);
                    //List<AreaDevice> areatras = PubMaster.Area.GetAreaDevListWithType(task.Type);
                    uint  taskTrackId;
                    short trackOrder;
                    short takeTrackOrder = PubMaster.Track.GetTrack(to_track_id)?.order ?? 0;
                    int   safedis        = PubMaster.Dic.GetDtlIntCode("FerryAvoidNumber");
                    foreach (AreaDevice ferry in areatras)
                    {
                        if (ferry.device_id != ferryid)
                        {
                            //同区域另一台摆渡车
                            FerryTask taskB = DevList.Find(c => c.ID == ferry.device_id);
                            if (!CheckFerryStatus(taskB, out string r))
                            {
                                continue;
                            }

                            //另一台摆渡车对着的轨道id
                            uint taskBTrackId = taskB.GetFerryCurrentTrackId();

                            short trackBOrder = PubMaster.Track.GetTrack(taskBTrackId)?.order ?? 0;

                            //另一台摆渡车的目的轨道的顺序
                            short taskBTargetOrder = PubMaster.Track.GetTrackByCode(taskB.DevStatus.TargetSite)?.order ?? 0;

                            //当前摆渡车对着的轨道id
                            taskTrackId = task.GetFerryCurrentTrackId();

                            //当前摆渡车对着的轨道的顺序
                            trackOrder = PubMaster.Track.GetTrack(taskTrackId)?.order ?? 0;

                            if (trackBOrder == 0 || trackOrder == 0)
                            {
                                return(false);
                            }

                            int leftCompare, rightCompare;
                            if (trackOrder >= takeTrackOrder)
                            {
                                leftCompare  = takeTrackOrder - safedis;
                                rightCompare = trackOrder + safedis;
                            }
                            else
                            {
                                leftCompare  = trackOrder - safedis;
                                rightCompare = takeTrackOrder + safedis;
                            }
                            leftCompare = leftCompare < 0 ? 0 : leftCompare;
                            switch (taskB.Status)
                            {
                            case DevFerryStatusE.停止:
                                //当前摆渡车要前进
                                if ((leftCompare < trackBOrder && trackBOrder < rightCompare) ||
                                    (leftCompare < taskBTargetOrder && taskBTargetOrder < rightCompare))
                                {
                                    if (taskB.IsFerryLock())
                                    {
                                        return(false);
                                    }
                                    uint avoidTrackId;
                                    if (trackOrder < takeTrackOrder)
                                    {
                                        avoidTrackId = PubMaster.Track.GetTrackIdByDifference(to_track_id, safedis, true);
                                    }
                                    else
                                    {
                                        avoidTrackId = PubMaster.Track.GetTrackIdByDifference(to_track_id, safedis, false);
                                    }
                                    if (PubMaster.Track.GetTrackFerryCode(avoidTrackId, task.Type, out ushort newtrackferrycode, out result))
                                    {
                                        taskB.DoLocate(newtrackferrycode);
                                        return(false);
                                    }
                                }
                                break;

                            case DevFerryStatusE.前进:
                            case DevFerryStatusE.后退:
                                //当前摆渡车在另一台摆渡车的后面
                                if ((leftCompare < trackBOrder && trackBOrder < rightCompare) ||
                                    (leftCompare < taskBTargetOrder && taskBTargetOrder < rightCompare))
                                {
                                    return(false);
                                }
                                break;

                            default:
                                return(false);
                            }
                        }
                    }

                    if (PubMaster.Track.GetTrackFerryCode(to_track_id, task.Type, out ushort trackferrycode, out result))
                    {
                        task.DoLocate(trackferrycode);
                    }
                }
            }
            finally
            {
                Monitor.Exit(_obj);
            }

            return(false);
        }
示例#3
0
        public bool DoManualLocate(uint ferryid, uint trackid, bool isdownferry, out string result)
        {
            Track tra = PubMaster.Track.GetTrack(trackid);

            if (tra == null)
            {
                result = "找不到轨道信息!";
                return(false);
            }

            if (!PubMaster.Area.IsFerrySetTrack(ferryid, tra.id))
            {
                result = "摆渡车未配置" + tra.name + "!";
                return(false);
            }

            ushort ferrycode = tra.ferry_down_code;

            if (isdownferry)
            {
                if (tra.Type == TrackTypeE.砖轨道 || tra.Type == TrackTypeE.储砖_出)
                {
                    result = "请选择下砖区域的轨道";
                    return(false);
                }
            }
            else
            {   //上砖摆渡
                if (tra.Type == TrackTypeE.砖轨道 || tra.Type == TrackTypeE.储砖_入)
                {
                    result = "请选择上砖区域的轨道";
                    return(false);
                }
            }

            switch (tra.Type)
            {
            case TrackTypeE.砖轨道:
                ferrycode = tra.ferry_up_code;
                break;

            case TrackTypeE.砖轨道:
                ferrycode = tra.ferry_down_code;
                break;

            case TrackTypeE.储砖_入:
                ferrycode = tra.ferry_up_code;
                break;

            case TrackTypeE.储砖_出:
                ferrycode = tra.ferry_down_code;
                break;

            case TrackTypeE.储砖_出入:
                ferrycode = isdownferry ? tra.ferry_up_code : tra.ferry_down_code;
                break;

            case TrackTypeE.摆渡车_入:
            case TrackTypeE.摆渡车_出:
                result = "请重新选择其他轨道";
                return(false);
            }

            if (Monitor.TryEnter(_obj, TimeSpan.FromSeconds(2)))
            {
                try
                {
                    //查看是否有小车正在上摆渡车
                    FerryTask task = DevList.Find(c => c.ID == ferryid);
                    if (!CheckFerryStatus(task, out result))
                    {
                        return(false);
                    }

                    if (!IsLoadOrEmpty(task, out result))
                    {
                        return(false);
                    }

                    if (task.IsUpLight &&
                        PubTask.Carrier.HaveCarrierTaskInTrack(task.UpTrackId, DevCarrierTaskE.后退至摆渡车))
                    {
                        result = "小车正在上摆渡车";
                        return(false);
                    }

                    if (task.IsDownLight &&
                        PubTask.Carrier.HaveCarrierTaskInTrack(task.DownTrackId, DevCarrierTaskE.前进至摆渡车))
                    {
                        result = "小车正在上摆渡车";
                        return(false);
                    }

                    task.DoLocate(ferrycode);
                    return(true);
                }
                finally
                {
                    Monitor.Exit(_obj);
                }
            }
            result = "稍后再试!";
            return(false);
        }