# HG changeset patch # User Michiel Broek # Date 1403705807 -7200 # Node ID d2c7b32f27d644c3a31c28faaa7438b731c72aa7 # Parent 4b976601737dd7f24b64535284251f83dc8cdbaa Can now write the fermenter units configurations diff -r 4b976601737d -r d2c7b32f27d6 thermferm/rdconfig.c --- a/thermferm/rdconfig.c Tue Jun 24 22:38:46 2014 +0200 +++ b/thermferm/rdconfig.c Wed Jun 25 16:16:47 2014 +0200 @@ -31,6 +31,7 @@ #define MY_ENCODING "utf-8" +const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; //static int getstr(char **); static int getw1(char **); @@ -145,32 +146,6 @@ } fprintf(fp, "\n"); - fprintf(fp, "# Fermenter Units.\n"); - fprintf(fp, "#\n"); - for (tmp3 = Config.units; tmp3; tmp3 = tmp3->next) { - fprintf(fp, "unit_uid %s\n", tmp3->uid); - if (tmp3->name) - fprintf(fp, "unit_name %s\n", tmp3->name); - if (tmp3->volume > 0.0) - fprintf(fp, "unit_volume %.1f\n", tmp3->volume); - if (tmp3->air_address) - fprintf(fp, "unit_air_address %s\n", tmp3->air_address); - if (tmp3->beer_address) - fprintf(fp, "unit_beer_address %s\n", tmp3->beer_address); - if (tmp3->io_address) - fprintf(fp, "unit_io_address %s\n", tmp3->io_address); - fprintf(fp, "unit_heater_available %s\n", tmp3->heater_available ? "yes":"no"); - fprintf(fp, "unit_cooler_available %s\n", tmp3->cooler_available ? "yes":"no"); - fprintf(fp, "unit_fan_available %s\n", tmp3->fan_available ? "yes":"no"); - fprintf(fp, "unit_light_available %s\n", tmp3->light_available ? "yes":"no"); - fprintf(fp, "unit_mode %d\n", tmp3->mode); - if (tmp3->profile) { - fprintf(fp, "unit_profile %s\n", tmp3->profile); - fprintf(fp, "unit_prof_started %d\n", (int)tmp3->prof_started); - } - } - fprintf(fp, "\n"); - fprintf(fp, "# Control Settings.\n"); fprintf(fp, "#\n"); fprintf(fp, "cs_mode %c\n", Config.cs_mode); @@ -260,6 +235,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); return 1; } + /* + * Start one LCD. It is possible to connect 7 LCD displays on the i2c bus. + * However this program doesn't use more then one yet. + */ if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCD")) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); return 1; @@ -301,6 +280,10 @@ return 1; } for (tmp3 = Config.units; tmp3; tmp3 = tmp3->next) { + /* + * Only configuration items are written, measured values and states + * are written to a state file. + */ if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "UNIT")) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); return 1; @@ -309,7 +292,88 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } - + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 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) { + 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) { + 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) { + 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) { + 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) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER", "%s", Config.units->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) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN", "%s", Config.units->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) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", Config.units->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) { + 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) { + 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) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_L", "%.1f", Config.units->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) { + 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) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%d", (unsigned int)Config.units->prof_started)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } + } if ((rc = xmlTextWriterEndElement(writer)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); return 1; diff -r 4b976601737d -r d2c7b32f27d6 thermferm/thermferm.h --- a/thermferm/thermferm.h Tue Jun 24 22:38:46 2014 +0200 +++ b/thermferm/thermferm.h Wed Jun 25 16:16:47 2014 +0200 @@ -61,38 +61,43 @@ * Each unit can have: * a DS18B20 sensor to measure the air temperature inside the unit. * a DS18B20 sensor to measure the beer temperature. - * a DS2408 for 8 bits I/O to read status, turn heater/cooler on/off etc. + * a DS2413 to turn the cooler and heater on or off. + * a DS2413 to switch the fan and sense the door. */ typedef struct _units_list { struct _units_list *next; - char *uid; /* uid code */ + char *uuid; /* uid code */ char *name; /* friendly name */ float volume; /* Volume of this unit */ char *air_address; /* DS18B20 address */ float air_temp; /* Air temperature */ char *beer_address; /* DS18B20 address */ float beer_temp; /* Beer temperature */ - char *io_address; /* DS2408 address */ - unsigned char io_read; /* I/O ports read state */ + char *io1_address; /* DS2413 address */ + char *io2_address; /* DS2413 address */ int heater_available; /* Heater available */ int heater_state; /* Heater status */ int cooler_available; /* Cooler available */ int cooler_state; /* Cooler status */ int fan_available; /* Fan available */ int fan_state; /* Fan status */ - int light_available; /* Door sensor and int. light */ - int light_state; /* Door and light status */ + int door_state; /* Door and light status */ int mode; /* Unit mode */ + float beer_set; /* Beer temperature setting */ + float fridge_set; /* Fridge temperature setting */ + float temp_set_min; /* Minimum temperature */ + float temp_set_max; /* Maximum temperature */ + float idle_rangeL; /* Idle temperature low */ + float idle_rangeH; /* Idle range high */ char *profile; /* Active profile */ time_t prof_started; /* Profile start time */ } units_list; -#define UNITMODE_NA 0 /* Unit is missing */ -#define UNITMODE_OFF 1 /* Unit turned off */ -#define UNITMODE_NONE 2 /* Unit on but does nothing */ -#define UNITMODE_FRIDGE 3 /* Unit acts as a fridge */ -#define UNITMODE_BEER 4 /* Unit acts as beer cooler */ -#define UNITMODE_PROFILE 5 /* Unit runs in profile mode */ +#define UNITMODE_OFF 0 /* Unit turned off */ +#define UNITMODE_NONE 1 /* Unit on but does nothing */ +#define UNITMODE_FRIDGE 2 /* Unit acts as a fridge */ +#define UNITMODE_BEER 3 /* Unit acts as beer cooler */ +#define UNITMODE_PROFILE 4 /* Unit runs in profile mode */ #define UNITIO_HEATER 0x01 /* Heater bit */ #define UNITIO_COOLER 0x02 /* Cooler bit */