31 sys_config Config; /* System configuration */ |
31 sys_config Config; /* System configuration */ |
32 extern pthread_mutex_t mutexes[5]; |
32 extern pthread_mutex_t mutexes[5]; |
33 |
33 |
34 #define MY_ENCODING "utf-8" |
34 #define MY_ENCODING "utf-8" |
35 |
35 |
36 const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" }; |
|
37 const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; |
36 const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; |
38 const char UNITSTAGE[4][12] = { "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" }; |
37 const char UNITSTAGE[4][12] = { "PRIMARY", "SECONDARY", "TERTIARY", "CARBONATION" }; |
39 const char PROFSTATE[5][6] = { "OFF", "PAUSE", "RUN", "DONE", "ABORT" }; |
38 const char PROFSTATE[5][6] = { "OFF", "PAUSE", "RUN", "DONE", "ABORT" }; |
40 const char DEVTYPE[8][6] = { "NA", "W1", "GPIO", "RC433", "DHT", "I2C", "SPI", "SIM" }; |
39 const char DEVTYPE[8][6] = { "NA", "W1", "GPIO", "RC433", "DHT", "I2C", "SPI", "SIM" }; |
41 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; |
40 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; |
57 |
56 |
58 if (Config.name) |
57 if (Config.name) |
59 free(Config.name); |
58 free(Config.name); |
60 Config.name = NULL; |
59 Config.name = NULL; |
61 |
60 |
62 Config.my_port = 6554; |
61 Config.server_port = 6554; |
63 Config.tempFormat = 'C'; |
62 Config.websocket_port = 8020; |
64 if (Config.temp_address) |
63 if (Config.temp_uuid) |
65 free(Config.temp_address); |
64 free(Config.temp_uuid); |
66 if (Config.hum_address) |
65 if (Config.hum_uuid) |
67 free(Config.hum_address); |
66 free(Config.hum_uuid); |
68 Config.temp_hum_idx = 0; |
67 Config.temp_hum_idx = 0; |
69 Config.temp_address = Config.hum_address = NULL; |
68 Config.temp_uuid = Config.hum_uuid = NULL; |
70 Config.temp_value = 20000; |
69 Config.temp_value = 20000; |
71 Config.temp_state = Config.hum_state = 1; // missing |
70 Config.temp_state = Config.hum_state = 1; // missing |
72 Config.hum_value = 50000; |
71 Config.hum_value = 50000; |
73 if (Config.mqtt_host) |
72 if (Config.mqtt_host) |
74 free(Config.mqtt_host); |
73 free(Config.mqtt_host); |
217 */ |
216 */ |
218 xmlTextWriterStartElement(writer, BAD_CAST "THERMFERM"); |
217 xmlTextWriterStartElement(writer, BAD_CAST "THERMFERM"); |
219 |
218 |
220 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", Config.name); |
219 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", Config.name); |
221 xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.uuid); |
220 xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.uuid); |
222 xmlTextWriterWriteFormatElement(writer, BAD_CAST "LISTEN_PORT", "%d", Config.my_port); |
221 xmlTextWriterWriteFormatElement(writer, BAD_CAST "SERVER_PORT", "%d", Config.server_port); |
223 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat); |
222 xmlTextWriterWriteFormatElement(writer, BAD_CAST "WS_PORT", "%d", Config.websocket_port); |
224 |
223 |
225 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_ADDRESS", "%s", Config.temp_address); |
224 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_UUID", "%s", Config.temp_uuid); |
226 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_STATE", "%d", Config.temp_state); |
225 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_STATE", "%d", Config.temp_state); |
227 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_VALUE", "%d", Config.temp_value); |
226 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_VALUE", "%d", Config.temp_value); |
228 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_ADDRESS", "%s", Config.hum_address); |
227 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_UUID", "%s", Config.hum_uuid); |
229 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_STATE", "%d", Config.hum_state); |
228 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_STATE", "%d", Config.hum_state); |
230 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_VALUE", "%d", Config.hum_value); |
229 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_VALUE", "%d", Config.hum_value); |
231 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_HUM_IDX", "%d", Config.temp_hum_idx); |
230 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_HUM_IDX", "%d", Config.temp_hum_idx); |
232 |
231 |
233 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit); |
232 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit); |
236 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PORT", "%d", Config.mqtt_port); |
235 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PORT", "%d", Config.mqtt_port); |
237 if (Config.mqtt_username && Config.mqtt_password) { |
236 if (Config.mqtt_username && Config.mqtt_password) { |
238 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_USER", "%s", Config.mqtt_username); |
237 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_USER", "%s", Config.mqtt_username); |
239 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PASS", "%s", Config.mqtt_password); |
238 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PASS", "%s", Config.mqtt_password); |
240 } |
239 } |
241 xmlTextWriterWriteFormatElement(writer, BAD_CAST "WS_PORT", "%d", Config.websocket_port); |
|
242 |
240 |
243 /* |
241 /* |
244 * Start an element named "LCDS" as child of THERMFERM. |
242 * Start an element named "LCDS" as child of THERMFERM. |
245 */ |
243 */ |
246 xmlTextWriterStartElement(writer, BAD_CAST "LCDS"); |
244 xmlTextWriterStartElement(writer, BAD_CAST "LCDS"); |
577 unit->heater_address = unit->cooler_address = unit->fan_address = unit->door_address = \ |
575 unit->heater_address = unit->cooler_address = unit->fan_address = unit->door_address = \ |
578 unit->light_address = unit->psu_address = unit->profile_uuid = unit->profile_name = NULL; |
576 unit->light_address = unit->psu_address = unit->profile_uuid = unit->profile_name = NULL; |
579 unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
577 unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
580 unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = unit->beer_set_lo = unit->beer_set_hi = \ |
578 unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = unit->beer_set_lo = unit->beer_set_hi = \ |
581 unit->fridge_set_lo = unit->fridge_set_hi = unit->profile_inittemp_lo = unit->profile_inittemp_hi = 20.0; |
579 unit->fridge_set_lo = unit->fridge_set_hi = unit->profile_inittemp_lo = unit->profile_inittemp_hi = 20.0; |
582 unit->air_state = unit->beer_state = unit->chiller_state = 1; // missing |
580 unit->air_state = unit->beer_state = unit->chiller_state = DEVPRESENT_NO; // missing |
583 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \ |
581 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \ |
584 unit->light_state = unit->light_timer = unit->psu_state = unit->mode = unit->prof_state = unit->stage = 0; |
582 unit->light_state = unit->light_timer = unit->psu_state = unit->mode = unit->prof_state = unit->stage = 0; |
585 unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \ |
583 unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \ |
586 unit->door_idx = unit->light_idx = unit->psu_idx = unit->profile_fridge_mode = \ |
584 unit->door_idx = unit->light_idx = unit->psu_idx = unit->profile_fridge_mode = \ |
587 unit->profile_duration = unit->profile_totalsteps = 0; |
585 unit->profile_duration = unit->profile_totalsteps = 0; |
1588 cur = cur->xmlChildrenNode; |
1586 cur = cur->xmlChildrenNode; |
1589 while (cur != NULL) { |
1587 while (cur != NULL) { |
1590 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { |
1588 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { |
1591 Config.name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1589 Config.name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1592 } |
1590 } |
1593 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LISTEN_PORT"))) { |
1591 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SERVER_PORT")) || (!xmlStrcmp(cur->name, (const xmlChar *)"LISTEN_PORT"))) { |
1594 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1592 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1595 if (sscanf((const char *)key, "%d", &ival) == 1) |
1593 if (sscanf((const char *)key, "%d", &ival) == 1) |
1596 Config.my_port = ival; |
1594 Config.server_port = ival; |
1597 xmlFree(key); |
1595 xmlFree(key); |
1598 } |
1596 } |
1599 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMPFORMAT"))) { |
1597 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMP_UUID")) || (!xmlStrcmp(cur->name, (const xmlChar *)"TEMP_ADDRESS"))) { |
1600 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1598 Config.temp_uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1601 Config.tempFormat = key[0]; |
1599 } |
1602 xmlFree(key); |
1600 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HUM_UUID")) || (!xmlStrcmp(cur->name, (const xmlChar *)"HUM_ADDRESS"))) { |
1603 } |
1601 Config.hum_uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1604 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMP_ADDRESS"))) { |
|
1605 Config.temp_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1606 } |
|
1607 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HUM_ADDRESS"))) { |
|
1608 Config.hum_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1609 } |
1602 } |
1610 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMP_HUM_IDX"))) { |
1603 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMP_HUM_IDX"))) { |
1611 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1604 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1612 if (sscanf((const char *)key, "%d", &ival) == 1) |
1605 if (sscanf((const char *)key, "%d", &ival) == 1) |
1613 Config.temp_hum_idx = ival; |
1606 Config.temp_hum_idx = ival; |