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

namespace PlcSiemens.Protocol.Control
{
    public class PlcStopParamsRequest
    {
        public byte Fun { get; set; }     // stop 0x29
        public byte[] Uk5 { get; set; } // unknown 5 bytes 0x00
        public byte Len2 { get; set; }   // Length part 2 : 0x09
        public char[] Cmd { get; set; }  // ascii 'P_PROGRAM' 0x09

        public ushort PacketLength
        { get { return 0x10; } }

        public void Build()
        {
            Fun = (byte)PduFuncType.PduStop;
            Uk5 = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00 };
            Len2 = 0x09;
            Cmd = new[] { 'P', '_', 'P', 'R', 'O', 'G', 'R', 'A', 'M' };
        }

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