forked from CPL/Simulator
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
376ce81a8a |
@ -2,6 +2,8 @@
|
||||
using System.Numerics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using static DroneSimulator.Drone;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
|
||||
|
||||
namespace DroneSimulator
|
||||
{
|
||||
@ -31,7 +33,17 @@ namespace DroneSimulator
|
||||
private Thread DroneThread;
|
||||
private int Timer;
|
||||
|
||||
private static int CounterID = 0;
|
||||
private Random MainRandom = new Random();
|
||||
|
||||
public struct DataBarometer
|
||||
{
|
||||
public int Value, Pressure; // Значение давления в Паскальях
|
||||
public float Accuracy;
|
||||
public int Frequency;
|
||||
public uint Time;
|
||||
}
|
||||
|
||||
public DataBarometer dataBarometer;
|
||||
|
||||
public static byte[] getBytes(object data)
|
||||
{
|
||||
@ -240,6 +252,14 @@ namespace DroneSimulator
|
||||
else LaserRange = float.MaxValue;
|
||||
}
|
||||
|
||||
if ((dataBarometer.Time + 1000 / dataBarometer.Frequency) < DataTimer)
|
||||
{
|
||||
float bar = dataBarometer.Pressure - PosXYZ.Z * 11;
|
||||
int rnd = MainRandom.Next(-(int)dataBarometer.Accuracy * 10, (int)dataBarometer.Accuracy * 10) / 10;
|
||||
dataBarometer.Value = (int)(bar + rnd);
|
||||
dataBarometer.Time = DataTimer;
|
||||
}
|
||||
|
||||
DataTimer = (uint)tick;
|
||||
}
|
||||
|
||||
@ -344,6 +364,21 @@ namespace DroneSimulator
|
||||
return getBytes(local);
|
||||
}
|
||||
|
||||
private byte[] SendDataBarometer()
|
||||
{
|
||||
DroneData.DataBar bar = new DroneData.DataBar();
|
||||
|
||||
bar.Head.Size = Marshal.SizeOf(typeof(DroneData.DataBar));
|
||||
bar.Head.Mode = DroneData.DataMode.Response;
|
||||
bar.Head.Type = DroneData.DataType.DataBar;
|
||||
bar.Head.Time = (uint)Environment.TickCount;
|
||||
|
||||
bar.Pressure = dataBarometer.Value;
|
||||
bar.Time = dataBarometer.Time;
|
||||
|
||||
return getBytes(bar);
|
||||
}
|
||||
|
||||
private byte[]? ServerRequestResponse(DroneData.DataHead head, byte[] body)
|
||||
{
|
||||
byte[] zero = new byte[0];
|
||||
@ -366,86 +401,17 @@ namespace DroneSimulator
|
||||
}
|
||||
}
|
||||
|
||||
case DroneData.DataType.DataGyr:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
// Запрос данных
|
||||
return SendDataGyr();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
// ... //
|
||||
//
|
||||
return zero;
|
||||
}
|
||||
}
|
||||
case DroneData.DataType.DataGyr: if (head.Mode == DroneData.DataMode.Request) return SendDataGyr(); else return zero;
|
||||
|
||||
case DroneData.DataType.DataMag:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
// Запрос данных
|
||||
return SendDataMag();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
// ... //
|
||||
//
|
||||
return zero;
|
||||
}
|
||||
}
|
||||
case DroneData.DataType.DataMag: if (head.Mode == DroneData.DataMode.Request) return SendDataMag(); else return zero;
|
||||
|
||||
case DroneData.DataType.DataRange:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
// Запрос данных
|
||||
return SendDataRange();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
// ... //
|
||||
//
|
||||
return zero;
|
||||
}
|
||||
}
|
||||
case DroneData.DataType.DataRange: if (head.Mode == DroneData.DataMode.Request) return SendDataRange(); else return zero;
|
||||
|
||||
case DroneData.DataType.DataLocal:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
// Запрос данных
|
||||
return SendDataLocal();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
// ... //
|
||||
//
|
||||
return zero;
|
||||
}
|
||||
}
|
||||
case DroneData.DataType.DataLocal: if (head.Mode == DroneData.DataMode.Request) return SendDataLocal(); else return zero;
|
||||
|
||||
case DroneData.DataType.DataMotor4:
|
||||
{
|
||||
if (head.Mode == DroneData.DataMode.Request)
|
||||
{
|
||||
// Запрос данных
|
||||
// ... //
|
||||
//
|
||||
return zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Пришли данные
|
||||
RecvDataMotor4(body);
|
||||
return zero;
|
||||
}
|
||||
}
|
||||
case DroneData.DataType.DataBar: if (head.Mode == DroneData.DataMode.Request) return SendDataBarometer(); else return zero;
|
||||
|
||||
case DroneData.DataType.DataMotor4: if (head.Mode == DroneData.DataMode.Response) RecvDataMotor4(body); return zero;
|
||||
}
|
||||
|
||||
return zero;
|
||||
|
@ -12,7 +12,7 @@ namespace DroneData
|
||||
None = 0, Head = 1,
|
||||
|
||||
// Output
|
||||
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005,
|
||||
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005, DataBar = 1006,
|
||||
|
||||
// Input
|
||||
DataMotor4 = 2001, DataMotor6 = 2002
|
||||
@ -62,6 +62,16 @@ namespace DroneData
|
||||
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;
|
||||
@ -72,14 +82,14 @@ namespace DroneData
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
||||
}
|
||||
|
||||
public struct DataRange
|
||||
public struct DataBar
|
||||
{
|
||||
public DataHead Head;
|
||||
public float LiDAR; // Äàò÷èê ïîñàäêè
|
||||
public int Pressure; // Ëîêàëüíûå êîîðäèíàòû
|
||||
|
||||
public uint Time; // Ïîñëåäíåå âðåìÿ èçìåíåíèÿ äàííûõ
|
||||
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataRange));
|
||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataBar));
|
||||
}
|
||||
|
||||
public struct DataMotor4
|
||||
|
1417
DroneSimulator/FormMain.Designer.cs
generated
1417
DroneSimulator/FormMain.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -8,11 +8,6 @@ using System.Runtime.InteropServices;
|
||||
using System.CodeDom;
|
||||
using System.Linq;
|
||||
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DroneSimulator
|
||||
{
|
||||
public partial class Form_Main : Form
|
||||
@ -23,9 +18,7 @@ namespace DroneSimulator
|
||||
NetServerVisual netServerVisual = new NetServerVisual();
|
||||
|
||||
List<Drone> AllDrones = new List<Drone>();
|
||||
private ClientWebSocket _webSocket;
|
||||
private CancellationTokenSource _cts;
|
||||
private bool _isRunning;
|
||||
|
||||
public Form_Main()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -45,6 +38,15 @@ namespace DroneSimulator
|
||||
Drone drone = new Drone(data.ID);
|
||||
drone.Create(1.0f, 0.5f, 1.0f);
|
||||
|
||||
//
|
||||
drone.dataBarometer.Pressure = 102258;
|
||||
drone.dataBarometer.Accuracy = (float)numericUpDown_Bar_Accur.Value;
|
||||
drone.dataBarometer.Frequency = (int)numericUpDown_Bar_Freq.Value;
|
||||
try { drone.dataBarometer.Pressure = int.Parse(textBox_Bar_Pressure.Text); }
|
||||
catch { MessageBox.Show("Pressure invalid format", "Barometer error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
|
||||
|
||||
//
|
||||
|
||||
screen2D.CreateDrone(Color.Red, data.ID);
|
||||
|
||||
AllDrones.Add(drone);
|
||||
@ -106,6 +108,7 @@ namespace DroneSimulator
|
||||
{
|
||||
button_Client_Start.Text = "Stop";
|
||||
button_Client_Start.BackColor = Color.LimeGreen;
|
||||
panel_Menu_Model.Enabled = false;
|
||||
break;
|
||||
}
|
||||
case NetServerClients.ServerState.Stop:
|
||||
@ -113,6 +116,7 @@ namespace DroneSimulator
|
||||
label_Clients_Num.Text = "0";
|
||||
button_Client_Start.Text = "Start";
|
||||
button_Client_Start.BackColor = Color.Transparent;
|
||||
panel_Menu_Model.Enabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -211,7 +215,5 @@ namespace DroneSimulator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user