Esempio n. 1
0
        private bool GenLEUGlobalFile(LEURF leurf, LEUGlobal leugb, GID gid, string filename)
        {
            try
            {
                XmlFileHelper xmlFile = XmlFileHelper.CreateFromString(null);
                //根据LEU Result Filtered Values文件的内容修改可变部分的值
                leugb.leuName      = leurf.leuName;
                leugb.inBoard.gid  = gid.ibGid;
                leugb.outBoard.gid = gid.ouGid;
                //5.2.1生成Output_balise,TBD
                foreach (LEUBeacon beacon in leurf.beaconList)
                {
                    OutBalise ob = new OutBalise();
                    ob.id       = beacon.outNum;
                    ob.telegram = "LONG";

                    leugb.obList.Add(ob);
                }
                leugb.encoder.netGid = gid.netGid;

                //根据模板文件格式写入LEU文件
                XmlVisitor leuNode = leugb.Write();
                xmlFile.SetRoot(leuNode);
                xmlFile.Save2File(filename);
                return(true);
            }
            catch (System.Exception ex)
            {
                return(false);
            }
        }
Esempio n. 2
0
        private void GenTJFormatFileHead(string path)
        {
            string        logMsg      = "";
            XmlVisitor    allFileRoot = null;
            string        filename    = string.Format("{0}\\all_beacons.xml", path);
            XmlFileHelper allxmlFile  = XmlFileHelper.CreateFromString(null);

            AddLogHead(ref allxmlFile);

            allxmlFile.SetRoot("Beacons", null);
            allxmlFile.Save2File(filename);

            allFileRoot = allxmlFile.GetRoot();
            allFileRoot.UpdateAttribute("NUMBERS", sydb.GetBeacons().Count());

            foreach (IBeaconInfo beacon in sydb.GetBeacons())
            {
                string telValue = "";
                if (isITC)
                {//BMGR-0004
                    TraceMethod.RecordInfo("iTC not support now!");
                    telValue = "iTC not support";
                }
                else
                {
                    BeaconMessage bm = new BeaconMessage();
                    telValue = bm.GenerateMessage(beacon, sydb.LineID);
                }

                byte[] urstel = DataOpr.String2byte(telValue);

                XmlVisitor beaconNode = XmlVisitor.Create("Beacon", null);
                beaconNode.UpdateAttribute("ID", beacon.ID);
                beaconNode.UpdateAttribute("NAME", beacon.Name);
                byte[] content = new byte[128];
                bool   result  = DataOpr.PackCallScram_Tel(urstel, content);
                if (result)
                {
                    string tel1 = DataOpr.Byte2string(content);
                    beaconNode.AppendChild("Telegram0", telValue);
                    beaconNode.AppendChild("Telegram1", tel1);
                }
                else
                {
                    logMsg = string.Format("Encoding Error!");
                    TraceMethod.RecordInfo(logMsg);
                    continue;
                }
                allFileRoot.AppendChild(beaconNode);
            }

            allxmlFile.Save2File(filename);
            logMsg = "Generate basic_beacons.xml file successfully!";
            TraceMethod.RecordInfo(logMsg);
        }
