| 889 | } |
| 890 | |
| 891 | void waybar::modules::Network::parseSignal(struct nlattr** bss) { |
| 892 | if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) { |
| 893 | // signalstrength in dBm from mBm |
| 894 | signal_strength_dbm_ = nla_get_s32(bss[NL80211_BSS_SIGNAL_MBM]) / 100; |
| 895 | // WiFi-hardware usually operates in the range -90 to -30dBm. |
| 896 | |
| 897 | // If a signal is too strong, it can overwhelm receiving circuity that is designed |
| 898 | // to pick up and process a certain signal level. The following percentage is scaled to |
| 899 | // punish signals that are too strong (>= -45dBm) or too weak (<= -45 dBm). |
| 900 | const int hardwareOptimum = -45; |
| 901 | const int hardwareMin = -90; |
| 902 | const int strength = |
| 903 | 100 - |
| 904 | ((abs(signal_strength_dbm_ - hardwareOptimum) / double{hardwareOptimum - hardwareMin}) * |
| 905 | 100); |
| 906 | signal_strength_ = std::clamp(strength, 0, 100); |
| 907 | |
| 908 | if (signal_strength_dbm_ >= -50) { |
| 909 | signal_strength_app_ = "Great Connectivity"; |
| 910 | } else if (signal_strength_dbm_ >= -60) { |
| 911 | signal_strength_app_ = "Good Connectivity"; |
| 912 | } else if (signal_strength_dbm_ >= -67) { |
| 913 | signal_strength_app_ = "Streaming"; |
| 914 | } else if (signal_strength_dbm_ >= -70) { |
| 915 | signal_strength_app_ = "Web Surfing"; |
| 916 | } else if (signal_strength_dbm_ >= -80) { |
| 917 | signal_strength_app_ = "Basic Connectivity"; |
| 918 | } else { |
| 919 | signal_strength_app_ = "Poor Connectivity"; |
| 920 | } |
| 921 | } |
| 922 | if (bss[NL80211_BSS_SIGNAL_UNSPEC] != nullptr) { |
| 923 | signal_strength_ = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | void waybar::modules::Network::parseFreq(struct nlattr** bss) { |
| 928 | if (bss[NL80211_BSS_FREQUENCY] != nullptr) { |