~aleteoryx/muditaos

ref: 6cc2bc9df4ed70d5548f7f4296be4062553b5c7a muditaos/module-services/service-cellular/src/CSQHandler.hpp -rw-r--r-- 1.6 KiB
6cc2bc9d — Dawid Wojtas [BH-1830] Fix eink crash while refreshing 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <at/cmd/CSQ.hpp>

#include <cstdint>
#include <chrono>
#include <functional>
#include <FreeRTOS.h>

namespace cellular::service
{
    enum class CSQMode
    {
        PermanentReporting,
        HybridReporting,
        HybridPolling
    };

    class CSQHandler
    {
      public:
        void handleTimerTick();
        void handleURCCounterMessage(std::uint32_t counter);

        std::function<bool()> onEnableCsqReporting;
        std::function<bool()> onDisableCsqReporting;
        std::function<std::optional<at::result::CSQ>()> onGetCsq;
        std::function<void(std::uint32_t)> onPropagateCSQ;
        std::function<void()> onInvalidCSQ;

        std::function<void(CSQMode)> onRetrySwitchMode;
        std::function<void()> onRetryGetCSQ;

        void handleLockPhone();
        void handleUnlockPhone();
        void handleBluetoothCarKitConnect();
        void handleBluetoothCarKitDisconnect();
        void checkConditionToChangeMode();
        bool switchToPermanentReportMode();
        bool switchToHybridReportMode();
        bool switchToHybridPollMode();
        bool getCSQ();

      private:
        std::uint32_t urcCounter = 0;
        CSQMode currentMode = CSQMode::HybridReporting;
        TickType_t switchToPollModeTimestamp{0};

        // parameters needed to switch poll/report mode
        bool isPhoneLocked{true};
        bool isBluetoothCarKitConnected{false};

        auto isPollModeTimeElapsed() -> bool;
        auto isTooManyURCs() -> bool;
    };
} // namespace cellular::service