~aleteoryx/muditaos

ref: 69cf2575cc10f8a090d687ea8da0a9c19ac4899b muditaos/module-services/service-cellular/connection-manager/ConnectionManagerCellularCommands.cpp -rw-r--r-- 3.5 KiB
69cf2575 — Kuba [EGD-7909] Fixed phone mode switching 4 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <service-cellular/service-cellular/connection-manager/ConnectionManagerCellularCommands.hpp>

#include <module-cellular/at/cmd/CFUN.hpp>
#include <module-cellular/at/Cmd.hpp>
#include <module-cellular/at/ATFactory.hpp>

auto ConnectionManagerCellularCommands::disconnectFromNetwork() -> bool
{
    using at::cfun::Functionality;
    auto channel = cellular.cmux->get(CellularMux::Channel::Commands);
    if (channel) {
        auto cmd = at::cmd::CFUN(at::cmd::Modifier::Set);
        cmd.set(Functionality::DisableRF);
        auto resp = channel->cmd(cmd);
        return resp.code == at::Result::Code::OK;
    }
    return false;
}

auto ConnectionManagerCellularCommands::connectToNetwork() -> bool
{
    using at::cfun::Functionality;
    auto channel = cellular.cmux->get(CellularMux::Channel::Commands);
    if (channel) {
        auto cmd = at::cmd::CFUN(at::cmd::Modifier::Set);
        cmd.set(Functionality::Full);
        auto resp = channel->cmd(cmd);
        return resp.code == at::Result::Code::OK;
    }
    return false;
}

auto ConnectionManagerCellularCommands::isConnectedToNetwork() -> bool
{

    using at::cfun::Functionality;
    auto channel = cellular.cmux->get(CellularMux::Channel::Commands);
    if (channel) {
        auto cmd      = at::cmd::CFUN(at::cmd::Modifier::Get);
        auto response = channel->cmd(cmd);
        if (response.code == at::Result::Code::OK) {
            auto result = cmd.parseCFUN(response);
            if (result.code == at::Result::Code::OK) {
                return result.functionality == Functionality::Full;
            }
        }
    }
    return false;
}

auto ConnectionManagerCellularCommands::clearNetworkIndicator() -> bool
{

    // force clear signal indicator
    constexpr auto rssi = 0;
    SignalStrength signalStrength(rssi);
    Store::GSM::get()->setSignalStrength(signalStrength.data);
    auto msg = std::make_shared<CellularSignalStrengthUpdateNotification>();
    cellular.bus.sendMulticast(msg, sys::BusChannel::ServiceCellularNotifications);

    return true;
}

auto ConnectionManagerCellularCommands::hangUpOngoingCall() -> bool
{
    if (cellular.ongoingCall.isActive()) {
        auto channel = cellular.cmux->get(CellularMux::Channel::Commands);
        if (channel) {
            if (channel->cmd(at::factory(at::AT::ATH))) {
                cellular.callStateTimer.stop();
                if (!cellular.ongoingCall.endCall(CellularCall::Forced::True)) {
                    LOG_ERROR("Failed to end ongoing call");
                    return false;
                }
                auto msg = std::make_shared<CellularCallAbortedNotification>();
                cellular.bus.sendMulticast(msg, sys::BusChannel::ServiceCellularNotifications);
            }
        }
    }
    return true;
}

auto ConnectionManagerCellularCommands::isConnectionTimerActive() -> bool
{
    return cellular.connectionTimer.isActive();
}

void ConnectionManagerCellularCommands::startConnectionTimer()
{
    cellular.connectionTimer.start();
}

void ConnectionManagerCellularCommands::stopConnectionTimer()
{
    cellular.connectionTimer.stop();
}

void ConnectionManagerCellularCommands::holdMinimumCpuFrequency()
{
    auto handle = cellular.getTaskHandle();
    if (cellular.cpuSentinel) {
        cellular.cpuSentinel->HoldMinimumFrequencyAndWait(bsp::CpuFrequencyHz::Level_4, handle, 2000);
    }
    return;
}