Adding ability to set priority for the Rx thread

Fork of ublox-at-cellular-interface by u-blox

Revision:
10:ba18f4418ee8
Parent:
7:3b2ca10cc23a
Child:
11:cc41a8636f7e
Child:
12:ff6fac481487
--- a/UbloxATCellularInterface.cpp	Wed Sep 27 15:33:07 2017 +0500
+++ b/UbloxATCellularInterface.cpp	Mon Oct 30 14:48:14 2017 +0000
@@ -688,8 +688,12 @@
                                   // losing characters in UARTSerial
             if (_at->send("AT+USORD=%d,%d", socket->modem_handle, read_blk) &&
                 _at->recv("+USORD: %*d,%d,\"", &usord_sz)) {
-                socket->pending -= usord_sz; // Must use what +USORD returns here as it
-                                             // may be less than we asked for
+                // Must use what +USORD returns here as it may be less or more than we asked for
+                if (usord_sz > socket->pending) {
+                    socket->pending = 0;
+                } else {
+                    socket->pending -= usord_sz; 
+                }
                 // Note: insert no debug between _at->recv() and _at->read(), no time...
                 if (usord_sz > size) {
                     usord_sz = size;
@@ -803,8 +807,12 @@
             if (_at->send("AT+USORF=%d,%d", socket->modem_handle, read_blk) &&
                 _at->recv("+USORF: %*d,\"%" u_stringify(NSAPI_IP_SIZE) "[^\"]\",%d,%d,\"",
                           ipAddress, &port, &usorf_sz)) {
-                socket->pending -= usorf_sz; // Must use what +USORF returns here as it
-                                             // may be less than we asked for
+                // Must use what +USORF returns here as it may be less or more than we asked for
+                if (usorf_sz > socket->pending) {
+                    socket->pending = 0;
+                } else {
+                    socket->pending -= usorf_sz; 
+                }
                 // Note: insert no debug between _at->recv() and _at->read(), no time...
                 if (usorf_sz > size) {
                     usorf_sz = size;