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

namespace PlcSiemens.Protocol.Control
{
    public class PlcColdStartParamsRequest
    {
        public byte Fun;     // start 0x28
        public byte[] Uk7; // unknown 7
        public ushort Len1;   // Length part 1 : 0x0002
        public ushort SFun;    // 'C ' 0x4320
        public byte Len2;   // Length part 2 : 0x09
        public char[] Cmd;  // ascii 'P_PROGRAM'
        public ushort PacketLength = 0x16;

        public void Build()
        {
            Fun = (byte)PduFuncType.PduStart;
            Uk7 = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD };
            Len1 = 0x0002;
            SFun = 0x4320;
            Len2 = 0x09;
            Cmd = new[] { 'P', '_', 'P', 'R', 'O', 'G', 'R', 'A', 'M' };
        }

        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));
        }
    }
}
