forked from CPL/Simulator
cpp
This commit is contained in:
parent
6aeb99968e
commit
64c0637e6a
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.vs/
|
.vs/
|
||||||
obj/
|
obj/
|
||||||
bin/
|
bin/
|
||||||
|
x64/
|
106
DroneClientCpp/Client.cpp
Normal file
106
DroneClientCpp/Client.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Client.h"
|
||||||
|
|
||||||
|
Client::Client(const char* ip, int port) : running(true), Connection(INVALID_SOCKET)
|
||||||
|
{
|
||||||
|
if (!ConnectToServer(ip, port))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to connect to server!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Client::~Client()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
CloseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Client::ConnectToServer(const char* ip, int port)
|
||||||
|
{
|
||||||
|
WSAData wsaData;
|
||||||
|
WORD DLLVersion = MAKEWORD(2, 2);
|
||||||
|
|
||||||
|
if (WSAStartup(DLLVersion, &wsaData) != 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: WSAStartup failed" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOCKADDR_IN addr;
|
||||||
|
inet_pton(AF_INET, ip, &addr.sin_addr);
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
|
||||||
|
Connection = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (Connection == INVALID_SOCKET)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Failed to create socket" << std::endl;
|
||||||
|
WSACleanup();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connect(Connection, (SOCKADDR*)&addr, sizeof(addr)) != 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Failed to connect to server" << std::endl;
|
||||||
|
closesocket(Connection);
|
||||||
|
WSACleanup();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::CloseConnection()
|
||||||
|
{
|
||||||
|
if (Connection != INVALID_SOCKET)
|
||||||
|
{
|
||||||
|
closesocket(Connection);
|
||||||
|
WSACleanup();
|
||||||
|
Connection = INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::ReceiveHandler()
|
||||||
|
{
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
DataIn tempData;
|
||||||
|
int result = recv(Connection, (char*)&tempData, sizeof(tempData), 0);
|
||||||
|
|
||||||
|
if (result <= 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Connection lost (recv failed)" << std::endl;
|
||||||
|
running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(dataMutex);
|
||||||
|
dataIn = tempData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::SendHandler()
|
||||||
|
{
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(dataMutex);
|
||||||
|
send(Connection, (char*)&dataOut, sizeof(dataOut), 0);
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::Start()
|
||||||
|
{
|
||||||
|
recvThread = std::thread(&Client::ReceiveHandler, this);
|
||||||
|
sendThread = std::thread(&Client::SendHandler, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::Stop()
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
if (recvThread.joinable()) recvThread.join();
|
||||||
|
if (sendThread.joinable()) sendThread.join();
|
||||||
|
}
|
44
DroneClientCpp/Client.h
Normal file
44
DroneClientCpp/Client.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <WinSock2.h>
|
||||||
|
#include <WS2tcpip.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#pragma comment(lib, "Ws2_32.lib")
|
||||||
|
|
||||||
|
class Client
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Client(const char* ip, int port);
|
||||||
|
~Client();
|
||||||
|
|
||||||
|
void Start(); // Запуск потоков
|
||||||
|
void Stop(); // Остановка потоков
|
||||||
|
struct DataIn
|
||||||
|
{
|
||||||
|
float AccX, AccY, AccZ;
|
||||||
|
float GyrX, GyrY, GyrZ;
|
||||||
|
float PosX, PosY, LaserRange;
|
||||||
|
} dataIn;
|
||||||
|
|
||||||
|
struct DataOut
|
||||||
|
{
|
||||||
|
float MotorUL, MotorUR, MotorDL, MotorDR;
|
||||||
|
} dataOut;
|
||||||
|
bool ConnectToServer(const char* ip, int port);
|
||||||
|
void CloseConnection();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::atomic<bool> running;
|
||||||
|
std::mutex dataMutex;
|
||||||
|
|
||||||
|
SOCKET Connection;
|
||||||
|
std::thread recvThread;
|
||||||
|
std::thread sendThread;
|
||||||
|
|
||||||
|
void ReceiveHandler();
|
||||||
|
void SendHandler();
|
||||||
|
};
|
197
DroneClientCpp/Drone.cpp
Normal file
197
DroneClientCpp/Drone.cpp
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
#include "Drone.h"
|
||||||
|
|
||||||
|
namespace DroneClient {
|
||||||
|
|
||||||
|
// Реализация статического метода GetBytes
|
||||||
|
array<Byte>^ Drone::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация статического метода FromBytes
|
||||||
|
Object^ Drone::FromBytes(array<Byte>^ arr, Type^ type)
|
||||||
|
{
|
||||||
|
Object^ mem = gcnew Object();
|
||||||
|
|
||||||
|
int size = Marshal::SizeOf(type);
|
||||||
|
IntPtr ptr = IntPtr::Zero;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ptr = Marshal::AllocHGlobal(size);
|
||||||
|
Marshal::Copy(arr, 0, ptr, size);
|
||||||
|
mem = Marshal::PtrToStructure(ptr, type);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Marshal::FreeHGlobal(ptr);
|
||||||
|
}
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация приватного метода SendDataMotor4
|
||||||
|
array<Byte>^ Drone::SendDataMotor4()
|
||||||
|
{
|
||||||
|
DroneData::DataMotor4 mot4;
|
||||||
|
|
||||||
|
mot4.Head.Size = Marshal::SizeOf(DroneData::DataMotor4::typeid);
|
||||||
|
mot4.Head.Mode = DroneData::DataMode::Response;
|
||||||
|
mot4.Head.Type = DroneData::DataType::DataMotor4;
|
||||||
|
|
||||||
|
mot4.UL = MotorUL;
|
||||||
|
mot4.UR = MotorUR;
|
||||||
|
mot4.DL = MotorDL;
|
||||||
|
mot4.DR = MotorDR;
|
||||||
|
|
||||||
|
return GetBytes(mot4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация приватного метода RecvDataIMU
|
||||||
|
array<Byte>^ Drone::RecvDataIMU(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
DroneData::DataIMU imu = (DroneData::DataIMU)FromBytes(data, DroneData::DataIMU::typeid);
|
||||||
|
|
||||||
|
AccX = imu.Acc.X; AccY = imu.Acc.Y; AccZ = imu.Acc.Z;
|
||||||
|
GyrX = imu.Gyr.X; GyrY = imu.Gyr.Y; GyrZ = imu.Gyr.Z;
|
||||||
|
|
||||||
|
return gcnew array<Byte>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация приватного метода RecvDataPos
|
||||||
|
array<Byte>^ Drone::RecvDataPos(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
DroneData::DataPos pos = (DroneData::DataPos)FromBytes(data, DroneData::DataPos::typeid);
|
||||||
|
|
||||||
|
PosX = pos.Local.X; PosY = pos.Local.Y;
|
||||||
|
LaserRange = pos.LiDAR;
|
||||||
|
|
||||||
|
return gcnew array<Byte>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация приватного метода ClientRequestResponse
|
||||||
|
array<Byte>^ Drone::ClientRequestResponse(DroneData::DataHead head, array<Byte>^ body)
|
||||||
|
{
|
||||||
|
array<Byte>^ zero = gcnew array<Byte>(0);
|
||||||
|
|
||||||
|
switch (head.Type)
|
||||||
|
{
|
||||||
|
case DroneData::DataType::DataIMU:
|
||||||
|
if (head.Mode == DroneData::DataMode::Request)
|
||||||
|
{
|
||||||
|
return zero; // Запрос данных (не реализовано)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecvDataIMU(body); // Пришли данные
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData::DataType::DataPos:
|
||||||
|
if (head.Mode == DroneData::DataMode::Request)
|
||||||
|
{
|
||||||
|
return zero; // Запрос данных (не реализовано)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecvDataPos(body); // Пришли данные
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData::DataType::DataMotor4:
|
||||||
|
if (head.Mode == DroneData::DataMode::Request)
|
||||||
|
{
|
||||||
|
return SendDataMotor4(); // Запрос данных
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return zero; // Пришли данные (не реализовано)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация конструктора
|
||||||
|
Drone::Drone()
|
||||||
|
{
|
||||||
|
DroneStreamData = gcnew array<Byte>(DroneStreamCount); // Инициализация массива
|
||||||
|
DroneStreamIndex = 0;
|
||||||
|
DroneStreamHead.Mode = DroneData::DataMode::None;
|
||||||
|
DroneStreamHead.Size = 0;
|
||||||
|
DroneStreamHead.Type = DroneData::DataType::None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода DataStream
|
||||||
|
System::Collections::Generic::List<array<Byte>^>^ Drone::DataStream(array<Byte>^ data, int size)
|
||||||
|
{
|
||||||
|
System::Collections::Generic::List<array<Byte>^>^ ret = gcnew System::Collections::Generic::List<array<Byte>^>();
|
||||||
|
|
||||||
|
if (data == nullptr) return ret; // Последовательность не сформирована
|
||||||
|
|
||||||
|
if (size + DroneStreamIndex > DroneStreamCount) return nullptr; // Ошибка переполнения
|
||||||
|
|
||||||
|
Array::Copy(data, 0, DroneStreamData, DroneStreamIndex, size);
|
||||||
|
DroneStreamIndex += size;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (DroneStreamHead.Size == 0) // Заголовок еще не получен
|
||||||
|
{
|
||||||
|
if (DroneStreamIndex < DroneData::DataHead::StrLen) return ret;
|
||||||
|
DroneStreamHead = (DroneData::DataHead)FromBytes(DroneStreamData, DroneData::DataHead::typeid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DroneStreamHead.Size > DroneStreamIndex) break; // Пакет еще не полный
|
||||||
|
|
||||||
|
array<Byte>^ body = gcnew array<Byte>(DroneStreamHead.Size);
|
||||||
|
Array::Copy(DroneStreamData, 0, body, 0, DroneStreamHead.Size);
|
||||||
|
|
||||||
|
int shift = DroneStreamHead.Size;
|
||||||
|
|
||||||
|
DroneStreamIndex -= shift;
|
||||||
|
Array::Copy(DroneStreamData, shift, DroneStreamData, 0, DroneStreamIndex); // Сдвиг массива
|
||||||
|
|
||||||
|
DroneStreamHead.Size = 0; // Сброс заголовка
|
||||||
|
|
||||||
|
ret->Add(ClientRequestResponse(DroneStreamHead, body));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода SendRequest
|
||||||
|
array<Byte>^ Drone::SendRequest()
|
||||||
|
{
|
||||||
|
DroneData::DataHead imu;
|
||||||
|
imu.Size = DroneData::DataHead::StrLen;
|
||||||
|
imu.Mode = DroneData::DataMode::Request;
|
||||||
|
imu.Type = DroneData::DataType::DataIMU;
|
||||||
|
|
||||||
|
DroneData::DataHead pos;
|
||||||
|
pos.Size = DroneData::DataHead::StrLen;
|
||||||
|
pos.Mode = DroneData::DataMode::Request;
|
||||||
|
pos.Type = DroneData::DataType::DataPos;
|
||||||
|
|
||||||
|
array<Byte>^ si = GetBytes(imu);
|
||||||
|
array<Byte>^ sp = GetBytes(pos);
|
||||||
|
array<Byte>^ sm = SendDataMotor4();
|
||||||
|
|
||||||
|
array<Byte>^ send = gcnew array<Byte>(si->Length + sp->Length + sm->Length);
|
||||||
|
Array::Copy(si, 0, send, 0, si->Length);
|
||||||
|
Array::Copy(sp, 0, send, si->Length, sp->Length);
|
||||||
|
Array::Copy(sm, 0, send, si->Length + sp->Length, sm->Length);
|
||||||
|
|
||||||
|
return send;
|
||||||
|
}
|
||||||
|
}
|
46
DroneClientCpp/Drone.h
Normal file
46
DroneClientCpp/Drone.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "DroneData.h"
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <vcclr.h>
|
||||||
|
|
||||||
|
#using <System.dll>
|
||||||
|
#using <mscorlib.dll>
|
||||||
|
|
||||||
|
using namespace System;
|
||||||
|
using namespace System::Collections::Generic;
|
||||||
|
using namespace System::Runtime::InteropServices;
|
||||||
|
|
||||||
|
namespace DroneClient {
|
||||||
|
|
||||||
|
public ref class Drone
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float AccX, AccY, AccZ;
|
||||||
|
float GyrX, GyrY, GyrZ;
|
||||||
|
float PosX, PosY;
|
||||||
|
float LaserRange;
|
||||||
|
|
||||||
|
float MotorUL, MotorUR, MotorDL, MotorDR;
|
||||||
|
|
||||||
|
static array<Byte>^ GetBytes(Object^ data);
|
||||||
|
static Object^ FromBytes(array<Byte>^ arr, Type^ type);
|
||||||
|
|
||||||
|
private:
|
||||||
|
array<Byte>^ SendDataMotor4();
|
||||||
|
array<Byte>^ RecvDataIMU(array<Byte>^ data);
|
||||||
|
array<Byte>^ RecvDataPos(array<Byte>^ data);
|
||||||
|
array<Byte>^ ClientRequestResponse(DroneData::DataHead head, array<Byte>^ body);
|
||||||
|
|
||||||
|
literal int DroneStreamCount = 512;
|
||||||
|
array<Byte>^ DroneStreamData;
|
||||||
|
int DroneStreamIndex;
|
||||||
|
DroneData::DataHead DroneStreamHead;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Drone(); // Конструктор для инициализации
|
||||||
|
|
||||||
|
System::Collections::Generic::List<array<Byte>^>^ DataStream(array<Byte>^ data, int size);
|
||||||
|
array<Byte>^ SendRequest();
|
||||||
|
};
|
||||||
|
}
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
28
DroneClientCpp/DroneClientCpp.sln
Normal file
28
DroneClientCpp/DroneClientCpp.sln
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.12.35527.113
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DroneClientCpp", "DroneClientCpp.vcxproj", "{690C304C-A70B-4B0F-BF61-8C51290BF444}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x64.Build.0 = Release|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
141
DroneClientCpp/DroneClientCpp.vcxproj
Normal file
141
DroneClientCpp/DroneClientCpp.vcxproj
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{690C304C-A70B-4B0F-BF61-8C51290BF444}</ProjectGuid>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<Keyword>ManagedCProj</Keyword>
|
||||||
|
<RootNamespace>DroneClientCpp</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Drone.cpp" />
|
||||||
|
<ClCompile Include="FormMain.cpp" />
|
||||||
|
<ClCompile Include="NetClient.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Drone.h" />
|
||||||
|
<ClInclude Include="DroneData.h" />
|
||||||
|
<ClInclude Include="FormMain.h">
|
||||||
|
<FileType>CppForm</FileType>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="NetClient.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="FormMain.resx">
|
||||||
|
<DependentUpon>FormMain.h</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
42
DroneClientCpp/DroneClientCpp.vcxproj.filters
Normal file
42
DroneClientCpp/DroneClientCpp.vcxproj.filters
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Исходные файлы">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы заголовков">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы ресурсов">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="FormMain.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="NetClient.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Drone.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="FormMain.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="NetClient.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="DroneData.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Drone.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
4
DroneClientCpp/DroneClientCpp.vcxproj.user
Normal file
4
DroneClientCpp/DroneClientCpp.vcxproj.user
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
</Project>
|
77
DroneClientCpp/DroneData.h
Normal file
77
DroneClientCpp/DroneData.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <vcclr.h>
|
||||||
|
|
||||||
|
using namespace System;
|
||||||
|
using namespace System::Runtime::InteropServices;
|
||||||
|
|
||||||
|
namespace DroneData {
|
||||||
|
|
||||||
|
public enum class DataMode : unsigned short
|
||||||
|
{
|
||||||
|
None = 0, Response = 1, Request = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum class DataType : unsigned short
|
||||||
|
{
|
||||||
|
None = 0, Head = 1,
|
||||||
|
DataIMU = 1001, DataPos = 1002,
|
||||||
|
DataMotor4 = 2001, DataMotor6 = 2002
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataHead
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int Size;
|
||||||
|
DataMode Mode;
|
||||||
|
DataType Type;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataHead);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct XYZ
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float X, Y, Z;
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataIMU
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
XYZ Acc, Gyr, Mag;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataIMU);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataPos
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
XYZ Local;
|
||||||
|
float LiDAR;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataPos);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataMotor4
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
unsigned long long Count;
|
||||||
|
float UL, UR, DL, DR;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataMotor4);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataMotor6
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
unsigned long long Count;
|
||||||
|
float UL, UR, LL, RR, DL, DR;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataMotor6);
|
||||||
|
};
|
||||||
|
}
|
12
DroneClientCpp/FormMain.cpp
Normal file
12
DroneClientCpp/FormMain.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "FormMain.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
using namespace DroneClientCpp;
|
||||||
|
|
||||||
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
|
||||||
|
Application::EnableVisualStyles();
|
||||||
|
Application::SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application::Run(gcnew FormMain);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
DroneClientCpp/FormMain.h
Normal file
BIN
DroneClientCpp/FormMain.h
Normal file
Binary file not shown.
126
DroneClientCpp/FormMain.resx
Normal file
126
DroneClientCpp/FormMain.resx
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>310, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
12
DroneClientCpp/MyForm.cpp
Normal file
12
DroneClientCpp/MyForm.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "MyForm.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
using namespace DroneClientCpp;
|
||||||
|
|
||||||
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
|
||||||
|
Application::EnableVisualStyles();
|
||||||
|
Application::SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application::Run(gcnew MyForm);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
DroneClientCpp/MyForm.h
Normal file
BIN
DroneClientCpp/MyForm.h
Normal file
Binary file not shown.
120
DroneClientCpp/MyForm.resx
Normal file
120
DroneClientCpp/MyForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
105
DroneClientCpp/NetClient.cpp
Normal file
105
DroneClientCpp/NetClient.cpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#include "NetClient.h"
|
||||||
|
|
||||||
|
namespace DroneSimulator {
|
||||||
|
|
||||||
|
// Конструктор ConnectData
|
||||||
|
NetClient::ConnectData::ConnectData(bool connect, Socket^ server)
|
||||||
|
{
|
||||||
|
Connect = connect;
|
||||||
|
Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конструктор ReceiveData
|
||||||
|
NetClient::ReceiveData::ReceiveData(array<Byte>^ buffer, int size, Socket^ server)
|
||||||
|
{
|
||||||
|
Buffer = buffer;
|
||||||
|
Size = size;
|
||||||
|
Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конструктор NetClient
|
||||||
|
NetClient::NetClient()
|
||||||
|
{
|
||||||
|
Connected = false;
|
||||||
|
ServerSocket = nullptr;
|
||||||
|
DataServer = gcnew ServerData(); // Инициализация DataServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода Connect
|
||||||
|
NetClient::ClientState NetClient::Connect(String^ Addr, int Port, ClientCallback^ Connection, ClientCallback^ Receive)
|
||||||
|
{
|
||||||
|
if (Connected)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
return ClientState::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionCallback = Connection;
|
||||||
|
ReceiveCallback = Receive;
|
||||||
|
|
||||||
|
IPEndPoint^ ep = gcnew IPEndPoint(IPAddress::Parse(Addr), Port);
|
||||||
|
ServerSocket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);
|
||||||
|
|
||||||
|
try { ServerSocket->Connect(ep); }
|
||||||
|
catch (...) { ServerSocket->Close(); return ClientState::Error; }
|
||||||
|
|
||||||
|
Connected = true;
|
||||||
|
|
||||||
|
ConnectionCallback(gcnew ConnectData(true, ServerSocket));
|
||||||
|
|
||||||
|
ReceiveData^ receiveData = gcnew ReceiveData(DataServer->buffer, ServerData::size, ServerSocket);
|
||||||
|
|
||||||
|
try { ServerSocket->BeginReceive(DataServer->buffer, 0, ServerData::size, SocketFlags::None, gcnew AsyncCallback(this, &NetClient::ReadCallback), receiveData); }
|
||||||
|
catch (...) {}
|
||||||
|
|
||||||
|
return ClientState::Connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода Close
|
||||||
|
void NetClient::Close()
|
||||||
|
{
|
||||||
|
try { ServerSocket->Shutdown(SocketShutdown::Both); }
|
||||||
|
catch (...) {}
|
||||||
|
ServerSocket->Close();
|
||||||
|
Connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода Send
|
||||||
|
void NetClient::Send(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
if (ServerSocket != nullptr && Connected)
|
||||||
|
{
|
||||||
|
try { ServerSocket->Send(data); }
|
||||||
|
catch (...) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода ReadCallback
|
||||||
|
void NetClient::ReadCallback(IAsyncResult^ ar)
|
||||||
|
{
|
||||||
|
ReceiveData^ cd = (ReceiveData^)ar->AsyncState;
|
||||||
|
if (cd == nullptr) return;
|
||||||
|
|
||||||
|
int bytes = 0;
|
||||||
|
try { bytes = ServerSocket->EndReceive(ar); }
|
||||||
|
catch (...) {}
|
||||||
|
|
||||||
|
if (bytes == 0)
|
||||||
|
{
|
||||||
|
ServerSocket->Close();
|
||||||
|
Connected = false;
|
||||||
|
|
||||||
|
if (ServerSocket != nullptr)
|
||||||
|
{
|
||||||
|
ConnectionCallback(gcnew ConnectData(false, nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReceiveCallback(gcnew ReceiveData(cd->Buffer, bytes, ServerSocket));
|
||||||
|
|
||||||
|
try { ServerSocket->BeginReceive(cd->Buffer, 0, ServerData::size, SocketFlags::None, gcnew AsyncCallback(this, &NetClient::ReadCallback), cd); }
|
||||||
|
catch (...) {}
|
||||||
|
}
|
||||||
|
}
|
68
DroneClientCpp/NetClient.h
Normal file
68
DroneClientCpp/NetClient.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <vcclr.h>
|
||||||
|
|
||||||
|
#using <System.dll>
|
||||||
|
#using <System.Net.dll>
|
||||||
|
|
||||||
|
using namespace System;
|
||||||
|
using namespace System::Net;
|
||||||
|
using namespace System::Net::Sockets;
|
||||||
|
|
||||||
|
namespace DroneSimulator {
|
||||||
|
|
||||||
|
public ref class NetClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ref class ConnectData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool Connect;
|
||||||
|
Socket^ Server;
|
||||||
|
|
||||||
|
ConnectData(bool connect, Socket^ server);
|
||||||
|
};
|
||||||
|
|
||||||
|
ref class ReceiveData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
array<Byte>^ Buffer;
|
||||||
|
int Size;
|
||||||
|
Socket^ Server;
|
||||||
|
|
||||||
|
ReceiveData(array<Byte>^ buffer, int size, Socket^ server);
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
ref class ServerData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
literal int size = 1024;
|
||||||
|
array<Byte>^ buffer = gcnew array<Byte>(size);
|
||||||
|
};
|
||||||
|
|
||||||
|
bool Connected;
|
||||||
|
Socket^ ServerSocket;
|
||||||
|
ServerData^ DataServer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
delegate void ClientCallback(Object^ o);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ClientCallback^ ConnectionCallback;
|
||||||
|
ClientCallback^ ReceiveCallback;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NetClient(); // Добавлен конструктор
|
||||||
|
|
||||||
|
enum class ClientState { Error, Connected, Stop };
|
||||||
|
|
||||||
|
ClientState Connect(String^ Addr, int Port, ClientCallback^ Connection, ClientCallback^ Receive);
|
||||||
|
void Close();
|
||||||
|
void Send(array<Byte>^ data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ReadCallback(IAsyncResult^ ar);
|
||||||
|
};
|
||||||
|
}
|
11
DroneClientCpp/Source.cpp
Normal file
11
DroneClientCpp/Source.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "MyForm.h"
|
||||||
|
|
||||||
|
using namespace MyWinFormsApp; // ???????????? ???? ?????? ???????
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
int main(array<String^>^ args) {
|
||||||
|
Application::EnableVisualStyles(); // ???????? ??????????? ????? ????????? ??????????
|
||||||
|
Application::SetCompatibleTextRenderingDefault(false); // ????????? ?????????? ??????
|
||||||
|
Application::Run(gcnew MyForm()); // ?????? ?????
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user