~aleteoryx/muditaos

ref: de5b923e81ed56bc845b75b2833cb040fafc3409 muditaos/module-bsp/bsp/cellular/bsp_cellular.hpp -rw-r--r-- 3.9 KiB
de5b923e — DariuszSabala [BH-369] Turned UTF8 into separate library 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef PUREPHONE_BSP_CELLULAR_HPP
#define PUREPHONE_BSP_CELLULAR_HPP

#include <optional>
#include <stdint.h>
#include <stddef.h>
#include <memory>
#include <chrono>
#include <FreeRTOS.h>
#include <FreeRTOS/include/queue.h>
#include "drivers/lpuart/DriverLPUART.hpp"
#include <common_data/EventStore.hpp>

namespace bsp
{
    namespace cellular
    {
        enum class antenna
        {
            lowBand,
            highBand
        };
    }
    class Cellular
    {
      public:
        static std::optional<std::unique_ptr<Cellular>> create(const char *term   = "/dev/ttyUSB0",
                                                               uint32_t portSpeed = 115200);

        Cellular()          = default;
        virtual ~Cellular() = default;

        virtual void powerUp() = 0;

        virtual void powerDown() = 0;

        virtual void restart() = 0;

        virtual uint32_t wait(std::chrono::milliseconds timeoutMs) = 0;

        virtual ssize_t read(void *buf, size_t nbytes, std::chrono::milliseconds timeoutMs) = 0;

        virtual ssize_t write(void *buf, size_t nbytes) = 0;

        virtual void informModemHostAsleep() = 0;

        virtual void informModemHostWakeup() = 0;

        virtual void enterSleep() = 0;

        virtual void exitSleep() = 0;

        virtual void setSpeed(uint32_t portSpeed) = 0;

        virtual void setSendingAllowed(bool state) = 0;

        virtual bool getSendingAllowed() const noexcept = 0;

        virtual void selectAntenna(bsp::cellular::antenna antenna) = 0;
        virtual bsp::cellular::antenna getAntenna()                = 0;

        [[nodiscard]] auto getCellularDevice() const noexcept -> std::shared_ptr<devices::Device>;
        [[nodiscard]] auto getLastCommunicationTimestamp() const noexcept -> TickType_t;
        [[nodiscard]] auto isCellularInSleepMode() const noexcept -> bool;

      protected:
        bool isInitialized = false;
        bool isInSleepMode{false};
        TickType_t lastCommunicationTimestamp;

        std::shared_ptr<drivers::DriverLPUART> driverLPUART;
    };
    namespace cellular
    {
        enum IRQsource
        {
            statusPin,
            trayPin,
            ringIndicatorPin,
        };

        /// initialize SIM queue directed to EventWorker
        int init(xQueueHandle qHandle);

        namespace USB
        {
            enum class PassthroughState
            {
                ENABLED,
                DISABLED,
            };

            enum class BootPinState
            {
                FIRMWARE_UPGRADE,
                NORMAL_BOOT,
            };

            BootPinState getBootPin();
            PassthroughState getPassthrough();

            void setBootPin(BootPinState bootPin);
            void setPassthrough(PassthroughState pass);
        } // namespace USB

        namespace status
        {
            enum class value
            {
                /// from the docs: When the module is turned on normally, the STATUS will present the low state.
                ACTIVE,
                INACTIVE,
            };
            /// returns true if status OK. Open drain pulled up; ground is OK.
            bsp::cellular::status::value getStatus();
            BaseType_t statusIRQhandler();
        } // namespace status

        namespace sim
        {
            /// handler for SIM tray which is connected to phone, not GSM
            BaseType_t trayIRQHandler();

            Store::GSM::Tray getTray();
            /// trigger swap pin on gsm so that it would reload sim card in tray
            /// after that +QPIN urc should come
            void hotSwapTrigger();
            void simSelect();
        } // namespace sim

        namespace ringIndicator
        {
            // handling incoming calls and sms - RI pin
            BaseType_t riIRQHandler();
        } // namespace ringIndicator

    } // namespace cellular
};    // namespace bsp

#endif // PUREPHONE_BSP_CELLULAR_HPP