@@ -219,7 +219,7 @@ bool SARA_R5::bufferedPoll(void)
219
219
}
220
220
memcpy (_saraRXBuffer + avail, _saraResponseBacklog, _saraResponseBacklogLength);
221
221
avail += _saraResponseBacklogLength;
222
- memset (_saraResponseBacklog, 0 , _RXBuffSize); // Clear the backlog making sure it is nullptr -terminated
222
+ memset (_saraResponseBacklog, 0 , _RXBuffSize); // Clear the backlog making sure it is NULL -terminated
223
223
_saraResponseBacklogLength = 0 ;
224
224
}
225
225
@@ -235,13 +235,13 @@ bool SARA_R5::bufferedPoll(void)
235
235
236
236
while (((millis () - timeIn) < _rxWindowMillis) && (avail < _RXBuffSize))
237
237
{
238
- if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is nullptr
238
+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
239
239
{
240
240
c = readChar ();
241
241
// bufferedPoll is only interested in the URCs.
242
242
// The URCs are all readable.
243
- // strtok does not like nullptr characters.
244
- // So we need to make sure no nullptr characters are added to _saraRXBuffer
243
+ // strtok does not like NULL characters.
244
+ // So we need to make sure no NULL characters are added to _saraRXBuffer
245
245
if (c == ' \0 ' )
246
246
c = ' 0' ; // Convert any NULLs to ASCII Zeros
247
247
_saraRXBuffer[avail++] = c;
@@ -254,9 +254,9 @@ bool SARA_R5::bufferedPoll(void)
254
254
// _saraRXBuffer now contains the backlog (if any) and the new serial data (if any)
255
255
256
256
// A health warning about strtok:
257
- // strtok will convert any delimiters it finds ("\r\n" in our case) into nullptr characters.
257
+ // strtok will convert any delimiters it finds ("\r\n" in our case) into NULL characters.
258
258
// Also, be very careful that you do not use strtok within an strtok while loop.
259
- // The next call of strtok(nullptr , ...) in the outer loop will use the pointer saved from the inner loop!
259
+ // The next call of strtok(NULL , ...) in the outer loop will use the pointer saved from the inner loop!
260
260
// In our case, strtok is also used in pruneBacklog, which is called by waitForRespone or sendCommandWithResponse,
261
261
// which is called by the parse functions called by processURCEvent...
262
262
// The solution is to use strtok_r - the reentrant version of strtok
@@ -678,7 +678,7 @@ bool SARA_R5::processURCEvent(const char *event)
678
678
}
679
679
}
680
680
}
681
- { // URC: +A
681
+ { // URC: +CREG
682
682
int status = 0 ;
683
683
unsigned int lac = 0 , ci = 0 , Act = 0 ;
684
684
char *searchPtr = strstr (event, " +CREG:" );
@@ -724,6 +724,7 @@ bool SARA_R5::processURCEvent(const char *event)
724
724
}
725
725
}
726
726
}
727
+ // NOTE: When adding new URC messages, remember to update pruneBacklog too!
727
728
728
729
return false ;
729
730
}
@@ -744,11 +745,11 @@ bool SARA_R5::poll(void)
744
745
745
746
memset (_saraRXBuffer, 0 , _RXBuffSize); // Clear _saraRXBuffer
746
747
747
- if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is nullptr
748
+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
748
749
{
749
750
while (c != ' \n ' ) // Copy characters into _saraRXBuffer. Stop at the first new line
750
751
{
751
- if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is nullptr
752
+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
752
753
{
753
754
c = readChar ();
754
755
_saraRXBuffer[avail++] = c;
@@ -1781,6 +1782,7 @@ SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip, SARA_R5_pdp
1781
1782
int ipOct[4 ];
1782
1783
1783
1784
searchPtr += strlen (" +CGDCONT:" ); // Point to the cid
1785
+ while (*searchPtr == ' ' ) searchPtr++; // skip spaces
1784
1786
scanned = sscanf (searchPtr, " %d,\" %[^\" ]\" ,\" %[^\" ]\" ,\" %d.%d.%d.%d" ,
1785
1787
&rcid, strPdpType, strApn,
1786
1788
&ipOct[0 ], &ipOct[1 ], &ipOct[2 ], &ipOct[3 ]);
@@ -5814,7 +5816,7 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
5814
5816
// that came in while waiting for response. To be processed later within bufferedPoll().
5815
5817
// Note: the expectedResponse or expectedError will also be added to the backlog
5816
5818
// The backlog is only used by bufferedPoll to process the URCs - which are all readable.
5817
- // bufferedPoll uses strtok - which does not like nullptr characters.
5819
+ // bufferedPoll uses strtok - which does not like NULL characters.
5818
5820
// So let's make sure no NULLs end up in the backlog!
5819
5821
if (_saraResponseBacklogLength < _RXBuffSize) // Don't overflow the buffer
5820
5822
{
@@ -5873,20 +5875,20 @@ void SARA_R5::sendCommand(const char *command, bool at)
5873
5875
// At 115200 baud, hwAvailable takes ~120 * 10 / 115200 = 10.4 millis before it indicates that data is being received.
5874
5876
5875
5877
unsigned long timeIn = millis ();
5876
- if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is nullptr
5878
+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
5877
5879
{
5878
5880
while (((millis () - timeIn) < _rxWindowMillis) && (_saraResponseBacklogLength < _RXBuffSize)) // May need to escape on newline?
5879
5881
{
5880
- if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is nullptr
5882
+ if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
5881
5883
{
5882
5884
// _saraResponseBacklog is a global array that holds the backlog of any events
5883
5885
// that came in while waiting for response. To be processed later within bufferedPoll().
5884
5886
// Note: the expectedResponse or expectedError will also be added to the backlog
5885
5887
// The backlog is only used by bufferedPoll to process the URCs - which are all readable.
5886
- // bufferedPoll uses strtok - which does not like nullptr characters.
5888
+ // bufferedPoll uses strtok - which does not like NULL characters.
5887
5889
// So let's make sure no NULLs end up in the backlog!
5888
5890
char c = readChar ();
5889
- if (c == ' \0 ' ) // Make sure no nullptr characters end up in the backlog! Change them to ASCII Zeros
5891
+ if (c == ' \0 ' ) // Make sure no NULL characters end up in the backlog! Change them to ASCII Zeros
5890
5892
c = ' 0' ;
5891
5893
_saraResponseBacklog[_saraResponseBacklogLength++] = c;
5892
5894
timeIn = millis ();
@@ -6281,11 +6283,11 @@ void SARA_R5::pruneBacklog()
6281
6283
|| (strstr (event, " +UULOC:" ) != nullptr )
6282
6284
|| (strstr (event, " +UUSIMSTAT:" ) != nullptr )
6283
6285
|| (strstr (event, " +UUPSDA:" ) != nullptr )
6284
- || (strstr (event, " +UUPING :" ) != nullptr )
6286
+ || (strstr (event, " +UUHTTPCR :" ) != nullptr )
6285
6287
|| (strstr (event, " +UUMQTTC:" ) != nullptr )
6286
- || (strstr (event, " +UUCREG :" ) != nullptr )
6287
- || (strstr (event, " +UUCEREG :" ) != nullptr )
6288
- || (strstr (event, " +UUHTTPCR :" ) != nullptr ))
6288
+ || (strstr (event, " +UUPING :" ) != nullptr )
6289
+ || (strstr (event, " +CREG :" ) != nullptr )
6290
+ || (strstr (event, " +CEREG :" ) != nullptr ))
6289
6291
{
6290
6292
strcat (_pruneBuffer, event); // The URCs are all readable text so using strcat is OK
6291
6293
strcat (_pruneBuffer, " \r\n " ); // strtok blows away delimiter, but we want that for later.
0 commit comments