package com.zy.common.HslCommunication.Core.IMessage; public class S7Message implements INetMessage { // 头字节 private byte[] HeadBytes = null; // 消息内容字节 private byte[] ContentBytes = null; // 发送的消息 private byte[] SendBytes = null; /** * 消息头的指令长度 */ public int ProtocolHeadBytesLength(){ return 4; } /** * 从当前的头子节文件中提取出接下来需要接收的数据长度 * @return 返回接下来的数据内容长度 */ public int GetContentLengthByHeadBytes(){ if(HeadBytes == null) return 0; return (HeadBytes[2] & 0xff) * 256 + (HeadBytes[3] & 0xff) - 4; } /** * 检查头子节的合法性 * @param token 特殊的令牌,有些特殊消息的验证 * @return 是否合法的验证 */ public boolean CheckHeadBytesLegal(byte[] token) { if(HeadBytes == null) return false; return HeadBytes[0] == 0x03 && HeadBytes[1] == 0x00; } /** * 获取头子节里的消息标识 */ public int GetHeadBytesIdentity(){ return 0; } @Override public byte[] getHeadBytes() { return HeadBytes; } @Override public byte[] getContentBytes() { return ContentBytes; } @Override public byte[] getSendBytes() { return SendBytes; } public void setHeadBytes(byte[] headBytes){ HeadBytes = headBytes; } public void setContentBytes(byte[] contentBytes){ ContentBytes = contentBytes; } public void setSendBytes(byte[] sendBytes){ SendBytes = sendBytes; } }