1 Commits
main ... Dana

Author SHA1 Message Date
28b33ed671 test 2025-03-31 11:31:28 +03:00
128 changed files with 1252 additions and 2110 deletions

4
.gitignore vendored
View File

@ -1,4 +0,0 @@
.vs/
obj/
bin/
x64/

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}

View File

@ -0,0 +1,53 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|d:\\cpl\\simulator\\droneclient\\droneclient\\formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|solutionrelative:formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
},
{
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|d:\\cpl\\simulator\\droneclient\\droneclient\\formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form",
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|solutionrelative:formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "FormMain.cs",
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
"RelativeDocumentMoniker": "FormMain.cs",
"ToolTip": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
"RelativeToolTip": "FormMain.cs",
"ViewState": "AgIAACEAAAAAAAAAAAAYwCYAAAAOAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-27T13:11:11.045Z",
"EditorCaption": ""
},
{
"$type": "Document",
"DocumentIndex": 1,
"Title": "FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
"RelativeDocumentMoniker": "FormMain.cs",
"ToolTip": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
"RelativeToolTip": "FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-27T13:11:01.471Z",
"EditorCaption": " [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]"
}
]
}
]
}
]
}

View File

@ -1,17 +1,26 @@
using System.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace DroneClient
{
internal class Drone
{
public struct DataOut
{
public float AccX, AccY, AccZ;
public float GyrX, GyrY, GyrZ;
public float PosX, PosY;
public float LaserRange;
}
public struct DataIn
{
public float MotorUL, MotorUR, MotorDL, MotorDR;
}
public static byte[] getBytes(object data)
{
@ -54,165 +63,5 @@ namespace DroneClient
return mem;
}
private byte[] SendDataMotor4()
{
DroneData.DataMotor4 mot4 = new DroneData.DataMotor4();
mot4.Head.Size = Marshal.SizeOf(typeof(DroneData.DataMotor4));
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);
}
private byte[]? RecvDataIMU(byte[] data)
{
DroneData.DataIMU imu = (DroneData.DataIMU)fromBytes(data, typeof(DroneData.DataIMU));
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 new byte[0];
}
private byte[]? RecvDataPos(byte[] data)
{
DroneData.DataPos pos = (DroneData.DataPos)fromBytes(data, typeof(DroneData.DataPos));
PosX = pos.Local.X; PosY = pos.Local.Y;
LaserRange = pos.LiDAR;
return new byte[0];
}
private byte[]? ClientRequestResponse(DroneData.DataHead head, byte[] body)
{
byte[] zero = new 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;
}
private const int DroneStreamCount = 512;
private byte[] DroneStreamData = new byte[DroneStreamCount];
private int DroneStreamIndex = 0;
private DroneData.DataHead DroneStreamHead = new DroneData.DataHead() { Mode = DroneData.DataMode.None, Size = 0, Type = DroneData.DataType.None };
public List<byte[]?>? DataStream(byte[]? data, int size)
{
List<byte[]?> ret = new List<byte[]?>();
if (data == null) return ret; // Последовательность не сформирована, ждать данных
if (size + DroneStreamIndex > DroneStreamCount) return null; // Ошибка переполнения, поток сломан (конец)
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, typeof(DroneData.DataHead));
}
if (DroneStreamHead.Size > DroneStreamIndex) break; // Пакет ещё не полный
byte[] body = new 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;
}
public byte[] SendReqest()
{
DroneData.DataHead imu = new DroneData.DataHead();
imu.Size = DroneData.DataHead.StrLen;
imu.Mode = DroneData.DataMode.Request;
imu.Type = DroneData.DataType.DataIMU;
DroneData.DataHead pos = new DroneData.DataHead();
pos.Size = DroneData.DataHead.StrLen;
pos.Mode = DroneData.DataMode.Request;
pos.Type = DroneData.DataType.DataPos;
byte[] si = getBytes(imu);
byte[] sp = getBytes(pos);
byte[] sm = SendDataMotor4();
byte[] send = new byte[si.Length + sp.Length + sm.Length];
si.CopyTo(send, 0);
sp.CopyTo(send, si.Length);
sm.CopyTo(send, si.Length + sp.Length);
return send;
}
}
}

View File

@ -1,67 +0,0 @@
using System.Runtime.InteropServices;
namespace DroneData
{
public enum DataMode : ushort
{
None = 0, Response = 1, Request = 2
};
public enum DataType : ushort
{
None = 0, Head = 1,
// Output
DataIMU = 1001, DataPos = 1002,
// Input
DataMotor4 = 2001, DataMotor6 = 2002
};
public struct DataHead
{
public int Size;
public DataMode Mode;
public DataType Type;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataHead));
}
public struct XYZ { public float X, Y, Z; }
public struct DataIMU
{
public DataHead Head;
public XYZ Acc, Gyr, Mag;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataIMU));
}
public struct DataPos
{
public DataHead Head;
public XYZ Local; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float LiDAR; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataPos));
}
public struct DataMotor4
{
public DataHead Head;
public ulong Count;
public float UL, UR, DL, DR;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor4));
}
public struct DataMotor6
{
public DataHead Head;
public ulong Count;
public float UL, UR, LL, RR, DL, DR;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor6));
}
}

View File

