worked on smartmon support
[psensor.git] / src / lib / hdd_atasmart.c
index cb5200f..11223b6 100644 (file)
@@ -35,18 +35,23 @@ static int filter_sd(const char *p)
 }
 
 static struct psensor *
-create_sensor(char *id, char *name, int values_max_length)
+create_sensor(char *id, char *name, SkDisk *disk, int values_max_length)
 {
-       return psensor_create(id,
-                             strdup(name),
-                             SENSOR_TYPE_HDD_TEMP,
-                             values_max_length);
+       struct psensor *s;
+       s = psensor_create(id,
+                          strdup(name),
+                          SENSOR_TYPE_HDD_TEMP_ATASMART,
+                          values_max_length);
+
+       s->disk = disk;
+
+       return s;
 }
 
 struct psensor **hdd_psensor_list_add(struct psensor **sensors,
                                      int values_max_length)
 {
-       char **paths, **tmp;
+       char **paths, **tmp, *id;
        SkDisk *disk;
        struct psensor *sensor, **tmp_sensors, **result;
 
@@ -57,14 +62,17 @@ struct psensor **hdd_psensor_list_add(struct psensor **sensors,
        result = sensors;
        tmp = paths;
        while (*tmp) {
-               log_debug("hdd_psensor_list_add open %s", tmp);
+               log_debug("hdd_psensor_list_add open %s", *tmp);
 
                if (!sk_disk_open(*tmp, &disk)) {
-                       char *id = malloc(strlen("hdd at") + strlen(*tmp) + 1);
+                       id = malloc(strlen("hdd at") + strlen(*tmp) + 1);
                        strcpy(id, "hdd at");
                        strcat(id, *tmp);
 
-                       sensor = create_sensor(id, *tmp, values_max_length);
+                       sensor = create_sensor(id,
+                                              *tmp,
+                                              disk,
+                                              values_max_length);
 
                        tmp_sensors = psensor_list_add(result, sensor);
 
@@ -86,4 +94,31 @@ struct psensor **hdd_psensor_list_add(struct psensor **sensors,
 
 void hdd_psensor_list_update(struct psensor **sensors)
 {
+       struct psensor **cur, *s;
+       uint64_t kelvin;
+       int ret;
+       double c;
+
+       cur = sensors;
+       while (*cur) {
+               s = *cur;
+               if (s->type == SENSOR_TYPE_HDD_TEMP_ATASMART) {
+                       ret = sk_disk_smart_read_data(s->disk);
+
+                       if (!ret) {
+                               ret = sk_disk_smart_get_temperature(s->disk,
+                                                                   &kelvin);
+
+                               if (!ret) {
+                                       c = (kelvin - 273150) / 1000;
+                                       psensor_set_current_value(s, c);
+                                       log_debug("hdd atasmart: %s %.2f",
+                                                 s->id,
+                                                 c);
+                               }
+                       }
+               }
+
+               cur++;
+       }
 }