#pragma once #include "Drone.h" // Новый Drone.h #include "DroneData.h" // Новый DroneData.h #include "NetClient.h" #include #include // Task, create_task #include "WsServer.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; using namespace System::Threading; using namespace System::Threading::Tasks; using namespace System::Net::WebSockets; using namespace concurrency; // пространство PPL public ref class FormMain : public System::Windows::Forms::Form { public: FormMain(void) { InitializeComponent(); netClient = gcnew NetClient(); dataDrone = gcnew Drone(); // Инициализация объекта Drone wsClient = gcnew WsServer(); } 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; private: System::Windows::Forms::Label^ label_time_acc; private: System::Windows::Forms::Label^ label_time_gyr; private: System::Windows::Forms::Label^ label_time_range; private: System::Windows::Forms::GroupBox^ groupBox1; private: System::Windows::Forms::Button^ button1; const float pow = 0.1f; WsServer^ wsClient; // WebSocket‑клиент private: System::Windows::Forms::Label^ label3; private: System::Windows::Forms::Label^ label2; private: System::Windows::Forms::Label^ label1; private: System::Windows::Forms::Label^ label6; private: System::Windows::Forms::Label^ label5; private: System::Windows::Forms::Label^ label4; bool _working = false; private: System::Windows::Forms::Label^ label8; private: System::Windows::Forms::Label^ label7; // Наши методы 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^>^ responses = dataDrone->DataStream(data->Buffer, data->Size); if (responses == nullptr) return; try { for each (array ^ b in responses) { if (b != nullptr) data->Server->Send(b); } } catch (...) {} } #pragma region Windows Form Designer generated code /// /// Требуемый метод для поддержки конструктора — не изменяйте /// содержимое этого метода с помощью редактора кода. /// 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_time_acc = (gcnew System::Windows::Forms::Label()); 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_time_gyr = (gcnew System::Windows::Forms::Label()); 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_time_range = (gcnew System::Windows::Forms::Label()); 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->groupBox1 = (gcnew System::Windows::Forms::GroupBox()); this->label6 = (gcnew System::Windows::Forms::Label()); this->label5 = (gcnew System::Windows::Forms::Label()); this->label4 = (gcnew System::Windows::Forms::Label()); this->label3 = (gcnew System::Windows::Forms::Label()); this->label2 = (gcnew System::Windows::Forms::Label()); this->label1 = (gcnew System::Windows::Forms::Label()); this->button1 = (gcnew System::Windows::Forms::Button()); this->label7 = (gcnew System::Windows::Forms::Label()); this->label8 = (gcnew System::Windows::Forms::Label()); this->groupBox_Server->SuspendLayout(); (cli::safe_cast(this->numericUpDown_Server_Port))->BeginInit(); this->groupBox_Acc->SuspendLayout(); this->groupBox_Gyr->SuspendLayout(); this->groupBox_Pos->SuspendLayout(); this->groupBox_Input->SuspendLayout(); (cli::safe_cast(this->trackBar_Power))->BeginInit(); this->groupBox1->SuspendLayout(); 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->Margin = System::Windows::Forms::Padding(4); this->groupBox_Server->Name = L"groupBox_Server"; this->groupBox_Server->Padding = System::Windows::Forms::Padding(4); this->groupBox_Server->Size = System::Drawing::Size(533, 110); 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(5, 26); this->label_Addr->Name = L"label_Addr"; this->label_Addr->Size = System::Drawing::Size(39, 16); this->label_Addr->TabIndex = 5; this->label_Addr->Text = L"Addr:"; // // button_Connect // this->button_Connect->Location = System::Drawing::Point(153, 66); this->button_Connect->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button_Connect->Name = L"button_Connect"; this->button_Connect->Size = System::Drawing::Size(116, 27); 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(56, 66); this->numericUpDown_Server_Port->Margin = System::Windows::Forms::Padding(3, 2, 3, 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(93, 22); 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(56, 23); this->textBox_Server_Addr->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->textBox_Server_Addr->Name = L"textBox_Server_Addr"; this->textBox_Server_Addr->Size = System::Drawing::Size(215, 22); 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(5, 70); this->label_Port->Name = L"label_Port"; this->label_Port->Size = System::Drawing::Size(34, 16); this->label_Port->TabIndex = 1; this->label_Port->Text = L"Port:"; // // groupBox_Acc // this->groupBox_Acc->Controls->Add(this->label_time_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(8, 116); this->groupBox_Acc->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Acc->Name = L"groupBox_Acc"; this->groupBox_Acc->Padding = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Acc->Size = System::Drawing::Size(101, 137); this->groupBox_Acc->TabIndex = 1; this->groupBox_Acc->TabStop = false; this->groupBox_Acc->Text = L"Acc"; // // label_time_acc // this->label_time_acc->AutoSize = true; this->label_time_acc->Location = System::Drawing::Point(7, 118); this->label_time_acc->Name = L"label_time_acc"; this->label_time_acc->Size = System::Drawing::Size(14, 16); this->label_time_acc->TabIndex = 6; this->label_time_acc->Text = L"0"; // // label_Acc_Z // this->label_Acc_Z->AutoSize = true; this->label_Acc_Z->Location = System::Drawing::Point(23, 75); this->label_Acc_Z->Name = L"label_Acc_Z"; this->label_Acc_Z->Size = System::Drawing::Size(14, 16); 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(23, 48); this->label_Acc_Y->Name = L"label_Acc_Y"; this->label_Acc_Y->Size = System::Drawing::Size(14, 16); 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(23, 20); this->label_Acc_X->Name = L"label_Acc_X"; this->label_Acc_X->Size = System::Drawing::Size(14, 16); 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(5, 75); this->label_Acc_Z_Info->Name = L"label_Acc_Z_Info"; this->label_Acc_Z_Info->Size = System::Drawing::Size(21, 16); 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(4, 48); this->label_Acc_Y_Info->Name = L"label_Acc_Y_Info"; this->label_Acc_Y_Info->Size = System::Drawing::Size(22, 16); 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(5, 20); this->label_Acc_X_Info->Name = L"label_Acc_X_Info"; this->label_Acc_X_Info->Size = System::Drawing::Size(21, 16); this->label_Acc_X_Info->TabIndex = 0; this->label_Acc_X_Info->Text = L"X: "; // // groupBox_Gyr // this->groupBox_Gyr->Controls->Add(this->label_time_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(123, 116); this->groupBox_Gyr->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Gyr->Name = L"groupBox_Gyr"; this->groupBox_Gyr->Padding = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Gyr->Size = System::Drawing::Size(96, 137); this->groupBox_Gyr->TabIndex = 6; this->groupBox_Gyr->TabStop = false; this->groupBox_Gyr->Text = L"Gyr"; // // label_time_gyr // this->label_time_gyr->AutoSize = true; this->label_time_gyr->Location = System::Drawing::Point(4, 118); this->label_time_gyr->Name = L"label_time_gyr"; this->label_time_gyr->Size = System::Drawing::Size(14, 16); this->label_time_gyr->TabIndex = 7; this->label_time_gyr->Text = L"0"; // // label_Gyr_Z // this->label_Gyr_Z->AutoSize = true; this->label_Gyr_Z->Location = System::Drawing::Point(23, 75); this->label_Gyr_Z->Name = L"label_Gyr_Z"; this->label_Gyr_Z->Size = System::Drawing::Size(14, 16); 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(23, 48); this->label_Gyr_Y->Name = L"label_Gyr_Y"; this->label_Gyr_Y->Size = System::Drawing::Size(14, 16); 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(23, 20); this->label_Gyr_X->Name = L"label_Gyr_X"; this->label_Gyr_X->Size = System::Drawing::Size(14, 16); 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(5, 75); this->label_Gyr_Z_Info->Name = L"label_Gyr_Z_Info"; this->label_Gyr_Z_Info->Size = System::Drawing::Size(21, 16); 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(4, 48); this->label_Gyr_Y_Info->Name = L"label_Gyr_Y_Info"; this->label_Gyr_Y_Info->Size = System::Drawing::Size(22, 16); 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(5, 20); this->label_Gyr_X_Info->Name = L"label_Gyr_X_Info"; this->label_Gyr_X_Info->Size = System::Drawing::Size(21, 16); this->label_Gyr_X_Info->TabIndex = 0; this->label_Gyr_X_Info->Text = L"X: "; // // groupBox_Pos // this->groupBox_Pos->Controls->Add(this->label_time_range); 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(236, 116); this->groupBox_Pos->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Pos->Name = L"groupBox_Pos"; this->groupBox_Pos->Padding = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Pos->Size = System::Drawing::Size(96, 137); this->groupBox_Pos->TabIndex = 7; this->groupBox_Pos->TabStop = false; this->groupBox_Pos->Text = L"Pos"; // // label_time_range // this->label_time_range->AutoSize = true; this->label_time_range->Location = System::Drawing::Point(5, 118); this->label_time_range->Name = L"label_time_range"; this->label_time_range->Size = System::Drawing::Size(14, 16); this->label_time_range->TabIndex = 8; this->label_time_range->Text = L"0"; // // label_Pos_L // this->label_Pos_L->AutoSize = true; this->label_Pos_L->Location = System::Drawing::Point(23, 75); this->label_Pos_L->Name = L"label_Pos_L"; this->label_Pos_L->Size = System::Drawing::Size(14, 16); 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(23, 48); this->label_Pos_Y->Name = L"label_Pos_Y"; this->label_Pos_Y->Size = System::Drawing::Size(14, 16); 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(23, 20); this->label_Pos_X->Name = L"label_Pos_X"; this->label_Pos_X->Size = System::Drawing::Size(14, 16); 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(5, 75); this->label_Pos_L_Info->Name = L"label_Pos_L_Info"; this->label_Pos_L_Info->Size = System::Drawing::Size(17, 16); 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(4, 48); this->label_Pos_Y_Info->Name = L"label_Pos_Y_Info"; this->label_Pos_Y_Info->Size = System::Drawing::Size(22, 16); 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(5, 20); this->label_Pos_X_Info->Name = L"label_Pos_X_Info"; this->label_Pos_X_Info->Size = System::Drawing::Size(21, 16); 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(8, 257); this->groupBox_Input->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Input->Name = L"groupBox_Input"; this->groupBox_Input->Padding = System::Windows::Forms::Padding(3, 2, 3, 2); this->groupBox_Input->Size = System::Drawing::Size(325, 345); this->groupBox_Input->TabIndex = 8; this->groupBox_Input->TabStop = false; // // label_Pow // this->label_Pow->AutoSize = true; this->label_Pow->Location = System::Drawing::Point(137, 256); this->label_Pow->Margin = System::Windows::Forms::Padding(4, 0, 4, 0); this->label_Pow->Name = L"label_Pow"; this->label_Pow->Size = System::Drawing::Size(14, 16); this->label_Pow->TabIndex = 10; this->label_Pow->Text = L"0"; // // button_RR // this->button_RR->Location = System::Drawing::Point(228, 165); this->button_RR->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button_RR->Name = L"button_RR"; this->button_RR->Size = System::Drawing::Size(77, 25); 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(8, 165); this->button_LL->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button_LL->Name = L"button_LL"; this->button_LL->Size = System::Drawing::Size(77, 25); 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(228, 37); this->button_MR->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button_MR->Name = L"button_MR"; this->button_MR->Size = System::Drawing::Size(77, 25); 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(8, 37); this->button_ML->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button_ML->Name = L"button_ML"; this->button_ML->Size = System::Drawing::Size(77, 25); 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(107, 308); this->button_DD->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button_DD->Name = L"button_DD"; this->button_DD->Size = System::Drawing::Size(77, 25); 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(115, 37); this->button_UU->Margin = System::Windows::Forms::Padding(3, 2, 3, 2); this->button_UU->Name = L"button_UU"; this->button_UU->Size = System::Drawing::Size(77, 25); 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(132, 85); this->trackBar_Power->Margin = System::Windows::Forms::Padding(3, 2, 3, 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(56, 169); 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); // // groupBox1 // this->groupBox1->Controls->Add(this->label6); this->groupBox1->Controls->Add(this->label5); this->groupBox1->Controls->Add(this->label4); this->groupBox1->Controls->Add(this->label3); this->groupBox1->Controls->Add(this->label2); this->groupBox1->Controls->Add(this->label1); this->groupBox1->Controls->Add(this->button1); this->groupBox1->Dock = System::Windows::Forms::DockStyle::Top; this->groupBox1->Location = System::Drawing::Point(0, 110); this->groupBox1->Name = L"groupBox1"; this->groupBox1->Size = System::Drawing::Size(533, 100); this->groupBox1->TabIndex = 9; this->groupBox1->TabStop = false; this->groupBox1->Text = L"groupBox1"; // // label6 // this->label6->AutoSize = true; this->label6->Location = System::Drawing::Point(365, 72); this->label6->Name = L"label6"; this->label6->Size = System::Drawing::Size(44, 16); this->label6->TabIndex = 6; this->label6->Text = L"label6"; // // label5 // this->label5->AutoSize = true; this->label5->Location = System::Drawing::Point(365, 45); this->label5->Name = L"label5"; this->label5->Size = System::Drawing::Size(44, 16); this->label5->TabIndex = 5; this->label5->Text = L"label5"; // // label4 // this->label4->AutoSize = true; this->label4->Location = System::Drawing::Point(365, 18); this->label4->Name = L"label4"; this->label4->Size = System::Drawing::Size(44, 16); this->label4->TabIndex = 4; this->label4->Text = L"label4"; // // label3 // this->label3->AutoSize = true; this->label3->Location = System::Drawing::Point(321, 72); this->label3->Name = L"label3"; this->label3->Size = System::Drawing::Size(34, 16); this->label3->TabIndex = 3; this->label3->Text = L"yaw:"; this->label3->TextAlign = System::Drawing::ContentAlignment::TopCenter; // // label2 // this->label2->AutoSize = true; this->label2->Location = System::Drawing::Point(321, 45); this->label2->Name = L"label2"; this->label2->Size = System::Drawing::Size(28, 16); this->label2->TabIndex = 2; this->label2->Text = L"roll:"; // // label1 // this->label1->AutoSize = true; this->label1->Location = System::Drawing::Point(321, 18); this->label1->Name = L"label1"; this->label1->Size = System::Drawing::Size(38, 16); this->label1->TabIndex = 1; this->label1->Text = L"pitch:"; // // button1 // this->button1->Location = System::Drawing::Point(28, 27); this->button1->Name = L"button1"; this->button1->Size = System::Drawing::Size(121, 23); this->button1->TabIndex = 0; this->button1->Text = L"connect ws"; this->button1->UseVisualStyleBackColor = true; this->button1->Click += gcnew System::EventHandler(this, &FormMain::button1_Click); // // label7 // this->label7->AutoSize = true; this->label7->Location = System::Drawing::Point(415, 243); this->label7->Name = L"label7"; this->label7->Size = System::Drawing::Size(44, 16); this->label7->TabIndex = 10; this->label7->Text = L"label7"; // // label8 // this->label8->AutoSize = true; this->label8->Location = System::Drawing::Point(418, 263); this->label8->Name = L"label8"; this->label8->Size = System::Drawing::Size(44, 16); this->label8->TabIndex = 11; this->label8->Text = L"label8"; // // FormMain // this->AutoScaleDimensions = System::Drawing::SizeF(8, 16); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(533, 610); this->Controls->Add(this->label8); this->Controls->Add(this->label7); this->Controls->Add(this->groupBox1); 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(3, 2, 3, 2); this->Name = L"FormMain"; this->Text = L"FormMain"; this->groupBox_Server->ResumeLayout(false); this->groupBox_Server->PerformLayout(); (cli::safe_cast(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(this->trackBar_Power))->EndInit(); this->groupBox1->ResumeLayout(false); this->groupBox1->PerformLayout(); this->ResumeLayout(false); this->PerformLayout(); } #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("F3"); label_Acc_Y->Text = dataDrone->AccY.ToString("F3"); label_Acc_Z->Text = dataDrone->AccZ.ToString("F3"); label_time_acc->Text = dataDrone->TimeAcc.ToString(); label_Gyr_X->Text = dataDrone->GyrX.ToString("F3"); label_Gyr_Y->Text = dataDrone->GyrY.ToString("F3"); label_Gyr_Z->Text = dataDrone->GyrZ.ToString("F3"); label_time_gyr->Text = dataDrone->TimeGyr.ToString(); label_Pos_X->Text = dataDrone->PosX.ToString("F3"); label_Pos_Y->Text = dataDrone->PosY.ToString("F3"); label_Pos_L->Text = dataDrone->LaserRange.ToString("F3"); label_time_range->Text = dataDrone->TimeRange.ToString(); label4->Text = dataDrone->pitch.ToString("F3"); label5->Text = dataDrone->roll.ToString("F3"); label6->Text = dataDrone->yaw.ToString("F3"); label7->Text = dataDrone->desPitch.ToString("F3"); label8->Text = dataDrone->desRoll.ToString("F3"); // Отправка запроса серверу, как в C# netClient->Send(dataDrone->SendRequest()); } private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (!wsClient->IsConnected) { // Пытаемся подключиться к Node‑серверу if (wsClient->Connect("ws://localhost:8080/")) { // -------- старт потока ------------- wsClient->_runTx = true; wsClient->_txThread = gcnew System::Threading::Thread( gcnew System::Threading::ParameterizedThreadStart( wsClient, &WsServer::TxLoop)); wsClient->_txThread->IsBackground = true; wsClient->_txThread->Start(dataDrone); // <-- передаём Drone^ // ----------------------------------- button1->Text = "disconnect ws"; button1->BackColor = System::Drawing::Color::LimeGreen; } else { System::Windows::Forms::MessageBox::Show("Не удалось подключиться"); } } else { wsClient->_runTx = false; if (wsClient->_txThread && wsClient->_txThread->IsAlive) wsClient->_txThread->Join(); // ждём завершения wsClient->Disconnect(); button1->Text = "connect ws"; button1->BackColor = System::Drawing::Color::Transparent; } } }; }