• 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     virtual int32_t GetSignalIntensity() const = 0;
48     virtual int32_t GetSignalLevel() const = 0;
49     virtual std::string ToString() const = 0;
50     virtual sptr<SignalInformation> NewInstance() const = 0;
51     SignalInformation();
52     virtual ~SignalInformation() = default;
53 
54 protected:
55     static int32_t signalBar_;
56 };
57 
58 class GsmSignalInformation : public SignalInformation {
59 public:
60     GsmSignalInformation() = default;
61     ~GsmSignalInformation() = default;
62     void SetValue(const int32_t gsmRssi = 0, const int32_t gsmBer = 0);
63     bool operator==(const GsmSignalInformation &gsm) const;
64     int32_t GetRssi() const;
65     int32_t GetGsmBer() const;
66     int32_t GetSignalIntensity() const override;
67     int32_t GetSignalLevel() const override;
68     std::string ToString() const override;
69     sptr<SignalInformation> NewInstance() const override;
70     SignalInformation::NetworkType GetNetworkType() const override;
71     bool Marshalling(Parcel &parcel) const override;
72     static std::unique_ptr<GsmSignalInformation> Unmarshalling(Parcel &parcel);
73     bool ReadFromParcel(Parcel &parcel) override;
74     bool ValidateGsmValue() const;
75 
76 private:
77     int32_t gsmRxlev_ = 0;
78     int32_t gsmBer_ = 0;
79 };
80 
81 class CdmaSignalInformation : public SignalInformation {
82 public:
83     CdmaSignalInformation() = default;
84     ~CdmaSignalInformation() = default;
85     void SetValue(const int32_t cdmaRssi = 0, const int32_t cdmaEcno = 0);
86     bool operator==(const CdmaSignalInformation &cdma) const;
87     int32_t GetCdmaRssi() const;
88     int32_t GetSignalIntensity() const override;
89     int32_t GetSignalLevel() const override;
90     std::string ToString() const override;
91     SignalInformation::NetworkType GetNetworkType() const override;
92     sptr<SignalInformation> NewInstance() const override;
93     bool Marshalling(Parcel &parcel) const override;
94     static std::unique_ptr<CdmaSignalInformation> Unmarshalling(Parcel &parcel);
95     bool ReadFromParcel(Parcel &parcel) override;
96     bool ValidateCdmaValue() const;
97 
98 private:
99     int32_t cdmaRssi_ = -1;
100     int32_t cdmaEcno_ = -1;
101 };
102 
103 class LteSignalInformation : public SignalInformation {
104 public:
105     LteSignalInformation() = default;
106     ~LteSignalInformation() = default;
107     void SetValue(
108         const int32_t rxlev = 0, const int32_t lteRsrp = 0, const int32_t lteRsrq = 0, const int32_t lteSnr = 0);
109     bool operator==(const LteSignalInformation &lte) const;
110     int32_t GetRxlev() const;
111     int32_t GetRsrp() const;
112     int32_t GetRsrq() const;
113     int32_t GetSnr() const;
114     int32_t GetSignalIntensity() const override;
115     int32_t GetSignalLevel() const override;
116     std::string ToString() const override;
117     SignalInformation::NetworkType GetNetworkType() const override;
118     sptr<SignalInformation> NewInstance() const override;
119     bool Marshalling(Parcel &parcel) const override;
120     static std::unique_ptr<LteSignalInformation> Unmarshalling(Parcel &parcel);
121     bool ReadFromParcel(Parcel &parcel) override;
122     bool ValidateLteValue() const;
123 
124 private:
125     int32_t rxlev_ = 0;
126     int32_t lteRsrp_ = 0;
127     int32_t lteRsrq_ = 0;
128     int32_t lteSnr_ = 0;
129 };
130 
131 class WcdmaSignalInformation : public SignalInformation {
132 public:
133     WcdmaSignalInformation() = default;
134     ~WcdmaSignalInformation() = default;
135     void SetValue(const int32_t wcdmaRxlev = 0, const int32_t wcdmaRscp = 0, const int32_t wcdmaEcio = 0,
136         const int32_t wcdmaBer = 0);
137     bool operator==(const WcdmaSignalInformation &wcdma) const;
138     int32_t GetRxlev() const;
139     int32_t GetRscp() const;
140     int32_t GetEcno() const;
141     int32_t GetBer() const;
142     int32_t GetSignalIntensity() const override;
143     int32_t GetSignalLevel() const override;
144     std::string ToString() const override;
145     SignalInformation::NetworkType GetNetworkType() const override;
146     sptr<SignalInformation> NewInstance() const override;
147     bool Marshalling(Parcel &parcel) const override;
148     static std::unique_ptr<WcdmaSignalInformation> Unmarshalling(Parcel &parcel);
149     bool ReadFromParcel(Parcel &parcel) override;
150     bool ValidateWcdmaValue() const;
151 
152 private:
153     int32_t wcdmaRxlev_ = 0;
154     int32_t wcdmaRscp_ = 0;
155     int32_t wcdmaEcio_ = 0;
156     int32_t wcdmaBer_ = 0;
157 };
158 
159 class TdScdmaSignalInformation : public SignalInformation {
160 public:
161     TdScdmaSignalInformation() = default;
162     ~TdScdmaSignalInformation() = default;
163     void SetValue(const int32_t tdScdmaRscp = 0);
164     bool operator==(const TdScdmaSignalInformation &tdScdma) const;
165     int32_t GetRscp() const;
166     int32_t GetSignalIntensity() const override;
167     int32_t GetSignalLevel() const override;
168     std::string ToString() const override;
169     SignalInformation::NetworkType GetNetworkType() const override;
170     sptr<SignalInformation> NewInstance() const override;
171     bool Marshalling(Parcel &parcel) const override;
172     static std::unique_ptr<TdScdmaSignalInformation> Unmarshalling(Parcel &parcel);
173     bool ReadFromParcel(Parcel &parcel) override;
174     bool ValidateTdScdmaValue() const;
175 
176 private:
177     int32_t tdScdmaRscp_ = 0;
178 };
179 
180 class NrSignalInformation : public SignalInformation {
181 public:
182     NrSignalInformation() = default;
183     ~NrSignalInformation() = default;
184     void SetValue(const int32_t rsrp = 0, const int32_t rsrq = 0, const int32_t sinr = 0);
185     bool operator==(const NrSignalInformation &nr) const;
186     int32_t GetRsrp() const;
187     int32_t GetRsrq() const;
188     int32_t GetSinr() const;
189     int32_t GetSignalIntensity() const override;
190     int32_t GetSignalLevel() const override;
191     std::string ToString() const override;
192     SignalInformation::NetworkType GetNetworkType() const override;
193     sptr<SignalInformation> NewInstance() const override;
194     bool Marshalling(Parcel &parcel) const override;
195     static std::unique_ptr<NrSignalInformation> Unmarshalling(Parcel &parcel);
196     bool ReadFromParcel(Parcel &parcel) override;
197     bool ValidateNrValue() const;
198 
199 private:
200     int32_t nrRsrp_ = 0;
201     int32_t nrRsrq_ = 0;
202     int32_t nrSinr_ = 0;
203 };
204 } // namespace Telephony
205 } // namespace OHOS
206 #endif // UNTITLED_SIGNAL_INFORMATION_H
207