From 622e9d900e6c1ae9d90896d197360db3a06eb291 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Orsini Date: Sun, 26 Aug 2012 10:09:34 +0000 Subject: [PATCH] improved sensor log format --- src/lib/slog.c | 40 ++++++++++++++++++++++++++++++++++------ src/server/description.txt | 23 ++++++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/lib/slog.c b/src/lib/slog.c index f1b2f5b..aed2a5b 100644 --- a/src/lib/slog.c +++ b/src/lib/slog.c @@ -21,14 +21,17 @@ #define _(str) gettext(str) #include +#include #include +#include "bool.h" #include "config.h" #include "log.h" #include "slog.h" static FILE *file; static struct timeval stv; +static double *last_values; int slog_init(const char *path, struct psensor **sensors) { @@ -47,7 +50,7 @@ int slog_init(const char *path, struct psensor **sensors) fprintf(file, "I,%ld,%s\n", stv.tv_sec, VERSION); while (*sensors) { - fprintf(file, "S,%s\n", (*sensors)->id); + fprintf(file, "S,%s,%x\n", (*sensors)->id, (*sensors)->type); sensors++; } @@ -56,9 +59,14 @@ int slog_init(const char *path, struct psensor **sensors) return 1; } + + void slog_write_sensors(struct psensor **sensors) { + int count, i; + double v; struct timeval tv; + bool first_call; if (!file) return ; @@ -68,11 +76,27 @@ void slog_write_sensors(struct psensor **sensors) return ; } - fprintf(file, "M,%ld", tv.tv_sec - stv.tv_sec); - while (*sensors) { - fprintf(file, ",%.1f", psensor_get_current_value(*sensors)); - sensors++; + count = psensor_list_size(sensors); + + if (last_values) { + first_call = 0; + } else { + first_call = 1; + last_values = malloc(count * sizeof(double)); } + + fprintf(file, "%ld", tv.tv_sec - stv.tv_sec); + for (i = 0; i < count; i++) { + v = psensor_get_current_value(sensors[i]); + + if (!first_call && last_values[i] == v) + fputc(',', file); + else + fprintf(file, ",%.1f", v); + + last_values[i] = v; + } + fputc('\n', file); fflush(file); @@ -80,6 +104,10 @@ void slog_write_sensors(struct psensor **sensors) void slog_close() { - if (file) + if (file) { fclose(file); + file = NULL; + free(last_values); + last_values = NULL; + } } diff --git a/src/server/description.txt b/src/server/description.txt index 9d1696b..744dc8c 100644 --- a/src/server/description.txt +++ b/src/server/description.txt @@ -64,18 +64,35 @@ since EPOC. %V is the version of psensor-server. -Following lines gives the ordered list of sensors: S,%I +Following lines gives the ordered list of sensors: S,%I,%T %I is the uniq identifier of the sensor. -Then, the values of all sensors are written: M,%D,%V... +%T is the hexadecimal representation of the sensor type. + +Then, the values of all sensors are written: %D,%V... %D is the number of seconds elapsed since the starting time of the log. %V... is the list separated by a comma of the current value of all sensors. The ordering is the same than the list of sensor identifiers. -The value is expressed as a float. + +The value is expressed as a float with one digit precision. Temperatures +are using Celcius unit. + +The value is written only if it has changed. + +Example: +I,1345974927,0.7.0.4 +S,lmsensor coretemp-isa-0000 Physical id 0,101 +S,lmsensor coretemp-isa-0000 Core 0,101 +S,lmsensor coretemp-isa-0000 Core 1,101 +0,37.0,37.0,36.0 +5,36.0,,36.0 + +Five seconds after the log starts, the temperature of the second +sensor (Core 0) is still 37C. [WARNING] -- 2.7.4