#pragma once #include #include #using #using using namespace System; using namespace System::Runtime::InteropServices; namespace DroneClient { public ref class Drone { public: value struct DataOut { float AccX, AccY, AccZ; float GyrX, GyrY, GyrZ; float PosX, PosY; float LaserRange; }; value struct DataIn { float MotorUL, MotorUR, MotorDL, MotorDR; }; static array^ GetBytes(Object^ data) { int size = Marshal::SizeOf(data); array^ arr = gcnew array(size); IntPtr ptr = IntPtr::Zero; try { ptr = Marshal::AllocHGlobal(size); Marshal::StructureToPtr(data, ptr, true); Marshal::Copy(ptr, arr, 0, size); } finally { Marshal::FreeHGlobal(ptr); } return arr; } static Object^ FromBytes(array^ arr, Type^ type) { int size = Marshal::SizeOf(type); IntPtr ptr = IntPtr::Zero; try { ptr = Marshal::AllocHGlobal(size); Marshal::Copy(arr, 0, ptr, size); return Marshal::PtrToStructure(ptr, type); } finally { Marshal::FreeHGlobal(ptr); } } }; }