using PlcSiemens.O;
using PlcSiemens.Protocol.Common;
using PlcSiemens.Protocol.Header;

namespace PlcSiemens.Protocol.ListBlocks
{
    public class ListBlocksRequest : IBuildRequest
    {
        public HeaderPacket Header { get; set; }
        public ParamsRequest Params { get; set; }
        public byte[] Data { get; set; }//4

        public ListBlocksRequest()
        {
            Header = new HeaderPacket();
            Params = new ParamsRequest();
        }

        public void Build()
        {
            Header.Build(PduType.Userdata, Params.PacketLength, 4);
            Params.Build(true, 0x00, GrType.GrBlocksInfo, PduFuncType.SFunListAll);
            Data = new byte[] { 0x0A, 0x00, 0x00, 0x00 };
        }

        public ByteBuffer GetBuffer()
        {
            ByteBuffer buffer = ByteBuffer.Allocate();
            Header.GetByteBuffer(buffer);
            Params.GetByteBuffer(buffer);
            buffer.Push(Data);
            return buffer;
        }
    }
}
