private byte[] BuildPacket(double x, double y, double z, double vx, double vy, double vz, int time) { PACK_HEAD packHeader = new PACK_HEAD() { Station = 0x21, Type = 0x20 }; S_HEAD sHead = new S_HEAD() { Len = (ushort)(Marshal.SizeOf(typeof(S_HEAD)) + Marshal.SizeOf(typeof(S_OBJECT))), Time = time, }; S_OBJECT sObject = new S_OBJECT { X = x, Y = y, Z = z, VX = vx, VY = vy, VZ = vz }; int len = Marshal.SizeOf(typeof(PACK_HEAD)) + sHead.Len; byte[] buffer = new byte[len]; MemoryStream memoryStream = new MemoryStream(buffer); BinaryWriter binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write(StructToBytes(packHeader)); binaryWriter.Write(StructToBytes(sHead)); binaryWriter.Write(StructToBytes(sObject)); return(buffer); }
private byte[] BuildT0() { PACK_HEAD packHeader = new PACK_HEAD() { Station = 0x21, Type = 0x50 }; S_HEAD sHead = new S_HEAD() { Len = (ushort)(Marshal.SizeOf(typeof(S_HEAD))), Time = (int)DateTime.Now.TimeOfDay.TotalMilliseconds, }; int len = Marshal.SizeOf(typeof(PACK_HEAD)) + sHead.Len; byte[] buffer = new byte[len]; MemoryStream memoryStream = new MemoryStream(buffer); BinaryWriter binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write(StructToBytes(packHeader)); binaryWriter.Write(StructToBytes(sHead)); return(buffer); }