M enabled_unittests => enabled_unittests +4 -0
@@ 382,3 382,7 @@ TESTS_LIST["catch2-vfs-littlefs"]="
littlefs: Basic API test;
"
#---------
+TESTS_LIST["catch2-cellular-cmux"]="
+ TS0170 frame;
+"
+#---------
M module-cellular/Modem/TS0710/TS0710_DATA.cpp => module-cellular/Modem/TS0710/TS0710_DATA.cpp +0 -1
@@ 32,7 32,6 @@ TS0710_DATA::TS0710_DATA(DLCI_t DLCI,
request(DLCI, sysParams, User_data);
}
-
/**
* @param DLCI
* @param User_data
M module-cellular/Modem/TS0710/TS0710_DATA.h => module-cellular/Modem/TS0710/TS0710_DATA.h +0 -1
@@ 24,7 24,6 @@ class TS0710_DATA
bsp::Cellular *cellular);
~TS0710_DATA()
{}
-
private:
/**
* @param DLCI
M module-cellular/test/CMakeLists.txt => module-cellular/test/CMakeLists.txt +10 -0
@@ 36,3 36,13 @@ add_catch2_executable(
LIBS
module-cellular
)
+
+add_catch2_executable(
+ NAME
+ cellular-cmux
+ SRCS
+ unittest_cmux.cpp
+ LIBS
+ module-cellular
+)
+
M module-cellular/test/mock/AtCommon_channel.hpp => module-cellular/test/mock/AtCommon_channel.hpp +1 -0
@@ 8,6 8,7 @@
namespace at
{
+
class ChannelMock : public BaseChannel
{
public:
M module-cellular/test/unittest_ATStream.cpp => module-cellular/test/unittest_ATStream.cpp +30 -0
@@ 92,4 92,34 @@ TEST_CASE("Channel Test- AT return parser")
auto code = stream.parseState("+XME ERROR:", errcode);
REQUIRE(code == at::Result::Code::NONE);
}
+
+ SECTION("Parse AT, OK on begin, two tokens")
+ {
+ std::string rawResponse(
+ "\r\nOK\r\n\r\n+QPING: 0,\"172.217.20.206\",32,30,255\r\n\r\n+QPING: 0,\"172.217.20.206\",32,31,255\r\n");
+
+ at::ATStream stream(3);
+ stream.write(rawResponse);
+ auto result = stream.getResult();
+
+ REQUIRE(result.code == at::Result::Code::OK);
+ REQUIRE(result.response.size() == 3);
+ REQUIRE(result.response[0] == "OK");
+ REQUIRE(result.response[1] == "+QPING: 0,\"172.217.20.206\",32,30,255");
+ REQUIRE(result.response[2] == "+QPING: 0,\"172.217.20.206\",32,31,255");
+ }
+
+ SECTION("Parse AT, OK at end, two tokens")
+ {
+ std::string rawResponse("\r\n+QDAI: 1,0,0,3,0,1,1,1\r\n\r\nOK\r\n");
+
+ at::ATStream stream(3);
+ stream.write(rawResponse);
+ auto result = stream.getResult();
+
+ REQUIRE(result.code == at::Result::Code::OK);
+ REQUIRE(result.response.size() == 2);
+ REQUIRE(result.response[0] == "+QDAI: 1,0,0,3,0,1,1,1");
+ REQUIRE(result.response[1] == "OK");
+ }
}
A module-cellular/test/unittest_cmux.cpp => module-cellular/test/unittest_cmux.cpp +80 -0
@@ 0,0 1,80 @@
+#define CATCH_CONFIG_MAIN
+
+#include <catch2/catch.hpp>
+#include <Modem/TS0710/TS0710_Frame.h>
+#include <Modem/TS0710/TS0710_types.h>
+#include <bsp/cellular/bsp_cellular.hpp>
+
+TEST_CASE("TS0170 frame")
+{
+
+ SECTION("Create frame from command")
+ {
+ auto DLCI = 2;
+ auto cmuxMinimumFrameLength = 6;
+
+ std::string command("AT\r");
+ std::vector<uint8_t> commandData(command.begin(), command.end());
+
+ TS0710_Frame::frame_t tempFrame;
+ tempFrame.Address = static_cast<uint8_t>(DLCI << 2);
+ tempFrame.Control = static_cast<uint8_t>(TypeOfFrame_e::UIH);
+ tempFrame.data = commandData;
+
+ TS0710_Frame frame(tempFrame);
+
+ REQUIRE(frame.isComplete(frame.getSerData()) == true);
+ REQUIRE(frame.isMyChannel(frame.getSerData(), DLCI) == true);
+ REQUIRE(frame.getFrameDLCI(frame.getSerData()) == DLCI);
+ REQUIRE(frame.getSerData().size() == cmuxMinimumFrameLength + command.length());
+ }
+
+ SECTION("Deserialise frame")
+ {
+ std::vector<uint8_t> tempFrame{0xf9, 0x09, 0xef, 0x07, 0x41, 0x54, 0x0d, 0x35, 0xf9};
+ auto DLCI = 2;
+
+ TS0710_Frame frame(tempFrame);
+ auto deserialisedFrame = frame.getFrame();
+
+ REQUIRE(frame.getFrameDLCI(frame.getSerData()) == DLCI);
+
+ REQUIRE(deserialisedFrame.data.size() == 3);
+ REQUIRE(deserialisedFrame.data[0] == 'A');
+ REQUIRE(deserialisedFrame.data[1] == 'T');
+ REQUIRE(deserialisedFrame.data[2] == '\r');
+ }
+
+ SECTION("Incomplete frame")
+ {
+ std::vector<uint8_t> tempFrame{0xf9, 0x09, 0xef, 0x07, 0x41, 0x54, 0x0d, 0x35};
+ auto DLCI = 2;
+
+ TS0710_Frame frame(tempFrame);
+
+ REQUIRE(frame.getFrameDLCI(frame.getSerData()) == DLCI);
+ REQUIRE(frame.isComplete(frame.getSerData()) == false);
+ }
+
+ SECTION("Incomplete data")
+ {
+ std::vector<uint8_t> tempFrame{0xf9, 0x09, 0xef, 0x07, 0x54, 0x0d, 0x35, 0xf9};
+ auto DLCI = 2;
+
+ TS0710_Frame frame(tempFrame);
+
+ REQUIRE(frame.getFrameDLCI(frame.getSerData()) == DLCI);
+ REQUIRE(frame.isComplete(frame.getSerData()) == false);
+ }
+
+ SECTION("Invalid length")
+ {
+ std::vector<uint8_t> tempFrame{0xf9, 0x09, 0xef, 0x09, 0x41, 0x54, 0x0d, 0x35, 0xf9};
+ auto DLCI = 2;
+
+ TS0710_Frame frame(tempFrame);
+
+ REQUIRE(frame.getFrameDLCI(frame.getSerData()) == DLCI);
+ REQUIRE(frame.isComplete(frame.getSerData()) == false);
+ }
+}