using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MECF.Framework.RT.Core.IoProviders.Siemens.IMessage
{
    /// 
    /// 西门子S7协议的消息解析规则
    /// 
    public class S7Message : INetMessage
    {
        /// 
        /// 西门子头字节的长度
        /// 
        public int ProtocolHeadBytesLength
        {
            get { return 4; }
        }
        /// 
        /// 头子节的数据
        /// 
        public byte[] HeadBytes { get; set; }
        /// 
        /// 内容字节的数据
        /// 
        public byte[] ContentBytes { get; set; }
        /// 
        /// 检查头子节是否合法的判断
        /// 
        /// 令牌
        /// 是否合法的
        public bool CheckHeadBytesLegal(byte[] token)
        {
            if (HeadBytes == null) return false;
            if (HeadBytes[0] == 0x03 && HeadBytes[1] == 0x00)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// 
        /// 获取剩余的内容长度
        /// 
        /// 数据内容长度
        public int GetContentLengthByHeadBytes()
        {
            if (HeadBytes?.Length >= 4)
            {
                return HeadBytes[2] * 256 + HeadBytes[3] - 4;
            }
            else
            {
                return 0;
            }
        }
        /// 
        /// 获取消息号,此处无效
        /// 
        /// 消息标识
        public int GetHeadBytesIdentity()
        {
            return 0;
        }
        /// 
        /// 发送的字节信息
        /// 
        public byte[] SendBytes { get; set; }
    }
}