~aleteoryx/muditaos

muditaos/module-utils/EventStore/EventStore.hpp -rw-r--r-- 5.3 KiB
a405cad6Aleteoryx trim readme 6 days 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

// static lifetime read only cache for (hw) states to not poll
// right now it serves data from:
// - battery
// - gsm SIM tray
// it's not meant to serve as polling interface - rather to serve data

#include <hal/cellular/SIM.hpp>

#include <cstddef>
#include <string>

namespace cpp_freertos
{
    class MutexStandard;
} // namespace cpp_freertos

namespace Store
{
    struct Battery
    {
      private:
        static bool updated;

      public:
        enum class LevelState : std::uint8_t
        {
            Normal,
            Shutdown,
            CriticalCharging,
            CriticalNotCharging
        } levelState = LevelState::Normal;

        enum class State : std::uint8_t
        {
            Discharging,
            Charging,
            ChargingDone,
            PluggedNotCharging,
        } state            = State::Discharging;

        enum class Temperature : std::uint8_t
        {
            Normal,
            TooLow,
            TooHigh,
            Unknown
        } temperature = Temperature::Normal;

        unsigned level = 0;

        /// @brief Returns const reference to Battery instance, used to read battery state
        /// @return const Battery&
        static const Battery &get();

        /// @brief Returns reference to Battery instance, used to change battery state
        /// @return Battery&
        static Battery &modify();

        static void setUpdated();
        static bool takeUpdated();
    };

    struct Usb
    {
      public:
        enum class Status : bool
        {
            NotConfigured,
            Configured
        } status = Status::NotConfigured;

        /// @brief Returns const reference to Usb instance, used to read Usb status
        /// @return const Usb&
        static const Usb &get();

        /// @brief Returns reference to Usb instance, used to change Usb status
        /// @return Usb&
        static Usb &modify();
    };

    enum class RssiBar : size_t
    {
        zero  = 0,
        one   = 1,
        two   = 2,
        three = 3,
        four  = 4,
        noOfSupportedBars
    };

    struct SignalStrength
    {
        int rssi        = 0;
        int rssidBm     = 0;
        RssiBar rssiBar = RssiBar::zero;
    };

    enum class Tethering
    {
        Off,
        On
    };

    struct Network
    {
        enum class Status
        {
            NotRegistered,
            RegisteredHomeNetwork,
            Searching,
            RegistrationDenied,
            Unknown,
            RegisteredRoaming
        } status = Status::NotRegistered;

        enum class AccessTechnology
        {
            Gsm   = 0,
            Utran = 2,
            GsmWEgprs,
            UtranWHsdpa,
            UtranWHsupa,
            UtranWHsdpaAndWHsupa,
            EUtran,
            Cdma = 100,
            Wcdma,
            Unknown = 255
        } accessTechnology = AccessTechnology::Unknown;

        inline bool operator==(const Network &rhs)
        {
            return this->status == rhs.status && this->accessTechnology == rhs.accessTechnology;
        }
        inline bool operator!=(const Network &rhs)
        {
            return !(*this == rhs);
        }
    };

    struct GSM
    {
      private:
        GSM() = default;
        SignalStrength signalStrength;
        Network network;
        std::string networkOperatorName;
        Tethering tethering;

        static cpp_freertos::MutexStandard mutex;

      public:
        GSM(const GSM &) = delete;
        GSM &operator=(const GSM &) = delete;

        enum class Tray
        {
            OUT,
            IN
        } tray = Tray::IN;
        /// tray - tray actual status which is visible right now on screen
        /// selected - tray selection settings settable sim tray
        enum class SIM
        {
            SIM1 = static_cast<int>(hal::cellular::SimSlot::SIM1),
            SIM2 = static_cast<int>(hal::cellular::SimSlot::SIM2),
            SIM_NEED_PIN,
            SIM_NEED_PUK,
            SIM_LOCKED,
            SIM_FAIL,
            SIM_UNKNOWN,
            NONE,
        } sim = SIM::SIM_UNKNOWN;

        enum class SelectedSIM
        {
            SIM1 = static_cast<int>(SIM::SIM1),
            SIM2 = static_cast<int>(SIM::SIM2),
            NONE,
        } selected = SelectedSIM::SIM1;

        bool simCardInserted();

        /// state of modem
        enum class Modem
        {
            OFF,             /// modem is off - it's not working
            ON_INITIALIZING, /// modem is set to on, just started - initialization not done yet
            ON_NEED_SIMFLOW, /// modem is on, initialized, no SIM initialization yet
            ON_INITIALIZED,  /// modem is on, and it's fully initialized
        } modem = Modem::OFF;

        void setSignalStrength(const SignalStrength &newSignalStrength);
        SignalStrength getSignalStrength() const;

        void setNetwork(const Network &network);
        Network getNetwork() const;

        void setNetworkOperatorName(const std::string &newNetworkOperatorName);
        std::string getNetworkOperatorName() const;

        void setTethering(const Tethering &newTethering);
        Tethering getTethering() const;

        static GSM *get();
    };
}; // namespace Store