using ProjectBase.Data.Logs;
using SIASUN.Autopilot.Device.Message;
using System;

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

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

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