thermferm/rdconfig.c

changeset 714
24749c296a50
parent 708
13555c27b592
child 716
5c30c8ef83a8
--- a/thermferm/rdconfig.c	Sun Apr 28 15:50:42 2024 +0200
+++ b/thermferm/rdconfig.c	Tue Apr 30 17:26:41 2024 +0200
@@ -154,6 +154,26 @@
 	    free(simulator->uuid);
 	if (simulator->name)
 	    free(simulator->name);
+	if (simulator->room_tempaddress)
+	    free(simulator->room_tempaddress);
+	if (simulator->room_humaddress)
+	    free(simulator->room_humaddress);
+	if (simulator->air_address)
+	    free(simulator->air_address);
+	if (simulator->beer_address)
+	    free(simulator->beer_address);
+	if (simulator->beer_address2)
+	    free(simulator->beer_address2);
+	if (simulator->chiller_address)
+	    free(simulator->chiller_address);
+	if (simulator->cooler_address)
+	    free(simulator->cooler_address);
+	if (simulator->heater_address)
+	    free(simulator->heater_address);
+	if (simulator->fan_address)
+	    free(simulator->fan_address);
+	if (simulator->light_address)
+	    free(simulator->light_address);
 	free(simulator);
     }
     Config.simulators = NULL;
@@ -430,22 +450,45 @@
     	    xmlTextWriterStartElement(writer, BAD_CAST "SIMULATOR");
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", simulator->uuid);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", simulator->name);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "SIMNO", "%d", simulator->simno);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_AIR", "%d", simulator->volume_air);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_BEER", "%d", simulator->volume_beer);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_TEMPADDRESS", "%s", simulator->room_tempaddress);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_TEMPERATURE", "%.1f", simulator->room_temperature);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_HUMADDRESS", "%s", simulator->room_humaddress);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_HUMIDITY", "%.1f", simulator->room_humidity);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", simulator->air_address);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%f", simulator->air_temperature);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_PRESENT", "%s", DEVPRESENT[simulator->air_present]);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", simulator->beer_address);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%f", simulator->beer_temperature);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_PRESENT", "%s", DEVPRESENT[simulator->beer_present]);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS2", "%s", simulator->beer_address2);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE2", "%f", simulator->beer_temperature2);
+            xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_PRESENT2", "%s", DEVPRESENT[simulator->beer_present2]);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_ADDRESS", "%s", simulator->chiller_address);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_TEMPERATURE", "%f", simulator->chiller_temperature);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_PRESENT", "%s", DEVPRESENT[simulator->chiller_present]);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_ADDRESS", "%s", simulator->cooler_address);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TEMP", "%f", simulator->cooler_temp);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TIME", "%d", simulator->cooler_time);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_SIZE", "%.3f", simulator->cooler_size);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_PRESENT", "%s", DEVPRESENT[simulator->cooler_present]);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_POWER", "%d", simulator->cooler_power);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_ADDRESS", "%s", simulator->heater_address);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TEMP", "%f", simulator->heater_temp);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TIME", "%d", simulator->heater_time);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_SIZE", "%.3f", simulator->heater_size);
-	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_STATE", "%d", simulator->heater_state);
-	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_STATE", "%d", simulator->cooler_state);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_PRESENT", "%s", DEVPRESENT[simulator->heater_present]);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_POWER", "%d", simulator->heater_power);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_ADDRESS", "%s", simulator->fan_address);
+            xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_PRESENT", "%s", DEVPRESENT[simulator->fan_present]);
+            xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_POWER", "%d", simulator->fan_power);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_ADDRESS", "%s", simulator->light_address);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_PRESENT", "%s", DEVPRESENT[simulator->light_present]);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_POWER", "%d", simulator->light_power);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIGO_ISOLATION", "%.3f", simulator->frigo_isolation);
+	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "TIMESTAMP", "%ld", (long)simulator->timestamp);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_HEAT", "%f", simulator->s_yeast_heat);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_STARTED", "%d", (int)simulator->s_yeast_started);
 	    xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_COOL_TEMP", "%f", simulator->s_cool_temp);
