Added usage counters

Wed, 29 Oct 2014 20:27:37 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 29 Oct 2014 20:27:37 +0100
changeset 293
881b1ae75468
parent 292
138d5e15be01
child 294
e07b08283d96

Added usage counters

thermferm/rdconfig.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/thermferm/rdconfig.c	Wed Oct 29 14:41:00 2014 +0100
+++ b/thermferm/rdconfig.c	Wed Oct 29 20:27:37 2014 +0100
@@ -358,6 +358,10 @@
 		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		    return 1;
 		}
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_USAGE", "%d", tmp3->heater_usage)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
 	    }
 	    if (tmp3->cooler_address) {
 		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_ADDRESS", "%s", tmp3->cooler_address)) < 0)) {
@@ -372,6 +376,10 @@
 		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		    return 1;
 		}
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_USAGE", "%d", tmp3->cooler_usage)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
 	    }
 	    if (tmp3->fan_address) {
 		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_ADDRESS", "%s", tmp3->fan_address)) < 0)) {
@@ -386,6 +394,10 @@
 		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		    return 1;
 		}
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_USAGE", "%d", tmp3->fan_usage)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
 	    }
 	    if (tmp3->door_address) {
 		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_ADDRESS", "%s", tmp3->door_address)) < 0)) {
@@ -867,6 +879,7 @@
     unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0;
     unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20;	/* 5 minutes delay */
     unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0;
+    unit->heater_usage = unit->cooler_usage = unit->fan_usage = 0;
     unit->temp_set_min = 1.0;
     unit->temp_set_max = 30.0;
     unit->idle_rangeH = 1.0;
@@ -937,6 +950,12 @@
 		unit->heater_delay = ival;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_USAGE"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (sscanf((const char *)key, "%d", &ival) == 1)
+		unit->heater_usage = ival;
+	    xmlFree(key);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_ADDRESS"))) {
 	    unit->cooler_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
@@ -946,6 +965,12 @@
 		unit->cooler_delay = ival;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_USAGE"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (sscanf((const char *)key, "%d", &ival) == 1)
+		unit->cooler_usage = ival;
+	    xmlFree(key);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_ADDRESS"))) {
 	    unit->fan_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
@@ -955,6 +980,12 @@
 		unit->fan_delay = ival;
 	    xmlFree(key);                           
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_USAGE"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (sscanf((const char *)key, "%d", &ival) == 1)
+		unit->fan_usage = ival;
+	    xmlFree(key);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"DOOR_ADDRESS"))) {
 	    unit->door_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
--- a/thermferm/server.c	Wed Oct 29 14:41:00 2014 +0100
+++ b/thermferm/server.c	Wed Oct 29 20:27:37 2014 +0100
@@ -1454,6 +1454,7 @@
 	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0;
 	unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20;     /* 5 minutes delay */
 	unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0;
+	unit->heater_usage = unit->cooler_usage = unit->fan_usage = 0;
 	unit->temp_set_min = 1.0;
 	unit->temp_set_max = 30.0;
 	unit->idle_rangeH = 1.0;
@@ -1535,12 +1536,15 @@
 		srv_send((char *)"HEATER_ADDRESS,%s", unit->heater_address);
 		srv_send((char *)"HEATER_STATE,%d", unit->heater_state);
 		srv_send((char *)"HEATER_DELAY,%d", unit->heater_delay);
+		srv_send((char *)"HEATER_USAGE,%d", unit->heater_usage);
 		srv_send((char *)"COOLER_ADDRESS,%s", unit->cooler_address);
 		srv_send((char *)"COOLER_STATE,%d", unit->cooler_state);
 		srv_send((char *)"COOLER_DELAY,%d", unit->cooler_delay);
+		srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage);
 		srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address);
 		srv_send((char *)"FAN_STATE,%d", unit->fan_state);
 		srv_send((char *)"FAN_DELAY,%d", unit->fan_delay);
+		srv_send((char *)"FAN_USAGE,%d", unit->fan_usage);
 		srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address);
 		srv_send((char *)"DOOR_STATE,%d", unit->door_state);
 		srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
--- a/thermferm/thermferm.c	Wed Oct 29 14:41:00 2014 +0100
+++ b/thermferm/thermferm.c	Wed Oct 29 20:27:37 2014 +0100
@@ -1252,6 +1252,17 @@
 		    device_out(unit->cooler_address, unit->cooler_state);
 		    device_out(unit->fan_address, unit->fan_state);
 		}
+
+		/*
+		 * Usage counters
+		 */
+		if (unit->heater_address && unit->heater_state)
+		    unit->heater_usage++;
+		if (unit->cooler_address && unit->cooler_state)
+		    unit->cooler_usage++;
+		if (unit->fan_address && unit->fan_state)
+		    unit->fan_usage++;
+
 #ifdef HAVE_WIRINGPI_H
 		if (unit->heater_address && unit->cooler_address) {
 		    piLock(LOCK_LCD);
@@ -1469,8 +1480,15 @@
 		}
 
 		minutes++;
-		if (minutes == 60)
+		if (minutes == 60) {
 		    minutes = 0;
+		    /*
+		     * Log usage counters every hour
+		     */
+		    for (unit = Config.units; unit; unit = unit->next) {
+		    	syslog(LOG_NOTICE, "Unit `%s' usage heater=%d cooler=%d fan=%d", unit->name, unit->heater_usage, unit->cooler_usage, unit->fan_usage);
+		    }
+		}
 
 		/*
 		 * Save the configuration each half hour.
--- a/thermferm/thermferm.h	Wed Oct 29 14:41:00 2014 +0100
+++ b/thermferm/thermferm.h	Wed Oct 29 20:27:37 2014 +0100
@@ -116,14 +116,17 @@
     int			heater_state;		/* Heater state 0..100		*/
     int			heater_delay;		/* Heater delay time /15 sec	*/
     int			heater_wait;		/* Heater wait counter		*/
+    int			heater_usage;		/* Heater usage in seconds	*/
     char		*cooler_address;	/* Cooler relay or PWM		*/
     int			cooler_state;		/* Cooler state 0..100		*/
     int			cooler_delay;		/* Cooler delay time /15 sec	*/
     int			cooler_wait;		/* Cooler wait counter		*/
+    int			cooler_usage;		/* Cooler usage in seconds	*/
     char		*fan_address;		/* Fan relay or PWM 		*/
     int			fan_state;		/* Fan state 0..100		*/
     int			fan_delay;		/* Fan delay time /15 sec	*/
     int			fan_wait;		/* Fan wait counter		*/
+    int			fan_usage;		/* Fan usage in seconds		*/
     char		*door_address;		/* Door input address		*/
     int			door_state;		/* Door and light status	*/
     int			mode;			/* Unit mode			*/

mercurial