using ProjectManagementSystem.Device.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectManagementSystem.Device.CommandCallback
{
    public class InfoIO : BaseInfo, IDeviceCommandCallback
    {
        public InfoIO()
        {
            TimeoutSecond = 3;
        }

        public int DeviceId { get; set; }
        public byte Output { get; set; }
        public byte Input { get; set; }

        public bool Y1 { get { return (Output & 0x01) > 0; } }
        public bool Y2 { get { return (Output & 0x02) > 0; } }
        public bool Y3 { get { return (Output & 0x04) > 0; } }
        public bool Y4 { get { return (Output & 0x08) > 0; } }
        public bool Y5 { get { return (Output & 0x10) > 0; } }
        public bool Y6 { get { return (Output & 0x20) > 0; } }
        public bool Y7 { get { return (Output & 0x40) > 0; } }
        public bool Y8 { get { return (Output & 0x80) > 0; } }

        public bool X1 { get { return (Input & 0x01) > 0; } }
        public bool X2 { get { return (Input & 0x02) > 0; } }
        public bool X3 { get { return (Input & 0x04) > 0; } }
        public bool X4 { get { return (Input & 0x08) > 0; } }
        public bool X5 { get { return (Input & 0x10) > 0; } }
        public bool X6 { get { return (Input & 0x20) > 0; } }
        public bool X7 { get { return (Input & 0x40) > 0; } }
        public bool X8 { get { return (Input & 0x80) > 0; } }

        public void Deserialize(byte[] data)
        {
            DeviceId = data[2];
            Output = data[4];
            Input = data[6];

            LastUpdateTime = DateTime.Now;
        }
    }
}
