respondd-module-airtime: add idx

implements freifunk-gluon/gluon#2204
This commit is contained in:
aiyion.prime 2021-04-18 11:50:36 +02:00 committed by David Bauer
parent 0229863094
commit 8d53ff54e5
2 changed files with 17 additions and 5 deletions

View File

@ -11,7 +11,8 @@ The format is the following:
"busy": 46496566, "busy": 46496566,
"rx": 808415, "rx": 808415,
"tx": 41711344, "tx": 41711344,
"noise": 162 "noise": 162,
"phy": 1
}, },
{ {
"frequency": 2437, "frequency": 2437,
@ -19,7 +20,8 @@ The format is the following:
"busy": 205221222, "busy": 205221222,
"rx": 108121446, "rx": 108121446,
"tx": 85453679, "tx": 85453679,
"noise": 161 "noise": 161,
"phy": 0
} }
] ]
} }
@ -29,8 +31,12 @@ The format is the following:
The numbers `active`, `busy`, `rx` and `tx` are times in milliseconds, where The numbers `active`, `busy`, `rx` and `tx` are times in milliseconds, where
`busy`, `rx` and `tx` have to be interpreted by taking the quotient with `busy`, `rx` and `tx` have to be interpreted by taking the quotient with
`active`. `active`.
`phy` is the index of the radio in the mac80211 subsystem.
The motivation for having a list with the frequency as a value in the objects The motivation for having a list with the frequency as a value in the objects
instead of having an object with the frequency as keys is that multiple wifi instead of having an object with the frequency as keys is that multiple wifi
devices might be present, in which case the same frequency can appear multiple devices might be present, in which case the same frequency can appear multiple
times (because the statistics are reported once for every phy). times (because the statistics are reported once for every phy).
The field `phy` is added to distinguish multiple radios in the same band.
It is not the key of mapped data due to backwards compatibility.

View File

@ -7,7 +7,9 @@
#include "ifaces.h" #include "ifaces.h"
static struct json_object *respondd_provider_statistics(void) { static struct json_object *respondd_provider_statistics(void) {
struct json_object *result, *wireless; bool ok;
int newest_element_index;
struct json_object *last, *result, *wireless;
struct iface_list *ifaces; struct iface_list *ifaces;
result = json_object_new_object(); result = json_object_new_object();
@ -22,8 +24,12 @@ static struct json_object *respondd_provider_statistics(void) {
ifaces = get_ifaces(); ifaces = get_ifaces();
while (ifaces != NULL) { while (ifaces != NULL) {
get_airtime(wireless, ifaces->ifx); ok = get_airtime(wireless, ifaces->ifx);
if (ok) {
newest_element_index = json_object_array_length(wireless)-1;
last = json_object_array_get_idx(wireless, newest_element_index);
json_object_object_add(last, "phy", json_object_new_int(ifaces->wiphy));
}
void *freeptr = ifaces; void *freeptr = ifaces;
ifaces = ifaces->next; ifaces = ifaces->next;
free(freeptr); free(freeptr);