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

namespace PlcSiemens.Protocol.Control
{
    public class CopyRamToRomParamsRequest
    {
        public byte Fun { get; set; }     // pduControl 0x28
        public byte[] Uk7 { get; set; }   // unknown 7
        public ushort Len1 { get; set; }     // Length part 1 : 0x0002
        public ushort SFun { get; set; }      // 'EP' 0x4550
        public byte Len2 { get; set; }     // Length part 2 : 0x05
        public char[] Cmd { get; set; }    // ascii '_MODU' 5
        public ushort PacketLength = 0x12;

        public void Build()
        {
            Fun = (byte)PduFuncType.PduControl;
            Uk7 = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD };
            Len1 = 0x0002;
            SFun = 0x4550;
            Len2 = 0x05;
            Cmd = new[] { '_', 'M', 'O', 'D', 'U' };
        }

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