Esempio n. 3
0
        private void Init()
        {
            logFile = currentRunDir + "\\Log\\BMGen.log";
            logMsg  = "BMGen started.";
            TraceMethod.RecordInfo(logMsg);

            //deal the config.xml which used to save the configuration
            configFile = currentRunDir + "\\Config\\config.xml";

            if (!File.Exists(configFile))
            {//create a new config file, which is empty
                XmlFileHelper xmlFile = XmlFileHelper.CreateFromString(null);
                xmlFile.SetRoot("config", null);
                if (!Directory.Exists(currentRunDir + "\\Config\\"))
                {
                    Directory.CreateDirectory(currentRunDir + "\\Config\\");
                }
                xmlFile.Save2File(configFile);
            }
            else
            {
                //set the input file path
                setTextBox(textBoxSyDB, "BeaconLayout_SYDB");
                setTextBox(textBoxLayout, "Layout_beacons");
                setTextBox(textBoxBoundaryBeacon, "Boundary_beacons");
                //set the output path
                setTextBox(textBoxOutput, "Output");
                setTextBox(textBox_UpstreamFile, "Upstream_File");
            }

            if (BMGenTest.Program.GenerateTJFormat)
            {
                Assembly ass = Assembly.LoadFile(Path.GetFullPath(".//MetaFly.dll"));
                Version  ver = ass.GetName().Version;
                TraceMethod.RecordInfo("MetaFly.dll " + ver.ToString());
            }

            {
                this.Text = "Bcode_iTRNV-BMGenTool2_V1.0.2_Build_20200409_debug";
                //set the project
                radioButtoniTC.Checked           = false;
                Upstream_path_considered.Checked = false;
                radioButtonInteroperable.Checked = true;
                //set if choose generate bin files
                checkBoxGenBin.Checked = false;
                UpdateUpstreamPage();
            }

            if (Program.AUTOTEST)
            {
                object    nullobj = new object();
                EventArgs nulle   = new EventArgs();
                progressBar1_Click(nullobj, nulle);
            }
        }
Esempio n. 4
0
        private bool GenerateBMVFile(string filename)
        {
            XmlFileHelper xmlFile = XmlFileHelper.CreateFromString(null);

            AddLogHead(ref xmlFile);
            xmlFile.SetRoot("Block_mode_beacons", null);

            XmlVisitor root = xmlFile.GetRoot();

            root.UpdateAttribute("LINE_ID", sydb.LineID);//BMGR-0014 log lineID

            foreach (BEACON beacon in GetValidBeaconList())
            {
                XmlVisitor beaconNode = XmlVisitor.Create("Beacon", null);

                if (false == beacon.SetBeaconInfoNode_BMVF(ref beaconNode) ||
                    false == GenerateLEUInfoNode(beacon.m_ibbmInfo, ref beaconNode) ||
                    false == GenerateBMBSDDBDisInfoNode(beacon, ref beaconNode))
                {
                    //log error
                    TraceMethod.RecordInfo($"Warning:GenerateBMVFile base info[Beacon][LEU][BMBSDDB_Distance] faild for {beacon.Info}.");
                }

                //then all reopen sig and the approach sig
                foreach (OriginSignal orgSig in beacon.GetOrgSignalList())
                {
                    beaconNode.AppendChild(orgSig.GetXmlNode(beacon.Name));
                }

                beaconNode.AppendChild(CalBMVariantNode(beacon));
                root.AppendChild(beaconNode);
            }

            xmlFile.Save2File(filename);
            return(true);
        }
