# HG changeset patch # User Michiel Broek # Date 1405197149 -7200 # Node ID 5e538c4e1ecbdfa850f9fbf17d79aa412dbe2925 # Parent 99c47a8a61cb386fa1c4d78a700220bb70023f65 Added units logging diff -r 99c47a8a61cb -r 5e538c4e1ecb thermferm/logger.c --- a/thermferm/logger.c Sat Jul 12 21:59:19 2014 +0200 +++ b/thermferm/logger.c Sat Jul 12 22:32:29 2014 +0200 @@ -23,7 +23,7 @@ #include "thermferm.h" -void logger(char *filename, char *progname, char *data) +void logger(char *filename, char *data) { struct timeval now; struct tm ptm; @@ -35,9 +35,7 @@ } else { name = xstrcpy(getenv((char *)"HOME")); } - name = xstrcat(name, (char *)"/."); - name = xstrcat(name, progname); - name = xstrcat(name, (char *)"/log/"); + name = xstrcat(name, (char *)"/.thermferm/log/"); mkdirs(name, 0755); name = xstrcat(name, filename); diff -r 99c47a8a61cb -r 5e538c4e1ecb thermferm/thermferm.c --- a/thermferm/thermferm.c Sat Jul 12 21:59:19 2014 +0200 +++ b/thermferm/thermferm.c Sat Jul 12 22:32:29 2014 +0200 @@ -43,6 +43,8 @@ #ifndef HAVE_WIRINGPI_H pthread_t threads[3]; #endif +extern const char UNITMODE[5][8]; + int server(void); void help(void); @@ -226,10 +228,11 @@ int server(void) { - char buf[1024]; + char buf[1024], *filename; time_t now, last = (time_t)0; w1_therm *tmp1; - int rc, run = 1, temp; + units_list *unit; + int rc, run = 1, temp, seconds = 0; #ifndef HAVE_WIRINGPI_H long t = 0; #endif @@ -282,7 +285,18 @@ } snprintf(buf, 1023, "tempA,tempB"); - logger((char *)"thermferm.log", (char *)"thermferm", buf); + logger((char *)"thermferm.log", buf); + + for (unit = Config.units; unit; unit = unit->next) { + if (unit->mode != UNITMODE_OFF) { + snprintf(buf, 1023, "Mode,Air,Beer,Target,Heater,Cooler,Fan,Door"); + filename = xstrcpy(unit->name); + filename = xstrcat(filename, (char *)".log"); + logger(filename, buf); + free(filename); + filename = NULL; + } + } do { lcdupdate = FALSE; @@ -311,17 +325,38 @@ } #endif + /* + * Timed schedulers + */ now = time(NULL); - if (((int)now - (int)last) > 60) { + if (now != last) { last = now; - if (Config.w1therms) { - tmp1 = Config.w1therms; - temp = tmp1->lastval; - tmp1 = tmp1->next; - if (temp && tmp1->lastval && run) { - snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0); - logger((char *)"thermferm.log", (char *)"thermferm", buf); + seconds++; + + if (seconds == 60) { + seconds = 0; + + if (Config.w1therms) { + tmp1 = Config.w1therms; + temp = tmp1->lastval; + tmp1 = tmp1->next; + if (temp && tmp1->lastval && run) { + snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0); + logger((char *)"thermferm.log", buf); + } } + + for (unit = Config.units; unit; unit = unit->next) { + if (unit->mode != UNITMODE_OFF) { + snprintf(buf, 1023, "%s,%.3f,%.3f,Target,Heater,Cooler,Fan,Door", + UNITMODE[unit->mode], unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0); + filename = xstrcpy(unit->name); + filename = xstrcat(filename, (char *)".log"); + logger(filename, buf); + free(filename); + filename = NULL; + } + } } } usleep(100000); diff -r 99c47a8a61cb -r 5e538c4e1ecb thermferm/thermferm.h --- a/thermferm/thermferm.h Sat Jul 12 21:59:19 2014 +0200 +++ b/thermferm/thermferm.h Sat Jul 12 22:32:29 2014 +0200 @@ -207,7 +207,7 @@ #endif /* logger.c */ -void logger(char *, char *, char *); +void logger(char *, char *); #ifdef HAVE_WIRINGPI_H PI_THREAD (my_sensors_loop);