Removed old brewPi settings

Mon, 07 Jul 2014 22:31:07 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 07 Jul 2014 22:31:07 +0200
changeset 95
2c28afc329a5
parent 94
38ee038f4cec
child 96
d08bf980ff28

Removed old brewPi settings

thermferm/rdconfig.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/thermferm/rdconfig.c	Mon Jul 07 21:15:44 2014 +0200
+++ b/thermferm/rdconfig.c	Mon Jul 07 22:31:07 2014 +0200
@@ -30,6 +30,7 @@
 #define MY_ENCODING "utf-8"
 
 const char      UNITMODE[5][8]	= { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" };
+const char	UNITmode[5]  = { 'o', 'n', 'f', 'b', 'p' };
 const char	PROFSTATE[4][6]	= { "OFF", "PAUSE", "RUN", "DONE" };
 
 
@@ -58,6 +59,9 @@
     Config.w1therms = NULL;
     Config.my_port = 6554;
     Config.tempFormat = 'C';
+    if (Config.air_address)
+	free(Config.air_address);
+    Config.air_address = NULL;
 
     for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) {
 	if (tmp2->uuid)
@@ -96,9 +100,6 @@
     Config.lcd_cols = 16;
     Config.lcd_rows = 2;
 #endif
-
-    defaultControlSettings();
-    defaultControlConstants();
 }
 
 
@@ -172,6 +173,10 @@
 	syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 	return 1;
     }
+    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", Config.air_address)) < 0) {
+	syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
+	return 1;
+    }
 
 #ifdef HAVE_WIRINGPI_H
     /* 
@@ -1000,6 +1005,9 @@
 	    Config.tempFormat = key[0];
 	    xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_ADDRESS"))) {
+	    Config.air_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	}
 #ifdef HAVE_WIRINGPI_H
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) {
 	    parseLCDs(doc, cur);
--- a/thermferm/server.c	Mon Jul 07 21:15:44 2014 +0200
+++ b/thermferm/server.c	Mon Jul 07 22:31:07 2014 +0200
@@ -32,6 +32,7 @@
 #endif
 extern sys_config       Config;
 extern const char	UNITMODE[5][8];
+extern const char	UNITmode[5];
 
 int			s;		/* connected socket			*/
 int			ls;		/* listen socket			*/
@@ -45,32 +46,12 @@
 #define SS_TIMEOUT      300
 
 
+float			cs_heatEstimator = 0.2;
+float			cs_coolEstimator = 5;
 float			cv_beerDiff = 0.0;
 
 
 
-void defaultControlSettings(void)
-{
-	Config.cs_mode = 'o';		/* o = Off, f = fridge, b = beer, p = profile-run */
-	Config.cs_beerSet = 20.0;
-	Config.cs_fridgeSet = 20.0;
-	Config.cs_heatEstimator = 0.2;
-	Config.cs_coolEstimator = 5;
-}
-
-
-
-void defaultControlConstants(void)
-{
-	Config.tempFormat = 'C';
-	Config.cc_tempSetMin = 1.0;
-	Config.cc_tempSetMax = 30.0;
-	Config.cc_idleRangeH = 1.000;
-	Config.cc_idleRangeL = -1.000;
-}
-
-
-
 /*
  * Send message to client
  */
