~aleteoryx/muditaos

muditaos/module-cellular/test/unittest_cmux.cpp -rw-r--r-- 2.6 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include <catch2/catch.hpp>
#include <modem/mux/CellularMuxFrame.h>
#include <modem/mux/CellularMuxTypes.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());

        CellularMuxFrame::frame_t tempFrame;
        tempFrame.Address = static_cast<uint8_t>(DLCI << 2);
        tempFrame.Control = static_cast<uint8_t>(TypeOfFrame_e::UIH);
        tempFrame.data    = commandData;

        CellularMuxFrame frame(tempFrame);

        REQUIRE(frame.isComplete(frame.getSerData()) == true);
        REQUIRE(frame.isMyChannel(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;

        CellularMuxFrame 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;

        CellularMuxFrame 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;

        CellularMuxFrame 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;

        CellularMuxFrame frame(tempFrame);

        REQUIRE(frame.getFrameDLCI(frame.getSerData()) == DLCI);
        REQUIRE(frame.isComplete(frame.getSerData()) == false);
    }
}