2025-04-09 21:10:35 +03:00

746 lines
74 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "Drone.h" // Новый Drone.h
#include "DroneData.h" // Новый DroneData.h
#include "NetClient.h"
namespace DroneClientCpp {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace DroneClient; // Пространство имен из Drone.h
using namespace DroneData; // Пространство имен из DroneData.h
using namespace DroneSimulator;
public ref class FormMain : public System::Windows::Forms::Form
{
public:
FormMain(void)
{
InitializeComponent();
netClient = gcnew NetClient();
dataDrone = gcnew Drone(); // Инициализация объекта Drone
}
protected:
~FormMain()
{
if (components) delete components;
if (netClient != nullptr)
{
netClient->Close();
netClient = nullptr;
}
}
private:
// Элементы управления (оставить как есть)
System::Windows::Forms::GroupBox^ groupBox_Server;
System::Windows::Forms::Label^ label_Port;
System::Windows::Forms::Button^ button_Connect;
System::Windows::Forms::NumericUpDown^ numericUpDown_Server_Port;
System::Windows::Forms::TextBox^ textBox_Server_Addr;
System::Windows::Forms::GroupBox^ groupBox_Acc;
System::Windows::Forms::Label^ label_Addr;
System::Windows::Forms::Label^ label_Acc_X_Info;
System::Windows::Forms::Label^ label_Acc_Z;
System::Windows::Forms::Label^ label_Acc_Y;
System::Windows::Forms::Label^ label_Acc_X;
System::Windows::Forms::Label^ label_Acc_Z_Info;
System::Windows::Forms::Label^ label_Acc_Y_Info;
System::ComponentModel::BackgroundWorker^ backgroundWorker1;
System::Windows::Forms::GroupBox^ groupBox_Gyr;
System::Windows::Forms::Label^ label_Gyr_Z;
System::Windows::Forms::Label^ label_Gyr_Y;
System::Windows::Forms::Label^ label_Gyr_X;
System::Windows::Forms::Label^ label_Gyr_Z_Info;
System::Windows::Forms::Label^ label_Gyr_Y_Info;
System::Windows::Forms::Label^ label_Gyr_X_Info;
System::Windows::Forms::GroupBox^ groupBox_Pos;
System::Windows::Forms::Label^ label_Pos_L;
System::Windows::Forms::Label^ label_Pos_Y;
System::Windows::Forms::Label^ label_Pos_X;
System::Windows::Forms::Label^ label_Pos_L_Info;
System::Windows::Forms::Label^ label_Pos_Y_Info;
System::Windows::Forms::Label^ label_Pos_X_Info;
System::Windows::Forms::GroupBox^ groupBox_Input;
System::Windows::Forms::Button^ button_RR;
System::Windows::Forms::Button^ button_LL;
System::Windows::Forms::Button^ button_MR;
System::Windows::Forms::Button^ button_ML;
System::Windows::Forms::Button^ button_DD;
System::Windows::Forms::Button^ button_UU;
System::Windows::Forms::TrackBar^ trackBar_Power;
System::Windows::Forms::Label^ label_Pow;
System::Windows::Forms::Timer^ timer1;
System::ComponentModel::IContainer^ components;
// Наши поля
NetClient^ netClient;
Drone^ dataDrone;
const float pow = 0.1f;
// Наши методы
private:
void ConnectionCallback(Object^ o)
{
NetClient::ConnectData^ data = (NetClient::ConnectData^)o;
if (!data->Connect)
{
try
{
this->Invoke(gcnew Action(this, &FormMain::UpdateDisconnectedUI));
}
catch (...) {}
return;
}
// Отправка начальных данных при подключении
data->Server->Send(dataDrone->SendRequest());
}
void UpdateDisconnectedUI()
{
button_Connect->Text = "Connect";
button_Connect->BackColor = Color::Transparent;
MessageBox::Show("Connection closed");
}
void ReceiveCallback(Object^ o)
{
NetClient::ReceiveData^ data = (NetClient::ReceiveData^)o;
System::Collections::Generic::List<array<Byte>^>^ responses = dataDrone->DataStream(data->Buffer, data->Size);
if (responses == nullptr) return;
try
{
for each (array<Byte> ^ b in responses)
{
if (b != nullptr) data->Server->Send(b);
}
}
catch (...) {}
}
#pragma region Windows Form Designer generated code
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->groupBox_Server = (gcnew System::Windows::Forms::GroupBox());
this->label_Addr = (gcnew System::Windows::Forms::Label());
this->button_Connect = (gcnew System::Windows::Forms::Button());
this->numericUpDown_Server_Port = (gcnew System::Windows::Forms::NumericUpDown());
this->textBox_Server_Addr = (gcnew System::Windows::Forms::TextBox());
this->label_Port = (gcnew System::Windows::Forms::Label());
this->groupBox_Acc = (gcnew System::Windows::Forms::GroupBox());
this->label_Acc_Z = (gcnew System::Windows::Forms::Label());
this->label_Acc_Y = (gcnew System::Windows::Forms::Label());
this->label_Acc_X = (gcnew System::Windows::Forms::Label());
this->label_Acc_Z_Info = (gcnew System::Windows::Forms::Label());
this->label_Acc_Y_Info = (gcnew System::Windows::Forms::Label());
this->label_Acc_X_Info = (gcnew System::Windows::Forms::Label());
this->backgroundWorker1 = (gcnew System::ComponentModel::BackgroundWorker());
this->groupBox_Gyr = (gcnew System::Windows::Forms::GroupBox());
this->label_Gyr_Z = (gcnew System::Windows::Forms::Label());
this->label_Gyr_Y = (gcnew System::Windows::Forms::Label());
this->label_Gyr_X = (gcnew System::Windows::Forms::Label());
this->label_Gyr_Z_Info = (gcnew System::Windows::Forms::Label());
this->label_Gyr_Y_Info = (gcnew System::Windows::Forms::Label());
this->label_Gyr_X_Info = (gcnew System::Windows::Forms::Label());
this->groupBox_Pos = (gcnew System::Windows::Forms::GroupBox());
this->label_Pos_L = (gcnew System::Windows::Forms::Label());
this->label_Pos_Y = (gcnew System::Windows::Forms::Label());
this->label_Pos_X = (gcnew System::Windows::Forms::Label());
this->label_Pos_L_Info = (gcnew System::Windows::Forms::Label());
this->label_Pos_Y_Info = (gcnew System::Windows::Forms::Label());
this->label_Pos_X_Info = (gcnew System::Windows::Forms::Label());
this->groupBox_Input = (gcnew System::Windows::Forms::GroupBox());
this->label_Pow = (gcnew System::Windows::Forms::Label());
this->button_RR = (gcnew System::Windows::Forms::Button());
this->button_LL = (gcnew System::Windows::Forms::Button());
this->button_MR = (gcnew System::Windows::Forms::Button());
this->button_ML = (gcnew System::Windows::Forms::Button());
this->button_DD = (gcnew System::Windows::Forms::Button());
this->button_UU = (gcnew System::Windows::Forms::Button());
this->trackBar_Power = (gcnew System::Windows::Forms::TrackBar());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->groupBox_Server->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown_Server_Port))->BeginInit();
this->groupBox_Acc->SuspendLayout();
this->groupBox_Gyr->SuspendLayout();
this->groupBox_Pos->SuspendLayout();
this->groupBox_Input->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->trackBar_Power))->BeginInit();
this->SuspendLayout();
//
// groupBox_Server
//
this->groupBox_Server->Controls->Add(this->label_Addr);
this->groupBox_Server->Controls->Add(this->button_Connect);
this->groupBox_Server->Controls->Add(this->numericUpDown_Server_Port);
this->groupBox_Server->Controls->Add(this->textBox_Server_Addr);
this->groupBox_Server->Controls->Add(this->label_Port);
this->groupBox_Server->Dock = System::Windows::Forms::DockStyle::Top;
this->groupBox_Server->Location = System::Drawing::Point(0, 0);
this->groupBox_Server->Name = L"groupBox_Server";
this->groupBox_Server->Size = System::Drawing::Size(256, 89);
this->groupBox_Server->TabIndex = 0;
this->groupBox_Server->TabStop = false;
this->groupBox_Server->Text = L"Server";
//
// label_Addr
//
this->label_Addr->AutoSize = true;
this->label_Addr->Location = System::Drawing::Point(4, 21);
this->label_Addr->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Addr->Name = L"label_Addr";
this->label_Addr->Size = System::Drawing::Size(32, 13);
this->label_Addr->TabIndex = 5;
this->label_Addr->Text = L"Addr:";
//
// button_Connect
//
this->button_Connect->Location = System::Drawing::Point(115, 54);
this->button_Connect->Margin = System::Windows::Forms::Padding(2);
this->button_Connect->Name = L"button_Connect";
this->button_Connect->Size = System::Drawing::Size(87, 22);
this->button_Connect->TabIndex = 4;
this->button_Connect->Text = L"Connect";
this->button_Connect->UseVisualStyleBackColor = true;
this->button_Connect->Click += gcnew System::EventHandler(this, &FormMain::button_Connect_Click);
//
// numericUpDown_Server_Port
//
this->numericUpDown_Server_Port->Location = System::Drawing::Point(42, 54);
this->numericUpDown_Server_Port->Margin = System::Windows::Forms::Padding(2);
this->numericUpDown_Server_Port->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 65000, 0, 0, 0 });
this->numericUpDown_Server_Port->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1, 0, 0, 0 });
this->numericUpDown_Server_Port->Name = L"numericUpDown_Server_Port";
this->numericUpDown_Server_Port->Size = System::Drawing::Size(70, 20);
this->numericUpDown_Server_Port->TabIndex = 3;
this->numericUpDown_Server_Port->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) { 1001, 0, 0, 0 });
//
// textBox_Server_Addr
//
this->textBox_Server_Addr->Location = System::Drawing::Point(42, 19);
this->textBox_Server_Addr->Margin = System::Windows::Forms::Padding(2);
this->textBox_Server_Addr->Name = L"textBox_Server_Addr";
this->textBox_Server_Addr->Size = System::Drawing::Size(162, 20);
this->textBox_Server_Addr->TabIndex = 2;
this->textBox_Server_Addr->Text = L"127.0.0.1";
//
// label_Port
//
this->label_Port->AutoSize = true;
this->label_Port->Location = System::Drawing::Point(4, 57);
this->label_Port->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Port->Name = L"label_Port";
this->label_Port->Size = System::Drawing::Size(29, 13);
this->label_Port->TabIndex = 1;
this->label_Port->Text = L"Port:";
//
// groupBox_Acc
//
this->groupBox_Acc->Controls->Add(this->label_Acc_Z);
this->groupBox_Acc->Controls->Add(this->label_Acc_Y);
this->groupBox_Acc->Controls->Add(this->label_Acc_X);
this->groupBox_Acc->Controls->Add(this->label_Acc_Z_Info);
this->groupBox_Acc->Controls->Add(this->label_Acc_Y_Info);
this->groupBox_Acc->Controls->Add(this->label_Acc_X_Info);
this->groupBox_Acc->Location = System::Drawing::Point(6, 94);
this->groupBox_Acc->Margin = System::Windows::Forms::Padding(2);
this->groupBox_Acc->Name = L"groupBox_Acc";
this->groupBox_Acc->Padding = System::Windows::Forms::Padding(2);
this->groupBox_Acc->Size = System::Drawing::Size(76, 111);
this->groupBox_Acc->TabIndex = 1;
this->groupBox_Acc->TabStop = false;
this->groupBox_Acc->Text = L"Acc";
//
// label_Acc_Z
//
this->label_Acc_Z->AutoSize = true;
this->label_Acc_Z->Location = System::Drawing::Point(17, 79);
this->label_Acc_Z->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Acc_Z->Name = L"label_Acc_Z";
this->label_Acc_Z->Size = System::Drawing::Size(13, 13);
this->label_Acc_Z->TabIndex = 5;
this->label_Acc_Z->Text = L"0";
//
// label_Acc_Y
//
this->label_Acc_Y->AutoSize = true;
this->label_Acc_Y->Location = System::Drawing::Point(17, 49);
this->label_Acc_Y->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Acc_Y->Name = L"label_Acc_Y";
this->label_Acc_Y->Size = System::Drawing::Size(13, 13);
this->label_Acc_Y->TabIndex = 4;
this->label_Acc_Y->Text = L"0";
//
// label_Acc_X
//
this->label_Acc_X->AutoSize = true;
this->label_Acc_X->Location = System::Drawing::Point(17, 16);
this->label_Acc_X->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Acc_X->Name = L"label_Acc_X";
this->label_Acc_X->Size = System::Drawing::Size(13, 13);
this->label_Acc_X->TabIndex = 3;
this->label_Acc_X->Text = L"0";
//
// label_Acc_Z_Info
//
this->label_Acc_Z_Info->AutoSize = true;
this->label_Acc_Z_Info->Location = System::Drawing::Point(4, 79);
this->label_Acc_Z_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Acc_Z_Info->Name = L"label_Acc_Z_Info";
this->label_Acc_Z_Info->Size = System::Drawing::Size(20, 13);
this->label_Acc_Z_Info->TabIndex = 2;
this->label_Acc_Z_Info->Text = L"Z: ";
//
// label_Acc_Y_Info
//
this->label_Acc_Y_Info->AutoSize = true;
this->label_Acc_Y_Info->Location = System::Drawing::Point(3, 49);
this->label_Acc_Y_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Acc_Y_Info->Name = L"label_Acc_Y_Info";
this->label_Acc_Y_Info->Size = System::Drawing::Size(20, 13);
this->label_Acc_Y_Info->TabIndex = 1;
this->label_Acc_Y_Info->Text = L"Y: ";
//
// label_Acc_X_Info
//
this->label_Acc_X_Info->AutoSize = true;
this->label_Acc_X_Info->Location = System::Drawing::Point(4, 16);
this->label_Acc_X_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Acc_X_Info->Name = L"label_Acc_X_Info";
this->label_Acc_X_Info->Size = System::Drawing::Size(20, 13);
this->label_Acc_X_Info->TabIndex = 0;
this->label_Acc_X_Info->Text = L"X: ";
//
// groupBox_Gyr
//
this->groupBox_Gyr->Controls->Add(this->label_Gyr_Z);
this->groupBox_Gyr->Controls->Add(this->label_Gyr_Y);
this->groupBox_Gyr->Controls->Add(this->label_Gyr_X);
this->groupBox_Gyr->Controls->Add(this->label_Gyr_Z_Info);
this->groupBox_Gyr->Controls->Add(this->label_Gyr_Y_Info);
this->groupBox_Gyr->Controls->Add(this->label_Gyr_X_Info);
this->groupBox_Gyr->Location = System::Drawing::Point(92, 94);
this->groupBox_Gyr->Margin = System::Windows::Forms::Padding(2);
this->groupBox_Gyr->Name = L"groupBox_Gyr";
this->groupBox_Gyr->Padding = System::Windows::Forms::Padding(2);
this->groupBox_Gyr->Size = System::Drawing::Size(72, 111);
this->groupBox_Gyr->TabIndex = 6;
this->groupBox_Gyr->TabStop = false;
this->groupBox_Gyr->Text = L"Gyr";
//
// label_Gyr_Z
//
this->label_Gyr_Z->AutoSize = true;
this->label_Gyr_Z->Location = System::Drawing::Point(17, 79);
this->label_Gyr_Z->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Gyr_Z->Name = L"label_Gyr_Z";
this->label_Gyr_Z->Size = System::Drawing::Size(13, 13);
this->label_Gyr_Z->TabIndex = 5;
this->label_Gyr_Z->Text = L"0";
//
// label_Gyr_Y
//
this->label_Gyr_Y->AutoSize = true;
this->label_Gyr_Y->Location = System::Drawing::Point(17, 49);
this->label_Gyr_Y->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Gyr_Y->Name = L"label_Gyr_Y";
this->label_Gyr_Y->Size = System::Drawing::Size(13, 13);
this->label_Gyr_Y->TabIndex = 4;
this->label_Gyr_Y->Text = L"0";
//
// label_Gyr_X
//
this->label_Gyr_X->AutoSize = true;
this->label_Gyr_X->Location = System::Drawing::Point(17, 16);
this->label_Gyr_X->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Gyr_X->Name = L"label_Gyr_X";
this->label_Gyr_X->Size = System::Drawing::Size(13, 13);
this->label_Gyr_X->TabIndex = 3;
this->label_Gyr_X->Text = L"0";
//
// label_Gyr_Z_Info
//
this->label_Gyr_Z_Info->AutoSize = true;
this->label_Gyr_Z_Info->Location = System::Drawing::Point(4, 79);
this->label_Gyr_Z_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Gyr_Z_Info->Name = L"label_Gyr_Z_Info";
this->label_Gyr_Z_Info->Size = System::Drawing::Size(20, 13);
this->label_Gyr_Z_Info->TabIndex = 2;
this->label_Gyr_Z_Info->Text = L"Z: ";
//
// label_Gyr_Y_Info
//
this->label_Gyr_Y_Info->AutoSize = true;
this->label_Gyr_Y_Info->Location = System::Drawing::Point(3, 49);
this->label_Gyr_Y_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Gyr_Y_Info->Name = L"label_Gyr_Y_Info";
this->label_Gyr_Y_Info->Size = System::Drawing::Size(20, 13);
this->label_Gyr_Y_Info->TabIndex = 1;
this->label_Gyr_Y_Info->Text = L"Y: ";
//
// label_Gyr_X_Info
//
this->label_Gyr_X_Info->AutoSize = true;
this->label_Gyr_X_Info->Location = System::Drawing::Point(4, 16);
this->label_Gyr_X_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Gyr_X_Info->Name = L"label_Gyr_X_Info";
this->label_Gyr_X_Info->Size = System::Drawing::Size(20, 13);
this->label_Gyr_X_Info->TabIndex = 0;
this->label_Gyr_X_Info->Text = L"X: ";
//
// groupBox_Pos
//
this->groupBox_Pos->Controls->Add(this->label_Pos_L);
this->groupBox_Pos->Controls->Add(this->label_Pos_Y);
this->groupBox_Pos->Controls->Add(this->label_Pos_X);
this->groupBox_Pos->Controls->Add(this->label_Pos_L_Info);
this->groupBox_Pos->Controls->Add(this->label_Pos_Y_Info);
this->groupBox_Pos->Controls->Add(this->label_Pos_X_Info);
this->groupBox_Pos->Location = System::Drawing::Point(177, 94);
this->groupBox_Pos->Margin = System::Windows::Forms::Padding(2);
this->groupBox_Pos->Name = L"groupBox_Pos";
this->groupBox_Pos->Padding = System::Windows::Forms::Padding(2);
this->groupBox_Pos->Size = System::Drawing::Size(72, 111);
this->groupBox_Pos->TabIndex = 7;
this->groupBox_Pos->TabStop = false;
this->groupBox_Pos->Text = L"Pos";
//
// label_Pos_L
//
this->label_Pos_L->AutoSize = true;
this->label_Pos_L->Location = System::Drawing::Point(17, 79);
this->label_Pos_L->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Pos_L->Name = L"label_Pos_L";
this->label_Pos_L->Size = System::Drawing::Size(13, 13);
this->label_Pos_L->TabIndex = 5;
this->label_Pos_L->Text = L"0";
//
// label_Pos_Y
//
this->label_Pos_Y->AutoSize = true;
this->label_Pos_Y->Location = System::Drawing::Point(17, 49);
this->label_Pos_Y->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Pos_Y->Name = L"label_Pos_Y";
this->label_Pos_Y->Size = System::Drawing::Size(13, 13);
this->label_Pos_Y->TabIndex = 4;
this->label_Pos_Y->Text = L"0";
//
// label_Pos_X
//
this->label_Pos_X->AutoSize = true;
this->label_Pos_X->Location = System::Drawing::Point(17, 16);
this->label_Pos_X->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Pos_X->Name = L"label_Pos_X";
this->label_Pos_X->Size = System::Drawing::Size(13, 13);
this->label_Pos_X->TabIndex = 3;
this->label_Pos_X->Text = L"0";
//
// label_Pos_L_Info
//
this->label_Pos_L_Info->AutoSize = true;
this->label_Pos_L_Info->Location = System::Drawing::Point(4, 79);
this->label_Pos_L_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Pos_L_Info->Name = L"label_Pos_L_Info";
this->label_Pos_L_Info->Size = System::Drawing::Size(16, 13);
this->label_Pos_L_Info->TabIndex = 2;
this->label_Pos_L_Info->Text = L"L:";
//
// label_Pos_Y_Info
//
this->label_Pos_Y_Info->AutoSize = true;
this->label_Pos_Y_Info->Location = System::Drawing::Point(3, 49);
this->label_Pos_Y_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Pos_Y_Info->Name = L"label_Pos_Y_Info";
this->label_Pos_Y_Info->Size = System::Drawing::Size(20, 13);
this->label_Pos_Y_Info->TabIndex = 1;
this->label_Pos_Y_Info->Text = L"Y: ";
//
// label_Pos_X_Info
//
this->label_Pos_X_Info->AutoSize = true;
this->label_Pos_X_Info->Location = System::Drawing::Point(4, 16);
this->label_Pos_X_Info->Margin = System::Windows::Forms::Padding(2, 0, 2, 0);
this->label_Pos_X_Info->Name = L"label_Pos_X_Info";
this->label_Pos_X_Info->Size = System::Drawing::Size(20, 13);
this->label_Pos_X_Info->TabIndex = 0;
this->label_Pos_X_Info->Text = L"X: ";
//
// groupBox_Input
//
this->groupBox_Input->Controls->Add(this->label_Pow);
this->groupBox_Input->Controls->Add(this->button_RR);
this->groupBox_Input->Controls->Add(this->button_LL);
this->groupBox_Input->Controls->Add(this->button_MR);
this->groupBox_Input->Controls->Add(this->button_ML);
this->groupBox_Input->Controls->Add(this->button_DD);
this->groupBox_Input->Controls->Add(this->button_UU);
this->groupBox_Input->Controls->Add(this->trackBar_Power);
this->groupBox_Input->Location = System::Drawing::Point(6, 207);
this->groupBox_Input->Margin = System::Windows::Forms::Padding(2);
this->groupBox_Input->Name = L"groupBox_Input";
this->groupBox_Input->Padding = System::Windows::Forms::Padding(2);
this->groupBox_Input->Size = System::Drawing::Size(244, 282);
this->groupBox_Input->TabIndex = 8;
this->groupBox_Input->TabStop = false;
//
// label_Pow
//
this->label_Pow->AutoSize = true;
this->label_Pow->Location = System::Drawing::Point(103, 208);
this->label_Pow->Name = L"label_Pow";
this->label_Pow->Size = System::Drawing::Size(13, 13);
this->label_Pow->TabIndex = 10;
this->label_Pow->Text = L"0";
//
// button_RR
//
this->button_RR->Location = System::Drawing::Point(171, 134);
this->button_RR->Margin = System::Windows::Forms::Padding(2);
this->button_RR->Name = L"button_RR";
this->button_RR->Size = System::Drawing::Size(58, 20);
this->button_RR->TabIndex = 9;
this->button_RR->Text = L"RR";
this->button_RR->UseVisualStyleBackColor = true;
this->button_RR->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_RR_MouseDown);
this->button_RR->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_RR_MouseUp);
//
// button_LL
//
this->button_LL->Location = System::Drawing::Point(6, 134);
this->button_LL->Margin = System::Windows::Forms::Padding(2);
this->button_LL->Name = L"button_LL";
this->button_LL->Size = System::Drawing::Size(58, 20);
this->button_LL->TabIndex = 8;
this->button_LL->Text = L"LL";
this->button_LL->UseVisualStyleBackColor = true;
this->button_LL->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_LL_MouseDown);
this->button_LL->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_LL_MouseUp);
//
// button_MR
//
this->button_MR->Location = System::Drawing::Point(171, 30);
this->button_MR->Margin = System::Windows::Forms::Padding(2);
this->button_MR->Name = L"button_MR";
this->button_MR->Size = System::Drawing::Size(58, 20);
this->button_MR->TabIndex = 7;
this->button_MR->Text = L"->";
this->button_MR->UseVisualStyleBackColor = true;
this->button_MR->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_MR_MouseDown);
this->button_MR->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_MR_MouseUp);
//
// button_ML
//
this->button_ML->Location = System::Drawing::Point(6, 30);
this->button_ML->Margin = System::Windows::Forms::Padding(2);
this->button_ML->Name = L"button_ML";
this->button_ML->Size = System::Drawing::Size(58, 20);
this->button_ML->TabIndex = 6;
this->button_ML->Text = L"<-";
this->button_ML->UseVisualStyleBackColor = true;
this->button_ML->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_ML_MouseDown);
this->button_ML->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_ML_MouseUp);
//
// button_DD
//
this->button_DD->Location = System::Drawing::Point(80, 250);
this->button_DD->Margin = System::Windows::Forms::Padding(2);
this->button_DD->Name = L"button_DD";
this->button_DD->Size = System::Drawing::Size(58, 20);
this->button_DD->TabIndex = 5;
this->button_DD->Text = L"DD";
this->button_DD->UseVisualStyleBackColor = true;
this->button_DD->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_DD_MouseDown);
this->button_DD->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_DD_MouseUp);
//
// button_UU
//
this->button_UU->Location = System::Drawing::Point(86, 30);
this->button_UU->Margin = System::Windows::Forms::Padding(2);
this->button_UU->Name = L"button_UU";
this->button_UU->Size = System::Drawing::Size(58, 20);
this->button_UU->TabIndex = 4;
this->button_UU->Text = L"UU";
this->button_UU->UseVisualStyleBackColor = true;
this->button_UU->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_UU_MouseDown);
this->button_UU->MouseUp += gcnew System::Windows::Forms::MouseEventHandler(this, &FormMain::button_UU_MouseUp);
//
// trackBar_Power
//
this->trackBar_Power->Location = System::Drawing::Point(99, 69);
this->trackBar_Power->Margin = System::Windows::Forms::Padding(2);
this->trackBar_Power->Maximum = 100;
this->trackBar_Power->Name = L"trackBar_Power";
this->trackBar_Power->Orientation = System::Windows::Forms::Orientation::Vertical;
this->trackBar_Power->RightToLeft = System::Windows::Forms::RightToLeft::No;
this->trackBar_Power->Size = System::Drawing::Size(45, 137);
this->trackBar_Power->TabIndex = 0;
this->trackBar_Power->Scroll += gcnew System::EventHandler(this, &FormMain::trackBar_Power_Scroll);
//
// timer1
//
this->timer1->Enabled = true;
this->timer1->Interval = 10;
this->timer1->Tick += gcnew System::EventHandler(this, &FormMain::timer1_Tick);
//
// FormMain
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(256, 496);
this->Controls->Add(this->groupBox_Input);
this->Controls->Add(this->groupBox_Pos);
this->Controls->Add(this->groupBox_Gyr);
this->Controls->Add(this->groupBox_Acc);
this->Controls->Add(this->groupBox_Server);
this->Margin = System::Windows::Forms::Padding(2);
this->Name = L"FormMain";
this->Text = L"FormMain";
this->groupBox_Server->ResumeLayout(false);
this->groupBox_Server->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericUpDown_Server_Port))->EndInit();
this->groupBox_Acc->ResumeLayout(false);
this->groupBox_Acc->PerformLayout();
this->groupBox_Gyr->ResumeLayout(false);
this->groupBox_Gyr->PerformLayout();
this->groupBox_Pos->ResumeLayout(false);
this->groupBox_Pos->PerformLayout();
this->groupBox_Input->ResumeLayout(false);
this->groupBox_Input->PerformLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->trackBar_Power))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button_Connect_Click(System::Object^ sender, System::EventArgs^ e)
{
NetClient::ClientState done = netClient->Connect(
textBox_Server_Addr->Text,
(int)numericUpDown_Server_Port->Value,
gcnew NetClient::ClientCallback(this, &FormMain::ConnectionCallback),
gcnew NetClient::ClientCallback(this, &FormMain::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;
}
}
private: System::Void trackBar_Power_Scroll(System::Object^ sender, System::EventArgs^ e)
{
float pow = (float)trackBar_Power->Value / 100.0f;
label_Pow->Text = pow.ToString("F2");
dataDrone->MotorUL = dataDrone->MotorUR = dataDrone->MotorDL = dataDrone->MotorDR = pow;
}
private: System::Void button_UU_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
dataDrone->MotorUL -= pow; dataDrone->MotorUR -= pow;
dataDrone->MotorDL += pow; dataDrone->MotorDR += pow;
}
private: System::Void button_DD_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
dataDrone->MotorUL += pow; dataDrone->MotorUR += pow;
dataDrone->MotorDL -= pow; dataDrone->MotorDR -= pow;
}
private: System::Void button_LL_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
dataDrone->MotorUL -= pow; dataDrone->MotorUR += pow;
dataDrone->MotorDL -= pow; dataDrone->MotorDR += pow;
}
private: System::Void button_RR_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
dataDrone->MotorUL += pow; dataDrone->MotorUR -= pow;
dataDrone->MotorDL += pow; dataDrone->MotorDR -= pow;
}
private: System::Void button_ML_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
dataDrone->MotorUL -= pow; dataDrone->MotorUR += pow;
dataDrone->MotorDL += pow; dataDrone->MotorDR -= pow;
}
private: System::Void button_MR_MouseDown(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
dataDrone->MotorUL += pow; dataDrone->MotorUR -= pow;
dataDrone->MotorDL -= pow; dataDrone->MotorDR += pow;
}
private: System::Void button_UU_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
trackBar_Power_Scroll(nullptr, nullptr); // Сброс мощности до значения ползунка
}
private: System::Void button_DD_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
trackBar_Power_Scroll(nullptr, nullptr);
}
private: System::Void button_LL_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
trackBar_Power_Scroll(nullptr, nullptr);
}
private: System::Void button_RR_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
trackBar_Power_Scroll(nullptr, nullptr);
}
private: System::Void button_ML_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
trackBar_Power_Scroll(nullptr, nullptr);
}
private: System::Void button_MR_MouseUp(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
trackBar_Power_Scroll(nullptr, nullptr);
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
label_Acc_X->Text = dataDrone->AccX.ToString("F2");
label_Acc_Y->Text = dataDrone->AccY.ToString("F2");
label_Acc_Z->Text = dataDrone->AccZ.ToString("F2");
label_Gyr_X->Text = dataDrone->GyrX.ToString("F2");
label_Gyr_Y->Text = dataDrone->GyrY.ToString("F2");
label_Gyr_Z->Text = dataDrone->GyrZ.ToString("F2");
label_Pos_X->Text = dataDrone->PosX.ToString("F2");
label_Pos_Y->Text = dataDrone->PosY.ToString("F2");
label_Pos_L->Text = dataDrone->LaserRange.ToString("F2");
// Отправка запроса серверу, как в C#
netClient->Send(dataDrone->SendRequest());
}
};
}