diff options
author | Ingo Bürk <admin@airblader.de> | 2020-02-17 08:34:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-17 08:34:09 +0100 |
commit | b61e959a58750fe3a4cf9ed2472d4cb7112bd2c3 (patch) | |
tree | 6625f042d17c82b43dfffa138a4e0ce89da6d345 /src | |
parent | 5b115d39f85c5575b8ef6b888c8a66dfc883e603 (diff) | |
parent | 42e714729178679b425095bc1acb1b143ed4885c (diff) |
Merge pull request #381 from Stunkymonkey/format_wireless
add wireless format-options
Diffstat (limited to 'src')
-rw-r--r-- | src/print_wireless_info.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/print_wireless_info.c b/src/print_wireless_info.c index c6df4cb..49421bb 100644 --- a/src/print_wireless_info.c +++ b/src/print_wireless_info.c @@ -97,7 +97,7 @@ typedef struct { #ifdef __linux__ // Like iw_print_bitrate, but without the dependency on libiw. -static void print_bitrate(char *buffer, int buflen, int bitrate) { +static void print_bitrate(char *buffer, int buflen, int bitrate, const char *format_bitrate) { const int kilo = 1e3; const int mega = 1e6; const int giga = 1e9; @@ -116,7 +116,7 @@ static void print_bitrate(char *buffer, int buflen, int bitrate) { scale = 'k'; divisor = kilo; } - snprintf(buffer, buflen, "%g %cb/s", rate / divisor, scale); + snprintf(buffer, buflen, format_bitrate, rate / divisor, scale); } // Based on NetworkManager/src/platform/wifi/wifi-utils-nl80211.c @@ -491,7 +491,7 @@ error1: * | 127.0.0.1 | no IP | IPv4 | ok | * | 127.0.0.1 | ::1/128 | IPv4 | ok | */ -void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down, const char *format_quality) { +void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down, const char *format_bitrate, const char *format_noise, const char *format_quality, const char *format_signal) { const char *walk; char *outwalk = buffer; wireless_info_t info; @@ -560,7 +560,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, } else if (BEGINS_WITH(walk + 1, "signal")) { if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) { if (info.signal_level_max) - outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark); + outwalk += sprintf(outwalk, format_signal, PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark); else outwalk += sprintf(outwalk, "%d dBm", info.signal_level); } else { @@ -571,7 +571,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, } else if (BEGINS_WITH(walk + 1, "noise")) { if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) { if (info.noise_level_max) - outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark); + outwalk += sprintf(outwalk, format_noise, PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark); else outwalk += sprintf(outwalk, "%d dBm", info.noise_level); } else { @@ -603,7 +603,7 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, else if (BEGINS_WITH(walk + 1, "bitrate")) { char br_buffer[128]; - print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate); + print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate, format_bitrate); outwalk += sprintf(outwalk, "%s", br_buffer); walk += strlen("bitrate"); |