thermferm/rdconfig.c

changeset 306
97602274eb58
parent 293
881b1ae75468
child 310
53774295e14a
--- a/thermferm/rdconfig.c	Wed Jan 14 13:20:16 2015 +0100
+++ b/thermferm/rdconfig.c	Sat Feb 07 23:12:55 2015 +0100
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * Copyright (C) 2014
+ * Copyright (C) 2014-2015
  *   
  * Michiel Broek <mbroek at mbse dot eu>
  *
@@ -80,8 +80,12 @@
 	    free(tmp2->cooler_address);
 	if (tmp2->fan_address)
 	    free(tmp2->fan_address);
+	if (tmp2->light_address)
+	    free(tmp2->light_address);
 	if (tmp2->door_address)
 	    free(tmp2->door_address);
+	if (tmp2->psu_address)
+	    free(tmp2->psu_address);
 	if (tmp2->profile)
 	    free(tmp2->profile);
 	free(tmp2);
@@ -399,6 +403,24 @@
 		    return 1;
 		}
 	    }
+	    if (tmp3->light_address) {
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_ADDRESS", "%s", tmp3->light_address)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_STATE", "%d", tmp3->light_state)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_DELAY", "%d", tmp3->light_delay)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_USAGE", "%d", tmp3->light_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)) {
 		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
@@ -409,6 +431,16 @@
 		return 1;
 		}
 	    }
+	    if (tmp3->psu_address) {
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_ADDRESS", "%s", tmp3->psu_address)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
+		if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_STATE", "%d", tmp3->psu_state)) < 0)) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
+	    }
 	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[tmp3->mode] )) < 0) {
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		return 1;
@@ -872,14 +904,17 @@
     unit->next = NULL;
     unit->version = 1;
     unit->uuid = unit->name = unit->air_address = unit->beer_address = unit->heater_address = \
-		 unit->cooler_address = unit->fan_address = unit->door_address = unit->profile = NULL;
+		 unit->cooler_address = unit->fan_address = unit->door_address = \
+		 unit->light_address = unit->psu_address = unit->profile = NULL;
     unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
     unit->air_temperature = unit->beer_temperature = unit->beer_set = unit->fridge_set = 20.0;
     unit->air_state = unit->beer_state = 1; // missing
-    unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0;
+    unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \
+			 unit->light_state = unit->psu_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->light_delay = 1;						/* 15 seconds delay	*/
+    unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
+    unit->heater_usage = unit->cooler_usage = unit->fan_usage = unit->light_usage = 0;
     unit->temp_set_min = 1.0;
     unit->temp_set_max = 30.0;
     unit->idle_rangeH = 1.0;
@@ -986,9 +1021,27 @@
 		unit->fan_usage = ival;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_ADDRESS"))) {
+	    unit->light_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_DELAY"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (sscanf((const char *)key, "%d", &ival) == 1)
+		unit->light_delay = ival;
+	    xmlFree(key);
+	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_USAGE"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (sscanf((const char *)key, "%d", &ival) == 1)
+		unit->light_usage = ival;
+	    xmlFree(key);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"DOOR_ADDRESS"))) {
 	    unit->door_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PSU_ADDRESS"))) {
+	    unit->psu_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"MODE"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    for (i = 0; i < 5; i++) {

mercurial