Changeset 4366

Show
Ignore:
Timestamp:
04/09/07 19:48:57 (6 years ago)
Author:
jwrdegoede
Message:

Generic chip support / get featuretype fixes just received from Bob Schlarmann, as the version I committed wasn't the latest version

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/lib/access.c

    r4364 r4366  
    2121#include <string.h> 
    2222#include <math.h> 
     23#include <regex.h> 
    2324#include "access.h" 
    2425#include "sensors.h" 
     
    2728#include "proc.h" 
    2829#include "general.h" 
     30 
     31#define GET_TYPE_REGEX "\\([[:alpha:]]\\{1,\\}\\)[[:digit:]]\\{0,\\}\\(_\\([[:alpha:]]\\{1,\\}\\)\\)\\{0,1\\}" 
     32 
     33#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 
     34#define container_of(ptr, type, member) ({                      \ 
     35        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \ 
     36        (type *)( (const char *)__mptr - offsetof(type,member) );}) 
    2937 
    3038static int sensors_do_this_chip_sets(sensors_chip_name name); 
     
    498506} 
    499507 
     508/* Static mappings for use by sensors_feature_get_type() */ 
     509struct feature_type_match 
     510{ 
     511        const char *name; 
     512        sensors_feature_type type; 
     513         
     514        struct feature_type_match *submatches; 
     515}; 
     516 
     517static struct feature_type_match temp_matches[] = { 
     518        { "max", SENSORS_FEATURE_TEMP_MAX }, 
     519        { "min", SENSORS_FEATURE_TEMP_MIN }, 
     520        { "type", SENSORS_FEATURE_TEMP_SENS }, 
     521        { "hyst", SENSORS_FEATURE_TEMP_HYST }, 
     522        { "over", SENSORS_FEATURE_TEMP_OVER }, 
     523        { "max", SENSORS_FEATURE_TEMP_MAX }, 
     524        { "min", SENSORS_FEATURE_TEMP_MIN }, 
     525        { "low", SENSORS_FEATURE_TEMP_LOW }, 
     526        { "crit", SENSORS_FEATURE_TEMP_CRIT }, 
     527        { "fault", SENSORS_FEATURE_TEMP_FAULT }, 
     528        { "alarm", SENSORS_FEATURE_TEMP_ALARM }, 
     529        { "type", SENSORS_FEATURE_TEMP_SENS }, 
     530        { 0 } 
     531}; 
     532 
     533static struct feature_type_match in_matches[] = { 
     534        { "max", SENSORS_FEATURE_IN_MAX }, 
     535        { "max_alarm", SENSORS_FEATURE_IN_MAX_ALARM }, 
     536        { "min", SENSORS_FEATURE_IN_MIN }, 
     537        { "min_alarm", SENSORS_FEATURE_IN_MIN_ALARM }, 
     538        { "alarm", SENSORS_FEATURE_IN_ALARM }, 
     539        { 0 } 
     540}; 
     541 
     542static struct feature_type_match fan_matches[] = { 
     543        { "min", SENSORS_FEATURE_FAN_MIN }, 
     544        { "div", SENSORS_FEATURE_FAN_DIV }, 
     545        { "alarm", SENSORS_FEATURE_FAN_ALARM }, 
     546        { "fault", SENSORS_FEATURE_FAN_FAULT }, 
     547        { 0 } 
     548}; 
     549 
     550static struct feature_type_match matches[] = {  
     551        { "temp", SENSORS_FEATURE_TEMP, temp_matches }, 
     552        { "in", SENSORS_FEATURE_IN, in_matches }, 
     553        { "fan", SENSORS_FEATURE_FAN, fan_matches }, 
     554        { "vrm", SENSORS_FEATURE_VRM, 0 }, 
     555        { "vid", SENSORS_FEATURE_VID, 0 }, 
     556        { "sensor", SENSORS_FEATURE_TEMP_SENS, 0 },  
     557        { 0 } 
     558}; 
     559 
    500560/* Return the feature type based on the feature name */ 
    501561sensors_feature_type sensors_feature_get_type( 
    502562        const sensors_feature_data *feature) 
    503563{ 
    504         const char *name;        
    505          
    506         /* this will only work when the sensors_chip_feature is obtained through  
    507                 sensors_get_all_features */ 
    508         if (((const struct sensors_chip_feature *)feature)->sysname) 
    509                 name = ((const struct sensors_chip_feature *)feature)->sysname; 
     564        const char *name; 
     565        regex_t preg; 
     566        regmatch_t pmatch[4]; 
     567        int size_first, size_second, retval, i; 
     568        struct feature_type_match *submatches; 
     569         
     570        /* use sysname if exists */ 
     571        if (container_of(feature, const struct sensors_chip_feature, data)->sysname) 
     572                name = container_of(feature, const struct sensors_chip_feature, data)->sysname; 
    510573        else 
    511574                name = feature->name; 
    512575         
    513         if (strstr(name, "temp")) { 
    514                 if (strlen(name) == 5) 
    515                         return SENSORS_FEATURE_TEMP; 
    516                  
    517                 if (strstr(name, "hyst")) 
    518                         return SENSORS_FEATURE_TEMP_HYST; 
    519                  
    520                 if (strstr(name, "over")) 
    521                         return SENSORS_FEATURE_TEMP_OVER; 
    522                  
    523                 if (strstr(name, "max")) 
    524                         return SENSORS_FEATURE_TEMP_MAX; 
    525                  
    526                 if (strstr(name, "min")) 
    527                         return SENSORS_FEATURE_TEMP_MIN; 
    528                  
    529                 if (strstr(name, "low")) 
    530                         return SENSORS_FEATURE_TEMP_LOW; 
    531                  
    532                 if (strstr(name, "crit")) 
    533                         return SENSORS_FEATURE_TEMP_CRIT; 
    534         } else if (strstr(name, "in") && name[0] != 'f') { 
    535                 if (strlen(name) == 3 || strstr(name, "input")) 
    536                         return SENSORS_FEATURE_IN; 
    537                  
    538                 if (strstr(name, "max_alarm")) 
    539                         return SENSORS_FEATURE_IN_MAX_ALARM; 
    540                  
    541                 if (strstr(name, "max")) 
    542                         return SENSORS_FEATURE_IN_MAX; 
    543                  
    544                 if (strstr(name, "min_alarm")) 
    545                         return SENSORS_FEATURE_IN_MIN_ALARM; 
    546                  
    547                 if (strstr(name, "min")) 
    548                         return SENSORS_FEATURE_IN_MIN; 
    549                  
    550                 if (strstr(name, "alarm")) 
    551                         return SENSORS_FEATURE_IN_ALARM; 
    552         } else if (strstr(name, "fan")) { 
    553                 if (strlen(name) == 4) 
    554                         return SENSORS_FEATURE_FAN; 
    555                  
    556                 if (strstr(name, "min")) 
    557                         return SENSORS_FEATURE_FAN_MIN; 
    558                  
    559                 if (strstr(name, "div")) 
    560                         return SENSORS_FEATURE_FAN_DIV; 
    561         } else if (!strcmp(name, "vrm")) { 
    562                 return SENSORS_FEATURE_VRM; 
    563         } else if (strstr(name, "vid")) { 
    564                 return SENSORS_FEATURE_VID; 
    565         } 
     576        regcomp(&preg, GET_TYPE_REGEX, 0); 
     577         
     578        retval = regexec(&preg, name, 4, pmatch, 0); 
     579         
     580        regfree(&preg); 
     581         
     582        if (retval == -1) 
     583                return SENSORS_FEATURE_UNKNOWN; 
     584         
     585        size_first = pmatch[1].rm_eo - pmatch[1].rm_so; 
     586        size_second = pmatch[3].rm_eo - pmatch[3].rm_so; 
     587         
     588        for(i = 0; matches[i].name != 0; i++) 
     589                if (!strncmp(name, matches[i].name, size_first)) 
     590                        break; 
     591         
     592        if (matches[i].name == NULL) /* no match */ 
     593                return SENSORS_FEATURE_UNKNOWN; 
     594        else if (size_second == 0) /* single type */ 
     595                return matches[i].type; 
     596        else if (matches[i].submatches == NULL) /* not single type, but no submatches */ 
     597                return SENSORS_FEATURE_UNKNOWN; 
     598 
     599        submatches = matches[i].submatches; 
     600        for(i = 0; submatches[i].name != 0; i++) 
     601                if (!strncmp(name + pmatch[3].rm_so, submatches[i].name, size_second)) 
     602                        return submatches[i].type; 
    566603         
    567604        return SENSORS_FEATURE_UNKNOWN; 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h

    r4360 r4366  
    2222 
    2323#include <stdio.h> 
     24#include <limits.h> 
    2425 
    2526/* Publicly accessible library functions */ 
     
    148149 
    149150typedef enum sensors_feature_type { 
    150   SENSORS_FEATURE_TEMP = 0, 
     151  SENSORS_FEATURE_TEMP = 0x0, 
    151152  SENSORS_FEATURE_TEMP_ALARM, 
     153  SENSORS_FEATURE_TEMP_FAULT, 
     154  SENSORS_FEATURE_TEMP_SENS, 
    152155  SENSORS_FEATURE_TEMP_HYST, 
    153156  SENSORS_FEATURE_TEMP_OVER, 
     
    159162  SENSORS_FEATURE_TEMP_CRIT, 
    160163   
    161   SENSORS_FEATURE_IN, 
     164  SENSORS_FEATURE_IN = 0x100, 
    162165  SENSORS_FEATURE_IN_ALARM, 
    163166  SENSORS_FEATURE_IN_MIN, 
     
    166169  SENSORS_FEATURE_IN_MAX_ALARM, 
    167170   
    168   SENSORS_FEATURE_FAN, 
     171  SENSORS_FEATURE_FAN = 0x200, 
    169172  SENSORS_FEATURE_FAN_ALARM, 
     173  SENSORS_FEATURE_FAN_FAULT, 
    170174  SENSORS_FEATURE_FAN_MIN, 
    171175  SENSORS_FEATURE_FAN_DIV, 
    172176   
    173   SENSORS_FEATURE_VID, 
     177  SENSORS_FEATURE_VID = 0x300, 
    174178  SENSORS_FEATURE_VRM, 
    175179   
    176   SENSORS_FEATURE_UNKNOWN 
     180  SENSORS_FEATURE_UNKNOWN = INT_MAX 
    177181} sensors_feature_type; 
    178182 
    179 sensors_feature_type sensors_feature_get_type( 
    180   const sensors_feature_data *feature); 
     183sensors_feature_type sensors_feature_get_type 
     184             (const sensors_feature_data *feature); 
     185 
    181186#ifdef __cplusplus 
    182187} 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/chips_generic.c

    r4365 r4366  
    194194  } 
    195195   
    196   /* TODO: check for FAULT */ 
    197   if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_ALARM) &&  
    198       TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_ALARM)) { 
     196  /* print out temperature sensor info */ 
     197  if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_SENS)) { 
     198    int sens = (int)TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_SENS); 
     199    printf("sensor = %s  ", sens == 0 ? "disabled" : 
     200                            sens == 1 ? "diode" : 
     201                            sens == 2 ? "transistor" : 
     202                            sens == 3 ? "thermal diode" : 
     203                            sens == 4 ? "thermistor" : 
     204                            "unkown"); 
     205  } 
     206   
     207  /* ALARM and FAULT features */ 
     208  if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_FAULT) && 
     209      TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_FAULT) > 0.5) { 
     210    printf(" FAULT"); 
     211  } else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_ALARM) &&  
     212      TEMP_FEATURE_VAL(SENSORS_FEATURE_TEMP_ALARM) > 0.5) { 
    199213    printf(" ALARM"); 
    200214  }