1 /* 2 * Copyright (C) 2021-2024 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 { UNKNOWN = 0, 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 virtual void SetSignalLevel(const int32_t level); 64 65 protected: 66 static int32_t signalBar_; 67 int32_t signalLevel_ = -1; 68 }; 69 70 class GsmSignalInformation : public SignalInformation { 71 public: 72 GsmSignalInformation() = default; 73 ~GsmSignalInformation() = default; 74 void SetValue(const int32_t gsmRssi = 0, const int32_t gsmBer = 0); 75 GsmSignalInformation &operator=(const GsmSignalInformation &gsm); 76 bool operator==(const GsmSignalInformation &gsm) const; 77 /** 78 * @brief Get signal strength Indicator 79 * 80 * @return Received Signal Strength Indicator 81 */ 82 int32_t GetRssi() const; 83 /** 84 * @brief Get Bit Error Rate 85 * 86 * @return Bit Error Rate 87 */ 88 int32_t GetGsmBer() const; 89 int32_t GetSignalIntensity() const override; 90 int32_t GetSignalLevel() const override; 91 std::string ToString() const override; 92 sptr<SignalInformation> NewInstance() const override; 93 SignalInformation::NetworkType GetNetworkType() const override; 94 bool Marshalling(Parcel &parcel) const override; 95 static std::unique_ptr<GsmSignalInformation> Unmarshalling(Parcel &parcel); 96 bool ReadFromParcel(Parcel &parcel) override; 97 bool ValidateGsmValue() const; 98 99 private: 100 int32_t gsmRxlev_ = 0; 101 int32_t gsmBer_ = 0; 102 }; 103 104 class CdmaSignalInformation : public SignalInformation { 105 public: 106 CdmaSignalInformation() = default; 107 ~CdmaSignalInformation() = default; 108 void SetValue(const int32_t cdmaRssi = 0, const int32_t cdmaEcno = 0); 109 CdmaSignalInformation &operator=(const CdmaSignalInformation &cdma); 110 bool operator==(const CdmaSignalInformation &cdma) const; 111 /** 112 * @brief Get CDMA Received Signal Strength Indicator 113 * 114 * @return CDMA Received Signal Strength Indicator 115 */ 116 int32_t GetCdmaRssi() const; 117 int32_t GetSignalIntensity() const override; 118 int32_t GetSignalLevel() const override; 119 std::string ToString() const override; 120 SignalInformation::NetworkType GetNetworkType() const override; 121 sptr<SignalInformation> NewInstance() const override; 122 bool Marshalling(Parcel &parcel) const override; 123 static std::unique_ptr<CdmaSignalInformation> Unmarshalling(Parcel &parcel); 124 bool ReadFromParcel(Parcel &parcel) override; 125 bool ValidateCdmaValue() const; 126 127 private: 128 int32_t cdmaRssi_ = -1; 129 int32_t cdmaEcno_ = -1; 130 }; 131 132 class LteSignalInformation : public SignalInformation { 133 public: 134 LteSignalInformation() = default; 135 ~LteSignalInformation() = default; 136 void SetValue( 137 const int32_t rxlev = 0, const int32_t lteRsrp = 0, const int32_t lteRsrq = 0, const int32_t lteSnr = 0); 138 LteSignalInformation &operator=(const LteSignalInformation <e); 139 bool operator==(const LteSignalInformation <e) const; 140 /** 141 * @brief Get signal level 142 * 143 * @return Received Signal Level 144 */ 145 int32_t GetRxlev() const; 146 /** 147 * @brief Get reference signal received power in dBm 148 * 149 * @return Reference signal received power in dBm 150 */ 151 int32_t GetRsrp() const; 152 /** 153 * @brief Get reference signal received quality 154 * 155 * @return Reference signal received quality 156 */ 157 int32_t GetRsrq() const; 158 /** 159 * @brief Get reference signal signal-to-noise ratio 160 * 161 * @return Reference signal signal-to-noise ratio 162 */ 163 int32_t GetSnr() const; 164 int32_t GetSignalIntensity() const override; 165 int32_t GetSignalLevel() const override; 166 std::string ToString() const override; 167 SignalInformation::NetworkType GetNetworkType() const override; 168 sptr<SignalInformation> NewInstance() const override; 169 bool Marshalling(Parcel &parcel) const override; 170 static std::unique_ptr<LteSignalInformation> Unmarshalling(Parcel &parcel); 171 bool ReadFromParcel(Parcel &parcel) override; 172 bool ValidateLteValue() const; 173 174 private: 175 int32_t rxlev_ = 0; 176 int32_t lteRsrp_ = 0; 177 int32_t lteRsrq_ = 0; 178 int32_t lteSnr_ = 0; 179 }; 180 181 class WcdmaSignalInformation : public SignalInformation { 182 public: 183 WcdmaSignalInformation() = default; 184 ~WcdmaSignalInformation() = default; 185 void SetValue(const int32_t wcdmaRxlev = 0, const int32_t wcdmaRscp = 0, const int32_t wcdmaEcio = 0, 186 const int32_t wcdmaBer = 0); 187 WcdmaSignalInformation &operator=(const WcdmaSignalInformation &wcdma); 188 bool operator==(const WcdmaSignalInformation &wcdma) const; 189 /** 190 * @brief Get signal level 191 * 192 * @return Received signal level 193 */ 194 int32_t GetRxlev() const; 195 /** 196 * @brief Get the Receive signal channel power as dBm 197 * 198 * @return Received receive signal channel power as dBm 199 */ 200 int32_t GetRscp() const; 201 /** 202 * @brief Get energy per chip over the noise spectral density 203 * 204 * @return Energy per chip over the noise spectral density 205 */ 206 int32_t GetEcno() const; 207 /** 208 * @brief Get Bit Error Rate 209 * 210 * @return Bit Error Rate 211 */ 212 int32_t GetBer() const; 213 int32_t GetSignalIntensity() const override; 214 int32_t GetSignalLevel() const override; 215 std::string ToString() const override; 216 SignalInformation::NetworkType GetNetworkType() const override; 217 sptr<SignalInformation> NewInstance() const override; 218 bool Marshalling(Parcel &parcel) const override; 219 static std::unique_ptr<WcdmaSignalInformation> Unmarshalling(Parcel &parcel); 220 bool ReadFromParcel(Parcel &parcel) override; 221 bool ValidateWcdmaValue() const; 222 223 private: 224 int32_t wcdmaRxlev_ = 0; 225 int32_t wcdmaRscp_ = 0; 226 int32_t wcdmaEcio_ = 0; 227 int32_t wcdmaBer_ = 0; 228 }; 229 230 class TdScdmaSignalInformation : public SignalInformation { 231 public: 232 TdScdmaSignalInformation() = default; 233 ~TdScdmaSignalInformation() = default; 234 void SetValue(const int32_t tdScdmaRscp = 0); 235 TdScdmaSignalInformation &operator=(const TdScdmaSignalInformation &tdScdma); 236 bool operator==(const TdScdmaSignalInformation &tdScdma) const; 237 /** 238 * @brief Get Receive signal channel power 239 * 240 * @return Received receive signal channel power 241 */ 242 int32_t GetRscp() const; 243 int32_t GetSignalIntensity() const override; 244 int32_t GetSignalLevel() const override; 245 std::string ToString() const override; 246 SignalInformation::NetworkType GetNetworkType() const override; 247 sptr<SignalInformation> NewInstance() const override; 248 bool Marshalling(Parcel &parcel) const override; 249 static std::unique_ptr<TdScdmaSignalInformation> Unmarshalling(Parcel &parcel); 250 bool ReadFromParcel(Parcel &parcel) override; 251 bool ValidateTdScdmaValue() const; 252 253 private: 254 int32_t tdScdmaRscp_ = 0; 255 }; 256 257 class NrSignalInformation : public SignalInformation { 258 public: 259 NrSignalInformation() = default; 260 ~NrSignalInformation() = default; 261 void SetValue(const int32_t rsrp = 0, const int32_t rsrq = 0, const int32_t sinr = 0); 262 NrSignalInformation &operator=(const NrSignalInformation &nr); 263 bool operator==(const NrSignalInformation &nr) const; 264 /** 265 * @brief Get Reference signal received power in dBm 266 * 267 * @return Reference signal received power in dBm 268 */ 269 int32_t GetRsrp() const; 270 /** 271 * @brief Get Reference signal received quality 272 * 273 * @return Reference signal received quality 274 */ 275 int32_t GetRsrq() const; 276 /** 277 * @brief Get Signal-to-noise and interference ratio 278 * 279 * @return Signal-to-noise and interference ratio 280 */ 281 int32_t GetSinr() const; 282 int32_t GetSignalIntensity() const override; 283 int32_t GetSignalLevel() const override; 284 std::string ToString() const override; 285 SignalInformation::NetworkType GetNetworkType() const override; 286 sptr<SignalInformation> NewInstance() const override; 287 bool Marshalling(Parcel &parcel) const override; 288 static std::unique_ptr<NrSignalInformation> Unmarshalling(Parcel &parcel); 289 bool ReadFromParcel(Parcel &parcel) override; 290 bool ValidateNrValue() const; 291 292 private: 293 int32_t nrRsrp_ = 0; 294 int32_t nrRsrq_ = 0; 295 int32_t nrSinr_ = 0; 296 }; 297 } // namespace Telephony 298 } // namespace OHOS 299 #endif // UNTITLED_SIGNAL_INFORMATION_H 300