@ -20,8 +20,6 @@ namespace DroneSimulator
ConnectData data = (ConnectData)o;
if (!data.Connect)
{
try
{
Invoke((MethodInvoker)delegate
{
@ -29,29 +27,28 @@ namespace DroneSimulator
button_Connect.BackColor = Color.Transparent;
MessageBox.Show("Connection closed");
});
}
catch { }
return;
}
byte[] send = Drone.getBytes(sendDrone);
data.Server.Send(send);
}
Drone dataDrone = new Drone();
Drone.DataIn sendDrone;
Drone.DataOut recvDrone;
private void ReceiveCallback(object o)
{
ReceiveData data = (ReceiveData)o;
List<byte[]?>? send = dataDrone.DataStream(data.Buffer, data.Size);
recvDrone = (Drone.DataOut)Drone.fromBytes(data.Buffer, typeof(Drone.DataOut));
if (send == null) return;
try
{
foreach (byte[]? b in send)
{
if (b != null) data.Server?.Send(b);
}
}
byte[] send = Drone.getBytes(sendDrone);
try { data.Server.Send(send); }
catch { }
}
@ -91,19 +88,17 @@ namespace DroneSimulator
private void timer_Test_Tick(object sender, EventArgs e)
{
label_Acc_X.Text = dataDrone.AccX.ToString();
label_Acc_Y.Text = dataDrone.AccY.ToString();
label_Acc_Z.Text = dataDrone.AccZ.ToString();
label_Acc_X.Text = recvDrone.AccX.ToString();
label_Acc_Y.Text = recvDrone.AccY.ToString();
label_Acc_Z.Text = recvDrone.AccZ.ToString();
label_Gyr_X.Text = dataDrone.GyrX.ToString();
label_Gyr_Y.Text = dataDrone.GyrY.ToString();
label_Gyr_Z.Text = dataDrone.GyrZ.ToString();
label_Gyr_X.Text = recvDrone.GyrX.ToString();
label_Gyr_Y.Text = recvDrone.GyrY.ToString();
label_Gyr_Z.Text = recvDrone.GyrZ.ToString();
label_Pos_X.Text = dataDrone.PosX.ToString();
label_Pos_Y.Text = dataDrone.PosY.ToString();
label_Pos_L.Text = dataDrone.LaserRange.ToString();
netClient.SendData(dataDrone.SendReqest());
label_Pos_X.Text = recvDrone.PosX.ToString();
label_Pos_Y.Text = recvDrone.PosY.ToString();
label_Pos_L.Text = recvDrone.LaserRange.ToString();
}
private void trackBar_Power_Scroll(object sender, EventArgs e)
@ -112,44 +107,42 @@ namespace DroneSimulator
label_Pow.Text = pow.ToString();
dataDrone.MotorUL = dataDrone.MotorUR = dataDrone.MotorDL = dataDrone.MotorDR = pow;
sendDrone.MotorUL = sendDrone.MotorUR = sendDrone.MotorDL = sendDrone.MotorDR = pow;
}
private void button_UU_MouseDown(object sender, MouseEventArgs e)
{
const float pow = 0.1f;
if (sender == button_UU)
{
dataDrone.MotorUL -= pow; dataDrone.MotorUR -= pow;
dataDrone.MotorDL += pow; dataDrone.MotorDR += pow;
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR -= 0.1f;
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR += 0.1f;
}
if (sender == button_DD)
{
dataDrone.MotorUL += pow; dataDrone.MotorUR += pow;
dataDrone.MotorDL -= pow; dataDrone.MotorDR -= pow;
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR += 0.1f;
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR -= 0.1f;
}
if (sender == button_LL)
{
dataDrone.MotorUL -= pow; dataDrone.MotorUR += pow;
dataDrone.MotorDL -= pow; dataDrone.MotorDR += pow;
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR += 0.1f;
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR += 0.1f;
}
if (sender == button_RR)
{
dataDrone.MotorUL += pow; dataDrone.MotorUR -= pow;
dataDrone.MotorDL += pow; dataDrone.MotorDR -= pow;
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR -= 0.1f;
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR -= 0.1f;
}
if (sender == button_ML)
{
dataDrone.MotorUL -= pow; dataDrone.MotorUR += pow;
dataDrone.MotorDL += pow; dataDrone.MotorDR -= pow;
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR += 0.1f;
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR -= 0.1f;
}
if (sender == button_MR)
{
dataDrone.MotorUL += pow; dataDrone.MotorUR -= pow;
dataDrone.MotorDL -= pow; dataDrone.MotorDR += pow;
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR -= 0.1f;
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR += 0.1f;
}
}

View File

@ -1,4 +1,9 @@
using System.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
namespace DroneSimulator
@ -26,7 +31,6 @@ namespace DroneSimulator
public byte[] buffer = new byte[size];
}
private bool Connected = false;
private Socket? ServerSocket = null;
private ServerData DataServer = new ServerData();
@ -39,9 +43,10 @@ namespace DroneSimulator
public ClientState Connect(string Addr, int Port, ClientCallback Connection, ClientCallback Receive)
{
if (Connected)
if (ServerSocket != null)
{
Close();
ServerSocket.Close();
ServerSocket = null;
return ClientState.Stop;
}
@ -51,26 +56,24 @@ namespace DroneSimulator
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(Addr), Port);
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try { ServerSocket.Connect(ep); }
catch { ServerSocket.Close(); return ClientState.Error; }
Connected = true;
try
{
ServerSocket.Connect(ep);
}
catch { ServerSocket.Close(); ServerSocket = null; return ClientState.Error; }
ConnectionCallback(new ConnectData { Connect = true, Server = ServerSocket });
ReceiveData receiveData = new ReceiveData { Buffer = DataServer.buffer, Size = ServerData.size, Server = ServerSocket };
try { ServerSocket.BeginReceive(DataServer.buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), receiveData); }
catch { }
ServerSocket.BeginReceive(DataServer.buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), receiveData);
return ClientState.Connected;
}
public void Close()
{
try { ServerSocket?.Shutdown(SocketShutdown.Both); } catch { }
ServerSocket?.Close();
Connected = false;
ServerSocket = null;
}
public void ReadCallback(IAsyncResult ar)
@ -79,28 +82,23 @@ namespace DroneSimulator
if (cd == null) return;
int bytes = 0;
try { bytes = ServerSocket.EndReceive(ar); } catch { }
try { bytes = ServerSocket.EndReceive(ar); }
catch { }
if (bytes == 0)
{
ServerSocket?.Close();
Connected = false;
if (ServerSocket != null) ConnectionCallback(new ConnectData { Connect = false, Server = null });
ServerSocket = null;
return;
}
ReceiveCallback(new ReceiveData { Buffer = cd.Buffer, Size = bytes, Server = ServerSocket });
try { ServerSocket?.BeginReceive(cd.Buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), cd); }
catch { }
}
public void SendData(byte[] data)
{
try { ServerSocket?.Send(data); } catch { }
ServerSocket?.BeginReceive(cd.Buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), cd);
}
}
}

