Browse Source

small modifs

Sébastien DI MERCURIO 2 years ago
parent
commit
111c118844

+ 55
- 19
software/monitor/monitor/MonitorUI.cs View File

@@ -200,6 +200,9 @@ public partial class MainWindow : Gtk.Window
200 200
         a.RetVal = true;
201 201
     }
202 202
 
203
+    private byte[] imageComplete;
204
+    private byte[] imageInProgress;
205
+
203 206
     /// <summary>
204 207
     /// Callback called when new message is received from server
205 208
     /// </summary>
@@ -208,17 +211,47 @@ public partial class MainWindow : Gtk.Window
208 211
     /// <param name="buffer">Raw buffer corresponding of received message</param>
209 212
     public void OnCommandReceivedEvent(string header, string data, byte[] buffer)
210 213
     {
214
+        if (buffer==null)
215
+        {
216
+            // we have lost server
217
+            ChangeState(SystemState.NotConnected);
218
+
219
+            MessagePopup(MessageType.Error,
220
+                     ButtonsType.Ok, "Server lost",
221
+                         "Server is down: disconnecting");
222
+            cmdManager.Close();
223
+        }
224
+
211 225
         // if we have received a valid message
212 226
         if (header != null)
213 227
         {
214 228
 #if DEBUG
215 229
             // print message content
216
-            Console.WriteLine("Received header (" + header.Length + "): " + header);
217
-            if (header.ToUpper() != DestijlCommandList.HeaderStmImage)
230
+            if (header.Length > 4)
231
+                Console.WriteLine("Bad header(" + buffer.Length + ")");
232
+            else
233
+                Console.WriteLine("Received header (" + header.Length + "): " + header);
234
+            //if (header.ToUpper() != DestijlCommandList.HeaderStmImage)
235
+            //{
236
+            //    if (data != null) Console.WriteLine("Received data (" + data.Length + "): " + data);
237
+            //}
238
+#endif
239
+            // Image management
240
+            if (header == DestijlCommandList.HeaderStmImage)
218 241
             {
219
-                if (data != null) Console.WriteLine("Received data (" + data.Length + "): " + data);
242
+                imageComplete = imageInProgress;
243
+                imageInProgress = buffer;
220 244
             }
221
-#endif
245
+            else
246
+            {
247
+                if (imageInProgress == null) imageInProgress = buffer;
248
+                else
249
+                {
250
+                    Array.Resize<byte>(ref imageInProgress, imageInProgress.Length + buffer.Length);
251
+                    System.Buffer.BlockCopy(buffer, 0, imageInProgress, imageInProgress.Length - buffer.Length, buffer.Length);
252
+                }
253
+            }
254
+
222 255
             // depending on message received (based on header)
223 256
             // launch correponding action
224 257
             if (header.ToUpper() == DestijlCommandList.HeaderStmBat)
@@ -243,23 +276,26 @@ public partial class MainWindow : Gtk.Window
243 276
             {
244 277
                 // if message is an image, convert it to a pixbuf
245 278
                 // that can be displayed
246
-                byte[] image = new byte[buffer.Length - 4];
247
-                System.Buffer.BlockCopy(buffer, 4, image, 0, image.Length);
248
-
249
-                imageReceivedCounter++;
250
-                try
251
-                {
252
-                    drawingareaCameraPixbuf = new Pixbuf(image);
253
-                    drawingAreaCamera.QueueDraw();
254
-                }
255
-                catch (GLib.GException)
279
+                if (imageComplete != null)
256 280
                 {
257
-                    badImageReceivedCounter++;
281
+                    byte[] image = new byte[imageComplete.Length - 4];
282
+                    System.Buffer.BlockCopy(imageComplete, 4, image, 0, image.Length);
283
+
284
+                    imageReceivedCounter++;
285
+                    try
286
+                    {
287
+                        drawingareaCameraPixbuf = new Pixbuf(image);
288
+                        drawingAreaCamera.QueueDraw();
289
+                    }
290
+                    catch (GLib.GException)
291
+                    {
292
+                        badImageReceivedCounter++;
258 293
 #if DEBUG
259
-                    Console.WriteLine("Bad Image: " + badImageReceivedCounter +
260
-                                      " / " + imageReceivedCounter +
261
-                                      " (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)");
262
-#endif                    
294
+                        Console.WriteLine("Bad Image: " + badImageReceivedCounter +
295
+                                          " / " + imageReceivedCounter +
296
+                                          " (" + badImageReceivedCounter * 100 / imageReceivedCounter + "%)");
297
+#endif
298
+                    }
263 299
                 }
264 300
             }
265 301
         }

BIN
software/monitor/monitor/monitor View File


+ 48
- 25
software/raspberry/testeur/testeur/main.cpp View File

@@ -63,6 +63,8 @@ MessageToMon messageAnswered;
63 63
 std::thread *threadTimer;
64 64
 std::thread *threadServer;
65 65
 
66
+char* imgMsg = NULL;
67
+
66 68
 using namespace std;
67 69
 
68 70
 /*
@@ -80,7 +82,8 @@ void ThreadTimer(void) {
80 82
     struct timespec tim, tim2;
81 83
     tim.tv_sec = 0;
82 84
     tim.tv_nsec = 100000000;
83
-
85
+    int cnt =0;
86
+    
84 87
     while (1) {
85 88
         //std::this_thread::sleep_for(std::chrono::seconds )
86 89
         //sleep(1);
@@ -89,24 +92,32 @@ void ThreadTimer(void) {
89 92
             return;
90 93
         }
91 94
         
92
-        sysTick = true;
95
+        cnt++;
96
+        
97
+        if (cnt>=1)
98
+        {     
99
+            sysTick = true;
100
+            cnt=0;
101
+        }
93 102
     }
94 103
 }
95 104
 
96 105
 void printReceivedMessage(MessageFromMon *mes) {
97
-    cout << "Received " + to_string(receivedLength) + " data\n";
106
+    cout << "Received " + to_string(receivedLength) + " data";
107
+    cout << std::endl;
98 108
     cout << "Header: ";
99 109
 
100 110
     for (int i = 0; i < 4; i++) {
101 111
         cout << mes->header[i];
102 112
     }
103 113
 
104
-    cout << "\nData: ";
114
+    cout << std::endl;
115
+    cout << "Data: ";
105 116
     for (int i = 0; i < receivedLength - 4; i++) {
106 117
         cout << mes->data[i];
107 118
     }
108 119
 
109
-    cout << "\n";
120
+    cout << std::endl;
110 121
 }
111 122
 
112 123
 int sendAnswer(string cmd, string data) {
@@ -115,7 +126,7 @@ int sendAnswer(string cmd, string data) {
115 126
 
116 127
     msg = cmd + ':' + data;
117 128
     cout << "Answer: " + msg;
118
-    cout << "\n";
129
+    cout << std::endl;
119 130
     sendDataToServer((char*) msg.c_str(), msg.length());
120 131
 
121 132
     return status;
@@ -123,20 +134,23 @@ int sendAnswer(string cmd, string data) {
123 134
 
124 135
 int sendBinaryData(string cmd, char* data, int length) {
125 136
     int status = 0;
126
-    char* msg;
127
-
128
-    msg = (char*) malloc(length + 4);
129
-    msg[0] = cmd[0];
130
-    msg[1] = cmd[1];
131
-    msg[2] = cmd[2];
132
-    msg[3] = ':';
133
-
134
-    memcpy((void*) &msg[4], (const void *) data, length);
137
+    int lengthSend;
138
+    
139
+    if (imgMsg != NULL) free((void*) imgMsg);
140
+    imgMsg = (char*) malloc(length + 4);
141
+    imgMsg[0] = cmd[0];
142
+    imgMsg[1] = cmd[1];
143
+    imgMsg[2] = cmd[2];
144
+    imgMsg[3] = ':';
145
+
146
+    memcpy((void*) &imgMsg[4], (const void *) data, length);
135 147
     cout << "Answer: " + cmd;
136
-    cout << "\n";
137
-    sendDataToServer(msg, length + 4);
148
+    cout << std::endl;
149
+
150
+    lengthSend=sendDataToServer(imgMsg, length + 4);
138 151
 
139
-    free((void*) msg);
152
+    cout << "Requested Length: " + to_string(length) + " / Send Length: " + to_string(lengthSend);
153
+    cout << std::endl;
140 154
     return status;
141 155
 }
142 156
 
@@ -198,30 +212,39 @@ int main(int argc, char** argv) {
198 212
 #else
199 213
     if (open_communication_robot("/dev/ttyS0") != 0) {
200 214
 #endif /*__FOR_PC__ */
201
-        cerr << "Unable to open /dev/ttyUSB0: abort\n";
215
+        cerr << "Unable to open /dev/ttyUSB0: abort";
216
+        cout << std::endl;
202 217
         return -1;
203 218
     }
