# HG changeset patch # User Michiel Broek # Date 1403708169 -7200 # Node ID 143077e54255ba9c9d825d57b733845ce6d0c01a # Parent d2c7b32f27d644c3a31c28faaa7438b731c72aa7 Added old configuration to write xml config diff -r d2c7b32f27d6 -r 143077e54255 thermferm/rdconfig.c --- a/thermferm/rdconfig.c Wed Jun 25 16:16:47 2014 +0200 +++ b/thermferm/rdconfig.c Wed Jun 25 16:56:09 2014 +0200 @@ -60,7 +60,7 @@ {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet}, {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator}, {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator}, - {(char *)"cc_tempFormat", getuch, (char **)&Config.cc_tempFormat}, + {(char *)"cc_tempFormat", getuch, (char **)&Config.tempFormat}, {(char *)"cc_tempSetMin", getfloat, (char **)&Config.cc_tempSetMin}, {(char *)"cc_tempSetMax", getfloat, (char **)&Config.cc_tempSetMax}, {(char *)"cc_idleRangeH", getfloat, (char **)&Config.cc_idleRangeH}, @@ -157,7 +157,7 @@ fprintf(fp, "# Control Constants.\n"); fprintf(fp, "#\n"); - fprintf(fp, "cc_tempFormat %c\n", Config.cc_tempFormat); + fprintf(fp, "cc_tempFormat %c\n", Config.tempFormat); fprintf(fp, "cc_tempSetMin %.1f\n", Config.cc_tempSetMin); fprintf(fp, "cc_tempSetMax %.1f\n", Config.cc_tempSetMax); fprintf(fp, "cc_idleRangeH %.1f\n", Config.cc_idleRangeH); @@ -221,11 +221,14 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LISTEN_PORT", "%d", Config.my_port)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } #ifdef HAVE_WIRINGPI_H /* @@ -272,6 +275,50 @@ #endif /* + * For backwards compatibility, the old setup + */ + if (Config.w1therms) { + if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "W1THERMS")) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); + return 1; + } + for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) { + if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "W1THERM")) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); + return 1; + } + if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASTER", "%s", tmp1->master)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BUS", "%d", tmp1->bus)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", tmp1->name)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ALIAS", "%s", tmp1->alias)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterEndElement(writer)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); + return 1; + } + } + if ((rc = xmlTextWriterEndElement(writer)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); + return 1; + } + } + + /* * Fermenter units */ if (Config.units) { @@ -292,84 +339,80 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", tmp3->uuid)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", MBSE_SS(tmp3->name))) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", MBSE_SS(Config.units->name))) < 0) { - syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", Config.units->volume)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", tmp3->volume)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", MBSE_SS(Config.units->air_address))) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", MBSE_SS(tmp3->air_address))) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", MBSE_SS(Config.units->beer_address))) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", MBSE_SS(tmp3->beer_address))) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO1_ADDRESS", "%s", MBSE_SS(Config.units->io1_address))) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO1_ADDRESS", "%s", MBSE_SS(tmp3->io1_address))) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO2_ADDRESS", "%s", MBSE_SS(Config.units->io2_address))) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO2_ADDRESS", "%s", MBSE_SS(tmp3->io2_address))) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER", "%s", Config.units->heater_available ? "YES":"NO")) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER", "%s", tmp3->heater_available ? "YES":"NO")) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER", "%s", Config.units->cooler_available? "YES":"NO")) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER", "%s", tmp3->cooler_available? "YES":"NO")) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN", "%s", Config.units->fan_available ? "YES":"NO")) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN", "%s", tmp3->fan_available ? "YES":"NO")) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[Config.units->mode] )) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[tmp3->mode] )) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", Config.units->beer_set)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", tmp3->beer_set)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_SET", "%.1f", Config.units->fridge_set)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_SET", "%.1f", tmp3->fridge_set)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MIN", "%.1f", Config.units->temp_set_min)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MIN", "%.1f", tmp3->temp_set_min)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MAX", "%.1f", Config.units->temp_set_max)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MAX", "%.1f", tmp3->temp_set_max)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_L", "%.1f", Config.units->idle_rangeL)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_L", "%.1f", tmp3->idle_rangeL)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_H", "%.1f", Config.units->idle_rangeH)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_H", "%.1f", tmp3->idle_rangeH)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if (Config.units->profile) { - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE", "%s", Config.units->profile)) < 0) { + if (tmp3->profile) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE", "%s", tmp3->profile)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%d", (unsigned int)Config.units->prof_started)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%d", (unsigned int)tmp3->prof_started)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } diff -r d2c7b32f27d6 -r 143077e54255 thermferm/server.c --- a/thermferm/server.c Wed Jun 25 16:16:47 2014 +0200 +++ b/thermferm/server.c Wed Jun 25 16:56:09 2014 +0200 @@ -61,7 +61,7 @@ void defaultControlConstants(void) { - Config.cc_tempFormat = 'C'; + Config.tempFormat = 'C'; Config.cc_tempSetMin = 1.0; Config.cc_tempSetMax = 30.0; Config.cc_idleRangeH = 1.000; @@ -192,7 +192,7 @@ srv_send("%.1f", Config.cs_beerSet); } else if (strncmp(buf, "getControlConstants", 19) == 0) { srv_send("{ \"tempFormat\":\"%c\", \"tempSetMin\":%.1f, \"tempSetMax\":%.1f, \"idleRangeH\":%.3f, \"idleRangeL\":%.3f }", - Config.cc_tempFormat, Config.cc_tempSetMin, Config.cc_tempSetMax, Config.cc_idleRangeH, Config.cc_idleRangeL ); + Config.tempFormat, Config.cc_tempSetMin, Config.cc_tempSetMax, Config.cc_idleRangeH, Config.cc_idleRangeL ); } 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); diff -r d2c7b32f27d6 -r 143077e54255 thermferm/thermferm.h --- a/thermferm/thermferm.h Wed Jun 25 16:16:47 2014 +0200 +++ b/thermferm/thermferm.h Wed Jun 25 16:56:09 2014 +0200 @@ -119,6 +119,7 @@ typedef struct _sys_config { char *name; /* Configuration name */ int my_port; /* my client/server port */ + unsigned char tempFormat; /* Temperature format, C or F */ w1_therm *w1therms; /* 1-wire temp sensors */ #ifdef HAVE_WIRINGPI_H int lcd_cols; /* LCD display columns */ @@ -132,7 +133,6 @@ float cs_heatEstimator; float cs_coolEstimator; /* ControlConstants */ - unsigned char cc_tempFormat; float cc_tempSetMin; float cc_tempSetMax; float cc_idleRangeH;