View File

@ -1,3 +0,0 @@
# Client
Образец клиента для подключения к симулятору.

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"DroneClient/1.0.0": {
"runtime": {
"DroneClient.dll": {}
}
}
}
},
"libraries": {
"DroneClient/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,19 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false
}
}
}

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]

View File

@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("DroneClient")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("DroneClient")]
[assembly: System.Reflection.AssemblyTitleAttribute("DroneClient")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows7.0")]
// Создано классом WriteCodeFragment MSBuild.

View File

@ -0,0 +1 @@
372de9fd6d36597e50cdb2250f48b9cb0d5e8e1a2d1e568b83e287afe9580301

View File

@ -0,0 +1,22 @@
is_global = true
build_property.ApplicationManifest =
build_property.StartupObject =
build_property.ApplicationDefaultFont =
build_property.ApplicationHighDpiMode =
build_property.ApplicationUseCompatibleTextRendering =
build_property.ApplicationVisualStyles =
build_property.TargetFramework = net9.0-windows
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = DroneClient
build_property.ProjectDir = D:\CPL\Simulator\DroneClient\DroneClient\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.CsWinRTUseWindowsUIXamlProjections = false
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@ -0,0 +1,10 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Drawing;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Windows.Forms;

View File

@ -0,0 +1 @@
01e86f1c7bc139724ab77bc57845e8da30f3f593b41b11317ce8867d8fb43c28

View File

@ -0,0 +1,32 @@
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.GenerateResource.cache
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.GeneratedMSBuildEditorConfig.editorconfig
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfoInputs.cache
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfo.cs
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.CoreCompileInputs.cache
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.exe
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.deps.json
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.runtimeconfig.json
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.dll
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.pdb
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.dll
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\refint\DroneClient.dll
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.pdb
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.genruntimeconfig.cache
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\ref\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.exe
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.deps.json
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.runtimeconfig.json
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.pdb
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.GenerateResource.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.GeneratedMSBuildEditorConfig.editorconfig
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfoInputs.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfo.cs
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.CoreCompileInputs.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\refint\DroneClient.dll
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.pdb
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.genruntimeconfig.cache
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\ref\DroneClient.dll

View File

@ -0,0 +1,11 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {}
},
"libraries": {}
}

View File

@ -0,0 +1,25 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"additionalProbingPaths": [
"C:\\Users\\Дана\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Дана\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false,
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
}
}
}

Binary file not shown.

View File

@ -0,0 +1 @@
812e26f7e032de5fb2d5301fec24f483552f39e0a38ac0c052cba2ffa3a73bbd

Binary file not shown.

View File

@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyTitleAttribute("DroneSimulator")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows7.0")]
// Generated by the MSBuild WriteCodeFragment class.

View File

@ -0,0 +1 @@
7f461f329c2aabe3c068a957f4f02cdcdb168c359c556cd0c46598798ec3c65d

View File

@ -0,0 +1,22 @@
is_global = true
build_property.ApplicationManifest =
build_property.StartupObject =
build_property.ApplicationDefaultFont =
build_property.ApplicationHighDpiMode =
build_property.ApplicationUseCompatibleTextRendering =
build_property.ApplicationVisualStyles =
build_property.TargetFramework = net9.0-windows
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = DroneSimulator
build_property.ProjectDir = D:\Files\Main\Projects\Fly\DroneClient\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
build_property.CsWinRTUseWindowsUIXamlProjections = false
build_property.EffectiveAnalysisLevelStyle = 9.0
build_property.EnableCodeStyleSeverity =

View File

@ -0,0 +1,10 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Drawing;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.Windows.Forms;

View File

@ -0,0 +1 @@
051ffb89f1ee627ab3b9aaef920afd665a18f0f3c3fe82852812d5c6608dcb30

View File

@ -0,0 +1,32 @@
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form1.resources
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
R:\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
R:\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources

View File

@ -0,0 +1,11 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {}
},
"libraries": {}
}

View File

@ -0,0 +1,25 @@
{
"runtimeOptions": {
"tfm": "net9.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "9.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "9.0.0"
}
],
"additionalProbingPaths": [
"C:\\Users\\USER\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\USER\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configProperties": {
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false,
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
}
}
}

View File

@ -0,0 +1 @@
42c9c47684404b6458665b5db1d77e8e1563e0e910b9607df810cd1011407bfc

Binary file not shown.

View File

@ -0,0 +1,76 @@
{
"format": 1,
"restore": {
"D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj": {}
},
"projects": {
"D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"projectName": "DroneClient",
"projectPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"packagesPath": "C:\\Users\\Дана\\.nuget\\packages\\",
"outputPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Дана\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net9.0-windows"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.200"
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
},
"Microsoft.WindowsDesktop.App.WindowsForms": {
"privateAssets": "none"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Дана\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.13.2</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Дана\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -0,0 +1,76 @@
{
"format": 1,
"restore": {
"D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj": {}
},
"projects": {
"D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj",
"projectName": "DroneSimulator",
"projectPath": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj",
"packagesPath": "C:\\Users\\USER\\.nuget\\packages\\",
"outputPath": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\USER\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net9.0-windows"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.200"
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
},
"Microsoft.WindowsDesktop.App.WindowsForms": {
"privateAssets": "none"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
}
}
}
}
}

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\USER\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.13.2</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\USER\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />

View File

@ -0,0 +1,82 @@
{
"version": 3,
"targets": {
"net9.0-windows7.0": {}
},
"libraries": {},
"projectFileDependencyGroups": {
"net9.0-windows7.0": []
},
"packageFolders": {
"C:\\Users\\Дана\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"projectName": "DroneClient",
"projectPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"packagesPath": "C:\\Users\\Дана\\.nuget\\packages\\",
"outputPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\Дана\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"net9.0-windows"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
},
"SdkAnalysisLevel": "9.0.200"
},
"frameworks": {
"net9.0-windows7.0": {
"targetAlias": "net9.0-windows",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48",
"net481"
],
"assetTargetFallback": true,
"warn": true,
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
},
"Microsoft.WindowsDesktop.App.WindowsForms": {
"privateAssets": "none"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"version": 2,
"dgSpecHash": "ddOSNwF62rQ=",
"success": true,
"projectFilePath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
"expectedPackageFiles": [],
"logs": []
}

