// Take Raw BACNet Packets and translate into XML packets private void TranslatePacketsToXMLBodies() { BVLL_IP bvll = new BVLL_IP(); System.Console.Write("Packet to XML"); string line; System.IO.StreamReader file = new System.IO.StreamReader("DataFiles\\BACPackets.txt"); while ((line = file.ReadLine()) != null) { Console.WriteLine(line); System.Diagnostics.Debug.WriteLine(line); try { bvll.Decode(new BACPacket(StringToByteAry(line))); System.Console.WriteLine(bvll.ToString()); } catch (Exception e) { System.Console.WriteLine("{0} Exception caught.", e); } } file.Close(); }
// Translate BACNet XML Data into raw BACNet Packets void TranslateToBACNetPacket() { System.Console.Write("XML to Packet"); XDocument xdo = XDocument.Load("DataFiles\\BACXMLFile.xml"); var fields = xdo.Root.Element("BVLL_IP").Element("Function").Value; XElement xBVLL_IP = xdo.Root.Element("BVLL_IP"); XElement xNetworkCtl = xdo.Root.Element("BVLL_IP").Element("NetworkCtl"); XElement xPDUUnConfirmedService = xdo.Root.Element("BVLL_IP").Element("PDUUnConfirmedService"); BVLL_IP bip = new BVLL_IP(); bip.Encode(xBVLL_IP); System.Console.WriteLine(xdo.ToString()); String packetFromXML = BitConverter.ToString(bip.packet.ToArray()).Replace("-", ""); byte[] packAsBytes = bip.packet.ToArray(); System.Console.WriteLine(packetFromXML); if (!packetFromXML.Contains("810A00120120204A064A2065000000FF100800")) { System.Console.WriteLine("Failed to correctly decode the XML"); throw new System.ArgumentException("Failed to correctly decode the XML"); } bip.Decode(new BACPacket(packAsBytes)); System.Console.WriteLine(bip.ToString()); }