thermferm/rdconfig.c

changeset 554
ab9f22ab57b5
parent 553
4091d4fe217f
child 561
fcfc3dbe85fa
--- a/thermferm/rdconfig.c	Wed Jul 25 20:08:13 2018 +0200
+++ b/thermferm/rdconfig.c	Tue Jul 31 16:42:11 2018 +0200
@@ -82,8 +82,12 @@
     for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) {
 	if (tmp2->uuid)
 	    free(tmp2->uuid);
-	if (tmp2->name)
-	    free(tmp2->name);
+	if (tmp2->product_uuid)
+	    free(tmp2->product_uuid);
+	if (tmp2->product_code)
+	    free(tmp2->product_code);
+	if (tmp2->product_name)
+	    free(tmp2->product_name);
 	if (tmp2->air_address)
 	    free(tmp2->air_address);
 	if (tmp2->beer_address)
@@ -356,7 +360,15 @@
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		return 1;
 	    }
-	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", tmp3->name)) < 0) {
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_UUID", "%s", tmp3->product_uuid)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_CODE", "%s", tmp3->product_code)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+		return 1;
+	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_NAME", "%s", tmp3->product_name)) < 0) {
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		return 1;
 	    }
@@ -1116,7 +1128,8 @@
     unit = (units_list *)malloc(sizeof(units_list));
     unit->next = NULL;
     unit->version = 1;
-    unit->uuid = unit->name = unit->alias = unit->air_address = unit->beer_address = unit->chiller_address = unit->heater_address = \
+    unit->uuid = unit->product_uuid = unit->product_code = unit->product_name = unit->event_msg = \
+		 unit->alias = unit->air_address = unit->beer_address = unit->chiller_address = unit->heater_address = \
 		 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;
@@ -1154,7 +1167,26 @@
 	    unit->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
-	    unit->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    /*
+	     * Upgrade to product code and name
+	     */
+	    char  *oldname =  (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (strstr(oldname, (char *)" ")) {
+		unit->product_code = xstrcpy(strtok(oldname, " "));
+		unit->product_name = xstrcpy(strtok(NULL, "\0"));
+	    } else {
+		unit->product_code = xstrcpy((char *)"000000");
+		unit->product_name = xstrcpy(oldname);
+	    }
+	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_UUID"))) {
+	    unit->product_uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_CODE"))) {
+	    unit->product_code = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_NAME"))) {
+	    unit->product_name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"ALIAS"))) {
 	    unit->alias = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);

mercurial