View File

@ -1,106 +0,0 @@
#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();
}

View File

@ -1,44 +0,0 @@
#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();
};

View File

@ -1,197 +0,0 @@
#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;
}
}

View File

@ -1,46 +0,0 @@
#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();
};
}

View File

@ -1,65 +0,0 @@
#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);
}
}
};
}

View File

@ -1,28 +0,0 @@

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

View File

@ -1,141 +0,0 @@
<?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>

View File

@ -1,42 +0,0 @@
<?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>

View File

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -1,77 +0,0 @@
#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);
};
}

View File

@ -1,12 +0,0 @@
#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;
}

Binary file not shown.

View File

@ -1,126 +0,0 @@
<?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>

View File

@ -1,12 +0,0 @@
#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;
}

Binary file not shown.

View File

@ -1,120 +0,0 @@
<?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>

View File

@ -1,105 +0,0 @@
#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 (...) {}
}
}

View File

@ -1,68 +0,0 @@
#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);
};
}

View File

@ -1,11 +0,0 @@
#include "MyForm.h"
using namespace MyWinFormsApp; // ???????????? ???? ?????? ???????
[STAThread]
int main(array<String^>^ args) {
Application::EnableVisualStyles(); // ???????? ??????????? ????? ????????? ??????????
Application::SetCompatibleTextRenderingDefault(false); // ????????? ?????????? ??????
Application::Run(gcnew MyForm()); // ?????? ?????
return 0;
}

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}

View File

@ -0,0 +1,37 @@
{
"Version": 1,
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\",
"Documents": [
{
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneSimulator.csproj|d:\\cpl\\simulator\\dronesimulator\\dronesimulator\\screen2d.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneSimulator.csproj|solutionrelative:screen2d.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
}
],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": [
{
"DockedWidth": 200,
"SelectedChildIndex": 0,
"Children": [
{
"$type": "Document",
"DocumentIndex": 0,
"Title": "Screen2D.cs",
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\Screen2D.cs",
"RelativeDocumentMoniker": "Screen2D.cs",
"ToolTip": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\Screen2D.cs",
"RelativeToolTip": "Screen2D.cs",
"ViewState": "AgIAAIgAAAAAAAAAAAAwwAAAAAAAAAAAAAAAAA==",
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
"WhenOpened": "2025-03-27T13:13:30.215Z",
"EditorCaption": ""
}
]
}
]
}
]
}

View File

