//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); }
private bool Init() { if (isBin) { if (!File.Exists(leuComPath)) { string logMsg = string.Format("[{0}] the compile tool for bin file is not exist, please check!", leuComPath); TraceMethod.RecordInfo(logMsg); return(false); } } //read all LEU info from LEU_Result_Filtered_Values.xml try { LEU_filtered_values leurfxml = FileLoader.Load <LEU_filtered_values>(leuRF); LeuInfoList = leurfxml.LEU; } catch (System.Exception ex) { TraceMethod.RecordInfo($"Read LEU file [{leuRF}] error {ex.Message}, please check!"); return(false); } //read LEU template info for each LEU.xml from LEUXMLTemplateExample.xml try { leuXmlTemplate = FileLoader.Load <LEUXML.LEU>(leuTF); } catch (System.Exception ex) { TraceMethod.RecordInfo("Read LEU XML Template file error {0}, please check!", ex.Message); return(false); } List <string> gidList = new List <string>(); string gidRepeatLog = ""; try { StreamReader sr = new StreamReader(gidTable); string line = null; while ((line = sr.ReadLine()) != null && gidList.Count < LeuInfoList.Count * 3) { //the used GID table, should not be repeated if (gidList.Contains(line)) { gidRepeatLog += line + " "; continue; } if (line.Length == 16) { //add check of gid data } else if ("" == line) { continue; } else { TraceMethod.RecordInfo($"invalid [{line}] in {gidTable}"); return(false); } gidList.Add(line); } sr.Close(); } catch (System.Exception ex) { TraceMethod.RecordInfo($"Read GID file [{gidTable}] error {ex.Message}, please check!"); return(false); } //read all the GID data from \\Config\\GID-Table.txt //BMGR-0062 //伪随机数不够,则返回false if (gidList.Count < LeuInfoList.Count * 3) { if ("" != gidRepeatLog) { gidRepeatLog = "Repeated gid: " + gidRepeatLog + " "; } gidRepeatLog += $" The data in GID-Table.txt has {gidList.Count} unique records, should be {LeuInfoList.Count * 3}!"; TraceMethod.Record(TraceMethod.TraceKind.ERROR, gidRepeatLog); return(false); } for (int i = 0; i < LeuInfoList.Count; ++i) { GID gid = new GID(gidList[i * 3], gidList[(i * 3) + 1], gidList[(i * 3) + 2]); GidInfoList.Add(gid); } return(true); }