mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-31 06:15:15 +00:00
Added feature to sensors to allow json output.
* Added -j option to sensors that outputs json. * -j option overrides raw option Signed-off-by: Matthew SL Tiffany <shadethedemon@gmail.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
committed by
Guenter Roeck
parent
90f7e3c069
commit
1b36ea4299
@@ -67,6 +67,54 @@ void print_chip_raw(const sensors_chip_name *name)
|
||||
}
|
||||
}
|
||||
|
||||
void print_chip_json(const sensors_chip_name *name)
|
||||
{
|
||||
int a, b, cnt, subCnt, err;
|
||||
const sensors_feature *feature;
|
||||
const sensors_subfeature *sub;
|
||||
char *label;
|
||||
double val;
|
||||
|
||||
a = 0;
|
||||
cnt = 0;
|
||||
while ((feature = sensors_get_features(name, &a))) {
|
||||
if (!(label = sensors_get_label(name, feature))) {
|
||||
fprintf(stderr, "ERROR: Can't get label of feature "
|
||||
"%s!\n", feature->name);
|
||||
continue;
|
||||
}
|
||||
if (cnt > 0)
|
||||
printf(",\n");
|
||||
printf(" \"%s\":{\n", label);
|
||||
free(label);
|
||||
|
||||
b = 0;
|
||||
subCnt = 0;
|
||||
while ((sub = sensors_get_all_subfeatures(name, feature, &b))) {
|
||||
if (sub->flags & SENSORS_MODE_R) {
|
||||
if ((err = sensors_get_value(name, sub->number,
|
||||
&val))) {
|
||||
fprintf(stderr, "ERROR: Can't get "
|
||||
"value of subfeature %s: %s\n",
|
||||
sub->name,
|
||||
sensors_strerror(err));
|
||||
} else {
|
||||
if (subCnt > 0)
|
||||
printf(",\n");
|
||||
printf(" \"%s\": %.3f", sub->name, val);
|
||||
}
|
||||
|
||||
} else {
|
||||
printf("(%s)", label);
|
||||
}
|
||||
subCnt++;
|
||||
}
|
||||
printf("\n }");
|
||||
cnt++;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static const char hyst_str[] = "hyst";
|
||||
|
||||
static inline double deg_ctof(double cel)
|
||||
|
Reference in New Issue
Block a user