thermferm/server.c

changeset 518
fd36bedab944
parent 513
a2732027afb3
child 520
32bf084df5af
--- a/thermferm/server.c	Mon Jun 26 13:58:11 2017 +0200
+++ b/thermferm/server.c	Mon Jun 26 19:21:07 2017 +0200
@@ -1864,6 +1864,9 @@
 		if (current->beer_address)
 		    free(current->beer_address);
 		current->beer_address = NULL;
+		if (current->chiller_address)
+		    free(current->chiller_address);
+		current->chiller_address = NULL;
 		if (current->heater_address)
 		    free(current->heater_address);
 		current->heater_address = NULL;
@@ -1904,6 +1907,9 @@
 		if (current->beer_address)
 		    free(current->beer_address);
 		current->beer_address = NULL;
+		if (current->chiller_address)
+		    free(current->chiller_address);
+		current->chiller_address = NULL;
 		if (current->heater_address)
 		    free(current->heater_address);
 		current->heater_address = NULL;
@@ -2009,14 +2015,14 @@
 	uuid_unparse(uu, unit->uuid);
 	unit->name = xstrcpy(param);
 	unit->alias = xstrcpy(an);
-	unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \
+	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->air_idx = unit->beer_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \
+	unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \
 			unit->door_idx = unit->light_idx = unit->psu_idx = 0;
 	unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
-	unit->air_state = unit->beer_state = 1;
-	unit->air_temperature = unit->beer_temperature = 20000;
+	unit->air_state = unit->beer_state = unit->chiller_state = 1;
+	unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = 20000;
 	unit->beer_set = unit->fridge_set = 20.0;
 	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = \
 			     unit->light_state = unit->psu_state = unit->prof_state = 0;
@@ -2102,6 +2108,10 @@
 		srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]);
 		srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0);
 		srv_send((char *)"BEER_IDX,%d", unit->beer_idx);
+		srv_send((char *)"CHILLER_ADDRESS,%s", MBSE_SS(unit->chiller_address));
+		srv_send((char *)"CHILLER_STATE,%s", TEMPSTATE[unit->chiller_state]);
+		srv_send((char *)"CHILLER_TEMPERATURE,%.3f", unit->chiller_temperature / 1000.0);
+		srv_send((char *)"CHILLER_IDX,%d", unit->chiller_idx);
 		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);
@@ -2264,6 +2274,27 @@
 				    unit->beer_idx = ival;
 				}
 
+			    } else if (strcmp(kwd, (char *)"CHILLER_ADDRESS") == 0) {
+				if (val && unit->chiller_address && (strcmp(val, unit->chiller_address)))
+				    syslog(LOG_NOTICE, "Fermenter unit %s chiller address `%s' to `%s'", unit->uuid, unit->chiller_address, val);
+				if (unit->chiller_address) {
+				    device_count(FALSE, unit->chiller_address);
+				    free(unit->chiller_address);
+				}
+				if (val) {
+				    unit->chiller_address = xstrcpy(val);
+				    device_count(TRUE, unit->chiller_address);
+				} else
+				    unit->chiller_address = NULL;
+				unit->mqtt_flag |= MQTT_FLAG_DATA;
+
+			    } else if (val && (strcmp(kwd, (char *)"CHILLER_IDX") == 0)) {
+				if (sscanf(val, "%d", &ival) == 1) {
+				    if (unit->chiller_idx != ival)
+					syslog(LOG_NOTICE, "Fermenter unit %s chiller idx %d to %d", unit->uuid, unit->chiller_idx, ival);
+				    unit->beer_idx = ival;
+				}
+
 			    } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) {
 				if (val && unit->heater_address && (strcmp(val, unit->heater_address)))
 				    syslog(LOG_NOTICE, "Fermenter unit %s heater address `%s' to `%s'", unit->uuid, unit->heater_address, val);

mercurial