Merge pull request #8350 from mirelachirica/at_consume_to_tag_fix

Cellular: Fix for AT handler consume to tag
pull/8503/head
Cruz Monrreal 2018-10-22 19:45:24 -05:00 committed by GitHub
commit ba23fef90b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -1063,6 +1063,27 @@ TEST_F(TestATHandler, test_ATHandler_consume_to_stop_tag)
ATHandler at(&fh1, que, 0, ",");
EXPECT_TRUE(at.consume_to_stop_tag());
at.clear_error();
char table1[] = "\r\n\r\r\r\nOOK\r\n";
at.flush();
filehandle_stub_table = table1;
filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = 1;
char buf1[6];
at.resp_start();
EXPECT_TRUE(at.consume_to_stop_tag());
at.clear_error();
char table2[] = "OKOK\r\n";
at.flush();
filehandle_stub_table = table2;
filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = 1;
char buf2[6];
EXPECT_TRUE(at.consume_to_stop_tag());
}
TEST_F(TestATHandler, test_ATHandler_set_debug)

View File

@ -943,7 +943,9 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
int c = get_char();
if (c == -1) {
break;
} else if (c == tag[match_pos]) {
// 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]))) {
match_pos++;
if (match_pos == strlen(tag)) {
if (!consume_tag) {
@ -951,8 +953,6 @@ bool ATHandler::consume_to_tag(const char *tag, bool consume_tag)
}
return true;
}
} else if (match_pos) {
match_pos = 0;
}
}
tr_debug("consume_to_tag not found");