mirror of
https://github.com/yoboujon/dumber.git
synced 2025-06-08 22:00:49 +02:00
keep supervisor alive if robot is killed
This commit is contained in:
parent
89a2bae5c0
commit
a87b0ffc69
1 changed files with 9 additions and 4 deletions
|
@ -155,17 +155,22 @@ Message *ComRobot::Write(Message* msg) {
|
||||||
|
|
||||||
char buffer[1024] = {0};
|
char buffer[1024] = {0};
|
||||||
cout << "[" << __PRETTY_FUNCTION__ << "] Send command: " << s << endl << flush;
|
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);
|
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);
|
msgAnswer = new Message(MESSAGE_ANSWER_ROBOT_TIMEOUT);
|
||||||
} else {
|
} else {
|
||||||
string s(&buffer[0], valread);
|
string s(&buffer[0], valread);
|
||||||
msgAnswer = StringToMessage(s);
|
msgAnswer = StringToMessage(s);
|
||||||
//msgAnswer = new Message(MESSAGE_ANSWER_ACK);
|
cout << "Response: " << buffer << ", id: " << msgAnswer->GetID() << endl;
|
||||||
}
|
}
|
||||||
cout << "response: " << buffer << ", id: " << msgAnswer->GetID() << endl;
|
|
||||||
#else
|
#else
|
||||||
AddChecksum(s);
|
AddChecksum(s);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue