Browse Source

keep supervisor alive if robot is killed

pehladik 4 years ago
parent
commit
a87b0ffc69
1 changed files with 9 additions and 4 deletions
  1. 9
    4
      software/raspberry/superviseur-robot/lib/comrobot.cpp

+ 9
- 4
software/raspberry/superviseur-robot/lib/comrobot.cpp View File

@@ -155,17 +155,22 @@ Message *ComRobot::Write(Message* msg) {
155 155
 
156 156
         char buffer[1024] = {0};
157 157
         cout << "[" << __PRETTY_FUNCTION__ << "] Send command: " << s << endl << flush;
158
-        send(sock, s.c_str(), s.length(), 0);
158
+        send(sock, s.c_str(), s.length(), MSG_NOSIGNAL);
159 159
 
160 160
         int valread = read(sock, buffer, 1024);
161
-        if (valread < 0) {
161
+
162
+        if (valread == 0) {
163
+            cout << "The communication is out of order" << endl;
164
+            msgAnswer = new Message(MESSAGE_ANSWER_COM_ERROR);
165
+        } else if (valread < 0) {
166
+            cout << "Timeout" << endl;
162 167
             msgAnswer = new Message(MESSAGE_ANSWER_ROBOT_TIMEOUT);
163 168
         } else {
164 169
             string s(&buffer[0], valread);
165 170
             msgAnswer = StringToMessage(s);
166
-            //msgAnswer = new Message(MESSAGE_ANSWER_ACK);
171
+            cout << "Response: " << buffer << ", id: " << msgAnswer->GetID() << endl;
167 172
         }
168
-        cout << "response: " <<  buffer << ", id: " << msgAnswer->GetID() << endl;
173
+
169 174
 #else       
170 175
         AddChecksum(s);
171 176
 

Loading…
Cancel
Save