Esempio n. 1
0
        /// <summary>
        /// test generate default message of VB and FB from csv and xml
        /// </summary>
        public void test_DefaultGenerateMessage()
        {
            BeaconMessage bm = new BeaconMessage();

            Debug.Assert("" == bm.GenerateMessage(null, 1));

            //Arrange
            string csv   = ".//input//validbeacons.csv";
            string xml   = ".//input//validbeacons.xml";
            BFGen  bfgen = new BFGen(csv, xml, "", false, false);

            Debug.Assert(bfgen.Init() == true);
            SyDB sydb = SyDB.GetInstance();

            int[] lineids = { 0, 1, 0x3ff };
            int   i       = 0;

            foreach (IBeaconInfo b in sydb.GetBeacons())
            {
                //Act
                BeaconMessage bm1    = new BeaconMessage();
                int           lineid = lineids[i % (lineids.Count())];
                checkbeaconmessage(b, bm1.GenerateMessage(b, lineid), lineid);
                ++i;
            }
            Debug.Assert(i == 12);
        }
Esempio n. 2
0
 public static SyDB GetInstance()
 {
     if (null == _SyDB)
     {
         _SyDB = new SyDB();
     }
     return(_SyDB);
 }
Esempio n. 3
0
        /// <summary>
        /// clear the old data in sydb, then load new data from input file
        /// </summary>
        /// <param name="filefullname"></param>
        public static void ReloadGlobalSydb(string filefullname)
        {
            GENERIC_SYSTEM_PARAMETERS sydbdata = FileLoader.Load <GENERIC_SYSTEM_PARAMETERS>(filefullname);
            SyDB sydb = SyDB.GetInstance();

            sydb.clear();
            sydb.LoadData(sydbdata);
        }
Esempio n. 4
0
 public BinaryTree(Block block, string dir, int id, SyDB sydb)
 {
     _root = new BlockNode(block);
     _dir  = dir;
     _sydb = sydb;
     _id   = id;
     Add(_root);
 }
Esempio n. 5
0
 public BinaryTree(Block block, int distance, string dir, SyDB sydb, string type, bool reverse)
 {
     _root     = new BlockNode(block);
     _distance = distance;
     _dir      = dir;
     _sydb     = sydb;
     _type     = type;
     _reverse  = reverse;
     Add(_root, _type, 0);
 }
Esempio n. 6
0
        public RouteSegment(GENERIC_SYSTEM_PARAMETERS.ROUTES.ROUTE route)
        {
            m_BlkLst = new List <GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK>();
            foreach (int blkID in route.Block_ID_List.Block_ID)
            {
                var blk = (GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK)Sys.GetNode(blkID,SyDB.GetInstance().blockInfoList.Cast <Node>().ToList());
                m_BlkLst.Add(blk);
            }

            SetRouteSegment(route.Origin_Signal_ID,route.Destination_Signal_ID,route);
        }
Esempio n. 7
0
 public static GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK GetLocatedBlock(KP_V kp, int TrackID)
 {
     foreach (GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK node in SyDB.GetInstance().blockInfoList)
     {
         if (TrackID == node.Track_ID &&
             Math.Abs(node.Kp_Begin - node.Kp_End) == Math.Abs(node.Kp_Begin - kp.KpRealValue) + Math.Abs(node.Kp_End - kp.KpRealValue)
             )
         {
             return(node);
         }
     }
     return(null);
 }
Esempio n. 8
0
        public static int GetSigIDInBlock(int blkID, List <int> sigList)
        {
            SyDB sydb  = SyDB.GetInstance();
            var  block = (GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK)Sys.GetNode(blkID, sydb.blockInfoList.Cast <Node>().ToList());

            foreach (int sID in sigList)
            {
                GENERIC_SYSTEM_PARAMETERS.SIGNALS.SIGNAL sig = sydb.signalInfoList.Find(x => x.ID == sID);
                if (null != sig && true == SyDB.IsLocatedOnBlock(sig.Kp,sig.Track_ID,block))
                {
                    return(sID);
                }
            }
            return(-1);
        }
Esempio n. 9
0
        void RunBFGenInit(object obj)
        {
            BFGen bfgen = new BFGen("", beaconxmlfullname, "", false, false);

            bfgen.Init();
            if (obj != null)
            {
                int BMB_SDDB_distance_cm = (int)(obj);

                SyDB sydb             = SyDB.GetInstance();
                List <IBeaconInfo> bs = sydb.GetBeacons();

                Debug.Assert(bs[0].BMB_Distance_cm == BMB_SDDB_distance_cm);
            }
        }
