Skip to content

Commit b646b21

Browse files
authored
Merge pull request #2239 from particle-iot/fix/electron-cxreg-urc-parsing
[electron] modem: fix C*REG URC parsing
2 parents db1f276 + f7766f6 commit b646b21

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

hal/src/electron/modem/mdm_hal.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,16 @@ int MDMParser::waitFinalResp(_CALLBACKPTR cb /* = NULL*/,
583583
// +CREG|CGREG: <stat>[,<lac>,<ci>[,AcT[,<rac>]]] // URC (1,3,4,5 results)
584584
b = (int)0xFFFF; c = (int)0xFFFFFFFF; d = -1; mode = -1; // default mode to -1 for safety
585585
r = sscanf(cmd, "%31s %d,%d,\"%x\",\"%x\",%d",s,&mode,&a,&b,&c,&d);
586-
if (r <= 1)
586+
if (r <= 2) {
587+
// Not a direct command response, re-parse as URC
587588
r = sscanf(cmd, "%31s %d,\"%x\",\"%x\",%d",s,&a,&b,&c,&d);
589+
// Fix mode that potentially has invalid value due to first parse attempt as a command response
590+
mode = -1;
591+
} else {
592+
// The code below doesn't consider mode to be one of the parsed values
593+
r--;
594+
}
588595
if (r >= 2) {
589-
if (r == 2) mode = 2; // Single URC <stat>, so fix mode that got overwritten in the first sscanf
590596
Reg *reg = !strcmp(s, "CREG:") ? &_net.csd :
591597
!strcmp(s, "CGREG:") ? &_net.psd :
592598
!strcmp(s, "CEREG:") ? &_net.eps : NULL;

0 commit comments

Comments
 (0)