From e0af20b46d3b92488e8669eefcf26a5f90688cbe Mon Sep 17 00:00:00 2001 From: Dizel Date: Fri, 4 Apr 2025 13:14:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B5=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...work,Version=v4.7.2.AssemblyAttributes.cpp | 2 + ...eClientCpp.vcxproj.AssemblyReference.cache | Bin 0 -> 3122 bytes TestClientConnection/TestClientConnection.cpp | 140 ------------------ .../TestClientConnection.vcxproj | 135 ----------------- .../TestClientConnection.vcxproj.filters | 22 --- 5 files changed, 2 insertions(+), 297 deletions(-) create mode 100644 DroneClientCpp/DroneClientCpp/x64/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cpp create mode 100644 DroneClientCpp/DroneClientCpp/x64/Debug/DroneClientCpp.vcxproj.AssemblyReference.cache delete mode 100644 TestClientConnection/TestClientConnection.cpp delete mode 100644 TestClientConnection/TestClientConnection.vcxproj delete mode 100644 TestClientConnection/TestClientConnection.vcxproj.filters diff --git a/DroneClientCpp/DroneClientCpp/x64/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cpp b/DroneClientCpp/DroneClientCpp/x64/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cpp new file mode 100644 index 0000000..62124be --- /dev/null +++ b/DroneClientCpp/DroneClientCpp/x64/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cpp @@ -0,0 +1,2 @@ +#using +[assembly: System::Runtime::Versioning::TargetFrameworkAttribute(L".NETFramework,Version=v4.7.2", FrameworkDisplayName=L".NET Framework 4.7.2")]; diff --git a/DroneClientCpp/DroneClientCpp/x64/Debug/DroneClientCpp.vcxproj.AssemblyReference.cache b/DroneClientCpp/DroneClientCpp/x64/Debug/DroneClientCpp.vcxproj.AssemblyReference.cache new file mode 100644 index 0000000000000000000000000000000000000000..0cd43936b46751cfe6dc03228d6928c4faf7262e GIT binary patch literal 3122 zcmd5;%Wl&^6!jGlg_MU12&ua)sf4UTD+=A9Ds6UDsIGv8rD`(14x`Q^%s36{rt7X) z@FVQ_lJ5Bw#_m{P;*I68gcp$~W1qP`_uQk?gI*8>a5~zH-)lA1L=4A_qZvN?`uf#o ze2gh-loW^i#-NyRh9-W;s8&X$Sv6z zlZ+|Z2=T|;)64bi!Cr|taEPA-Z-i5=EJuTZrD7}G-r9cgCV-?%mJdiqYN)=OSK*85 z-VHG=NCEIeF2G~gq!Ue~AvABgX;s)m2Y56Ws2Obs=3kUgU3tfInK6Okh|teWP8)sl zzd~Pgm?NdJ5l~g>02>bIP-duSni-5xpEHWhSgh8!IzZD-2S}5JCA4OSyxNtI8S<^J zRi;IkOn+oDQ414}l@_Lk?}1Oxdf=paaMRvKGOy|pptOhx>0GmH*$T{;5&966HzV+^ zOo03Q)Y^z)6UN&zzFtZJXIw1>%B)obpF6nHk*(!1!r4U;Knih_%-W#|BSmH{PFkH# z+U0cG)KfE)c|!ZIa>S#unR)JszVLQo&3}ws?HcK%Yh{M6=~+?29s7GvTBl`+B%$Q9 awR|B{`qzDu-xm+b^sLw@7sXB`#r_69nJ?b} literal 0 HcmV?d00001 diff --git a/TestClientConnection/TestClientConnection.cpp b/TestClientConnection/TestClientConnection.cpp deleted file mode 100644 index 37dc7f9..0000000 --- a/TestClientConnection/TestClientConnection.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#pragma comment(lib, "Ws2_32.lib") - -struct DataIn -{ - float AccX, AccY, AccZ; - float GyrX, GyrY, GyrZ; - float PosX, PosY, LaserRange; -} dataIn; - -struct DataOut -{ - float MotorUL, MotorUR, MotorDL, MotorDR; -} dataOut; - -std::atomic running(true); // Флаг работы потоков -std::mutex dataMutex; // Мьютекс для синхронизации доступа к dataIn и dataOut - -SOCKET ConnectToServer(const char* ip, int port) -{ - WSAData wsaData; - WORD DLLVersion = MAKEWORD(2, 1); - - if (WSAStartup(DLLVersion, &wsaData) != 0) - { - std::cout << "Error: WSAStartup failed\n"; - return INVALID_SOCKET; - } - - SOCKADDR_IN addr; - inet_pton(AF_INET, ip, &addr.sin_addr); - addr.sin_port = htons(port); - addr.sin_family = AF_INET; - - SOCKET Connection = socket(AF_INET, SOCK_STREAM, 0); - if (Connection == INVALID_SOCKET) - { - std::cout << "Error: Failed to create socket\n"; - WSACleanup(); - return INVALID_SOCKET; - } - - if (connect(Connection, (SOCKADDR*)&addr, sizeof(addr)) != 0) - { - std::cout << "Error: Failed to connect to server\n"; - closesocket(Connection); - WSACleanup(); - return INVALID_SOCKET; - } - - return Connection; -} - -void CloseConnection(SOCKET& socket) -{ - if (socket != INVALID_SOCKET) - { - closesocket(socket); - WSACleanup(); - socket = INVALID_SOCKET; - } -} - -// Функция приема данных -void ReceiveHandler(SOCKET socket) -{ - while (running) - { - DataIn tempData; - int result = recv(socket, (char*)&tempData, sizeof(tempData), 0); - - if (result <= 0) - { - std::cout << "Error: Connection lost (recv failed)\n"; - running = false; - break; - } - - // Потокобезопасное обновление данных - std::lock_guard lock(dataMutex); - dataIn = tempData; - } -} - -// Функция отправки данных -void SendHandler(SOCKET socket) -{ - while (running) - { - { - std::lock_guard lock(dataMutex); - send(socket, (char*)&dataOut, sizeof(dataOut), 0); - } - std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Задержка для уменьшения нагрузки - } -} - -int main() -{ - SOCKET Connection = ConnectToServer("127.0.0.1", 1001); - if (Connection == INVALID_SOCKET) - { - return 1; - } - - dataOut.MotorUL = 10; - dataOut.MotorUR = 10; - dataOut.MotorDL = 10; - dataOut.MotorDR = 10; - - // Создание потоков - std::thread recvThread(ReceiveHandler, Connection); - std::thread sendThread(SendHandler, Connection); - - for (int i = 0; i < 1000000; i++) - { - { - std::lock_guard lock(dataMutex); - std::cout << "Laser Range: " << dataIn.LaserRange << std::endl; - } - std::cout << "-----------------------------------------------------------" << std::endl; - std::this_thread::sleep_for(std::chrono::milliseconds(500)); // Задержка вывода - } - - // Завершаем работу потоков - running = false; - recvThread.join(); - sendThread.join(); - - CloseConnection(Connection); - - system("pause"); - return 0; -} diff --git a/TestClientConnection/TestClientConnection.vcxproj b/TestClientConnection/TestClientConnection.vcxproj deleted file mode 100644 index 89baf73..0000000 --- a/TestClientConnection/TestClientConnection.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {b7cc5245-b628-40e9-a9a0-a904e2bf25ea} - TestClientConnection - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/TestClientConnection/TestClientConnection.vcxproj.filters b/TestClientConnection/TestClientConnection.vcxproj.filters deleted file mode 100644 index 505cabd..0000000 --- a/TestClientConnection/TestClientConnection.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file