~aleteoryx/muditaos

ref: 44d3306f280cc7d6daa718d2a9f6323e48f54616 muditaos/module-cellular/at/src/UrcCreg.cpp -rw-r--r-- 2.1 KiB
44d3306f — rrandomsky [CP-1059] Fix for erase only sensitive data from logs 2 years 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
82
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <UrcCreg.hpp>
#include <magic_enum.hpp>

using namespace at::urc;

auto Creg::isValid() const noexcept -> bool
{
    return isExtended() || isShort();
}

auto Creg::isExtended() const noexcept -> bool
{
    return tokens.size() == magic_enum::enum_count<Tokens>();
}

auto Creg::isShort() const noexcept -> bool
{
    return tokens.size() == NumOfShortTokens;
}

auto Creg::getStatus() const noexcept -> Store::Network::Status
{
    if (isValid()) {
        int statusInt;
        try {
            statusInt = std::stoi(tokens[Tokens::Stat]);
        }
        catch (const std::exception &e) {
            return Store::Network::Status::Unknown;
        }

        auto status = magic_enum::enum_cast<Store::Network::Status>(statusInt);
        if (status.has_value()) {
            return status.value();
        }
    }
    return Store::Network::Status::Unknown;
}

auto Creg::getLocation() const noexcept -> std::optional<std::string>
{
    if (isValid() && isExtended()) {
        auto location = tokens[Tokens::Lac];
        utils::findAndReplaceAll(location, "\"", "");
        return location;
    }

    return std::nullopt;
}

auto Creg::getCellId() const noexcept -> std::optional<std::string>
{
    if (isValid() && isExtended()) {
        auto cellId = tokens[Tokens::Ci];
        utils::findAndReplaceAll(cellId, "\"", "");
        return cellId;
    }

    return std::nullopt;
}

auto Creg::getAccessTechnology() const noexcept -> Store::Network::AccessTechnology
{
    if (isValid() && isExtended()) {
        int accessTechnologyInt;
        try {
            accessTechnologyInt = std::stoi(tokens[Tokens::Act]);
        }
        catch (const std::exception &e) {
            return Store::Network::AccessTechnology::Unknown;
        }

        auto accessTechnology = magic_enum::enum_cast<Store::Network::AccessTechnology>(accessTechnologyInt);
        if (accessTechnology.has_value()) {
            return accessTechnology.value();
        }
    }
    return Store::Network::AccessTechnology::Unknown;
}