forked from CPL/Simulator
cpp
This commit is contained in:
65
DroneClientCpp/DroneClient.h
Normal file
65
DroneClientCpp/DroneClient.h
Normal file
@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vcclr.h>
|
||||
|
||||
#using <System.dll>
|
||||
#using <mscorlib.dll>
|
||||
|
||||
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<Byte>^ GetBytes(Object^ data)
|
||||
{
|
||||
int size = Marshal::SizeOf(data);
|
||||
array<Byte>^ arr = gcnew array<Byte>(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<Byte>^ 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user