brewco/rdconfig.c

changeset 435
4b1ed6897d80
parent 434
eb724767860d
child 438
7d1ec160d751
equal deleted inserted replaced
434:eb724767860d 435:4b1ed6897d80
29 sys_config Config; /* System configuration */ 29 sys_config Config; /* System configuration */
30 30
31 #define MY_ENCODING "utf-8" 31 #define MY_ENCODING "utf-8"
32 32
33 const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" }; 33 const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" };
34 const char DEVTYPE[8][6] = { "NA", "W1", "GPIO", "RC433", "DHT", "I2C", "SPI", "SIM" }; 34 const char DEVTYPE[6][5] = { "NA", "W1", "GPIO", "I2C", "SPI", "SIM" };
35 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; 35 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" };
36 const char DEVDIR[7][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM", "INTERN" }; 36 const char DEVDIR[7][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM", "INTERN" };
37 const char PIDMODE[3][5] = { "NONE", "AUTO", "BOO" }; 37 const char PIDMODE[3][5] = { "NONE", "AUTO", "BOO" };
38 const char WHIRLPOOL_TYPE[3][5] = { "OFF", "COLD", "HOT" };
38 39
39 40
40 void killconfig(void) 41 void killconfig(void)
41 { 42 {
42 units_list *unit; 43 units_list *unit;
49 free(Config.name); 50 free(Config.name);
50 Config.name = NULL; 51 Config.name = NULL;
51 52
52 Config.my_port = 6554; 53 Config.my_port = 6554;
53 Config.tempFormat = 'C'; 54 Config.tempFormat = 'C';
54 if (Config.temp_address) 55 if (Config.roomtemp)
55 free(Config.temp_address); 56 free(Config.roomtemp);
56 if (Config.hum_address) 57 Config.roomtemp = NULL;
57 free(Config.hum_address);
58 Config.temp_address = Config.hum_address = NULL;
59 Config.temp_value = 20000;
60 Config.temp_state = Config.hum_state = 1; // missing
61 Config.hum_value = 50000;
62 Config.lcd_cols = 20; 58 Config.lcd_cols = 20;
63 Config.lcd_rows = 4; 59 Config.lcd_rows = 4;
64 60
65 for (unit = Config.units; unit; unit = unit->next) { 61 for (unit = Config.units; unit; unit = unit->next) {
66 if (unit->uuid) 62 if (unit->uuid)
67 free(unit->uuid); 63 free(unit->uuid);
68 if (unit->name) 64 if (unit->name)
69 free(unit->name); 65 free(unit->name);
70 if (unit->hlt_sensor_address) 66 if (unit->hlt_sensor)
71 free(unit->hlt_sensor_address); 67 free(unit->hlt_sensor);
72 if (unit->mlt_sensor_address) 68 if (unit->mlt_sensor)
73 free(unit->mlt_sensor_address); 69 free(unit->mlt_sensor);
74 if (unit->hlt_heater_address) 70 if (unit->hlt_heater)
75 free(unit->hlt_heater_address); 71 free(unit->hlt_heater);
76 if (unit->mlt_heater_address) 72 if (unit->mlt_heater)
77 free(unit->mlt_heater_address); 73 free(unit->mlt_heater);
78 if (unit->mlt_pump_address) 74 if (unit->mlt_pump)
79 free(unit->mlt_pump_address); 75 free(unit->mlt_pump);
76 if (unit->PID_hlt)
77 free(unit->PID_hlt);
78 if (unit->PID_mlt)
79 free(unit->PID_mlt);
80 free(unit); 80 free(unit);
81 } 81 }
82 Config.units = NULL; 82 Config.units = NULL;
83 83
84 for (device = Config.devices; device; device = device->next) { 84 for (device = Config.devices; device; device = device->next) {
182 } 182 }
183 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat)) < 0) { 183 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat)) < 0) {
184 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 184 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
185 return 1; 185 return 1;
186 } 186 }
187 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_ADDRESS", "%s", Config.temp_address)) < 0) { 187 if (Config.roomtemp) {
188 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 188 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOMTEMP_UUID", "%s", Config.roomtemp->uuid)) < 0) {
189 return 1; 189 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
190 } 190 return 1;
191 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_STATE", "%d", Config.temp_state)) < 0) { 191 }
192 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 192 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOMTEMP_STATE", "%d", Config.roomtemp->state)) < 0) {
193 return 1; 193 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
194 } 194 return 1;
195 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_VALUE", "%d", Config.temp_value)) < 0) { 195 }
196 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 196 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOMTEMP_VALUE", "%d", Config.roomtemp->value)) < 0) {
197 return 1; 197 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
198 } 198 return 1;
199 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_ADDRESS", "%s", Config.hum_address)) < 0) { 199 }
200 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
201 return 1;
202 }
203 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_STATE", "%d", Config.hum_state)) < 0) {
204 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
205 return 1;
206 }
207 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_VALUE", "%d", Config.hum_value)) < 0) {
208 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
209 return 1;
210 } 200 }
211 201
212 /* 202 /*
213 * Start an element named "LCDS" as child of BREWCO. 203 * Start an element named "LCDS" as child of BREWCO.
214 */ 204 */
283 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", unit->name)) < 0) { 273 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", unit->name)) < 0) {
284 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 274 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
285 return 1; 275 return 1;
286 } 276 }
287 277
288 if (unit->hlt_sensor_address) { 278 if (unit->hlt_sensor) {
289 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_SENSOR_ADDRESS", "%s", unit->hlt_sensor_address)) < 0)) { 279 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_SENSOR_UUID", "%s", unit->hlt_sensor->uuid)) < 0)) {
290 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 280 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
291 return 1; 281 return 1;
292 } 282 }
293 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_SENSOR_STATE", "%d", unit->hlt_sensor_state)) < 0)) { 283 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_SENSOR_STATE", "%d", unit->hlt_sensor->state)) < 0)) {
294 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 284 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
295 return 1; 285 return 1;
296 } 286 }
297 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_SENSOR_VALUE", "%d", unit->hlt_sensor_value)) < 0)) { 287 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_SENSOR_VALUE", "%d", unit->hlt_sensor->value)) < 0)) {
298 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 288 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
299 return 1; 289 return 1;
300 } 290 }
301 } 291 }
302 292
303 if (unit->hlt_heater_address) { 293 if (unit->hlt_heater) {
304 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_ADDRESS", "%s", unit->hlt_heater_address)) < 0)) { 294 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_UUID", "%s", unit->hlt_heater->uuid)) < 0)) {
305 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 295 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
306 return 1; 296 return 1;
307 } 297 }
308 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_STATE", "%d", unit->hlt_heater_state)) < 0)) { 298 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_VALUE", "%d", unit->hlt_heater->value)) < 0)) {
309 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 299 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
310 return 1; 300 return 1;
311 } 301 }
312 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_DELAY", "%d", unit->hlt_heater_delay)) < 0)) { 302 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_DELAY", "%d", unit->hlt_heater->delay)) < 0)) {
313 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 303 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
314 return 1; 304 return 1;
315 } 305 }
316 } 306 }
317 307
318 if (unit->mlt_sensor_address) { 308 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_MLTFIRST", "%d", unit->hlt_heater_mltfirst)) < 0)) {
319 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_SENSOR_ADDRESS", "%s", unit->mlt_sensor_address)) < 0)) { 309 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
320 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 310 return 1;
321 return 1; 311 }
322 } 312
323 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_SENSOR_STATE", "%d", unit->mlt_sensor_state)) < 0)) { 313 if (unit->mlt_sensor) {
324 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 314 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_SENSOR_UUID", "%s", unit->mlt_sensor->uuid)) < 0)) {
325 return 1; 315 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
326 } 316 return 1;
327 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_SENSOR_VALUE", "%d", unit->mlt_sensor_value)) < 0)) { 317 }
328 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 318 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_SENSOR_STATE", "%d", unit->mlt_sensor->state)) < 0)) {
329 return 1; 319 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
330 } 320 return 1;
331 } 321 }
332 322 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_SENSOR_VALUE", "%d", unit->mlt_sensor->value)) < 0)) {
333 if (unit->mlt_heater_address) { 323 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
334 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_ADDRESS", "%s", unit->mlt_heater_address)) < 0)) { 324 return 1;
335 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 325 }
336 return 1; 326 }
337 } 327
338 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_STATE", "%d", unit->mlt_heater_state)) < 0)) { 328 if (unit->mlt_heater) {
339 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 329 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_UUID", "%s", unit->mlt_heater->uuid)) < 0)) {
340 return 1; 330 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
341 } 331 return 1;
342 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_DELAY", "%d", unit->mlt_heater_delay)) < 0)) { 332 }
343 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 333 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_VALUE", "%d", unit->mlt_heater->value)) < 0)) {
344 return 1; 334 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
345 } 335 return 1;
346 } 336 }
347 337 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_DELAY", "%d", unit->mlt_heater->delay)) < 0)) {
348 if (unit->mlt_pump_address) { 338 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
349 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_PUMP_ADDRESS", "%s", unit->mlt_pump_address)) < 0)) { 339 return 1;
350 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 340 }
351 return 1; 341 }
352 } 342
353 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_PUMP_STATE", "%d", unit->mlt_pump_state)) < 0)) { 343 if (unit->mlt_pump) {
354 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 344 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_PUMP_UUID", "%s", unit->mlt_pump->uuid)) < 0)) {
355 return 1; 345 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
356 } 346 return 1;
357 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_PUMP_DELAY", "%d", unit->mlt_pump_delay)) < 0)) { 347 }
358 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 348 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_PUMP_VALUE", "%d", unit->mlt_pump->value)) < 0)) {
359 return 1; 349 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
360 } 350 return 1;
361 } 351 }
352 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_PUMP_DELAY", "%d", unit->mlt_pump->delay)) < 0)) {
353 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
354 return 1;
355 }
356 }
357
358 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_CYCLE", "%d", unit->pump_cycle)) < 0)) {
359 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
360 return 1;
361 }
362 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_REST", "%d", unit->pump_rest)) < 0)) {
363 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
364 return 1;
365 }
366 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_PREMASH", "%d", unit->pump_premash)) < 0)) {
367 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
368 return 1;
369 }
370 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_ONMASH", "%d", unit->pump_onmash)) < 0)) {
371 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
372 return 1;
373 }
374 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_MASHOUT", "%d", unit->pump_mashout)) < 0)) {
375 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
376 return 1;
377 }
378 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_ONBOIL", "%d", unit->pump_onboil)) < 0)) {
379 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
380 return 1;
381 }
382 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PUMP_STOP", "%d", unit->pump_stop)) < 0)) {
383 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
384 return 1;
385 }
386 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "SKIP_ADD", "%d", unit->skip_add)) < 0)) {
387 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
388 return 1;
389 }
390 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "SKIP_REMOVE", "%d", unit->skip_remove)) < 0)) {
391 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
392 return 1;
393 }
394 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "SKIP_IODINE", "%d", unit->skip_iodine)) < 0)) {
395 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
396 return 1;
397 }
398 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IODINE_TIME", "%d", unit->iodine_time)) < 0)) {
399 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
400 return 1;
401 }
402 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "WHIRLPOOL", "%s", WHIRLPOOL_TYPE[unit->whirlpool])) < 0)) {
403 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
404 return 1;
405 }
362 406
363 if (unit->PID_hlt) { 407 if (unit->PID_hlt) {
364 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_HLT_IMAX", "%.2f", unit->PID_hlt->iMax)) < 0) { 408 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_HLT_IMAX", "%.2f", unit->PID_hlt->iMax)) < 0) {
365 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 409 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
366 return 1; 410 return 1;
403 } 447 }
404 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_HLT_MODE", "%s", PIDMODE[unit->PID_hlt->Mode])) < 0) { 448 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_HLT_MODE", "%s", PIDMODE[unit->PID_hlt->Mode])) < 0) {
405 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 449 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
406 return 1; 450 return 1;
407 } 451 }
408 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_HLT_TYPE", "HEAT")) < 0) { 452 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_HLT_TIMES", "%d", unit->PID_hlt->Times)) < 0)) {
409 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 453 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
410 return 1; 454 return 1;
411 } 455 }
412 } 456 }
413 457
414 if (unit->PID_mlt) { 458 if (unit->PID_mlt) {
415 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_MLT_IMAX", "%.2f", unit->PID_mlt->iMax)) < 0) { 459 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_MLT_IMAX", "%.2f", unit->PID_mlt->iMax)) < 0) {
416 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 460 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
454 } 498 }
455 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_MLT_MODE", "%s", PIDMODE[unit->PID_mlt->Mode])) < 0) { 499 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_MLT_MODE", "%s", PIDMODE[unit->PID_mlt->Mode])) < 0) {
456 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 500 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
457 return 1; 501 return 1;
458 } 502 }
459 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_MLT_TYPE", "HEAT")) < 0) { 503 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PID_MLT_TIMES", "%d", unit->PID_mlt->Times)) < 0)) {
460 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 504 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
461 return 1; 505 return 1;
462 } 506 }
463 } 507 }
464 508
465 if ((rc = xmlTextWriterEndElement(writer)) < 0) { 509 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
466 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); 510 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
467 return 1; 511 return 1;
705 units_list *unit, *tmp; 749 units_list *unit, *tmp;
706 750
707 unit = (units_list *)malloc(sizeof(units_list)); 751 unit = (units_list *)malloc(sizeof(units_list));
708 unit->next = NULL; 752 unit->next = NULL;
709 unit->version = 1; 753 unit->version = 1;
710 unit->uuid = unit->name = unit->hlt_sensor_address = unit->hlt_heater_address = unit->mlt_sensor_address = \ 754 unit->uuid = unit->name = NULL;
711 unit->mlt_heater_address = unit->mlt_pump_address = NULL; 755 unit->hlt_sensor = unit->mlt_sensor = NULL;
712 unit->hlt_sensor_state = unit->mlt_sensor_state = 1; // missing 756 unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL;
713 unit->hlt_heater_state = unit->mlt_heater_state = unit->mlt_pump_state = 0; 757 unit->hlt_heater_mltfirst = 0;
714 unit->hlt_heater_delay = unit->mlt_heater_delay = unit->mlt_pump_delay = 20; /* 5 minutes delay */ 758 unit->pump_cycle = 7;
759 unit->pump_rest = 2;
760 unit->pump_premash = 1;
761 unit->pump_onmash = 1;
762 unit->pump_mashout = 0;
763 unit->pump_onboil = 0;
764 unit->pump_stop = 90;
765 unit->skip_add = 0;
766 unit->skip_remove = 0;
767 unit->skip_iodine = 0;
768 unit->iodine_time = 90;
769 unit->whirlpool = 0;
715 unit->PID_hlt = (pid_var *)malloc(sizeof(pid_var)); 770 unit->PID_hlt = (pid_var *)malloc(sizeof(pid_var));
716 unit->PID_mlt = (pid_var *)malloc(sizeof(pid_var)); 771 unit->PID_mlt = (pid_var *)malloc(sizeof(pid_var));
717 InitPID(unit->PID_hlt); 772 InitPID(unit->PID_hlt);
718 InitPID(unit->PID_mlt); 773 InitPID(unit->PID_mlt);
719 774
733 } 788 }
734 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { 789 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
735 unit->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 790 unit->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
736 } 791 }
737 792
738 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_SENSOR_ADDRESS"))) { 793 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_SENSOR_UUID"))) {
739 unit->hlt_sensor_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 794 if (unit->hlt_sensor == NULL) {
795 unit->hlt_sensor = (sensor_var *)malloc(sizeof(sensor_var));
796 unit->hlt_sensor->uuid[0] = '\0';
797 unit->hlt_sensor->state = 1; // missing
798 unit->hlt_sensor->value = 0;
799 }
800 snprintf(unit->hlt_sensor->uuid, 36, "%s", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
740 } 801 }
741 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_SENSOR_STATE"))) { 802 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_SENSOR_STATE"))) {
742 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 803 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
743 if (sscanf((const char *)key, "%d", &ival) == 1) 804 if (sscanf((const char *)key, "%d", &ival) == 1)
744 unit->hlt_sensor_state = ival; 805 unit->hlt_sensor->state = ival;
745 xmlFree(key); 806 xmlFree(key);
746 } 807 }
747 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_SENSOR_VALUE"))) { 808 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_SENSOR_VALUE"))) {
748 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 809 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
749 if (sscanf((const char *)key, "%d", &ival) == 1) 810 if (sscanf((const char *)key, "%d", &ival) == 1)
750 unit->hlt_sensor_value = ival; 811 unit->hlt_sensor->value = ival;
751 xmlFree(key); 812 xmlFree(key);
752 } 813 }
753 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_ADDRESS"))) { 814
754 unit->hlt_heater_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 815 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_UUID"))) {
755 } 816 if (unit->hlt_heater == NULL) {
817 unit->hlt_heater = (switch_var *)malloc(sizeof(switch_var));
818 unit->hlt_heater->uuid[0] = '\0';
819 unit->hlt_heater->value = 0;
820 unit->hlt_heater->delay = 1; // 15 seconds
821 }
822 snprintf(unit->hlt_heater->uuid, 36, "%s", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
823 }
824 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_VALUE"))) {
825 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
826 if (sscanf((const char *)key, "%d", &ival) == 1)
827 unit->hlt_heater->value = ival;
828 xmlFree(key);
829 }
756 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_DELAY"))) { 830 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_DELAY"))) {
757 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 831 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
758 if (sscanf((const char *)key, "%d", &ival) == 1) 832 if (sscanf((const char *)key, "%d", &ival) == 1)
759 unit->hlt_heater_delay = ival; 833 unit->hlt_heater->delay = ival;
760 xmlFree(key); 834 xmlFree(key);
761 } 835 }
762 836
763 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_SENSOR_ADDRESS"))) { 837 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_MLTFIRST"))) {
764 unit->mlt_sensor_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 838 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
839 if (sscanf((const char *)key, "%d", &ival) == 1)
840 unit->hlt_heater_mltfirst = ival;
841 xmlFree(key);
842 }
843
844 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_SENSOR_UUID"))) {
845 if (unit->mlt_sensor == NULL) {
846 unit->mlt_sensor = (sensor_var *)malloc(sizeof(sensor_var));
847 unit->mlt_sensor->uuid[0] = '\0';
848 unit->mlt_sensor->state = 1; // missing
849 unit->mlt_sensor->value = 0;
850 }
851 snprintf(unit->mlt_sensor->uuid, 36, "%s", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
765 } 852 }
766 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_SENSOR_STATE"))) { 853 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_SENSOR_STATE"))) {
767 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 854 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
768 if (sscanf((const char *)key, "%d", &ival) == 1) 855 if (sscanf((const char *)key, "%d", &ival) == 1)
769 unit->mlt_sensor_state = ival; 856 unit->mlt_sensor->state = ival;
770 xmlFree(key); 857 xmlFree(key);
771 } 858 }
772 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_SENSOR_VALUE"))) { 859 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_SENSOR_VALUE"))) {
773 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 860 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
774 if (sscanf((const char *)key, "%d", &ival) == 1) 861 if (sscanf((const char *)key, "%d", &ival) == 1)
775 unit->mlt_sensor_value = ival; 862 unit->mlt_sensor->value = ival;
776 xmlFree(key); 863 xmlFree(key);
777 } 864 }
778 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_ADDRESS"))) { 865
779 unit->mlt_heater_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 866 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_UUID"))) {
780 } 867 if (unit->mlt_heater == NULL) {
868 unit->mlt_heater = (switch_var *)malloc(sizeof(switch_var));
869 unit->mlt_heater->uuid[0] = '\0';
870 unit->mlt_heater->value = 0;
871 unit->mlt_heater->delay = 1; // 15 seconds
872 }
873 snprintf(unit->mlt_heater->uuid, 36, "%s", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
874 }
875 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_VALUE"))) {
876 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
877 if (sscanf((const char *)key, "%d", &ival) == 1)
878 unit->mlt_heater->value = ival;
879 xmlFree(key);
880 }
781 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_DELAY"))) { 881 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_DELAY"))) {
782 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 882 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
783 if (sscanf((const char *)key, "%d", &ival) == 1) 883 if (sscanf((const char *)key, "%d", &ival) == 1)
784 unit->mlt_heater_delay = ival; 884 unit->mlt_heater->delay = ival;
785 xmlFree(key); 885 xmlFree(key);
786 } 886 }
787 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_PUMP_ADDRESS"))) { 887
788 unit->mlt_pump_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 888 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_PUMP_UUID"))) {
789 } 889 if (unit->mlt_pump == NULL) {
890 unit->mlt_pump = (switch_var *)malloc(sizeof(switch_var));
891 unit->mlt_pump->uuid[0] = '\0';
892 unit->mlt_pump->value = 0;
893 unit->mlt_pump->delay = 1; // 15 seconds
894 }
895 snprintf(unit->mlt_pump->uuid, 36, "%s", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
896 }
897 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_PUMP_VALUE"))) {
898 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
899 if (sscanf((const char *)key, "%d", &ival) == 1)
900 unit->mlt_pump->value = ival;
901 xmlFree(key);
902 }
790 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_PUMP_DELAY"))) { 903 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_PUMP_DELAY"))) {
791 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 904 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
792 if (sscanf((const char *)key, "%d", &ival) == 1) 905 if (sscanf((const char *)key, "%d", &ival) == 1)
793 unit->mlt_pump_delay = ival; 906 unit->mlt_pump->delay = ival;
794 xmlFree(key); 907 xmlFree(key);
795 } 908 }
909
910 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_CYCLE"))) {
911 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
912 if (sscanf((const char *)key, "%d", &ival) == 1)
913 unit->pump_cycle = ival;
914 xmlFree(key);
915 }
916 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_REST"))) {
917 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
918 if (sscanf((const char *)key, "%d", &ival) == 1)
919 unit->pump_rest = ival;
920 xmlFree(key);
921 }
922 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_PREMASH"))) {
923 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
924 if (sscanf((const char *)key, "%d", &ival) == 1)
925 unit->pump_premash = ival;
926 xmlFree(key);
927 }
928 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_ONMASH"))) {
929 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
930 if (sscanf((const char *)key, "%d", &ival) == 1)
931 unit->pump_onmash = ival;
932 xmlFree(key);
933 }
934 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_MASHOUT "))) {
935 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
936 if (sscanf((const char *)key, "%d", &ival) == 1)
937 unit->pump_mashout = ival;
938 xmlFree(key);
939 }
940 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_ONBOIL"))) {
941 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
942 if (sscanf((const char *)key, "%d", &ival) == 1)
943 unit->pump_onboil = ival;
944 xmlFree(key);
945 }
946 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PUMP_STOP"))) {
947 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
948 if (sscanf((const char *)key, "%d", &ival) == 1)
949 unit->pump_stop = ival;
950 xmlFree(key);
951 }
952 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SKIP_ADD"))) {
953 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
954 if (sscanf((const char *)key, "%d", &ival) == 1)
955 unit->skip_add = ival;
956 xmlFree(key);
957 }
958 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SKIP_REMOVE"))) {
959 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
960 if (sscanf((const char *)key, "%d", &ival) == 1)
961 unit->skip_remove = ival;
962 xmlFree(key);
963 }
964 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SKIP_IODINE"))) {
965 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
966 if (sscanf((const char *)key, "%d", &ival) == 1)
967 unit->skip_iodine = ival;
968 xmlFree(key);
969 }
970 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IODINE_TIME"))) {
971 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
972 if (sscanf((const char *)key, "%d", &ival) == 1)
973 unit->iodine_time = ival;
974 xmlFree(key);
975 }
976 if ((!xmlStrcmp(cur->name, (const xmlChar *)"WHIRLPOOL"))) {
977 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
978 for (i = 0; i < 2; i++) {
979 if (! xmlStrcmp(key, (const xmlChar *)WHIRLPOOL_TYPE[i])) {
980 unit->whirlpool = i;
981 break;
982 }
983 }
984 xmlFree(key);
985 }
796 986
797 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_IMAX"))) { 987 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_HLT_IMAX"))) {
798 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 988 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
799 if (sscanf((const char *)key, "%f", &val) == 1) 989 if (sscanf((const char *)key, "%f", &val) == 1)
800 unit->PID_hlt->iMax = val; 990 unit->PID_hlt->iMax = val;
1325 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMPFORMAT"))) { 1515 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMPFORMAT"))) {
1326 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1516 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1327 Config.tempFormat = key[0]; 1517 Config.tempFormat = key[0];
1328 xmlFree(key); 1518 xmlFree(key);
1329 } 1519 }
1330 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TEMP_ADDRESS"))) { 1520 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOMTEMP_UUID"))) {
1331 Config.temp_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1521 if (Config.roomtemp == NULL) {
1332 } 1522 Config.roomtemp = (sensor_var *)malloc(sizeof(sensor_var));
1333 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HUM_ADDRESS"))) { 1523 Config.roomtemp->uuid[0] = '\0';
1334 Config.hum_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1524 Config.roomtemp->state = 1; // missing
1525 Config.roomtemp->value = 0;
1526 }
1527 snprintf(Config.roomtemp->uuid, 36, "%s", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
1335 } 1528 }
1336 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) { 1529 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) {
1337 parseLCDs(doc, cur); 1530 parseLCDs(doc, cur);
1338 } 1531 }
1339 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BREWSYSTEMS"))) { 1532 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BREWSYSTEMS"))) {

mercurial