/// <summary> /// Load XML commands from the file. /// </summary> /// <param name="fileName"></param> /// <returns></returns> public byte[][] PduToMessages(GXDLMSXmlPdu pdu) { List <byte[]> messages = new List <byte[]>(); if (pdu.Command == Command.Snrm) { messages.Add(pdu.Data); } else if (pdu.Command == Command.Ua) { messages.Add(pdu.Data); } else if (pdu.Command == Command.DisconnectRequest) { messages.Add(GXDLMS.GetHdlcFrame(Settings, (byte)Command.DisconnectRequest, new GXByteBuffer(pdu.Data))); } else { GXByteBuffer reply; if (Settings.InterfaceType == InterfaceType.WRAPPER) { if (Ciphering.Security != (byte)Security.None) { GXDLMSLNParameters p = new GXDLMSLNParameters(this, Settings, 0, pdu.Command, 0x0, null, null, 0xff, Command.None); reply = new GXByteBuffer(GXDLMS.Cipher0(p, pdu.Data)); } else { reply = new GXByteBuffer(pdu.Data); } } else { if (Ciphering.Security != (byte)Security.None) { GXDLMSLNParameters p = new GXDLMSLNParameters(this, Settings, 0, pdu.Command, 0x0, null, null, 0xff, Command.None); byte[] tmp = GXDLMS.Cipher0(p, pdu.Data); reply = new GXByteBuffer((UInt16)(3 + tmp.Length)); reply.Set(GXCommon.LLCSendBytes); reply.Set(tmp); } else { reply = new GXByteBuffer((UInt16)(3 + pdu.Data.Length)); reply.Set(GXCommon.LLCSendBytes); reply.Set(pdu.Data); } } byte frame = 0; while (reply.Position != reply.Size) { if (Settings.InterfaceType == Enums.InterfaceType.WRAPPER) { messages.Add(GXDLMS.GetWrapperFrame(Settings, pdu.Command, reply)); } else if (GXDLMS.UseHdlc(Settings.InterfaceType)) { if (pdu.Command == Command.Aarq) { frame = 0x10; } else if (pdu.Command == Command.Aare) { frame = 0x30; } else if (pdu.Command == Command.EventNotification) { frame = 0x13; } messages.Add(GXDLMS.GetHdlcFrame(Settings, frame, reply)); if (reply.Position != reply.Size) { frame = Settings.NextSend(false); } } else if (Settings.InterfaceType == Enums.InterfaceType.PDU) { messages.Add(reply.Array()); break; } else { throw new ArgumentOutOfRangeException("InterfaceType"); } } } return(messages.ToArray()); }