~aleteoryx/muditaos

ref: 54128e656c947dd843dc08daddeb2e460693353f muditaos/module-cellular/at/cmd/src/QNWINFO.cpp -rw-r--r-- 2.4 KiB
54128e65 — Lefucjusz [MOS-1048] Fix not fitting VoLTE button label 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <log/log.hpp>
#include <at/cmd/QNWINFO.hpp>
#include <Utils.hpp>

#include <memory>
#include <string>
#include <type_traits>

namespace at
{
    namespace cmd
    {
        QNWINFO::QNWINFO(at::cmd::Modifier mod) noexcept : Cmd("AT+QNWINFO", mod)
        {}

        QNWINFO::QNWINFO() noexcept : QNWINFO(at::cmd::Modifier::None)
        {}

        result::QNWINFO QNWINFO::parseQNWINFO(const Result &base_result)
        {
            auto baseResult = Cmd::parseBase(base_result);
            result::QNWINFO p{baseResult};
            // use parent operator bool
            if (baseResult && p.tokens.size() == 1) {
                auto tokens         = p.tokens[0];
                auto numberOfTokens = tokens.size();
                if (numberOfTokens != magic_enum::enum_count<at::result::QNWINFOTokens>()) {
                    LOG_ERROR("Can't parse - number of tokens %u is not valid",
                              static_cast<unsigned int>(p.tokens.size()));
                    p.code = result::QNWINFO::Code::PARSING_ERROR;
                    return p;
                }
                p.act = tokens[at::result::QNWINFOTokens::act];
                if (!utils::toNumeric(tokens[at::result::QNWINFOTokens::op], p.op)) {
                    p.op = 0;
                }
                p.band = tokens[at::result::QNWINFOTokens::band];
                if (!utils::toNumeric(tokens[at::result::QNWINFOTokens::channel], p.channel)) {
                    p.channel = 0;
                }
            }

            if (!p.operator bool()) {
                p.code = result::QNWINFO::Code::PARSING_ERROR;
            }

            return p;
        }
    } // namespace cmd

    namespace result
    {
        bool isStringValid(const std::string &str)
        {
            return !str.empty() && str != "\"\"";
        }

        QNWINFO::QNWINFO(const Result &that) : Result(that)
        {}

        QNWINFO::operator bool() const
        {
            if (!Result::operator bool()) {
                return false;
            }
            if (!isStringValid(act)) {
                return false;
            }
            if (!isStringValid(band)) {
                return false;
            }
            return true;
        }
    } // namespace result
} // namespace at