From 5f8067c83d0540e1ad429b493dac1dcdee6f2f3d Mon Sep 17 00:00:00 2001 From: ackimixs Date: Thu, 18 Apr 2024 20:19:22 +0200 Subject: [PATCH] sleep --- TCPServer.cpp | 11 +++++++---- TCPServer.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/TCPServer.cpp b/TCPServer.cpp index 2219e67..af7d8e4 100644 --- a/TCPServer.cpp +++ b/TCPServer.cpp @@ -264,7 +264,9 @@ void TCPServer::handleMessage(const std::string& message, int clientSocket) } } else if (tokens[0] == "arduino" && tokens[2] == "set state") { - this->isRobotIdle = TCPUtils::startWith(tokens[3], "0"); + if (TCPUtils::startWith(tokens[3], "0")) { + this->isRobotIdle++; + } } std::cout << "Received: " << message << std::endl; } @@ -1315,11 +1317,12 @@ void TCPServer::askArduinoPos() { } void TCPServer::awaitRobotIdle() { - isRobotIdle = false; + isRobotIdle = 0; // ReSharper disable once CppDFAConstantConditions // ReSharper disable once CppDFAEndlessLoop - while (!isRobotIdle) { - usleep(100'000); + usleep(200'000); + while (isRobotIdle < 3) { + usleep(200'000); this->broadcastMessage("strat;arduino;get state;1\n"); } } diff --git a/TCPServer.h b/TCPServer.h index 3bf6733..9e13b7e 100644 --- a/TCPServer.h +++ b/TCPServer.h @@ -52,7 +52,7 @@ private: std::vector clients; // Store connected clients PinceState pinceState[3] = {NONE, NONE, NONE}; - bool isRobotIdle = true; + int isRobotIdle = 0; struct Position { struct {