public override BaseMessage Decode(byte[] frameData, string ipEndPort) { if (frameData.Length < 10) { return null; } else { ShakeHandMsg shakeHandMsg = new ShakeHandMsg(); shakeHandMsg.IpAndPort = ipEndPort; shakeHandMsg.ProtocolVersion = frameData[0]; byte[] cyclebytes = new byte[4]; Array.Copy(frameData, 1, cyclebytes, 0, 4); int CycleNo = BitConverter.ToInt32(cyclebytes, 0); shakeHandMsg.CycleNo = CycleNo; shakeHandMsg.Type = frameData[5]; shakeHandMsg.SubType = frameData[6]; shakeHandMsg.ErrorStatus = frameData[7]; byte[] data = new byte[frameData.Length - 10]; Array.Copy(frameData, 10, data, 0, data.Length); shakeHandMsg.DataLen = System.Net.IPAddress.HostToNetworkOrder((short)data.Length); shakeHandMsg.Data = data; return shakeHandMsg; } }
public override BaseMessage Decode(byte[] frameData, string ipEndPort) { if (frameData.Length < 10) { return(null); } else { ShakeHandMsg shakeHandMsg = new ShakeHandMsg(); shakeHandMsg.IpAndPort = ipEndPort; shakeHandMsg.ProtocolVersion = frameData[0]; byte[] cyclebytes = new byte[4]; Array.Copy(frameData, 1, cyclebytes, 0, 4); int CycleNo = BitConverter.ToInt32(cyclebytes, 0); shakeHandMsg.CycleNo = CycleNo; shakeHandMsg.Type = frameData[5]; shakeHandMsg.SubType = frameData[6]; shakeHandMsg.ErrorStatus = frameData[7]; byte[] data = new byte[frameData.Length - 10]; Array.Copy(frameData, 10, data, 0, data.Length); shakeHandMsg.DataLen = System.Net.IPAddress.HostToNetworkOrder((short)data.Length); shakeHandMsg.Data = data; return(shakeHandMsg); } }
public override BaseMessage Request(byte subType, byte[] data, string IpAndPort) { ShakeHandMsg shakeHandMsg = new ShakeHandMsg(); shakeHandMsg.IpAndPort = IpAndPort; shakeHandMsg.ProtocolVersion = 0x01; shakeHandMsg.CycleNo = 0x01; shakeHandMsg.Type = 0x01; shakeHandMsg.SubType = 0x01; shakeHandMsg.ErrorStatus = 0x00; shakeHandMsg.DataLen = 1; shakeHandMsg.Encode(data); return shakeHandMsg; }