Esempio n. 5
0
        //for tj format
        private bool GenBasciXml(string leuFile, string outputPath)
        {
            LEU_filtered_values leurfxml = FileLoader.Load <LEU_filtered_values>(leuFile);

            List <BasicBeacon> BeaconInfoList = new List <BasicBeacon>();

            foreach (LEU_filtered_values.leu leurf in leurfxml.LEU)
            {
                foreach (LEU_filtered_values.leu.BEACON leuBeacon in leurf.Beacon)
                {
                    BasicBeacon baBeacon = new BasicBeacon(leuBeacon);
                    var         signal   = (GENERIC_SYSTEM_PARAMETERS.SIGNALS.SIGNAL)Sys.GetNode((string)leuBeacon.LINKED_SIGNAL,sydb.signalInfoList.Cast <Node>().ToList());
                    if (null == signal)
                    {
                        continue;
                    }
                    baBeacon.SignalId   = signal.ID;
                    baBeacon.SignalName = signal.Name;
                    baBeacon.MsgList    = new List <MsgRank>();
                    foreach (LEU_filtered_values.leu.BEACON.MESSAGE msg in leuBeacon.msgList)
                    {
                        MsgRank msgRk = new MsgRank();
                        msgRk.routeInfo = new List <string>();
                        //按照Upstream_section,Reopening_section,Approach_section,Overlap_section的顺序将进路上的道岔和信号机依次取出
                        //先算道岔,再算信号机
                        List <string> ptList  = new List <string>();
                        List <string> sigList = new List <string>();
                        if (null != msg.Combined_sections)
                        {
                            JudgeSection(msg.Combined_sections.Upstream_section,ptList,sigList);
                            JudgeSection(msg.Combined_sections.Reopening_section,ptList,sigList);
                            JudgeSection(msg.Combined_sections.Approach_section,ptList,sigList);
                            JudgeSection(msg.Combined_sections.Overlap_section,ptList,sigList);
                        }

                        msgRk.routeInfo.AddRange(ptList);
                        msgRk.routeInfo.AddRange(sigList);

                        //计算tel0和tel1
                        msgRk.Tel0 = msg.Interoperable;
                        byte[] content  = new byte[128];
                        byte[] telValue = DataOpr.String2byte(msgRk.Tel0);
                        bool   result   = ScrambleTel(telValue,content);
                        if (result)
                        {
                            msgRk.Tel1 = DataOpr.Byte2string(content);
                        }
                        else
                        {
                            TraceMethod.RecordInfo("Encoding Error!");
                            continue;
                        }
                        baBeacon.MsgList.Add(msgRk);
                    }
                    BeaconInfoList.Add(baBeacon);
                }
            }

            //写入可变报文配置文件
            string        allFileName = string.Format("{0}\\basic_beacons.xml",outputPath);
            XmlFileHelper allxmlFile  = XmlFileHelper.CreateFromString(null);

            AddLogHead(ref allxmlFile);
            allxmlFile.SetRoot("Beacons",null);
            allxmlFile.Save2File(allFileName);

            XmlVisitor allFileRoot = allxmlFile.GetRoot();

            allFileRoot.UpdateAttribute("NUMBERS",BeaconInfoList.Count);

            foreach (BasicBeacon basBeacon in BeaconInfoList)
            {
                XmlVisitor beaconNode = XmlVisitor.Create("Beacon",null);
                beaconNode.UpdateAttribute("ID",basBeacon.ID);
                beaconNode.UpdateAttribute("NAME",basBeacon.Name);
                beaconNode.UpdateAttribute("RANKS",basBeacon.MsgList.Count());
                beaconNode.UpdateAttribute("TYPE",basBeacon.Type);
                beaconNode.UpdateAttribute("LINKED_SIGNALID",basBeacon.SignalId);
                beaconNode.UpdateAttribute("LINKED_SIGNALName",basBeacon.SignalName);
                for (int i = 0; i < basBeacon.MsgList.Count(); i++)
                {
                    XmlVisitor rankNode = XmlVisitor.Create("Message",null);
                    rankNode.UpdateAttribute("Rank",i);
                    string route = "";
                    foreach (string info in basBeacon.MsgList[i].routeInfo)
                    {
                        route += info + "|";
                    }
                    if (route.EndsWith('|'.ToString()))
                    {
                        route = route.Remove(route.LastIndexOf('|'));
                    }
                    if ("" != route)
                    {
                        rankNode.AppendChild("Route", route);
                    }
                    rankNode.AppendChild("Telegram0", basBeacon.MsgList[i].Tel0);
                    rankNode.AppendChild("Telegram1", basBeacon.MsgList[i].Tel1);
                    beaconNode.AppendChild(rankNode);
                }
                allFileRoot.AppendChild(beaconNode);
            }
            allxmlFile.Save2File(allFileName);
            return(true);
        }
