Simple websocket client based on the original with a few added features such as: - setBaud() - set the baud rate for the communication - Initialize() - mimics the constructor - chaged read() to readmsg() to avoid confusion with other functions - Added SerialCommPort

Fork of WebSocketClient by Damien Frost

Files at this revision

API Documentation at this revision

Comitter:
defrost
Date:
Wed Aug 23 10:59:19 2017 +0000
Parent:
29:33d77a538611
Commit message:
- Fixed bug in receiveBytes, it now works

Changed in this revision

Websocket.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 33d77a538611 -r 0b5a84149a79 Websocket.cpp
--- a/Websocket.cpp	Tue Aug 22 11:04:31 2017 +0000
+++ b/Websocket.cpp	Wed Aug 23 10:59:19 2017 +0000
@@ -282,8 +282,9 @@
         }
 
         socket.set_blocking(false, 1);
-        if (socket.receive(&opcode, 1) != 2) {
+        if (socket.receive(&opcode, 1) != 1) {
             socket.set_blocking(false, 2000);
+            DBG(SerialCommPort, "opcode: %d", opcode);
             return 0;
         }
 
@@ -325,15 +326,21 @@
 
     int nb = read(bytes, len_msg, len_msg);
     
+    DBG(SerialCommPort, "Done read(), nb = %d", nb);
+    
     if (nb != len_msg){
         ERR(SerialCommPort, "Unexpected number of bytes read: %d, expected: %d", nb, len_msg);
         return 0;
     }
-
+    
+    DBG(SerialCommPort, "Masking...");
+    
     for (i = 0; i < len_msg; i++) {
         bytes[i] = bytes[i] ^ mask[i % 4];
     }
     
+    DBG(SerialCommPort, "Returning nb = %d", nb);
+    
     // Return the number of bytes read:
     return nb;
 }
@@ -469,7 +476,7 @@
         if ((res = socket.receive_all(str + idx, len - idx)) == -1)
             continue;
         idx += res;
-        DBG(SerialCommPort, "In read(* str, len, min_len), res = %d, idx = %d", res, idx);
+        DBG(SerialCommPort, "In read(* str, len = %d, min_len = %d), res = %d, idx = %d", len, min_len, res, idx);
         if (idx == len || (min_len != -1 && idx > min_len))
             return idx;
     }