~aleteoryx/muditaos

ref: 4df235d1ffd9ec18cc33cf89730f3eccc1f30ac3 muditaos/module-services/service-cellular/src/SimContacts.cpp -rw-r--r-- 1.2 KiB
4df235d1 — Lefucjusz Revert "[MOS-977] Added VoLTE support in additional countries" 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimContacts.hpp"

#include <modem/BaseChannel.hpp>
#include <at/cmd/CPBR.hpp>

namespace cellular::service
{
    void SimContacts::setChannel(at::BaseChannel *channel)
    {
        this->channel = channel;
    }

    auto SimContacts::getContacts(std::vector<cellular::SimContact> &destination) -> bool
    {
        if (!channel) {
            LOG_ERROR("No channel provided. Request ignored");
            return false;
        }

        auto command = at::cmd::CPBR(at::cmd::Modifier::Set);
        constexpr int firstIndex = 1, maxIndex = 250;
        command.setSimContactsReadRange(firstIndex, maxIndex);
        auto response = channel->cmd(command);
        auto result   = command.parseCPBR(response);

        if (result.code != at::Result::Code::OK) {
            LOG_ERROR("Failed to get contacts list");
            return false;
        }

        for (auto el : result.contacts) {
            destination.push_back(SimContact(el.name, el.number));
        }

        return true;
    }
} // namespace cellular::service