~aleteoryx/muditaos

ref: 253ff8685c0102c7fc2ee1dc6e462cd16186dd19 muditaos/module-services/service-cellular/requests/SupplementaryServicesRequest.cpp -rw-r--r-- 3.2 KiB
253ff868 — Hubert Chrzaniuk [EGD-4403][EGD-4412] MMI support (#1021) 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <string>
#include <memory>

#include <at/Commands.hpp>

#include "service-cellular/requests/SupplementaryServicesRequest.hpp"
#include "service-cellular/requests/CallForwardingRequest.hpp"
#include "service-cellular/requests/PasswordRegistrationRequest.hpp"

namespace
{
    const std::map<std::string, cellular::SupplementaryServicesRequest::ProcedureType> procedureTypeMap = {
        {"*", cellular::SupplementaryServicesRequest::ProcedureType::Activation},
        {"#", cellular::SupplementaryServicesRequest::ProcedureType::Deactivation},
        {"*#", cellular::SupplementaryServicesRequest::ProcedureType::Interrogation},
        {"**", cellular::SupplementaryServicesRequest::ProcedureType::Registration},
        {"##", cellular::SupplementaryServicesRequest::ProcedureType::Erasure},
    };
}

namespace cellular
{
    SupplementaryServicesRequest::SupplementaryServicesRequest(const std::string &data, GroupMatch matchGroups)
        : Request(data),
          serviceCode(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::ServiceCode)]),
          supplementaryInfoA(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::SupInfoA)]),
          supplementaryInfoB(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::SupInfoB)]),
          supplementaryInfoC(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::SupInfoC)])
    {
        static_assert(magic_enum::enum_count<SupplementaryServicesRegexGroups>() <= maxGroupsInRequest);

        auto &procedureTypeString =
            matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::ProcedureType)];

        auto pType = procedureTypeMap.find(procedureTypeString);
        if (pType == procedureTypeMap.end()) {

            throw std::runtime_error(std::string(__FUNCTION__) + ": procedure type not covered by constructor.");
        }
        procedureType = pType->second;
    }

    auto SupplementaryServicesRequest::create(const std::string &data, GroupMatch matchGroups)
        -> std::unique_ptr<SupplementaryServicesRequest>
    {
        std::string serviceCode = matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::ServiceCode)];

        auto factoryList = {
            CallForwardingRequest::create,
        };

        for (auto &createCb : factoryList) {
            if (auto req = createCb(serviceCode, data, matchGroups)) {
                return req;
            }
        }

        return nullptr;
    }

    auto SupplementaryServicesRequest::getCommandInformationClass(const std::string &basicServiceGroup) const
        -> std::string
    {
        // according to EC25&EC21_AT_Commands_Manual_V1.3
        if (basicServiceGroup == basicServiceVoice) {
            return atInformationClassVoice;
        }
        else if (basicServiceGroup == basicServiceVoiceFax) {
            return atInformationClassFax;
        }
        else if (basicServiceGroup == basicServiceVoiceData) {
            return atInformationClassData;
        }
        return atInformationClassAllButSms;
    }

}; // namespace cellular