Gurux.DLMS.GXDLMS.AppendMultipleSNBlocks C# (CSharp) Méthode

AppendMultipleSNBlocks() static private méthode

static private AppendMultipleSNBlocks ( GXDLMSSNParameters p, GXByteBuffer header, GXByteBuffer reply ) : int
p GXDLMSSNParameters
header GXByteBuffer
reply GXByteBuffer
Résultat int
        static int AppendMultipleSNBlocks(GXDLMSSNParameters p, GXByteBuffer header, GXByteBuffer reply)
        {
            bool ciphering = p.settings.Cipher != null && p.settings.Cipher.Security != Gurux.DLMS.Enums.Security.None;
            int hSize = reply.Size + 3;
            if (header != null)
            {
                hSize += header.Size;
            }
            //Add LLC bytes.
            if (p.command == Command.WriteRequest ||
                    p.command == Command.ReadRequest)
            {
                hSize += 1 + GXCommon.GetObjectCountSizeInBytes(p.count);
            }
            int maxSize = p.settings.MaxPduSize - hSize;
            if (ciphering)
            {
                maxSize -= CipheringHeaderSize;
                if (p.settings.InterfaceType == InterfaceType.HDLC)
                {
                    maxSize -= 3;
                }
            }
            maxSize -= GXCommon.GetObjectCountSizeInBytes(maxSize);
            if (p.data.Size - p.data.Position > maxSize)
            {
                //More blocks.
                reply.SetUInt8(0);
            }
            else
            {
                //Last block.
                reply.SetUInt8(1);
                maxSize = p.data.Size - p.data.Position;
            }
            //Add block index.
            reply.SetUInt16(p.blockIndex);
            if (p.command == Command.WriteRequest)
            {
                ++p.blockIndex;
                GXCommon.SetObjectCount(p.count, reply);
                reply.SetUInt8(DataType.OctetString);
            }
            if (p.command == Command.ReadRequest)
            {
                ++p.blockIndex;
            }
            if (header != null)
            {
                GXCommon.SetObjectCount(maxSize + header.Size, reply);
                reply.Set(header);
            }
            else
            {
                GXCommon.SetObjectCount(maxSize, reply);
            }
            return maxSize;
        }