204
-    cout << "Com port opened\n";
219
+    cout << "Com port opened";
220
+    cout << std::endl;
205 221
      
206 222
     // Ouverture de la camera
207 223
     if (open_camera(&cam) == -1) {
208
-        cerr << "Unable to open camera: abort\n";
224
+        cerr << "Unable to open camera: abort";
225
+        cout << std::endl;
226
+        
209 227
         return -1;
210 228
     }
211
-    cout << "Camera opened\n";
229
+    cout << "Camera opened";
230
+    cout << std::endl;
212 231
 
213 232
     // Ouverture du serveur
214 233
     socketID = openServer(5544);
215
-    cout << "Server opened on port 5544\n";
234
+    cout << "Server opened on port 5544";
235
+    cout << std::endl;
216 236
 
217 237
     threadTimer = new std::thread(ThreadTimer);
218 238
 
219 239
     for (;;) {
220
-        cout << "Waiting for client to connect ...\n";
240
+        cout << "Waiting for client to connect ...";
241
+        cout << std::endl;
221 242
         acceptClient();
222 243
         disconnected = false;
223 244
         dataReady = false;
224
-        cout << "Client connected\n";
245
+        cout << "Client connected";
246
+        cout << std::endl;
247
+        
225 248
         threadServer = new std::thread(ThreadServer);
226 249
 
227 250
         while (disconnected == false) {

+ 10
- 10
software/raspberry/testeur/testeur/nbproject/private/timestamps-10.105.1.13-pi-22 View File

@@ -1,26 +1,26 @@
1
-#Mon Nov 12 09:47:39 CET 2018
1
+#Mon Nov 12 11:20:04 CET 2018
2 2
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/robot.h=c1541685829000
3
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/project.xml=c1541775358000
4
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-impl.mk=c1541775357000
3
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/project.xml=c1542014288000
4
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-impl.mk=c1542014288000
5 5
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/robot.cpp=c1541685829000
6 6
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/image.h=c1541685829000
7
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/main.cpp=c1541778496000
8
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/server.cpp=c1541685829000
7
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/main.cpp=c1542017998000
8
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/server.cpp=c1542014288000
9 9
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-Release.mk=c1541685829000
10 10
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/message.cpp=c1541685829000
11 11
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Package-Debug.bash=c1541685829000
12 12
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/.gitignore=c1541685829000
13
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-variables.mk=c1541775358000
14
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/private/Makefile-variables.mk=c1541775358000
13
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-variables.mk=c1542014288000
14
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/private/Makefile-variables.mk=c1542014288000
15 15
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/Makefile=c1541685829000
16
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-Debug-rpi.mk=c1541776257000
16
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-Debug-rpi.mk=c1542014288000
17 17
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Makefile-Debug.mk=c1541775193000
18 18
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/message.h=c1541685829000
19
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/image.cpp=c1541778370000
19
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/image.cpp=c1542014288000
20 20
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Package-Release.bash=c1541685829000
21 21
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/.dep.inc=c1541685829000
22 22
 VERSION=1.3
23 23
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/server.h=c1541685829000
24 24
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/definitions.h=c1541685829000
25
-/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Package-Debug-rpi.bash=c1541775358000
25
+/home/dimercur/Documents/Travail/git/dumber/software/raspberry/testeur/testeur/nbproject/Package-Debug-rpi.bash=c1542014288000
26 26
 /home/dimercur/Documents/Travail/git/dumber/software/raspberry/superviseur-robot/lib/src/monitor.cpp=c1541685829000

Loading…
Cancel
Save