--- 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); }