Skip to content

Commit

Permalink
Merge pull request #2239 from particle-iot/fix/electron-cxreg-urc-par…
Browse files Browse the repository at this point in the history
…sing

[electron] modem: fix C*REG URC parsing
  • Loading branch information
avtolstoy authored Nov 27, 2020
2 parents db1f276 + f7766f6 commit b646b21
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hal/src/electron/modem/mdm_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,16 @@ int MDMParser::waitFinalResp(_CALLBACKPTR cb /* = NULL*/,
// +CREG|CGREG: <stat>[,<lac>,<ci>[,AcT[,<rac>]]] // URC (1,3,4,5 results)
b = (int)0xFFFF; c = (int)0xFFFFFFFF; d = -1; mode = -1; // default mode to -1 for safety
r = sscanf(cmd, "%31s %d,%d,\"%x\",\"%x\",%d",s,&mode,&a,&b,&c,&d);
if (r <= 1)
if (r <= 2) {
// Not a direct command response, re-parse as URC
r = sscanf(cmd, "%31s %d,\"%x\",\"%x\",%d",s,&a,&b,&c,&d);
// Fix mode that potentially has invalid value due to first parse attempt as a command response
mode = -1;
} else {
// The code below doesn't consider mode to be one of the parsed values
r--;
}
if (r >= 2) {
if (r == 2) mode = 2; // Single URC <stat>, so fix mode that got overwritten in the first sscanf
Reg *reg = !strcmp(s, "CREG:") ? &_net.csd :
!strcmp(s, "CGREG:") ? &_net.psd :
!strcmp(s, "CEREG:") ? &_net.eps : NULL;
Expand Down

0 comments on commit b646b21

Please sign in to comment.