• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef UNTITLED_SIGNAL_INFORMATION_H
17 #define UNTITLED_SIGNAL_INFORMATION_H
18 
19 #include "parcel.h"
20 
21 namespace OHOS {
22 namespace Telephony {
23 class SignalInformation : public Parcelable {
24 public:
25     enum class NetworkType { GSM = 1, CDMA, WCDMA, TDSCDMA, LTE, NR };
26     static constexpr int32_t NO_VALUE = 0x1AAAAAAA;
27     static constexpr int32_t MAX_SIGNAL_NUM = 2;
28     static constexpr int32_t GSM_SIGNAL_THRESHOLD_5BAR[] = {-110, -109, -103, -97, -91, -85};
29     static constexpr int32_t CDMA_SIGNAL_THRESHOLD_5BAR[] = {-113, -112, -106, -99, -92, -85};
30     static constexpr int32_t LTE_SIGNAL_THRESHOLD_5BAR[] = {-121, -120, -115, -110, -105, -97};
31     static constexpr int32_t WCDMA_SIGNAL_THRESHOLD_5BAR[] = {-113, -112, -105, -99, -93, -87};
32     static constexpr int32_t TD_SCDMA_SIGNAL_THRESHOLD_5BAR[] = {-112, -111, -105, -99, -93, -87};
33     static constexpr int32_t NR_SIGNAL_THRESHOLD_5BAR[] = {-121, -120, -115, -110, -105, -97};
34     static constexpr int32_t GSM_SIGNAL_THRESHOLD_4BAR[] = {-110, -103, -97, -91, -85};
35     static constexpr int32_t CDMA_SIGNAL_THRESHOLD_4BAR[] = {-113, -106, -99, -92, -85};
36     static constexpr int32_t LTE_SIGNAL_THRESHOLD_4BAR[] = {-121, -115, -109, -103, -97};
37     static constexpr int32_t WCDMA_SIGNAL_THRESHOLD_4BAR[] = {-113, -105, -99, -93, -87};
38     static constexpr int32_t TD_SCDMA_SIGNAL_THRESHOLD_4BAR[] = {-112, -105, -99, -93, -87};
39     static constexpr int32_t NR_SIGNAL_THRESHOLD_4BAR[] = {-121, -115, -109, -103, -97};
40 
41 public:
42     virtual SignalInformation::NetworkType GetNetworkType() const = 0;
43     virtual bool Marshalling(Parcel &parcel) const = 0;
44     static void InitSignalBar(const int32_t bar = 5);
45     static std::unique_ptr<SignalInformation> Unmarshalling(Parcel &parcel);
46     virtual bool ReadFromParcel(Parcel &parcel) = 0;
47     /**
48      * @brief Get signal strength
49      *
50      * @return Received signal strength
51      */
52     virtual int32_t GetSignalIntensity() const = 0;
53     /**
54      * @brief Get signal strength level
55      *
56      * @return Received signal strength level
57      */
58     virtual int32_t GetSignalLevel() const = 0;
59     virtual std::string ToString() const = 0;
60     virtual sptr<SignalInformation> NewInstance() const = 0;
61     SignalInformation();
62     virtual ~SignalInformation() = default;
63 
64 protected:
65     static int32_t signalBar_;
66 };
67 
68 class GsmSignalInformation : public SignalInformation {
69 public:
70     GsmSignalInformation() = default;
71     ~GsmSignalInformation() = default;
72     void SetValue(const int32_t gsmRssi = 0, const int32_t gsmBer = 0);
73     bool operator==(const GsmSignalInformation &gsm) const;
74     /**
75      * @brief Get signal strength Indicator
76      *
77      * @return Received Signal Strength Indicator
78      */
79     int32_t GetRssi() const;
80     /**
81      * @brief Get Bit Error Rate
82      *
83      * @return Bit Error Rate
84      */
85     int32_t GetGsmBer() const;
86     int32_t GetSignalIntensity() const override;
87     int32_t GetSignalLevel() const override;
88     std::string ToString() const override;
89     sptr<SignalInformation> NewInstance() const override;
90     SignalInformation::NetworkType GetNetworkType() const override;
91     bool Marshalling(Parcel &parcel) const override;
92     static std::unique_ptr<GsmSignalInformation> Unmarshalling(Parcel &parcel);
93     bool ReadFromParcel(Parcel &parcel) override;
94     bool ValidateGsmValue() const;
95 
96 private:
97     int32_t gsmRxlev_ = 0;
98     int32_t gsmBer_ = 0;
99 };
100 
101 class CdmaSignalInformation : public SignalInformation {
102 public:
103     CdmaSignalInformation() = default;
104     ~CdmaSignalInformation() = default;
105     void SetValue(const int32_t cdmaRssi = 0, const int32_t cdmaEcno = 0);
106     bool operator==(const CdmaSignalInformation &cdma) const;
107     /**
108      * @brief Get CDMA Received Signal Strength Indicator
109      *
110      * @return CDMA Received Signal Strength Indicator
111      */
112     int32_t GetCdmaRssi() const;
113     int32_t GetSignalIntensity() const override;
114     int32_t GetSignalLevel() const override;
115     std::string ToString() const override;
116     SignalInformation::NetworkType GetNetworkType() const override;
117     sptr<SignalInformation> NewInstance() const override;
118     bool Marshalling(Parcel &parcel) const override;
119     static std::unique_ptr<CdmaSignalInformation> Unmarshalling(Parcel &parcel);
120     bool ReadFromParcel(Parcel &parcel) override;
121     bool ValidateCdmaValue() const;
122 
123 private:
124     int32_t cdmaRssi_ = -1;
125     int32_t cdmaEcno_ = -1;
126 };
127 
128 class LteSignalInformation : public SignalInformation {
129 public:
130     LteSignalInformation() = default;
131     ~LteSignalInformation() = default;
132     void SetValue(
133         const int32_t rxlev = 0, const int32_t lteRsrp = 0, const int32_t lteRsrq = 0, const int32_t lteSnr = 0);
134     bool operator==(const LteSignalInformation &lte) const;
135     /**
136      * @brief Get signal level
137      *
138      * @return Received Signal Level
139      */
140     int32_t GetRxlev() const;
141     /**
142      * @brief Get reference signal received power in dBm
143      *
144      * @return Reference signal received power in dBm
145      */
146     int32_t GetRsrp() const;
147     /**
148      * @brief Get reference signal received quality
149      *
150      * @return Reference signal received quality
151      */
152     int32_t GetRsrq() const;
153     /**
154      * @brief Get reference signal signal-to-noise ratio
155      *
156      * @return Reference signal signal-to-noise ratio
157      */
158     int32_t GetSnr() const;
159     int32_t GetSignalIntensity() const override;
160     int32_t GetSignalLevel() const override;
161     std::string ToString() const override;
162     SignalInformation::NetworkType GetNetworkType() const override;
163     sptr<SignalInformation> NewInstance() const override;
164     bool Marshalling(Parcel &parcel) const override;
165     static std::unique_ptr<LteSignalInformation> Unmarshalling(Parcel &parcel);
166     bool ReadFromParcel(Parcel &parcel) override;
167     bool ValidateLteValue() const;
168 
169 private:
170     int32_t rxlev_ = 0;
171     int32_t lteRsrp_ = 0;
172     int32_t lteRsrq_ = 0;
173     int32_t lteSnr_ = 0;
174 };
175 
176 class WcdmaSignalInformation : public SignalInformation {
177 public:
178     WcdmaSignalInformation() = default;
179     ~WcdmaSignalInformation() = default;
180     void SetValue(const int32_t wcdmaRxlev = 0, const int32_t wcdmaRscp = 0, const int32_t wcdmaEcio = 0,
181         const int32_t wcdmaBer = 0);
182     bool operator==(const WcdmaSignalInformation &wcdma) const;
183     /**
184      * @brief Get signal level
185      *
186      * @return Received signal level
187      */
188     int32_t GetRxlev() const;
189     /**
190      * @brief Get the Receive signal channel power as dBm
191      *
192      * @return Received receive signal channel power as dBm
193      */
194     int32_t GetRscp() const;
195     /**
196      * @brief Get energy per chip over the noise spectral density
197      *
198      * @return Energy per chip over the noise spectral density
199      */
200     int32_t GetEcno() const;
201     /**
202      * @brief Get Bit Error Rate
203      *
204      * @return Bit Error Rate
205      */
206     int32_t GetBer() const;
207     int32_t GetSignalIntensity() const override;
208     int32_t GetSignalLevel() const override;
209     std::string ToString() const override;
210     SignalInformation::NetworkType GetNetworkType() const override;
211     sptr<SignalInformation> NewInstance() const override;
212     bool Marshalling(Parcel &parcel) const override;
213     static std::unique_ptr<WcdmaSignalInformation> Unmarshalling(Parcel &parcel);
214     bool ReadFromParcel(Parcel &parcel) override;
215     bool ValidateWcdmaValue() const;
216 
217 private:
218     int32_t wcdmaRxlev_ = 0;
219     int32_t wcdmaRscp_ = 0;
220     int32_t wcdmaEcio_ = 0;
221     int32_t wcdmaBer_ = 0;
222 };
223 
224 class TdScdmaSignalInformation : public SignalInformation {
225 public:
226     TdScdmaSignalInformation() = default;
227     ~TdScdmaSignalInformation() = default;
228     void SetValue(const int32_t tdScdmaRscp = 0);
229     bool operator==(const TdScdmaSignalInformation &tdScdma) const;
230     /**
231      * @brief Get Receive signal channel power
232      *
233      * @return Received receive signal channel power
234      */
235     int32_t GetRscp() const;
236     int32_t GetSignalIntensity() const override;
237     int32_t GetSignalLevel() const override;
238     std::string ToString() const override;
239     SignalInformation::NetworkType GetNetworkType() const override;
240     sptr<SignalInformation> NewInstance() const override;
241     bool Marshalling(Parcel &parcel) const override;
242     static std::unique_ptr<TdScdmaSignalInformation> Unmarshalling(Parcel &parcel);
243     bool ReadFromParcel(Parcel &parcel) override;
244     bool ValidateTdScdmaValue() const;
245 
246 private:
247     int32_t tdScdmaRscp_ = 0;
248 };
249 
250 class NrSignalInformation : public SignalInformation {
251 public:
252     NrSignalInformation() = default;
253     ~NrSignalInformation() = default;
254     void SetValue(const int32_t rsrp = 0, const int32_t rsrq = 0, const int32_t sinr = 0);
255     bool operator==(const NrSignalInformation &nr) const;
256     /**
257      * @brief Get Reference signal received power in dBm
258      *
259      * @return Reference signal received power in dBm
260      */
261     int32_t GetRsrp() const;
262     /**
263      * @brief Get Reference signal received quality
264      *
265      * @return Reference signal received quality
266      */
267     int32_t GetRsrq() const;
268     /**
269      * @brief Get Signal-to-noise and interference ratio
270      *
271      * @return Signal-to-noise and interference ratio
272      */
273     int32_t GetSinr() const;
274     int32_t GetSignalIntensity() const override;
275     int32_t GetSignalLevel() const override;
276     std::string ToString() const override;
277     SignalInformation::NetworkType GetNetworkType() const override;
278     sptr<SignalInformation> NewInstance() const override;
279     bool Marshalling(Parcel &parcel) const override;
280     static std::unique_ptr<NrSignalInformation> Unmarshalling(Parcel &parcel);
281     bool ReadFromParcel(Parcel &parcel) override;
282     bool ValidateNrValue() const;
283 
284 private:
285     int32_t nrRsrp_ = 0;
286     int32_t nrRsrq_ = 0;
287     int32_t nrSinr_ = 0;
288 };
289 } // namespace Telephony
290 } // namespace OHOS
291 #endif // UNTITLED_SIGNAL_INFORMATION_H
292