forked from CPL/Simulator
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
06d621288c | |||
28b33ed671 |
@ -2,8 +2,6 @@
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using static DroneSimulator.Drone;
|
|
||||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
|
|
||||||
|
|
||||||
namespace DroneSimulator
|
namespace DroneSimulator
|
||||||
{
|
{
|
||||||
@ -33,17 +31,7 @@ namespace DroneSimulator
|
|||||||
private Thread DroneThread;
|
private Thread DroneThread;
|
||||||
private int Timer;
|
private int Timer;
|
||||||
|
|
||||||
private Random MainRandom = new Random();
|
private static int CounterID = 0;
|
||||||
|
|
||||||
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)
|
public static byte[] getBytes(object data)
|
||||||
{
|
{
|
||||||
@ -252,14 +240,6 @@ namespace DroneSimulator
|
|||||||
else LaserRange = float.MaxValue;
|
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;
|
DataTimer = (uint)tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,21 +344,6 @@ namespace DroneSimulator
|
|||||||
return getBytes(local);
|
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)
|
private byte[]? ServerRequestResponse(DroneData.DataHead head, byte[] body)
|
||||||
{
|
{
|
||||||
byte[] zero = new byte[0];
|
byte[] zero = new byte[0];
|
||||||
@ -401,17 +366,86 @@ 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.DataBar: if (head.Mode == DroneData.DataMode.Request) return SendDataBarometer(); else return zero;
|
case DroneData.DataType.DataMotor4:
|
||||||
|
{
|
||||||
case DroneData.DataType.DataMotor4: if (head.Mode == DroneData.DataMode.Response) RecvDataMotor4(body); return zero;
|
if (head.Mode == DroneData.DataMode.Request)
|
||||||
|
{
|
||||||
|
// Запрос данных
|
||||||
|
// ... //
|
||||||
|
//
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Пришли данные
|
||||||
|
RecvDataMotor4(body);
|
||||||
|
return zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return zero;
|
return zero;
|
||||||
|
@ -12,7 +12,7 @@ namespace DroneData
|
|||||||
None = 0, Head = 1,
|
None = 0, Head = 1,
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005, DataBar = 1006,
|
DataAcc = 1001, DataGyr = 1002, DataMag = 1003, DataRange = 1004, DataLocal = 1005,
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
DataMotor4 = 2001, DataMotor6 = 2002
|
DataMotor4 = 2001, DataMotor6 = 2002
|
||||||
@ -62,16 +62,6 @@ namespace DroneData
|
|||||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMag));
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataMag));
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct DataRange
|
|
||||||
{
|
|
||||||
public DataHead Head;
|
|
||||||
public float LiDAR; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
|
|
||||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
||||||
|
|
||||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataRange));
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct DataLocal
|
public struct DataLocal
|
||||||
{
|
{
|
||||||
public DataHead Head;
|
public DataHead Head;
|
||||||
@ -82,14 +72,14 @@ namespace DroneData
|
|||||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataLocal));
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct DataBar
|
public struct DataRange
|
||||||
{
|
{
|
||||||
public DataHead Head;
|
public DataHead Head;
|
||||||
public int Pressure; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
public float LiDAR; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
public uint Time; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataBar));
|
static public int StrLen = Marshal.SizeOf(typeof(DroneData.DataRange));
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct DataMotor4
|
public struct DataMotor4
|
||||||
|
1709
DroneSimulator/FormMain.Designer.cs
generated
1709
DroneSimulator/FormMain.Designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -38,15 +38,6 @@ namespace DroneSimulator
|
|||||||
Drone drone = new Drone(data.ID);
|
Drone drone = new Drone(data.ID);
|
||||||
drone.Create(1.0f, 0.5f, 1.0f);
|
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);
|
screen2D.CreateDrone(Color.Red, data.ID);
|
||||||
|
|
||||||
AllDrones.Add(drone);
|
AllDrones.Add(drone);
|
||||||
@ -108,7 +99,6 @@ namespace DroneSimulator
|
|||||||
{
|
{
|
||||||
button_Client_Start.Text = "Stop";
|
button_Client_Start.Text = "Stop";
|
||||||
button_Client_Start.BackColor = Color.LimeGreen;
|
button_Client_Start.BackColor = Color.LimeGreen;
|
||||||
panel_Menu_Model.Enabled = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NetServerClients.ServerState.Stop:
|
case NetServerClients.ServerState.Stop:
|
||||||
@ -116,7 +106,6 @@ namespace DroneSimulator
|
|||||||
label_Clients_Num.Text = "0";
|
label_Clients_Num.Text = "0";
|
||||||
button_Client_Start.Text = "Start";
|
button_Client_Start.Text = "Start";
|
||||||
button_Client_Start.BackColor = Color.Transparent;
|
button_Client_Start.BackColor = Color.Transparent;
|
||||||
panel_Menu_Model.Enabled = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user