public static byte[] SerializeDroneInfo(DroneInfoPacket packet) { int rawsize = Marshal.SizeOf(packet); IntPtr buffer = Marshal.AllocHGlobal(rawsize); Marshal.StructureToPtr(packet, buffer, false); byte[] rawdata = new byte[rawsize]; Marshal.Copy(buffer, rawdata, 0, rawsize); Marshal.FreeHGlobal(buffer); return(rawdata); }
private void PacketHandle(DroneInfoPacket packet) { // Do something with drone info.. if (packet.flyingState == DroneFlyingState.ACK) { if (ackCheckEvent != null) { ackCheckEvent.Invoke(); } RemoveACKCheckEvent(); return; } if (packet.battery >= 0 && packet.battery <= 100) { BatteryChange(packet.battery); } if (packet.flyingState != DroneFlyingState.NONE) { FlyingStateChange(packet.flyingState); } }