Changeset 4817

Show
Ignore:
Timestamp:
09/19/07 17:11:34 (7 years ago)
Author:
khali
Message:

Add generic chip support to sensord, much like sensors has.
Alarm and beep mask support is still missing.

Location:
lm-sensors/branches/lm-sensors-3.0.0/prog/sensord
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/chips.c

    r4805 r4817  
    7272 
    7373static const char * 
    74 fmtTemps_minmax_0 
    75 (const double values[], int alarm, int beep) { 
    76  sprintf (buff, "%.0f C (min = %.0f C, max = %.0f C)", values[0], values[1], values[2]); 
     74fmtTemps_minmax_1 
     75(const double values[], int alarm, int beep) { 
     76 sprintf (buff, "%.1f C (min = %.1f C, max = %.1f C)", values[0], values[1], values[2]); 
    7777 return fmtExtra (alarm, beep); 
    7878} 
     
    117117(const double values[], int alarm, int beep) { 
    118118  sprintf (buff, "%.0f RPM (min = %.0f RPM)", values[0], values[1]); 
     119  return fmtExtra (alarm, beep); 
     120} 
     121 
     122static const char * 
     123fmtFan_only 
     124(const double values[], int alarm, int beep) { 
     125  sprintf (buff, "%.0f RPM", values[0]); 
    119126  return fmtExtra (alarm, beep); 
    120127} 
     
    176183} 
    177184 
    178 /** ALL **/ 
    179  
    180 const ChipDescriptor * const knownChips[] = { 
    181   NULL 
    182 }; 
     185static void getAvailableFeatures (const sensors_chip_name *name, 
     186                                  const sensors_feature_data *feature, 
     187                                  int i, short *has_features, 
     188                                  int *feature_nrs, int size, 
     189                                  int first_val) 
     190{ 
     191  const sensors_feature_data *iter; 
     192 
     193  while ((iter = sensors_get_all_features (name, &i)) && 
     194         iter->mapping == feature->number) { 
     195    int index0; 
     196 
     197    index0 = iter->type - first_val - 1; 
     198    if (index0 < 0 || index0 >= size) 
     199      /* New feature in libsensors? Ignore. */ 
     200      continue; 
     201 
     202    has_features[index0] = 1; 
     203    feature_nrs[index0] = iter->number; 
     204  } 
     205} 
     206 
     207#define IN_FEATURE(x)      has_features[x - SENSORS_FEATURE_IN - 1] 
     208#define IN_FEATURE_NR(x)   feature_nrs[x - SENSORS_FEATURE_IN - 1] 
     209static void fillChipVoltage (FeatureDescriptor *voltage, 
     210                             const sensors_chip_name *name, 
     211                             const sensors_feature_data *feature, int i) 
     212{ 
     213  const int size = SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN; 
     214  short has_features[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN] = { 0, }; 
     215  int feature_nrs[SENSORS_FEATURE_IN_MAX_ALARM - SENSORS_FEATURE_IN]; 
     216  int pos = 0; 
     217 
     218  voltage->rrd = rrdF2; 
     219  voltage->type = DataType_voltage; 
     220  voltage->dataNumbers[pos++] = feature->number; 
     221 
     222  getAvailableFeatures (name, feature, i, has_features, 
     223                        feature_nrs, size, SENSORS_FEATURE_IN); 
     224 
     225  if (IN_FEATURE(SENSORS_FEATURE_IN_MIN) && 
     226      IN_FEATURE(SENSORS_FEATURE_IN_MAX)) { 
     227    voltage->format = fmtVolts_2; 
     228    voltage->dataNumbers[pos++] = IN_FEATURE_NR(SENSORS_FEATURE_IN_MIN); 
     229    voltage->dataNumbers[pos++] = IN_FEATURE_NR(SENSORS_FEATURE_IN_MAX); 
     230  } else { 
     231    voltage->format = fmtVolt_2; 
     232  } 
     233   
     234  /* terminate the list */ 
     235  voltage->dataNumbers[pos] = -1; 
     236} 
     237 
     238#define TEMP_FEATURE(x)      has_features[x - SENSORS_FEATURE_TEMP - 1] 
     239#define TEMP_FEATURE_NR(x)   feature_nrs[x - SENSORS_FEATURE_TEMP - 1] 
     240static void fillChipTemperature (FeatureDescriptor *temperature, 
     241                                 const sensors_chip_name *name, 
     242                                 const sensors_feature_data *feature, int i) 
     243{ 
     244  const int size = SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP; 
     245  short has_features[SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP] = { 0, }; 
     246  int feature_nrs[SENSORS_FEATURE_TEMP_TYPE - SENSORS_FEATURE_TEMP]; 
     247  int pos = 0; 
     248 
     249  temperature->rrd = rrdF1; 
     250  temperature->type = DataType_temperature; 
     251  temperature->dataNumbers[pos++] = feature->number; 
     252 
     253  getAvailableFeatures (name, feature, i, has_features, 
     254                        feature_nrs, size, SENSORS_FEATURE_TEMP); 
     255 
     256  if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MIN) && 
     257      TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX)) { 
     258    temperature->format = fmtTemps_minmax_1; 
     259    temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MIN); 
     260    temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MAX); 
     261  } else if (TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX) && 
     262             TEMP_FEATURE(SENSORS_FEATURE_TEMP_MAX_HYST)) { 
     263    temperature->format = fmtTemps_1; 
     264    temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MAX); 
     265    temperature->dataNumbers[pos++] = TEMP_FEATURE_NR(SENSORS_FEATURE_TEMP_MAX_HYST); 
     266  } else { 
     267    temperature->format = fmtTemp_only; 
     268  } 
     269   
     270  /* terminate the list */ 
     271  temperature->dataNumbers[pos] = -1; 
     272} 
     273 
     274#define FAN_FEATURE(x)      has_features[x - SENSORS_FEATURE_FAN - 1] 
     275#define FAN_FEATURE_NR(x)   feature_nrs[x - SENSORS_FEATURE_FAN - 1] 
     276static void fillChipFan (FeatureDescriptor *fan, 
     277                         const sensors_chip_name *name, 
     278                         const sensors_feature_data *feature, int i) 
     279{ 
     280  const int size = SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN; 
     281  short has_features[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN] = { 0, }; 
     282  int feature_nrs[SENSORS_FEATURE_FAN_DIV - SENSORS_FEATURE_FAN]; 
     283  int pos = 0; 
     284 
     285  fan->rrd = rrdF0; 
     286  fan->type = DataType_rpm; 
     287  fan->dataNumbers[pos++] = feature->number; 
     288 
     289  getAvailableFeatures (name, feature, i, has_features, 
     290                        feature_nrs, size, SENSORS_FEATURE_FAN); 
     291 
     292  if (FAN_FEATURE(SENSORS_FEATURE_FAN_MIN)) { 
     293    fan->dataNumbers[pos++] = FAN_FEATURE_NR(SENSORS_FEATURE_FAN_MIN); 
     294    if (FAN_FEATURE(SENSORS_FEATURE_FAN_DIV)) { 
     295      fan->format = fmtFans_0; 
     296      fan->dataNumbers[pos++] = FAN_FEATURE_NR(SENSORS_FEATURE_FAN_DIV); 
     297    } else { 
     298      fan->format = fmtFans_nodiv_0; 
     299    } 
     300  } else { 
     301      fan->format = fmtFan_only; 
     302  } 
     303   
     304  /* terminate the list */ 
     305  fan->dataNumbers[pos] = -1; 
     306} 
     307 
     308static void fillChipVid (FeatureDescriptor *voltage, 
     309                         const sensors_feature_data *feature) 
     310{ 
     311  voltage->format = fmtVolt_3; 
     312  voltage->rrd = rrdF3; 
     313  voltage->type = DataType_voltage; 
     314  voltage->dataNumbers[0] = feature->number; 
     315  voltage->dataNumbers[1] = -1; 
     316} 
     317 
     318static void fillChipBeepEnable (FeatureDescriptor *voltage, 
     319                                const sensors_feature_data *feature) 
     320{ 
     321  voltage->format = fmtSoundAlarm; 
     322  voltage->rrd = rrdF0; 
     323  voltage->type = DataType_other; 
     324  voltage->dataNumbers[0] = feature->number; 
     325  voltage->dataNumbers[1] = -1; 
     326} 
     327 
     328/* Note that alarms and beeps are no longer (or not yet) supported */ 
     329ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip) 
     330{ 
     331        int nr, count = 1; 
     332        const sensors_feature_data *sensor; 
     333        ChipDescriptor *descriptor; 
     334        FeatureDescriptor *features; 
     335 
     336        /* How many main features do we have? */ 
     337        nr = 0; 
     338        while ((sensor = sensors_get_all_features(chip, &nr))) { 
     339                if (sensor->mapping == SENSORS_NO_MAPPING) 
     340                        count++; 
     341        } 
     342 
     343        /* Allocate the memory we need */ 
     344        descriptor = calloc(1, sizeof(ChipDescriptor)); 
     345        features = calloc(count, sizeof(FeatureDescriptor)); 
     346        if (!descriptor || !features) { 
     347                free(descriptor); 
     348                free(features); 
     349                return NULL; 
     350        } 
     351        descriptor->features = features; 
     352 
     353        /* Fill in the data structures */ 
     354        count = 0; 
     355        nr = 0; 
     356        while ((sensor = sensors_get_all_features(chip, &nr))) { 
     357                if (sensor->mapping != SENSORS_NO_MAPPING) 
     358                        continue; 
     359 
     360                switch (sensor->type) { 
     361                case SENSORS_FEATURE_TEMP: 
     362                        fillChipTemperature(&features[count], chip, sensor, nr); 
     363                        break; 
     364                case SENSORS_FEATURE_IN: 
     365                        fillChipVoltage(&features[count], chip, sensor, nr); 
     366                        break; 
     367                case SENSORS_FEATURE_FAN: 
     368                        fillChipFan(&features[count], chip, sensor, nr); 
     369                        break; 
     370                case SENSORS_FEATURE_VID: 
     371                        fillChipVid(&features[count], sensor); 
     372                        break; 
     373                case SENSORS_FEATURE_BEEP_ENABLE: 
     374                        fillChipBeepEnable(&features[count], sensor); 
     375                        break; 
     376                default: 
     377                        continue; 
     378                } 
     379 
     380                count++; 
     381        } 
     382 
     383        return descriptor; 
     384} 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/rrd.c

    r4807 r4817  
    142142  for (j = 0; (ret == 0) && (j < numChipNames); ++ j) { 
    143143    while ((ret == 0) && ((chip = sensors_get_detected_chips (&chipNames[j], &i)) != NULL)) { 
    144       int index0, subindex, chipindex = -1; 
    145       for (index0 = 0; knownChips[index0]; ++ index0) 
    146         for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex) 
    147           if (!strcmp (chip->prefix, knownChips[index0]->names[subindex])) 
    148             chipindex = index0; 
    149       if (chipindex >= 0) { 
    150         const ChipDescriptor *descriptor = knownChips[chipindex]; 
     144      ChipDescriptor *descriptor; 
     145      descriptor = generateChipDescriptor (chip); 
     146      if (descriptor) { 
    151147        const FeatureDescriptor *features = descriptor->features; 
     148        int index0; 
    152149 
    153150        for (index0 = 0; (ret == 0) && (num < MAX_RRD_SENSORS) && features[index0].format; ++ index0) { 
     
    171168            free (label); 
    172169        } 
     170        free (descriptor->features); 
     171        free (descriptor); 
    173172      } 
    174173    } 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sense.c

    r4806 r4817  
    198198    ret = setChip (chip); 
    199199  } else { 
    200     int index0, subindex, chipindex = -1; 
    201     for (index0 = 0; knownChips[index0]; ++ index0) 
    202       for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex) 
    203         if (!strcmp (chip->prefix, knownChips[index0]->names[subindex])) 
    204           chipindex = index0; 
    205     if (chipindex >= 0) 
    206       ret = doKnownChip (chip, knownChips[chipindex], action); 
    207     else if (action == DO_READ) 
     200    ChipDescriptor *descriptor; 
     201    descriptor = generateChipDescriptor (chip); 
     202    if (descriptor) { 
     203      ret = doKnownChip (chip, descriptor, action); 
     204      free (descriptor->features); 
     205      free (descriptor); 
     206    } else if (action == DO_READ) 
    208207      ret = readUnknownChip (chip); 
    209208  } 
  • lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/sensord.h

    r4804 r4817  
    9292  int alarmMask; 
    9393  int beepMask; 
    94   const int dataNumbers[MAX_DATA + 1]; /* First entry is used for the label */ 
     94  int dataNumbers[MAX_DATA + 1]; /* First entry is used for the label */ 
    9595} FeatureDescriptor; 
    9696 
    9797typedef struct { 
    98   const char * const *names; 
    99   const FeatureDescriptor *features; 
     98  FeatureDescriptor *features; 
    10099  int alarmNumber; 
    101100  int beepNumber; 
    102101} ChipDescriptor; 
    103102 
    104 extern const ChipDescriptor * const knownChips[]; 
     103extern ChipDescriptor * generateChipDescriptor (const sensors_chip_name *chip);