Skip to content

Commit ba23fef

Browse files
author
Cruz Monrreal
authored
Merge pull request #8350 from mirelachirica/at_consume_to_tag_fix
Cellular: Fix for AT handler consume to tag
2 parents ecb6e6e + 31f153a commit ba23fef

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,27 @@ TEST_F(TestATHandler, test_ATHandler_consume_to_stop_tag)
10631063

10641064
ATHandler at(&fh1, que, 0, ",");
10651065
EXPECT_TRUE(at.consume_to_stop_tag());
1066+
1067+
at.clear_error();
1068+
char table1[] = "\r\n\r\r\r\nOOK\r\n";
1069+
at.flush();
1070+
filehandle_stub_table = table1;
1071+
filehandle_stub_table_pos = 0;
1072+
mbed_poll_stub::revents_value = POLLIN;
1073+
mbed_poll_stub::int_value = 1;
1074+
char buf1[6];
1075+
at.resp_start();
1076+
EXPECT_TRUE(at.consume_to_stop_tag());
1077+
1078+
at.clear_error();
1079+
char table2[] = "OKOK\r\n";
1080+
at.flush();
1081+
filehandle_stub_table = table2;
1082+
filehandle_stub_table_pos = 0;
1083+
mbed_poll_stub::revents_value = POLLIN;
1084+
mbed_poll_stub::int_value = 1;
1085+
char buf2[6];
1086+
EXPECT_TRUE(at.consume_to_stop_tag());
10661087
}
10671088

10681089
TEST_F(TestATHandler, test_ATHandler_set_debug)

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -943,16 +943,16 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
943943
int c = get_char();
944944
if (c == -1) {
945945
break;
946-
} else if (c == tag[match_pos]) {
946+
// compares c against tag at current position and if this match fails
947+
// compares c against tag[0] and also resets match_pos to 0
948+
} else if (c == tag[match_pos] || ((match_pos = 1) && (c == tag[--match_pos]))) {
947949
match_pos++;
948950
if (match_pos == strlen(tag)) {
949951
if (!consume_tag) {
950952
_recv_pos -= strlen(tag);
951953
}
952954
return true;
953955
}
954-
} else if (match_pos) {
955-
match_pos = 0;
956956
}
957957
}
958958
tr_debug("consume_to_tag not found");

0 commit comments

Comments
 (0)