internal static byte[][] GetSnMessages(GXDLMSSNParameters p)
{
GXByteBuffer reply = new GXByteBuffer();
List<byte[]> messages = new List<byte[]>();
byte frame = 0x0;
if (p.command == Command.Aarq)
{
frame = 0x10;
}
else if (p.command == Command.None)
{
frame = p.settings.NextSend();
}
do
{
GetSNPdu(p, reply);
if (p.command != Command.Aarq && p.command != Command.Aare)
{
System.Diagnostics.Debug.Assert(!(p.settings.MaxPduSize < reply.Size));
}
//Command is not add to next PDUs.
while (reply.Position != reply.Size)
{
if (p.settings.InterfaceType == Enums.InterfaceType.WRAPPER)
{
messages.Add(GXDLMS.GetWrapperFrame(p.settings, reply));
}
else if (p.settings.InterfaceType == Enums.InterfaceType.HDLC)
{
messages.Add(GXDLMS.GetHdlcFrame(p.settings, frame, reply));
frame = 0;
}
else if (p.settings.InterfaceType == Enums.InterfaceType.PDU)
{
messages.Add(reply.Array());
frame = 0;
break;
}
else
{
throw new ArgumentOutOfRangeException("InterfaceType");
}
}
reply.Clear();
} while (p.data != null && p.data.Position != p.data.Size);
return messages.ToArray();
}