using ProjectBase.Data.Logs;
using SIASUN.Autopilot.Device.Message;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SIASUN.Autopilot.Device.Command
{
    /// <summary>
    /// 车辆状态3
    /// </summary>
    public class VehicleStatus3
    {
        /// <summary>
        /// 接收到车辆状态触发
        /// </summary>
        public event ReceiveMessageEventHandler ReceiveMessage;
        public void Subscribe()
        {
            EventManage.Instance.SubscribeEvent(车辆状态3.OperationCode, new EventProcessingHandler(ProcessPackage));
        }

        public void UnSubscribe()
        {
            EventManage.Instance.UnSubscribeEvent(车辆状态3.OperationCode, ProcessPackage);
        }

        private void ProcessPackage(PackageProcessingEventArgs e)
        {
            //接收到车辆状态3数据，转换常规数据后触发ReceiveMessage处理。
            try
            {
                //通知
                if (ReceiveMessage != null)
                {
                    var args = new ReceiveMessageEventArgs(e.PackageBytes[0] as 车辆状态3);
                    ReceiveMessage(args);
                }
            }
            catch (Exception ex)
            {
                LogHelper.log.Error("车辆状态3->ProcessPackage事件出现未知异常。", ex);
                //TODO，日志
                var args = new ReceiveMessageEventArgs(null);
                ReceiveMessage(args);
            }
        }
    }
}
