thermferm/thermferm.c

changeset 591
95cf33f8021f
parent 588
322a29000fd7
child 594
1904badedf8f
equal deleted inserted replaced
589:230a502b75ec 591:95cf33f8021f
19 * along with ThermFerm; see the file COPYING. If not, write to the Free 19 * along with ThermFerm; see the file COPYING. If not, write to the Free
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23 #include "lock.h" 23 #include "lock.h"
24 #include "logger.h"
25 #include "rdconfig.h" 24 #include "rdconfig.h"
26 #include "devices.h" 25 #include "devices.h"
27 #include "server.h" 26 #include "server.h"
28 #include "thermferm.h" 27 #include "thermferm.h"
29 #include "simulator.h" 28 #include "simulator.h"
403 */ 402 */
404 void change_mode(int mode) 403 void change_mode(int mode)
405 { 404 {
406 current_unit->mqtt_flag |= MQTT_FLAG_DATA; 405 current_unit->mqtt_flag |= MQTT_FLAG_DATA;
407 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) { 406 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF)) {
408 initlog(current_unit->product_code, current_unit->product_name);
409 current_unit->mqtt_flag |= MQTT_FLAG_BIRTH; 407 current_unit->mqtt_flag |= MQTT_FLAG_BIRTH;
410 } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) { 408 } else if ((current_unit->mode != UNITMODE_OFF) && (mode == UNITMODE_OFF)) {
411 current_unit->mqtt_flag |= MQTT_FLAG_DEATH; 409 current_unit->mqtt_flag |= MQTT_FLAG_DEATH;
412 } 410 }
413 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); 411 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
1006 1004
1007 1005
1008 1006
1009 int server(void) 1007 int server(void)
1010 { 1008 {
1011 char buf[1024], *filename, target_lo[40], target_hi[40], heater[40], cooler[40], fan[40], door[40];
1012 char use_heater[40], use_cooler[40], use_fan[40], room_temp[40];
1013 time_t now, last = (time_t)0, ndata = (time_t)0;; 1009 time_t now, last = (time_t)0, ndata = (time_t)0;;
1014 units_list *unit; 1010 units_list *unit;
1015 prof_step *step; 1011 prof_step *step;
1016 int row, rc, run = 1, seconds = 0, minutes = 0, temp, deviation; 1012 int row, rc, run = 1, seconds = 0, minutes = 0, temp, deviation;
1017 int run_seconds, run_minutes, run_hours, tot_minutes, key; 1013 int run_seconds, run_minutes, run_hours, tot_minutes, key;
1119 syslog(LOG_NOTICE, "Starting unit `%s' as refridgerator at %.1f - %.1f degrees", unit->alias, unit->fridge_set_lo, unit->fridge_set_hi); 1115 syslog(LOG_NOTICE, "Starting unit `%s' as refridgerator at %.1f - %.1f degrees", unit->alias, unit->fridge_set_lo, unit->fridge_set_hi);
1120 } else if (unit->mode == UNITMODE_NONE) { 1116 } else if (unit->mode == UNITMODE_NONE) {
1121 syslog(LOG_NOTICE, "Starting unit `%s' in inactive state", unit->alias); 1117 syslog(LOG_NOTICE, "Starting unit `%s' in inactive state", unit->alias);
1122 } else { 1118 } else {
1123 syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->alias); 1119 syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->alias);
1124 }
1125
1126 /*
1127 * Initialize logfile
1128 */
1129 if (unit->mode != UNITMODE_OFF) {
1130 initlog(unit->product_code, unit->product_name);
1131 } 1120 }
1132 } 1121 }
1133 printf("Units started\n"); 1122 printf("Units started\n");
1134 publishDBirthAll(); 1123 publishDBirthAll();
1135 printf("Birth all done\n"); 1124 printf("Birth all done\n");
1961 1950
1962 if (seconds == 60) { 1951 if (seconds == 60) {
1963 seconds = 0; 1952 seconds = 0;
1964 1953
1965 /* 1954 /*
1966 * Log temperature and status every minute if unit is active. 1955 * Publish data every minute if unit is active.
1967 */ 1956 */
1968 for (unit = Config.units; unit; unit = unit->next) { 1957 for (unit = Config.units; unit; unit = unit->next) {
1969 if (unit->mode != UNITMODE_OFF) { 1958 if (unit->mode != UNITMODE_OFF) {
1970
1971 snprintf(target_lo, 39, "NA");
1972 snprintf(target_hi, 39, "NA");
1973 snprintf(heater, 39, "NA");
1974 snprintf(cooler, 39, "NA");
1975 snprintf(fan, 39, "NA");
1976 snprintf(door, 39, "NA");
1977 snprintf(use_heater, 39, "NA");
1978 snprintf(use_cooler, 39, "NA");
1979 snprintf(use_fan, 39, "NA");
1980 snprintf(room_temp, 39, "NA");
1981
1982 if ((unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_PROFILE)) {
1983 snprintf(target_lo, 39, "%.1f", unit->PID_heat->SetP);
1984 snprintf(target_hi, 39, "%.1f", unit->PID_cool->SetP);
1985 }
1986
1987 if (unit->heater_address) {
1988 snprintf(heater, 39, "%d", unit->heater_state);
1989 snprintf(use_heater, 39, "%d", unit->heater_usage);
1990 }
1991 if (unit->cooler_address) {
1992 snprintf(cooler, 39, "%d", unit->cooler_state);
1993 snprintf(use_cooler, 39, "%d", unit->cooler_usage);
1994 }
1995 if (unit->fan_address) {
1996 snprintf(fan, 39, "%d", unit->fan_state);
1997 snprintf(use_fan, 39, "%d", unit->fan_usage);
1998 }
1999 if (unit->door_address) {
2000 snprintf(door, 39, "%d", unit->door_state);
2001 }
2002 if (Config.temp_address) {
2003 snprintf(room_temp, 39, "%.3f", Config.temp_value / 1000.0);
2004 }
2005
2006 snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%.3f,%s",
2007 UNITMODE[unit->mode], unit->air_temperature / 1000.0,
2008 unit->beer_temperature / 1000.0,
2009 target_lo, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp, target_hi,
2010 unit->chiller_temperature / 1000.0,
2011 (unit->event_msg) ? unit->event_msg : (char *)"");
2012 filename = xstrcpy(unit->product_code);
2013 filename = xstrcat(filename, (char *)" ");
2014 filename = xstrcat(filename, unit->product_name);
2015 filename = xstrcat(filename, (char *)".log");
2016 logger(filename, buf);
2017 free(filename);
2018 filename = NULL;
2019
2020 publishDLog(unit); 1959 publishDLog(unit);
2021 if (unit->event_msg) 1960 if (unit->event_msg)
2022 free(unit->event_msg); 1961 free(unit->event_msg);
2023 unit->event_msg = NULL; 1962 unit->event_msg = NULL;
2024 } 1963 }

mercurial