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

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

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

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