root/lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips.c @ 4644

Revision 4644, 4.1 KB (checked in by khali, 6 years ago)

Let libsensors handle ignore statements by itself, rather than
delegating the task to the user applications.

For now, I am calling sensors_get_ignored() in
sensors_get_all_features(), because this is the least intrusive way.
This is in no way optimal though, it would be better to not add
ignored features to the feature list in the first place. However,
doing so would require that the configuration file is read before
sysfs is scanned for features, which isn't currently the case. So
this improvement is left for later.

Note that this patch adds a small cost in terms of performance. This
is because we now honor ignore statements on all features (main ones
and subfeatures) while in practice "sensors" was only checking for
main features. It would be trivial to stop checking for subfeatures,
but it seems to me that supporting ignore on subfeatures is a good
move, as the user may actually want to ignore a specific subfeature.
Individual alarms come to mind. This will also be handy to debug the
generic print code in "sensors".

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/*
2    chips.c - Part of sensors, a user-space program for hardware monitoring
3    Copyright (c) 1998-2003 Frodo Looijaard <frodol@dds.nl>
4                            and Mark D. Studebaker <mdsxyz123@yahoo.com>
5    Copyright (c) 2003-2006 The lm_sensors team
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <math.h>
26
27#include "chips.h"
28#include "lib/sensors.h"
29
30extern int fahrenheit;
31extern char degstr[5];
32
33static inline float deg_ctof(float cel)
34{
35   return ( cel * ( 9.0F / 5.0F ) + 32.0F );
36}
37
38/* minmax = 0 for limit/hysteresis, 1 for max/min, 2 for max only;
39   curprec and limitprec are # of digits after decimal point
40   for the current temp and the limits
41   note: symbolic constants defined in chips.h */
42void print_temp_info(float n_cur, float n_over, float n_hyst,
43                     int minmax, int curprec, int limitprec)
44{
45   /* note: deg_ctof() will preserve HUGEVAL */
46   if (fahrenheit) {
47      n_cur  = deg_ctof(n_cur);
48      n_over = deg_ctof(n_over);
49      n_hyst = deg_ctof(n_hyst);
50   }
51
52   /* use %* to pass precision as an argument */
53   if (n_cur != HUGE_VAL)
54      printf("%+6.*f%s  ", curprec, n_cur, degstr);
55   else
56      printf("   FAULT  ");
57
58   if(minmax == MINMAX)
59        printf("(low  = %+5.*f%s, high = %+5.*f%s)  ",
60            limitprec, n_hyst, degstr,
61            limitprec, n_over, degstr);
62   else if(minmax == MAXONLY)
63        printf("(high = %+5.*f%s)                  ",
64            limitprec, n_over, degstr);
65   else if(minmax == CRIT)
66        printf("(high = %+5.*f%s, crit = %+5.*f%s)  ",
67            limitprec, n_over, degstr,
68            limitprec, n_hyst, degstr);
69   else if(minmax == HYST)
70        printf("(high = %+5.*f%s, hyst = %+5.*f%s)  ",
71            limitprec, n_over, degstr,
72            limitprec, n_hyst, degstr);
73   else if(minmax == HYSTONLY)
74        printf("(hyst = %+5.*f%s)                  ",
75            limitprec, n_over, degstr);
76   else if(minmax != SINGLE)
77        printf("Unknown temperature mode!");
78}
79
80void print_label(const char *label, int space)
81{
82  int len=strlen(label)+1;
83  if (len > space)
84    printf("%s:\n%*s", label, space, "");
85  else
86    printf("%s:%*s", label, space - len, "");
87}
88
89int sensors_get_label_and_valid(sensors_chip_name name, int feature, char **label,
90                        int *valid)
91{
92  int err;
93  err = sensors_get_label(name,feature,label);
94  *valid = !err;
95  return err;
96}
97
98void print_vid_info(const sensors_chip_name *name, int f_vid, int label_size)
99{
100  char *label;
101  int valid;
102  double vid;
103
104  if (!sensors_get_label_and_valid(*name,f_vid,&label,&valid)
105      && !sensors_get_feature(*name,f_vid,&vid) ) {
106    if (valid) {
107      print_label(label, label_size);
108      printf("%+6.3f V\n", vid);
109    }
110  }
111  free(label);
112}
113
114void print_unknown_chip(const sensors_chip_name *name)
115{
116  int a, valid;
117  const sensors_feature_data *data;
118  char *label;
119  double val;
120 
121  a = 0;
122  while((data=sensors_get_all_features(*name, &a))) {
123    if (sensors_get_label_and_valid(*name,data->number,&label,&valid)) {
124      printf("ERROR: Can't get feature `%s' data!\n",data->name);
125      continue;
126    }
127    if (! valid)
128      continue;
129    if (data->mode & SENSORS_MODE_R) {
130      if(sensors_get_feature(*name,data->number,&val)) {
131        printf("ERROR: Can't get feature `%s' data!\n",data->name);
132        continue;
133      }
134      if (data->mapping != SENSORS_NO_MAPPING)
135        printf("  %s: %.2f (%s)\n",label,val,data->name);
136      else
137        printf("%s: %.2f (%s)\n",label,val,data->name);
138    } else 
139      printf("(%s)\n",label);
140    free(label);
141  }
142}
143
Note: See TracBrowser for help on using the browser.