From a87b0ffc69ce109b868592cf4af9c4789f9e7c37 Mon Sep 17 00:00:00 2001 From: pehladik Date: Mon, 30 Mar 2020 15:37:42 +0200 Subject: [PATCH] keep supervisor alive if robot is killed --- .../raspberry/superviseur-robot/lib/comrobot.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/software/raspberry/superviseur-robot/lib/comrobot.cpp b/software/raspberry/superviseur-robot/lib/comrobot.cpp index cbc618a..904f0ba 100644 --- a/software/raspberry/superviseur-robot/lib/comrobot.cpp +++ b/software/raspberry/superviseur-robot/lib/comrobot.cpp @@ -155,17 +155,22 @@ Message *ComRobot::Write(Message* msg) { char buffer[1024] = {0}; cout << "[" << __PRETTY_FUNCTION__ << "] Send command: " << s << endl << flush; - send(sock, s.c_str(), s.length(), 0); + send(sock, s.c_str(), s.length(), MSG_NOSIGNAL); int valread = read(sock, buffer, 1024); - if (valread < 0) { + + if (valread == 0) { + cout << "The communication is out of order" << endl; + msgAnswer = new Message(MESSAGE_ANSWER_COM_ERROR); + } else if (valread < 0) { + cout << "Timeout" << endl; msgAnswer = new Message(MESSAGE_ANSWER_ROBOT_TIMEOUT); } else { string s(&buffer[0], valread); msgAnswer = StringToMessage(s); - //msgAnswer = new Message(MESSAGE_ANSWER_ACK); + cout << "Response: " << buffer << ", id: " << msgAnswer->GetID() << endl; } - cout << "response: " << buffer << ", id: " << msgAnswer->GetID() << endl; + #else AddChecksum(s);