| 1 | /* |
|---|
| 2 | chips.c - Part of sensors, a user-space program for hardware monitoring |
|---|
| 3 | Copyright (C) 1998-2003 Frodo Looijaard <frodol@dds.nl> and |
|---|
| 4 | Mark D. Studebaker <mdsxyz123@yahoo.com> |
|---|
| 5 | Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> |
|---|
| 6 | |
|---|
| 7 | This program is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | This program is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with this program; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 20 | MA 02110-1301 USA. |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #include <stdio.h> |
|---|
| 24 | #include <stdlib.h> |
|---|
| 25 | #include <string.h> |
|---|
| 26 | #include <math.h> |
|---|
| 27 | |
|---|
| 28 | #include "main.h" |
|---|
| 29 | #include "chips.h" |
|---|
| 30 | #include "lib/sensors.h" |
|---|
| 31 | #include "lib/error.h" |
|---|
| 32 | |
|---|
| 33 | void print_chip_raw(const sensors_chip_name *name) |
|---|
| 34 | { |
|---|
| 35 | int a, b, err; |
|---|
| 36 | const sensors_feature *feature; |
|---|
| 37 | const sensors_subfeature *sub; |
|---|
| 38 | char *label; |
|---|
| 39 | double val; |
|---|
| 40 | |
|---|
| 41 | a = 0; |
|---|
| 42 | while ((feature = sensors_get_features(name, &a))) { |
|---|
| 43 | if (!(label = sensors_get_label(name, feature))) { |
|---|
| 44 | fprintf(stderr, "ERROR: Can't get label of feature " |
|---|
| 45 | "%s!\n", feature->name); |
|---|
| 46 | continue; |
|---|
| 47 | } |
|---|
| 48 | printf("%s:\n", label); |
|---|
| 49 | free(label); |
|---|
| 50 | |
|---|
| 51 | b = 0; |
|---|
| 52 | while ((sub = sensors_get_all_subfeatures(name, feature, &b))) { |
|---|
| 53 | if (sub->flags & SENSORS_MODE_R) { |
|---|
| 54 | if ((err = sensors_get_value(name, sub->number, |
|---|
| 55 | &val))) |
|---|
| 56 | fprintf(stderr, "ERROR: Can't get " |
|---|
| 57 | "value of subfeature %s: %s\n", |
|---|
| 58 | sub->name, |
|---|
| 59 | sensors_strerror(err)); |
|---|
| 60 | else |
|---|
| 61 | printf(" %s: %.2f\n", sub->name, val); |
|---|
| 62 | } else |
|---|
| 63 | printf("(%s)\n", label); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | static inline double deg_ctof(double cel) |
|---|
| 69 | { |
|---|
| 70 | return cel * (9.0F / 5.0F) + 32.0F; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | static void print_label(const char *label, int space) |
|---|
| 74 | { |
|---|
| 75 | int len = strlen(label)+1; |
|---|
| 76 | printf("%s:%*s", label, space - len, ""); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | static double get_value(const sensors_chip_name *name, |
|---|
| 80 | const sensors_subfeature *sub) |
|---|
| 81 | { |
|---|
| 82 | double val; |
|---|
| 83 | int err; |
|---|
| 84 | |
|---|
| 85 | err = sensors_get_value(name, sub->number, &val); |
|---|
| 86 | if (err) { |
|---|
| 87 | fprintf(stderr, "ERROR: Can't get value of subfeature %s: %s\n", |
|---|
| 88 | sub->name, sensors_strerror(err)); |
|---|
| 89 | val = 0; |
|---|
| 90 | } |
|---|
| 91 | return val; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | static int get_label_size(const sensors_chip_name *name) |
|---|
| 95 | { |
|---|
| 96 | int i; |
|---|
| 97 | const sensors_feature *iter; |
|---|
| 98 | char *label; |
|---|
| 99 | unsigned int max_size = 11; /* 11 as minumum label width */ |
|---|
| 100 | |
|---|
| 101 | i = 0; |
|---|
| 102 | while ((iter = sensors_get_features(name, &i))) { |
|---|
| 103 | if ((label = sensors_get_label(name, iter)) && |
|---|
| 104 | strlen(label) > max_size) |
|---|
| 105 | max_size = strlen(label); |
|---|
| 106 | free(label); |
|---|
| 107 | } |
|---|
| 108 | return max_size + 1; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | static void print_temp_limits(double limit1, double limit2, |
|---|
| 112 | const char *name1, const char *name2, int alarm) |
|---|
| 113 | { |
|---|
| 114 | if (fahrenheit) { |
|---|
| 115 | limit1 = deg_ctof(limit1); |
|---|
| 116 | limit2 = deg_ctof(limit2); |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | if (name2) { |
|---|
| 120 | printf("(%-4s = %+5.1f%s, %-4s = %+5.1f%s) ", |
|---|
| 121 | name1, limit1, degstr, |
|---|
| 122 | name2, limit2, degstr); |
|---|
| 123 | } else if (name1) { |
|---|
| 124 | printf("(%-4s = %+5.1f%s) ", |
|---|
| 125 | name1, limit1, degstr); |
|---|
| 126 | } else { |
|---|
| 127 | printf(" "); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | if (alarm) |
|---|
| 131 | printf("ALARM "); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | static void print_chip_temp(const sensors_chip_name *name, |
|---|
| 135 | const sensors_feature *feature, |
|---|
| 136 | int label_size) |
|---|
| 137 | { |
|---|
| 138 | const sensors_subfeature *sf, *sfmin, *sfmax, *sfcrit, *sfhyst; |
|---|
| 139 | double val, limit1, limit2; |
|---|
| 140 | const char *s1, *s2; |
|---|
| 141 | int alarm, crit_displayed = 0; |
|---|
| 142 | char *label; |
|---|
| 143 | |
|---|
| 144 | if (!(label = sensors_get_label(name, feature))) { |
|---|
| 145 | fprintf(stderr, "ERROR: Can't get label of feature %s!\n", |
|---|
| 146 | feature->name); |
|---|
| 147 | return; |
|---|
| 148 | } |
|---|
| 149 | print_label(label, label_size); |
|---|
| 150 | free(label); |
|---|
| 151 | |
|---|
| 152 | sf = sensors_get_subfeature(name, feature, |
|---|
| 153 | SENSORS_SUBFEATURE_TEMP_ALARM); |
|---|
| 154 | alarm = sf && get_value(name, sf); |
|---|
| 155 | |
|---|
| 156 | sfmin = sensors_get_subfeature(name, feature, |
|---|
| 157 | SENSORS_SUBFEATURE_TEMP_MIN); |
|---|
| 158 | sfmax = sensors_get_subfeature(name, feature, |
|---|
| 159 | SENSORS_SUBFEATURE_TEMP_MAX); |
|---|
| 160 | sfcrit = sensors_get_subfeature(name, feature, |
|---|
| 161 | SENSORS_SUBFEATURE_TEMP_CRIT); |
|---|
| 162 | if (sfmax) { |
|---|
| 163 | sf = sensors_get_subfeature(name, feature, |
|---|
| 164 | SENSORS_SUBFEATURE_TEMP_MAX_ALARM); |
|---|
| 165 | if (sf && get_value(name, sf)) |
|---|
| 166 | alarm |= 1; |
|---|
| 167 | |
|---|
| 168 | if (sfmin) { |
|---|
| 169 | limit1 = get_value(name, sfmin); |
|---|
| 170 | s1 = "low"; |
|---|
| 171 | limit2 = get_value(name, sfmax); |
|---|
| 172 | s2 = "high"; |
|---|
| 173 | |
|---|
| 174 | sf = sensors_get_subfeature(name, feature, |
|---|
| 175 | SENSORS_SUBFEATURE_TEMP_MIN_ALARM); |
|---|
| 176 | if (sf && get_value(name, sf)) |
|---|
| 177 | alarm |= 1; |
|---|
| 178 | } else { |
|---|
| 179 | limit1 = get_value(name, sfmax); |
|---|
| 180 | s1 = "high"; |
|---|
| 181 | |
|---|
| 182 | sfhyst = sensors_get_subfeature(name, feature, |
|---|
| 183 | SENSORS_SUBFEATURE_TEMP_MAX_HYST); |
|---|
| 184 | if (sfhyst) { |
|---|
| 185 | limit2 = get_value(name, sfhyst); |
|---|
| 186 | s2 = "hyst"; |
|---|
| 187 | } else if (sfcrit) { |
|---|
| 188 | limit2 = get_value(name, sfcrit); |
|---|
| 189 | s2 = "crit"; |
|---|
| 190 | |
|---|
| 191 | sf = sensors_get_subfeature(name, feature, |
|---|
| 192 | SENSORS_SUBFEATURE_TEMP_CRIT_ALARM); |
|---|
| 193 | if (sf && get_value(name, sf)) |
|---|
| 194 | alarm |= 1; |
|---|
| 195 | crit_displayed = 1; |
|---|
| 196 | } else { |
|---|
| 197 | limit2 = 0; |
|---|
| 198 | s2 = NULL; |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | } else if (sfcrit) { |
|---|
| 202 | limit1 = get_value(name, sfcrit); |
|---|
| 203 | s1 = "crit"; |
|---|
| 204 | |
|---|
| 205 | sfhyst = sensors_get_subfeature(name, feature, |
|---|
| 206 | SENSORS_SUBFEATURE_TEMP_CRIT_HYST); |
|---|
| 207 | if (sfhyst) { |
|---|
| 208 | limit2 = get_value(name, sfhyst); |
|---|
| 209 | s2 = "hyst"; |
|---|
| 210 | } else { |
|---|
| 211 | limit2 = 0; |
|---|
| 212 | s2 = NULL; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | sf = sensors_get_subfeature(name, feature, |
|---|
| 216 | SENSORS_SUBFEATURE_TEMP_CRIT_ALARM); |
|---|
| 217 | if (sf && get_value(name, sf)) |
|---|
| 218 | alarm |= 1; |
|---|
| 219 | crit_displayed = 1; |
|---|
| 220 | } else { |
|---|
| 221 | limit1 = limit2 = 0; |
|---|
| 222 | s1 = s2 = NULL; |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | sf = sensors_get_subfeature(name, feature, |
|---|
| 227 | SENSORS_SUBFEATURE_TEMP_FAULT); |
|---|
| 228 | if (sf && get_value(name, sf)) { |
|---|
| 229 | printf(" FAULT "); |
|---|
| 230 | } else { |
|---|
| 231 | sf = sensors_get_subfeature(name, feature, |
|---|
| 232 | SENSORS_SUBFEATURE_TEMP_INPUT); |
|---|
| 233 | if (sf) { |
|---|
| 234 | val = get_value(name, sf); |
|---|
| 235 | if (fahrenheit) |
|---|
| 236 | val = deg_ctof(val); |
|---|
| 237 | printf("%+6.1f%s ", val, degstr); |
|---|
| 238 | } else |
|---|
| 239 | printf(" N/A "); |
|---|
| 240 | } |
|---|
| 241 | print_temp_limits(limit1, limit2, s1, s2, alarm); |
|---|
| 242 | |
|---|
| 243 | if (!crit_displayed && sfcrit) { |
|---|
| 244 | limit1 = get_value(name, sfcrit); |
|---|
| 245 | s1 = "crit"; |
|---|
| 246 | |
|---|
| 247 | sfhyst = sensors_get_subfeature(name, feature, |
|---|
| 248 | SENSORS_SUBFEATURE_TEMP_CRIT_HYST); |
|---|
| 249 | if (sfhyst) { |
|---|
| 250 | limit2 = get_value(name, sfhyst); |
|---|
| 251 | s2 = "hyst"; |
|---|
| 252 | } else { |
|---|
| 253 | limit2 = 0; |
|---|
| 254 | s2 = NULL; |
|---|
| 255 | } |
|---|
| 256 | |
|---|
| 257 | sf = sensors_get_subfeature(name, feature, |
|---|
| 258 | SENSORS_SUBFEATURE_TEMP_CRIT_ALARM); |
|---|
| 259 | alarm = sf && get_value(name, sf); |
|---|
| 260 | |
|---|
| 261 | printf("\n%*s", label_size + 10, ""); |
|---|
| 262 | print_temp_limits(limit1, limit2, s1, s2, alarm); |
|---|
| 263 | } |
|---|
| 264 | |
|---|
| 265 | /* print out temperature sensor info */ |
|---|
| 266 | sf = sensors_get_subfeature(name, feature, |
|---|
| 267 | SENSORS_SUBFEATURE_TEMP_TYPE); |
|---|
| 268 | if (sf) { |
|---|
| 269 | int sens = (int)get_value(name, sf); |
|---|
| 270 | |
|---|
| 271 | /* older kernels / drivers sometimes report a beta value for |
|---|
| 272 | thermistors */ |
|---|
| 273 | if (sens > 1000) |
|---|
| 274 | sens = 4; |
|---|
| 275 | |
|---|
| 276 | printf("sensor = %s", sens == 0 ? "disabled" : |
|---|
| 277 | sens == 1 ? "diode" : |
|---|
| 278 | sens == 2 ? "transistor" : |
|---|
| 279 | sens == 3 ? "thermal diode" : |
|---|
| 280 | sens == 4 ? "thermistor" : |
|---|
| 281 | sens == 5 ? "AMD AMDSI" : |
|---|
| 282 | sens == 6 ? "Intel PECI" : "unknown"); |
|---|
| 283 | } |
|---|
| 284 | printf("\n"); |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | static void print_chip_in(const sensors_chip_name *name, |
|---|
| 288 | const sensors_feature *feature, |
|---|
| 289 | int label_size) |
|---|
| 290 | { |
|---|
| 291 | const sensors_subfeature *sf, *sfmin, *sfmax; |
|---|
| 292 | double alarm_max, alarm_min; |
|---|
| 293 | char *label; |
|---|
| 294 | |
|---|
| 295 | if (!(label = sensors_get_label(name, feature))) { |
|---|
| 296 | fprintf(stderr, "ERROR: Can't get label of feature %s!\n", |
|---|
| 297 | feature->name); |
|---|
| 298 | return; |
|---|
| 299 | } |
|---|
| 300 | print_label(label, label_size); |
|---|
| 301 | free(label); |
|---|
| 302 | |
|---|
| 303 | sf = sensors_get_subfeature(name, feature, |
|---|
| 304 | SENSORS_SUBFEATURE_IN_INPUT); |
|---|
| 305 | if (sf) |
|---|
| 306 | printf("%+6.2f V", get_value(name, sf)); |
|---|
| 307 | else |
|---|
| 308 | printf(" N/A"); |
|---|
| 309 | |
|---|
| 310 | sfmin = sensors_get_subfeature(name, feature, |
|---|
| 311 | SENSORS_SUBFEATURE_IN_MIN); |
|---|
| 312 | sfmax = sensors_get_subfeature(name, feature, |
|---|
| 313 | SENSORS_SUBFEATURE_IN_MAX); |
|---|
| 314 | if (sfmin && sfmax) |
|---|
| 315 | printf(" (min = %+6.2f V, max = %+6.2f V)", |
|---|
| 316 | get_value(name, sfmin), |
|---|
| 317 | get_value(name, sfmax)); |
|---|
| 318 | else if (sfmin) |
|---|
| 319 | printf(" (min = %+6.2f V)", |
|---|
| 320 | get_value(name, sfmin)); |
|---|
| 321 | else if (sfmax) |
|---|
| 322 | printf(" (max = %+6.2f V)", |
|---|
| 323 | get_value(name, sfmax)); |
|---|
| 324 | |
|---|
| 325 | sf = sensors_get_subfeature(name, feature, |
|---|
| 326 | SENSORS_SUBFEATURE_IN_ALARM); |
|---|
| 327 | sfmin = sensors_get_subfeature(name, feature, |
|---|
| 328 | SENSORS_SUBFEATURE_IN_MIN_ALARM); |
|---|
| 329 | sfmax = sensors_get_subfeature(name, feature, |
|---|
| 330 | SENSORS_SUBFEATURE_IN_MAX_ALARM); |
|---|
| 331 | if (sfmin || sfmax) { |
|---|
| 332 | alarm_max = sfmax ? get_value(name, sfmax) : 0; |
|---|
| 333 | alarm_min = sfmin ? get_value(name, sfmin) : 0; |
|---|
| 334 | |
|---|
| 335 | if (alarm_min || alarm_max) { |
|---|
| 336 | printf(" ALARM ("); |
|---|
| 337 | |
|---|
| 338 | if (alarm_min) |
|---|
| 339 | printf("MIN"); |
|---|
| 340 | if (alarm_max) |
|---|
| 341 | printf("%sMAX", (alarm_min) ? ", " : ""); |
|---|
| 342 | |
|---|
| 343 | printf(")"); |
|---|
| 344 | } |
|---|
| 345 | } else if (sf) { |
|---|
| 346 | printf(" %s", |
|---|
| 347 | get_value(name, sf) ? "ALARM" : ""); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | printf("\n"); |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | static void print_chip_fan(const sensors_chip_name *name, |
|---|
| 354 | const sensors_feature *feature, |
|---|
| 355 | int label_size) |
|---|
| 356 | { |
|---|
| 357 | const sensors_subfeature *sf, *sfmin, *sfdiv; |
|---|
| 358 | char *label; |
|---|
| 359 | |
|---|
| 360 | if (!(label = sensors_get_label(name, feature))) { |
|---|
| 361 | fprintf(stderr, "ERROR: Can't get label of feature %s!\n", |
|---|
| 362 | feature->name); |
|---|
| 363 | return; |
|---|
| 364 | } |
|---|
| 365 | print_label(label, label_size); |
|---|
| 366 | free(label); |
|---|
| 367 | |
|---|
| 368 | sf = sensors_get_subfeature(name, feature, |
|---|
| 369 | SENSORS_SUBFEATURE_FAN_FAULT); |
|---|
| 370 | if (sf && get_value(name, sf)) |
|---|
| 371 | printf(" FAULT"); |
|---|
| 372 | else { |
|---|
| 373 | sf = sensors_get_subfeature(name, feature, |
|---|
| 374 | SENSORS_SUBFEATURE_FAN_INPUT); |
|---|
| 375 | if (sf) |
|---|
| 376 | printf("%4.0f RPM", get_value(name, sf)); |
|---|
| 377 | else |
|---|
| 378 | printf(" N/A"); |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | sfmin = sensors_get_subfeature(name, feature, |
|---|
| 382 | SENSORS_SUBFEATURE_FAN_MIN); |
|---|
| 383 | sfdiv = sensors_get_subfeature(name, feature, |
|---|
| 384 | SENSORS_SUBFEATURE_FAN_DIV); |
|---|
| 385 | if (sfmin && sfdiv) |
|---|
| 386 | printf(" (min = %4.0f RPM, div = %1.0f)", |
|---|
| 387 | get_value(name, sfmin), |
|---|
| 388 | get_value(name, sfdiv)); |
|---|
| 389 | else if (sfmin) |
|---|
| 390 | printf(" (min = %4.0f RPM)", |
|---|
| 391 | get_value(name, sfmin)); |
|---|
| 392 | else if (sfdiv) |
|---|
| 393 | printf(" (div = %1.0f)", |
|---|
| 394 | get_value(name, sfdiv)); |
|---|
| 395 | |
|---|
| 396 | sf = sensors_get_subfeature(name, feature, |
|---|
| 397 | SENSORS_SUBFEATURE_FAN_ALARM); |
|---|
| 398 | if (sf && get_value(name, sf)) { |
|---|
| 399 | printf(" ALARM"); |
|---|
| 400 | } |
|---|
| 401 | |
|---|
| 402 | printf("\n"); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | struct scale_table { |
|---|
| 406 | double upper_bound; |
|---|
| 407 | const char *unit; |
|---|
| 408 | }; |
|---|
| 409 | |
|---|
| 410 | static void scale_value(double *value, const char **prefixstr) |
|---|
| 411 | { |
|---|
| 412 | double abs_value = fabs(*value); |
|---|
| 413 | double divisor = 1e-9; |
|---|
| 414 | static struct scale_table prefix_scales[] = { |
|---|
| 415 | {1e-6, "n"}, |
|---|
| 416 | {1e-3, "u"}, |
|---|
| 417 | {1, "m"}, |
|---|
| 418 | {1e3, ""}, |
|---|
| 419 | {1e6, "k"}, |
|---|
| 420 | {1e9, "M"}, |
|---|
| 421 | {0, "G"}, /* no upper bound */ |
|---|
| 422 | }; |
|---|
| 423 | struct scale_table *scale = prefix_scales; |
|---|
| 424 | |
|---|
| 425 | while (scale->upper_bound && abs_value > scale->upper_bound) { |
|---|
| 426 | divisor = scale->upper_bound; |
|---|
| 427 | scale++; |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | *value /= divisor; |
|---|
| 431 | *prefixstr = scale->unit; |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | static void print_chip_power(const sensors_chip_name *name, |
|---|
| 435 | const sensors_feature *feature, |
|---|
| 436 | int label_size) |
|---|
| 437 | { |
|---|
| 438 | double val; |
|---|
| 439 | int need_space = 0; |
|---|
| 440 | const sensors_subfeature *sf, *sfmin, *sfmax, *sfint; |
|---|
| 441 | char *label; |
|---|
| 442 | const char *unit; |
|---|
| 443 | |
|---|
| 444 | if (!(label = sensors_get_label(name, feature))) { |
|---|
| 445 | fprintf(stderr, "ERROR: Can't get label of feature %s!\n", |
|---|
| 446 | feature->name); |
|---|
| 447 | return; |
|---|
| 448 | } |
|---|
| 449 | print_label(label, label_size); |
|---|
| 450 | free(label); |
|---|
| 451 | |
|---|
| 452 | /* Power sensors come in 2 flavors: instantaneous and averaged. |
|---|
| 453 | To keep things simple, we assume that each sensor only implements |
|---|
| 454 | one flavor. */ |
|---|
| 455 | sf = sensors_get_subfeature(name, feature, |
|---|
| 456 | SENSORS_SUBFEATURE_POWER_INPUT); |
|---|
| 457 | if (sf) { |
|---|
| 458 | sfmin = sensors_get_subfeature(name, feature, |
|---|
| 459 | SENSORS_SUBFEATURE_POWER_INPUT_HIGHEST); |
|---|
| 460 | sfmax = sensors_get_subfeature(name, feature, |
|---|
| 461 | SENSORS_SUBFEATURE_POWER_INPUT_LOWEST); |
|---|
| 462 | sfint = NULL; |
|---|
| 463 | } else { |
|---|
| 464 | sf = sensors_get_subfeature(name, feature, |
|---|
| 465 | SENSORS_SUBFEATURE_POWER_AVERAGE); |
|---|
| 466 | sfmin = sensors_get_subfeature(name, feature, |
|---|
| 467 | SENSORS_SUBFEATURE_POWER_AVERAGE_HIGHEST); |
|---|
| 468 | sfmax = sensors_get_subfeature(name, feature, |
|---|
| 469 | SENSORS_SUBFEATURE_POWER_AVERAGE_LOWEST); |
|---|
| 470 | sfint = sensors_get_subfeature(name, feature, |
|---|
| 471 | SENSORS_SUBFEATURE_POWER_AVERAGE_INTERVAL); |
|---|
| 472 | } |
|---|
| 473 | |
|---|
| 474 | if (sf) { |
|---|
| 475 | val = get_value(name, sf); |
|---|
| 476 | scale_value(&val, &unit); |
|---|
| 477 | printf("%6.2f %sW", val, unit); |
|---|
| 478 | } else |
|---|
| 479 | printf(" N/A"); |
|---|
| 480 | |
|---|
| 481 | if (sfmin || sfmax || sfint) { |
|---|
| 482 | printf(" ("); |
|---|
| 483 | |
|---|
| 484 | if (sfmin) { |
|---|
| 485 | val = get_value(name, sfmin); |
|---|
| 486 | scale_value(&val, &unit); |
|---|
| 487 | printf("min = %6.2f %sW", val, unit); |
|---|
| 488 | need_space = 1; |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | if (sfmax) { |
|---|
| 492 | val = get_value(name, sfmax); |
|---|
| 493 | scale_value(&val, &unit); |
|---|
| 494 | printf("%smax = %6.2f %sW", (need_space ? ", " : ""), |
|---|
| 495 | val, unit); |
|---|
| 496 | need_space = 1; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | if (sfint) { |
|---|
| 500 | printf("%sinterval = %6.2f s", (need_space ? ", " : ""), |
|---|
| 501 | get_value(name, sfint)); |
|---|
| 502 | need_space = 1; |
|---|
| 503 | } |
|---|
| 504 | printf(")"); |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | printf("\n"); |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | static void print_chip_energy(const sensors_chip_name *name, |
|---|
| 511 | const sensors_feature *feature, |
|---|
| 512 | int label_size) |
|---|
| 513 | { |
|---|
| 514 | double val; |
|---|
| 515 | const sensors_subfeature *sf; |
|---|
| 516 | char *label; |
|---|
| 517 | const char *unit; |
|---|
| 518 | |
|---|
| 519 | if (!(label = sensors_get_label(name, feature))) { |
|---|
| 520 | fprintf(stderr, "ERROR: Can't get label of feature %s!\n", |
|---|
| 521 | feature->name); |
|---|
| 522 | return; |
|---|
| 523 | } |
|---|
| 524 | print_label(label, label_size); |
|---|
| 525 | free(label); |
|---|
| 526 | |
|---|
| 527 | sf = sensors_get_subfeature(name, feature, |
|---|
| 528 | SENSORS_SUBFEATURE_ENERGY_INPUT); |
|---|
| 529 | if (sf) { |
|---|
| 530 | val = get_value(name, sf); |
|---|
| 531 | scale_value(&val, &unit); |
|---|
| 532 | printf("%6.2f %sJ", val, unit); |
|---|
| 533 | } else |
|---|
| 534 | printf(" N/A"); |
|---|
| 535 | |
|---|
| 536 | printf("\n"); |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | static void print_chip_vid(const sensors_chip_name *name, |
|---|
| 540 | const sensors_feature *feature, |
|---|
| 541 | int label_size) |
|---|
| 542 | { |
|---|
| 543 | char *label; |
|---|
| 544 | const sensors_subfeature *subfeature; |
|---|
| 545 | double vid; |
|---|
| 546 | |
|---|
| 547 | subfeature = sensors_get_subfeature(name, feature, |
|---|
| 548 | SENSORS_SUBFEATURE_VID); |
|---|
| 549 | if (!subfeature) |
|---|
| 550 | return; |
|---|
| 551 | |
|---|
| 552 | if ((label = sensors_get_label(name, feature)) |
|---|
| 553 | && !sensors_get_value(name, subfeature->number, &vid)) { |
|---|
| 554 | print_label(label, label_size); |
|---|
| 555 | printf("%+6.3f V\n", vid); |
|---|
| 556 | } |
|---|
| 557 | free(label); |
|---|
| 558 | } |
|---|
| 559 | |
|---|
| 560 | static void print_chip_beep_enable(const sensors_chip_name *name, |
|---|
| 561 | const sensors_feature *feature, |
|---|
| 562 | int label_size) |
|---|
| 563 | { |
|---|
| 564 | char *label; |
|---|
| 565 | const sensors_subfeature *subfeature; |
|---|
| 566 | double beep_enable; |
|---|
| 567 | |
|---|
| 568 | subfeature = sensors_get_subfeature(name, feature, |
|---|
| 569 | SENSORS_SUBFEATURE_BEEP_ENABLE); |
|---|
| 570 | if (!subfeature) |
|---|
| 571 | return; |
|---|
| 572 | |
|---|
| 573 | if ((label = sensors_get_label(name, feature)) |
|---|
| 574 | && !sensors_get_value(name, subfeature->number, &beep_enable)) { |
|---|
| 575 | print_label(label, label_size); |
|---|
| 576 | printf("%s\n", beep_enable ? "enabled" : "disabled"); |
|---|
| 577 | } |
|---|
| 578 | free(label); |
|---|
| 579 | } |
|---|
| 580 | |
|---|
| 581 | void print_chip(const sensors_chip_name *name) |
|---|
| 582 | { |
|---|
| 583 | const sensors_feature *feature; |
|---|
| 584 | int i, label_size; |
|---|
| 585 | |
|---|
| 586 | label_size = get_label_size(name); |
|---|
| 587 | |
|---|
| 588 | i = 0; |
|---|
| 589 | while ((feature = sensors_get_features(name, &i))) { |
|---|
| 590 | switch (feature->type) { |
|---|
| 591 | case SENSORS_FEATURE_TEMP: |
|---|
| 592 | print_chip_temp(name, feature, label_size); |
|---|
| 593 | break; |
|---|
| 594 | case SENSORS_FEATURE_IN: |
|---|
| 595 | print_chip_in(name, feature, label_size); |
|---|
| 596 | break; |
|---|
| 597 | case SENSORS_FEATURE_FAN: |
|---|
| 598 | print_chip_fan(name, feature, label_size); |
|---|
| 599 | break; |
|---|
| 600 | case SENSORS_FEATURE_VID: |
|---|
| 601 | print_chip_vid(name, feature, label_size); |
|---|
| 602 | break; |
|---|
| 603 | case SENSORS_FEATURE_BEEP_ENABLE: |
|---|
| 604 | print_chip_beep_enable(name, feature, label_size); |
|---|
| 605 | break; |
|---|
| 606 | case SENSORS_FEATURE_POWER: |
|---|
| 607 | print_chip_power(name, feature, label_size); |
|---|
| 608 | break; |
|---|
| 609 | case SENSORS_FEATURE_ENERGY: |
|---|
| 610 | print_chip_energy(name, feature, label_size); |
|---|
| 611 | break; |
|---|
| 612 | default: |
|---|
| 613 | continue; |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | } |
|---|