@@ -1328,18 +1371,22 @@
 {
     xmlChar             *key;
     simulator_list      *simulator, *tmp;
-    int                 ival;
+    int                 ival, i;
     float		fval;
 
     simulator = (simulator_list *)malloc(sizeof(simulator_list));
     simulator->next = NULL;
     simulator->uuid = simulator->name = NULL;
-    simulator->volume_air = simulator->volume_beer = 0;
+    simulator->room_tempaddress = simulator->room_humaddress = simulator->air_address = simulator->beer_address = simulator->beer_address2 = NULL;
+    simulator->chiller_address = simulator->cooler_address = simulator->heater_address = simulator->fan_address = simulator->light_address = NULL;
+    simulator->simno = simulator->volume_air = simulator->volume_beer = 0;
     simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->s_cool_temp = simulator->s_heat_temp = 20.0;
     simulator->chiller_temperature = 1.5;
     simulator->room_humidity = 49.2;
     simulator->cooler_temp = simulator->cooler_size = simulator->heater_temp = simulator->heater_size = simulator->frigo_isolation = 0.0;
-    simulator->cooler_time = simulator->heater_time = simulator->cooler_state = simulator->heater_state = 0;
+    simulator->cooler_time = simulator->heater_time = 0;
+    simulator->air_present = simulator->beer_present = DEVPRESENT_YES;
+    simulator->beer_present2 = simulator->chiller_present = simulator->cooler_present = simulator->heater_present = DEVPRESENT_UNDEF;
     simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (time_t)0;
     simulator->s_yeast_heat = simulator->s_cool_temp = simulator->s_heat_temp = 0.0;
 
@@ -1351,6 +1398,12 @@
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
 	    simulator->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"SIMNO"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            if (sscanf((const char *)key, "%d", &ival) == 1)
+                simulator->simno = ival;
+            xmlFree(key);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"VOLUME_AIR"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%d", &ival) == 1)
@@ -1363,36 +1416,103 @@
 		simulator->volume_beer = ival;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_TEMPADDRESS"))) {
+            simulator->room_tempaddress = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_TEMPERATURE"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
 		simulator->room_temperature = fval;
 	    xmlFree(key);
 	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_GUMIDITY"))) {
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_HUMADDRESS"))) {
+            simulator->room_humaddress = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_HUMIDITY"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
 		simulator->room_humidity= fval;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_ADDRESS"))) {
+            simulator->air_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_TEMPERATURE"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
 		simulator->air_temperature = fval;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_PRESENT"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->air_present = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_ADDRESS"))) {
+            simulator->beer_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_TEMPERATURE"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
 		simulator->beer_temperature = fval;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_PRESENT"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->beer_present = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_ADDRESS2"))) {
+            simulator->beer_address2 = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_TEMPERATURE2"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            if (sscanf((const char *)key, "%f", &fval) == 1)
+                simulator->beer_temperature2 = fval;
+            xmlFree(key);
+        }
+        if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_PRESENT2"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->beer_present2 = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"CHILLER_ADDRESS"))) {
+            simulator->chiller_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"CHILLER_TEMPERATURE"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
 		simulator->chiller_temperature = fval;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"CHILLER_PRESENT"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->chiller_present = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_ADDRESS"))) {
+            simulator->cooler_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_TEMP"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
@@ -1411,6 +1531,25 @@
 		simulator->cooler_size = fval;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_PRESENT"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->cooler_present = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_POWER"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            if (sscanf((const char *)key, "%d", &ival) == 1)
+                simulator->cooler_power = ival;
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_ADDRESS"))) {
+            simulator->heater_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_TEMP"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
@@ -1429,24 +1568,72 @@
 		simulator->heater_size = fval;
 	    xmlFree(key);
 	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_STATE"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		simulator->heater_state = ival;
-	    xmlFree(key);
-	}
-	if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_STATE"))) {
-	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
-	    if (sscanf((const char *)key, "%d", &ival) == 1)
-		simulator->cooler_state = ival;
-	    xmlFree(key);
-	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_PRESENT"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->heater_present = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_POWER"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            if (sscanf((const char *)key, "%d", &ival) == 1)
+                simulator->heater_power = ival;
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_ADDRESS"))) {
+            simulator->fan_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_PRESENT"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->fan_present = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+        }
+        if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_POWER"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            if (sscanf((const char *)key, "%d", &ival) == 1)
+                simulator->fan_power = ival;
+            xmlFree(key);
+        }
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_ADDRESS"))) {
+            simulator->light_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+        }
+        if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_PRESENT"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            for (i = 0; i < 4; i++) {
+                if (! xmlStrcmp(key, (const xmlChar *)DEVPRESENT[i])) {
+                    simulator->light_present = i;
+                    break;
+                }
+            }
+            xmlFree(key);
+        }
+        if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_POWER"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            if (sscanf((const char *)key, "%d", &ival) == 1)
+                simulator->light_power = ival;
+            xmlFree(key);
+        }
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"FRIGO_ISOLATION"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    if (sscanf((const char *)key, "%f", &fval) == 1)
 		simulator->frigo_isolation = fval;
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIMESTAMP"))) {
+            key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+            if (sscanf((const char *)key, "%d", &ival) == 1)
+                simulator->timestamp = ival;
+            xmlFree(key);
+        }
 
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_YEAST_HEAT"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);

mercurial