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