thermferm/rdconfig.c

changeset 76
d2c7b32f27d6
parent 75
4b976601737d
child 77
143077e54255
--- a/thermferm/rdconfig.c	Tue Jun 24 22:38:46 2014 +0200
+++ b/thermferm/rdconfig.c	Wed Jun 25 16:16:47 2014 +0200
@@ -31,6 +31,7 @@
 
 #define MY_ENCODING "utf-8"
 
+const char      UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" };
 
 //static int getstr(char **);
 static int getw1(char **);
@@ -145,32 +146,6 @@
     }
     fprintf(fp, "\n");
 
-    fprintf(fp, "# Fermenter Units.\n");
-    fprintf(fp, "#\n");
-    for (tmp3 = Config.units; tmp3; tmp3 = tmp3->next) {
-	fprintf(fp, "unit_uid	%s\n", tmp3->uid);
-	if (tmp3->name)
-	    fprintf(fp, "unit_name	%s\n", tmp3->name);
-	if (tmp3->volume > 0.0)
-	    fprintf(fp, "unit_volume	%.1f\n", tmp3->volume);
-	if (tmp3->air_address)
-	    fprintf(fp, "unit_air_address	%s\n", tmp3->air_address);
-	if (tmp3->beer_address)
-	    fprintf(fp, "unit_beer_address	%s\n", tmp3->beer_address);
-	if (tmp3->io_address)
-	    fprintf(fp, "unit_io_address	%s\n", tmp3->io_address);
-	fprintf(fp, "unit_heater_available	%s\n", tmp3->heater_available ? "yes":"no");
-	fprintf(fp, "unit_cooler_available	%s\n", tmp3->cooler_available ? "yes":"no");
-	fprintf(fp, "unit_fan_available	%s\n", tmp3->fan_available ? "yes":"no");
-	fprintf(fp, "unit_light_available	%s\n", tmp3->light_available ? "yes":"no");
-	fprintf(fp, "unit_mode	%d\n", tmp3->mode);
-	if (tmp3->profile) {
-	    fprintf(fp, "unit_profile	%s\n", tmp3->profile);
-	    fprintf(fp, "unit_prof_started	%d\n", (int)tmp3->prof_started);
-	}
-    }
-    fprintf(fp, "\n");
-
     fprintf(fp, "# Control Settings.\n");
     fprintf(fp, "#\n");
     fprintf(fp, "cs_mode			%c\n", Config.cs_mode);
@@ -260,6 +235,10 @@
 	syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
 	return 1;
     }
+    /*
+     * Start one LCD. It is possible to connect 7 LCD displays on the i2c bus.
+     * However this program doesn't use more then one yet.
+     */
     if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCD")) < 0) {
 	syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
 	return 1;
@@ -301,6 +280,10 @@
 	    return 1;
 	}
 	for (tmp3 = Config.units; tmp3; tmp3 = tmp3->next) {
+	    /*
+	     * Only configuration items are written, measured values and states
+	     * are written to a state file.
+	     */
 	    if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "UNIT")) < 0) {
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
 		return 1;
@@ -309,7 +292,88 @@
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
 		return 1;
 	    }
-
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", MBSE_SS(Config.units->name))) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", Config.units->volume)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", MBSE_SS(Config.units->air_address))) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", MBSE_SS(Config.units->beer_address))) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO1_ADDRESS", "%s", MBSE_SS(Config.units->io1_address))) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO2_ADDRESS", "%s", MBSE_SS(Config.units->io2_address))) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER", "%s", Config.units->heater_available ? "YES":"NO")) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;                           
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER", "%s", Config.units->cooler_available? "YES":"NO")) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN", "%s", Config.units->fan_available ? "YES":"NO")) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[Config.units->mode] )) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", Config.units->beer_set)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_SET", "%.1f", Config.units->fridge_set)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MIN", "%.1f", Config.units->temp_set_min)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MAX", "%.1f", Config.units->temp_set_max)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_L", "%.1f", Config.units->idle_rangeL)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_H", "%.1f", Config.units->idle_rangeH)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if (Config.units->profile) {
+		if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE", "%s", Config.units->profile)) < 0) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
+		if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%d", (unsigned int)Config.units->prof_started)) < 0) {
+		    syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		    return 1;
+		}
+	    }
 	    if ((rc = xmlTextWriterEndElement(writer)) < 0) {
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
 		return 1;

mercurial