Skip to content

Commit c8f2ed3

Browse files
author
Mirela Chirica
committed
Cellular: ATHandler to reset match URC generated errors and continue response handling
1 parent 4e6cbb8 commit c8f2ed3

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

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

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ TEST_F(TestATHandler, test_ATHandler_skip_param)
460460
fh1.short_value = POLLIN;
461461
at.resp_start();
462462
at.skip_param();
463-
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
463+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_OK);
464464

465465
char table1[] = "ss,sssssssssssss,sssssssssssOK\r\n\0";
466466
filehandle_stub_table = table1;
@@ -935,15 +935,88 @@ TEST_F(TestATHandler, test_ATHandler_resp_start)
935935
filehandle_stub_table_pos = 0;
936936
at.resp_start();
937937

938-
char table7[] = "ssssss\0";
938+
char table7[] = "urc: info\r\nresponseOK\r\n\0";
939+
at.flush();
940+
at.clear_error();
939941
filehandle_stub_table = table7;
940942
filehandle_stub_table_pos = 0;
941943

944+
at.set_urc_handler("urc: ", NULL);
945+
at.resp_start(); // recv_buff: "responseOK\r\n\0"
946+
at.resp_stop(); // consumes to OKCRLF -> OK
947+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_OK);
948+
949+
char table8[] = "urc: info\r\nresponse\0";
950+
at.flush();
951+
at.clear_error();
952+
filehandle_stub_table = table8;
953+
filehandle_stub_table_pos = 0;
954+
955+
at.set_urc_handler("urc: ", NULL);
956+
at.resp_start();
957+
at.resp_stop();
958+
// No stop tag(OKCRLF) found
959+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
960+
961+
char table9[] = "urc: prefix: infoOK\r\n\0";
942962
at.flush();
943963
at.clear_error();
944-
at.set_urc_handler("ss", NULL);
964+
filehandle_stub_table = table9;
945965
filehandle_stub_table_pos = 0;
966+
967+
at.set_urc_handler("urc: ", NULL);
946968
at.resp_start();
969+
// Match URC consumes to CRLF -> nothing to read after that -> ERROR
970+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
971+
972+
char table10[] = "urc: info\r\ngarbage\r\nprefix: info\r\nOK\r\n\0";
973+
at.flush();
974+
at.clear_error();
975+
filehandle_stub_table = table10;
976+
filehandle_stub_table_pos = 0;
977+
978+
at.set_urc_handler("urc: ", NULL);
979+
at.resp_start("prefix"); // match URC -> consumes to first CRLF -> consumes the garbage because there is expected prefix and no match found -> then prefix match
980+
at.resp_stop(); //ends the info scope -> consumes to CRLF -> ends the resp scope -> consumes to OKCRLF
981+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_OK);
982+
983+
// No stop tag(OKCRLF) will be found because, after match URC consumed everything to CRLF, rest of buffer
984+
// is consumed to next/last CRLF because there is expected prefix and no match found
985+
// -> nothing to read after that -> ERROR
986+
char table11[] = "urc: info\r\ngarbageprefix: infoOK\r\n\0";
987+
at.flush();
988+
at.clear_error();
989+
filehandle_stub_table = table11;
990+
filehandle_stub_table_pos = 0;
991+
992+
at.set_urc_handler("urc: ", NULL);
993+
at.resp_start("prefix");
994+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
995+
996+
// After URC match no prefix match -> try to read more -> no more to read
997+
char table12[] = "urc: infoprefix: info\0";
998+
at.flush();
999+
at.clear_error();
1000+
filehandle_stub_table = table12;
1001+
filehandle_stub_table_pos = 0;
1002+
1003+
at.set_urc_handler("urc: ", NULL);
1004+
at.resp_start("prefix");
1005+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
1006+
1007+
// Will run into mem_str check of identical strings
1008+
char table13[] = "\r\n\r\n\0";
1009+
at.flush();
1010+
at.clear_error();
1011+
filehandle_stub_table = table13;
1012+
filehandle_stub_table_pos = 0;
1013+
1014+
char buf[3];
1015+
at.resp_start();
1016+
EXPECT_TRUE(2 == at.read_string(buf, 3));
1017+
EXPECT_TRUE(!strncmp(buf, "\r\n", 2));
1018+
// Consume to delimiter or stop_tag OKCRLF fails -> ERROR
1019+
EXPECT_TRUE(at.get_last_error() == NSAPI_ERROR_DEVICE_ERROR);
9471020
}
9481021

9491022
TEST_F(TestATHandler, test_ATHandler_resp_stop)

UNITTESTS/stubs/FileHandle_stub.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class FileHandle_stub : public FileHandle {
4242
if (size < ret) {
4343
ret = size;
4444
}
45-
memcpy(buffer, filehandle_stub_table, ret);
45+
memcpy(buffer, filehandle_stub_table + filehandle_stub_table_pos, ret);
4646
filehandle_stub_table_pos += ret;
4747
return ret;
4848
}

features/cellular/framework/AT/ATHandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,8 @@ void ATHandler::resp(const char *prefix, bool check_urc)
820820

821821
if (check_urc && match_urc()) {
822822
_urc_matched = true;
823+
clear_error();
824+
continue;
823825
}
824826

825827
// If no match found, look for CRLF and consume everything up to and including CRLF

0 commit comments

Comments
 (0)