Esempio n. 10
0
        //check read csv file, only right range beacon will read in
        //check read xml file
        //check repeat beacon id or repeat beacon name will be ignore
        void test_BFGenIni()
        {
            //Arrange
            Func <int, bool> checkbeaconnumber = (num) =>
            {
                SyDB sydb             = SyDB.GetInstance();
                List <IBeaconInfo> bs = sydb.GetBeacons();
                Debug.Assert(bs.Count == num);//only read the valid beacons
                return(true);
            };

            Func <int, int[], bool> checkbeaconkps = (num, kps) =>
            {
                SyDB sydb             = SyDB.GetInstance();
                List <IBeaconInfo> bs = sydb.GetBeacons();
                Debug.Assert(bs.Count == num);//only read the valid beacons

                for (int i = 0; i < kps.Length; ++i)
                {
                    Debug.Assert(bs[i].kp.Value == kps[i]);
                }
                return(true);
            };

            string csv = ".//input//beacons.csv";
            string xml = ".//input//beacons.xml";
            //Arrange of wrong file type
            BFGen bfgen = new BFGen(xml, csv, "", false, false);

            //Act   Assert
            Debug.Assert(bfgen.Init() == false);

            //no file
            bfgen = new BFGen("", "", "", false, false);
            Debug.Assert(bfgen.Init() == false);

            //csv: input data valid range
            bfgen = new BFGen(csv, "", "", false, false);
            Debug.Assert(bfgen.Init() == true);
            int[] kpscsv = { 0, 10000000, 9999900, 9999910, 9999992, 9999992, 0, 10000000, 9999900, 9999910, 9999992, 9999992 }; //valid beacon kps from csv
            checkbeaconkps(21, kpscsv);

            //csv and xml beacon repeated
            bfgen = new BFGen(csv, xml, "", false, false);
            Debug.Assert(bfgen.Init() == true);
            //delete the beacon of same name and same ID
            checkbeaconnumber(24);
        }
Esempio n. 11
0
        private void SetRouteSegment(int orgID,int dstID,GENERIC_SYSTEM_PARAMETERS.ROUTES.ROUTE route)
        {
            this.RouteInfo = route;
            GENERIC_SYSTEM_PARAMETERS.SIGNALS.SIGNAL orgSig = SyDB.GetInstance().signalInfoList.Find(x => x.ID == orgID);
            GENERIC_SYSTEM_PARAMETERS.SIGNALS.SIGNAL dstSig = SyDB.GetInstance().signalInfoList.Find(x => x.ID == dstID);

            if (null == orgSig || null == dstSig)
            {
                throw new Exception($"sydb error:{route.Info} create RouteSegment error. can't find orgsig[{orgID}] or dstsig[{dstID}] in sydb.Signal");
            }

            OrgSig = orgSig;
            DstSig = dstSig;

            if (0 == m_BlkLst.Count())
            {
                throw new Exception($"sydb error:{Info} error. has no block in route");
            }
            m_PtLst = new List <PointInfo>();
            GetPointLstFromBlkLst();
        }
Esempio n. 12
0
        public static bool checkbeaconfiles(string path, bool hasbin)
        {
            bool check = false;

            if (Directory.Exists(path) &&
                Directory.Exists(Path.Combine(path, "Beacon")))
            {
                SyDB sydb                   = SyDB.GetInstance();
                List <IBeaconInfo> bs       = sydb.GetBeacons();
                List <string>      postfixs = new List <string>();
                postfixs.Add(".xml");
                if (hasbin)
                {
                    postfixs.Add(".tgm");
                    postfixs.Add(".udf");
                }
                foreach (IBeaconInfo b in bs)
                {
                    string subpath = Path.Combine(path, "Beacon");
                    foreach (string fix in postfixs)
                    {
                        if (!File.Exists(Path.Combine(subpath, $"{b.Name}{fix}")))
                        {
                            return(false);
                        }
                        else
                        {
                            check = true;
                        }
                    }
                }
            }
            else
            {
                return(false);
            }
            return(check);
        }