Esempio n. 6
0
        private bool GenerateLEUResultFilterFile(string filename)
        {
            XmlFileHelper xmlFile = XmlFileHelper.CreateFromString(null);

            AddLogHead(ref xmlFile);

            //BMGR-0044
            xmlFile.SetRoot("LEU_filtered_values", null);
            xmlFile.Save2File(filename);

            XmlVisitor root = xmlFile.GetRoot();

            //BMGR-0044
            root.UpdateAttribute("LINE_ID", sydb.LineID);

            //BMGR-0045
            List <LEU> orderLEULst = m_LEULst.OrderBy(o => o.ID).ToList();

            foreach (LEU leu in orderLEULst)
            {
                XmlVisitor LEUnode = XmlVisitor.Create("LEU", null);

                //set LEU info
                if (false == GenerateLEUInfoNode(leu, ref LEUnode))
                {
                    return(false);
                }

                string[] bNames = leu.GetBeaconNames();
                //BMGR-0046
                for (int i = 0; i < bNames.Count(); ++i)
                {
                    string bName = bNames[i];
                    if ("" == bName)
                    {
                        continue;
                    }
                    int Bidx = m_BeaconLst.FindIndex(x => (x.Name == bName));
                    if (-1 == Bidx)
                    {
                        TraceMethod.RecordInfo($"Warning:LEU[{leu.Name}] contain beacon[{bName}] which not in valid beacon List, this beacon will be ignore!");
                        continue;
                    }

                    XmlVisitor beaconnode = XmlVisitor.Create("Beacon", null);
                    if (false == GenerateBeaconInfoNode(m_BeaconLst[Bidx], ref beaconnode, i + 1))
                    {
                        //
                    }

                    m_BeaconLst[Bidx].m_MsgLst = GenerateMessage(m_BeaconLst[Bidx]);

                    if (m_BeaconLst[Bidx].m_MsgLst.Count() > 128)
                    {//BMGR-0050
                        TraceMethod.RecordInfo($"LEU[{leu.Info} {m_BeaconLst[Bidx].Info}] generate messages {m_BeaconLst[Bidx].m_MsgLst.Count()} > 128");
                    }

                    foreach (Message msg in m_BeaconLst[Bidx].m_MsgLst)
                    {
                        //mes and combine_sections
                        XmlVisitor msgNode = msg.GetXmlNode();

                        //BMGR-0051 Variant_state
                        string varstate = GetMsgVar(msg, m_BeaconLst[Bidx]);
                        if (BEACON.MAXVARNUM != varstate.Length)
                        {
                            TraceMethod.RecordInfo($"Beacon[{m_BeaconLst[Bidx].Name}] Variant_state[{varstate}] length != {BEACON.MAXVARNUM}");
                        }
                        msgNode.AppendChild("Variant_state", varstate);

                        string msgBuff = "";
                        //Urbalis_iTC
                        if (0 == msg.GetRank())
                        {//BMGR-0004 leu default msg for input beacon
                            varstate = "";
                        }

                        //don't output Urbalis_iTC for BMGen tool this time
#if itcsupport
                        msgBuff = m_BeaconLst[Bidx].GenMsgItc(varstate);
                        if (86 != msgBuff.Length)
                        {
                            TraceMethod.RecordInfo(string.Format("Beacon[{0}] Urbalis_iTC message length != 16",
                                                                 m_BeaconLst[Bidx].Name));
                            return(false);
                        }

                        msgNode.AppendChild("Urbalis_iTC", msgBuff);
#endif
                        //Interoperable
                        BeaconMessage bm = new BeaconMessage();
                        msgBuff = bm.GenerateMessage(m_BeaconLst[Bidx], sydb.LineID, msg);

                        if (311 != msgBuff.Length)
                        {
                            TraceMethod.RecordInfo($"{m_BeaconLst[Bidx].Info} Interoperable message length != 311");
                        }
                        msgNode.AppendChild("Interoperable", msgBuff);

                        beaconnode.AppendChild(msgNode);
                    }

                    LEUnode.AppendChild(beaconnode);
                }

                root.AppendChild(LEUnode);
            }
            xmlFile.Save2File(filename);
            return(true);
        }
