Skip to content

Commit 806e95c

Browse files
author
Mirela Chirica
committed
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.
1 parent c180676 commit 806e95c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -952,25 +952,31 @@ bool ATHandler::consume_char(char ch)
952952
bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
953953
{
954954
size_t match_pos = 0;
955+
size_t tag_length = strlen(tag);
955956

956957
while (true) {
957958
int c = get_char();
958959
if (c == -1) {
959-
break;
960-
// compares c against tag at current position and if this match fails
961-
// compares c against tag[0] and also resets match_pos to 0
962-
} else if (c == tag[match_pos] || ((match_pos = 1) && (c == tag[--match_pos]))) {
960+
tr_debug("consume_to_tag not found");
961+
return false;
962+
}
963+
if (c == tag[match_pos]) {
963964
match_pos++;
964-
if (match_pos == strlen(tag)) {
965-
if (!consume_tag) {
966-
_recv_pos -= strlen(tag);
967-
}
968-
return true;
965+
} else if (match_pos != 0) {
966+
match_pos = 0;
967+
if (c == tag[match_pos]) {
968+
match_pos++;
969969
}
970970
}
971+
if (match_pos == tag_length) {
972+
break;
973+
}
971974
}
972-
tr_debug("consume_to_tag not found");
973-
return false;
975+
976+
if (!consume_tag) {
977+
_recv_pos -= tag_length;
978+
}
979+
return true;
974980
}
975981

976982
bool ATHandler::consume_to_stop_tag()

0 commit comments

Comments
 (0)