From 83cb530a95735f80375c369f8c08841b6b2cb380 Mon Sep 17 00:00:00 2001 From: Technobly Date: Tue, 17 Jan 2017 23:27:32 -0600 Subject: [PATCH] preserve data instead of discarding and report UNK type --- hal/src/electron/modem/mdm_hal.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hal/src/electron/modem/mdm_hal.cpp b/hal/src/electron/modem/mdm_hal.cpp index 8a5ba1f87e..4783fce378 100644 --- a/hal/src/electron/modem/mdm_hal.cpp +++ b/hal/src/electron/modem/mdm_hal.cpp @@ -2253,36 +2253,40 @@ int MDMParser::_getLine(Pipe* pipe, char* buf, int len) { "\r\n>", NULL, TYPE_PROMPT }, // SMS { "\n>", NULL, TYPE_PROMPT }, // File { "\r\nABORTED\r\n", NULL, TYPE_ABORTED }, // Current command aborted - { "\r\n\r\n", "\r\n", TYPE_DBLNEWLINE }, // Double CRLF detected, discard one and reprocess line + { "\r\n\r\n", "\r\n", TYPE_DBLNEWLINE }, // Double CRLF detected { "\r\n", "\r\n", TYPE_UNKNOWN }, // If all else fails, break up generic strings }; for (int i = 0; i < (int)(sizeof(lutF)/sizeof(*lutF)); i ++) { pipe->set(unkn); int ln = _parseFormated(pipe, len, lutF[i].fmt); - if (ln == WAIT && fr) + if (ln == WAIT && fr) { return WAIT; - if ((ln != NOT_FOUND) && (unkn > 0)) + } + if ((ln != NOT_FOUND) && (unkn > 0)) { return TYPE_UNKNOWN | pipe->get(buf, unkn); - if (ln > 0) + } + if (ln > 0) { return lutF[i].type | pipe->get(buf, ln); + } } for (int i = 0; i < (int)(sizeof(lut)/sizeof(*lut)); i ++) { pipe->set(unkn); int ln = _parseMatch(pipe, len, lut[i].sta, lut[i].end); - if (ln == WAIT && fr) + if (ln == WAIT && fr) { return WAIT; - // Double CRLF detected, discard one and reprocess line. + } + // Double CRLF detected, discard it. // This resolves a case on G350 where "\r\n" is generated after +USORF response, but missing - // on U260/U270, which would otherwise generate "\r\n\r\nOK\r\n" which is not parsable. + // on U260/U270, which would otherwise generate "\r\n\r\nOK\r\n" which is not parseable. if ((ln > 0) && (lut[i].type == TYPE_DBLNEWLINE) && (unkn == 0)) { - char tmp[2]; - pipe->get(tmp, 2); - break; + return TYPE_UNKNOWN | pipe->get(buf, 2); } - if ((ln != NOT_FOUND) && (unkn > 0)) + if ((ln != NOT_FOUND) && (unkn > 0)) { return TYPE_UNKNOWN | pipe->get(buf, unkn); - if (ln > 0) + } + if (ln > 0) { return lut[i].type | pipe->get(buf, ln); + } } // UNKNOWN unkn ++;