Esempio n. 7
0
        private bool GenLEUXmlFile(LEU_filtered_values.leu leurf, GID gid, string filename)
        {
            try
            {
                XmlFileHelper xmlFile = XmlFileHelper.CreateFromString(null);
                AddLogHead(ref xmlFile);

                //根据LEU Result Filtered Values文件的内容修改可变部分的值
                leuXmlTemplate.name = leurf.NAME;

                //5.2.1生成Output_balise
                leuXmlTemplate.Output_balise.Clear();//先清掉已有数据

                //calculate leugb.obList by leurf.beaconList
                #region [cal oblist]
                foreach (LEU_filtered_values.leu.BEACON beacon in leurf.beaconList)
                {
                    LEUXML.LEU.OUTPUT_BALISE ob = new LEUXML.LEU.OUTPUT_BALISE(beacon.NAME, beacon.NUM);

                    string[] varInputs = beacon.Variants_inputs.ToString().Split(' ');
                    int      index     = 0;
                    //BMGR-0064
                    foreach (string varInput in varInputs)
                    {
                        if (varInput != "0")
                        {
                            LEUXML.LEU.OUTPUT_BALISE.INPUT input = new LEUXML.LEU.OUTPUT_BALISE.INPUT();
                            input.Channel = new StringData("00");
                            input.Number  = new StringData(varInput.PadLeft(2, '0'));
                            input.index   = index;
                            ob.Input.Add(input);
                        }
                        ++index;//BMGR-0072 this is the pos index in variant_input and varait_state
                    }
                    ob.Input.Sort((x, y) =>
                    {
                        return(x.Number.ToString().CompareTo(y.Number.ToString()));   //根据intNum重新排序,这个排序影响mask的值
                    });

                    foreach (LEU_filtered_values.leu.BEACON.MESSAGE msg in beacon.msgList)
                    {
                        if (0 != msg.RANK)//BMGR-0071
                        {
                            LEUXML.LEU.OUTPUT_BALISE.ASPECT asp = new LEUXML.LEU.OUTPUT_BALISE.ASPECT();
                            string mask = "";
                            //BMGR-0072
                            //根据Input的顺序确定其在MASK中的位置,根据其num找到其在Variants_inputs中的索引
                            //根据其在Variants_inputs中索引,确定此码位在Variant_state中的索引.[两个索引相等]
                            //判断此索引位置的值,为0则取0,为1则取1,为P或S则取X,然后将MASK不足X至30位
                            foreach (var inNode in ob.Input)
                            {
                                string value = msg.VarState.Substring(inNode.index, 1);
                                if (value == "0")
                                {
                                    mask += '0';
                                }
                                else if (value == "1")
                                {
                                    mask += '1';
                                }
                                else if (value == "P" || value == "S")
                                {
                                    mask += 'X';
                                }
                            }
                            //补足30位
                            for (int i = mask.Length; i < 30; i++)
                            {
                                mask += 'X';
                            }
                            asp.Mask = new StringData(mask);
                            //BMGR-0073
                            if (isITC)
                            {
                                throw new NotImplementedException();
                            }
                            else
                            {
                                asp.Telegram = msg.Interoperable;
                            }
                            ob.CheckAspect(asp);
                            ob.Aspect.Add(asp);
                        }
                    }
                    //BMGR-0074
                    LEU_filtered_values.leu.BEACON.MESSAGE dftMsg = beacon.msgList.Find(x => (int)x.RANK == 0);
                    if (isITC)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        ob.Default_telegram = dftMsg.Interoperable;
                    }
                    leuXmlTemplate.Output_balise.Add(ob);
                }
                #endregion

                //GMBR-0060
                leuXmlTemplate.updateGid(gid);

                FileSerializer.Serialize(leuXmlTemplate, filename, AddLogHead());

                return(true);
            }
            catch (System.Exception ex)
            {
                TraceMethod.Record(TraceMethod.TraceKind.ERROR, ex.Message);
                return(false);
            }
        }