Esempio n. 13
0
        //BMGR-0069 cal ol points info by block link
        private void GeneratePathPtList(GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK curB,string dir,string pos,ref List <PointInfo> ptList)
        {
            int nextID = SyDB.GetNextBlkID(curB,dir,pos);

            if (nextID == curB.ID)//there is a coo, then change dir
            {
                dir    = SyDB.GetReverseDir(dir);
                nextID = SyDB.GetNextBlkID(curB,dir,pos);
            }

            if (-1 != m_Ol.Overlap_Block_ID_List.Block_ID.FindIndex(x => nextID == Convert.ToInt32(x.Value)))
            {
                var nextB = (GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK)Sys.GetNode(nextID,SyDB.GetInstance().blockInfoList.Cast <Node>().ToList());
                if (null != curB.Point_ID && null != nextB.Point_ID && curB.Point_ID == nextB.Point_ID)
                {//get a valid point
                    var       pt     = (GENERIC_SYSTEM_PARAMETERS.POINTS.POINT)Sys.GetNode((int)curB.Point_ID,SyDB.GetInstance().pointInfoList.Cast <Node>().ToList());
                    PointInfo ptInfo = new PointInfo(pt,SyDB.GetPosByBlocks(curB,nextB),SyDB.GetOrientByBlocks(curB,nextB),PointLocation.Overlap,this.m_Ol);
                    ptList.Add(ptInfo);
                }
                //go on search next
                GeneratePathPtList(nextB,dir,pos,ref ptList);
            }
        }
Esempio n. 14
0
        //BMGR-0024
        //the blockList is in order of direction
        public bool GetPointLstFromBlkLst()
        {
            m_PtLst.Clear();
            if (0 == m_BlkLst.Count)
            {
                TraceMethod.Record(TraceMethod.TraceKind.ERROR,$"route[{Info}] include no block, original route[{RouteInfo.Info}]\n");
                return(false);
            }

            for (int i = 0; i < m_BlkLst.Count - 1; ++i)
            {
                GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK preBlock  = m_BlkLst[i];
                GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK nextBlock = m_BlkLst[i + 1];
                if (preBlock.Point_ID == nextBlock.Point_ID && null != preBlock.Point_ID)
                {//BMGR-0025 cal point info by block link
                    var point = (GENERIC_SYSTEM_PARAMETERS.POINTS.POINT)Sys.GetNode((int)preBlock.Point_ID,SyDB.GetInstance().pointInfoList.Cast <Node>().ToList());

                    PointInfo objpt = new PointInfo(point,
                                                    SyDB.GetPosByBlocks(preBlock,nextBlock),
                                                    SyDB.GetOrientByBlocks(preBlock,nextBlock),
                                                    PointLocation.Route,
                                                    this.RouteInfo);

                    m_PtLst.Add(objpt);
                }
            }
            if (10 < m_PtLst.Count())
            {
                TraceMethod.Record(TraceMethod.TraceKind.ERROR,$"points in route[{Info}] is more than 10.\n");
                foreach (PointInfo pt in m_PtLst)
                {
                    TraceMethod.RecordInfo(pt.Info);
                }
                return(false);
            }
            return(true);
        }
