Skip to content

Commit 8efd3fe

Browse files
committed
Update processURCEvent for UUSORD
1 parent a0052e2 commit 8efd3fe

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -320,27 +320,33 @@ bool SARA_R5::processURCEvent(const char *event)
320320
{
321321
{ // URC: +UUSORD (Read Socket Data)
322322
int socket, length;
323-
int ret = sscanf(event, "+UUSORD:%d,%d", &socket, &length);
324-
if (ret == 2)
323+
char *searchPtr = strstr(event, "+UUSORD:");
324+
if (searchPtr != nullptr)
325325
{
326-
if (_printDebug == true)
327-
_debugPort->println(F("processReadEvent: read socket data"));
328-
// From the SARA_R5 AT Commands Manual:
329-
// "For the UDP socket type the URC +UUSORD: <socket>,<length> notifies that a UDP packet has been received,
330-
// either when buffer is empty or after a UDP packet has been read and one or more packets are stored in the
331-
// buffer."
332-
// So we need to check if this is a TCP socket or a UDP socket:
333-
// If UDP, we call parseSocketReadIndicationUDP.
334-
// Otherwise, we call parseSocketReadIndication.
335-
if (_lastSocketProtocol[socket] == SARA_R5_UDP)
326+
searchPtr += strlen("+UUSORD:"); // Move searchPtr to first character - probably a space
327+
while (*searchPtr == ' ') searchPtr++; // skip spaces
328+
int ret = sscanf(event, "%d,%d", &socket, &length);
329+
if (ret == 2)
336330
{
337331
if (_printDebug == true)
338-
_debugPort->println(F("processReadEvent: received +UUSORD but socket is UDP. Calling parseSocketReadIndicationUDP"));
339-
parseSocketReadIndicationUDP(socket, length);
332+
_debugPort->println(F("processReadEvent: read socket data"));
333+
// From the SARA_R5 AT Commands Manual:
334+
// "For the UDP socket type the URC +UUSORD: <socket>,<length> notifies that a UDP packet has been received,
335+
// either when buffer is empty or after a UDP packet has been read and one or more packets are stored in the
336+
// buffer."
337+
// So we need to check if this is a TCP socket or a UDP socket:
338+
// If UDP, we call parseSocketReadIndicationUDP.
339+
// Otherwise, we call parseSocketReadIndication.
340+
if (_lastSocketProtocol[socket] == SARA_R5_UDP)
341+
{
342+
if (_printDebug == true)
343+
_debugPort->println(F("processReadEvent: received +UUSORD but socket is UDP. Calling parseSocketReadIndicationUDP"));
344+
parseSocketReadIndicationUDP(socket, length);
345+
}
346+
else
347+
parseSocketReadIndication(socket, length);
348+
return true;
340349
}
341-
else
342-
parseSocketReadIndication(socket, length);
343-
return true;
344350
}
345351
}
346352
{ // URC: +UUSORF (Receive From command (UDP only))

0 commit comments

Comments
 (0)