Skip to content

Commit 9abc6c3

Browse files
committed
make parser more tolerant to missing spaces in URCs
- this is needed to support LENA commands
1 parent a56d051 commit 9abc6c3

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ SARA_R5_error_t SARA_R5::clock(uint8_t *y, uint8_t *mo, uint8_t *d,
11221122
// Response format (if TZ is negative): \r\n+CCLK: "YY/MM/DD,HH:MM:SS-TZ"\r\n\r\nOK\r\n
11231123
if (err == SARA_R5_ERROR_SUCCESS)
11241124
{
1125-
char *searchPtr = strstr(response, "+CCLK: ");
1125+
char *searchPtr = strstr(response, "+CCLK:");
11261126
if (searchPtr != NULL)
11271127
scanNum = sscanf(searchPtr, "+CCLK: \"%d/%d/%d,%d:%d:%d%c%d\"\r\n",
11281128
&iy, &imo, &id, &ih, &imin, &is, &tzPlusMinus, &itz);
@@ -1257,7 +1257,7 @@ SARA_R5_error_t SARA_R5::getUtimeMode(SARA_R5_utime_mode_t *mode, SARA_R5_utime_
12571257
if (err == SARA_R5_ERROR_SUCCESS)
12581258
{
12591259
int mStore, sStore, scanned = 0;
1260-
char *searchPtr = strstr(response, "+UTIME: ");
1260+
char *searchPtr = strstr(response, "+UTIME:");
12611261
if (searchPtr != NULL)
12621262
scanned = sscanf(searchPtr, "+UTIME: %d,%d\r\n", &mStore, &sStore);
12631263
m = (SARA_R5_utime_mode_t)mStore;
@@ -1324,7 +1324,7 @@ SARA_R5_error_t SARA_R5::getUtimeIndication(SARA_R5_utime_urc_configuration_t *c
13241324
if (err == SARA_R5_ERROR_SUCCESS)
13251325
{
13261326
int cStore, scanned = 0;
1327-
char *searchPtr = strstr(response, "+UTIMEIND: ");
1327+
char *searchPtr = strstr(response, "+UTIMEIND:");
13281328
if (searchPtr != NULL)
13291329
scanned = sscanf(searchPtr, "+UTIMEIND: %d\r\n", &cStore);
13301330
c = (SARA_R5_utime_urc_configuration_t)cStore;
@@ -1389,7 +1389,7 @@ SARA_R5_error_t SARA_R5::getUtimeConfiguration(int32_t *offsetNanoseconds, int32
13891389
if (err == SARA_R5_ERROR_SUCCESS)
13901390
{
13911391
int scanned = 0;
1392-
char *searchPtr = strstr(response, "+UTIMECFG: ");
1392+
char *searchPtr = strstr(response, "+UTIMECFG:");
13931393
if (searchPtr != NULL)
13941394
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
13951395
scanned = sscanf(searchPtr, "+UTIMECFG: %d,%d\r\n", &ons, &os);
@@ -1456,7 +1456,7 @@ int8_t SARA_R5::rssi(void)
14561456
}
14571457

14581458
int scanned = 0;
1459-
char *searchPtr = strstr(response, "+CSQ: ");
1459+
char *searchPtr = strstr(response, "+CSQ:");
14601460
if (searchPtr != NULL)
14611461
scanned = sscanf(searchPtr, "+CSQ: %d,%*d", &rssi);
14621462
if (scanned != 1)
@@ -1499,7 +1499,7 @@ SARA_R5_registration_status_t SARA_R5::registration(bool eps)
14991499
}
15001500

15011501
int scanned = 0;
1502-
const char *startTag = eps ? "+CEREG: " : "+CREG: ";
1502+
const char *startTag = eps ? "+CEREG:" : "+CREG:";
15031503
char *searchPtr = strstr(response, startTag);
15041504
if (searchPtr != NULL) {
15051505
const char *format = eps ? "+CEREG: %*d,%d" : "+CREG: %*d,%d";
@@ -1661,14 +1661,14 @@ SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip, SARA_R5_pdp
16611661
{
16621662
int scanned = 0;
16631663
// Find the first/next occurrence of +CGDCONT:
1664-
searchPtr = strstr(searchPtr, "+CGDCONT: ");
1664+
searchPtr = strstr(searchPtr, "+CGDCONT:");
16651665
if (searchPtr != NULL)
16661666
{
16671667
char strPdpType[10];
16681668
char strApn[128];
16691669
int ipOct[4];
16701670

1671-
searchPtr += strlen("+CGDCONT: "); // Point to the cid
1671+
searchPtr += strlen("+CGDCONT:"); // Point to the cid
16721672
scanned = sscanf(searchPtr, "%d,\"%[^\"]\",\"%[^\"]\",\"%d.%d.%d.%d",
16731673
&rcid, strPdpType, strApn,
16741674
&ipOct[0], &ipOct[1], &ipOct[2], &ipOct[3]);
@@ -1729,7 +1729,7 @@ SARA_R5_error_t SARA_R5::getSimStatus(String* code)
17291729
{
17301730
int scanned = 0;
17311731
char c[16];
1732-
char *searchPtr = strstr(response, "+CPIN: ");
1732+
char *searchPtr = strstr(response, "+CPIN:");
17331733
if (searchPtr != NULL)
17341734
scanned = sscanf(searchPtr, "+CPIN: %s\r\n", c);
17351735
if (scanned == 1)
@@ -1803,7 +1803,7 @@ SARA_R5_error_t SARA_R5::getSIMstateReportingMode(int *mode)
18031803
if (err == SARA_R5_ERROR_SUCCESS)
18041804
{
18051805
int scanned = 0;
1806-
char *searchPtr = strstr(response, "+USIMSTAT: ");
1806+
char *searchPtr = strstr(response, "+USIMSTAT:");
18071807
if (searchPtr != NULL)
18081808
scanned = sscanf(searchPtr, "+USIMSTAT: %d\r\n", &m);
18091809
if (scanned == 1)
@@ -2005,10 +2005,11 @@ SARA_R5_error_t SARA_R5::getOperator(String *oper)
20052005

20062006
if (err == SARA_R5_ERROR_SUCCESS)
20072007
{
2008-
searchPtr = strstr(response, "+COPS: ");
2008+
searchPtr = strstr(response, "+COPS:");
20092009
if (searchPtr != NULL)
20102010
{
2011-
searchPtr += strlen("+COPS: "); // Move searchPtr to first char
2011+
searchPtr += 6; // Move searchPtr to first char
2012+
while (*searchPtr == ' ') searchPtr++; // skip spaces
20122013
mode = *searchPtr; // Read first char -- should be mode
20132014
if (mode == '2') // Check for de-register
20142015
{
@@ -2157,7 +2158,7 @@ SARA_R5_error_t SARA_R5::getPreferredMessageStorage(int *used, int *total, Strin
21572158
}
21582159

21592160
int scanned = 0;
2160-
char *searchPtr = strstr(response, "+CPMS: ");
2161+
char *searchPtr = strstr(response, "+CPMS:");
21612162
if (searchPtr != NULL)
21622163
scanned = sscanf(searchPtr, "+CPMS: %d,%d", &u, &t);
21632164
if (scanned == 2)
@@ -2209,11 +2210,12 @@ SARA_R5_error_t SARA_R5::readSMSmessage(int location, String *unread, String *fr
22092210
{
22102211
char *searchPtr = response;
22112212

2212-
// Find the first occurrence of +CGDCONT:
2213-
searchPtr = strstr(searchPtr, "+CMGR: ");
2213+
// Find the first occurrence of +CMGR:
2214+
searchPtr = strstr(searchPtr, "+CMGR:");
22142215
if (searchPtr != NULL)
22152216
{
2216-
searchPtr += strlen("+CMGR: "); // Point to the originator address
2217+
searchPtr += 6; // Move searchPtr to first char
2218+
while (*searchPtr == ' ') searchPtr++; // skip spaces
22172219
int pointer = 0;
22182220
while ((*(++searchPtr) != '\"') && (*searchPtr != '\0') && (pointer < 12))
22192221
{
@@ -2759,7 +2761,7 @@ SARA_R5_error_t SARA_R5::socketRead(int socket, int length, char *readDest, int
27592761
}
27602762

27612763
// Extract the data
2762-
char *searchPtr = strstr(response, "+USORD: ");
2764+
char *searchPtr = strstr(response, "+USORD:");
27632765
if (searchPtr != NULL)
27642766
scanNum = sscanf(searchPtr, "+USORD: %d,%d",
27652767
&socketStore, &readLength);
@@ -2872,7 +2874,7 @@ SARA_R5_error_t SARA_R5::socketReadAvailable(int socket, int *length)
28722874

28732875
if (err == SARA_R5_ERROR_SUCCESS)
28742876
{
2875-
char *searchPtr = strstr(response, "+USORD: ");
2877+
char *searchPtr = strstr(response, "+USORD:");
28762878
if (searchPtr != NULL)
28772879
scanNum = sscanf(searchPtr, "+USORD: %d,%d",
28782880
&socketStore, &readLength);
@@ -2969,7 +2971,7 @@ SARA_R5_error_t SARA_R5::socketReadUDP(int socket, int length, char *readDest,
29692971
}
29702972

29712973
// Extract the data
2972-
char *searchPtr = strstr(response, "+USORF: ");
2974+
char *searchPtr = strstr(response, "+USORF:");
29732975
if (searchPtr != NULL)
29742976
scanNum = sscanf(searchPtr, "+USORF: %d,\"%d.%d.%d.%d\",%d,%d",
29752977
&socketStore, &remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3],
@@ -3102,7 +3104,7 @@ SARA_R5_error_t SARA_R5::socketReadAvailableUDP(int socket, int *length)
31023104

31033105
if (err == SARA_R5_ERROR_SUCCESS)
31043106
{
3105-
char *searchPtr = strstr(response, "+USORF: ");
3107+
char *searchPtr = strstr(response, "+USORF:");
31063108
if (searchPtr != NULL)
31073109
scanNum = sscanf(searchPtr, "+USORF: %d,%d",
31083110
&socketStore, &readLength);
@@ -3271,7 +3273,7 @@ SARA_R5_error_t SARA_R5::querySocketType(int socket, SARA_R5_socket_protocol_t *
32713273

32723274
if (err == SARA_R5_ERROR_SUCCESS)
32733275
{
3274-
char *searchPtr = strstr(response, "+USOCTL: ");
3276+
char *searchPtr = strstr(response, "+USOCTL:");
32753277
if (searchPtr != NULL)
32763278
scanNum = sscanf(searchPtr, "+USOCTL: %d,0,%d",
32773279
&socketStore, &paramVal);
@@ -3323,7 +3325,7 @@ SARA_R5_error_t SARA_R5::querySocketLastError(int socket, int *error)
33233325

33243326
if (err == SARA_R5_ERROR_SUCCESS)
33253327
{
3326-
char *searchPtr = strstr(response, "+USOCTL: ");
3328+
char *searchPtr = strstr(response, "+USOCTL:");
33273329
if (searchPtr != NULL)
33283330
scanNum = sscanf(searchPtr, "+USOCTL: %d,1,%d",
33293331
&socketStore, &paramVal);
@@ -3374,7 +3376,7 @@ SARA_R5_error_t SARA_R5::querySocketTotalBytesSent(int socket, uint32_t *total)
33743376

33753377
if (err == SARA_R5_ERROR_SUCCESS)
33763378
{
3377-
char *searchPtr = strstr(response, "+USOCTL: ");
3379+
char *searchPtr = strstr(response, "+USOCTL:");
33783380
if (searchPtr != NULL)
33793381
scanNum = sscanf(searchPtr, "+USOCTL: %d,2,%lu",
33803382
&socketStore, &paramVal);
@@ -3425,7 +3427,7 @@ SARA_R5_error_t SARA_R5::querySocketTotalBytesReceived(int socket, uint32_t *tot
34253427

34263428
if (err == SARA_R5_ERROR_SUCCESS)
34273429
{
3428-
char *searchPtr = strstr(response, "+USOCTL: ");
3430+
char *searchPtr = strstr(response, "+USOCTL:");
34293431
if (searchPtr != NULL)
34303432
scanNum = sscanf(searchPtr, "+USOCTL: %d,3,%lu",
34313433
&socketStore, &paramVal);
@@ -3476,7 +3478,7 @@ SARA_R5_error_t SARA_R5::querySocketRemoteIPAddress(int socket, IPAddress *addre
34763478

34773479
if (err == SARA_R5_ERROR_SUCCESS)
34783480
{
3479-
char *searchPtr = strstr(response, "+USOCTL: ");
3481+
char *searchPtr = strstr(response, "+USOCTL:");
34803482
if (searchPtr != NULL)
34813483
scanNum = sscanf(searchPtr, "+USOCTL: %d,4,\"%d.%d.%d.%d\",%d",
34823484
&socketStore,
@@ -3532,7 +3534,7 @@ SARA_R5_error_t SARA_R5::querySocketStatusTCP(int socket, SARA_R5_tcp_socket_sta
35323534

35333535
if (err == SARA_R5_ERROR_SUCCESS)
35343536
{
3535-
char *searchPtr = strstr(response, "+USOCTL: ");
3537+
char *searchPtr = strstr(response, "+USOCTL:");
35363538
if (searchPtr != NULL)
35373539
scanNum = sscanf(searchPtr, "+USOCTL: %d,10,%d",
35383540
&socketStore, &paramVal);
@@ -3583,7 +3585,7 @@ SARA_R5_error_t SARA_R5::querySocketOutUnackData(int socket, uint32_t *total)
35833585

35843586
if (err == SARA_R5_ERROR_SUCCESS)
35853587
{
3586-
char *searchPtr = strstr(response, "+USOCTL: ");
3588+
char *searchPtr = strstr(response, "+USOCTL:");
35873589
if (searchPtr != NULL)
35883590
scanNum = sscanf(searchPtr, "+USOCTL: %d,11,%lu",
35893591
&socketStore, &paramVal);
@@ -3634,7 +3636,7 @@ int SARA_R5::socketGetLastError()
36343636

36353637
if (err == SARA_R5_ERROR_SUCCESS)
36363638
{
3637-
char *searchPtr = strstr(response, "+USOER: ");
3639+
char *searchPtr = strstr(response, "+USOER:");
36383640
if (searchPtr != NULL)
36393641
sscanf(searchPtr, "+USOER: %d", &errorCode);
36403642
}
@@ -4450,7 +4452,7 @@ SARA_R5_error_t SARA_R5::getNetworkAssignedIPAddress(int profile, IPAddress *add
44504452

44514453
if (err == SARA_R5_ERROR_SUCCESS)
44524454
{
4453-
char *searchPtr = strstr(response, "+UPSND: ");
4455+
char *searchPtr = strstr(response, "+UPSND:");
44544456
if (searchPtr != NULL)
44554457
scanNum = sscanf(searchPtr, "+UPSND: %d,%d,\"%d.%d.%d.%d\"",
44564458
&profileStore, &paramTag,
@@ -4872,7 +4874,7 @@ SARA_R5_error_t SARA_R5::getFileContents(String filename, String *contents)
48724874
// Response format: \r\n+URDFILE: "filename",36,"these bytes are the data of the file"\r\n\r\nOK\r\n
48734875
int scanned = 0;
48744876
int readFileSize = 0;
4875-
char *searchPtr = strstr(response, "+URDFILE: ");
4877+
char *searchPtr = strstr(response, "+URDFILE:");
48764878
if (searchPtr != NULL)
48774879
{
48784880
searchPtr = strchr(searchPtr, '\"'); // Find the first quote
@@ -4994,7 +4996,7 @@ SARA_R5_error_t SARA_R5::getFileContents(String filename, char *contents)
49944996
// Response format: \r\n+URDFILE: "filename",36,"these bytes are the data of the file"\r\n\r\nOK\r\n
49954997
int scanned = 0;
49964998
int readFileSize = 0;
4997-
char *searchPtr = strstr(response, "+URDFILE: ");
4999+
char *searchPtr = strstr(response, "+URDFILE:");
49985000
if (searchPtr != NULL)
49995001
{
50005002
searchPtr = strchr(searchPtr, '\"'); // Find the first quote
@@ -5087,7 +5089,7 @@ SARA_R5_error_t SARA_R5::getFileSize(String filename, int *size)
50875089
return err;
50885090
}
50895091

5090-
char *responseStart = strstr(response, "+ULSTFILE: ");
5092+
char *responseStart = strstr(response, "+ULSTFILE:");
50915093
if (responseStart == NULL)
50925094
{
50935095
if (_printDebug == true)
@@ -5416,7 +5418,7 @@ SARA_R5_error_t SARA_R5::getMNOprofile(mobile_network_operator_t *mno)
54165418
}
54175419

54185420
int scanned = 0;
5419-
char *searchPtr = strstr(response, "+UMNOPROF: ");
5421+
char *searchPtr = strstr(response, "+UMNOPROF:");
54205422
if (searchPtr != NULL)
54215423
scanned = sscanf(searchPtr, "+UMNOPROF: %d,%d,%d,%d", &oStore, &d, &r, &u);
54225424
o = (mobile_network_operator_t)oStore;
@@ -5828,7 +5830,7 @@ SARA_R5_error_t SARA_R5::parseSocketCloseIndication(String *closeIndication)
58285830
int search;
58295831
int socket;
58305832

5831-
search = closeIndication->indexOf("UUSOCL: ") + strlen("UUSOCL: ");
5833+
search = closeIndication->indexOf("UUSOCL:") + strlen("UUSOCL:");
58325834

58335835
// Socket will be first integer, should be single-digit number between 0-6:
58345836
socket = closeIndication->substring(search, search + 1).toInt();

0 commit comments

Comments
 (0)