@ -1,7 +1,11 @@
using System.CodeDom;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.AxHost;
namespace DroneSimulator
{
@ -11,17 +15,15 @@ namespace DroneSimulator
public float Mass; // Масса
public bool Active; // Живой?
public float Length; // Длинна лучей
public const float Dynamic = 10; // Динамика вращения
public Vector3 PosXYZ, SpdXYZ, AccXYZ; // Положение в пространстве: Позиция, Скорость, Ускорение
public Quaternion Quat; // Основной кватернион
public float Power = 0; // Тяга всех двигателей (0-1)
public float MaxPower; // Максимальная Тяга всех двигателей (КГ)
public float Power = 0; // Тяга всех двигателей
public Vector3 SpdPRY, AccPRY; // Поворот в пространстве: pitch roll yaw
public Vector3 Acc, Gyr; // Имитация: Акселерометр, Гироскоп
public float LaserRange; // Имитация: Дальномер
private const float Gravity = 9.8f;
private const float Gravity = 1.0f;
private const float TO_GRAD = 180 / MathF.PI;
private const float TO_RADI = MathF.PI / 180;
@ -31,16 +33,25 @@ namespace DroneSimulator
private static int CounterID = 0;
public static byte[] getBytes(object data)
public struct DataOut
{
int size = Marshal.SizeOf(data);
public float AccX, AccY, AccZ;
public float GyrX, GyrY, GyrZ;
public float PosX, PosY;
public float LaserRange;
public byte[] getBytes()
{
int size = Marshal.SizeOf(this);
byte[] arr = new byte[size];
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(data, ptr, true);
Marshal.StructureToPtr(this, ptr, true);
Marshal.Copy(ptr, arr, 0, size);
}
finally
@ -49,12 +60,17 @@ namespace DroneSimulator
}
return arr;
}
}
public static object fromBytes(byte[] arr, Type type)
public struct DataIn
{
object mem = new object();
public float MotorUL, MotorUR, MotorDL, MotorDR;
int size = Marshal.SizeOf(type);
public void fromBytes(byte[] arr)
{
DataIn mem = new DataIn();
int size = Marshal.SizeOf(mem);
IntPtr ptr = IntPtr.Zero;
try
{
@ -62,60 +78,24 @@ namespace DroneSimulator
Marshal.Copy(arr, 0, ptr, size);
mem = Marshal.PtrToStructure(ptr, type);
mem = (DataIn)Marshal.PtrToStructure(ptr, mem.GetType());
}
finally
{
Marshal.FreeHGlobal(ptr);
}
return mem;
this = mem;
}
/*public struct DataOut
{
public float AccX, AccY, AccZ;
public float GyrX, GyrY, GyrZ;
public float PosX, PosY;
public float LaserRange;
}
public DataOut GetDataOut()
{
DataOut data = new DataOut();
data.AccX = Acc.X; data.AccY = Acc.Y; data.AccZ = Acc.Z;
data.GyrX = Gyr.X; data.GyrY = Gyr.Y; data.GyrZ = Gyr.Z;
data.PosX = PosXYZ.X; data.PosY = PosXYZ.Y;
data.LaserRange = LaserRange;
return data;
}
public struct DataIn
{
public float MotorUL, MotorUR, MotorDL, MotorDR;
}*/
public struct DataVisual
{
public int ID; // Идентификатор
public float W, X, Y, Z; // Кватернион вращения
public float PosX, PosY, PosZ; // Координаты в пространстве
}
public DataVisual GetVisual()
{
return new DataVisual() { ID = this.ID, W = this.Quat.W, X = this.Quat.X, Y = this.Quat.Y, Z = this.Quat.Z, PosX = this.PosXYZ.X, PosY = this.PosXYZ.Y, PosZ = this.PosXYZ.Z };
}
private void ThreadFunction()
{
while (DroneThread != null)
{
Action(Environment.TickCount);
float time = Environment.TickCount - Timer;
Timer = Environment.TickCount;
Action(time / 100);
Thread.Sleep(1);
}
}
@ -124,7 +104,7 @@ namespace DroneSimulator
{
ID = id;
Active = false;
PosXYZ = Vector3.Zero;
PosXYZ = new Vector3(2000, 1000, 0);
SpdXYZ = Vector3.Zero;
AccXYZ = Vector3.Zero;
Quat = Quaternion.Identity;
@ -134,11 +114,10 @@ namespace DroneSimulator
DroneThread.Start();
}
public int Create(float power, float mass, float len)
public int Create(float mass, float len)
{
Mass = mass;
Mass = Range(mass);
Length = len;
MaxPower = power;
Active = true;
@ -191,30 +170,25 @@ namespace DroneSimulator
return new Vector4(GetAngle(grav.Y, grav.X, grav.Z), GetAngle(-grav.X, grav.Y, grav.Z), yaw, grav.Z);
}
public void Action(int tick)
public void Action(float time)
{
float time = (tick - Timer) / 1000.0f;
Timer = tick;
if (!Active) return;
float flow = Power;
if (PosXYZ.Z < 0.3f)
if (PosXYZ.Z < 100)
{
flow += flow * 0.1f; // Воздушная подушка
}
SpdPRY += AccPRY * (Dynamic * time / (Mass * Length));
Quaternion pow = Quaternion.Inverse(Quat) * new Quaternion(0, 0, flow, 0) * Quat;
AccXYZ = new Vector3(pow.X, pow.Y, pow.Z) * (Gravity / Mass);
AccXYZ = new Vector3(pow.X, pow.Y, pow.Z) / Mass;
SpdPRY += AccPRY * time / (Mass * Length);
SpdXYZ += (AccXYZ + new Vector3(0, 0, -Gravity)) * time;
PosXYZ += SpdXYZ * time;
AccXYZ /= Gravity; // Вернуть измерения в G
if (PosXYZ.Z < 0)
{
SpdPRY = Vector3.Zero;
@ -222,7 +196,7 @@ namespace DroneSimulator
SpdXYZ.Y = 0;
Quat = Quaternion.Identity;
}
else Rotate(SpdPRY.X * time, SpdPRY.Y * time, SpdPRY.Z * time);
else Rotate(SpdPRY.X, SpdPRY.Y, SpdPRY.Z);
Vector4 ori = GetOrientation();
@ -235,7 +209,7 @@ namespace DroneSimulator
Active = false; // Сильно ударился о землю
}*/
/*if (MathF.Abs(ori.X) > 20 || MathF.Abs(ori.Y) > 20)
/*if (MathF.Abs(ori.X) > 45 || MathF.Abs(ori.Y) > 45)
{
Active = false; // Повредил винты при посадке
}*/
@ -248,13 +222,13 @@ namespace DroneSimulator
}
else
{
if (ori.W < 0)
/*if (ori.W < 0)
{
//Active = false; // Перевернулся вверх ногами
}
Active = false; // Перевернулся вверх ногами
}*/
Quaternion grav = new Quaternion(AccXYZ.X, AccXYZ.Y, AccXYZ.Z, 0);
//grav = (Quat * grav) * Quaternion.Inverse(Quat); // Инерциальный акселерометр (тест)
grav = (Quat * grav) * Quaternion.Inverse(Quat);
Acc = new Vector3(grav.X, grav.Y, grav.Z);
Gyr = SpdPRY;
@ -271,7 +245,7 @@ namespace DroneSimulator
if (pow > 1) pow = 1;
if (pow < 0) pow = 0;
return pow * MaxPower;
return pow;
}
public void SetQadroPow(float ul, float ur, float dl, float dr)
@ -284,143 +258,5 @@ namespace DroneSimulator
AccPRY.X = ((ul + ur) - (dl + dr));
AccPRY.Z = ((ul + dr) - (dl + ur)) / 4;
}
private void RecvDataMotor4(byte[] data)
{
DroneData.DataMotor4 mot = (DroneData.DataMotor4)fromBytes(data, typeof(DroneData.DataMotor4));
/* обработка */
SetQadroPow(mot.UL, mot.UR, mot.DL, mot.DR);
}
private byte[] SendDataIMU()
{
DroneData.DataIMU imu = new DroneData.DataIMU();
imu.Head.Size = Marshal.SizeOf(typeof(DroneData.DataIMU));
imu.Head.Mode = DroneData.DataMode.Response;
imu.Head.Type = DroneData.DataType.DataIMU;
imu.Acc.X = Acc.X; imu.Acc.Y = Acc.Y; imu.Acc.Z = Acc.Z;
imu.Gyr.X = Gyr.X; imu.Gyr.Y = Gyr.Y; imu.Gyr.Z = Gyr.Z;
imu.Mag.X = 0; imu.Mag.Y = 0; imu.Mag.Z = 0;
return getBytes(imu);
}
private byte[] SendDataPos()
{
DroneData.DataPos pos = new DroneData.DataPos();
pos.Head.Size = Marshal.SizeOf(typeof(DroneData.DataPos));
pos.Head.Mode = DroneData.DataMode.Response;
pos.Head.Type = DroneData.DataType.DataPos;
pos.Local.X = PosXYZ.X; pos.Local.Y = PosXYZ.Y; pos.Local.Z = PosXYZ.Z;
pos.LiDAR = LaserRange;
return getBytes(pos);
}
private byte[]? ServerRequestResponse(DroneData.DataHead head, byte[] body)
{
byte[] zero = new byte[0];
switch (head.Type)
{
case DroneData.DataType.DataIMU:
{
if (head.Mode == DroneData.DataMode.Request)
{
// Запрос данных
return SendDataIMU();
}
else
{
// Пришли данные
// ... //
//
return zero;
}
}
case DroneData.DataType.DataPos:
{
if (head.Mode == DroneData.DataMode.Request)
{
// Запрос данных
return SendDataPos();
}
else
{
// Пришли данные
// ... //
//
return zero;
}
}
case DroneData.DataType.DataMotor4:
{
if (head.Mode == DroneData.DataMode.Request)
{
// Запрос данных
// ... //
//
return zero;
}
else
{
// Пришли данные
RecvDataMotor4(body);
return zero;
}
}
}
return zero;
}
private const int DroneStreamCount = 512;
private byte[] DroneStreamData = new byte[DroneStreamCount];
private int DroneStreamIndex = 0;
private DroneData.DataHead DroneStreamHead = new DroneData.DataHead() { Mode = DroneData.DataMode.None, Size = 0, Type = DroneData.DataType.None };
public List<byte[]?>? DataStream(byte[]? data, int size)
{
List<byte[]?> ret = new List<byte[]?>();
if (data == null) return ret; // Последовательность не сформирована, ждать данных
if (size + DroneStreamIndex > DroneStreamCount) return null; // Ошибка переполнения, поток сломан (конец)
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, typeof(DroneData.DataHead));
}
if (DroneStreamHead.Size > DroneStreamIndex) break; // Пакет ещё не полный
byte[] body = new 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(ServerRequestResponse(DroneStreamHead, body));
}
return ret;
}
}
}