Esempio n. 15
0
        //BMGR-0067
        //dst sig -> start blk
        //start blk, blk list, end overlap blk lst -> path list
        public bool GeneratePath(GENERIC_SYSTEM_PARAMETERS.IMPLEMENTATION_BEACON_BLOCK_MODE.BM_BEACON input)
        {
            if ("" == m_switchPos)//no path will generate
            {
                return(true);
            }

            if (0 == m_Ol.Overlap_Switch_ID_List.Switch_ID.Count)
            {
                //this ol has no point, so only 1 path with no point.
                PathInfo path = new PathInfo(m_sig);
                m_pathLst.Add(path);
            }
            else
            {
                if (null == m_sig || false == m_sig.checkDirection())
                {
                    TraceMethod.RecordInfo($"GeneratePath error, {Info} sig[{GetSigname()}] is invalid !");
                    return(false);
                }
                if (0 == m_Ol.Overlap_Block_ID_List.Block_ID.Count)
                {
                    TraceMethod.RecordInfo($"GeneratePath error, {Info} Overlap_Block_ID_List is empty!");
                    return(false);
                }

                foreach (string pos in Sys.PointPositions)
                {
                    if (m_switchPos == pos || "Either" == m_switchPos)
                    {
                        var startB = (GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK)Sys.GetNode((int)m_Ol.Overlap_Block_ID_List.Block_ID[0],SyDB.GetInstance().blockInfoList.Cast <Node>().ToList());
                        List <PointInfo> pathPtList = new List <PointInfo>();
                        GeneratePathPtList(startB,m_sig.Direction,pos,ref pathPtList);
                        if (0 == pathPtList.Count)
                        {
                            PathInfo new1Path = new PathInfo(m_sig);
                            m_pathLst.Add(new1Path);
                            break;//get no point, then won't be able to has 2 path
                        }
                        else
                        {
                            PathInfo newPath = new PathInfo(m_sig,pathPtList);
                            m_pathLst.Add(newPath);
                        }
                    }
                }
                if ("Either" == m_switchPos && 2 == m_pathLst.Count())
                {
                    foreach (PathInfo path in m_pathLst)
                    {
                        foreach (PointInfo pt in path.pointList)
                        {
                            if (pt.Orientation == Sys.Divergent)
                            {     //check the point-pos of first divergent point
                                if (-1 == input.getInputRank(pt.Point.Name,pt.Position))
                                { //point-pos not in IBBM, then only reverse path
                                    m_pathLst.RemoveAt(0);
                                }
                                break;
                            }
                        }
                        break;
                    }

                    if (2 == m_pathLst.Count())
                    {
                        if (m_pathLst[0].GetOverlapPathName() == m_pathLst[1].GetOverlapPathName())
                        {
                            m_pathLst.RemoveAt(1);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 16
0
        /// <summary>
        /// route_segment length, based on blk_list, check sddb
        /// </summary>//0035
        /// <param name="blockList"></param>
        /// <returns></returns>
        /// //BMGR-0035
        public int GetLength()
        {
            int len       = 0;
            int startBIdx = 0;

            for (int i = 0; i < m_BlkLst.Count; ++i)
            {
                if (OrgSig.SDDId == m_BlkLst[i].Secondary_Detection_Device_ID &&
                    0 != m_BlkLst[i].Secondary_Detection_Device_ID)
                {
                    startBIdx = i;
                    break;
                }
            }

            int endBIdx = m_BlkLst.Count - 1;

            if (m_BlkLst.Count() > 1)
            {
                //find signal located block
                GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK blk = SyDB.GetLocatedBlock(DstSig.Kp,DstSig.Track_ID);
                if (blk == null)
                {
                    TraceMethod.Record(TraceMethod.TraceKind.ERROR,$"dstSignal{DstSig.Info} can't find located block");
                    return(-1);
                }
                if (SyDB.IsLocatedOnBlockBeginOrEnd(DstSig.Kp,DstSig.Track_ID,blk))
                {
                    if (m_BlkLst.Exists(s => s.ID == blk.ID) == false)
                    {
                        //the last one is the endBIdx, so donothing
                    }
                    else
                    {
                        endBIdx = m_BlkLst.FindIndex(s => s.ID == blk.ID);
                        var preBlk = (GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK)Sys.GetNode((int)(m_BlkLst[endBIdx - 1].ID),SyDB.GetInstance().blockInfoList.Cast <Node>().ToList());
                        if (SyDB.IsLocatedOnBlockBeginOrEnd(DstSig.Kp,DstSig.Track_ID,preBlk))
                        {
                            endBIdx = endBIdx - 1;//route length end with preblk
                        }
                        else
                        {
                            //the located one is the endBIdx, so donothing
                        }
                    }
                }
                else
                {//the local block is the end one
                    if (m_BlkLst.Exists(s => s.ID == blk.ID) == false)
                    {
                        m_BlkLst.Add(blk);
                        ++endBIdx;
                    }
                    else
                    {
                        endBIdx = m_BlkLst.FindIndex(s => s.ID == blk.ID);
                    }
                }
            }

            string log = "";

            for (int i = startBIdx; i <= endBIdx; ++i)
            {
                len += m_BlkLst[i].GetBlockLen();
                log += "[" + m_BlkLst[i].Info + "]";
            }
            //TraceMethod.RecordInfo($"RouteSegment {Info} has blocks {log}");

            return(len);
        }
Esempio n. 17
0
 public bool CalOverlap(GENERIC_SYSTEM_PARAMETERS.IMPLEMENTATION_BEACON_BLOCK_MODE.BM_BEACON ibbm)
 {
     //BMGR-0026
     if (null != DstSig.Overlap_ID)//get overlap
     {
         var ol = (GENERIC_SYSTEM_PARAMETERS.OVERLAPS.OVERLAP)Sys.GetNode((int)DstSig.Overlap_ID,SyDB.GetInstance().overlapInfoList.Cast <Node>().ToList());
         m_overlap = new ObjOverlap(ol,DstSig);
         //BMGR-0067
         if (false == m_overlap.GeneratePath(ibbm))
         {
             TraceMethod.RecordInfo($"RouteSegment {Info} generate overlap path error!");
             return(false);
         }
     }
     else
     {
         m_overlap = null;
     }
     return(true);
 }