From 806e95cf67a968126e3e443aed78ed09a97f2cb3 Mon Sep 17 00:00:00 2001 From: Mirela Chirica Date: Tue, 11 Dec 2018 13:52:24 +0200 Subject: [PATCH] Cellular: Rewrite AT handler consume to tag If sequence from buffer contains tag but symbol before tag is same as first symbol of the tag, then the tag wasn't detected. For example, "\r\n" tag was not found from "\r\r\nOK" sequence. --- features/cellular/framework/AT/ATHandler.cpp | 28 ++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/features/cellular/framework/AT/ATHandler.cpp b/features/cellular/framework/AT/ATHandler.cpp index bbb278be810..26129793f41 100644 --- a/features/cellular/framework/AT/ATHandler.cpp +++ b/features/cellular/framework/AT/ATHandler.cpp @@ -952,25 +952,31 @@ bool ATHandler::consume_char(char ch) bool ATHandler::consume_to_tag(const char *tag, bool consume_tag) { size_t match_pos = 0; + size_t tag_length = strlen(tag); while (true) { int c = get_char(); if (c == -1) { - break; - // compares c against tag at current position and if this match fails - // compares c against tag[0] and also resets match_pos to 0 - } else if (c == tag[match_pos] || ((match_pos = 1) && (c == tag[--match_pos]))) { + tr_debug("consume_to_tag not found"); + return false; + } + if (c == tag[match_pos]) { match_pos++; - if (match_pos == strlen(tag)) { - if (!consume_tag) { - _recv_pos -= strlen(tag); - } - return true; + } else if (match_pos != 0) { + match_pos = 0; + if (c == tag[match_pos]) { + match_pos++; } } + if (match_pos == tag_length) { + break; + } } - tr_debug("consume_to_tag not found"); - return false; + + if (!consume_tag) { + _recv_pos -= tag_length; + } + return true; } bool ATHandler::consume_to_stop_tag()