Compare commits
32 Commits
16fa3780d9
...
Dana
Author | SHA1 | Date | |
---|---|---|---|
06d621288c | |||
bac52d315b | |||
64c0637e6a | |||
6aeb99968e | |||
21b60b7f4c | |||
da7f5a8404 | |||
fd2318cbf6 | |||
bf037b0870 | |||
46e296b7c2 | |||
b8ff486e5a | |||
8dc1e17080 | |||
71e772a440 | |||
e6cb5430ef | |||
114522ad0a | |||
a74b5d1ab9 | |||
3975f5c6ed | |||
2c08331bbe | |||
215236fa15 | |||
d5e4c08527 | |||
b19fb44822 | |||
e1eb3bd73f | |||
38be80788b | |||
d8deec303a | |||
01023a458e | |||
6f3c102ad8 | |||
0ae998f0fb | |||
b611a915b6 | |||
b2599c94f8 | |||
ed2719f2b8 | |||
f1921083bb | |||
e1b7f7b8e3 | |||
28b33ed671 |
60
.gitignore
vendored
60
.gitignore
vendored
@ -1,58 +1,4 @@
|
|||||||
# Файлы и папки Visual Studio
|
|
||||||
*.obj
|
|
||||||
*.exe
|
|
||||||
*.pdb
|
|
||||||
*.user
|
|
||||||
*.aps
|
|
||||||
*.pch
|
|
||||||
*.vspscc
|
|
||||||
*.vssscc
|
|
||||||
*_i.c
|
|
||||||
*_p.c
|
|
||||||
*.ncb
|
|
||||||
*.suo
|
|
||||||
*.tlb
|
|
||||||
*.tlh
|
|
||||||
*.bak
|
|
||||||
*.cache
|
|
||||||
*.ilk
|
|
||||||
*.log
|
|
||||||
*.sbr
|
|
||||||
*.scc
|
|
||||||
*.idb
|
|
||||||
*.tlog
|
|
||||||
*.ipch
|
|
||||||
*.db
|
|
||||||
|
|
||||||
# Папки сборки
|
|
||||||
bin/
|
|
||||||
obj/
|
|
||||||
[Bb]in/
|
|
||||||
[Oo]bj/
|
|
||||||
Debug/
|
|
||||||
Release/
|
|
||||||
x64/
|
|
||||||
x86/
|
|
||||||
[Any CPU]/
|
|
||||||
|
|
||||||
# Файлы кэша и настройки VS
|
|
||||||
.vscode/
|
|
||||||
*.code-workspace
|
|
||||||
.vs/
|
.vs/
|
||||||
*.sln.docstates
|
obj/
|
||||||
|
bin/
|
||||||
# NuGet
|
x64/
|
||||||
packages/
|
|
||||||
*.nupkg
|
|
||||||
*.snupkg
|
|
||||||
|
|
||||||
# Дополнительные временные файлы
|
|
||||||
Thumbs.db
|
|
||||||
*.DS_Store
|
|
||||||
|
|
||||||
# Игнорировать файлы резервирования
|
|
||||||
~$*
|
|
||||||
|
|
||||||
# Опционально: игнорировать файлы конфигурации пользователя
|
|
||||||
appsettings.json
|
|
||||||
*.config.user
|
|
@ -1,21 +1,21 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace DroneClient
|
namespace DroneClient
|
||||||
{
|
{
|
||||||
internal class Drone
|
internal class Drone
|
||||||
{
|
{
|
||||||
public struct DataOut
|
|
||||||
{
|
|
||||||
public float AccX, AccY, AccZ;
|
public float AccX, AccY, AccZ;
|
||||||
public float GyrX, GyrY, GyrZ;
|
public float GyrX, GyrY, GyrZ;
|
||||||
|
public uint TimeAcc, TimeGyr;
|
||||||
|
|
||||||
public float PosX, PosY;
|
public float PosX, PosY;
|
||||||
public float LaserRange;
|
public float LaserRange;
|
||||||
}
|
public uint TimeRange;
|
||||||
|
|
||||||
public struct DataIn
|
|
||||||
{
|
|
||||||
public float MotorUL, MotorUR, MotorDL, MotorDR;
|
public float MotorUL, MotorUR, MotorDL, MotorDR;
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] getBytes(object data)
|
public static byte[] getBytes(object data)
|
||||||
{
|
{
|
||||||
@ -58,5 +58,241 @@ namespace DroneClient
|
|||||||
return mem;
|
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[]? RecvDataAcc(byte[] data)
|
||||||
|
{
|
||||||
|
DroneData.DataAcc imu = (DroneData.DataAcc)fromBytes(data, typeof(DroneData.DataAcc));
|
||||||
|
|
||||||
|
AccX = imu.Acc.X; AccY = imu.Acc.Y; AccZ = imu.Acc.Z;
|
||||||
|
|
||||||
|
TimeAcc= imu.Time;
|
||||||
|
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[]? RecvDataGyr(byte[] data)
|
||||||
|
{
|
||||||
|
DroneData.DataGyr imu = (DroneData.DataGyr)fromBytes(data, typeof(DroneData.DataGyr));
|
||||||
|
|
||||||
|
GyrX = imu.Gyr.X; GyrY = imu.Gyr.Y; GyrZ = imu.Gyr.Z;
|
||||||
|
|
||||||
|
TimeGyr = imu.Time;
|
||||||
|
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[]? RecvDataRange(byte[] data)
|
||||||
|
{
|
||||||
|
DroneData.DataRange pos = (DroneData.DataRange)fromBytes(data, typeof(DroneData.DataRange));
|
||||||
|
|
||||||
|
LaserRange = pos.LiDAR;
|
||||||
|
|
||||||
|
TimeRange = pos.Time;
|
||||||
|
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[]? RecvDataLocal(byte[] data)
|
||||||
|
{
|
||||||
|
DroneData.DataLocal pos = (DroneData.DataLocal)fromBytes(data, typeof(DroneData.DataLocal));
|
||||||
|
|
||||||
|
PosX = pos.Local.X; PosY = pos.Local.Y;
|
||||||
|
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[]? ClientRequestResponse(DroneData.DataHead head, byte[] body)
|
||||||
|
{
|
||||||
|
byte[] zero = new byte[0];
|
||||||
|
|
||||||
|
switch (head.Type)
|
||||||
|
{
|
||||||
|
case DroneData.DataType.DataAcc:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
return RecvDataAcc(body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData.DataType.DataGyr:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
return RecvDataGyr(body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData.DataType.DataRange:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
return RecvDataRange(body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData.DataType.DataLocal:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
return RecvDataLocal(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 acc = new DroneData.DataHead();
|
||||||
|
acc.Size = DroneData.DataHead.StrLen;
|
||||||
|
acc.Mode = DroneData.DataMode.Request;
|
||||||
|
acc.Type = DroneData.DataType.DataAcc;
|
||||||
|
|
||||||
|
DroneData.DataHead gyr = new DroneData.DataHead();
|
||||||
|
gyr.Size = DroneData.DataHead.StrLen;
|
||||||
|
gyr.Mode = DroneData.DataMode.Request;
|
||||||
|
gyr.Type = DroneData.DataType.DataGyr;
|
||||||
|
|
||||||
|
DroneData.DataHead range = new DroneData.DataHead();
|
||||||
|
range.Size = DroneData.DataHead.StrLen;
|
||||||
|
range.Mode = DroneData.DataMode.Request;
|
||||||
|
range.Type = DroneData.DataType.DataRange;
|
||||||
|
|
||||||
|
DroneData.DataHead local = new DroneData.DataHead();
|
||||||
|
local.Size = DroneData.DataHead.StrLen;
|
||||||
|
local.Mode = DroneData.DataMode.Request;
|
||||||
|
local.Type = DroneData.DataType.DataLocal;
|
||||||
|
|
||||||
|
List<byte[]> list = new List<byte[]>();
|
||||||
|
|
||||||
|
list.Add(getBytes(acc));
|
||||||
|
list.Add(getBytes(gyr));
|
||||||
|
list.Add(getBytes(range));
|
||||||
|
list.Add(getBytes(local));
|
||||||
|
list.Add(SendDataMotor4());
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
foreach (byte[] d in list) count += d.Length;
|
||||||
|
|
||||||
|
byte[] send = new byte[count];
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
foreach (byte[] d in list)
|
||||||
|
{
|
||||||
|
d.CopyTo(send, count);
|
||||||
|
count += d.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return send;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
100
DroneClient/DroneData.cs
Normal file
100
DroneClient/DroneData.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
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
|
||||||
|
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005,
|
||||||
|
|
||||||
|
// Input
|
||||||
|
DataMotor4 = 2001, DataMotor6 = 2002
|
||||||
|
};
|
||||||
|
|
||||||
|
public struct DataHead
|
||||||
|
{
|
||||||
|
public int Size;
|
||||||
|
|
||||||
|
public DataMode Mode;
|
||||||
|
public DataType Type;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataHead));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct XYZ { public float X, Y, Z; }
|
||||||
|
|
||||||
|
public struct DataAcc
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Acc;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataAcc));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataGyr
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Gyr;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataGyr));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataMag
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Mag;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataLocal
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Local; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataRange
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float LiDAR; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataRange));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataMotor4
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float UL, UR, DL, DR;
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataMotor6
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float UL, UR, LL, RR, DL, DR;
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor6));
|
||||||
|
}
|
||||||
|
}
|
43
DroneClient/FormMain.Designer.cs
generated
43
DroneClient/FormMain.Designer.cs
generated
@ -65,6 +65,9 @@
|
|||||||
label_Pow = new Label();
|
label_Pow = new Label();
|
||||||
button_ML = new Button();
|
button_ML = new Button();
|
||||||
button_MR = new Button();
|
button_MR = new Button();
|
||||||
|
label_time_acc = new Label();
|
||||||
|
label_time_range = new Label();
|
||||||
|
label_time_gyr = new Label();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Server_Port).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Server_Port).BeginInit();
|
||||||
groupBox2.SuspendLayout();
|
groupBox2.SuspendLayout();
|
||||||
@ -156,6 +159,7 @@
|
|||||||
//
|
//
|
||||||
// groupBox2
|
// groupBox2
|
||||||
//
|
//
|
||||||
|
groupBox2.Controls.Add(label_time_acc);
|
||||||
groupBox2.Controls.Add(label_Acc_Z);
|
groupBox2.Controls.Add(label_Acc_Z);
|
||||||
groupBox2.Controls.Add(label7);
|
groupBox2.Controls.Add(label7);
|
||||||
groupBox2.Controls.Add(label_Acc_Y);
|
groupBox2.Controls.Add(label_Acc_Y);
|
||||||
@ -164,7 +168,7 @@
|
|||||||
groupBox2.Controls.Add(label1);
|
groupBox2.Controls.Add(label1);
|
||||||
groupBox2.Location = new Point(6, 86);
|
groupBox2.Location = new Point(6, 86);
|
||||||
groupBox2.Name = "groupBox2";
|
groupBox2.Name = "groupBox2";
|
||||||
groupBox2.Size = new Size(78, 100);
|
groupBox2.Size = new Size(78, 118);
|
||||||
groupBox2.TabIndex = 5;
|
groupBox2.TabIndex = 5;
|
||||||
groupBox2.TabStop = false;
|
groupBox2.TabStop = false;
|
||||||
groupBox2.Text = "Acc";
|
groupBox2.Text = "Acc";
|
||||||
@ -216,6 +220,7 @@
|
|||||||
//
|
//
|
||||||
// groupBox3
|
// groupBox3
|
||||||
//
|
//
|
||||||
|
groupBox3.Controls.Add(label_time_gyr);
|
||||||
groupBox3.Controls.Add(label_Gyr_Z);
|
groupBox3.Controls.Add(label_Gyr_Z);
|
||||||
groupBox3.Controls.Add(label9);
|
groupBox3.Controls.Add(label9);
|
||||||
groupBox3.Controls.Add(label_Gyr_Y);
|
groupBox3.Controls.Add(label_Gyr_Y);
|
||||||
@ -224,7 +229,7 @@
|
|||||||
groupBox3.Controls.Add(label13);
|
groupBox3.Controls.Add(label13);
|
||||||
groupBox3.Location = new Point(95, 86);
|
groupBox3.Location = new Point(95, 86);
|
||||||
groupBox3.Name = "groupBox3";
|
groupBox3.Name = "groupBox3";
|
||||||
groupBox3.Size = new Size(78, 100);
|
groupBox3.Size = new Size(78, 118);
|
||||||
groupBox3.TabIndex = 6;
|
groupBox3.TabIndex = 6;
|
||||||
groupBox3.TabStop = false;
|
groupBox3.TabStop = false;
|
||||||
groupBox3.Text = "Gyr";
|
groupBox3.Text = "Gyr";
|
||||||
@ -285,6 +290,7 @@
|
|||||||
//
|
//
|
||||||
// groupBox4
|
// groupBox4
|
||||||
//
|
//
|
||||||
|
groupBox4.Controls.Add(label_time_range);
|
||||||
groupBox4.Controls.Add(label_Pos_L);
|
groupBox4.Controls.Add(label_Pos_L);
|
||||||
groupBox4.Controls.Add(label6);
|
groupBox4.Controls.Add(label6);
|
||||||
groupBox4.Controls.Add(label_Pos_Y);
|
groupBox4.Controls.Add(label_Pos_Y);
|
||||||
@ -293,7 +299,7 @@
|
|||||||
groupBox4.Controls.Add(label14);
|
groupBox4.Controls.Add(label14);
|
||||||
groupBox4.Location = new Point(188, 86);
|
groupBox4.Location = new Point(188, 86);
|
||||||
groupBox4.Name = "groupBox4";
|
groupBox4.Name = "groupBox4";
|
||||||
groupBox4.Size = new Size(78, 100);
|
groupBox4.Size = new Size(78, 118);
|
||||||
groupBox4.TabIndex = 7;
|
groupBox4.TabIndex = 7;
|
||||||
groupBox4.TabStop = false;
|
groupBox4.TabStop = false;
|
||||||
groupBox4.Text = "Pos";
|
groupBox4.Text = "Pos";
|
||||||
@ -437,6 +443,33 @@
|
|||||||
button_MR.MouseDown += button_UU_MouseDown;
|
button_MR.MouseDown += button_UU_MouseDown;
|
||||||
button_MR.MouseUp += button_UU_MouseUp;
|
button_MR.MouseUp += button_UU_MouseUp;
|
||||||
//
|
//
|
||||||
|
// label_time_acc
|
||||||
|
//
|
||||||
|
label_time_acc.AutoSize = true;
|
||||||
|
label_time_acc.Location = new Point(6, 100);
|
||||||
|
label_time_acc.Name = "label_time_acc";
|
||||||
|
label_time_acc.Size = new Size(13, 15);
|
||||||
|
label_time_acc.TabIndex = 25;
|
||||||
|
label_time_acc.Text = "0";
|
||||||
|
//
|
||||||
|
// label_time_range
|
||||||
|
//
|
||||||
|
label_time_range.AutoSize = true;
|
||||||
|
label_time_range.Location = new Point(6, 100);
|
||||||
|
label_time_range.Name = "label_time_range";
|
||||||
|
label_time_range.Size = new Size(13, 15);
|
||||||
|
label_time_range.TabIndex = 27;
|
||||||
|
label_time_range.Text = "0";
|
||||||
|
//
|
||||||
|
// label_time_gyr
|
||||||
|
//
|
||||||
|
label_time_gyr.AutoSize = true;
|
||||||
|
label_time_gyr.Location = new Point(3, 100);
|
||||||
|
label_time_gyr.Name = "label_time_gyr";
|
||||||
|
label_time_gyr.Size = new Size(13, 15);
|
||||||
|
label_time_gyr.TabIndex = 26;
|
||||||
|
label_time_gyr.Text = "0";
|
||||||
|
//
|
||||||
// Form_Main
|
// Form_Main
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -509,5 +542,9 @@
|
|||||||
private Label label_Pow;
|
private Label label_Pow;
|
||||||
private Button button_ML;
|
private Button button_ML;
|
||||||
private Button button_MR;
|
private Button button_MR;
|
||||||
|
private Label label4;
|
||||||
|
private Label label_time_acc;
|
||||||
|
private Label label_time_range;
|
||||||
|
private Label label_time_gyr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ namespace DroneSimulator
|
|||||||
ConnectData data = (ConnectData)o;
|
ConnectData data = (ConnectData)o;
|
||||||
|
|
||||||
if (!data.Connect)
|
if (!data.Connect)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Invoke((MethodInvoker)delegate
|
Invoke((MethodInvoker)delegate
|
||||||
{
|
{
|
||||||
@ -27,28 +29,29 @@ namespace DroneSimulator
|
|||||||
button_Connect.BackColor = Color.Transparent;
|
button_Connect.BackColor = Color.Transparent;
|
||||||
MessageBox.Show("Connection closed");
|
MessageBox.Show("Connection closed");
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] send = Drone.getBytes(sendDrone);
|
|
||||||
|
|
||||||
data.Server.Send(send);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Drone.DataIn sendDrone;
|
Drone dataDrone = new Drone();
|
||||||
|
|
||||||
Drone.DataOut recvDrone;
|
|
||||||
|
|
||||||
private void ReceiveCallback(object o)
|
private void ReceiveCallback(object o)
|
||||||
{
|
{
|
||||||
ReceiveData data = (ReceiveData)o;
|
ReceiveData data = (ReceiveData)o;
|
||||||
|
|
||||||
recvDrone = (Drone.DataOut)Drone.fromBytes(data.Buffer, typeof(Drone.DataOut));
|
List<byte[]?>? send = dataDrone.DataStream(data.Buffer, data.Size);
|
||||||
|
|
||||||
byte[] send = Drone.getBytes(sendDrone);
|
if (send == null) return;
|
||||||
|
try
|
||||||
try { data.Server.Send(send); }
|
{
|
||||||
|
foreach (byte[]? b in send)
|
||||||
|
{
|
||||||
|
if (b != null) data.Server?.Send(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,17 +91,25 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
private void timer_Test_Tick(object sender, EventArgs e)
|
private void timer_Test_Tick(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
label_Acc_X.Text = recvDrone.AccX.ToString();
|
label_Acc_X.Text = dataDrone.AccX.ToString();
|
||||||
label_Acc_Y.Text = recvDrone.AccY.ToString();
|
label_Acc_Y.Text = dataDrone.AccY.ToString();
|
||||||
label_Acc_Z.Text = recvDrone.AccZ.ToString();
|
label_Acc_Z.Text = dataDrone.AccZ.ToString();
|
||||||
|
|
||||||
label_Gyr_X.Text = recvDrone.GyrX.ToString();
|
label_time_acc.Text = dataDrone.TimeAcc.ToString();
|
||||||
label_Gyr_Y.Text = recvDrone.GyrY.ToString();
|
|
||||||
label_Gyr_Z.Text = recvDrone.GyrZ.ToString();
|
|
||||||
|
|
||||||
label_Pos_X.Text = recvDrone.PosX.ToString();
|
label_Gyr_X.Text = dataDrone.GyrX.ToString();
|
||||||
label_Pos_Y.Text = recvDrone.PosY.ToString();
|
label_Gyr_Y.Text = dataDrone.GyrY.ToString();
|
||||||
label_Pos_L.Text = recvDrone.LaserRange.ToString();
|
label_Gyr_Z.Text = dataDrone.GyrZ.ToString();
|
||||||
|
|
||||||
|
label_time_gyr.Text = dataDrone.TimeGyr.ToString();
|
||||||
|
|
||||||
|
label_Pos_X.Text = dataDrone.PosX.ToString();
|
||||||
|
label_Pos_Y.Text = dataDrone.PosY.ToString();
|
||||||
|
label_Pos_L.Text = dataDrone.LaserRange.ToString();
|
||||||
|
|
||||||
|
label_time_range.Text = dataDrone.TimeRange.ToString();
|
||||||
|
|
||||||
|
netClient.SendData(dataDrone.SendReqest());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void trackBar_Power_Scroll(object sender, EventArgs e)
|
private void trackBar_Power_Scroll(object sender, EventArgs e)
|
||||||
@ -107,42 +118,44 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
label_Pow.Text = pow.ToString();
|
label_Pow.Text = pow.ToString();
|
||||||
|
|
||||||
sendDrone.MotorUL = sendDrone.MotorUR = sendDrone.MotorDL = sendDrone.MotorDR = pow;
|
dataDrone.MotorUL = dataDrone.MotorUR = dataDrone.MotorDL = dataDrone.MotorDR = pow;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button_UU_MouseDown(object sender, MouseEventArgs e)
|
private void button_UU_MouseDown(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
|
const float pow = 0.1f;
|
||||||
|
|
||||||
if (sender == button_UU)
|
if (sender == button_UU)
|
||||||
{
|
{
|
||||||
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR -= 0.1f;
|
dataDrone.MotorUL -= pow; dataDrone.MotorUR -= pow;
|
||||||
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR += 0.1f;
|
dataDrone.MotorDL += pow; dataDrone.MotorDR += pow;
|
||||||
}
|
}
|
||||||
if (sender == button_DD)
|
if (sender == button_DD)
|
||||||
{
|
{
|
||||||
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR += 0.1f;
|
dataDrone.MotorUL += pow; dataDrone.MotorUR += pow;
|
||||||
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR -= 0.1f;
|
dataDrone.MotorDL -= pow; dataDrone.MotorDR -= pow;
|
||||||
}
|
}
|
||||||
if (sender == button_LL)
|
if (sender == button_LL)
|
||||||
{
|
{
|
||||||
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR += 0.1f;
|
dataDrone.MotorUL -= pow; dataDrone.MotorUR += pow;
|
||||||
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR += 0.1f;
|
dataDrone.MotorDL -= pow; dataDrone.MotorDR += pow;
|
||||||
}
|
}
|
||||||
if (sender == button_RR)
|
if (sender == button_RR)
|
||||||
{
|
{
|
||||||
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR -= 0.1f;
|
dataDrone.MotorUL += pow; dataDrone.MotorUR -= pow;
|
||||||
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR -= 0.1f;
|
dataDrone.MotorDL += pow; dataDrone.MotorDR -= pow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender == button_ML)
|
if (sender == button_ML)
|
||||||
{
|
{
|
||||||
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR += 0.1f;
|
dataDrone.MotorUL -= pow; dataDrone.MotorUR += pow;
|
||||||
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR -= 0.1f;
|
dataDrone.MotorDL += pow; dataDrone.MotorDR -= pow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender == button_MR)
|
if (sender == button_MR)
|
||||||
{
|
{
|
||||||
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR -= 0.1f;
|
dataDrone.MotorUL += pow; dataDrone.MotorUR -= pow;
|
||||||
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR += 0.1f;
|
dataDrone.MotorDL -= pow; dataDrone.MotorDR += pow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using System.Net;
|
using System.Net.Sockets;
|
||||||
using System.Net.Sockets;
|
using System.Net;
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator
|
||||||
{
|
{
|
||||||
@ -41,9 +41,7 @@ namespace DroneSimulator
|
|||||||
{
|
{
|
||||||
if (Connected)
|
if (Connected)
|
||||||
{
|
{
|
||||||
try { ServerSocket?.Shutdown(SocketShutdown.Both); } catch { }
|
Close();
|
||||||
ServerSocket?.Close();
|
|
||||||
Connected = false;
|
|
||||||
return ClientState.Stop;
|
return ClientState.Stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,5 +97,10 @@ namespace DroneSimulator
|
|||||||
try { ServerSocket?.BeginReceive(cd.Buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), cd); }
|
try { ServerSocket?.BeginReceive(cd.Buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), cd); }
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendData(byte[] data)
|
||||||
|
{
|
||||||
|
try { ServerSocket?.Send(data); } catch { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
DroneClient/README.md
Normal file
3
DroneClient/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Client
|
||||||
|
|
||||||
|
Образец клиента для подключения к симулятору.
|
255
DroneClientCpp/Drone.cpp
Normal file
255
DroneClientCpp/Drone.cpp
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<Byte>^ Drone::RecvDataAcc(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
DroneData::DataAcc imu = (DroneData::DataAcc)FromBytes(data, DroneData::DataAcc::typeid);
|
||||||
|
|
||||||
|
AccX = imu.Acc.X; AccY = imu.Acc.Y; AccZ = imu.Acc.Z;
|
||||||
|
TimeAcc = imu.Time;
|
||||||
|
|
||||||
|
return gcnew array<Byte>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<Byte>^ Drone::RecvDataGyr(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
DroneData::DataGyr imu = (DroneData::DataGyr)FromBytes(data, DroneData::DataGyr::typeid);
|
||||||
|
|
||||||
|
GyrX = imu.Gyr.X; GyrY = imu.Gyr.Y; GyrZ = imu.Gyr.Z;
|
||||||
|
TimeGyr = imu.Time;
|
||||||
|
|
||||||
|
return gcnew array<Byte>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<Byte>^ Drone::RecvDataRange(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
DroneData::DataRange pos = (DroneData::DataRange)FromBytes(data, DroneData::DataRange::typeid);
|
||||||
|
|
||||||
|
LaserRange = pos.LiDAR;
|
||||||
|
TimeRange = pos.Time;
|
||||||
|
|
||||||
|
return gcnew array<Byte>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<Byte>^ Drone::RecvDataLocal(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
DroneData::DataLocal pos = (DroneData::DataLocal)FromBytes(data, DroneData::DataLocal::typeid);
|
||||||
|
|
||||||
|
PosX = pos.Local.X; PosY = pos.Local.Y;
|
||||||
|
|
||||||
|
return gcnew array<Byte>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
array<Byte>^ Drone::ClientRequestResponse(DroneData::DataHead head, array<Byte>^ body)
|
||||||
|
{
|
||||||
|
array<Byte>^ zero = gcnew array<Byte>(0);
|
||||||
|
|
||||||
|
switch (head.Type)
|
||||||
|
{
|
||||||
|
case DroneData::DataType::DataAcc:
|
||||||
|
if (head.Mode == DroneData::DataMode::Request)
|
||||||
|
{
|
||||||
|
return zero; // Запрос данных (не реализовано)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecvDataAcc(body); // Пришли данные
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData::DataType::DataGyr:
|
||||||
|
if (head.Mode == DroneData::DataMode::Request)
|
||||||
|
{
|
||||||
|
return zero; // Запрос данных (не реализовано)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecvDataGyr(body); // Пришли данные
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData::DataType::DataRange:
|
||||||
|
if (head.Mode == DroneData::DataMode::Request)
|
||||||
|
{
|
||||||
|
return zero; // Запрос данных (не реализовано)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecvDataRange(body); // Пришли данные
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData::DataType::DataLocal:
|
||||||
|
if (head.Mode == DroneData::DataMode::Request)
|
||||||
|
{
|
||||||
|
return zero; // Запрос данных (не реализовано)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecvDataLocal(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
|
||||||
|
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^ acc = gcnew DroneData::DataHead();
|
||||||
|
acc->Size = DroneData::DataHead::StrLen;
|
||||||
|
acc->Mode = DroneData::DataMode::Request;
|
||||||
|
acc->Type = DroneData::DataType::DataAcc;
|
||||||
|
|
||||||
|
DroneData::DataHead^ gyr = gcnew DroneData::DataHead();
|
||||||
|
gyr->Size = DroneData::DataHead::StrLen;
|
||||||
|
gyr->Mode = DroneData::DataMode::Request;
|
||||||
|
gyr->Type = DroneData::DataType::DataGyr;
|
||||||
|
|
||||||
|
DroneData::DataHead^ range = gcnew DroneData::DataHead();
|
||||||
|
range->Size = DroneData::DataHead::StrLen;
|
||||||
|
range->Mode = DroneData::DataMode::Request;
|
||||||
|
range->Type = DroneData::DataType::DataRange;
|
||||||
|
|
||||||
|
DroneData::DataHead^ local = gcnew DroneData::DataHead();
|
||||||
|
local->Size = DroneData::DataHead::StrLen;
|
||||||
|
local->Mode = DroneData::DataMode::Request;
|
||||||
|
local->Type = DroneData::DataType::DataLocal;
|
||||||
|
|
||||||
|
List<array<byte>^>^ list = gcnew List<array<byte>^>();
|
||||||
|
|
||||||
|
list->Add(GetBytes(acc));
|
||||||
|
list->Add(GetBytes(gyr));
|
||||||
|
list->Add(GetBytes(range));
|
||||||
|
list->Add(GetBytes(local));
|
||||||
|
list->Add(SendDataMotor4());
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for each(array<byte>^ d in list) count += d->Length;
|
||||||
|
|
||||||
|
array<byte>^ send = gcnew array<byte>(count);
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for each (array<byte> ^ d in list)
|
||||||
|
{
|
||||||
|
d->CopyTo(send, count);
|
||||||
|
count += d->Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return send;
|
||||||
|
}
|
||||||
|
}
|
51
DroneClientCpp/Drone.h
Normal file
51
DroneClientCpp/Drone.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#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;
|
||||||
|
unsigned int TimeAcc, TimeGyr;
|
||||||
|
|
||||||
|
float PosX, PosY;
|
||||||
|
float LaserRange;
|
||||||
|
unsigned int TimeRange;
|
||||||
|
|
||||||
|
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>^ RecvDataAcc(array<Byte>^ data);
|
||||||
|
array<Byte>^ RecvDataGyr(array<Byte>^ data);
|
||||||
|
array<Byte>^ RecvDataRange(array<Byte>^ data);
|
||||||
|
array<Byte>^ RecvDataLocal(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();
|
||||||
|
};
|
||||||
|
}
|
@ -5,8 +5,6 @@ VisualStudioVersion = 17.12.35527.113
|
|||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DroneClientCpp", "DroneClientCpp.vcxproj", "{690C304C-A70B-4B0F-BF61-8C51290BF444}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DroneClientCpp", "DroneClientCpp.vcxproj", "{690C304C-A70B-4B0F-BF61-8C51290BF444}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestClientConnection", "..\TestClientConnection\TestClientConnection.vcxproj", "{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
@ -23,14 +21,6 @@ Global
|
|||||||
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x64.Build.0 = 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.ActiveCfg = Release|Win32
|
||||||
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x86.Build.0 = Release|Win32
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x86.Build.0 = Release|Win32
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Debug|x86.ActiveCfg = Debug|Win32
|
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Debug|x86.Build.0 = Debug|Win32
|
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Release|x64.Build.0 = Release|x64
|
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Release|x86.ActiveCfg = Release|Win32
|
|
||||||
{B7CC5245-B628-40E9-A9A0-A904E2BF25EA}.Release|x86.Build.0 = Release|Win32
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -118,10 +118,13 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Drone.cpp" />
|
||||||
<ClCompile Include="FormMain.cpp" />
|
<ClCompile Include="FormMain.cpp" />
|
||||||
|
<ClCompile Include="NetClient.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="DroneClient.h" />
|
<ClInclude Include="Drone.h" />
|
||||||
|
<ClInclude Include="DroneData.h" />
|
||||||
<ClInclude Include="FormMain.h">
|
<ClInclude Include="FormMain.h">
|
||||||
<FileType>CppForm</FileType>
|
<FileType>CppForm</FileType>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -18,6 +18,12 @@
|
|||||||
<ClCompile Include="FormMain.cpp">
|
<ClCompile Include="FormMain.cpp">
|
||||||
<Filter>Исходные файлы</Filter>
|
<Filter>Исходные файлы</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="NetClient.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Drone.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="FormMain.h">
|
<ClInclude Include="FormMain.h">
|
||||||
@ -26,7 +32,10 @@
|
|||||||
<ClInclude Include="NetClient.h">
|
<ClInclude Include="NetClient.h">
|
||||||
<Filter>Файлы заголовков</Filter>
|
<Filter>Файлы заголовков</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="DroneClient.h">
|
<ClInclude Include="DroneData.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Drone.h">
|
||||||
<Filter>Файлы заголовков</Filter>
|
<Filter>Файлы заголовков</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
4
DroneClientCpp/DroneClientCpp.vcxproj.user
Normal file
4
DroneClientCpp/DroneClientCpp.vcxproj.user
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
</Project>
|
117
DroneClientCpp/DroneData.h
Normal file
117
DroneClientCpp/DroneData.h
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#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,
|
||||||
|
|
||||||
|
// Output
|
||||||
|
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005,
|
||||||
|
|
||||||
|
// Input
|
||||||
|
DataMotor4 = 2001, DataMotor6 = 2002
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataHead
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
long Size;
|
||||||
|
DataMode Mode;
|
||||||
|
DataType Type;
|
||||||
|
|
||||||
|
unsigned long Time;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataHead);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct XYZ
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
float X, Y, Z;
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataAcc
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
XYZ Acc;
|
||||||
|
|
||||||
|
unsigned long Time;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataAcc);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataGyr
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
XYZ Gyr;
|
||||||
|
|
||||||
|
unsigned long Time;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataGyr);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataMag
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
XYZ Mag;
|
||||||
|
|
||||||
|
unsigned long Time;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataMag);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataRange
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
float LiDAR;
|
||||||
|
|
||||||
|
unsigned long Time;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataRange);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataLocal
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
XYZ Local;
|
||||||
|
|
||||||
|
unsigned long Time;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataLocal);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataMotor4
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
float UL, UR, DL, DR;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataMotor4);
|
||||||
|
};
|
||||||
|
|
||||||
|
public value struct DataMotor6
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DataHead Head;
|
||||||
|
float UL, UR, LL, RR, DL, DR;
|
||||||
|
|
||||||
|
static const int StrLen = sizeof(DataMotor6);
|
||||||
|
};
|
||||||
|
}
|
Binary file not shown.
105
DroneClientCpp/NetClient.cpp
Normal file
105
DroneClientCpp/NetClient.cpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#include "NetClient.h"
|
||||||
|
|
||||||
|
namespace DroneSimulator {
|
||||||
|
|
||||||
|
// Конструктор ConnectData
|
||||||
|
NetClient::ConnectData::ConnectData(bool connect, Socket^ server)
|
||||||
|
{
|
||||||
|
Connect = connect;
|
||||||
|
Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конструктор ReceiveData
|
||||||
|
NetClient::ReceiveData::ReceiveData(array<Byte>^ buffer, int size, Socket^ server)
|
||||||
|
{
|
||||||
|
Buffer = buffer;
|
||||||
|
Size = size;
|
||||||
|
Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конструктор NetClient
|
||||||
|
NetClient::NetClient()
|
||||||
|
{
|
||||||
|
Connected = false;
|
||||||
|
ServerSocket = nullptr;
|
||||||
|
DataServer = gcnew ServerData(); // Инициализация DataServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода Connect
|
||||||
|
NetClient::ClientState NetClient::Connect(String^ Addr, int Port, ClientCallback^ Connection, ClientCallback^ Receive)
|
||||||
|
{
|
||||||
|
if (Connected)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
return ClientState::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionCallback = Connection;
|
||||||
|
ReceiveCallback = Receive;
|
||||||
|
|
||||||
|
IPEndPoint^ ep = gcnew IPEndPoint(IPAddress::Parse(Addr), Port);
|
||||||
|
ServerSocket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);
|
||||||
|
|
||||||
|
try { if (ServerSocket) 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 { if (ServerSocket) ServerSocket->BeginReceive(DataServer->buffer, 0, ServerData::size, SocketFlags::None, gcnew AsyncCallback(this, &NetClient::ReadCallback), receiveData); }
|
||||||
|
catch (...) {}
|
||||||
|
|
||||||
|
return ClientState::Connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода Close
|
||||||
|
void NetClient::Close()
|
||||||
|
{
|
||||||
|
try { if(ServerSocket) ServerSocket->Shutdown(SocketShutdown::Both); }
|
||||||
|
catch (...) {}
|
||||||
|
if(ServerSocket) ServerSocket->Close();
|
||||||
|
Connected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода Send
|
||||||
|
void NetClient::Send(array<Byte>^ data)
|
||||||
|
{
|
||||||
|
if (ServerSocket != nullptr && Connected)
|
||||||
|
{
|
||||||
|
try { if (ServerSocket) 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)
|
||||||
|
{
|
||||||
|
if (ServerSocket) ServerSocket->Close();
|
||||||
|
Connected = false;
|
||||||
|
|
||||||
|
if (ServerSocket != nullptr)
|
||||||
|
{
|
||||||
|
ConnectionCallback(gcnew ConnectData(false, nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReceiveCallback(gcnew ReceiveData(cd->Buffer, bytes, ServerSocket));
|
||||||
|
|
||||||
|
try { if (ServerSocket) ServerSocket->BeginReceive(cd->Buffer, 0, ServerData::size, SocketFlags::None, gcnew AsyncCallback(this, &NetClient::ReadCallback), cd); }
|
||||||
|
catch (...) {}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
// NetClient.h
|
#pragma once
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <vcclr.h>
|
#include <vcclr.h>
|
||||||
@ -10,247 +9,60 @@
|
|||||||
using namespace System;
|
using namespace System;
|
||||||
using namespace System::Net;
|
using namespace System::Net;
|
||||||
using namespace System::Net::Sockets;
|
using namespace System::Net::Sockets;
|
||||||
using namespace System::Runtime::InteropServices;
|
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator {
|
||||||
{
|
|
||||||
public ref class NetClient
|
public ref class NetClient
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Вложенный класс для данных подключения
|
|
||||||
ref class ConnectData
|
ref class ConnectData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
property bool Connect;
|
bool Connect;
|
||||||
property Socket^ Server;
|
Socket^ Server;
|
||||||
|
|
||||||
|
ConnectData(bool connect, Socket^ server);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Вложенный класс для данных приема
|
|
||||||
ref class ReceiveData
|
ref class ReceiveData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
property array<Byte>^ Buffer;
|
array<Byte>^ Buffer;
|
||||||
property int Size;
|
int Size;
|
||||||
property Socket^ Server;
|
Socket^ Server;
|
||||||
|
|
||||||
|
ReceiveData(array<Byte>^ buffer, int size, Socket^ server);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Состояния клиента
|
|
||||||
enum class ClientState { Error, Connected, Stop };
|
|
||||||
|
|
||||||
// Делегат для callback-функций
|
|
||||||
delegate void ClientCallback(Object^ o);
|
|
||||||
|
|
||||||
NetClient()
|
|
||||||
{
|
|
||||||
Connected = false;
|
|
||||||
ServerSocket = nullptr;
|
|
||||||
DataServer = gcnew ServerData();
|
|
||||||
}
|
|
||||||
|
|
||||||
~NetClient()
|
|
||||||
{
|
|
||||||
// Вызываем Close() для корректного закрытия соединения
|
|
||||||
Close();
|
|
||||||
|
|
||||||
// Дополнительная очистка ресурсов
|
|
||||||
if (DataServer != nullptr)
|
|
||||||
{
|
|
||||||
// Очищаем буфер данных
|
|
||||||
DataServer->buffer = nullptr;
|
|
||||||
DataServer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Обнуляем callback-делегаты
|
|
||||||
ConnectionCallback = nullptr;
|
|
||||||
ReceiveCallback = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClientState Connect(String^ addr, int port, ClientCallback^ connectionCallback, ClientCallback^ receiveCallback)
|
|
||||||
{
|
|
||||||
if (Connected)
|
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
return ClientState::Stop;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionCallback = connectionCallback;
|
|
||||||
ReceiveCallback = receiveCallback;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IPEndPoint^ ep = gcnew IPEndPoint(IPAddress::Parse(addr), port);
|
|
||||||
ServerSocket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);
|
|
||||||
ServerSocket->Connect(ep);
|
|
||||||
|
|
||||||
Connected = true;
|
|
||||||
|
|
||||||
// Уведомление о подключении
|
|
||||||
ConnectData^ connectData = gcnew ConnectData();
|
|
||||||
connectData->Connect = true;
|
|
||||||
connectData->Server = ServerSocket;
|
|
||||||
ConnectionCallback(connectData);
|
|
||||||
|
|
||||||
// Начало приема данных
|
|
||||||
ReceiveData^ receiveData = gcnew ReceiveData();
|
|
||||||
receiveData->Buffer = DataServer->buffer;
|
|
||||||
receiveData->Size = ServerData::size;
|
|
||||||
receiveData->Server = ServerSocket;
|
|
||||||
|
|
||||||
ServerSocket->BeginReceive(DataServer->buffer, 0, ServerData::size, SocketFlags::None, gcnew AsyncCallback(this, &NetClient::ReadCallback), receiveData);
|
|
||||||
|
|
||||||
return ClientState::Connected;
|
|
||||||
}
|
|
||||||
catch (Exception^)
|
|
||||||
{
|
|
||||||
if (ServerSocket != nullptr)
|
|
||||||
{
|
|
||||||
ServerSocket->Close();
|
|
||||||
}
|
|
||||||
return ClientState::Error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Close()
|
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ref class ServerData
|
ref class ServerData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const int size = 1024;
|
literal int size = 1024;
|
||||||
array<Byte>^ buffer = gcnew array<Byte>(size);
|
array<Byte>^ buffer = gcnew array<Byte>(size);
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Connected;
|
bool Connected;
|
||||||
Socket^ ServerSocket;
|
Socket^ ServerSocket;
|
||||||
ServerData^ DataServer;
|
ServerData^ DataServer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
delegate void ClientCallback(Object^ o);
|
||||||
|
|
||||||
|
private:
|
||||||
ClientCallback^ ConnectionCallback;
|
ClientCallback^ ConnectionCallback;
|
||||||
ClientCallback^ ReceiveCallback;
|
ClientCallback^ ReceiveCallback;
|
||||||
|
|
||||||
void Disconnect()
|
public:
|
||||||
{
|
NetClient(); // Добавлен конструктор
|
||||||
if (ServerSocket != nullptr)
|
|
||||||
{
|
|
||||||
try { ServerSocket->Shutdown(SocketShutdown::Both); }
|
|
||||||
catch (...) {}
|
|
||||||
ServerSocket->Close();
|
|
||||||
ServerSocket = nullptr;
|
|
||||||
}
|
|
||||||
Connected = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReadCallback(IAsyncResult^ ar)
|
enum class ClientState { Error, Connected, Stop };
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Проверка на null входного параметра
|
|
||||||
if (ar == nullptr) return;
|
|
||||||
|
|
||||||
// Безопасное приведение типа
|
ClientState Connect(String^ Addr, int Port, ClientCallback^ Connection, ClientCallback^ Receive);
|
||||||
ReceiveData^ cd = dynamic_cast<ReceiveData^>(ar->AsyncState);
|
void Close();
|
||||||
if (cd == nullptr || ServerSocket == nullptr || !ServerSocket->Connected)
|
void Send(array<Byte>^ data);
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bytes = 0;
|
private:
|
||||||
try
|
void ReadCallback(IAsyncResult^ ar);
|
||||||
{
|
|
||||||
bytes = ServerSocket->EndReceive(ar);
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException^)
|
|
||||||
{
|
|
||||||
// Сокет был закрыт
|
|
||||||
Disconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (SocketException^ ex)
|
|
||||||
{
|
|
||||||
// Логирование ошибки сокета
|
|
||||||
System::Diagnostics::Debug::WriteLine(
|
|
||||||
"Socket receive error: " + ex->Message);
|
|
||||||
Disconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверка на разрыв соединения
|
|
||||||
if (bytes == 0)
|
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
|
|
||||||
if (ConnectionCallback != nullptr)
|
|
||||||
{
|
|
||||||
ConnectData^ disconnectData = gcnew ConnectData();
|
|
||||||
disconnectData->Connect = false;
|
|
||||||
disconnectData->Server = nullptr;
|
|
||||||
ConnectionCallback(disconnectData);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Вызов callback получения данных
|
|
||||||
if (ReceiveCallback != nullptr && cd->Buffer != nullptr)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ReceiveCallback(cd);
|
|
||||||
}
|
|
||||||
catch (Exception^ ex)
|
|
||||||
{
|
|
||||||
System::Diagnostics::Debug::WriteLine(
|
|
||||||
"ReceiveCallback error: " + ex->Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Продолжаем прием данных
|
|
||||||
if (ServerSocket != nullptr && ServerSocket->Connected)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IAsyncResult^ result = ServerSocket->BeginReceive(
|
|
||||||
cd->Buffer,
|
|
||||||
0,
|
|
||||||
ServerData::size,
|
|
||||||
SocketFlags::None,
|
|
||||||
gcnew AsyncCallback(this, &NetClient::ReadCallback),
|
|
||||||
cd);
|
|
||||||
|
|
||||||
// Проверка на ошибку асинхронной операции
|
|
||||||
if (result == nullptr)
|
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException^)
|
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
}
|
|
||||||
catch (SocketException^ ex)
|
|
||||||
{
|
|
||||||
System::Diagnostics::Debug::WriteLine(
|
|
||||||
"BeginReceive error: " + ex->Message);
|
|
||||||
Disconnect();
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
Disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception^ ex)
|
|
||||||
{
|
|
||||||
System::Diagnostics::Debug::WriteLine(
|
|
||||||
"ReadCallback general error: " + ex->Message);
|
|
||||||
Disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
using System.Numerics;
|
using System.CodeDom;
|
||||||
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator
|
||||||
{
|
{
|
||||||
@ -9,15 +11,19 @@ namespace DroneSimulator
|
|||||||
public float Mass; // Масса
|
public float Mass; // Масса
|
||||||
public bool Active; // Живой?
|
public bool Active; // Живой?
|
||||||
public float Length; // Длинна лучей
|
public float Length; // Длинна лучей
|
||||||
|
public const float Dynamic = 10; // Динамика вращения
|
||||||
public Vector3 PosXYZ, SpdXYZ, AccXYZ; // Положение в пространстве: Позиция, Скорость, Ускорение
|
public Vector3 PosXYZ, SpdXYZ, AccXYZ; // Положение в пространстве: Позиция, Скорость, Ускорение
|
||||||
public Quaternion Quat; // Основной кватернион
|
public Quaternion Quat; // Основной кватернион
|
||||||
public float Power = 0; // Тяга всех двигателей
|
public float Power = 0; // Тяга всех двигателей (0-1)
|
||||||
|
public float MaxPower; // Максимальная Тяга всех двигателей (КГ)
|
||||||
public Vector3 SpdPRY, AccPRY; // Поворот в пространстве: pitch roll yaw
|
public Vector3 SpdPRY, AccPRY; // Поворот в пространстве: pitch roll yaw
|
||||||
|
|
||||||
public Vector3 Acc, Gyr; // Имитация: Акселерометр, Гироскоп
|
public Vector3 Acc, Gyr; // Имитация: Акселерометр, Гироскоп
|
||||||
public float LaserRange; // Имитация: Дальномер
|
public float LaserRange; // Имитация: Дальномер
|
||||||
|
|
||||||
private const float Gravity = 1.0f;
|
private uint DataTimer;
|
||||||
|
|
||||||
|
private const float Gravity = 9.8f;
|
||||||
|
|
||||||
private const float TO_GRAD = 180 / MathF.PI;
|
private const float TO_GRAD = 180 / MathF.PI;
|
||||||
private const float TO_RADI = MathF.PI / 180;
|
private const float TO_RADI = MathF.PI / 180;
|
||||||
@ -27,25 +33,16 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
private static int CounterID = 0;
|
private static int CounterID = 0;
|
||||||
|
|
||||||
|
public static byte[] getBytes(object data)
|
||||||
|
|
||||||
public struct DataOut
|
|
||||||
{
|
{
|
||||||
public float AccX, AccY, AccZ;
|
int size = Marshal.SizeOf(data);
|
||||||
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];
|
byte[] arr = new byte[size];
|
||||||
|
|
||||||
IntPtr ptr = IntPtr.Zero;
|
IntPtr ptr = IntPtr.Zero;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ptr = Marshal.AllocHGlobal(size);
|
ptr = Marshal.AllocHGlobal(size);
|
||||||
Marshal.StructureToPtr(this, ptr, true);
|
Marshal.StructureToPtr(data, ptr, true);
|
||||||
Marshal.Copy(ptr, arr, 0, size);
|
Marshal.Copy(ptr, arr, 0, size);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@ -54,17 +51,12 @@ namespace DroneSimulator
|
|||||||
}
|
}
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public struct DataIn
|
public static object fromBytes(byte[] arr, Type type)
|
||||||
{
|
{
|
||||||
public float MotorUL, MotorUR, MotorDL, MotorDR;
|
object mem = new object();
|
||||||
|
|
||||||
public void fromBytes(byte[] arr)
|
int size = Marshal.SizeOf(type);
|
||||||
{
|
|
||||||
DataIn mem = new DataIn();
|
|
||||||
|
|
||||||
int size = Marshal.SizeOf(mem);
|
|
||||||
IntPtr ptr = IntPtr.Zero;
|
IntPtr ptr = IntPtr.Zero;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -72,24 +64,33 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
Marshal.Copy(arr, 0, ptr, size);
|
Marshal.Copy(arr, 0, ptr, size);
|
||||||
|
|
||||||
mem = (DataIn)Marshal.PtrToStructure(ptr, mem.GetType());
|
mem = Marshal.PtrToStructure(ptr, type);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Marshal.FreeHGlobal(ptr);
|
Marshal.FreeHGlobal(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
this = mem;
|
return mem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
private void ThreadFunction()
|
||||||
{
|
{
|
||||||
while (DroneThread != null)
|
while (DroneThread != null)
|
||||||
{
|
{
|
||||||
float time = Environment.TickCount - Timer;
|
Action(Environment.TickCount);
|
||||||
Timer = Environment.TickCount;
|
|
||||||
Action(time / 100);
|
|
||||||
Thread.Sleep(1);
|
Thread.Sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,7 +99,7 @@ namespace DroneSimulator
|
|||||||
{
|
{
|
||||||
ID = id;
|
ID = id;
|
||||||
Active = false;
|
Active = false;
|
||||||
PosXYZ = new Vector3(2000, 1000, 0);
|
PosXYZ = Vector3.Zero;
|
||||||
SpdXYZ = Vector3.Zero;
|
SpdXYZ = Vector3.Zero;
|
||||||
AccXYZ = Vector3.Zero;
|
AccXYZ = Vector3.Zero;
|
||||||
Quat = Quaternion.Identity;
|
Quat = Quaternion.Identity;
|
||||||
@ -108,10 +109,11 @@ namespace DroneSimulator
|
|||||||
DroneThread.Start();
|
DroneThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Create(float mass, float len)
|
public int Create(float power, float mass, float len)
|
||||||
{
|
{
|
||||||
Mass = Range(mass);
|
Mass = mass;
|
||||||
Length = len;
|
Length = len;
|
||||||
|
MaxPower = power;
|
||||||
|
|
||||||
Active = true;
|
Active = true;
|
||||||
|
|
||||||
@ -164,25 +166,30 @@ namespace DroneSimulator
|
|||||||
return new Vector4(GetAngle(grav.Y, grav.X, grav.Z), GetAngle(-grav.X, grav.Y, grav.Z), yaw, grav.Z);
|
return new Vector4(GetAngle(grav.Y, grav.X, grav.Z), GetAngle(-grav.X, grav.Y, grav.Z), yaw, grav.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Action(float time)
|
public void Action(int tick)
|
||||||
{
|
{
|
||||||
|
float time = (tick - Timer) / 1000.0f;
|
||||||
|
Timer = tick;
|
||||||
|
|
||||||
if (!Active) return;
|
if (!Active) return;
|
||||||
|
|
||||||
float flow = Power;
|
float flow = Power;
|
||||||
|
|
||||||
if (PosXYZ.Z < 100)
|
if (PosXYZ.Z < 0.3f)
|
||||||
{
|
{
|
||||||
flow += flow * 0.1f; // Воздушная подушка
|
flow += flow * 0.1f; // Воздушная подушка
|
||||||
}
|
}
|
||||||
|
|
||||||
Quaternion pow = Quaternion.Inverse(Quat) * new Quaternion(0, 0, flow, 0) * Quat;
|
SpdPRY += AccPRY * (Dynamic * time / (Mass * Length));
|
||||||
AccXYZ = new Vector3(pow.X, pow.Y, pow.Z) / Mass;
|
|
||||||
|
|
||||||
SpdPRY += AccPRY * 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);
|
||||||
|
|
||||||
SpdXYZ += (AccXYZ + new Vector3(0, 0, -Gravity)) * time;
|
SpdXYZ += (AccXYZ + new Vector3(0, 0, -Gravity)) * time;
|
||||||
PosXYZ += SpdXYZ * time;
|
PosXYZ += SpdXYZ * time;
|
||||||
|
|
||||||
|
AccXYZ /= Gravity; // Вернуть измерения в G
|
||||||
|
|
||||||
if (PosXYZ.Z < 0)
|
if (PosXYZ.Z < 0)
|
||||||
{
|
{
|
||||||
SpdPRY = Vector3.Zero;
|
SpdPRY = Vector3.Zero;
|
||||||
@ -190,7 +197,7 @@ namespace DroneSimulator
|
|||||||
SpdXYZ.Y = 0;
|
SpdXYZ.Y = 0;
|
||||||
Quat = Quaternion.Identity;
|
Quat = Quaternion.Identity;
|
||||||
}
|
}
|
||||||
else Rotate(SpdPRY.X, SpdPRY.Y, SpdPRY.Z);
|
else Rotate(SpdPRY.X * time, SpdPRY.Y * time, SpdPRY.Z * time);
|
||||||
|
|
||||||
Vector4 ori = GetOrientation();
|
Vector4 ori = GetOrientation();
|
||||||
|
|
||||||
@ -203,7 +210,7 @@ namespace DroneSimulator
|
|||||||
Active = false; // Сильно ударился о землю
|
Active = false; // Сильно ударился о землю
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
/*if (MathF.Abs(ori.X) > 45 || MathF.Abs(ori.Y) > 45)
|
/*if (MathF.Abs(ori.X) > 20 || MathF.Abs(ori.Y) > 20)
|
||||||
{
|
{
|
||||||
Active = false; // Повредил винты при посадке
|
Active = false; // Повредил винты при посадке
|
||||||
}*/
|
}*/
|
||||||
@ -216,13 +223,13 @@ namespace DroneSimulator
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*if (ori.W < 0)
|
if (ori.W < 0)
|
||||||
{
|
{
|
||||||
Active = false; // Перевернулся вверх ногами
|
//Active = false; // Перевернулся вверх ногами
|
||||||
}*/
|
}
|
||||||
|
|
||||||
Quaternion grav = new Quaternion(AccXYZ.X, AccXYZ.Y, AccXYZ.Z, 0);
|
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);
|
Acc = new Vector3(grav.X, grav.Y, grav.Z);
|
||||||
|
|
||||||
Gyr = SpdPRY;
|
Gyr = SpdPRY;
|
||||||
@ -232,6 +239,8 @@ namespace DroneSimulator
|
|||||||
if (tilt < 90 && ori.W > 0) LaserRange = PosXYZ.Z / MathF.Cos(tilt);
|
if (tilt < 90 && ori.W > 0) LaserRange = PosXYZ.Z / MathF.Cos(tilt);
|
||||||
else LaserRange = float.MaxValue;
|
else LaserRange = float.MaxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DataTimer = (uint)tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float Range(float pow)
|
private float Range(float pow)
|
||||||
@ -239,7 +248,7 @@ namespace DroneSimulator
|
|||||||
if (pow > 1) pow = 1;
|
if (pow > 1) pow = 1;
|
||||||
if (pow < 0) pow = 0;
|
if (pow < 0) pow = 0;
|
||||||
|
|
||||||
return pow;
|
return pow * MaxPower;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetQadroPow(float ul, float ur, float dl, float dr)
|
public void SetQadroPow(float ul, float ur, float dl, float dr)
|
||||||
@ -252,5 +261,237 @@ namespace DroneSimulator
|
|||||||
AccPRY.X = ((ul + ur) - (dl + dr));
|
AccPRY.X = ((ul + ur) - (dl + dr));
|
||||||
AccPRY.Z = ((ul + dr) - (dl + ur)) / 4;
|
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[] SendDataAcc()
|
||||||
|
{
|
||||||
|
DroneData.DataAcc acc = new DroneData.DataAcc();
|
||||||
|
|
||||||
|
acc.Head.Size = Marshal.SizeOf(typeof(DroneData.DataAcc));
|
||||||
|
acc.Head.Mode = DroneData.DataMode.Response;
|
||||||
|
acc.Head.Type = DroneData.DataType.DataAcc;
|
||||||
|
acc.Head.Time = (uint)Environment.TickCount;
|
||||||
|
|
||||||
|
acc.Acc.X = Acc.X; acc.Acc.Y = Acc.Y; acc.Acc.Z = Acc.Z;
|
||||||
|
acc.Time = DataTimer;
|
||||||
|
|
||||||
|
return getBytes(acc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] SendDataGyr()
|
||||||
|
{
|
||||||
|
DroneData.DataGyr gyr = new DroneData.DataGyr();
|
||||||
|
|
||||||
|
gyr.Head.Size = Marshal.SizeOf(typeof(DroneData.DataGyr));
|
||||||
|
gyr.Head.Mode = DroneData.DataMode.Response;
|
||||||
|
gyr.Head.Type = DroneData.DataType.DataGyr;
|
||||||
|
gyr.Head.Time = (uint)Environment.TickCount;
|
||||||
|
|
||||||
|
gyr.Gyr.X = Gyr.X; gyr.Gyr.Y = Gyr.Y; gyr.Gyr.Z = Gyr.Z;
|
||||||
|
gyr.Time = DataTimer;
|
||||||
|
|
||||||
|
return getBytes(gyr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] SendDataMag()
|
||||||
|
{
|
||||||
|
DroneData.DataMag mag = new DroneData.DataMag();
|
||||||
|
|
||||||
|
mag.Head.Size = Marshal.SizeOf(typeof(DroneData.DataMag));
|
||||||
|
mag.Head.Mode = DroneData.DataMode.Response;
|
||||||
|
mag.Head.Type = DroneData.DataType.DataMag;
|
||||||
|
mag.Head.Time = (uint)Environment.TickCount;
|
||||||
|
|
||||||
|
mag.Mag.X = 0; mag.Mag.Y = 0; mag.Mag.Z = 0;
|
||||||
|
mag.Time = DataTimer;
|
||||||
|
|
||||||
|
return getBytes(mag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] SendDataRange()
|
||||||
|
{
|
||||||
|
DroneData.DataRange range = new DroneData.DataRange();
|
||||||
|
|
||||||
|
range.Head.Size = Marshal.SizeOf(typeof(DroneData.DataRange));
|
||||||
|
range.Head.Mode = DroneData.DataMode.Response;
|
||||||
|
range.Head.Type = DroneData.DataType.DataRange;
|
||||||
|
range.Head.Time = (uint)Environment.TickCount;
|
||||||
|
|
||||||
|
range.LiDAR = LaserRange;
|
||||||
|
range.Time = DataTimer;
|
||||||
|
|
||||||
|
return getBytes(range);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] SendDataLocal()
|
||||||
|
{
|
||||||
|
DroneData.DataLocal local = new DroneData.DataLocal();
|
||||||
|
|
||||||
|
local.Head.Size = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
||||||
|
local.Head.Mode = DroneData.DataMode.Response;
|
||||||
|
local.Head.Type = DroneData.DataType.DataLocal;
|
||||||
|
local.Head.Time = (uint)Environment.TickCount;
|
||||||
|
|
||||||
|
local.Local.X = PosXYZ.X; local.Local.Y = PosXYZ.Y; local.Local.Z = PosXYZ.Z;
|
||||||
|
local.Time = DataTimer;
|
||||||
|
|
||||||
|
return getBytes(local);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[]? ServerRequestResponse(DroneData.DataHead head, byte[] body)
|
||||||
|
{
|
||||||
|
byte[] zero = new byte[0];
|
||||||
|
|
||||||
|
switch (head.Type)
|
||||||
|
{
|
||||||
|
case DroneData.DataType.DataAcc:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
return SendDataAcc();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData.DataType.DataGyr:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
return SendDataGyr();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData.DataType.DataMag:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
return SendDataMag();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData.DataType.DataRange:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
return SendDataRange();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case DroneData.DataType.DataLocal:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
return SendDataLocal();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
100
DroneSimulator/DroneData.cs
Normal file
100
DroneSimulator/DroneData.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
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
|
||||||
|
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005,
|
||||||
|
|
||||||
|
// Input
|
||||||
|
DataMotor4 = 2001, DataMotor6 = 2002
|
||||||
|
};
|
||||||
|
|
||||||
|
public struct DataHead
|
||||||
|
{
|
||||||
|
public int Size;
|
||||||
|
|
||||||
|
public DataMode Mode;
|
||||||
|
public DataType Type;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataHead));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct XYZ { public float X, Y, Z; }
|
||||||
|
|
||||||
|
public struct DataAcc
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Acc;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataAcc));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataGyr
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Gyr;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataGyr));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataMag
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Mag;
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataLocal
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Local; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataRange
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float LiDAR; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataRange));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataMotor4
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float UL, UR, DL, DR;
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataMotor6
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float UL, UR, LL, RR, DL, DR;
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMotor6));
|
||||||
|
}
|
||||||
|
}
|
481
DroneSimulator/FormMain.Designer.cs
generated
481
DroneSimulator/FormMain.Designer.cs
generated
@ -38,6 +38,10 @@
|
|||||||
tabControl_Menu = new TabControl();
|
tabControl_Menu = new TabControl();
|
||||||
tabPage_Main = new TabPage();
|
tabPage_Main = new TabPage();
|
||||||
groupBox_Visual = new GroupBox();
|
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();
|
button_Visual_Start = new Button();
|
||||||
numericUpDown_Visual_Port = new NumericUpDown();
|
numericUpDown_Visual_Port = new NumericUpDown();
|
||||||
label_Visual_Port = new Label();
|
label_Visual_Port = new Label();
|
||||||
@ -57,18 +61,61 @@
|
|||||||
comboBox_Drone_Rotor = new ComboBox();
|
comboBox_Drone_Rotor = new ComboBox();
|
||||||
comboBox_Drone = new ComboBox();
|
comboBox_Drone = new ComboBox();
|
||||||
timer_Test = new System.Windows.Forms.Timer(components);
|
timer_Test = new System.Windows.Forms.Timer(components);
|
||||||
|
textBox_GPS_Lat = new TextBox();
|
||||||
|
label2 = new Label();
|
||||||
|
groupBox_GPS = new GroupBox();
|
||||||
|
textBox_GPS_Lon = new TextBox();
|
||||||
|
label4 = new Label();
|
||||||
|
numericUpDown_GPS_Freq = new NumericUpDown();
|
||||||
|
label_GPS_Frequency = new Label();
|
||||||
|
label6 = new Label();
|
||||||
|
groupBox_Barometer = new GroupBox();
|
||||||
|
numericUpDown_Bar_Freq = new NumericUpDown();
|
||||||
|
label5 = new Label();
|
||||||
|
label7 = new Label();
|
||||||
|
label8 = new Label();
|
||||||
|
numericUpDown_Bar_Accur = new NumericUpDown();
|
||||||
|
label9 = new Label();
|
||||||
|
label10 = new Label();
|
||||||
|
textBox_GPS_Accur = new NumericUpDown();
|
||||||
|
label11 = new Label();
|
||||||
|
groupBox1 = new GroupBox();
|
||||||
|
label12 = new Label();
|
||||||
|
numericUpDown_OF_Accur = new NumericUpDown();
|
||||||
|
label13 = new Label();
|
||||||
|
numericUpDown_OF_Freq = new NumericUpDown();
|
||||||
|
label14 = new Label();
|
||||||
|
label15 = new Label();
|
||||||
|
checkBox_GPS_Enable = new CheckBox();
|
||||||
|
label16 = new Label();
|
||||||
|
numericUpDown1 = new NumericUpDown();
|
||||||
|
label17 = new Label();
|
||||||
|
checkBox_OF_Enable = new CheckBox();
|
||||||
|
checkBox_Bar_Enable = new CheckBox();
|
||||||
menuStrip_Menu.SuspendLayout();
|
menuStrip_Menu.SuspendLayout();
|
||||||
groupBox_Screen.SuspendLayout();
|
groupBox_Screen.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox_2D).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox_2D).BeginInit();
|
||||||
tabControl_Menu.SuspendLayout();
|
tabControl_Menu.SuspendLayout();
|
||||||
tabPage_Main.SuspendLayout();
|
tabPage_Main.SuspendLayout();
|
||||||
groupBox_Visual.SuspendLayout();
|
groupBox_Visual.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Limit).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).BeginInit();
|
||||||
groupBox_Clients.SuspendLayout();
|
groupBox_Clients.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Limit).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Limit).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Port).BeginInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Port).BeginInit();
|
||||||
|
tabPage_Model.SuspendLayout();
|
||||||
groupBox_Navi.SuspendLayout();
|
groupBox_Navi.SuspendLayout();
|
||||||
panel1.SuspendLayout();
|
panel1.SuspendLayout();
|
||||||
|
groupBox_GPS.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_GPS_Freq).BeginInit();
|
||||||
|
groupBox_Barometer.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Bar_Freq).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Bar_Accur).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)textBox_GPS_Accur).BeginInit();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_OF_Accur).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_OF_Freq).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// menuStrip_Menu
|
// menuStrip_Menu
|
||||||
@ -144,18 +191,61 @@
|
|||||||
//
|
//
|
||||||
// groupBox_Visual
|
// 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(button_Visual_Start);
|
||||||
groupBox_Visual.Controls.Add(numericUpDown_Visual_Port);
|
groupBox_Visual.Controls.Add(numericUpDown_Visual_Port);
|
||||||
groupBox_Visual.Controls.Add(label_Visual_Port);
|
groupBox_Visual.Controls.Add(label_Visual_Port);
|
||||||
groupBox_Visual.Dock = DockStyle.Top;
|
groupBox_Visual.Dock = DockStyle.Top;
|
||||||
groupBox_Visual.Location = new Point(3, 83);
|
groupBox_Visual.Location = new Point(3, 83);
|
||||||
groupBox_Visual.Name = "groupBox_Visual";
|
groupBox_Visual.Name = "groupBox_Visual";
|
||||||
groupBox_Visual.Size = new Size(204, 62);
|
groupBox_Visual.Size = new Size(204, 91);
|
||||||
groupBox_Visual.TabIndex = 2;
|
groupBox_Visual.TabIndex = 2;
|
||||||
groupBox_Visual.TabStop = false;
|
groupBox_Visual.TabStop = false;
|
||||||
groupBox_Visual.Tag = "#visual";
|
groupBox_Visual.Tag = "#visual";
|
||||||
groupBox_Visual.Text = "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
|
||||||
//
|
//
|
||||||
button_Visual_Start.Location = new Point(112, 22);
|
button_Visual_Start.Location = new Point(112, 22);
|
||||||
@ -165,6 +255,7 @@
|
|||||||
button_Visual_Start.Tag = "#visual_start";
|
button_Visual_Start.Tag = "#visual_start";
|
||||||
button_Visual_Start.Text = "Start";
|
button_Visual_Start.Text = "Start";
|
||||||
button_Visual_Start.UseVisualStyleBackColor = true;
|
button_Visual_Start.UseVisualStyleBackColor = true;
|
||||||
|
button_Visual_Start.Click += button_Visual_Start_Click;
|
||||||
//
|
//
|
||||||
// numericUpDown_Visual_Port
|
// numericUpDown_Visual_Port
|
||||||
//
|
//
|
||||||
@ -277,6 +368,9 @@
|
|||||||
//
|
//
|
||||||
// tabPage_Model
|
// tabPage_Model
|
||||||
//
|
//
|
||||||
|
tabPage_Model.Controls.Add(groupBox1);
|
||||||
|
tabPage_Model.Controls.Add(groupBox_Barometer);
|
||||||
|
tabPage_Model.Controls.Add(groupBox_GPS);
|
||||||
tabPage_Model.Location = new Point(4, 24);
|
tabPage_Model.Location = new Point(4, 24);
|
||||||
tabPage_Model.Name = "tabPage_Model";
|
tabPage_Model.Name = "tabPage_Model";
|
||||||
tabPage_Model.Padding = new Padding(3);
|
tabPage_Model.Padding = new Padding(3);
|
||||||
@ -353,6 +447,341 @@
|
|||||||
timer_Test.Interval = 10;
|
timer_Test.Interval = 10;
|
||||||
timer_Test.Tick += timer_Test_Tick;
|
timer_Test.Tick += timer_Test_Tick;
|
||||||
//
|
//
|
||||||
|
// textBox_GPS_Lat
|
||||||
|
//
|
||||||
|
textBox_GPS_Lat.Location = new Point(37, 22);
|
||||||
|
textBox_GPS_Lat.Name = "textBox_GPS_Lat";
|
||||||
|
textBox_GPS_Lat.Size = new Size(92, 23);
|
||||||
|
textBox_GPS_Lat.TabIndex = 0;
|
||||||
|
textBox_GPS_Lat.Text = "47.2125649";
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(5, 25);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(26, 15);
|
||||||
|
label2.TabIndex = 1;
|
||||||
|
label2.Text = "Lat:";
|
||||||
|
//
|
||||||
|
// groupBox_GPS
|
||||||
|
//
|
||||||
|
groupBox_GPS.Controls.Add(checkBox_GPS_Enable);
|
||||||
|
groupBox_GPS.Controls.Add(label10);
|
||||||
|
groupBox_GPS.Controls.Add(textBox_GPS_Accur);
|
||||||
|
groupBox_GPS.Controls.Add(label11);
|
||||||
|
groupBox_GPS.Controls.Add(numericUpDown_GPS_Freq);
|
||||||
|
groupBox_GPS.Controls.Add(label6);
|
||||||
|
groupBox_GPS.Controls.Add(label_GPS_Frequency);
|
||||||
|
groupBox_GPS.Controls.Add(label4);
|
||||||
|
groupBox_GPS.Controls.Add(textBox_GPS_Lon);
|
||||||
|
groupBox_GPS.Controls.Add(label2);
|
||||||
|
groupBox_GPS.Controls.Add(textBox_GPS_Lat);
|
||||||
|
groupBox_GPS.Dock = DockStyle.Top;
|
||||||
|
groupBox_GPS.Enabled = false;
|
||||||
|
groupBox_GPS.Location = new Point(3, 3);
|
||||||
|
groupBox_GPS.Name = "groupBox_GPS";
|
||||||
|
groupBox_GPS.Size = new Size(204, 112);
|
||||||
|
groupBox_GPS.TabIndex = 2;
|
||||||
|
groupBox_GPS.TabStop = false;
|
||||||
|
groupBox_GPS.Text = "GPS";
|
||||||
|
//
|
||||||
|
// textBox_GPS_Lon
|
||||||
|
//
|
||||||
|
textBox_GPS_Lon.Location = new Point(37, 51);
|
||||||
|
textBox_GPS_Lon.Name = "textBox_GPS_Lon";
|
||||||
|
textBox_GPS_Lon.Size = new Size(92, 23);
|
||||||
|
textBox_GPS_Lon.TabIndex = 2;
|
||||||
|
textBox_GPS_Lon.Text = "38.9160740";
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(5, 54);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(30, 15);
|
||||||
|
label4.TabIndex = 3;
|
||||||
|
label4.Text = "Lon:";
|
||||||
|
//
|
||||||
|
// numericUpDown_GPS_Freq
|
||||||
|
//
|
||||||
|
numericUpDown_GPS_Freq.Location = new Point(135, 51);
|
||||||
|
numericUpDown_GPS_Freq.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
|
numericUpDown_GPS_Freq.Name = "numericUpDown_GPS_Freq";
|
||||||
|
numericUpDown_GPS_Freq.Size = new Size(40, 23);
|
||||||
|
numericUpDown_GPS_Freq.TabIndex = 4;
|
||||||
|
numericUpDown_GPS_Freq.Value = new decimal(new int[] { 10, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label_GPS_Frequency
|
||||||
|
//
|
||||||
|
label_GPS_Frequency.AutoSize = true;
|
||||||
|
label_GPS_Frequency.Location = new Point(135, 25);
|
||||||
|
label_GPS_Frequency.Name = "label_GPS_Frequency";
|
||||||
|
label_GPS_Frequency.Size = new Size(62, 15);
|
||||||
|
label_GPS_Frequency.TabIndex = 5;
|
||||||
|
label_GPS_Frequency.Tag = "#frequency";
|
||||||
|
label_GPS_Frequency.Text = "Frequency";
|
||||||
|
//
|
||||||
|
// label6
|
||||||
|
//
|
||||||
|
label6.AutoSize = true;
|
||||||
|
label6.Location = new Point(176, 54);
|
||||||
|
label6.Name = "label6";
|
||||||
|
label6.Size = new Size(21, 15);
|
||||||
|
label6.TabIndex = 6;
|
||||||
|
label6.Text = "Hz";
|
||||||
|
//
|
||||||
|
// groupBox_Barometer
|
||||||
|
//
|
||||||
|
groupBox_Barometer.Controls.Add(checkBox_Bar_Enable);
|
||||||
|
groupBox_Barometer.Controls.Add(label9);
|
||||||
|
groupBox_Barometer.Controls.Add(numericUpDown_Bar_Accur);
|
||||||
|
groupBox_Barometer.Controls.Add(label8);
|
||||||
|
groupBox_Barometer.Controls.Add(numericUpDown_Bar_Freq);
|
||||||
|
groupBox_Barometer.Controls.Add(label5);
|
||||||
|
groupBox_Barometer.Controls.Add(label7);
|
||||||
|
groupBox_Barometer.Dock = DockStyle.Top;
|
||||||
|
groupBox_Barometer.Location = new Point(3, 115);
|
||||||
|
groupBox_Barometer.Name = "groupBox_Barometer";
|
||||||
|
groupBox_Barometer.Size = new Size(204, 88);
|
||||||
|
groupBox_Barometer.TabIndex = 3;
|
||||||
|
groupBox_Barometer.TabStop = false;
|
||||||
|
groupBox_Barometer.Tag = "#barometer";
|
||||||
|
groupBox_Barometer.Text = "Barometer";
|
||||||
|
//
|
||||||
|
// numericUpDown_Bar_Freq
|
||||||
|
//
|
||||||
|
numericUpDown_Bar_Freq.Location = new Point(69, 22);
|
||||||
|
numericUpDown_Bar_Freq.Maximum = new decimal(new int[] { 200, 0, 0, 0 });
|
||||||
|
numericUpDown_Bar_Freq.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
|
numericUpDown_Bar_Freq.Name = "numericUpDown_Bar_Freq";
|
||||||
|
numericUpDown_Bar_Freq.Size = new Size(40, 23);
|
||||||
|
numericUpDown_Bar_Freq.TabIndex = 7;
|
||||||
|
numericUpDown_Bar_Freq.Value = new decimal(new int[] { 50, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label5
|
||||||
|
//
|
||||||
|
label5.AutoSize = true;
|
||||||
|
label5.Location = new Point(111, 24);
|
||||||
|
label5.Name = "label5";
|
||||||
|
label5.Size = new Size(21, 15);
|
||||||
|
label5.TabIndex = 9;
|
||||||
|
label5.Text = "Hz";
|
||||||
|
//
|
||||||
|
// label7
|
||||||
|
//
|
||||||
|
label7.AutoSize = true;
|
||||||
|
label7.Location = new Point(6, 24);
|
||||||
|
label7.Name = "label7";
|
||||||
|
label7.Size = new Size(62, 15);
|
||||||
|
label7.TabIndex = 8;
|
||||||
|
label7.Tag = "#frequency";
|
||||||
|
label7.Text = "Frequency";
|
||||||
|
//
|
||||||
|
// label8
|
||||||
|
//
|
||||||
|
label8.AutoSize = true;
|
||||||
|
label8.Location = new Point(7, 53);
|
||||||
|
label8.Name = "label8";
|
||||||
|
label8.Size = new Size(56, 15);
|
||||||
|
label8.TabIndex = 10;
|
||||||
|
label8.Tag = "#accuracy";
|
||||||
|
label8.Text = "Accuracy";
|
||||||
|
//
|
||||||
|
// numericUpDown_Bar_Accur
|
||||||
|
//
|
||||||
|
numericUpDown_Bar_Accur.DecimalPlaces = 1;
|
||||||
|
numericUpDown_Bar_Accur.Location = new Point(69, 51);
|
||||||
|
numericUpDown_Bar_Accur.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
|
||||||
|
numericUpDown_Bar_Accur.Name = "numericUpDown_Bar_Accur";
|
||||||
|
numericUpDown_Bar_Accur.Size = new Size(40, 23);
|
||||||
|
numericUpDown_Bar_Accur.TabIndex = 11;
|
||||||
|
numericUpDown_Bar_Accur.Value = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label9
|
||||||
|
//
|
||||||
|
label9.AutoSize = true;
|
||||||
|
label9.Location = new Point(112, 53);
|
||||||
|
label9.Name = "label9";
|
||||||
|
label9.Size = new Size(20, 15);
|
||||||
|
label9.TabIndex = 12;
|
||||||
|
label9.Text = "Pa";
|
||||||
|
//
|
||||||
|
// label10
|
||||||
|
//
|
||||||
|
label10.AutoSize = true;
|
||||||
|
label10.Location = new Point(111, 82);
|
||||||
|
label10.Name = "label10";
|
||||||
|
label10.Size = new Size(18, 15);
|
||||||
|
label10.TabIndex = 15;
|
||||||
|
label10.Text = "m";
|
||||||
|
//
|
||||||
|
// textBox_GPS_Accur
|
||||||
|
//
|
||||||
|
textBox_GPS_Accur.DecimalPlaces = 1;
|
||||||
|
textBox_GPS_Accur.Location = new Point(68, 80);
|
||||||
|
textBox_GPS_Accur.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
|
||||||
|
textBox_GPS_Accur.Name = "textBox_GPS_Accur";
|
||||||
|
textBox_GPS_Accur.Size = new Size(40, 23);
|
||||||
|
textBox_GPS_Accur.TabIndex = 14;
|
||||||
|
textBox_GPS_Accur.Value = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label11
|
||||||
|
//
|
||||||
|
label11.AutoSize = true;
|
||||||
|
label11.Location = new Point(6, 82);
|
||||||
|
label11.Name = "label11";
|
||||||
|
label11.Size = new Size(56, 15);
|
||||||
|
label11.TabIndex = 13;
|
||||||
|
label11.Tag = "#accuracy";
|
||||||
|
label11.Text = "Accuracy";
|
||||||
|
//
|
||||||
|
// groupBox1
|
||||||
|
//
|
||||||
|
groupBox1.Controls.Add(checkBox_OF_Enable);
|
||||||
|
groupBox1.Controls.Add(label17);
|
||||||
|
groupBox1.Controls.Add(numericUpDown1);
|
||||||
|
groupBox1.Controls.Add(label16);
|
||||||
|
groupBox1.Controls.Add(label12);
|
||||||
|
groupBox1.Controls.Add(numericUpDown_OF_Accur);
|
||||||
|
groupBox1.Controls.Add(label13);
|
||||||
|
groupBox1.Controls.Add(numericUpDown_OF_Freq);
|
||||||
|
groupBox1.Controls.Add(label14);
|
||||||
|
groupBox1.Controls.Add(label15);
|
||||||
|
groupBox1.Dock = DockStyle.Top;
|
||||||
|
groupBox1.Enabled = false;
|
||||||
|
groupBox1.Location = new Point(3, 203);
|
||||||
|
groupBox1.Name = "groupBox1";
|
||||||
|
groupBox1.Size = new Size(204, 114);
|
||||||
|
groupBox1.TabIndex = 4;
|
||||||
|
groupBox1.TabStop = false;
|
||||||
|
groupBox1.Text = "Optical flow";
|
||||||
|
//
|
||||||
|
// label12
|
||||||
|
//
|
||||||
|
label12.AutoSize = true;
|
||||||
|
label12.Location = new Point(111, 53);
|
||||||
|
label12.Name = "label12";
|
||||||
|
label12.Size = new Size(28, 15);
|
||||||
|
label12.TabIndex = 18;
|
||||||
|
label12.Text = "Deg";
|
||||||
|
//
|
||||||
|
// numericUpDown_OF_Accur
|
||||||
|
//
|
||||||
|
numericUpDown_OF_Accur.DecimalPlaces = 1;
|
||||||
|
numericUpDown_OF_Accur.Location = new Point(69, 51);
|
||||||
|
numericUpDown_OF_Accur.Maximum = new decimal(new int[] { 10, 0, 0, 0 });
|
||||||
|
numericUpDown_OF_Accur.Name = "numericUpDown_OF_Accur";
|
||||||
|
numericUpDown_OF_Accur.Size = new Size(40, 23);
|
||||||
|
numericUpDown_OF_Accur.TabIndex = 17;
|
||||||
|
numericUpDown_OF_Accur.Value = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label13
|
||||||
|
//
|
||||||
|
label13.AutoSize = true;
|
||||||
|
label13.Location = new Point(7, 53);
|
||||||
|
label13.Name = "label13";
|
||||||
|
label13.Size = new Size(56, 15);
|
||||||
|
label13.TabIndex = 16;
|
||||||
|
label13.Tag = "#accuracy";
|
||||||
|
label13.Text = "Accuracy";
|
||||||
|
//
|
||||||
|
// numericUpDown_OF_Freq
|
||||||
|
//
|
||||||
|
numericUpDown_OF_Freq.Location = new Point(69, 22);
|
||||||
|
numericUpDown_OF_Freq.Maximum = new decimal(new int[] { 200, 0, 0, 0 });
|
||||||
|
numericUpDown_OF_Freq.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
|
numericUpDown_OF_Freq.Name = "numericUpDown_OF_Freq";
|
||||||
|
numericUpDown_OF_Freq.Size = new Size(40, 23);
|
||||||
|
numericUpDown_OF_Freq.TabIndex = 13;
|
||||||
|
numericUpDown_OF_Freq.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label14
|
||||||
|
//
|
||||||
|
label14.AutoSize = true;
|
||||||
|
label14.Location = new Point(112, 24);
|
||||||
|
label14.Name = "label14";
|
||||||
|
label14.Size = new Size(21, 15);
|
||||||
|
label14.TabIndex = 15;
|
||||||
|
label14.Text = "Hz";
|
||||||
|
//
|
||||||
|
// label15
|
||||||
|
//
|
||||||
|
label15.AutoSize = true;
|
||||||
|
label15.Location = new Point(6, 24);
|
||||||
|
label15.Name = "label15";
|
||||||
|
label15.Size = new Size(62, 15);
|
||||||
|
label15.TabIndex = 14;
|
||||||
|
label15.Tag = "#frequency";
|
||||||
|
label15.Text = "Frequency";
|
||||||
|
//
|
||||||
|
// checkBox_GPS_Enable
|
||||||
|
//
|
||||||
|
checkBox_GPS_Enable.AutoSize = true;
|
||||||
|
checkBox_GPS_Enable.Checked = true;
|
||||||
|
checkBox_GPS_Enable.CheckState = CheckState.Checked;
|
||||||
|
checkBox_GPS_Enable.Location = new Point(158, 87);
|
||||||
|
checkBox_GPS_Enable.Name = "checkBox_GPS_Enable";
|
||||||
|
checkBox_GPS_Enable.Size = new Size(39, 19);
|
||||||
|
checkBox_GPS_Enable.TabIndex = 16;
|
||||||
|
checkBox_GPS_Enable.Tag = "#en";
|
||||||
|
checkBox_GPS_Enable.Text = "En";
|
||||||
|
checkBox_GPS_Enable.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// label16
|
||||||
|
//
|
||||||
|
label16.AutoSize = true;
|
||||||
|
label16.Location = new Point(1, 82);
|
||||||
|
label16.Name = "label16";
|
||||||
|
label16.Size = new Size(67, 15);
|
||||||
|
label16.TabIndex = 19;
|
||||||
|
label16.Tag = "#max_height";
|
||||||
|
label16.Text = "Max height";
|
||||||
|
//
|
||||||
|
// numericUpDown1
|
||||||
|
//
|
||||||
|
numericUpDown1.Location = new Point(68, 80);
|
||||||
|
numericUpDown1.Minimum = new decimal(new int[] { 1, 0, 0, 0 });
|
||||||
|
numericUpDown1.Name = "numericUpDown1";
|
||||||
|
numericUpDown1.Size = new Size(40, 23);
|
||||||
|
numericUpDown1.TabIndex = 20;
|
||||||
|
numericUpDown1.Value = new decimal(new int[] { 8, 0, 0, 0 });
|
||||||
|
//
|
||||||
|
// label17
|
||||||
|
//
|
||||||
|
label17.AutoSize = true;
|
||||||
|
label17.Location = new Point(111, 82);
|
||||||
|
label17.Name = "label17";
|
||||||
|
label17.Size = new Size(18, 15);
|
||||||
|
label17.TabIndex = 21;
|
||||||
|
label17.Text = "m";
|
||||||
|
//
|
||||||
|
// checkBox_OF_Enable
|
||||||
|
//
|
||||||
|
checkBox_OF_Enable.AutoSize = true;
|
||||||
|
checkBox_OF_Enable.Checked = true;
|
||||||
|
checkBox_OF_Enable.CheckState = CheckState.Checked;
|
||||||
|
checkBox_OF_Enable.Location = new Point(158, 89);
|
||||||
|
checkBox_OF_Enable.Name = "checkBox_OF_Enable";
|
||||||
|
checkBox_OF_Enable.Size = new Size(39, 19);
|
||||||
|
checkBox_OF_Enable.TabIndex = 22;
|
||||||
|
checkBox_OF_Enable.Tag = "#en";
|
||||||
|
checkBox_OF_Enable.Text = "En";
|
||||||
|
checkBox_OF_Enable.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// checkBox_Bar_Enable
|
||||||
|
//
|
||||||
|
checkBox_Bar_Enable.AutoSize = true;
|
||||||
|
checkBox_Bar_Enable.Checked = true;
|
||||||
|
checkBox_Bar_Enable.CheckState = CheckState.Checked;
|
||||||
|
checkBox_Bar_Enable.Location = new Point(158, 63);
|
||||||
|
checkBox_Bar_Enable.Name = "checkBox_Bar_Enable";
|
||||||
|
checkBox_Bar_Enable.Size = new Size(39, 19);
|
||||||
|
checkBox_Bar_Enable.TabIndex = 17;
|
||||||
|
checkBox_Bar_Enable.Tag = "#en";
|
||||||
|
checkBox_Bar_Enable.Text = "En";
|
||||||
|
checkBox_Bar_Enable.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
// Form_Main
|
// Form_Main
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -376,13 +805,28 @@
|
|||||||
tabPage_Main.ResumeLayout(false);
|
tabPage_Main.ResumeLayout(false);
|
||||||
groupBox_Visual.ResumeLayout(false);
|
groupBox_Visual.ResumeLayout(false);
|
||||||
groupBox_Visual.PerformLayout();
|
groupBox_Visual.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Limit).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).EndInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Visual_Port).EndInit();
|
||||||
groupBox_Clients.ResumeLayout(false);
|
groupBox_Clients.ResumeLayout(false);
|
||||||
groupBox_Clients.PerformLayout();
|
groupBox_Clients.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Limit).EndInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Limit).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Port).EndInit();
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Clients_Port).EndInit();
|
||||||
|
tabPage_Model.ResumeLayout(false);
|
||||||
groupBox_Navi.ResumeLayout(false);
|
groupBox_Navi.ResumeLayout(false);
|
||||||
panel1.ResumeLayout(false);
|
panel1.ResumeLayout(false);
|
||||||
|
groupBox_GPS.ResumeLayout(false);
|
||||||
|
groupBox_GPS.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_GPS_Freq).EndInit();
|
||||||
|
groupBox_Barometer.ResumeLayout(false);
|
||||||
|
groupBox_Barometer.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Bar_Freq).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_Bar_Accur).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)textBox_GPS_Accur).EndInit();
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_OF_Accur).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown_OF_Freq).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
}
|
}
|
||||||
@ -416,5 +860,40 @@
|
|||||||
private Panel panel1;
|
private Panel panel1;
|
||||||
private ToolStripMenuItem exitToolStripMenuItem;
|
private ToolStripMenuItem exitToolStripMenuItem;
|
||||||
private System.Windows.Forms.Timer timer_Test;
|
private System.Windows.Forms.Timer timer_Test;
|
||||||
|
private NumericUpDown numericUpDown_Visual_Limit;
|
||||||
|
private Label label1;
|
||||||
|
private Label label_Visual_Num;
|
||||||
|
private Label label3;
|
||||||
|
private GroupBox groupBox_GPS;
|
||||||
|
private TextBox textBox_GPS_Lon;
|
||||||
|
private Label label2;
|
||||||
|
private TextBox textBox_GPS_Lat;
|
||||||
|
private NumericUpDown numericUpDown_GPS_Freq;
|
||||||
|
private Label label6;
|
||||||
|
private Label label_GPS_Frequency;
|
||||||
|
private Label label4;
|
||||||
|
private GroupBox groupBox_Barometer;
|
||||||
|
private NumericUpDown numericUpDown_Bar_Freq;
|
||||||
|
private Label label5;
|
||||||
|
private Label label7;
|
||||||
|
private Label label9;
|
||||||
|
private NumericUpDown numericUpDown_Bar_Accur;
|
||||||
|
private Label label8;
|
||||||
|
private Label label10;
|
||||||
|
private NumericUpDown textBox_GPS_Accur;
|
||||||
|
private Label label11;
|
||||||
|
private GroupBox groupBox1;
|
||||||
|
private Label label12;
|
||||||
|
private NumericUpDown numericUpDown_OF_Accur;
|
||||||
|
private Label label13;
|
||||||
|
private NumericUpDown numericUpDown_OF_Freq;
|
||||||
|
private Label label14;
|
||||||
|
private Label label15;
|
||||||
|
private CheckBox checkBox_GPS_Enable;
|
||||||
|
private Label label17;
|
||||||
|
private NumericUpDown numericUpDown1;
|
||||||
|
private Label label16;
|
||||||
|
private CheckBox checkBox_OF_Enable;
|
||||||
|
private CheckBox checkBox_Bar_Enable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,9 @@ using System.Windows.Forms;
|
|||||||
using static System.Net.Mime.MediaTypeNames;
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
using System.Security.Policy;
|
using System.Security.Policy;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.CodeDom;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator
|
||||||
{
|
{
|
||||||
@ -12,6 +15,7 @@ namespace DroneSimulator
|
|||||||
Screen2D screen2D = null;
|
Screen2D screen2D = null;
|
||||||
|
|
||||||
NetServerClients netServerClient = new NetServerClients();
|
NetServerClients netServerClient = new NetServerClients();
|
||||||
|
NetServerVisual netServerVisual = new NetServerVisual();
|
||||||
|
|
||||||
List<Drone> AllDrones = new List<Drone>();
|
List<Drone> AllDrones = new List<Drone>();
|
||||||
|
|
||||||
@ -20,7 +24,7 @@ namespace DroneSimulator
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ConnectionCallback(object o)
|
private void ClientConnectionCallback(object o)
|
||||||
{
|
{
|
||||||
NetServerClients.ConnectData data = (NetServerClients.ConnectData)o;
|
NetServerClients.ConnectData data = (NetServerClients.ConnectData)o;
|
||||||
|
|
||||||
@ -32,7 +36,7 @@ namespace DroneSimulator
|
|||||||
if (data.Connect)
|
if (data.Connect)
|
||||||
{
|
{
|
||||||
Drone drone = new Drone(data.ID);
|
Drone drone = new Drone(data.ID);
|
||||||
drone.Create(0.5f, 10.0f);
|
drone.Create(1.0f, 0.5f, 1.0f);
|
||||||
|
|
||||||
screen2D.CreateDrone(Color.Red, data.ID);
|
screen2D.CreateDrone(Color.Red, data.ID);
|
||||||
|
|
||||||
@ -53,7 +57,7 @@ namespace DroneSimulator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReceiveCallback(object o)
|
private void ClientReceiveCallback(object o)
|
||||||
{
|
{
|
||||||
NetServerClients.ReceiveData data = (NetServerClients.ReceiveData)o;
|
NetServerClients.ReceiveData data = (NetServerClients.ReceiveData)o;
|
||||||
|
|
||||||
@ -68,31 +72,27 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
if (drone == null) return;
|
if (drone == null) return;
|
||||||
|
|
||||||
Drone.DataIn id = new Drone.DataIn();
|
List<byte[]?>? send = drone.DataStream(data.Buffer, data.Size);
|
||||||
|
|
||||||
id.fromBytes(data.Buffer);
|
if (send == null) return;
|
||||||
|
try
|
||||||
drone.SetQadroPow(id.MotorUL, id.MotorUR, id.MotorDL, id.MotorDR);
|
{
|
||||||
|
foreach (byte[]? b in send)
|
||||||
Drone.DataOut od = new Drone.DataOut();
|
{
|
||||||
|
if (b != null) data.Client?.Send(b);
|
||||||
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;
|
|
||||||
|
|
||||||
try { data.Client.Send(od.getBytes()); }
|
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button_Client_Start_Click(object sender, EventArgs e)
|
private void button_Client_Start_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var done = netServerClient.StartServer((int)numericUpDown_Clients_Port.Value, (int)numericUpDown_Clients_Limit.Value, ConnectionCallback, ReceiveCallback);
|
var done = netServerClient.StartServer((int)numericUpDown_Clients_Port.Value, (int)numericUpDown_Clients_Limit.Value, ClientConnectionCallback, ClientReceiveCallback);
|
||||||
switch (done)
|
switch (done)
|
||||||
{
|
{
|
||||||
case NetServerClients.ServerState.Error:
|
case NetServerClients.ServerState.Error:
|
||||||
{
|
{
|
||||||
MessageBox.Show("Error to start server");
|
MessageBox.Show("Error to start clients server", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NetServerClients.ServerState.Start:
|
case NetServerClients.ServerState.Start:
|
||||||
@ -146,5 +146,63 @@ namespace DroneSimulator
|
|||||||
{
|
{
|
||||||
foreach (Drone d in AllDrones) d.Close();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.Net;
|
using System.Net.Sockets;
|
||||||
using System.Net.Sockets;
|
using System.Net;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator
|
||||||
{
|
{
|
||||||
@ -16,8 +17,9 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
public class ReceiveData
|
public class ReceiveData
|
||||||
{
|
{
|
||||||
|
|
||||||
public int ID;
|
public int ID;
|
||||||
public byte[]? Buffer;
|
public byte[] Buffer;
|
||||||
public int Size;
|
public int Size;
|
||||||
|
|
||||||
public Socket? Client;
|
public Socket? Client;
|
||||||
@ -27,8 +29,8 @@ namespace DroneSimulator
|
|||||||
{
|
{
|
||||||
public int ID;
|
public int ID;
|
||||||
public Socket? workSocket = null;
|
public Socket? workSocket = null;
|
||||||
public const int BufferSize = 1024;
|
public const int count = 1024;
|
||||||
public byte[] buffer = new byte[BufferSize];
|
public byte[] buffer = new byte[count];
|
||||||
}
|
}
|
||||||
|
|
||||||
private int SocketID = 0;
|
private int SocketID = 0;
|
||||||
@ -87,7 +89,7 @@ namespace DroneSimulator
|
|||||||
Socket handler;
|
Socket handler;
|
||||||
|
|
||||||
try { handler = listener.EndAccept(ar); }
|
try { handler = listener.EndAccept(ar); }
|
||||||
catch { ServerSocket?.Close(); Active = false; return; }
|
catch{ ServerSocket?.Close(); Active = false; return; }
|
||||||
|
|
||||||
if (SocketLimit > ClientSockets.Count)
|
if (SocketLimit > ClientSockets.Count)
|
||||||
{
|
{
|
||||||
@ -101,7 +103,7 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
ConnectionCallback(new ConnectData { ID = clientData.ID, Connect = true, Count = ClientSockets.Count, Client = handler });
|
ConnectionCallback(new ConnectData { ID = clientData.ID, Connect = true, Count = ClientSockets.Count, Client = handler });
|
||||||
|
|
||||||
handler.BeginReceive(clientData.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), clientData);
|
handler.BeginReceive(clientData.buffer, 0, ClientData.count, 0, new AsyncCallback(ReadCallback), clientData);
|
||||||
}
|
}
|
||||||
else handler.Close();
|
else handler.Close();
|
||||||
|
|
||||||
@ -132,7 +134,7 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.BufferSize, 0, new AsyncCallback(ReadCallback), cd);
|
cd.workSocket?.BeginReceive(cd.buffer, 0, ClientData.count, 0, new AsyncCallback(ReadCallback), cd);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
134
DroneSimulator/NetServerVisual.cs
Normal file
134
DroneSimulator/NetServerVisual.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
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 { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ namespace DroneSimulator
|
|||||||
public int Azimuth = 0;
|
public int Azimuth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float Scale = 100;
|
||||||
private DrawCallback drawCallback;
|
private DrawCallback drawCallback;
|
||||||
private Bitmap MainArea = new Bitmap(4096, 2560);
|
private Bitmap MainArea = new Bitmap(4096, 2560);
|
||||||
private List<DroneInfo> DroneList = new List<DroneInfo>();
|
private List<DroneInfo> DroneList = new List<DroneInfo>();
|
||||||
@ -161,6 +162,11 @@ namespace DroneSimulator
|
|||||||
const float TO_GRAD = 180 / MathF.PI;
|
const float TO_GRAD = 180 / MathF.PI;
|
||||||
const float TO_RADI = MathF.PI / 180;
|
const float TO_RADI = MathF.PI / 180;
|
||||||
|
|
||||||
|
pos *= Scale;
|
||||||
|
|
||||||
|
pos.X += MainArea.Width / 2;
|
||||||
|
pos.Y += MainArea.Height / 2;
|
||||||
|
|
||||||
foreach (var d in DroneList)
|
foreach (var d in DroneList)
|
||||||
{
|
{
|
||||||
if (d.ID != id) continue;
|
if (d.ID != id) continue;
|
||||||
|
@ -1,140 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <WinSock2.h>
|
|
||||||
#include <WS2tcpip.h>
|
|
||||||
#include <thread>
|
|
||||||
#include <atomic>
|
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#pragma comment(lib, "Ws2_32.lib")
|
|
||||||
|
|
||||||
struct DataIn
|
|
||||||
{
|
|
||||||
float AccX, AccY, AccZ;
|
|
||||||
float GyrX, GyrY, GyrZ;
|
|
||||||
float PosX, PosY, LaserRange;
|
|
||||||
} dataIn;
|
|
||||||
|
|
||||||
struct DataOut
|
|
||||||
{
|
|
||||||
float MotorUL, MotorUR, MotorDL, MotorDR;
|
|
||||||
} dataOut;
|
|
||||||
|
|
||||||
std::atomic<bool> running(true); // Флаг работы потоков
|
|
||||||
std::mutex dataMutex; // Мьютекс для синхронизации доступа к dataIn и dataOut
|
|
||||||
|
|
||||||
SOCKET ConnectToServer(const char* ip, int port)
|
|
||||||
{
|
|
||||||
WSAData wsaData;
|
|
||||||
WORD DLLVersion = MAKEWORD(2, 1);
|
|
||||||
|
|
||||||
if (WSAStartup(DLLVersion, &wsaData) != 0)
|
|
||||||
{
|
|
||||||
std::cout << "Error: WSAStartup failed\n";
|
|
||||||
return INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
SOCKADDR_IN addr;
|
|
||||||
inet_pton(AF_INET, ip, &addr.sin_addr);
|
|
||||||
addr.sin_port = htons(port);
|
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
|
|
||||||
SOCKET Connection = socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
if (Connection == INVALID_SOCKET)
|
|
||||||
{
|
|
||||||
std::cout << "Error: Failed to create socket\n";
|
|
||||||
WSACleanup();
|
|
||||||
return INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connect(Connection, (SOCKADDR*)&addr, sizeof(addr)) != 0)
|
|
||||||
{
|
|
||||||
std::cout << "Error: Failed to connect to server\n";
|
|
||||||
closesocket(Connection);
|
|
||||||
WSACleanup();
|
|
||||||
return INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CloseConnection(SOCKET& socket)
|
|
||||||
{
|
|
||||||
if (socket != INVALID_SOCKET)
|
|
||||||
{
|
|
||||||
closesocket(socket);
|
|
||||||
WSACleanup();
|
|
||||||
socket = INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Функция приема данных
|
|
||||||
void ReceiveHandler(SOCKET socket)
|
|
||||||
{
|
|
||||||
while (running)
|
|
||||||
{
|
|
||||||
DataIn tempData;
|
|
||||||
int result = recv(socket, (char*)&tempData, sizeof(tempData), 0);
|
|
||||||
|
|
||||||
if (result <= 0)
|
|
||||||
{
|
|
||||||
std::cout << "Error: Connection lost (recv failed)\n";
|
|
||||||
running = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Потокобезопасное обновление данных
|
|
||||||
std::lock_guard<std::mutex> lock(dataMutex);
|
|
||||||
dataIn = tempData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Функция отправки данных
|
|
||||||
void SendHandler(SOCKET socket)
|
|
||||||
{
|
|
||||||
while (running)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(dataMutex);
|
|
||||||
send(socket, (char*)&dataOut, sizeof(dataOut), 0);
|
|
||||||
}
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Задержка для уменьшения нагрузки
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
SOCKET Connection = ConnectToServer("127.0.0.1", 1001);
|
|
||||||
if (Connection == INVALID_SOCKET)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataOut.MotorUL = 10;
|
|
||||||
dataOut.MotorUR = 10;
|
|
||||||
dataOut.MotorDL = 10;
|
|
||||||
dataOut.MotorDR = 10;
|
|
||||||
|
|
||||||
// Создание потоков
|
|
||||||
std::thread recvThread(ReceiveHandler, Connection);
|
|
||||||
std::thread sendThread(SendHandler, Connection);
|
|
||||||
|
|
||||||
for (int i = 0; i < 1000000; i++)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(dataMutex);
|
|
||||||
std::cout << "Laser Range: " << dataIn.LaserRange << std::endl;
|
|
||||||
}
|
|
||||||
std::cout << "-----------------------------------------------------------" << std::endl;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); // Задержка вывода
|
|
||||||
}
|
|
||||||
|
|
||||||
// Завершаем работу потоков
|
|
||||||
running = false;
|
|
||||||
recvThread.join();
|
|
||||||
sendThread.join();
|
|
||||||
|
|
||||||
CloseConnection(Connection);
|
|
||||||
|
|
||||||
system("pause");
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,135 +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>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<ProjectGuid>{b7cc5245-b628-40e9-a9a0-a904e2bf25ea}</ProjectGuid>
|
|
||||||
<RootNamespace>TestClientConnection</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>
|
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
|
||||||
<PlatformToolset>v143</PlatformToolset>
|
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
|
||||||
<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" />
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<WarningLevel>Level3</WarningLevel>
|
|
||||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
|
||||||
<SDLCheck>true</SDLCheck>
|
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<ConformanceMode>true</ConformanceMode>
|
|
||||||
</ClCompile>
|
|
||||||
<Link>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
</Link>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClCompile Include="TestClientConnection.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
@ -1,22 +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="TestClientConnection.cpp">
|
|
||||||
<Filter>Исходные файлы</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
Reference in New Issue
Block a user