~aleteoryx/muditaos

ref: 20e0437d15787fc7b635490d2c73bf3082feea38 muditaos/module-services/service-cellular/src/ModemResetHandler.hpp -rw-r--r-- 2.2 KiB
20e0437d — Lefucjusz [MOS-000] Update Pure 1.8.0 changelog 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
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <service-cellular/State.hpp>

#include <functional>

namespace cellular::service
{

    class ModemResetHandler
    {

      public:
        /**
         * It performs modem reset via AT command
         * @return true on success, false on fail
         */
        auto performSoftReset() -> bool;
        /**
         * It performs modem reset via modem's Reset pin
         * @return
         */
        auto performHardReset() -> bool;
        /**
         * It performs power cycle modem's via PWR_KEY pin
         * @return
         */
        auto performReboot() -> bool;
        /**
         * It performs functionality reset via AT command. It does not require cellular reinitialisation.
         * @return true on success
         */
        auto performFunctionalityReset() -> bool;
        /**
         * It handles STATUS pin changed event when any reset procedure is in progress, other case it's doing nothing.
         * @param isActive STATUS pin value. True when STATUS is active, false when it's inactive
         * @return true when event is handled, false when not
         */
        auto handleStatusPinEvent(bool isActive) -> bool;
        /**
         * It checks if any reset procedure is in progress.
         * @return true when any reset procedure is in progress, false when not
         */
        auto isResetInProgress() -> bool;
        /**
         * User defined callbacks
         */
        std::function<void(cellular::service::State::ST)> onCellularStateSet;
        std::function<void()> onTurnModemOn;
        std::function<void()> onTurnModemOff;
        std::function<bool()> onSoftReset;
        std::function<void()> onHardReset;
        std::function<bool()> onFunctionalityReset;
        std::function<void()> onAnyReset;

      private:
        enum class ProcedureInProgress
        {
            None,
            SoftReset,
            HardReset,
            Reboot
        };

        ProcedureInProgress procedureInProgress = ProcedureInProgress::None;

        auto handleSwitchToInactive() -> bool;
        auto handleSwitchToActive() -> bool;
    };
} // namespace cellular::service