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.
pull/9052/head
Mirela Chirica 2018-12-11 13:52:24 +02:00
parent c1806765dd
commit 806e95cf67
1 changed files with 17 additions and 11 deletions

View File

@ -952,25 +952,31 @@ bool ATHandler::consume_char(char ch)
bool ATHandler::consume_to_tag(const char *tag, bool consume_tag) bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
{ {
size_t match_pos = 0; size_t match_pos = 0;
size_t tag_length = strlen(tag);
while (true) { while (true) {
int c = get_char(); int c = get_char();
if (c == -1) { if (c == -1) {
break; tr_debug("consume_to_tag not found");
// compares c against tag at current position and if this match fails return false;
// 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]))) { if (c == tag[match_pos]) {
match_pos++; match_pos++;
if (match_pos == strlen(tag)) { } else if (match_pos != 0) {
if (!consume_tag) { match_pos = 0;
_recv_pos -= strlen(tag); if (c == tag[match_pos]) {
} match_pos++;
return true;
} }
} }
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() bool ATHandler::consume_to_stop_tag()