View File

@ -1,67 +0,0 @@
using System.Runtime.InteropServices;
namespace DroneData
{
public enum DataMode : ushort
{
None = 0, Response = 1, Request = 2
};
public enum DataType : ushort
{
None = 0, Head = 1,
// Output
DataIMU = 1001, DataPos = 1002,
// Input
DataMotor4 = 2001, DataMotor6 = 2002
};
public struct DataHead
{
public int Size;
public DataMode Mode;
public DataType Type;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataHead));
}
public struct XYZ { public float X, Y, Z; }
public struct DataIMU
{
public DataHead Head;
public XYZ Acc, Gyr, Mag;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataIMU));
}
public struct DataPos
{
public DataHead Head;
public XYZ Local; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public float LiDAR; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataPos));
}
public struct DataMotor4
{
public DataHead Head;
public ulong Count;
public float UL, UR, DL, DR;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor4));
}
public struct DataMotor6
{
public DataHead Head;
public ulong Count;
public float UL, UR, LL, RR, DL, DR;
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor6));
}
}

View File

@ -38,10 +38,6 @@
tabControl_Menu = new TabControl();
tabPage_Main = new TabPage();
groupBox_Visual = new GroupBox();
numericUpDown_Visual_Limit = new NumericUpDown();
label1 = new Label();
label_Visual_Num = new Label();
label3 = new Label();
button_Visual_Start = new Button();
numericUpDown_Visual_Port = new NumericUpDown();
label_Visual_Port = new Label();
@ -67,7 +63,6 @@
tabControl_Menu.SuspendLayout();
tabPage_Main.SuspendLayout();
groupBox_Visual.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Limit).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).BeginInit();
groupBox_Clients.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Limit).BeginInit();
@ -149,61 +144,18 @@
//
// groupBox_Visual
//
groupBox_Visual.Controls.Add(numericUpDown_Visual_Limit);
groupBox_Visual.Controls.Add(label1);
groupBox_Visual.Controls.Add(label_Visual_Num);
groupBox_Visual.Controls.Add(label3);
groupBox_Visual.Controls.Add(button_Visual_Start);
groupBox_Visual.Controls.Add(numericUpDown_Visual_Port);
groupBox_Visual.Controls.Add(label_Visual_Port);
groupBox_Visual.Dock = DockStyle.Top;
groupBox_Visual.Location = new Point(3, 83);
groupBox_Visual.Name = "groupBox_Visual";
groupBox_Visual.Size = new Size(204, 91);
groupBox_Visual.Size = new Size(204, 62);
groupBox_Visual.TabIndex = 2;
groupBox_Visual.TabStop = false;
groupBox_Visual.Tag = "#visual";
groupBox_Visual.Text = "Visual";
//
// numericUpDown_Visual_Limit
//
numericUpDown_Visual_Limit.Location = new Point(44, 57);
numericUpDown_Visual_Limit.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
numericUpDown_Visual_Limit.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
numericUpDown_Visual_Limit.Name = "numericUpDown_Visual_Limit";
numericUpDown_Visual_Limit.Size = new Size(42, 23);
numericUpDown_Visual_Limit.TabIndex = 13;
numericUpDown_Visual_Limit.Value = new decimal(new int[] { 1, 0, 0, 0 });
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(6, 59);
label1.Name = "label1";
label1.Size = new Size(37, 15);
label1.TabIndex = 12;
label1.Tag = "#clients_limit";
label1.Text = "Limit:";
//
// label_Visual_Num
//
label_Visual_Num.AutoSize = true;
label_Visual_Num.Location = new Point(161, 59);
label_Visual_Num.Name = "label_Visual_Num";
label_Visual_Num.Size = new Size(13, 15);
label_Visual_Num.TabIndex = 11;
label_Visual_Num.Text = "0";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(112, 59);
label3.Name = "label3";
label3.Size = new Size(43, 15);
label3.TabIndex = 10;
label3.Tag = "#clients_count";
label3.Text = "Count:";
//
// button_Visual_Start
//
button_Visual_Start.Location = new Point(112, 22);
@ -213,7 +165,6 @@
button_Visual_Start.Tag = "#visual_start";
button_Visual_Start.Text = "Start";
button_Visual_Start.UseVisualStyleBackColor = true;
button_Visual_Start.Click += button_Visual_Start_Click;
//
// numericUpDown_Visual_Port
//
@ -425,7 +376,6 @@
tabPage_Main.ResumeLayout(false);
groupBox_Visual.ResumeLayout(false);
groupBox_Visual.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Limit).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).EndInit();
groupBox_Clients.ResumeLayout(false);
groupBox_Clients.PerformLayout();
@ -466,9 +416,5 @@
private Panel panel1;
private ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.Timer timer_Test;
private NumericUpDown numericUpDown_Visual_Limit;
private Label label1;
private Label label_Visual_Num;
private Label label3;
}
}

