using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MECF.Framework.RT.Core.IoProviders.Common.IMessage;
namespace MECF.Framework.RT.Core.IoProviders.Melsec
{
    
    /// 
    /// 三菱的Qna兼容3E帧协议解析规则
    /// 
    public class MelsecQnA3EBinaryMessage : INetMessage
    {
        /// 
        /// 消息头的指令长度
        /// 
        public int ProtocolHeadBytesLength
        {
            get
            {
                return 9;
            }
        }
        /// 
        /// 从当前的头子节文件中提取出接下来需要接收的数据长度
        /// 
        /// 返回接下来的数据内容长度
        public int GetContentLengthByHeadBytes()
        {
            return BitConverter.ToUInt16( HeadBytes, 7 );
        }
        /// 
        /// 检查头子节的合法性
        /// 
        /// 特殊的令牌,有些特殊消息的验证
        /// 是否成功的结果
        public bool CheckHeadBytesLegal( byte[] token )
        {
            if (HeadBytes == null) return false;
            if (HeadBytes[0] == 0xD0 && HeadBytes[1] == 0x00)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// 
        /// 获取头子节里的消息标识
        /// 
        /// 消息标识
        public int GetHeadBytesIdentity()
        {
            return 0;
        }
        /// 
        /// 消息头字节
        /// 
        public byte[] HeadBytes { get; set; }
        /// 
        /// 消息内容字节
        /// 
        public byte[] ContentBytes { get; set; }
        /// 
        /// 发送的字节信息
        /// 
        public byte[] SendBytes { get; set; }
    }
}