~aleteoryx/muditaos

ref: 6e106deb29555ed8b69ff751e0da31280e06789d muditaos/module-services/service-cellular/requests/Request.cpp -rw-r--r-- 1.4 KiB
6e106deb — Alek Rudnik [EGD-6455] Disable service audio debug loggs 5 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <string>
#include <memory>

#include <at/Result.hpp>
#include <at/Commands.hpp>
#include <at/ATFactory.hpp>

#include "service-cellular/requests/Request.hpp"

namespace cellular
{
    void Request::setHandled(bool handled)
    {
        isRequestHandled = handled;
    }

    bool Request::isHandled() const noexcept
    {
        return isRequestHandled;
    }

    bool Request::checkModemResponse(const at::Result &result)
    {
        return result.code == at::Result::Code::OK;
    }

    bool Request::isValid() const noexcept
    {
        return true;
    }

    std::string Request::buildCommand(at::AT atCommand,
                                      const std::vector<commandBuilderFunc> &builderFunctions,
                                      bool trim) const
    {
        if (!isValid()) {
            return std::string();
        }

        std::string cmd(at::factory(atCommand));

        auto formatFirst = true;
        for (auto &cmdPart : builderFunctions) {
            auto partStr = cmdPart();
            if (partStr.empty() && trim) {
                break;
            }
            cmd.append(formatFirst ? partStr : "," + partStr);
            formatFirst = false;
        }

        return cmd;
    }
}; // namespace cellular