~aleteoryx/muditaos

ref: b4568c32eb2a4b37e9dfbbe08c446430eee2145c muditaos/module-services/service-cellular/src/NetworkTime.cpp -rw-r--r-- 1.7 KiB
b4568c32 — Kuba Kleczkowski [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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "NetworkTime.hpp"

#include <modem/BaseChannel.hpp>
#include <at/ATFactory.hpp>
#include <at/UrcFactory.hpp>

#include <service-time/service-time/TimeMessage.hpp>

namespace cellular::service
{

    void NetworkTime::setChannel(at::BaseChannel *channel)
    {
        this->channel = channel;
    }

    std::shared_ptr<sys::Message> NetworkTime::createSettingsRequest()
    {
        return std::make_shared<stm::message::GetAutomaticDateAndTimeRequest>();
    }

    void NetworkTime::processSettings(bool newValue, bool isOfflineModeOn)
    {
        if (isAutomaticDateAndTime == newValue) {
            return;
        }
        isAutomaticDateAndTime = newValue;

        if (isAutomaticDateAndTime) {
            enableTimeReporting(isOfflineModeOn);
        }
        else {
            disableTimeReporting();
        }
    }

    void NetworkTime::enableTimeReporting(bool isOfflineModeOn)
    {
        if (channel == nullptr) {
            LOG_ERROR("No channel provided. Request ignored");
            return;
        }
        channel->cmd(at::AT::ENABLE_TIME_ZONE_UPDATE);
        channel->cmd(at::AT::SET_TIME_ZONE_REPORTING);
        if (!isOfflineModeOn) {
            channel->cmd(at::AT::CFUN_DISABLE_TRANSMITTING);
            channel->cmd(at::AT::CFUN_FULL_FUNCTIONALITY);
        }
    }

    void NetworkTime::disableTimeReporting()
    {
        if (channel == nullptr) {
            LOG_ERROR("No channel provided. Request ignored");
            return;
        }
        channel->cmd(at::AT::DISABLE_TIME_ZONE_UPDATE);
        channel->cmd(at::AT::DISABLE_TIME_ZONE_REPORTING);
    }
}; // namespace cellular::service