27 static char *mypath; |
27 static char *mypath; |
28 sys_config Config; /* System configuration */ |
28 sys_config Config; /* System configuration */ |
29 |
29 |
30 #define MY_ENCODING "utf-8" |
30 #define MY_ENCODING "utf-8" |
31 |
31 |
|
32 const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" }; |
32 const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; |
33 const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; |
33 const char UNITmode[5] = { 'o', 'n', 'f', 'b', 'p' }; |
34 const char UNITmode[5] = { 'o', 'n', 'f', 'b', 'p' }; |
34 const char PROFSTATE[4][6] = { "OFF", "PAUSE", "RUN", "DONE" }; |
35 const char PROFSTATE[4][6] = { "OFF", "PAUSE", "RUN", "DONE" }; |
35 |
36 |
36 |
37 |
60 Config.my_port = 6554; |
61 Config.my_port = 6554; |
61 Config.tempFormat = 'C'; |
62 Config.tempFormat = 'C'; |
62 if (Config.air_address) |
63 if (Config.air_address) |
63 free(Config.air_address); |
64 free(Config.air_address); |
64 Config.air_address = NULL; |
65 Config.air_address = NULL; |
|
66 Config.air_temperature = 20000; |
|
67 Config.air_state = 1; // missing |
65 |
68 |
66 for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) { |
69 for (tmp2 = Config.units; tmp2; tmp2 = tmp2->next) { |
67 if (tmp2->uuid) |
70 if (tmp2->uuid) |
68 free(tmp2->uuid); |
71 free(tmp2->uuid); |
69 if (tmp2->name) |
72 if (tmp2->name) |
171 } |
174 } |
172 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat)) < 0) { |
175 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat)) < 0) { |
173 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
176 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
174 return 1; |
177 return 1; |
175 } |
178 } |
176 if (Config.air_address && (rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", Config.air_address)) < 0) { |
179 if (Config.air_address) { |
177 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
180 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", Config.air_address)) < 0) { |
178 return 1; |
181 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
182 return 1; |
|
183 } |
|
184 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_STATE", "%d", Config.air_state)) < 0) { |
|
185 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
186 return 1; |
|
187 } |
|
188 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%d", Config.air_temperature)) < 0) { |
|
189 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
190 return 1; |
|
191 } |
179 } |
192 } |
180 |
193 |
181 #ifdef HAVE_WIRINGPI_H |
194 #ifdef HAVE_WIRINGPI_H |
182 /* |
195 /* |
183 * Start an element named "LCDS" as child of THERMFERM. |
196 * Start an element named "LCDS" as child of THERMFERM. |
301 } |
314 } |
302 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", tmp3->volume)) < 0) { |
315 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", tmp3->volume)) < 0) { |
303 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
316 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
304 return 1; |
317 return 1; |
305 } |
318 } |
306 if (tmp3->air_address && ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", tmp3->air_address)) < 0)) { |
319 if (tmp3->air_address) { |
307 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
320 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", tmp3->air_address)) < 0)) { |
308 return 1; |
321 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
309 } |
322 return 1; |
310 if (tmp3->beer_address && ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", tmp3->beer_address)) < 0)) { |
323 } |
311 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
324 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_STATE", "%d", tmp3->air_state)) < 0)) { |
312 return 1; |
325 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
326 return 1; |
|
327 } |
|
328 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%d", tmp3->air_temperature)) < 0)) { |
|
329 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
330 return 1; |
|
331 } |
|
332 } |
|
333 if (tmp3->beer_address) { |
|
334 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", tmp3->beer_address)) < 0)) { |
|
335 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
336 return 1; |
|
337 } |
|
338 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_STATE", "%d", tmp3->beer_state)) < 0)) { |
|
339 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
340 return 1; |
|
341 } |
|
342 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%d", tmp3->beer_temperature)) < 0)) { |
|
343 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
344 return 1; |
|
345 } |
313 } |
346 } |
314 if (tmp3->io1_address && ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO1_ADDRESS", "%s", tmp3->io1_address)) < 0)) { |
347 if (tmp3->io1_address && ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO1_ADDRESS", "%s", tmp3->io1_address)) < 0)) { |
315 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
348 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
316 return 1; |
349 return 1; |
317 } |
350 } |
629 unit->next = NULL; |
662 unit->next = NULL; |
630 unit->version = 1; |
663 unit->version = 1; |
631 unit->uuid = unit->name = unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL; |
664 unit->uuid = unit->name = unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL; |
632 unit->volume = 0.0; |
665 unit->volume = 0.0; |
633 unit->heater_available = unit->cooler_available = unit->fan_available = FALSE; |
666 unit->heater_available = unit->cooler_available = unit->fan_available = FALSE; |
634 unit->air_temp = unit->beer_temp = unit->beer_set = unit->fridge_set = 20.0; |
667 unit->air_temperature = unit->beer_temperature = unit->beer_set = unit->fridge_set = 20.0; |
|
668 unit->air_state = unit->beer_state = 1; // missing |
635 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; |
669 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; |
636 unit->temp_set_min = 1.0; |
670 unit->temp_set_min = 1.0; |
637 unit->temp_set_max = 30.0; |
671 unit->temp_set_max = 30.0; |
638 unit->idle_rangeH = 1.0; |
672 unit->idle_rangeH = 1.0; |
639 unit->idle_rangeL = -1.0; |
673 unit->idle_rangeL = -1.0; |
663 xmlFree(key); |
697 xmlFree(key); |
664 } |
698 } |
665 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_ADDRESS"))) { |
699 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_ADDRESS"))) { |
666 unit->air_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
700 unit->air_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
667 } |
701 } |
|
702 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_STATE"))) { |
|
703 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
704 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
705 unit->air_state = ival; |
|
706 xmlFree(key); |
|
707 } |
|
708 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_TEMPERATURE"))) { |
|
709 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
710 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
711 unit->air_temperature = ival; |
|
712 xmlFree(key); |
|
713 } |
668 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_ADDRESS"))) { |
714 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_ADDRESS"))) { |
669 unit->beer_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
715 unit->beer_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
716 } |
|
717 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_STATE"))) { |
|
718 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
719 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
720 unit->beer_state = ival; |
|
721 xmlFree(key); |
|
722 } |
|
723 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_TEMPERATURE"))) { |
|
724 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
725 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
726 unit->beer_temperature = ival; |
|
727 xmlFree(key); |
670 } |
728 } |
671 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IO1_ADDRESS"))) { |
729 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IO1_ADDRESS"))) { |
672 unit->io1_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
730 unit->io1_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
673 } |
731 } |
674 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IO2_ADDRESS"))) { |
732 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IO2_ADDRESS"))) { |