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