From 27dbfd7c484146e3e39391aea3caee286af68819 Mon Sep 17 00:00:00 2001 From: Kelvin Cao Date: Fri, 1 Dec 2023 17:49:48 -0800 Subject: [PATCH] cli: Add verbose mode for 'temp' command to show individual die temperature sensor readings. --- cli/main.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/cli/main.c b/cli/main.c index 78d3401e..390724ef 100644 --- a/cli/main.c +++ b/cli/main.c @@ -1284,26 +1284,48 @@ static int test(int argc, char **argv) static int temp(int argc, char **argv) { float ret; + int nr_reading; + float temps[4]; static struct { struct switchtec_dev *dev; + int verbose; } cfg = {}; const struct argconfig_options opts[] = { DEVICE_OPTION, + {"verbose", 'v', "", CFG_NONE, &cfg.verbose, no_argument, + "print individual die temperature sensor reading"}, {NULL}}; argconfig_parse(argc, argv, CMD_DESC_TEMP, opts, &cfg, sizeof(cfg)); - ret = switchtec_die_temp(cfg.dev); - if (ret < 0) { - switchtec_perror("die_temp"); - return 1; + if (!cfg.verbose) { + ret = switchtec_die_temp(cfg.dev); + if (ret < 0) { + switchtec_perror("die_temp"); + return 1; + } + + if (have_decent_term()) + printf("%.3g °C\n", ret); + else + printf("%.3g degC\n", ret); + } else { + int i; + nr_reading = switchtec_die_temps(cfg.dev, 4, temps); + if (nr_reading < 0) { + switchtec_perror("die_temp"); + return 1; + } + + for (i = 0; i < nr_reading; i++) { + if (have_decent_term()) + printf("Sensor %d: %.3g °C\n", i, temps[i]); + else + printf("Sensor %d: %.3g degC\n", i, temps[i]); + } } - if (have_decent_term()) - printf("%.3g °C\n", ret); - else - printf("%.3g degC\n", ret); return 0; }