ActionDataRtnPkg.cs 1.8 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mushiny.Model
{
    /// <summary>
    /// 命令码回复数据包:当RCS发送命令码过来,并执行完相应的命令码后发一次
    /// AGV->RCS
    /// </summary>
    internal class ActionDataRtnPkg : PkgData
    {
        public ActionDataRtnPkg() : base()
        {
        }
        /// <summary>
        /// 命令码
        /// 数据位置:起始编号12,长度1
        /// </summary>
        public byte ActionCode { get; set; }
        /// <summary>
        /// 属性值
        /// int8
        /// 数据位置:起始编号13,长度1
        /// </summary>
        public byte PropVal { get; set; }
        /// <summary>
        /// 动作参数
        /// 数据位置:起始编号14
        /// </summary>
        public List<byte> ActionParams { get; set; }

        public override bool Parse(byte[] bytes)
        {
            bool result = false;
            try
            {
                if (base.Parse(bytes))
                {
                    if (bytes.Length < 17)
                    {
                        return false;
                    }
                    ActionCode = Common.GetSubBytes(bytes, 12, 1)[0];
                    PropVal = Common.GetSubBytes(bytes, 13, 1)[0];
                    ActionParams = new List<byte>();
                    for (int i = 14; i <= bytes.Length - 1 - 2; i++)
                    {
                        ActionParams.Add(bytes[i]);
                    }
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
    }
}