add wireless format-options
This commit is contained in:
parent
eccd4a7618
commit
42e7147291
@ -338,7 +338,10 @@ int main(int argc, char *argv[]) {
|
||||
cfg_opt_t wireless_opts[] = {
|
||||
CFG_STR("format_up", "W: (%quality at %essid, %bitrate) %ip", CFGF_NONE),
|
||||
CFG_STR("format_down", "W: down", CFGF_NONE),
|
||||
CFG_STR("format_bitrate", "%g %cb/s", CFGF_NONE),
|
||||
CFG_STR("format_noise", "%3d%s", CFGF_NONE),
|
||||
CFG_STR("format_quality", "%3d%s", CFGF_NONE),
|
||||
CFG_STR("format_signal", "%3d%s", CFGF_NONE),
|
||||
CFG_CUSTOM_ALIGN_OPT,
|
||||
CFG_CUSTOM_COLOR_OPTS,
|
||||
CFG_CUSTOM_MIN_WIDTH_OPT,
|
||||
@ -732,7 +735,7 @@ int main(int argc, char *argv[]) {
|
||||
interface = first_eth_interface(NET_TYPE_WIRELESS);
|
||||
if (interface == NULL)
|
||||
interface = title;
|
||||
print_wireless_info(json_gen, buffer, interface, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"), cfg_getstr(sec, "format_quality"));
|
||||
print_wireless_info(json_gen, buffer, interface, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"), cfg_getstr(sec, "format_bitrate"), cfg_getstr(sec, "format_noise"), cfg_getstr(sec, "format_quality"), cfg_getstr(sec, "format_signal"));
|
||||
SEC_CLOSE_MAP;
|
||||
}
|
||||
|
||||
|
@ -218,7 +218,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
|
||||
void print_time(yajl_gen json_gen, char *buffer, const char *title, const char *format, const char *tz, const char *locale, const char *format_time, bool hide_if_equals_localtime, time_t t);
|
||||
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, time_t t);
|
||||
const char *get_ip_addr(const char *interface, int family);
|
||||
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down, const char *quality_min_lenght);
|
||||
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);
|
||||
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format, const char *format_down);
|
||||
void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const char *path, const char *format, const char *format_down);
|
||||
void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format, const char *format_above_threshold, int);
|
||||
|
@ -306,7 +306,8 @@ There also is an option "format_down". You can hide the output with
|
||||
Gets the link quality, frequency and ESSID of the given wireless network
|
||||
interface. You can specify different format strings for the network being
|
||||
connected or not connected. The quality is padded with leading zeroes by
|
||||
default; to pad with something else use +format_quality+.
|
||||
default; to pad with something else use +format_bitrate+, +format_noise+,
|
||||
+format_quality+ or +format_signal+.
|
||||
|
||||
The special interface name `_first_` will be replaced by the first wireless
|
||||
network interface found on the system (excluding devices starting with "lo").
|
||||
@ -317,8 +318,14 @@ network interface found on the system (excluding devices starting with "lo").
|
||||
|
||||
*Example format_down*: +W: down+
|
||||
|
||||
*Example format_bitrate*: +"%g %cb/s"+
|
||||
|
||||
*Example format_noise*: +"%03d%s"+
|
||||
|
||||
*Example format_quality*: +"%03d%s"+
|
||||
|
||||
*Example format_signal*: +"%03d%s"+
|
||||
|
||||
=== Ethernet
|
||||
|
||||
Gets the IP address and (if possible) the link speed of the given ethernet
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user