View File

@ -4,9 +4,6 @@ using System.Windows.Forms;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Security.Policy;
using System.Runtime.InteropServices;
using System.CodeDom;
using System.Linq;
namespace DroneSimulator
{
@ -15,7 +12,6 @@ namespace DroneSimulator
Screen2D screen2D = null;
NetServerClients netServerClient = new NetServerClients();
NetServerVisual netServerVisual = new NetServerVisual();
List<Drone> AllDrones = new List<Drone>();
@ -24,7 +20,7 @@ namespace DroneSimulator
InitializeComponent();
}
private void ClientConnectionCallback(object o)
private void ConnectionCallback(object o)
{
NetServerClients.ConnectData data = (NetServerClients.ConnectData)o;
@ -36,7 +32,7 @@ namespace DroneSimulator
if (data.Connect)
{
Drone drone = new Drone(data.ID);
drone.Create(1.0f, 0.5f, 1.0f);
drone.Create(0.5f, 10.0f);
screen2D.CreateDrone(Color.Red, data.ID);
@ -57,7 +53,7 @@ namespace DroneSimulator
}
}
private void ClientReceiveCallback(object o)
private void ReceiveCallback(object o)
{
NetServerClients.ReceiveData data = (NetServerClients.ReceiveData)o;
@ -72,27 +68,30 @@ namespace DroneSimulator
if (drone == null) return;
List<byte[]?>? send = drone.DataStream(data.Buffer, data.Size);
Drone.DataIn id = new Drone.DataIn();
if (send == null) return;
try
{
foreach (byte[]? b in send)
{
if (b != null) data.Client?.Send(b);
}
}
catch { }
id.fromBytes(data.Buffer);
drone.SetQadroPow(id.MotorUL, id.MotorUR, id.MotorDL, id.MotorDR);
Drone.DataOut od = new Drone.DataOut();
od.AccX= drone.Acc.X; od.AccY= drone.Acc.Y; od.AccZ= drone.Acc.Z;
od.GyrX = drone.Gyr.X; od.GyrY = drone.Gyr.Y; od.GyrZ = drone.Gyr.Z;
od.PosX= drone.PosXYZ.X; od.PosY = drone.PosXYZ.Y;
od.LaserRange = drone.LaserRange;
data.Client.Send(od.getBytes());
}
private void button_Client_Start_Click(object sender, EventArgs e)
{
var done = netServerClient.StartServer((int)numericUpDown_Clients_Port.Value, (int)numericUpDown_Clients_Limit.Value, ClientConnectionCallback, ClientReceiveCallback);
var done = netServerClient.StartServer((int)numericUpDown_Clients_Port.Value, (int)numericUpDown_Clients_Limit.Value, ConnectionCallback, ReceiveCallback);
switch (done)
{
case NetServerClients.ServerState.Error:
{
MessageBox.Show("Error to start clients server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Error to start server");
break;
}
case NetServerClients.ServerState.Start:
@ -103,7 +102,6 @@ namespace DroneSimulator
}
case NetServerClients.ServerState.Stop:
{
label_Clients_Num.Text = "0";
button_Client_Start.Text = "Start";
button_Client_Start.BackColor = Color.Transparent;
break;
@ -146,63 +144,5 @@ namespace DroneSimulator
{
foreach (Drone d in AllDrones) d.Close();
}
private void VisualConnectionCallback(object o)
{
NetServerVisual.ConnectData data = (NetServerVisual.ConnectData)o;
Invoke((MethodInvoker)delegate
{
label_Clients_Num.Text = data.Count.ToString();
});
if (data.Connect)
{
//---
}
else
{
//---
}
}
private void VisualReceiveCallback(object o)
{
NetServerVisual.ReceiveData data = (NetServerVisual.ReceiveData)o;
foreach (Drone d in AllDrones)
{
Drone.DataVisual v = d.GetVisual();
try { data.Client.Send(Drone.getBytes(v)); }
catch { }
}
}
private void button_Visual_Start_Click(object sender, EventArgs e)
{
var done = netServerVisual.StartServer((int)numericUpDown_Visual_Port.Value, (int)numericUpDown_Visual_Limit.Value, VisualConnectionCallback, VisualReceiveCallback);
switch (done)
{
case NetServerVisual.ServerState.Error:
{
MessageBox.Show("Error to start visual server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
case NetServerVisual.ServerState.Start:
{
button_Visual_Start.Text = "Stop";
button_Visual_Start.BackColor = Color.LimeGreen;
break;
}
case NetServerVisual.ServerState.Stop:
{
label_Visual_Num.Text = "0";
button_Visual_Start.Text = "Start";
button_Visual_Start.BackColor = Color.Transparent;
break;
}
}
}
}
}

View File

@ -1,6 +1,10 @@
using System.Net.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
using System.Drawing;
namespace DroneSimulator
{
@ -17,9 +21,8 @@ namespace DroneSimulator
public class ReceiveData
{
public int ID;
public byte[] Buffer;
public byte[]? Buffer;
public int Size;
public Socket? Client;
@ -29,13 +32,13 @@ namespace DroneSimulator
{
public int ID;
public Socket? workSocket = null;
public const int count = 1024;
public byte[] buffer = new byte[count];
public const int BufferSize = 1024;
public byte[] buffer = new byte[BufferSize];
}
private int SocketID = 0;
private int SocketLimit;
private Socket? ServerSocket;
private Socket? ServerSocket = null;
private List<ClientData> ClientSockets = new List<ClientData>();
public delegate void ServerCallback(object o);
@ -43,21 +46,14 @@ namespace DroneSimulator
private ServerCallback? ConnectionCallback;
private ServerCallback? ReceiveCallback;
private bool Active = false;
public enum ServerState { Error, Start, Stop };
public ServerState StartServer(int Port, int Limit, ServerCallback Connection, ServerCallback Receive)
{
if (Active)
if (ServerSocket != null)
{
ServerSocket?.Close();
foreach (ClientData c in ClientSockets)
{
try { c.workSocket?.Shutdown(SocketShutdown.Both); } catch { }
c.workSocket?.Close();
}
ClientSockets.Clear();
ServerSocket.Close();
foreach (ClientData c in ClientSockets) { c.workSocket?.Shutdown(SocketShutdown.Both); c.workSocket?.Close(); }
return ServerState.Stop;
}
@ -74,9 +70,8 @@ namespace DroneSimulator
ServerSocket.Bind(ip);
ServerSocket.Listen(10);
ServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), ServerSocket);
Active = true;
}
catch { ServerSocket.Close(); return ServerState.Error; }
catch { ServerSocket.Close(); ServerSocket = null; return ServerState.Error; }
return ServerState.Start;
}
@ -89,7 +84,7 @@ namespace DroneSimulator
Socket handler;
try { handler = listener.EndAccept(ar); }
catch{ ServerSocket?.Close(); Active = false; return; }
catch{ ServerSocket?.Close(); ServerSocket = null; return; }
if (SocketLimit > ClientSockets.Count)
{
@ -103,7 +98,7 @@ namespace DroneSimulator
ConnectionCallback(new ConnectData { ID = clientData.ID, Connect = true, Count = ClientSockets.Count, Client = handler });
handler.BeginReceive(clientData.buffer, 0, ClientData.count, 0, new AsyncCallback(ReadCallback), clientData);
handler.BeginReceive(clientData.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), clientData);
}
else handler.Close();
@ -132,11 +127,7 @@ namespace DroneSimulator
ReceiveCallback(new ReceiveData { ID = cd.ID, Buffer = cd.buffer, Size = bytes, Client = cd.workSocket });
try
{
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.count, 0, new AsyncCallback(ReadCallback), cd);
}
catch { }
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), cd);
}
}
}

