~aleteoryx/muditaos

ref: master muditaos/module-cellular/at/UrcResponse.hpp -rw-r--r-- 1.7 KiB
2cd0e472 — Lefucjusz [BH-000] Update Harmony 2.10.0 changelog 2 months 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include "Urc.hpp"

namespace at::urc
{
    class UrcResponse : public Urc
    {
      public:
        // this table has to be aligned with responseBodies
        enum class URCResponseType
        {
            Ok,
            Connect,
            Ring,
            NoCarrier,
            Error,
            NoDialtone,
            Busy,
            NoAnswer
        };

        static auto isURC(const std::string &uHead) -> std::optional<URCResponseType>
        {
            for (auto &resp : urcResponses) {
                if (uHead.find(resp.second) != std::string::npos) {
                    return resp.first;
                }
            }
            return std::nullopt;
        }

        explicit UrcResponse(URCResponseType type) : Urc(std::string()), type(type){};

        auto getURCResponseType() const noexcept -> URCResponseType;

        void Handle(UrcHandler &h) final
        {
            h.Handle(*this);
        }

      private:
        URCResponseType type;

        static constexpr std::array<std::pair<URCResponseType, std::string_view>, 8> urcResponses = {{
            {URCResponseType::Ok, "OK"},
            {URCResponseType::Connect, "CONNECT"},
            {URCResponseType::Ring, "RING"},
            {URCResponseType::NoCarrier, "NO CARRIER"},
            {URCResponseType::Error, "ERROR"},
            {URCResponseType::NoDialtone, "NO DIALTONE"},
            {URCResponseType::Busy, "BUSY"},
            {URCResponseType::NoAnswer, "NO ANSWER"},
        }};
    };
} // namespace at::urc