RealtimePkg.cs 3.1 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mushiny.Model
{
    /// <summary>
    /// 实时数据包:
    /// (登录完成后,从未检测到二维码到检测到二维码的时刻发一次, 正常情况下如果停在二维码上则每隔0.5秒发一次)
    /// </summary>
    internal class RealtimePkg:PkgData
    {

        public RealtimePkg() : base() 
        {
        }
        /// <summary>
        /// 位置
        /// </summary>
        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 < 49)
                    {
                        return false;
                    }
                    Location = new Location();
                    Location.AddrCode = Common.ConvertToUInt(Common.GetSubBytes(bytes, 12, 4));
                    Location.AddrShiftX = Common.ConvertToUshort(Common.GetSubBytes(bytes, 16, 2));
                    Location.AddrShiftY = Common.ConvertToUshort(Common.GetSubBytes(bytes, 18, 2));
                    Location.AddrShiftTheta = Common.ConvertToFloat(Common.GetSubBytes(bytes, 20, 4));

                    CurState = Common.GetSubBytes(bytes, 24, 1)[0];
                    StraightDirectionCoordinates = Common.ConvertToFloat(Common.GetSubBytes(bytes, 25, 4));
                    CurAngle = Common.ConvertToFloat(Common.GetSubBytes(bytes, 29, 4));
                    InertialNavigationAngle= Common.ConvertToFloat(Common.GetSubBytes(bytes, 33, 4));
                    EncoderAngle= Common.ConvertToFloat(Common.GetSubBytes(bytes, 37, 4));
                    CurHeight = Common.ConvertToShort(Common.GetSubBytes(bytes, 41, 2));
                    SensorStatusFlags = Common.GetSubBytes(bytes, 43, 4);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
    }
}