View File

@ -1,134 +0,0 @@
using System.Net.Sockets;
using System.Net;
namespace DroneSimulator
{
internal class NetServerVisual
{
public class ConnectData
{
public bool Connect;
public int Count;
public Socket? Client;
}
public class ReceiveData
{
public byte[]? Buffer;
public int Size;
public Socket? Client;
}
private class ClientData
{
public Socket? workSocket = null;
public const int BufferSize = 1024;
public byte[] buffer = new byte[BufferSize];
}
private int SocketLimit;
private Socket? ServerSocket;
private List<ClientData> ClientSockets = new List<ClientData>();
public delegate void ServerCallback(object o);
private ServerCallback? ConnectionCallback;
private ServerCallback? ReceiveCallback;
private bool Active = false;
public enum ServerState { Error, Start, Stop };
public ServerState StartServer(int Port, int Limit, ServerCallback Connection, ServerCallback Receive)
{
if (Active)
{
ServerSocket?.Close();
foreach (ClientData c in ClientSockets)
{
try { c.workSocket?.Shutdown(SocketShutdown.Both); } catch { }
c.workSocket?.Close();
}
ClientSockets.Clear();
return ServerState.Stop;
}
ConnectionCallback = Connection;
ReceiveCallback = Receive;
SocketLimit = Limit;
IPEndPoint ip = new(IPAddress.Any, Port);
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
ServerSocket.Bind(ip);
ServerSocket.Listen(10);
ServerSocket.BeginAccept(new AsyncCallback(AcceptCallback), ServerSocket);
Active = true;
}
catch { ServerSocket.Close(); return ServerState.Error; }
return ServerState.Start;
}
public void AcceptCallback(IAsyncResult ar)
{
Socket listener = (Socket)ar.AsyncState;
if (listener == null) return;
Socket handler;
try { handler = listener.EndAccept(ar); }
catch{ ServerSocket?.Close(); Active = false; return; }
if (SocketLimit > ClientSockets.Count)
{
ClientData clientData = new ClientData();
clientData.workSocket = handler;
ClientSockets.Add(clientData);
ConnectionCallback(new ConnectData { Connect = true, Count = ClientSockets.Count, Client = handler });
handler.BeginReceive(clientData.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), clientData);
}
else handler.Close();
listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
}
public void ReadCallback(IAsyncResult ar)
{
ClientData cd = (ClientData)ar.AsyncState;
if (cd == null) return;
int bytes = 0;
try { bytes = cd.workSocket.EndReceive(ar); }
catch { }
if (bytes == 0)
{
cd.workSocket?.Close();
ClientSockets.Remove(cd);
ConnectionCallback(new ConnectData { Connect = false, Count = ClientSockets.Count, Client = null });
return;
}
ReceiveCallback(new ReceiveData { Buffer = cd.buffer, Size = bytes, Client = cd.workSocket });
try
{
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), cd);
}
catch { }
}
}
}

View File

@ -1,4 +1,10 @@
using System.Numerics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
namespace DroneSimulator
{
@ -24,7 +30,6 @@ namespace DroneSimulator
public int Azimuth = 0;
}
private float Scale = 100;
private DrawCallback drawCallback;
private Bitmap MainArea = new Bitmap(4096, 2560);
private List<DroneInfo> DroneList = new List<DroneInfo>();
@ -162,11 +167,6 @@ namespace DroneSimulator
const float TO_GRAD = 180 / MathF.PI;
const float TO_RADI = MathF.PI / 180;
pos *= Scale;
pos.X += MainArea.Width / 2;
pos.Y += MainArea.Height / 2;
foreach (var d in DroneList)
{
if (d.ID != id) continue;

View File

@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v9.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v9.0": {
"DroneSimulator/1.0.0": {
"runtime": {
"DroneSimulator.dll": {}
}
}
}
},
"libraries": {
"DroneSimulator/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}

Some files were not shown because too many files have changed in this diff Show More