diff -r fd1354e2a045 -r a2732027afb3 thermferm/rdconfig.c --- a/thermferm/rdconfig.c Wed May 31 16:29:52 2017 +0200 +++ b/thermferm/rdconfig.c Wed Jun 07 23:06:47 2017 +0200 @@ -60,6 +60,7 @@ free(Config.temp_address); if (Config.hum_address) free(Config.hum_address); + Config.temp_hum_idx = 0; Config.temp_address = Config.hum_address = NULL; Config.temp_value = 20000; Config.temp_state = Config.hum_state = 1; // missing @@ -244,6 +245,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_HUM_IDX", "%d", Config.temp_hum_idx)) < 0) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; @@ -355,6 +360,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_IDX", "%d", tmp3->air_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->beer_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", tmp3->beer_address)) < 0)) { @@ -369,6 +378,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_IDX", "%d", tmp3->beer_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->heater_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_ADDRESS", "%s", tmp3->heater_address)) < 0)) { @@ -387,6 +400,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_IDX", "%d", tmp3->heater_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->cooler_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_ADDRESS", "%s", tmp3->cooler_address)) < 0)) { @@ -405,6 +422,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_IDX", "%d", tmp3->cooler_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->fan_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_ADDRESS", "%s", tmp3->fan_address)) < 0)) { @@ -423,6 +444,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_IDX", "%d", tmp3->fan_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->light_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_ADDRESS", "%s", tmp3->light_address)) < 0)) { @@ -441,6 +466,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_IDX", "%d", tmp3->light_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->door_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_ADDRESS", "%s", tmp3->door_address)) < 0)) { @@ -451,6 +480,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_IDX", "%d", tmp3->door_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->psu_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_ADDRESS", "%s", tmp3->psu_address)) < 0)) { @@ -461,6 +494,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_IDX", "%d", tmp3->psu_idx)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[tmp3->mode] )) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); @@ -1040,6 +1077,8 @@ unit->air_state = unit->beer_state = 1; // missing unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \ unit->light_state = unit->psu_state = unit->mode = unit->prof_state = 0; + unit->air_idx = unit->beer_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \ + unit->door_idx = unit->light_idx = unit->psu_idx = 0; unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ unit->light_delay = 1; /* 15 seconds delay */ unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; @@ -1088,6 +1127,12 @@ unit->air_state = ival; xmlFree(key); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->air_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_TEMPERATURE"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) @@ -1103,6 +1148,12 @@ unit->beer_state = ival; xmlFree(key); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->beer_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_TEMPERATURE"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) @@ -1118,6 +1169,12 @@ unit->heater_delay = ival; xmlFree(key); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->heater_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_USAGE"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) @@ -1133,6 +1190,12 @@ unit->cooler_delay = ival; xmlFree(key); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->cooler_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_USAGE"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) @@ -1148,6 +1211,12 @@ unit->fan_delay = ival; xmlFree(key); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->fan_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_USAGE"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) @@ -1163,6 +1232,12 @@ unit->light_delay = ival; xmlFree(key); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->light_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"LIGHT_USAGE"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) @@ -1172,9 +1247,21 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"DOOR_ADDRESS"))) { unit->door_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"DOOR_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->door_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"PSU_ADDRESS"))) { unit->psu_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"PSU_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->psu_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"MODE"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); for (i = 0; i < 5; i++) { @@ -1413,15 +1500,6 @@ cur = cur->next; } - /* - * If there is no alias name, create it. - */ -// if (unit->alias == NULL) { -// char an[128]; -// sprintf(an, "unit%d", number); -// unit->alias = xstrcpy(an); -// } - if (Config.units == NULL) { Config.units = unit; } else { @@ -1443,8 +1521,7 @@ cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"UNIT"))) { - parseUnit(doc, cur/* , Config.next_unit*/); -// Config.next_unit++; + parseUnit(doc, cur); } cur = cur->next; } @@ -2064,6 +2141,12 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"HUM_ADDRESS"))) { Config.hum_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMP_HUM_IDX"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + Config.temp_hum_idx = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"NEXT_UNIT"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1)