@@ -636,6 +617,10 @@
 		    wrconfig();
 	    } else if (strncmp(buf, "UNIT", 4) == 0) {
 		cmd_unit(buf);
+
+	    /*
+	     * Now the old style (brewPi) commands. These will go away.
+	     */
 	    } else if (strncmp(buf, "ack", 3) == 0) {
 		srv_send((char *)"ack");
 	    } else if (strncmp(buf, "lcd", 3) == 0) {
@@ -650,24 +635,24 @@
 #endif
 		srv_send(obuf);
 	    } else if (strncmp(buf, "getMode", 7) == 0) {
-		srv_send("%c", Config.cs_mode);
+		srv_send("%c", UNITmode[Config.units->mode]);
 	    } else if (strncmp(buf, "getFridge", 9) == 0) {
-		srv_send("%.1f", Config.cs_fridgeSet);
+		srv_send("%.1f", Config.units->fridge_set);
 	    } else if (strncmp(buf, "getBeer", 7) == 0) {
-		srv_send("%.1f", Config.cs_beerSet);
+		srv_send("%.1f", Config.units->beer_set);
 	    } else if (strncmp(buf, "getControlConstants", 19) == 0) {
 		srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", 
-			Config.tempFormat, Config.cc_tempSetMin, Config.cc_tempSetMax, Config.cc_idleRangeH, Config.cc_idleRangeL );
+			Config.tempFormat, Config.units->temp_set_min, Config.units->temp_set_max, Config.units->idle_rangeH, Config.units->idle_rangeL);
 	    } else if (strncmp(buf, "getControlSettings", 18) == 0) {
 		srv_send("{ \"mode\":\"%c\", \"beerSet\":%.1f, \"fridgeSet\":%.1f, \"heatEstimator\":%.1f, \"coolEstimator\":%.1f }", 
-			Config.cs_mode, Config.cs_beerSet, Config.cs_fridgeSet, Config.cs_heatEstimator, Config.cs_coolEstimator);
+			UNITmode[Config.units->mode], Config.units->beer_set, Config.units->fridge_set, cs_heatEstimator, cs_coolEstimator);
 	    } else if (strncmp(buf, "getControlVariables", 19) == 0) {
 		srv_send("{ \"beerDiff\":%.2f }", cv_beerDiff);
 	    } else if (strncmp(buf, "loadDefaultControlSettings", 26) == 0) {
-		defaultControlSettings();
+		// Does nothing anymore
 		srv_send("ack");
 	    } else if (strncmp(buf, "loadDefaultControlConstants", 27) == 0) {
-		defaultControlConstants();
+		// Does nothing anymore
 		srv_send("ack");
 	    } else if (strncmp(buf, "setBeer=", 8) == 0) {
 		inp = xstrcpy(buf+8);
@@ -675,13 +660,13 @@
 		if (debug)
 		    fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc);
 		if (rc == 1) {
-		    if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) {
+		    if ((Config.units->temp_set_min <= newtemp) && (newtemp <= Config.units->temp_set_max)) {
 		    	syslog(LOG_NOTICE, "Beer temperature set to %.1f degrees in web interface", newtemp);
 		    	srv_send("ack");
-		    	Config.cs_mode = 'b';
-		    	Config.cs_beerSet = newtemp;
+		    	Config.units->mode = UNITMODE_BEER;
+		    	Config.units->beer_set = newtemp;
 		    } else {
-			syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax);
+			syslog(LOG_NOTICE, "Beer temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.units->temp_set_min, Config.units->temp_set_max);
 			srv_send("err");
 		    }
 		} else {
@@ -695,13 +680,13 @@
 		if (debug)
 		    fprintf(stdout, "new temp from %s, %.1f, rc=%d\n", inp, newtemp, rc);
 		if (rc == 1) {
-		    if ((Config.cc_tempSetMin <= newtemp) && (newtemp <= Config.cc_tempSetMax)) {
+		    if ((Config.units->temp_set_min <= newtemp) && (newtemp <= Config.units->temp_set_max)) {
 			syslog(LOG_NOTICE, "Fridge temperature set to %.1f degrees in web interface", newtemp);
 		    	srv_send("ack");
-		    	Config.cs_mode = 'f';
-		    	Config.cs_fridgeSet = newtemp;
+		    	Config.units->mode = UNITMODE_FRIDGE;
+		    	Config.units->fridge_set = newtemp;
 		    } else {
-			syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.cc_tempSetMin, Config.cc_tempSetMax);
+			syslog(LOG_NOTICE, "Fridge temperature setting %.1f is outside of allowed range %.1f - %.1f", newtemp, Config.units->temp_set_min, Config.units->temp_set_max);
 			srv_send("err");
 		    }
 		} else {
@@ -713,7 +698,7 @@
 		if (debug)
 		    fprintf(stdout, "temperature control disabled\n");
 		syslog(LOG_NOTICE, "Notification: Temperature control disabled");
-		Config.cs_mode = 'o';
+		Config.units->mode = UNITMODE_OFF;
 		srv_send("ack");
 	    } else if (strncmp(buf, "setParameters=", 14) == 0) {
 		inp = xstrcpy(buf+14); /* {"tempSetMax":30.5} */
@@ -726,7 +711,7 @@
 		    rc = sscanf(q, "%f", &newtemp);
 		    if (rc == 1) {
 			syslog(LOG_NOTICE, "cc_tempSetMin = %1.f", newtemp);
-			Config.cc_tempSetMin = newtemp;
+			Config.units->temp_set_min = newtemp;
 			srv_send("ack");
 		    } else {
 			srv_send("ERR");
@@ -735,7 +720,7 @@
 		    rc = sscanf(q, "%f", &newtemp);
 		    if (rc == 1) {
 			syslog(LOG_NOTICE, "cc_tempSetMax = %1.f", newtemp);
-			Config.cc_tempSetMax = newtemp;
+			Config.units->temp_set_max = newtemp;
 			srv_send("ack");
 		    } else {
 			srv_send("ERR");
@@ -768,11 +753,6 @@
 	}
     }
 
-//    if (debug) {
-//    	syslog(LOG_NOTICE, "End connection from %s port %u", hostname, ntohs(peeraddr_in.sin_port));
-//	fprintf(stdout, "End connection from %s port %u\n", hostname, ntohs(peeraddr_in.sin_port));
-//    }
-
     close(s);
 }
 
--- a/thermferm/thermferm.h	Mon Jul 07 21:15:44 2014 +0200
+++ b/thermferm/thermferm.h	Mon Jul 07 22:31:07 2014 +0200
@@ -156,17 +156,6 @@
 #endif
     units_list		*units;			/* Fermenter units		*/
     profiles_list	*profiles;		/* Ferment profiles		*/
-    						/* ControlSettings:		*/
-    unsigned char	cs_mode;		/* mode				*/
-    float		cs_beerSet;		/* beer temperature		*/
-    float		cs_fridgeSet;		/* fridge temperature		*/
-    float		cs_heatEstimator;
-    float		cs_coolEstimator;
-    						/* ControlConstants		*/
-    float		cc_tempSetMin;
-    float		cc_tempSetMax;
-    float		cc_idleRangeH;
-    float		cc_idleRangeL;
 } sys_config;
 
 
@@ -223,8 +212,6 @@
 #endif
 
 /* server.c */
-void defaultControlSettings(void);
-void defaultControlConstants(void);
 #ifdef HAVE_WIRINGPI_H
 PI_THREAD (my_server_loop);
 #else

mercurial