mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-28 07:44:06 +01:00
Common (Percent): adds ffRssiToSignalQuality
This commit is contained in:
@@ -20,6 +20,14 @@ typedef struct FFPercentageModuleConfig {
|
|||||||
FFPercentageTypeFlags type;
|
FFPercentageTypeFlags type;
|
||||||
} FFPercentageModuleConfig;
|
} FFPercentageModuleConfig;
|
||||||
|
|
||||||
|
// Maps a received signal strength in dBm onto the 0-100 scale the percentage formatters want.
|
||||||
|
// -50 dBm and above counts as a perfect link, -100 dBm and below as no link at all, and the range in
|
||||||
|
// between is linear. Both ends are clamped rather than extrapolated, so the result is always a
|
||||||
|
// percentage -- which also keeps it usable with `{?x}` guards, unlike a raw negative RSSI.
|
||||||
|
[[gnu::const]] static inline double ffRssiToSignalQuality(int32_t rssi) {
|
||||||
|
return (double) (rssi >= -50 ? 100 : rssi <= -100 ? 0 : (rssi + 100) * 2);
|
||||||
|
}
|
||||||
|
|
||||||
// if (green <= yellow)
|
// if (green <= yellow)
|
||||||
// [0, green]: print green
|
// [0, green]: print green
|
||||||
// (green, yellow]: print yellow
|
// (green, yellow]: print yellow
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
#include "common/percent.h"
|
||||||
#include "common/processing.h"
|
#include "common/processing.h"
|
||||||
#include "common/strutil.h"
|
#include "common/strutil.h"
|
||||||
#include "common/apple/cf_helpers.h"
|
#include "common/apple/cf_helpers.h"
|
||||||
@@ -7,11 +8,6 @@
|
|||||||
#import <IOKit/IOKitLib.h>
|
#import <IOKit/IOKitLib.h>
|
||||||
#import <IOKit/kext/KextManager.h>
|
#import <IOKit/kext/KextManager.h>
|
||||||
|
|
||||||
static inline double rssiToSignalQuality(int rssi) {
|
|
||||||
return (double) (rssi >= -50 ? 100 : rssi <= -100 ? 0
|
|
||||||
: (rssi + 100) * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@interface CWNetworkProfile ()
|
@interface CWNetworkProfile ()
|
||||||
@property (readonly, retain, nullable) NSArray<NSDictionary*>* bssidList;
|
@property (readonly, retain, nullable) NSArray<NSDictionary*>* bssidList;
|
||||||
@end
|
@end
|
||||||
@@ -101,7 +97,7 @@ const char* ffDetectWifi(FFlist* result) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
item->conn.signalQuality = rssiToSignalQuality((int) inf.rssiValue);
|
item->conn.signalQuality = ffRssiToSignalQuality((int) inf.rssiValue);
|
||||||
item->conn.txRate = inf.transmitRate;
|
item->conn.txRate = inf.transmitRate;
|
||||||
|
|
||||||
switch (inf.security) {
|
switch (inf.security) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "common/endian.h"
|
#include "common/endian.h"
|
||||||
#include "common/io.h"
|
#include "common/io.h"
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
|
#include "common/percent.h"
|
||||||
#include "common/strutil.h"
|
#include "common/strutil.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
@@ -35,11 +36,6 @@ typedef struct FFWifiSecurityFlags {
|
|||||||
bool eap : 1;
|
bool eap : 1;
|
||||||
} FFWifiSecurityFlags;
|
} FFWifiSecurityFlags;
|
||||||
|
|
||||||
static inline double rssiToSignalQuality(int rssi) {
|
|
||||||
return (double) (rssi >= -50 ? 100 : rssi <= -100 ? 0
|
|
||||||
: (rssi + 100) * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t ffWifiGetNetlinkPortId(int sockFd) {
|
static inline uint32_t ffWifiGetNetlinkPortId(int sockFd) {
|
||||||
struct sockaddr_nl addr = {};
|
struct sockaddr_nl addr = {};
|
||||||
socklen_t addrLen = sizeof(addr);
|
socklen_t addrLen = sizeof(addr);
|
||||||
@@ -605,7 +601,7 @@ static void ffWifiParseBssAttr(const struct nlattr* bssAttr, FFWifiResult* item)
|
|||||||
item->conn.channel = ffWifiFreqToChannel(item->conn.frequency);
|
item->conn.channel = ffWifiFreqToChannel(item->conn.frequency);
|
||||||
} else if (type == NL80211_BSS_SIGNAL_MBM && payload >= sizeof(int32_t)) {
|
} else if (type == NL80211_BSS_SIGNAL_MBM && payload >= sizeof(int32_t)) {
|
||||||
int rssi = *(int32_t*) ffWifiNlAttrData(attr) / 100; // mBm (100 * dBm) => dBm
|
int rssi = *(int32_t*) ffWifiNlAttrData(attr) / 100; // mBm (100 * dBm) => dBm
|
||||||
item->conn.signalQuality = rssiToSignalQuality(rssi);
|
item->conn.signalQuality = ffRssiToSignalQuality(rssi);
|
||||||
} else if (type == NL80211_BSS_CAPABILITY && payload >= sizeof(uint16_t)) {
|
} else if (type == NL80211_BSS_CAPABILITY && payload >= sizeof(uint16_t)) {
|
||||||
uint16_t capability = *(uint16_t*) ffWifiNlAttrData(attr);
|
uint16_t capability = *(uint16_t*) ffWifiNlAttrData(attr);
|
||||||
sec.privacy = (capability & (1u << 4u)) != 0; // IEEE 802.11 capability bit 4: privacy
|
sec.privacy = (capability & (1u << 4u)) != 0; // IEEE 802.11 capability bit 4: privacy
|
||||||
@@ -717,7 +713,7 @@ static void ffWifiParseStationInfo(const struct nlattr* staInfoAttr, FFWifiResul
|
|||||||
|
|
||||||
if (type == NL80211_STA_INFO_SIGNAL && payload >= sizeof(uint8_t) && item->conn.signalQuality == -DBL_MAX) {
|
if (type == NL80211_STA_INFO_SIGNAL && payload >= sizeof(uint8_t) && item->conn.signalQuality == -DBL_MAX) {
|
||||||
int rssi = (int8_t) *(const uint8_t*) ffWifiNlAttrData(attr);
|
int rssi = (int8_t) *(const uint8_t*) ffWifiNlAttrData(attr);
|
||||||
item->conn.signalQuality = rssiToSignalQuality(rssi);
|
item->conn.signalQuality = ffRssiToSignalQuality(rssi);
|
||||||
} else if (type == NL80211_STA_INFO_TX_BITRATE && (item->conn.txRate == -DBL_MAX || item->conn.channelWidth == 0)) {
|
} else if (type == NL80211_STA_INFO_TX_BITRATE && (item->conn.txRate == -DBL_MAX || item->conn.channelWidth == 0)) {
|
||||||
double tx = ffWifiParseBitrateFromRateInfo(attr, &item->conn.protocol, &item->conn.channelWidth);
|
double tx = ffWifiParseBitrateFromRateInfo(attr, &item->conn.protocol, &item->conn.channelWidth);
|
||||||
if (tx != -DBL_MAX) {
|
if (tx != -DBL_MAX) {
|
||||||
|
|||||||
Reference in New Issue
Block a user