forked from CPL/Simulator
Compare commits
65 Commits
Author | SHA1 | Date | |
---|---|---|---|
5082ecee14 | |||
e5d8a9c507 | |||
12e518af0e | |||
39c81a227b | |||
c763581ebb | |||
f4044e3939 | |||
0d8b03ef9a | |||
4b78b7d146 | |||
3e4973a129 | |||
15d4fa5011 | |||
4ff3c2c5da | |||
b4f2ecb18e | |||
fdbfd85180 | |||
c22f4d825d | |||
48c07bf59f | |||
3dcf30882a | |||
afece52bb2 | |||
72ea9fd6a6 | |||
a97e618695 | |||
2d56ea0ae1 | |||
89f4a186ff | |||
2b595ba585 | |||
3d39f7da12 | |||
3a462be82d | |||
90cec037eb | |||
e0f3e3db19 | |||
7bf2553455 | |||
cdf8c18d9b | |||
376ce81a8a | |||
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 | |||
a35d7fdb97 | |||
ffc309ce21 | |||
39dab5b50e | |||
5c9caf645a | |||
70391a13fc | |||
ddf80ed6f7 |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.vs/
|
||||||
|
obj/
|
||||||
|
bin/
|
||||||
|
x64/
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\",
|
|
||||||
"Documents": [],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\",
|
|
||||||
"Documents": [
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|d:\\cpl\\simulator\\droneclient\\droneclient\\formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|solutionrelative:formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|d:\\cpl\\simulator\\droneclient\\droneclient\\formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form",
|
|
||||||
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneClient.csproj|solutionrelative:formmain.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}|Form"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": [
|
|
||||||
{
|
|
||||||
"DockedWidth": 200,
|
|
||||||
"SelectedChildIndex": 0,
|
|
||||||
"Children": [
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 0,
|
|
||||||
"Title": "FormMain.cs",
|
|
||||||
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
|
|
||||||
"RelativeDocumentMoniker": "FormMain.cs",
|
|
||||||
"ToolTip": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
|
|
||||||
"RelativeToolTip": "FormMain.cs",
|
|
||||||
"ViewState": "AgIAACEAAAAAAAAAAAAYwCYAAAAOAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2025-03-27T13:11:11.045Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 1,
|
|
||||||
"Title": "FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
|
|
||||||
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs",
|
|
||||||
"RelativeDocumentMoniker": "FormMain.cs",
|
|
||||||
"ToolTip": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
|
|
||||||
"RelativeToolTip": "FormMain.cs [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2025-03-27T13:11:01.471Z",
|
|
||||||
"EditorCaption": " [\u041A\u043E\u043D\u0441\u0442\u0440\u0443\u043A\u0442\u043E\u0440]"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
478
DroneClient/BaseCommHandler.cs
Normal file
478
DroneClient/BaseCommHandler.cs
Normal file
@ -0,0 +1,478 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelemetryIO.Models;
|
||||||
|
|
||||||
|
namespace TelemetryIO
|
||||||
|
{
|
||||||
|
public interface iCommParams
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
internal class TCPCommParams : iCommParams
|
||||||
|
{
|
||||||
|
public string IP = "";
|
||||||
|
public int Port = 0;
|
||||||
|
public TCPCommParams(string addr, int port)
|
||||||
|
{
|
||||||
|
this.IP = addr;
|
||||||
|
this.Port = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SerialCommParams : iCommParams
|
||||||
|
{
|
||||||
|
public string PortName = "";
|
||||||
|
public int BaudRate = 9600;
|
||||||
|
public SerialCommParams(string portName, int baudRate)
|
||||||
|
{
|
||||||
|
PortName = portName;
|
||||||
|
BaudRate = baudRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class BaseCommHandler
|
||||||
|
{
|
||||||
|
public const int TELE_CMD_RD_ONCE = 1;
|
||||||
|
public const int TELE_CMD_RD_MON_ON = 2;
|
||||||
|
public const int TELE_CMD_RD_MON_OFF = 3;
|
||||||
|
public const int TELE_CMD_RD_MON_ADD = 4;
|
||||||
|
public const int TELE_CMD_RD_MON_REMOVE = 5;
|
||||||
|
public const int TELE_CMD_RD_MON_REMOVEALL = 6;
|
||||||
|
public const int TELE_CMD_WR = 10;
|
||||||
|
public const int TELE_CMD_MOTORS_CTRL = 100;
|
||||||
|
public const int TELE_CMD_ABORT = 999;
|
||||||
|
public const int TELE_CMD_HELLO = 9999;
|
||||||
|
public const byte CRC8_POLYNOMIAL = 0x07;
|
||||||
|
public const int CRC32_POLY = 0x04C11DB7;
|
||||||
|
public const byte ESCAPE_BEGIN = 0xBE;
|
||||||
|
public const byte ESCAPE_END = 0xED;
|
||||||
|
public const byte ESCAPE_CHAR = 0x0E;
|
||||||
|
|
||||||
|
|
||||||
|
private volatile bool _isReading = true;
|
||||||
|
private readonly ConcurrentQueue<byte> dataQueue = new ConcurrentQueue<byte>();
|
||||||
|
static private List<byte> rx_buf = new List<byte>();
|
||||||
|
private Task _readingTask;
|
||||||
|
private object lock_obj = new object();
|
||||||
|
private object lock_obj_put = new object();
|
||||||
|
private bool waitingForResponse = false;
|
||||||
|
private bool isTimeout = false;
|
||||||
|
private readonly int responseTimeout = 2000;
|
||||||
|
private System.Timers.Timer timeout = new System.Timers.Timer(3000);
|
||||||
|
private bool exitPending = false;
|
||||||
|
private float[] monitor = new float[32];
|
||||||
|
public string view_str = "";
|
||||||
|
|
||||||
|
protected string IP = "127.0.0.1";
|
||||||
|
protected int Port = 8888;
|
||||||
|
|
||||||
|
protected string PortName = "COM1";
|
||||||
|
protected int BaudRate = 9600;
|
||||||
|
|
||||||
|
private Queue<byte[]> req_buffer = new Queue<byte[]>();
|
||||||
|
|
||||||
|
//Generate event when answer is received
|
||||||
|
public delegate void AnswerEventHandler<SerialEventArgs>(object sender, SerialEventArgs e);
|
||||||
|
public event AnswerEventHandler<FeedbackEventArgs> AnswerReceived;//событие получены данные в ответ на запрос
|
||||||
|
|
||||||
|
//Generate event when handshake is occurred
|
||||||
|
public delegate void HandShakeHandler(object sender, EventArgs e);
|
||||||
|
public event HandShakeHandler HandShakeOccurred;//событие полетник ответил на запрос HELLO
|
||||||
|
|
||||||
|
//Generate event when monitoring telegram is received
|
||||||
|
public delegate void MonitoringEventHandler<MonitoringEventArgs>(object sender, MonitoringEventArgs e);
|
||||||
|
public event MonitoringEventHandler<MonitoringEventArgs> MonitoringItemsReceived;//событие получены данные мониторинга
|
||||||
|
|
||||||
|
Models.Telemetry telemetry = Models.Telemetry.Instance;
|
||||||
|
abstract public Task Open();
|
||||||
|
abstract public void Close();
|
||||||
|
abstract protected void sendData(byte[] data);
|
||||||
|
abstract public bool IsOpen();
|
||||||
|
abstract public void CloseConnection();
|
||||||
|
abstract public Task StartReadingAsync(object? client = null);
|
||||||
|
|
||||||
|
abstract public void setCommParams(iCommParams commParams);
|
||||||
|
|
||||||
|
abstract protected void ProcessCommand(int cmd, int slot, byte[] data, int offset, int len);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обрабатывает входящий поток данных, при обнаружении ECSAPE_END байта декодирует данные, проверяет контрольную сумму и запускает обработку команды
|
||||||
|
/// </summary>
|
||||||
|
protected void data_extract()
|
||||||
|
{
|
||||||
|
byte b = new byte();
|
||||||
|
while (dataQueue.TryDequeue(out b))
|
||||||
|
{
|
||||||
|
if (b == ESCAPE_END)
|
||||||
|
{//END BYTE IS RECEIVED
|
||||||
|
isTimeout = false;
|
||||||
|
byte[] unscape = EscapeSeqToBytes(rx_buf.ToArray());
|
||||||
|
uint checksum = crc32(unscape, unscape.Length - 4);
|
||||||
|
uint re_checksum = BitConverter.ToUInt32(unscape, unscape.Length - 4);
|
||||||
|
if (re_checksum == checksum)
|
||||||
|
{
|
||||||
|
//Parse telegram
|
||||||
|
int cmd = BitConverter.ToInt32(unscape, 0);
|
||||||
|
int slot = BitConverter.ToInt32(unscape, 4);
|
||||||
|
int len = BitConverter.ToInt32(unscape, 8);
|
||||||
|
int offset = BitConverter.ToInt32(unscape, 12);
|
||||||
|
byte[] data = new byte[len];
|
||||||
|
Debug.WriteLine($"cmd = {cmd} *** slot = {slot} *** offset = {offset} *** len = {len}");
|
||||||
|
if(cmd == TELE_CMD_WR)Array.Copy(unscape, 16, data, 0, len);
|
||||||
|
ProcessCommand(cmd, slot, data, offset, len);
|
||||||
|
|
||||||
|
waitingForResponse = false;
|
||||||
|
timeout.Stop();
|
||||||
|
sendNextRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (b == ESCAPE_BEGIN)
|
||||||
|
{//START BYTE IS RECEIVED
|
||||||
|
rx_buf.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{//FILLING BUFFER
|
||||||
|
rx_buf.Add(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
//**********************************************************************************************
|
||||||
|
//*************************************** REQUESTS BLOCK ***************************************
|
||||||
|
//**********************************************************************************************
|
||||||
|
|
||||||
|
public void getPIDs()
|
||||||
|
{
|
||||||
|
//отправить наборы ПИДов
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_ONCE, 1000, new byte[0], 0, 4 * 9));
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_ONCE, 1001, new byte[0], 0, 4 * 9));
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_ONCE, 1002, new byte[0], 0, 4 * 9));
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_ONCE, 1003, new byte[0], 0, 4 * 9));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopMonitoring()
|
||||||
|
{
|
||||||
|
//остановить мониторинг
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_MON_OFF, 0, new byte[0], 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startMonitoring()
|
||||||
|
{
|
||||||
|
//начать мониторинг
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_MON_ON, 0, new byte[0], 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMonitoringItem(int slot, int offset)
|
||||||
|
{
|
||||||
|
//добавить элемент из массива мониторинга по адресу
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_MON_ADD, slot, new byte[0], offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddMonitoringItem(string name)
|
||||||
|
{
|
||||||
|
//добавить элемент из массива мониторинга по имени
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_MON_ADD, new byte[0], name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveMonitoringItem(int id)
|
||||||
|
{
|
||||||
|
//удалить элемент из массива мониторинга (len == id)
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_MON_REMOVE, 0, new byte[0], id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveMonitoringItems()
|
||||||
|
{
|
||||||
|
//удалить все элементы из массива мониторинга
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_RD_MON_REMOVEALL, 0, new byte[0], 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendFloats(int slot, float[] sp)
|
||||||
|
{
|
||||||
|
//Записать массив чисел с плавающей точкой
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_WR, slot, sp, 0, sp.Length * 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMotorsControl()
|
||||||
|
{
|
||||||
|
//Отправляет задание на моторы в полетник. Тот в ответ посылает актуальные скорости на моторах
|
||||||
|
//В offset передается количество моторов
|
||||||
|
putRequest(prepareTelegram(TELE_CMD_MOTORS_CTRL, Telemetry.MOTORS_SP_ADDRESS, telemetry.motor_sp, 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Считает контрольную сумму CRC32
|
||||||
|
/// </summary>
|
||||||
|
public uint crc32(byte[] data, int length)
|
||||||
|
{
|
||||||
|
uint crc = 0xFFFFFFFF; // Начальное значение CRC
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
crc ^= (uint)data[i] << 24; // XOR с текущим байтом
|
||||||
|
|
||||||
|
for (int j = 0; j < 8; j++)
|
||||||
|
{
|
||||||
|
if ((uint)(crc & 0x80000000) != 0)
|
||||||
|
{
|
||||||
|
crc = (crc << 1) ^ CRC32_POLY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
public byte[] prepareTelegram<T>(int cmd, T[] load, string var_name)
|
||||||
|
{
|
||||||
|
VarAddress va = telemetry.getVarAdress(var_name);
|
||||||
|
return prepareTelegram(cmd, va.slot, load, va.offset, va.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Подготавливает данные для отправки, кодируя их в ESCAPE-последовательность
|
||||||
|
/// </summary>
|
||||||
|
public byte[] prepareTelegram<T>(int cmd, int slot, T[] load, int offset, int len = 0)
|
||||||
|
{
|
||||||
|
byte[] byteload = DataArrayToBytes(load);
|
||||||
|
int total_len = 20 + byteload.Length;//cmd[4 bytes] + slot[4 bytes] + len[4 bytes] + offset[4 bytes] + load[len bytes]
|
||||||
|
byte[] data = new byte[total_len];
|
||||||
|
|
||||||
|
//Construct telegram
|
||||||
|
data[0] = (byte)(0xFF & cmd);
|
||||||
|
data[1] = (byte)(0xFF & (cmd >> 8));
|
||||||
|
data[2] = (byte)(0xFF & (cmd >> 16));
|
||||||
|
data[3] = (byte)(0xFF & (cmd >> 24));
|
||||||
|
|
||||||
|
data[4] = (byte)(0xFF & slot);
|
||||||
|
data[5] = (byte)(0xFF & (slot >> 8));
|
||||||
|
data[6] = (byte)(0xFF & (slot >> 16));
|
||||||
|
data[7] = (byte)(0xFF & (slot >> 24));
|
||||||
|
|
||||||
|
int l = 0;
|
||||||
|
if (cmd == TELE_CMD_WR) l = byteload.Length;
|
||||||
|
else l = len;
|
||||||
|
|
||||||
|
data[8] = (byte)(0xFF & l);
|
||||||
|
data[9] = (byte)(0xFF & (l >> 8));
|
||||||
|
data[10] = (byte)(0xFF & (l >> 16));
|
||||||
|
data[11] = (byte)(0xFF & (l >> 24));
|
||||||
|
|
||||||
|
data[12] = (byte)(0xFF & offset);
|
||||||
|
data[13] = (byte)(0xFF & (offset >> 8));
|
||||||
|
data[14] = (byte)(0xFF & (offset >> 16));
|
||||||
|
data[15] = (byte)(0xFF & (offset >> 24));
|
||||||
|
|
||||||
|
if (byteload.Length > 0)
|
||||||
|
{
|
||||||
|
//Copy data
|
||||||
|
Array.Copy(byteload, 0, data, 16, byteload.Length);
|
||||||
|
}
|
||||||
|
//CRC32
|
||||||
|
uint checksum = crc32(data, total_len - 4);
|
||||||
|
data[total_len - 4] = (byte)(0xFF & checksum);
|
||||||
|
data[total_len - 3] = (byte)(0xFF & (checksum >> 8));
|
||||||
|
data[total_len - 2] = (byte)(0xFF & (checksum >> 16));
|
||||||
|
data[total_len - 1] = (byte)(0xFF & (checksum >> 24));
|
||||||
|
|
||||||
|
byte[] escape = BytesToEscapeSeq(data);
|
||||||
|
byte[] ret = new byte[escape.Length + 2];
|
||||||
|
Array.Copy(escape, 0, ret, 1, escape.Length);
|
||||||
|
ret[0] = ESCAPE_BEGIN;
|
||||||
|
ret[ret.Length - 1] = ESCAPE_END;
|
||||||
|
//Array.Copy(ret, saving_request, ret.Length);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертирует массив bool/byte/int/float в массив байт. Создает новый массив.
|
||||||
|
/// </summary>
|
||||||
|
byte[] DataArrayToBytes<T>(T[] data)
|
||||||
|
{
|
||||||
|
if (data == null) return new byte[0];
|
||||||
|
List<byte> ret = new List<byte>();
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
{
|
||||||
|
if (typeof(T) == typeof(float))
|
||||||
|
{
|
||||||
|
ret.AddRange(BitConverter.GetBytes((float)(object)data[i]));
|
||||||
|
}
|
||||||
|
else if (typeof(T) == typeof(int))
|
||||||
|
{
|
||||||
|
ret.AddRange(BitConverter.GetBytes((int)(object)data[i]));
|
||||||
|
}
|
||||||
|
else if (typeof(T) == typeof(byte))
|
||||||
|
{
|
||||||
|
ret.Add((byte)(object)data[i]);
|
||||||
|
}
|
||||||
|
else if (typeof(T) == typeof(bool))
|
||||||
|
{
|
||||||
|
bool t = (bool)(object)data[i];
|
||||||
|
if (t) ret.Add(1);
|
||||||
|
else ret.Add(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертирует массив байт в ESCAPE-последовательность.
|
||||||
|
/// </summary>
|
||||||
|
public byte[] BytesToEscapeSeq(byte[] data)
|
||||||
|
{
|
||||||
|
List<byte> ret = new List<byte>();
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
{
|
||||||
|
if ((data[i] == ESCAPE_BEGIN) || (data[i] == ESCAPE_CHAR) || (data[i] == ESCAPE_END))
|
||||||
|
{
|
||||||
|
ret.Add(ESCAPE_CHAR);
|
||||||
|
ret.Add((byte)(data[i] - 0x0E));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret.Add(data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конвертирует ESCAPE-последовательность в массив байт.
|
||||||
|
/// </summary>
|
||||||
|
public byte[] EscapeSeqToBytes(byte[] EscSeq)
|
||||||
|
{
|
||||||
|
List<byte> ret = new List<byte>();
|
||||||
|
for (int i = 0; i < EscSeq.Length; i++)
|
||||||
|
{
|
||||||
|
//if ((EscSeq[i] == ESCAPE_BEGIN) || (EscSeq[i] == ESCAPE_CHAR) || (EscSeq[i] == ESCAPE_END))
|
||||||
|
if (EscSeq[i] == ESCAPE_CHAR)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
ret.Add((byte)(EscSeq[i] + 0x0E));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret.Add(EscSeq[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestExit()
|
||||||
|
{
|
||||||
|
//запрос на закрытие приложения, отправляем команду на очистку массива мониторинга и ждем ответ, либо таймаут,
|
||||||
|
//после чего приложение закрывается
|
||||||
|
RemoveMonitoringItems();
|
||||||
|
exitPending = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавляет данные в очередь ожидания отправки.
|
||||||
|
/// </summary>
|
||||||
|
public void putRequest(byte[] request)
|
||||||
|
{
|
||||||
|
//добавить в очередь или отправить(если очередь пуста) пакет в порт
|
||||||
|
lock (lock_obj_put)
|
||||||
|
{
|
||||||
|
if (waitingForResponse)
|
||||||
|
{
|
||||||
|
req_buffer.Enqueue(request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRequest(request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Толкает данные непосредственно в очередь отправки.
|
||||||
|
/// </summary>
|
||||||
|
protected void sendRequest(byte[] request)
|
||||||
|
{
|
||||||
|
//отправка пакета
|
||||||
|
//waitingForResponse = true;
|
||||||
|
if (IsOpen())
|
||||||
|
{
|
||||||
|
sendData(request);
|
||||||
|
}
|
||||||
|
timeout.Stop();
|
||||||
|
timeout.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вытягивает данные из очереди ожидания непосредственно в очередь отправки.
|
||||||
|
/// </summary>
|
||||||
|
protected void sendNextRequest()
|
||||||
|
{
|
||||||
|
//вытащить из очереди пакет и отправить в порт
|
||||||
|
waitingForResponse = false;
|
||||||
|
if (req_buffer.Count > 0)
|
||||||
|
{
|
||||||
|
sendRequest(req_buffer.Dequeue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Копирует входящие данные в очередь.
|
||||||
|
/// </summary>
|
||||||
|
protected void EnqueueData(byte[] data, int len)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
dataQueue.Enqueue(data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearReqQueue()
|
||||||
|
{
|
||||||
|
req_buffer.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnAnswerReceived(string answer, int id)
|
||||||
|
{
|
||||||
|
AnswerReceived?.Invoke(this, new FeedbackEventArgs(answer, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnHandShakeOccurred()
|
||||||
|
{
|
||||||
|
HandShakeOccurred?.Invoke(this, new EventArgs());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnMonitoringItemsReceived(float[] data)
|
||||||
|
{
|
||||||
|
MonitoringItemsReceived?.Invoke(this, new MonitoringEventArgs(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FeedbackEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public string Answer { get; set; }
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public FeedbackEventArgs(string answer, int id)
|
||||||
|
{
|
||||||
|
Answer = answer;
|
||||||
|
Id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MonitoringEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public float[] Data { get; set; }
|
||||||
|
|
||||||
|
public MonitoringEventArgs(float[] data)
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +1,25 @@
|
|||||||
using System;
|
using DroneData;
|
||||||
using System.Collections.Generic;
|
using System.Diagnostics.Metrics;
|
||||||
using System.Linq;
|
using System.Drawing;
|
||||||
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DroneClient
|
namespace DroneClient
|
||||||
{
|
{
|
||||||
internal class Drone
|
internal class Drone
|
||||||
{
|
{
|
||||||
public struct DataOut
|
|
||||||
{
|
|
||||||
public float AccX, AccY, AccZ;
|
|
||||||
public float GyrX, GyrY, GyrZ;
|
|
||||||
public float PosX, PosY;
|
|
||||||
public float LaserRange;
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct DataIn
|
public float AccX, AccY, AccZ;
|
||||||
{
|
public float GyrX, GyrY, GyrZ;
|
||||||
public float MotorUL, MotorUR, MotorDL, MotorDR;
|
public uint TimeAcc, TimeGyr;
|
||||||
}
|
|
||||||
|
public float PosX, PosY;
|
||||||
|
public float LaserRange;
|
||||||
|
public uint TimeRange;
|
||||||
|
|
||||||
|
public Vector2 OF = Vector2.Zero;
|
||||||
|
|
||||||
|
public float MotorUL, MotorUR, MotorDL, MotorDR;
|
||||||
|
|
||||||
public static byte[] getBytes(object data)
|
public static byte[] getBytes(object data)
|
||||||
{
|
{
|
||||||
@ -63,5 +62,273 @@ 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[]? RecvDataOF(byte[] data)
|
||||||
|
{
|
||||||
|
DroneData.DataOF of = (DroneData.DataOF)fromBytes(data, typeof(DroneData.DataOF));
|
||||||
|
|
||||||
|
OF.X = of.X;
|
||||||
|
OF.Y = of.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.DataOF:
|
||||||
|
{
|
||||||
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
return RecvDataOF(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;
|
||||||
|
|
||||||
|
DroneData.DataHead of = new DroneData.DataHead();
|
||||||
|
of.Size = DroneData.DataHead.StrLen;
|
||||||
|
of.Mode = DroneData.DataMode.Request;
|
||||||
|
of.Type = DroneData.DataType.DataOF;
|
||||||
|
|
||||||
|
List<byte[]> list = new List<byte[]>();
|
||||||
|
|
||||||
|
list.Add(getBytes(acc));
|
||||||
|
list.Add(getBytes(gyr));
|
||||||
|
list.Add(getBytes(range));
|
||||||
|
list.Add(getBytes(local));
|
||||||
|
list.Add(getBytes(of));
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,28 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="images\connect.ico">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Update="images\disconnect.ico">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
123
DroneClient/DroneData.cs
Normal file
123
DroneClient/DroneData.cs
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
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, DataBar = 1006, DataOF = 1007,
|
||||||
|
|
||||||
|
// Input
|
||||||
|
DataMotor4 = 2001, DataMotor6 = 2002,
|
||||||
|
|
||||||
|
// State
|
||||||
|
DataQuat = 3001,
|
||||||
|
};
|
||||||
|
|
||||||
|
public struct DataHead
|
||||||
|
{
|
||||||
|
public int Size;
|
||||||
|
|
||||||
|
public DataMode Mode;
|
||||||
|
public DataType Type;
|
||||||
|
|
||||||
|
public uint Time; // Общее время
|
||||||
|
|
||||||
|
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; // Последнее время изменения данных
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataAcc));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataGyr
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Gyr;
|
||||||
|
|
||||||
|
public uint Time; // Последнее время изменения данных
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataGyr));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataMag
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Mag;
|
||||||
|
|
||||||
|
public uint Time; // Последнее время изменения данных
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataRange
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float LiDAR; // Датчик посадки
|
||||||
|
|
||||||
|
public uint Time; // Последнее время изменения данных
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataRange));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataLocal
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public XYZ Local; // Локальные координаты
|
||||||
|
|
||||||
|
public uint Time; // Последнее время изменения данных
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataBar
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float Pressure; // Давление
|
||||||
|
|
||||||
|
public uint Time; // Последнее время изменения данных
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataBar));
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct DataOF
|
||||||
|
{
|
||||||
|
public DataHead Head;
|
||||||
|
public float X, Y; // Угловой сдвиг
|
||||||
|
|
||||||
|
public uint Time; // Последнее время изменения данных
|
||||||
|
|
||||||
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataOF));
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
1139
DroneClient/FormMain.Designer.cs
generated
1139
DroneClient/FormMain.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -1,154 +1,280 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using static DroneSimulator.NetClient;
|
using static DroneSimulator.NetClient;
|
||||||
using DroneClient;
|
using DroneClient;
|
||||||
|
using TelemetryIO.Models;
|
||||||
|
using TelemetryIO;
|
||||||
|
using DroneClient.Models;
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator
|
||||||
{
|
{
|
||||||
public partial class Form_Main : Form
|
public partial class Form_Main : Form
|
||||||
{
|
|
||||||
private NetClient netClient = new NetClient();
|
|
||||||
|
|
||||||
public Form_Main()
|
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
private NetClient netClient = new NetClient();
|
||||||
}
|
private Telemetry telemetry = Telemetry.Instance;
|
||||||
|
private MonitorContainer monitoring = MonitorContainer.Instance;
|
||||||
|
private System.Windows.Forms.Timer copyDataTimer = new System.Windows.Forms.Timer();
|
||||||
|
private System.Windows.Forms.Timer MonitoringTimer = new System.Windows.Forms.Timer();
|
||||||
|
TelemetryServer tele_server;
|
||||||
|
string connectIco = Path.Combine(Application.StartupPath, "Images", "connect.ico");
|
||||||
|
string disconnectIco = Path.Combine(Application.StartupPath, "Images", "disconnect.ico");
|
||||||
|
|
||||||
private void ConnectionCallback(object o)
|
public Form_Main()
|
||||||
{
|
|
||||||
ConnectData data = (ConnectData)o;
|
|
||||||
|
|
||||||
if (!data.Connect)
|
|
||||||
{
|
|
||||||
Invoke((MethodInvoker)delegate
|
|
||||||
{
|
{
|
||||||
button_Connect.Text = "Connect";
|
InitializeComponent();
|
||||||
button_Connect.BackColor = Color.Transparent;
|
tele_server = new TelemetryServer();
|
||||||
MessageBox.Show("Connection closed");
|
if (Path.Exists(connectIco)) TeleClientStatusPicture.Image = Image.FromFile(disconnectIco);
|
||||||
});
|
}
|
||||||
|
|
||||||
return;
|
private void Tele_server_OnTeleClientDisconnected(object? sender, EventArgs e)
|
||||||
}
|
{
|
||||||
|
if (TeleClientStatusPicture.InvokeRequired)
|
||||||
|
{
|
||||||
|
TeleClientStatusPicture.Invoke(new Action(() => { if (Path.Exists(connectIco)) TeleClientStatusPicture.Image = Image.FromFile(disconnectIco); }));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Path.Exists(connectIco)) TeleClientStatusPicture.Image = Image.FromFile(disconnectIco);
|
||||||
|
}
|
||||||
|
monitoring.resetMonitorContainer();
|
||||||
|
}
|
||||||
|
|
||||||
byte[] send = Drone.getBytes(sendDrone);
|
private void Tele_server_OnTeleClientСonnected(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (TeleClientStatusPicture.InvokeRequired)
|
||||||
|
{
|
||||||
|
TeleClientStatusPicture.Invoke(new Action(() => { if (Path.Exists(connectIco)) TeleClientStatusPicture.Image = Image.FromFile(connectIco); }));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (Path.Exists(connectIco)) TeleClientStatusPicture.Image = Image.FromFile(connectIco);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data.Server.Send(send);
|
private void MonitoringTimer_Tick(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (monitoring.isMonitor == 1)
|
||||||
|
{
|
||||||
|
byte[] load = new byte[monitoring.monitorFillLevel * sizeof(float)];
|
||||||
|
for (int i = 0; i < monitoring.monitorFillLevel; i++)
|
||||||
|
{
|
||||||
|
int slot = monitoring.monitorItems[i].slotNo;
|
||||||
|
int offset = monitoring.monitorItems[i].offset;
|
||||||
|
int len = monitoring.monitorItems[i].len;
|
||||||
|
if(len == 0)continue;
|
||||||
|
Array.Copy(telemetry.getSlot(slot, offset, len), 0, load, i * sizeof(float), sizeof(float));
|
||||||
|
}
|
||||||
|
if (tele_server != null)
|
||||||
|
{
|
||||||
|
tele_server.putRequest(tele_server.prepareTelegram(BaseCommHandler.TELE_CMD_RD_MON_ON, 0, load, 0, load.Length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CopyDataTimer_Tick(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
/*if (dataDrone != null)
|
||||||
|
{
|
||||||
|
float[] imu = { dataDrone.AccX, dataDrone.AccY, dataDrone.AccZ, dataDrone.GyrX, dataDrone.GyrY, dataDrone.GyrZ };
|
||||||
|
Array.Copy(imu, telemetry.imu, 6);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (monitoring.isMonitor == 1) MonitoringTimer.Start();
|
||||||
|
else MonitoringTimer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConnectionCallback(object o)
|
||||||
|
{
|
||||||
|
ConnectData data = (ConnectData)o;
|
||||||
|
|
||||||
|
if (!data.Connect)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Invoke((MethodInvoker)delegate
|
||||||
|
{
|
||||||
|
button_Connect.Text = "Connect";
|
||||||
|
button_Connect.BackColor = Color.Transparent;
|
||||||
|
MessageBox.Show("Connection closed");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Drone dataDrone = new Drone();
|
||||||
|
|
||||||
|
private void ReceiveCallback(object o)
|
||||||
|
{
|
||||||
|
ReceiveData data = (ReceiveData)o;
|
||||||
|
|
||||||
|
List<byte[]?>? send = dataDrone.DataStream(data.Buffer, data.Size);
|
||||||
|
|
||||||
|
if (send == null) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (byte[]? b in send)
|
||||||
|
{
|
||||||
|
if (b != null) data.Server?.Send(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button_Connect_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var done = netClient.Connect(textBox_Server_Addr.Text, (int)numericUpDown_Server_Port.Value, ConnectionCallback, ReceiveCallback);
|
||||||
|
|
||||||
|
switch (done)
|
||||||
|
{
|
||||||
|
case NetClient.ClientState.Error:
|
||||||
|
{
|
||||||
|
MessageBox.Show("Error connecting to server");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NetClient.ClientState.Connected:
|
||||||
|
{
|
||||||
|
button_Connect.Text = "Disconnect";
|
||||||
|
button_Connect.BackColor = Color.LimeGreen;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NetClient.ClientState.Stop:
|
||||||
|
{
|
||||||
|
button_Connect.Text = "Connect";
|
||||||
|
button_Connect.BackColor = Color.Transparent;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (done != NetClient.ClientState.Connected) return;
|
||||||
|
|
||||||
|
|
||||||
|
copyDataTimer.Interval = 10;
|
||||||
|
copyDataTimer.Tick += CopyDataTimer_Tick;
|
||||||
|
tele_server.setCommParams(new TCPCommParams("", (int)TeleServerPortCtrl.Value));
|
||||||
|
var t = Task.Run(() => tele_server.Open());
|
||||||
|
tele_server.OnTeleClientConnected += Tele_server_OnTeleClientСonnected;
|
||||||
|
tele_server.OnTeleClientDisconnected += Tele_server_OnTeleClientDisconnected;
|
||||||
|
MonitoringTimer.Interval = 25;
|
||||||
|
MonitoringTimer.Tick += MonitoringTimer_Tick;
|
||||||
|
copyDataTimer.Start();
|
||||||
|
button1.BackColor = Color.LimeGreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
|
{
|
||||||
|
netClient?.Close();
|
||||||
|
netClient = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void timer_Test_Tick(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
label_Acc_X.Text = dataDrone.AccX.ToString();
|
||||||
|
label_Acc_Y.Text = dataDrone.AccY.ToString();
|
||||||
|
label_Acc_Z.Text = dataDrone.AccZ.ToString();
|
||||||
|
|
||||||
|
label_time_acc.Text = dataDrone.TimeAcc.ToString();
|
||||||
|
|
||||||
|
label_Gyr_X.Text = dataDrone.GyrX.ToString();
|
||||||
|
label_Gyr_Y.Text = dataDrone.GyrY.ToString();
|
||||||
|
label_Gyr_Z.Text = dataDrone.GyrZ.ToString();
|
||||||
|
|
||||||
|
label_time_gyr.Text = dataDrone.TimeGyr.ToString();
|
||||||
|
|
||||||
|
float[] imu = { dataDrone.AccX, dataDrone.AccY, dataDrone.AccZ, dataDrone.GyrX, dataDrone.GyrY, dataDrone.GyrZ };
|
||||||
|
Array.Copy(imu, telemetry.imu, 6);
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
float[] pos = { dataDrone.PosX, dataDrone.PosY, dataDrone.LaserRange };
|
||||||
|
Array.Copy(pos, telemetry.pos, 3);
|
||||||
|
|
||||||
|
label_OF_X.Text = dataDrone.OF.X.ToString();
|
||||||
|
label_OF_Y.Text = dataDrone.OF.Y.ToString();
|
||||||
|
|
||||||
|
label_time_of.Text = dataDrone.TimeRange.ToString();
|
||||||
|
|
||||||
|
float[] of = { dataDrone.OF.X, dataDrone.OF.Y };
|
||||||
|
Array.Copy(of, telemetry.of, 2);
|
||||||
|
|
||||||
|
if (monitoring.isMonitor == 1) MonitoringTimer.Start();
|
||||||
|
else MonitoringTimer.Stop();
|
||||||
|
|
||||||
|
netClient.SendData(dataDrone.SendReqest());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void trackBar_Power_Scroll(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
float pow = (float)trackBar_Power.Value / 100;
|
||||||
|
|
||||||
|
label_Pow.Text = pow.ToString();
|
||||||
|
|
||||||
|
dataDrone.MotorUL = dataDrone.MotorUR = dataDrone.MotorDL = dataDrone.MotorDR = pow;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button_UU_MouseDown(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
float pow = ((float)trackBar_Value.Value) / 10.0f;
|
||||||
|
|
||||||
|
if (sender == button_UU)
|
||||||
|
{
|
||||||
|
dataDrone.MotorUL -= pow; dataDrone.MotorUR -= pow;
|
||||||
|
dataDrone.MotorDL += pow; dataDrone.MotorDR += pow;
|
||||||
|
}
|
||||||
|
if (sender == button_DD)
|
||||||
|
{
|
||||||
|
dataDrone.MotorUL += pow; dataDrone.MotorUR += pow;
|
||||||
|
dataDrone.MotorDL -= pow; dataDrone.MotorDR -= pow;
|
||||||
|
}
|
||||||
|
if (sender == button_LL)
|
||||||
|
{
|
||||||
|
dataDrone.MotorUL -= pow; dataDrone.MotorUR += pow;
|
||||||
|
dataDrone.MotorDL -= pow; dataDrone.MotorDR += pow;
|
||||||
|
}
|
||||||
|
if (sender == button_RR)
|
||||||
|
{
|
||||||
|
dataDrone.MotorUL += pow; dataDrone.MotorUR -= pow;
|
||||||
|
dataDrone.MotorDL += pow; dataDrone.MotorDR -= pow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender == button_ML)
|
||||||
|
{
|
||||||
|
dataDrone.MotorUL -= pow; dataDrone.MotorUR += pow;
|
||||||
|
dataDrone.MotorDL += pow; dataDrone.MotorDR -= pow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender == button_MR)
|
||||||
|
{
|
||||||
|
dataDrone.MotorUL += pow; dataDrone.MotorUR -= pow;
|
||||||
|
dataDrone.MotorDL -= pow; dataDrone.MotorDR += pow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button_UU_MouseUp(object sender, MouseEventArgs e)
|
||||||
|
{
|
||||||
|
trackBar_Power_Scroll(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
copyDataTimer.Interval = 10;
|
||||||
|
copyDataTimer.Tick += CopyDataTimer_Tick;
|
||||||
|
tele_server.setCommParams(new TCPCommParams("", (int)TeleServerPortCtrl.Value));
|
||||||
|
var t = Task.Run(() => tele_server.Open());
|
||||||
|
tele_server.OnTeleClientConnected += Tele_server_OnTeleClientСonnected;
|
||||||
|
tele_server.OnTeleClientDisconnected += Tele_server_OnTeleClientDisconnected;
|
||||||
|
MonitoringTimer.Interval = 25;
|
||||||
|
MonitoringTimer.Tick += MonitoringTimer_Tick;
|
||||||
|
copyDataTimer.Start();
|
||||||
|
button1.BackColor = Color.LimeGreen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Drone.DataIn sendDrone;
|
|
||||||
|
|
||||||
Drone.DataOut recvDrone;
|
|
||||||
|
|
||||||
private void ReceiveCallback(object o)
|
|
||||||
{
|
|
||||||
ReceiveData data = (ReceiveData)o;
|
|
||||||
|
|
||||||
recvDrone = (Drone.DataOut)Drone.fromBytes(data.Buffer, typeof(Drone.DataOut));
|
|
||||||
|
|
||||||
byte[] send = Drone.getBytes(sendDrone);
|
|
||||||
|
|
||||||
try { data.Server.Send(send); }
|
|
||||||
catch { }
|
|
||||||
}
|
|
||||||
|
|
||||||
private void button_Connect_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
var done = netClient.Connect(textBox_Server_Addr.Text, (int)numericUpDown_Server_Port.Value, ConnectionCallback, ReceiveCallback);
|
|
||||||
|
|
||||||
switch (done)
|
|
||||||
{
|
|
||||||
case NetClient.ClientState.Error:
|
|
||||||
{
|
|
||||||
MessageBox.Show("Error connecting to server");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NetClient.ClientState.Connected:
|
|
||||||
{
|
|
||||||
button_Connect.Text = "Disconnect";
|
|
||||||
button_Connect.BackColor = Color.LimeGreen;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NetClient.ClientState.Stop:
|
|
||||||
{
|
|
||||||
button_Connect.Text = "Connect";
|
|
||||||
button_Connect.BackColor = Color.Transparent;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done != NetClient.ClientState.Connected) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Form_Main_FormClosing(object sender, FormClosingEventArgs e)
|
|
||||||
{
|
|
||||||
netClient?.Close();
|
|
||||||
netClient = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void timer_Test_Tick(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
label_Acc_X.Text = recvDrone.AccX.ToString();
|
|
||||||
label_Acc_Y.Text = recvDrone.AccY.ToString();
|
|
||||||
label_Acc_Z.Text = recvDrone.AccZ.ToString();
|
|
||||||
|
|
||||||
label_Gyr_X.Text = recvDrone.GyrX.ToString();
|
|
||||||
label_Gyr_Y.Text = recvDrone.GyrY.ToString();
|
|
||||||
label_Gyr_Z.Text = recvDrone.GyrZ.ToString();
|
|
||||||
|
|
||||||
label_Pos_X.Text = recvDrone.PosX.ToString();
|
|
||||||
label_Pos_Y.Text = recvDrone.PosY.ToString();
|
|
||||||
label_Pos_L.Text = recvDrone.LaserRange.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void trackBar_Power_Scroll(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
float pow = (float)trackBar_Power.Value / 100;
|
|
||||||
|
|
||||||
label_Pow.Text = pow.ToString();
|
|
||||||
|
|
||||||
sendDrone.MotorUL = sendDrone.MotorUR = sendDrone.MotorDL = sendDrone.MotorDR = pow;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void button_UU_MouseDown(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
if (sender == button_UU)
|
|
||||||
{
|
|
||||||
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR -= 0.1f;
|
|
||||||
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR += 0.1f;
|
|
||||||
}
|
|
||||||
if (sender == button_DD)
|
|
||||||
{
|
|
||||||
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR += 0.1f;
|
|
||||||
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR -= 0.1f;
|
|
||||||
}
|
|
||||||
if (sender == button_LL)
|
|
||||||
{
|
|
||||||
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR += 0.1f;
|
|
||||||
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR += 0.1f;
|
|
||||||
}
|
|
||||||
if (sender == button_RR)
|
|
||||||
{
|
|
||||||
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR -= 0.1f;
|
|
||||||
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR -= 0.1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender == button_ML)
|
|
||||||
{
|
|
||||||
sendDrone.MotorUL -= 0.1f; sendDrone.MotorUR += 0.1f;
|
|
||||||
sendDrone.MotorDL += 0.1f; sendDrone.MotorDR -= 0.1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sender == button_MR)
|
|
||||||
{
|
|
||||||
sendDrone.MotorUL += 0.1f; sendDrone.MotorUR -= 0.1f;
|
|
||||||
sendDrone.MotorDL -= 0.1f; sendDrone.MotorDR += 0.1f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void button_UU_MouseUp(object sender, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
trackBar_Power_Scroll(null, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
126
DroneClient/Models/MonitorContainer.cs
Normal file
126
DroneClient/Models/MonitorContainer.cs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelemetryIO;
|
||||||
|
|
||||||
|
namespace DroneClient.Models
|
||||||
|
{
|
||||||
|
public class monitorItem
|
||||||
|
{
|
||||||
|
public int slotNo = 0;
|
||||||
|
public int offset = 0;
|
||||||
|
public int len = 0;
|
||||||
|
public int id = 0;
|
||||||
|
|
||||||
|
public monitorItem()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public monitorItem(int slotNo, int offset, int len, int id)
|
||||||
|
{
|
||||||
|
this.slotNo = slotNo;
|
||||||
|
this.offset = offset;
|
||||||
|
this.len = len;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MonitorContainer
|
||||||
|
{
|
||||||
|
public const int monitorMaxFill = 32;
|
||||||
|
public int monitorFillLevel = 0;
|
||||||
|
public monitorItem[] monitorItems = new monitorItem[monitorMaxFill];
|
||||||
|
public int isMonitor = 0;
|
||||||
|
private static volatile MonitorContainer instance;
|
||||||
|
private static readonly object _lock = new object();
|
||||||
|
|
||||||
|
public static MonitorContainer Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new MonitorContainer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private MonitorContainer()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < monitorMaxFill; i++)
|
||||||
|
{
|
||||||
|
monitorItems[i] = new monitorItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetMonitorContainer()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < monitorMaxFill; i++)
|
||||||
|
{
|
||||||
|
monitorItems[i] = new monitorItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monitorPut(int slot, int offset, int len)
|
||||||
|
{
|
||||||
|
int ret_id = 0;
|
||||||
|
if (monitorFillLevel < monitorMaxFill)
|
||||||
|
{
|
||||||
|
monitorItems[monitorFillLevel].slotNo = slot;
|
||||||
|
monitorItems[monitorFillLevel].offset = offset;
|
||||||
|
monitorItems[monitorFillLevel].len = len;
|
||||||
|
monitorItems[monitorFillLevel].id = (slot << 8) + offset;
|
||||||
|
ret_id = monitorItems[monitorFillLevel].id;
|
||||||
|
monitorFillLevel++;
|
||||||
|
isMonitor = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int monitorRemove(int id)
|
||||||
|
{
|
||||||
|
int match = 0;
|
||||||
|
int ret_id = 0;
|
||||||
|
for (int i = 0; i < monitorMaxFill; i++)
|
||||||
|
{
|
||||||
|
if (monitorItems[i].id == id)
|
||||||
|
{
|
||||||
|
match = 1;
|
||||||
|
if (monitorFillLevel > 0) monitorFillLevel--;
|
||||||
|
ret_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match > 0)
|
||||||
|
{
|
||||||
|
if (monitorItems[i].len == 0) return ret_id;
|
||||||
|
if (i < 31)
|
||||||
|
{
|
||||||
|
monitorItems[i].id = monitorItems[i + 1].id;
|
||||||
|
monitorItems[i].offset = monitorItems[i + 1].offset;
|
||||||
|
monitorItems[i].slotNo = monitorItems[i + 1].slotNo;
|
||||||
|
monitorItems[i].len = monitorItems[i + 1].len;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
monitorItems[i].id = 0;
|
||||||
|
monitorItems[i].offset = 0;
|
||||||
|
monitorItems[i].slotNo = 0;
|
||||||
|
monitorItems[i].len = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
340
DroneClient/Models/Telemetry.cs
Normal file
340
DroneClient/Models/Telemetry.cs
Normal file
@ -0,0 +1,340 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace TelemetryIO.Models
|
||||||
|
{
|
||||||
|
public sealed class Telemetry
|
||||||
|
{
|
||||||
|
//Класс синглтон для хранения данных телеметрии
|
||||||
|
private static volatile Telemetry instance;
|
||||||
|
private static readonly object _lock = new object();
|
||||||
|
private Dictionary<string, VarAddress> dictMonitor = new Dictionary<string, VarAddress>();//Словарь адресов, для целей мониторинга
|
||||||
|
public string name = "_150";
|
||||||
|
public float[] raw_imu = new float[6];
|
||||||
|
public float[] imu = new float[6];
|
||||||
|
public float[] filtered_imu = new float[6];
|
||||||
|
public float[] g_integration = new float[3];
|
||||||
|
public float[] euler = new float[3];
|
||||||
|
public float[] quaternion = new float[4];
|
||||||
|
public float[] battery = new float[4];
|
||||||
|
public float[] motor_act = new float[8];
|
||||||
|
public float[] motor_sp = new float[8];
|
||||||
|
public float[] pid0 = new float[9];
|
||||||
|
public float[] pid1 = new float[9];
|
||||||
|
public float[] pid2 = new float[9];
|
||||||
|
public float[] pid3 = new float[9];
|
||||||
|
public float[] pos = new float[3];
|
||||||
|
public float[] of = new float[2];
|
||||||
|
|
||||||
|
private object _lockRW = new object();
|
||||||
|
|
||||||
|
private Telemetry() {
|
||||||
|
dictMonitor.Add("rawAx", new VarAddress(RAW_IMU_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("rawAy", new VarAddress(RAW_IMU_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("rawAz", new VarAddress(RAW_IMU_ADDRESS, 2));
|
||||||
|
dictMonitor.Add("rawGx", new VarAddress(RAW_IMU_ADDRESS, 3));
|
||||||
|
dictMonitor.Add("rawGy", new VarAddress(RAW_IMU_ADDRESS, 4));
|
||||||
|
dictMonitor.Add("rawGz", new VarAddress(RAW_IMU_ADDRESS, 5));
|
||||||
|
|
||||||
|
dictMonitor.Add("Ax", new VarAddress(IMU_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("Ay", new VarAddress(IMU_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("Az", new VarAddress(IMU_ADDRESS, 2));
|
||||||
|
dictMonitor.Add("Gx", new VarAddress(IMU_ADDRESS, 3));
|
||||||
|
dictMonitor.Add("Gy", new VarAddress(IMU_ADDRESS, 4));
|
||||||
|
dictMonitor.Add("Gz", new VarAddress(IMU_ADDRESS, 5));
|
||||||
|
|
||||||
|
dictMonitor.Add("filtered_Ax", new VarAddress(FILTERED_IMU_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("filtered_Ay", new VarAddress(FILTERED_IMU_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("filtered_Az", new VarAddress(FILTERED_IMU_ADDRESS, 2));
|
||||||
|
dictMonitor.Add("filtered_Gx", new VarAddress(FILTERED_IMU_ADDRESS, 3));
|
||||||
|
dictMonitor.Add("filtered_Gy", new VarAddress(FILTERED_IMU_ADDRESS, 4));
|
||||||
|
dictMonitor.Add("filtered_Gz", new VarAddress(FILTERED_IMU_ADDRESS, 5));
|
||||||
|
|
||||||
|
dictMonitor.Add("Gx_int", new VarAddress(G_INTEGRATION_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("Gy_int", new VarAddress(G_INTEGRATION_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("Gz_int", new VarAddress(G_INTEGRATION_ADDRESS, 2));
|
||||||
|
|
||||||
|
dictMonitor.Add("Euler.Phi", new VarAddress(EULER_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("Euler.Theta", new VarAddress(EULER_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("Euler.Psi", new VarAddress(EULER_ADDRESS, 2));
|
||||||
|
|
||||||
|
dictMonitor.Add("Qw", new VarAddress(Q_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("Qx", new VarAddress(Q_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("Qy", new VarAddress(Q_ADDRESS, 2));
|
||||||
|
dictMonitor.Add("Qz", new VarAddress(Q_ADDRESS, 3));
|
||||||
|
|
||||||
|
dictMonitor.Add("Battery[V]", new VarAddress(BAT_ADDRESS, 0));
|
||||||
|
|
||||||
|
dictMonitor.Add("motor0_Act", new VarAddress(MOTORS_ACT_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("motor1_Act", new VarAddress(MOTORS_ACT_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("motor2_Act", new VarAddress(MOTORS_ACT_ADDRESS, 2));
|
||||||
|
dictMonitor.Add("motor3_Act", new VarAddress(MOTORS_ACT_ADDRESS, 3));
|
||||||
|
dictMonitor.Add("motor4_Act", new VarAddress(MOTORS_ACT_ADDRESS, 4));
|
||||||
|
dictMonitor.Add("motor5_Act", new VarAddress(MOTORS_ACT_ADDRESS, 5));
|
||||||
|
dictMonitor.Add("motor6_Act", new VarAddress(MOTORS_ACT_ADDRESS, 6));
|
||||||
|
dictMonitor.Add("motor7_Act", new VarAddress(MOTORS_ACT_ADDRESS, 7));
|
||||||
|
|
||||||
|
dictMonitor.Add("Pos_X", new VarAddress(POS_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("Pos_Y", new VarAddress(POS_ADDRESS, 1));
|
||||||
|
dictMonitor.Add("Pos_L", new VarAddress(POS_ADDRESS, 2));
|
||||||
|
|
||||||
|
dictMonitor.Add("OF_X", new VarAddress(OF_ADDRESS, 0));
|
||||||
|
dictMonitor.Add("OF_Y", new VarAddress(OF_ADDRESS, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId(string name)
|
||||||
|
{
|
||||||
|
VarAddress var = dictMonitor[name];
|
||||||
|
if (var == null) return -1;
|
||||||
|
return (var.slot << 8) | var.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string getName(int id)
|
||||||
|
{
|
||||||
|
int slot = id >> 8;
|
||||||
|
int offset = id & 0xFF;
|
||||||
|
foreach(var element in dictMonitor)
|
||||||
|
{
|
||||||
|
if ((element.Value.slot == slot) && (element.Value.offset == offset)) return element.Key;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VarAddress getVarAdress(string name)
|
||||||
|
{
|
||||||
|
VarAddress ret;
|
||||||
|
dictMonitor.TryGetValue(name, out ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] getKeys()
|
||||||
|
{
|
||||||
|
return dictMonitor.Keys.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Telemetry Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if(instance == null)
|
||||||
|
{
|
||||||
|
lock(_lock)
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new Telemetry();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSlot(int slot, byte[] data, int offset, int len)
|
||||||
|
{
|
||||||
|
switch (slot)
|
||||||
|
{
|
||||||
|
case RAW_IMU_ADDRESS://RAW IMU
|
||||||
|
set_float(raw_imu, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IMU_ADDRESS://IMU
|
||||||
|
set_float(imu, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Q_ADDRESS://quaternion
|
||||||
|
set_float(quaternion, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case G_INTEGRATION_ADDRESS://quaternion
|
||||||
|
set_float(g_integration, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EULER_ADDRESS://quaternion
|
||||||
|
set_float(euler, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FILTERED_IMU_ADDRESS://IMU
|
||||||
|
set_float(filtered_imu, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BAT_ADDRESS://battery
|
||||||
|
set_float(battery, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOTORS_ACT_ADDRESS://motors act
|
||||||
|
set_float(motor_act, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MOTORS_SP_ADDRESS://motors act
|
||||||
|
set_float(motor_sp, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PID0_ADDRESS:
|
||||||
|
set_float(pid0, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PID1_ADDRESS:
|
||||||
|
set_float(pid1, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PID2_ADDRESS:
|
||||||
|
set_float(pid2, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PID3_ADDRESS:
|
||||||
|
set_float(pid3, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case POS_ADDRESS:
|
||||||
|
set_float(pos, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OF_ADDRESS:
|
||||||
|
set_float(of, data, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NAME_ADDRESS:
|
||||||
|
set_name(data);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getSlot(int slot, int offset, int len)
|
||||||
|
{
|
||||||
|
switch (slot)
|
||||||
|
{
|
||||||
|
case RAW_IMU_ADDRESS://RAW IMU
|
||||||
|
return get_float(raw_imu, offset, len);
|
||||||
|
|
||||||
|
case IMU_ADDRESS://IMU
|
||||||
|
return get_float(imu, offset, len);
|
||||||
|
|
||||||
|
case Q_ADDRESS://quaternion
|
||||||
|
return get_float(quaternion, offset, len);
|
||||||
|
|
||||||
|
case G_INTEGRATION_ADDRESS://quaternion
|
||||||
|
return get_float(g_integration, offset, len);
|
||||||
|
|
||||||
|
case EULER_ADDRESS://quaternion
|
||||||
|
return get_float(euler, offset, len);
|
||||||
|
|
||||||
|
case FILTERED_IMU_ADDRESS://IMU
|
||||||
|
return get_float(filtered_imu, offset, len);
|
||||||
|
|
||||||
|
case BAT_ADDRESS://battery
|
||||||
|
return get_float(battery, offset, len);
|
||||||
|
|
||||||
|
case MOTORS_ACT_ADDRESS://motors act
|
||||||
|
return get_float(motor_act, offset, len);
|
||||||
|
|
||||||
|
case MOTORS_SP_ADDRESS://motors act
|
||||||
|
return get_float(motor_sp, offset, len);
|
||||||
|
|
||||||
|
case PID0_ADDRESS:
|
||||||
|
return get_float(pid0, offset, len);
|
||||||
|
|
||||||
|
case PID1_ADDRESS:
|
||||||
|
return get_float(pid1, offset, len);
|
||||||
|
|
||||||
|
case PID2_ADDRESS:
|
||||||
|
return get_float(pid2, offset, len);
|
||||||
|
|
||||||
|
case PID3_ADDRESS:
|
||||||
|
return get_float(pid3, offset, len);
|
||||||
|
|
||||||
|
case POS_ADDRESS:
|
||||||
|
return get_float(pos, offset, len);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case OF_ADDRESS:
|
||||||
|
return get_float(of, offset, len);
|
||||||
|
|
||||||
|
case NAME_ADDRESS:
|
||||||
|
return Encoding.ASCII.GetBytes(name);
|
||||||
|
|
||||||
|
default:
|
||||||
|
byte[] data = new byte[0];
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void set_float(float[] dest, byte[] data, int offset, int len)
|
||||||
|
{
|
||||||
|
lock (_lockRW)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int)(len / 4); i++)
|
||||||
|
{
|
||||||
|
byte[] bs = new byte[4];
|
||||||
|
Array.Copy(data, i * 4, bs, 0, 4);
|
||||||
|
float f = BitConverter.ToSingle(bs, 0);
|
||||||
|
dest[offset + i] = f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] get_float(float[] source, int offset, int len)
|
||||||
|
{
|
||||||
|
lock (_lockRW)
|
||||||
|
{
|
||||||
|
byte[] bs = new byte[len];
|
||||||
|
Buffer.BlockCopy(source, offset * sizeof(float), bs, 0, len);
|
||||||
|
return bs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void set_name(byte[] data)
|
||||||
|
{
|
||||||
|
int len = data.Length;
|
||||||
|
if (len > 16) len = 16;
|
||||||
|
name = Encoding.ASCII.GetString(data, 0, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
public const int RAW_IMU_ADDRESS = 0;
|
||||||
|
public const int IMU_ADDRESS = 1;
|
||||||
|
public const int Q_ADDRESS = 2;
|
||||||
|
public const int G_INTEGRATION_ADDRESS = 3;
|
||||||
|
public const int EULER_ADDRESS = 4;
|
||||||
|
public const int FILTERED_IMU_ADDRESS = 5;
|
||||||
|
public const int POS_ADDRESS = 6;
|
||||||
|
public const int OF_ADDRESS = 7;
|
||||||
|
|
||||||
|
public const int BAT_ADDRESS = 50;
|
||||||
|
|
||||||
|
public const int MOTORS_ACT_ADDRESS = 100;
|
||||||
|
public const int MOTORS_SP_ADDRESS = 101;
|
||||||
|
|
||||||
|
public const int PID0_ADDRESS = 1000;
|
||||||
|
public const int PID1_ADDRESS = 1001;
|
||||||
|
public const int PID2_ADDRESS = 1002;
|
||||||
|
public const int PID3_ADDRESS = 1003;
|
||||||
|
|
||||||
|
public const int NAME_ADDRESS = 9999;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class VarAddress
|
||||||
|
{
|
||||||
|
public int slot = 0;
|
||||||
|
public int offset = 0;
|
||||||
|
public int length = 0;
|
||||||
|
|
||||||
|
public VarAddress()
|
||||||
|
{
|
||||||
|
slot = offset = 0;
|
||||||
|
length = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VarAddress(int slot, int offset, int length = 4)
|
||||||
|
{
|
||||||
|
this.slot = slot;
|
||||||
|
this.offset = offset;
|
||||||
|
this.length = length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,4 @@
|
|||||||
using System;
|
using System.Net.Sockets;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator
|
||||||
@ -31,6 +26,7 @@ namespace DroneSimulator
|
|||||||
public byte[] buffer = new byte[size];
|
public byte[] buffer = new byte[size];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool Connected = false;
|
||||||
private Socket? ServerSocket = null;
|
private Socket? ServerSocket = null;
|
||||||
private ServerData DataServer = new ServerData();
|
private ServerData DataServer = new ServerData();
|
||||||
|
|
||||||
@ -43,10 +39,9 @@ namespace DroneSimulator
|
|||||||
|
|
||||||
public ClientState Connect(string Addr, int Port, ClientCallback Connection, ClientCallback Receive)
|
public ClientState Connect(string Addr, int Port, ClientCallback Connection, ClientCallback Receive)
|
||||||
{
|
{
|
||||||
if (ServerSocket != null)
|
if (Connected)
|
||||||
{
|
{
|
||||||
ServerSocket.Close();
|
Close();
|
||||||
ServerSocket = null;
|
|
||||||
return ClientState.Stop;
|
return ClientState.Stop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,24 +51,26 @@ namespace DroneSimulator
|
|||||||
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(Addr), Port);
|
IPEndPoint ep = new IPEndPoint(IPAddress.Parse(Addr), Port);
|
||||||
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
|
||||||
try
|
try { ServerSocket.Connect(ep); }
|
||||||
{
|
catch { ServerSocket.Close(); return ClientState.Error; }
|
||||||
ServerSocket.Connect(ep);
|
|
||||||
}
|
Connected = true;
|
||||||
catch { ServerSocket.Close(); ServerSocket = null; return ClientState.Error; }
|
|
||||||
|
|
||||||
ConnectionCallback(new ConnectData { Connect = true, Server = ServerSocket });
|
ConnectionCallback(new ConnectData { Connect = true, Server = ServerSocket });
|
||||||
|
|
||||||
ReceiveData receiveData = new ReceiveData { Buffer = DataServer.buffer, Size = ServerData.size, Server = ServerSocket };
|
ReceiveData receiveData = new ReceiveData { Buffer = DataServer.buffer, Size = ServerData.size, Server = ServerSocket };
|
||||||
ServerSocket.BeginReceive(DataServer.buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), receiveData);
|
|
||||||
|
try { ServerSocket.BeginReceive(DataServer.buffer, 0, ServerData.size, 0, new AsyncCallback(ReadCallback), receiveData); }
|
||||||
|
catch { }
|
||||||
|
|
||||||
return ClientState.Connected;
|
return ClientState.Connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
|
try { ServerSocket?.Shutdown(SocketShutdown.Both); } catch { }
|
||||||
ServerSocket?.Close();
|
ServerSocket?.Close();
|
||||||
ServerSocket = null;
|
Connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadCallback(IAsyncResult ar)
|
public void ReadCallback(IAsyncResult ar)
|
||||||
@ -82,23 +79,28 @@ namespace DroneSimulator
|
|||||||
if (cd == null) return;
|
if (cd == null) return;
|
||||||
|
|
||||||
int bytes = 0;
|
int bytes = 0;
|
||||||
try { bytes = ServerSocket.EndReceive(ar); }
|
try { bytes = ServerSocket.EndReceive(ar); } catch { }
|
||||||
catch { }
|
|
||||||
|
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
{
|
{
|
||||||
ServerSocket?.Close();
|
ServerSocket?.Close();
|
||||||
|
|
||||||
if (ServerSocket != null) ConnectionCallback(new ConnectData { Connect = false, Server = null });
|
Connected = false;
|
||||||
|
|
||||||
ServerSocket = null;
|
if (ServerSocket != null) ConnectionCallback(new ConnectData { Connect = false, Server = null });
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiveCallback(new ReceiveData { Buffer = cd.Buffer, Size = bytes, Server = ServerSocket });
|
ReceiveCallback(new ReceiveData { Buffer = cd.Buffer, Size = bytes, Server = ServerSocket });
|
||||||
|
|
||||||
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 { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendData(byte[] data)
|
||||||
|
{
|
||||||
|
try { ServerSocket?.Send(data); } catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
63
DroneClient/Properties/Resources.Designer.cs
generated
Normal file
63
DroneClient/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// Этот код создан программой.
|
||||||
|
// Исполняемая версия:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||||
|
// повторной генерации кода.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace DroneClient.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||||
|
/// </summary>
|
||||||
|
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||||
|
// с помощью такого средства, как ResGen или Visual Studio.
|
||||||
|
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||||
|
// с параметром /str или перестройте свой проект VS.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
internal class Resources {
|
||||||
|
|
||||||
|
private static global::System.Resources.ResourceManager resourceMan;
|
||||||
|
|
||||||
|
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||||
|
|
||||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||||
|
internal Resources() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||||
|
get {
|
||||||
|
if (object.ReferenceEquals(resourceMan, null)) {
|
||||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DroneClient.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||||
|
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
DroneClient/Properties/Resources.resx
Normal file
120
DroneClient/Properties/Resources.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
3
DroneClient/README.md
Normal file
3
DroneClient/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Client
|
||||||
|
|
||||||
|
Образец клиента для подключения к симулятору.
|
258
DroneClient/TelemetryServer.cs
Normal file
258
DroneClient/TelemetryServer.cs
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
using DroneClient.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using TelemetryIO;
|
||||||
|
using TelemetryIO.Models;
|
||||||
|
|
||||||
|
namespace TelemetryIO
|
||||||
|
{
|
||||||
|
internal class TelemetryServer : TelemetryIO.BaseCommHandler
|
||||||
|
{
|
||||||
|
ConcurrentQueue<byte[]> sendQueue = new ConcurrentQueue<byte[]>();
|
||||||
|
Telemetry telemetry = Telemetry.Instance;
|
||||||
|
MonitorContainer monitoring = MonitorContainer.Instance;
|
||||||
|
private bool isClientConnected = false;
|
||||||
|
|
||||||
|
public event EventHandler OnTeleClientConnected = delegate { };
|
||||||
|
public event EventHandler OnTeleClientDisconnected = delegate { };
|
||||||
|
|
||||||
|
public bool isClientAvailable { get { return isClientConnected; } }
|
||||||
|
|
||||||
|
public TelemetryServer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void CloseConnection()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool IsOpen()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async override Task Open()
|
||||||
|
{
|
||||||
|
await StartServerAsync();
|
||||||
|
//Console.ReadLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartServerAsync()
|
||||||
|
{
|
||||||
|
var listener = new TcpListener(IPAddress.Any, Port);
|
||||||
|
listener.Start();
|
||||||
|
Console.WriteLine("Server is running");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
//if (isClientConnected) await Task.Delay(25);
|
||||||
|
var client = await listener.AcceptTcpClientAsync();
|
||||||
|
StrikeOnTeleClientConnected();
|
||||||
|
isClientConnected = true;
|
||||||
|
Debug.WriteLine("Client is connected");
|
||||||
|
//this.client = client;
|
||||||
|
var readTask = StartReadingAsync(client);
|
||||||
|
var writeTask = SendMessageAsync(client);
|
||||||
|
await readTask;
|
||||||
|
await writeTask;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex) when (IsNetworkError(ex))
|
||||||
|
{
|
||||||
|
// Специальная обработка сетевых ошибок
|
||||||
|
Debug.WriteLine($"Ошибка при запуске сервера: {ex.Message}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("An error occurred: " + ex.Message);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
listener.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SendMessageAsync(TcpClient c)
|
||||||
|
{
|
||||||
|
if (c.GetStream() == null || !c.Connected)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Not connected to server");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (c.Connected)
|
||||||
|
{
|
||||||
|
if (sendQueue.TryDequeue(out byte[] buffer))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await c.GetStream().WriteAsync(buffer, 0, buffer.Length);
|
||||||
|
Debug.WriteLine($"Sent");
|
||||||
|
}
|
||||||
|
catch (IOException ex) when (IsNetworkError(ex))
|
||||||
|
{
|
||||||
|
// Специальная обработка сетевых ошибок
|
||||||
|
Debug.WriteLine($"Клиент отключился: {ex.Message}");
|
||||||
|
HandleDisconnectedClient(c);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Error sending message: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async override Task StartReadingAsync(object C)
|
||||||
|
{
|
||||||
|
TcpClient client;
|
||||||
|
if (C is TcpClient) client = (TcpClient)C;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using NetworkStream stream = client.GetStream();
|
||||||
|
|
||||||
|
while (client.Connected)
|
||||||
|
{
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length);
|
||||||
|
//string response = await reader.ReadLineAsync();
|
||||||
|
if (bytesRead > 0)
|
||||||
|
{
|
||||||
|
EnqueueData(buffer, bytesRead);
|
||||||
|
}
|
||||||
|
data_extract();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException ex) when (IsNetworkError(ex))
|
||||||
|
{
|
||||||
|
// Специальная обработка сетевых ошибок
|
||||||
|
Debug.WriteLine($"Клиент отключился: {ex.Message}");
|
||||||
|
HandleDisconnectedClient(client);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"Error sending message: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ProcessCommand(int cmd, int slot, byte[] data, int offset, int len)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(@"server cmd = " + cmd);
|
||||||
|
|
||||||
|
switch (cmd)
|
||||||
|
{
|
||||||
|
case TELE_CMD_HELLO:
|
||||||
|
byte[] load = telemetry.getSlot(cmd, offset, len);
|
||||||
|
putRequest(prepareTelegram(cmd, 0, load, 0, load.Length));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELE_CMD_RD_ONCE:
|
||||||
|
byte[] load1 = telemetry.getSlot(slot, offset, len);
|
||||||
|
putRequest(prepareTelegram(cmd, slot, load1, offset, load1.Length));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELE_CMD_WR:
|
||||||
|
setData(data, slot, offset, len);
|
||||||
|
sendVoidAnswer(TELE_CMD_WR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELE_CMD_RD_MON_ON:
|
||||||
|
monitoring.isMonitor = 1;
|
||||||
|
sendVoidAnswer(TELE_CMD_RD_MON_ON);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELE_CMD_RD_MON_OFF:
|
||||||
|
monitoring.isMonitor = 0;
|
||||||
|
sendVoidAnswer(TELE_CMD_RD_MON_OFF);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELE_CMD_RD_MON_ADD:
|
||||||
|
int id = monitoring.monitorPut(slot, offset, 4);
|
||||||
|
sendIntAnswer(TELE_CMD_RD_MON_ADD, id);
|
||||||
|
monitoring.isMonitor = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TELE_CMD_RD_MON_REMOVE:
|
||||||
|
id = monitoring.monitorRemove(offset);//in this case offset == id
|
||||||
|
if(monitoring.monitorFillLevel == 0)monitoring.isMonitor = 0;//if monitor_fill_level == 0 there is no item to monitor
|
||||||
|
if (monitoring.isMonitor > 0) sendIntAnswer(TELE_CMD_RD_MON_REMOVE, id);
|
||||||
|
else sendVoidAnswer(TELE_CMD_RD_MON_REMOVEALL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setData(byte[] load, int slot, int offset, int len)
|
||||||
|
{
|
||||||
|
telemetry.setSlot(slot, load, offset, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendVoidAnswer(int command)
|
||||||
|
{
|
||||||
|
putRequest(prepareTelegram(command, 0, new byte[0], 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendIntAnswer(int command, int param)
|
||||||
|
{
|
||||||
|
putRequest(prepareTelegram(command, 0, new byte[0], param));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void sendData(byte[] data)
|
||||||
|
{
|
||||||
|
sendQueue.Enqueue(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void setCommParams(iCommParams commParams)
|
||||||
|
{
|
||||||
|
if (commParams.GetType() == typeof(TCPCommParams))
|
||||||
|
{
|
||||||
|
var comm = (TCPCommParams)commParams;
|
||||||
|
IP = comm.IP;
|
||||||
|
Port = comm.Port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleDisconnectedClient(TcpClient client)
|
||||||
|
{
|
||||||
|
isClientConnected = false;
|
||||||
|
StrikeOnTeleClientDisconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsNetworkError(Exception ex)
|
||||||
|
{
|
||||||
|
// Проверяем типичные сетевые ошибки при разрыве соединения
|
||||||
|
return ex is IOException
|
||||||
|
|| ex is SocketException
|
||||||
|
|| ex.InnerException is SocketException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StrikeOnTeleClientConnected()
|
||||||
|
{
|
||||||
|
OnTeleClientConnected?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StrikeOnTeleClientDisconnected()
|
||||||
|
{
|
||||||
|
OnTeleClientDisconnected?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeTarget": {
|
|
||||||
"name": ".NETCoreApp,Version=v9.0",
|
|
||||||
"signature": ""
|
|
||||||
},
|
|
||||||
"compilationOptions": {},
|
|
||||||
"targets": {
|
|
||||||
".NETCoreApp,Version=v9.0": {
|
|
||||||
"DroneClient/1.0.0": {
|
|
||||||
"runtime": {
|
|
||||||
"DroneClient.dll": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"libraries": {
|
|
||||||
"DroneClient/1.0.0": {
|
|
||||||
"type": "project",
|
|
||||||
"serviceable": false,
|
|
||||||
"sha512": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeOptions": {
|
|
||||||
"tfm": "net9.0",
|
|
||||||
"frameworks": [
|
|
||||||
{
|
|
||||||
"name": "Microsoft.NETCore.App",
|
|
||||||
"version": "9.0.0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Microsoft.WindowsDesktop.App",
|
|
||||||
"version": "9.0.0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"configProperties": {
|
|
||||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
|
|
||||||
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
BIN
DroneClient/images/connect.ico
Normal file
BIN
DroneClient/images/connect.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 102 KiB |
BIN
DroneClient/images/disconnect.ico
Normal file
BIN
DroneClient/images/disconnect.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 101 KiB |
@ -1,4 +0,0 @@
|
|||||||
// <autogenerated />
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
|
|
@ -1,25 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// Этот код создан программой.
|
|
||||||
// Исполняемая версия:4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
|
||||||
// повторной генерации кода.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("DroneClient")]
|
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
|
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("DroneClient")]
|
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("DroneClient")]
|
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
|
||||||
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows7.0")]
|
|
||||||
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows7.0")]
|
|
||||||
|
|
||||||
// Создано классом WriteCodeFragment MSBuild.
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
372de9fd6d36597e50cdb2250f48b9cb0d5e8e1a2d1e568b83e287afe9580301
|
|
@ -1,22 +0,0 @@
|
|||||||
is_global = true
|
|
||||||
build_property.ApplicationManifest =
|
|
||||||
build_property.StartupObject =
|
|
||||||
build_property.ApplicationDefaultFont =
|
|
||||||
build_property.ApplicationHighDpiMode =
|
|
||||||
build_property.ApplicationUseCompatibleTextRendering =
|
|
||||||
build_property.ApplicationVisualStyles =
|
|
||||||
build_property.TargetFramework = net9.0-windows
|
|
||||||
build_property.TargetPlatformMinVersion = 7.0
|
|
||||||
build_property.UsingMicrosoftNETSdkWeb =
|
|
||||||
build_property.ProjectTypeGuids =
|
|
||||||
build_property.InvariantGlobalization =
|
|
||||||
build_property.PlatformNeutralAssembly =
|
|
||||||
build_property.EnforceExtendedAnalyzerRules =
|
|
||||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
|
||||||
build_property.RootNamespace = DroneClient
|
|
||||||
build_property.ProjectDir = D:\CPL\Simulator\DroneClient\DroneClient\
|
|
||||||
build_property.EnableComHosting =
|
|
||||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
|
||||||
build_property.CsWinRTUseWindowsUIXamlProjections = false
|
|
||||||
build_property.EffectiveAnalysisLevelStyle = 9.0
|
|
||||||
build_property.EnableCodeStyleSeverity =
|
|
@ -1,10 +0,0 @@
|
|||||||
// <auto-generated/>
|
|
||||||
global using global::System;
|
|
||||||
global using global::System.Collections.Generic;
|
|
||||||
global using global::System.Drawing;
|
|
||||||
global using global::System.IO;
|
|
||||||
global using global::System.Linq;
|
|
||||||
global using global::System.Net.Http;
|
|
||||||
global using global::System.Threading;
|
|
||||||
global using global::System.Threading.Tasks;
|
|
||||||
global using global::System.Windows.Forms;
|
|
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
01e86f1c7bc139724ab77bc57845e8da30f3f593b41b11317ce8867d8fb43c28
|
|
@ -1,32 +0,0 @@
|
|||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.GenerateResource.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.GeneratedMSBuildEditorConfig.editorconfig
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfoInputs.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfo.cs
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.CoreCompileInputs.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.exe
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.deps.json
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.runtimeconfig.json
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\bin\Debug\net9.0-windows\DroneClient.pdb
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\refint\DroneClient.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.pdb
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\DroneClient.genruntimeconfig.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneClient\obj\Debug\net9.0-windows\ref\DroneClient.dll
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.exe
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.deps.json
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.runtimeconfig.json
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.dll
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\bin\Debug\net9.0-windows\DroneClient.pdb
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.GenerateResource.cache
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.GeneratedMSBuildEditorConfig.editorconfig
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfoInputs.cache
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.AssemblyInfo.cs
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.csproj.CoreCompileInputs.cache
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.dll
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\refint\DroneClient.dll
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.pdb
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\DroneClient.genruntimeconfig.cache
|
|
||||||
D:\CPL\Simulator\DroneClient\DroneClient\obj\Debug\net9.0-windows\ref\DroneClient.dll
|
|
Binary file not shown.
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeTarget": {
|
|
||||||
"name": ".NETCoreApp,Version=v9.0",
|
|
||||||
"signature": ""
|
|
||||||
},
|
|
||||||
"compilationOptions": {},
|
|
||||||
"targets": {
|
|
||||||
".NETCoreApp,Version=v9.0": {}
|
|
||||||
},
|
|
||||||
"libraries": {}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeOptions": {
|
|
||||||
"tfm": "net9.0",
|
|
||||||
"frameworks": [
|
|
||||||
{
|
|
||||||
"name": "Microsoft.NETCore.App",
|
|
||||||
"version": "9.0.0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Microsoft.WindowsDesktop.App",
|
|
||||||
"version": "9.0.0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"additionalProbingPaths": [
|
|
||||||
"C:\\Users\\Дана\\.dotnet\\store\\|arch|\\|tfm|",
|
|
||||||
"C:\\Users\\Дана\\.nuget\\packages",
|
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
|
||||||
],
|
|
||||||
"configProperties": {
|
|
||||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
|
|
||||||
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false,
|
|
||||||
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
812e26f7e032de5fb2d5301fec24f483552f39e0a38ac0c052cba2ffa3a73bbd
|
|
Binary file not shown.
@ -1,25 +0,0 @@
|
|||||||
//------------------------------------------------------------------------------
|
|
||||||
// <auto-generated>
|
|
||||||
// This code was generated by a tool.
|
|
||||||
// Runtime Version:4.0.30319.42000
|
|
||||||
//
|
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
|
||||||
// the code is regenerated.
|
|
||||||
// </auto-generated>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("DroneSimulator")]
|
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
|
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("DroneSimulator")]
|
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("DroneSimulator")]
|
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
|
||||||
[assembly: System.Runtime.Versioning.TargetPlatformAttribute("Windows7.0")]
|
|
||||||
[assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("Windows7.0")]
|
|
||||||
|
|
||||||
// Generated by the MSBuild WriteCodeFragment class.
|
|
||||||
|
|
@ -1 +0,0 @@
|
|||||||
7f461f329c2aabe3c068a957f4f02cdcdb168c359c556cd0c46598798ec3c65d
|
|
Binary file not shown.
@ -1,22 +0,0 @@
|
|||||||
is_global = true
|
|
||||||
build_property.ApplicationManifest =
|
|
||||||
build_property.StartupObject =
|
|
||||||
build_property.ApplicationDefaultFont =
|
|
||||||
build_property.ApplicationHighDpiMode =
|
|
||||||
build_property.ApplicationUseCompatibleTextRendering =
|
|
||||||
build_property.ApplicationVisualStyles =
|
|
||||||
build_property.TargetFramework = net9.0-windows
|
|
||||||
build_property.TargetPlatformMinVersion = 7.0
|
|
||||||
build_property.UsingMicrosoftNETSdkWeb =
|
|
||||||
build_property.ProjectTypeGuids =
|
|
||||||
build_property.InvariantGlobalization =
|
|
||||||
build_property.PlatformNeutralAssembly =
|
|
||||||
build_property.EnforceExtendedAnalyzerRules =
|
|
||||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
|
||||||
build_property.RootNamespace = DroneSimulator
|
|
||||||
build_property.ProjectDir = D:\Files\Main\Projects\Fly\DroneClient\
|
|
||||||
build_property.EnableComHosting =
|
|
||||||
build_property.EnableGeneratedComInterfaceComImportInterop =
|
|
||||||
build_property.CsWinRTUseWindowsUIXamlProjections = false
|
|
||||||
build_property.EffectiveAnalysisLevelStyle = 9.0
|
|
||||||
build_property.EnableCodeStyleSeverity =
|
|
@ -1,10 +0,0 @@
|
|||||||
// <auto-generated/>
|
|
||||||
global using global::System;
|
|
||||||
global using global::System.Collections.Generic;
|
|
||||||
global using global::System.Drawing;
|
|
||||||
global using global::System.IO;
|
|
||||||
global using global::System.Linq;
|
|
||||||
global using global::System.Net.Http;
|
|
||||||
global using global::System.Threading;
|
|
||||||
global using global::System.Threading.Tasks;
|
|
||||||
global using global::System.Windows.Forms;
|
|
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
051ffb89f1ee627ab3b9aaef920afd665a18f0f3c3fe82852812d5c6608dcb30
|
|
@ -1,32 +0,0 @@
|
|||||||
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
|
|
||||||
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
|
|
||||||
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
|
|
||||||
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
|
|
||||||
R:\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form1.resources
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
|
|
||||||
R:\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.exe
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.deps.json
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.runtimeconfig.json
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\bin\Debug\net9.0-windows\DroneSimulator.pdb
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.GenerateResource.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.GeneratedMSBuildEditorConfig.editorconfig
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfoInputs.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.AssemblyInfo.cs
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.csproj.CoreCompileInputs.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\refint\DroneSimulator.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.pdb
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.genruntimeconfig.cache
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\ref\DroneSimulator.dll
|
|
||||||
D:\Files\Main\Projects\Fly\DroneSimulator\obj\Debug\net9.0-windows\DroneSimulator.Form_Main.resources
|
|
Binary file not shown.
@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeTarget": {
|
|
||||||
"name": ".NETCoreApp,Version=v9.0",
|
|
||||||
"signature": ""
|
|
||||||
},
|
|
||||||
"compilationOptions": {},
|
|
||||||
"targets": {
|
|
||||||
".NETCoreApp,Version=v9.0": {}
|
|
||||||
},
|
|
||||||
"libraries": {}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"runtimeOptions": {
|
|
||||||
"tfm": "net9.0",
|
|
||||||
"frameworks": [
|
|
||||||
{
|
|
||||||
"name": "Microsoft.NETCore.App",
|
|
||||||
"version": "9.0.0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Microsoft.WindowsDesktop.App",
|
|
||||||
"version": "9.0.0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"additionalProbingPaths": [
|
|
||||||
"C:\\Users\\USER\\.dotnet\\store\\|arch|\\|tfm|",
|
|
||||||
"C:\\Users\\USER\\.nuget\\packages",
|
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
|
||||||
],
|
|
||||||
"configProperties": {
|
|
||||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
|
|
||||||
"CSWINRT_USE_WINDOWS_UI_XAML_PROJECTIONS": false,
|
|
||||||
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
@ -1 +0,0 @@
|
|||||||
42c9c47684404b6458665b5db1d77e8e1563e0e910b9607df810cd1011407bfc
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,76 +0,0 @@
|
|||||||
{
|
|
||||||
"format": 1,
|
|
||||||
"restore": {
|
|
||||||
"D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj": {}
|
|
||||||
},
|
|
||||||
"projects": {
|
|
||||||
"D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"restore": {
|
|
||||||
"projectUniqueName": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
|
|
||||||
"projectName": "DroneClient",
|
|
||||||
"projectPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
|
|
||||||
"packagesPath": "C:\\Users\\Дана\\.nuget\\packages\\",
|
|
||||||
"outputPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\obj\\",
|
|
||||||
"projectStyle": "PackageReference",
|
|
||||||
"fallbackFolders": [
|
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
|
||||||
],
|
|
||||||
"configFilePaths": [
|
|
||||||
"C:\\Users\\Дана\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
|
||||||
],
|
|
||||||
"originalTargetFrameworks": [
|
|
||||||
"net9.0-windows"
|
|
||||||
],
|
|
||||||
"sources": {
|
|
||||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
|
||||||
"https://api.nuget.org/v3/index.json": {}
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"net9.0-windows7.0": {
|
|
||||||
"targetAlias": "net9.0-windows",
|
|
||||||
"projectReferences": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"warningProperties": {
|
|
||||||
"warnAsError": [
|
|
||||||
"NU1605"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"restoreAuditProperties": {
|
|
||||||
"enableAudit": "true",
|
|
||||||
"auditLevel": "low",
|
|
||||||
"auditMode": "direct"
|
|
||||||
},
|
|
||||||
"SdkAnalysisLevel": "9.0.200"
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"net9.0-windows7.0": {
|
|
||||||
"targetAlias": "net9.0-windows",
|
|
||||||
"imports": [
|
|
||||||
"net461",
|
|
||||||
"net462",
|
|
||||||
"net47",
|
|
||||||
"net471",
|
|
||||||
"net472",
|
|
||||||
"net48",
|
|
||||||
"net481"
|
|
||||||
],
|
|
||||||
"assetTargetFallback": true,
|
|
||||||
"warn": true,
|
|
||||||
"frameworkReferences": {
|
|
||||||
"Microsoft.NETCore.App": {
|
|
||||||
"privateAssets": "all"
|
|
||||||
},
|
|
||||||
"Microsoft.WindowsDesktop.App.WindowsForms": {
|
|
||||||
"privateAssets": "none"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
|
||||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
|
||||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
|
||||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
|
||||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
|
||||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Дана\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
|
||||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
|
||||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.13.2</NuGetToolVersion>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
|
||||||
<SourceRoot Include="C:\Users\Дана\.nuget\packages\" />
|
|
||||||
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
|
@ -1,76 +0,0 @@
|
|||||||
{
|
|
||||||
"format": 1,
|
|
||||||
"restore": {
|
|
||||||
"D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj": {}
|
|
||||||
},
|
|
||||||
"projects": {
|
|
||||||
"D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"restore": {
|
|
||||||
"projectUniqueName": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj",
|
|
||||||
"projectName": "DroneSimulator",
|
|
||||||
"projectPath": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\DroneSimulator.csproj",
|
|
||||||
"packagesPath": "C:\\Users\\USER\\.nuget\\packages\\",
|
|
||||||
"outputPath": "D:\\Files\\Main\\Projects\\Fly\\DroneClient\\obj\\",
|
|
||||||
"projectStyle": "PackageReference",
|
|
||||||
"fallbackFolders": [
|
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
|
||||||
],
|
|
||||||
"configFilePaths": [
|
|
||||||
"C:\\Users\\USER\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
|
||||||
],
|
|
||||||
"originalTargetFrameworks": [
|
|
||||||
"net9.0-windows"
|
|
||||||
],
|
|
||||||
"sources": {
|
|
||||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
|
||||||
"https://api.nuget.org/v3/index.json": {}
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"net9.0-windows7.0": {
|
|
||||||
"targetAlias": "net9.0-windows",
|
|
||||||
"projectReferences": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"warningProperties": {
|
|
||||||
"warnAsError": [
|
|
||||||
"NU1605"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"restoreAuditProperties": {
|
|
||||||
"enableAudit": "true",
|
|
||||||
"auditLevel": "low",
|
|
||||||
"auditMode": "direct"
|
|
||||||
},
|
|
||||||
"SdkAnalysisLevel": "9.0.200"
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"net9.0-windows7.0": {
|
|
||||||
"targetAlias": "net9.0-windows",
|
|
||||||
"imports": [
|
|
||||||
"net461",
|
|
||||||
"net462",
|
|
||||||
"net47",
|
|
||||||
"net471",
|
|
||||||
"net472",
|
|
||||||
"net48",
|
|
||||||
"net481"
|
|
||||||
],
|
|
||||||
"assetTargetFallback": true,
|
|
||||||
"warn": true,
|
|
||||||
"frameworkReferences": {
|
|
||||||
"Microsoft.NETCore.App": {
|
|
||||||
"privateAssets": "all"
|
|
||||||
},
|
|
||||||
"Microsoft.WindowsDesktop.App.WindowsForms": {
|
|
||||||
"privateAssets": "none"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
|
||||||
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
|
|
||||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
|
||||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
|
||||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
|
||||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\USER\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
|
|
||||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
|
||||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.13.2</NuGetToolVersion>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
|
||||||
<SourceRoot Include="C:\Users\USER\.nuget\packages\" />
|
|
||||||
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
|
||||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
|
|
@ -1,82 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 3,
|
|
||||||
"targets": {
|
|
||||||
"net9.0-windows7.0": {}
|
|
||||||
},
|
|
||||||
"libraries": {},
|
|
||||||
"projectFileDependencyGroups": {
|
|
||||||
"net9.0-windows7.0": []
|
|
||||||
},
|
|
||||||
"packageFolders": {
|
|
||||||
"C:\\Users\\Дана\\.nuget\\packages\\": {},
|
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"restore": {
|
|
||||||
"projectUniqueName": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
|
|
||||||
"projectName": "DroneClient",
|
|
||||||
"projectPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
|
|
||||||
"packagesPath": "C:\\Users\\Дана\\.nuget\\packages\\",
|
|
||||||
"outputPath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\obj\\",
|
|
||||||
"projectStyle": "PackageReference",
|
|
||||||
"fallbackFolders": [
|
|
||||||
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
|
|
||||||
],
|
|
||||||
"configFilePaths": [
|
|
||||||
"C:\\Users\\Дана\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
|
|
||||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
|
||||||
],
|
|
||||||
"originalTargetFrameworks": [
|
|
||||||
"net9.0-windows"
|
|
||||||
],
|
|
||||||
"sources": {
|
|
||||||
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
|
|
||||||
"https://api.nuget.org/v3/index.json": {}
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"net9.0-windows7.0": {
|
|
||||||
"targetAlias": "net9.0-windows",
|
|
||||||
"projectReferences": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"warningProperties": {
|
|
||||||
"warnAsError": [
|
|
||||||
"NU1605"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"restoreAuditProperties": {
|
|
||||||
"enableAudit": "true",
|
|
||||||
"auditLevel": "low",
|
|
||||||
"auditMode": "direct"
|
|
||||||
},
|
|
||||||
"SdkAnalysisLevel": "9.0.200"
|
|
||||||
},
|
|
||||||
"frameworks": {
|
|
||||||
"net9.0-windows7.0": {
|
|
||||||
"targetAlias": "net9.0-windows",
|
|
||||||
"imports": [
|
|
||||||
"net461",
|
|
||||||
"net462",
|
|
||||||
"net47",
|
|
||||||
"net471",
|
|
||||||
"net472",
|
|
||||||
"net48",
|
|
||||||
"net481"
|
|
||||||
],
|
|
||||||
"assetTargetFallback": true,
|
|
||||||
"warn": true,
|
|
||||||
"frameworkReferences": {
|
|
||||||
"Microsoft.NETCore.App": {
|
|
||||||
"privateAssets": "all"
|
|
||||||
},
|
|
||||||
"Microsoft.WindowsDesktop.App.WindowsForms": {
|
|
||||||
"privateAssets": "none"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.201/PortableRuntimeIdentifierGraph.json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 2,
|
|
||||||
"dgSpecHash": "ddOSNwF62rQ=",
|
|
||||||
"success": true,
|
|
||||||
"projectFilePath": "D:\\CPL\\Simulator\\DroneClient\\DroneClient\\DroneClient.csproj",
|
|
||||||
"expectedPackageFiles": [],
|
|
||||||
"logs": []
|
|
||||||
}
|
|
106
DroneClientCpp/Client.cpp
Normal file
106
DroneClientCpp/Client.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Client.h"
|
||||||
|
|
||||||
|
Client::Client(const char* ip, int port) : running(true), Connection(INVALID_SOCKET)
|
||||||
|
{
|
||||||
|
if (!ConnectToServer(ip, port))
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to connect to server!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Client::~Client()
|
||||||
|
{
|
||||||
|
Stop();
|
||||||
|
CloseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Client::ConnectToServer(const char* ip, int port)
|
||||||
|
{
|
||||||
|
WSAData wsaData;
|
||||||
|
WORD DLLVersion = MAKEWORD(2, 2);
|
||||||
|
|
||||||
|
if (WSAStartup(DLLVersion, &wsaData) != 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: WSAStartup failed" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOCKADDR_IN addr;
|
||||||
|
inet_pton(AF_INET, ip, &addr.sin_addr);
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
|
||||||
|
Connection = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
|
if (Connection == INVALID_SOCKET)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Failed to create socket" << std::endl;
|
||||||
|
WSACleanup();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connect(Connection, (SOCKADDR*)&addr, sizeof(addr)) != 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Failed to connect to server" << std::endl;
|
||||||
|
closesocket(Connection);
|
||||||
|
WSACleanup();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::CloseConnection()
|
||||||
|
{
|
||||||
|
if (Connection != INVALID_SOCKET)
|
||||||
|
{
|
||||||
|
closesocket(Connection);
|
||||||
|
WSACleanup();
|
||||||
|
Connection = INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::ReceiveHandler()
|
||||||
|
{
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
DataIn tempData;
|
||||||
|
int result = recv(Connection, (char*)&tempData, sizeof(tempData), 0);
|
||||||
|
|
||||||
|
if (result <= 0)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Connection lost (recv failed)" << std::endl;
|
||||||
|
running = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(dataMutex);
|
||||||
|
dataIn = tempData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::SendHandler()
|
||||||
|
{
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(dataMutex);
|
||||||
|
send(Connection, (char*)&dataOut, sizeof(dataOut), 0);
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::Start()
|
||||||
|
{
|
||||||
|
recvThread = std::thread(&Client::ReceiveHandler, this);
|
||||||
|
sendThread = std::thread(&Client::SendHandler, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Client::Stop()
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
if (recvThread.joinable()) recvThread.join();
|
||||||
|
if (sendThread.joinable()) sendThread.join();
|
||||||
|
}
|
44
DroneClientCpp/Client.h
Normal file
44
DroneClientCpp/Client.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <WinSock2.h>
|
||||||
|
#include <WS2tcpip.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#pragma comment(lib, "Ws2_32.lib")
|
||||||
|
|
||||||
|
class Client
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Client(const char* ip, int port);
|
||||||
|
~Client();
|
||||||
|
|
||||||
|
void Start(); // Запуск потоков
|
||||||
|
void Stop(); // Остановка потоков
|
||||||
|
struct DataIn
|
||||||
|
{
|
||||||
|
float AccX, AccY, AccZ;
|
||||||
|
float GyrX, GyrY, GyrZ;
|
||||||
|
float PosX, PosY, LaserRange;
|
||||||
|
} dataIn;
|
||||||
|
|
||||||
|
struct DataOut
|
||||||
|
{
|
||||||
|
float MotorUL, MotorUR, MotorDL, MotorDR;
|
||||||
|
} dataOut;
|
||||||
|
bool ConnectToServer(const char* ip, int port);
|
||||||
|
void CloseConnection();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::atomic<bool> running;
|
||||||
|
std::mutex dataMutex;
|
||||||
|
|
||||||
|
SOCKET Connection;
|
||||||
|
std::thread recvThread;
|
||||||
|
std::thread sendThread;
|
||||||
|
|
||||||
|
void ReceiveHandler();
|
||||||
|
void SendHandler();
|
||||||
|
};
|
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();
|
||||||
|
};
|
||||||
|
}
|
65
DroneClientCpp/DroneClient.h
Normal file
65
DroneClientCpp/DroneClient.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <vcclr.h>
|
||||||
|
|
||||||
|
#using <System.dll>
|
||||||
|
#using <mscorlib.dll>
|
||||||
|
|
||||||
|
using namespace System;
|
||||||
|
using namespace System::Runtime::InteropServices;
|
||||||
|
|
||||||
|
namespace DroneClient {
|
||||||
|
|
||||||
|
public ref class Drone
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
value struct DataOut
|
||||||
|
{
|
||||||
|
float AccX, AccY, AccZ;
|
||||||
|
float GyrX, GyrY, GyrZ;
|
||||||
|
float PosX, PosY;
|
||||||
|
float LaserRange;
|
||||||
|
};
|
||||||
|
|
||||||
|
value struct DataIn
|
||||||
|
{
|
||||||
|
float MotorUL, MotorUR, MotorDL, MotorDR;
|
||||||
|
};
|
||||||
|
|
||||||
|
static array<Byte>^ GetBytes(Object^ data)
|
||||||
|
{
|
||||||
|
int size = Marshal::SizeOf(data);
|
||||||
|
array<Byte>^ arr = gcnew array<Byte>(size);
|
||||||
|
|
||||||
|
IntPtr ptr = IntPtr::Zero;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ptr = Marshal::AllocHGlobal(size);
|
||||||
|
Marshal::StructureToPtr(data, ptr, true);
|
||||||
|
Marshal::Copy(ptr, arr, 0, size);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Marshal::FreeHGlobal(ptr);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object^ FromBytes(array<Byte>^ arr, Type^ type)
|
||||||
|
{
|
||||||
|
int size = Marshal::SizeOf(type);
|
||||||
|
IntPtr ptr = IntPtr::Zero;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ptr = Marshal::AllocHGlobal(size);
|
||||||
|
Marshal::Copy(arr, 0, ptr, size);
|
||||||
|
return Marshal::PtrToStructure(ptr, type);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Marshal::FreeHGlobal(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
28
DroneClientCpp/DroneClientCpp.sln
Normal file
28
DroneClientCpp/DroneClientCpp.sln
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.12.35527.113
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DroneClientCpp", "DroneClientCpp.vcxproj", "{690C304C-A70B-4B0F-BF61-8C51290BF444}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Debug|x86.Build.0 = Debug|Win32
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x64.Build.0 = Release|x64
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x86.ActiveCfg = Release|Win32
|
||||||
|
{690C304C-A70B-4B0F-BF61-8C51290BF444}.Release|x86.Build.0 = Release|Win32
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
141
DroneClientCpp/DroneClientCpp.vcxproj
Normal file
141
DroneClientCpp/DroneClientCpp.vcxproj
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
|
<ProjectGuid>{690C304C-A70B-4B0F-BF61-8C51290BF444}</ProjectGuid>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<Keyword>ManagedCProj</Keyword>
|
||||||
|
<RootNamespace>DroneClientCpp</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CLRSupport>true</CLRSupport>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup />
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies />
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Drone.cpp" />
|
||||||
|
<ClCompile Include="FormMain.cpp" />
|
||||||
|
<ClCompile Include="NetClient.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Drone.h" />
|
||||||
|
<ClInclude Include="DroneData.h" />
|
||||||
|
<ClInclude Include="FormMain.h">
|
||||||
|
<FileType>CppForm</FileType>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="NetClient.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="FormMain.resx">
|
||||||
|
<DependentUpon>FormMain.h</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
42
DroneClientCpp/DroneClientCpp.vcxproj.filters
Normal file
42
DroneClientCpp/DroneClientCpp.vcxproj.filters
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="Исходные файлы">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы заголовков">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="Файлы ресурсов">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="FormMain.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="NetClient.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Drone.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="FormMain.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="NetClient.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="DroneData.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Drone.h">
|
||||||
|
<Filter>Файлы заголовков</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
4
DroneClientCpp/DroneClientCpp.vcxproj.user
Normal file
4
DroneClientCpp/DroneClientCpp.vcxproj.user
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup />
|
||||||
|
</Project>
|
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);
|
||||||
|
};
|
||||||
|
}
|
12
DroneClientCpp/FormMain.cpp
Normal file
12
DroneClientCpp/FormMain.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "FormMain.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
using namespace DroneClientCpp;
|
||||||
|
|
||||||
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
|
||||||
|
Application::EnableVisualStyles();
|
||||||
|
Application::SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application::Run(gcnew FormMain);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
DroneClientCpp/FormMain.h
Normal file
BIN
DroneClientCpp/FormMain.h
Normal file
Binary file not shown.
126
DroneClientCpp/FormMain.resx
Normal file
126
DroneClientCpp/FormMain.resx
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>310, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
12
DroneClientCpp/MyForm.cpp
Normal file
12
DroneClientCpp/MyForm.cpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "MyForm.h"
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
using namespace DroneClientCpp;
|
||||||
|
|
||||||
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
|
||||||
|
Application::EnableVisualStyles();
|
||||||
|
Application::SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application::Run(gcnew MyForm);
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
DroneClientCpp/MyForm.h
Normal file
BIN
DroneClientCpp/MyForm.h
Normal file
Binary file not shown.
120
DroneClientCpp/MyForm.resx
Normal file
120
DroneClientCpp/MyForm.resx
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<root>
|
||||||
|
<!--
|
||||||
|
Microsoft ResX Schema
|
||||||
|
|
||||||
|
Version 2.0
|
||||||
|
|
||||||
|
The primary goals of this format is to allow a simple XML format
|
||||||
|
that is mostly human readable. The generation and parsing of the
|
||||||
|
various data types are done through the TypeConverter classes
|
||||||
|
associated with the data types.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
... ado.net/XML headers & schema ...
|
||||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||||
|
<resheader name="version">2.0</resheader>
|
||||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
|
</data>
|
||||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||||
|
<comment>This is a comment</comment>
|
||||||
|
</data>
|
||||||
|
|
||||||
|
There are any number of "resheader" rows that contain simple
|
||||||
|
name/value pairs.
|
||||||
|
|
||||||
|
Each data row contains a name, and value. The row also contains a
|
||||||
|
type or mimetype. Type corresponds to a .NET class that support
|
||||||
|
text/value conversion through the TypeConverter architecture.
|
||||||
|
Classes that don't support this are serialized and stored with the
|
||||||
|
mimetype set.
|
||||||
|
|
||||||
|
The mimetype is used for serialized objects, and tells the
|
||||||
|
ResXResourceReader how to depersist the object. This is currently not
|
||||||
|
extensible. For a given mimetype the value must be set accordingly:
|
||||||
|
|
||||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||||
|
that the ResXResourceWriter will generate, however the reader can
|
||||||
|
read any of the formats listed below.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.binary.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.soap.base64
|
||||||
|
value : The object must be serialized with
|
||||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
|
||||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||||
|
value : The object must be serialized into a byte array
|
||||||
|
: using a System.ComponentModel.TypeConverter
|
||||||
|
: and then encoded with base64 encoding.
|
||||||
|
-->
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
105
DroneClientCpp/NetClient.cpp
Normal file
105
DroneClientCpp/NetClient.cpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#include "NetClient.h"
|
||||||
|
|
||||||
|
namespace DroneSimulator {
|
||||||
|
|
||||||
|
// Конструктор ConnectData
|
||||||
|
NetClient::ConnectData::ConnectData(bool connect, Socket^ server)
|
||||||
|
{
|
||||||
|
Connect = connect;
|
||||||
|
Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конструктор ReceiveData
|
||||||
|
NetClient::ReceiveData::ReceiveData(array<Byte>^ buffer, int size, Socket^ server)
|
||||||
|
{
|
||||||
|
Buffer = buffer;
|
||||||
|
Size = size;
|
||||||
|
Server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Конструктор NetClient
|
||||||
|
NetClient::NetClient()
|
||||||
|
{
|
||||||
|
Connected = false;
|
||||||
|
ServerSocket = nullptr;
|
||||||
|
DataServer = gcnew ServerData(); // Инициализация DataServer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Реализация метода Connect
|
||||||
|
NetClient::ClientState NetClient::Connect(String^ Addr, int Port, ClientCallback^ Connection, ClientCallback^ Receive)
|
||||||
|
{
|
||||||
|
if (Connected)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
return ClientState::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionCallback = Connection;
|
||||||
|
ReceiveCallback = Receive;
|
||||||
|
|
||||||
|
IPEndPoint^ ep = gcnew IPEndPoint(IPAddress::Parse(Addr), Port);
|
||||||
|
ServerSocket = gcnew Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);
|
||||||
|
|
||||||
|
try { 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 (...) {}
|
||||||
|
}
|
||||||
|
}
|
68
DroneClientCpp/NetClient.h
Normal file
68
DroneClientCpp/NetClient.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <vcclr.h>
|
||||||
|
|
||||||
|
#using <System.dll>
|
||||||
|
#using <System.Net.dll>
|
||||||
|
|
||||||
|
using namespace System;
|
||||||
|
using namespace System::Net;
|
||||||
|
using namespace System::Net::Sockets;
|
||||||
|
|
||||||
|
namespace DroneSimulator {
|
||||||
|
|
||||||
|
public ref class NetClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ref class ConnectData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool Connect;
|
||||||
|
Socket^ Server;
|
||||||
|
|
||||||
|
ConnectData(bool connect, Socket^ server);
|
||||||
|
};
|
||||||
|
|
||||||
|
ref class ReceiveData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
array<Byte>^ Buffer;
|
||||||
|
int Size;
|
||||||
|
Socket^ Server;
|
||||||
|
|
||||||
|
ReceiveData(array<Byte>^ buffer, int size, Socket^ server);
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
ref class ServerData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
literal int size = 1024;
|
||||||
|
array<Byte>^ buffer = gcnew array<Byte>(size);
|
||||||
|
};
|
||||||
|
|
||||||
|
bool Connected;
|
||||||
|
Socket^ ServerSocket;
|
||||||
|
ServerData^ DataServer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
delegate void ClientCallback(Object^ o);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ClientCallback^ ConnectionCallback;
|
||||||
|
ClientCallback^ ReceiveCallback;
|
||||||
|
|
||||||
|
public:
|
||||||
|
NetClient(); // Добавлен конструктор
|
||||||
|
|
||||||
|
enum class ClientState { Error, Connected, Stop };
|
||||||
|
|
||||||
|
ClientState Connect(String^ Addr, int Port, ClientCallback^ Connection, ClientCallback^ Receive);
|
||||||
|
void Close();
|
||||||
|
void Send(array<Byte>^ data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ReadCallback(IAsyncResult^ ar);
|
||||||
|
};
|
||||||
|
}
|
11
DroneClientCpp/Source.cpp
Normal file
11
DroneClientCpp/Source.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include "MyForm.h"
|
||||||
|
|
||||||
|
using namespace MyWinFormsApp; // ???????????? ???? ?????? ???????
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
int main(array<String^>^ args) {
|
||||||
|
Application::EnableVisualStyles(); // ???????? ??????????? ????? ????????? ??????????
|
||||||
|
Application::SetCompatibleTextRenderingDefault(false); // ????????? ?????????? ??????
|
||||||
|
Application::Run(gcnew MyForm()); // ?????? ?????
|
||||||
|
return 0;
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\",
|
|
||||||
"Documents": [],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"Version": 1,
|
|
||||||
"WorkspaceRootPath": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\",
|
|
||||||
"Documents": [
|
|
||||||
{
|
|
||||||
"AbsoluteMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneSimulator.csproj|d:\\cpl\\simulator\\dronesimulator\\dronesimulator\\screen2d.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}",
|
|
||||||
"RelativeMoniker": "D:0:0:{B66DBB0A-CCDD-4711-ADB0-5AA11AC1760D}|DroneSimulator.csproj|solutionrelative:screen2d.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"DocumentGroupContainers": [
|
|
||||||
{
|
|
||||||
"Orientation": 0,
|
|
||||||
"VerticalTabListWidth": 256,
|
|
||||||
"DocumentGroups": [
|
|
||||||
{
|
|
||||||
"DockedWidth": 200,
|
|
||||||
"SelectedChildIndex": 0,
|
|
||||||
"Children": [
|
|
||||||
{
|
|
||||||
"$type": "Document",
|
|
||||||
"DocumentIndex": 0,
|
|
||||||
"Title": "Screen2D.cs",
|
|
||||||
"DocumentMoniker": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\Screen2D.cs",
|
|
||||||
"RelativeDocumentMoniker": "Screen2D.cs",
|
|
||||||
"ToolTip": "D:\\CPL\\Simulator\\DroneSimulator\\DroneSimulator\\Screen2D.cs",
|
|
||||||
"RelativeToolTip": "Screen2D.cs",
|
|
||||||
"ViewState": "AgIAAIgAAAAAAAAAAAAwwAAAAAAAAAAAAAAAAA==",
|
|
||||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|",
|
|
||||||
"WhenOpened": "2025-03-27T13:13:30.215Z",
|
|
||||||
"EditorCaption": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user