Skip to content

Commit 31f153a

Browse files
author
Mirela Chirica
committed
Cellular: Fix for 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 fd4f47d commit 31f153a

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
@@ -1052,6 +1052,27 @@ TEST_F(TestATHandler, test_ATHandler_consume_to_stop_tag)
10521052

10531053
ATHandler at(&fh1, que, 0, ",");
10541054
EXPECT_TRUE(at.consume_to_stop_tag());
1055+
1056+
at.clear_error();
1057+
char table1[] = "\r\n\r\r\r\nOOK\r\n";
1058+
at.flush();
1059+
filehandle_stub_table = table1;
1060+
filehandle_stub_table_pos = 0;
1061+
mbed_poll_stub::revents_value = POLLIN;
1062+
mbed_poll_stub::int_value = 1;
1063+
char buf1[6];
1064+
at.resp_start();
1065+
EXPECT_TRUE(at.consume_to_stop_tag());
1066+
1067+
at.clear_error();
1068+
char table2[] = "OKOK\r\n";
1069+
at.flush();
1070+
filehandle_stub_table = table2;
1071+
filehandle_stub_table_pos = 0;
1072+
mbed_poll_stub::revents_value = POLLIN;
1073+
mbed_poll_stub::int_value = 1;
1074+
char buf2[6];
1075+
EXPECT_TRUE(at.consume_to_stop_tag());
10551076
}
10561077

10571078
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
@@ -926,16 +926,16 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
926926
int c = get_char();
927927
if (c == -1) {
928928
break;
929-
} else if (c == tag[match_pos]) {
929+
// compares c against tag at current position and if this match fails
930+
// compares c against tag[0] and also resets match_pos to 0
931+
} else if (c == tag[match_pos] || ((match_pos = 1) && (c == tag[--match_pos]))) {
930932
match_pos++;
931933
if (match_pos == strlen(tag)) {
932934
if (!consume_tag) {
933935
_recv_pos -= strlen(tag);
934936
}
935937
return true;
936938
}
937-
} else if (match_pos) {
938-
match_pos = 0;
939939
}
940940
}
941941
tr_debug("consume_to_tag not found");

0 commit comments

Comments
 (0)