HeartBeatPkg.cs 2.5 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mushiny.Model
{
    /// <summary>
    /// AGV->RCS
    /// </summary>
    internal class HeartBeatPkg:PkgData
    {
        public HeartBeatPkg() : base() 
        {
        }
        public Location Location { get; set; }
        public  byte CurState { get; set; }

        /// <summary>
        /// 直行方向坐标
        /// 单位:mm
        /// </summary>
        public float StraightDirectionCoordinates { get; set; }
        /// <summary>
        /// 当前角度
        /// 单位:°
        /// </summary>
        public float CurAngle { get; set; }
        /// <summary>
        /// 惯导角度
        /// 单位:°
        /// </summary>
        public float InertialNavigationAngle { get; set; }
        /// <summary>
        /// 编码器角度
        /// 单位:°
        /// </summary>
        public float EncoderAngle { get; set; }
        /// <summary>
        /// 当前高度
        /// </summary>
        public short CurHeight { get; set; }
        /// <summary>
        /// 传感器状态标志
        /// </summary>
        public byte[] SensorStatusFlags { get; set; }

        public override bool Parse(byte[] bytes)
        {
            bool result = false;
            try
            {
                if (base.Parse(bytes))
                {
                    if (bytes.Length < 41)
                    {
                        return false;
                    }
                    Location = new Location();
                    Location.AddrCode = Common.ConvertToUInt(Common.GetSubBytes(bytes, 12, 4));

                    CurState = Common.GetSubBytes(bytes, 16, 1)[0];
                    StraightDirectionCoordinates = Common.ConvertToFloat(Common.GetSubBytes(bytes, 17, 4));
                    CurAngle = Common.ConvertToFloat(Common.GetSubBytes(bytes, 21, 4));
                    InertialNavigationAngle = Common.ConvertToFloat(Common.GetSubBytes(bytes, 25, 4));
                    EncoderAngle = Common.ConvertToFloat(Common.GetSubBytes(bytes, 29, 4));
                    CurHeight = Common.ConvertToShort(Common.GetSubBytes(bytes, 33, 2));
                    SensorStatusFlags = Common.GetSubBytes(bytes, 35, 4);
                    result = true;
                }
                else
                {
                    result = false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
    }
}