using PlcSiemens.Core.Extension;
using PlcSiemens.O;
using PlcSiemens.Protocol.Common;

namespace PlcSiemens.Protocol.Control
{
    public class CompressParamsRequest
    {
        public byte Fun;     // pduControl 0x28
        public byte[] Uk7; // unknown 7
        public ushort Len1;   // Length part 1 : 0x00
        public byte Len2;   // Length part 2 : 0x05
        public char[] Cmd;  // ascii '_GARB'
        public ushort PacketLength = 0x10;

        public void Build()
        {
            Fun = (byte)PduFuncType.PduControl;
            Uk7 = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD };
            Len1 = 0x0000;
            Len2 = 0x05;
            Cmd = new[] { '_', 'G', 'A', 'R', 'B' };
        }

        public void GetByteBuffer(ByteBuffer buffer)
        {
            buffer.Push(Fun);
            buffer.Push(Uk7);
            buffer.Push(Len1);
            buffer.Push(Len2);
            Cmd.ForEach(t => buffer.Push((byte)t));
        }
    }
}
