From ede3370b65fe0114d66e7dc31e41f1b96c776e04 Mon Sep 17 00:00:00 2001 From: Technobly Date: Tue, 17 Jan 2017 16:18:47 -0600 Subject: [PATCH] fixes double newline parser issue on G350 introduced in 428835a --- hal/src/electron/modem/enums_hal.h | 1 + hal/src/electron/modem/mdm_hal.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/hal/src/electron/modem/enums_hal.h b/hal/src/electron/modem/enums_hal.h index 2931fb5d63..8eebc11154 100644 --- a/hal/src/electron/modem/enums_hal.h +++ b/hal/src/electron/modem/enums_hal.h @@ -167,6 +167,7 @@ enum { TYPE_PLUS = 0x400000, TYPE_TEXT = 0x500000, TYPE_ABORTED = 0x600000, + TYPE_DBLNEWLINE = 0x700000, // special timout constant TIMEOUT_BLOCKING = 0xffffffff diff --git a/hal/src/electron/modem/mdm_hal.cpp b/hal/src/electron/modem/mdm_hal.cpp index fe26bd9103..8a5ba1f87e 100644 --- a/hal/src/electron/modem/mdm_hal.cpp +++ b/hal/src/electron/modem/mdm_hal.cpp @@ -2253,6 +2253,7 @@ 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", TYPE_UNKNOWN }, // If all else fails, break up generic strings }; for (int i = 0; i < (int)(sizeof(lutF)/sizeof(*lutF)); i ++) { @@ -2270,6 +2271,14 @@ int MDMParser::_getLine(Pipe* pipe, char* buf, int len) int ln = _parseMatch(pipe, len, lut[i].sta, lut[i].end); if (ln == WAIT && fr) return WAIT; + // Double CRLF detected, discard one and reprocess line. + // 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. + if ((ln > 0) && (lut[i].type == TYPE_DBLNEWLINE) && (unkn == 0)) { + char tmp[2]; + pipe->get(tmp, 2); + break; + } if ((ln != NOT_FOUND) && (unkn > 0)) return TYPE_UNKNOWN | pipe->get(buf, unkn); if (ln > 0)