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 InfoAgv : BaseInfo, IDeviceCommandCallback
    {
        private bool lastDataValid;
        private int lastMark;
        private int lastRoute;
        private int lastStatus;
        private int lastAlarm;

        public int AgvId { get; set; }
        public int Mark { get; set; }
        public int Route { get; set; }
        public bool InStation { get { return DataValid && (Status == (int)EnumInfoAgvStatus.停止点 || Status == (int)EnumInfoAgvStatus.结束点); } }
        public EnumInfoAgvStatus StatusEnum { get { return (EnumInfoAgvStatus)Status; } }
        public int Status { get; set; }
        public string StatusText { get; set; }
        public int Alarm { get; set; }
        public string AlarmText { get; set; }
        public decimal BatteyPower { get; set; }
        public decimal BatteyVoltage { get; set; }
        public decimal BatteyCurrent { get; set; }
        public decimal BatteyTemperature { get; set; }
        public int SpeedLevel { get; set; }
        internal int FPS { get; set; }

        internal bool IsChanged
        {
            get { return DataValid != lastDataValid || Mark != lastMark || Route != lastRoute || Status != lastStatus || Alarm != lastAlarm; }
        }

        public InfoAgv()
        {
            TimeoutSecond = 60;
        }

        public virtual void Deserialize(byte[] data)
        {
            lastDataValid = DataValid;
            lastMark = Mark;
            lastRoute = Route;
            lastStatus = Status;
            lastAlarm = Alarm;
        }
    }

    public enum EnumInfoAgvStatus
    {
        None = 0x00,
        //急停 = 0x01,
        //防撞机构报警 = 0x02,
        //牵引棒 = 0x03,
        //障碍物 = 0x04,
        //驱动报警 = 0x05,
        //后驱动异常 = 0x06,
        //脱轨 = 0x07,
        //低电压报警 = 0x08,
        //低电压停机 = 0x09,
        //超载 = 0x0A,
        //驱动提升 = 0x0B,
        //后牵引 = 0x0C,
        //未知 = 0x0D,
        //启动 = 0x0E,
        //复位 = 0x0F,
        //方向切换 = 0x10,
        运行 = 0x40,
        暂停 = 0x43,
        停止点 = 0x41,
        结束点 = 0x42,
        充电中 = 0x44
    }
}
