X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fslog.c;h=aed2a5b20313c98532e4521ff4154e31521da902;hb=622e9d900e6c1ae9d90896d197360db3a06eb291;hp=f1b2f5bd8d8ff9654912a530d8f98dbabb4c7a3a;hpb=fb3b77c1b0f2a1d461b18580497c1ab4a6d6616c;p=psensor.git 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; + } }