32 #define MY_ENCODING "utf-8" |
32 #define MY_ENCODING "utf-8" |
33 |
33 |
34 const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" }; |
34 const char TEMPSTATE[3][8] = { "OK", "MISSING", "ERROR" }; |
35 const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; |
35 const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" }; |
36 const char PROFSTATE[5][6] = { "OFF", "PAUSE", "RUN", "DONE", "ABORT" }; |
36 const char PROFSTATE[5][6] = { "OFF", "PAUSE", "RUN", "DONE", "ABORT" }; |
37 const char DEVTYPE[7][6] = { "NA", "W1", "GPIO", "RC433", "DHT", "I2C", "SPI" }; |
37 const char DEVTYPE[8][6] = { "NA", "W1", "GPIO", "RC433", "DHT", "I2C", "SPI", "SIM" }; |
38 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; |
38 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; |
39 const char DEVDIR[7][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM", "INTERN" }; |
39 const char DEVDIR[7][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM", "INTERN" }; |
40 |
40 |
41 |
41 |
42 |
42 |
583 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterEndElement"); |
600 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterEndElement"); |
584 return 1; |
601 return 1; |
585 } |
602 } |
586 } |
603 } |
587 |
604 |
|
605 #ifdef USE_SIMULATOR |
|
606 if (Config.simulators) { |
|
607 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "SIMULATORS")) < 0) { |
|
608 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterStartElement"); |
|
609 return 1; |
|
610 } |
|
611 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
|
612 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "SIMULATOR")) < 0) { |
|
613 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterStartElement"); |
|
614 return 1; |
|
615 } |
|
616 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VERSION", "%d", simulator->version)) < 0) { |
|
617 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
618 return 1; |
|
619 } |
|
620 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", simulator->uuid)) < 0) { |
|
621 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
622 return 1; |
|
623 } |
|
624 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", simulator->name)) < 0) { |
|
625 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
|
626 return 1; |
|
627 } |
|
628 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_AIR", "%d", simulator->volume_air)) < 0) { |
|
629 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
630 return 1; |
|
631 } |
|
632 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_BEER", "%d", simulator->volume_beer)) < 0) { |
|
633 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
634 return 1; |
|
635 } |
|
636 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_TEMPERATURE", "%.1f", simulator->room_temperature)) < 0) { |
|
637 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
638 return 1; |
|
639 } |
|
640 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%.1f", simulator->air_temperature)) < 0) { |
|
641 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
642 return 1; |
|
643 } |
|
644 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%.1f", simulator->beer_temperature)) < 0) { |
|
645 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
646 return 1; |
|
647 } |
|
648 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TEMP", "%.1f", simulator->cooler_temp)) < 0) { |
|
649 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
650 return 1; |
|
651 } |
|
652 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TIME", "%d", simulator->cooler_time)) < 0) { |
|
653 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
654 return 1; |
|
655 } |
|
656 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_SIZE", "%.3f", simulator->cooler_size)) < 0) { |
|
657 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
658 return 1; |
|
659 } |
|
660 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TEMP", "%.1f", simulator->heater_temp)) < 0) { |
|
661 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
662 return 1; |
|
663 } |
|
664 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TIME", "%d", simulator->heater_time)) < 0) { |
|
665 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
666 return 1; |
|
667 } |
|
668 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_SIZE", "%.3f", simulator->heater_size)) < 0) { |
|
669 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
670 return 1; |
|
671 } |
|
672 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_STATE", "%d", simulator->heater_state)) < 0) { |
|
673 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
674 return 1; |
|
675 } |
|
676 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_STATE", "%d", simulator->cooler_state)) < 0) { |
|
677 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
678 return 1; |
|
679 } |
|
680 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIGO_ISOLATION", "%.3f", simulator->frigo_isolation)) < 0) { |
|
681 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
682 return 1; |
|
683 } |
|
684 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_HEAT", "%.1f", simulator->s_yeast_heat)) < 0) { |
|
685 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
686 return 1; |
|
687 } |
|
688 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_STARTED", "%d", (int)simulator->s_yeast_started)) < 0) { |
|
689 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
690 return 1; |
|
691 } |
|
692 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_COOL_TEMP", "%.1f", simulator->s_cool_temp)) < 0) { |
|
693 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
694 return 1; |
|
695 } |
|
696 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HEAT_TEMP", "%.1f", simulator->s_heat_temp)) < 0) { |
|
697 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
698 return 1; |
|
699 } |
|
700 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_COOL_CHANGED", "%d", (int)simulator->s_cool_changed)) < 0) { |
|
701 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
702 return 1; |
|
703 } |
|
704 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HEAT_CHANGED", "%d", (int)simulator->s_heat_changed)) < 0) { |
|
705 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterWriteElement"); |
|
706 return 1; |
|
707 } |
|
708 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
|
709 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterEndElement"); |
|
710 return 1; |
|
711 } |
|
712 } |
|
713 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
|
714 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterEndElement"); |
|
715 return 1; |
|
716 } |
|
717 } |
|
718 #endif |
|
719 |
588 /* |
720 /* |
589 * All done, close any open elements |
721 * All done, close any open elements |
590 */ |
722 */ |
591 if ((rc = xmlTextWriterEndDocument(writer)) < 0) { |
723 if ((rc = xmlTextWriterEndDocument(writer)) < 0) { |
592 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterEndDocument"); |
724 syslog(LOG_WARNING, "wrconfig: error at xmlTextWriterEndDocument"); |
1167 } |
1299 } |
1168 cur = cur->next; |
1300 cur = cur->next; |
1169 } |
1301 } |
1170 return 0; |
1302 return 0; |
1171 } |
1303 } |
|
1304 |
|
1305 |
|
1306 |
|
1307 #ifdef USE_SIMULATOR |
|
1308 int parseSimulator(xmlDocPtr doc, xmlNodePtr cur) |
|
1309 { |
|
1310 xmlChar *key; |
|
1311 simulator_list *simulator, *tmp; |
|
1312 int ival; |
|
1313 float fval; |
|
1314 |
|
1315 simulator = (simulator_list *)malloc(sizeof(simulator_list)); |
|
1316 simulator->next = NULL; |
|
1317 simulator->version = 1; |
|
1318 simulator->uuid = simulator->name = NULL; |
|
1319 simulator->volume_air = simulator->volume_beer = 0; |
|
1320 simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->s_cool_temp = simulator->s_heat_temp = 20.0; |
|
1321 simulator->cooler_temp = simulator->cooler_size = simulator->heater_temp = simulator->heater_size = simulator->frigo_isolation = 0.0; |
|
1322 simulator->cooler_time = simulator->heater_time = simulator->cooler_state = simulator->heater_state = 0; |
|
1323 simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (time_t)0; |
|
1324 simulator->s_yeast_heat = simulator->s_cool_temp = simulator->s_heat_temp = 0.0; |
|
1325 |
|
1326 cur = cur->xmlChildrenNode; |
|
1327 while (cur != NULL) { |
|
1328 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) { |
|
1329 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1330 if (xmlStrcmp(key, (const xmlChar *)"1")) { |
|
1331 xmlFree(key); |
|
1332 return 1; |
|
1333 } |
|
1334 simulator->version = 1; |
|
1335 xmlFree(key); |
|
1336 } |
|
1337 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) { |
|
1338 simulator->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1339 } |
|
1340 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { |
|
1341 simulator->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1342 } |
|
1343 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VOLUME_AIR"))) { |
|
1344 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1345 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1346 simulator->volume_air = ival; |
|
1347 xmlFree(key); |
|
1348 } |
|
1349 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VOLUME_BEER"))) { |
|
1350 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1351 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1352 simulator->volume_beer = ival; |
|
1353 xmlFree(key); |
|
1354 } |
|
1355 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_TEMPERATURE"))) { |
|
1356 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1357 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1358 simulator->room_temperature = fval; |
|
1359 xmlFree(key); |
|
1360 } |
|
1361 if ((!xmlStrcmp(cur->name, (const xmlChar *)"AIR_TEMPERATURE"))) { |
|
1362 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1363 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1364 simulator->air_temperature = fval; |
|
1365 xmlFree(key); |
|
1366 } |
|
1367 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BEER_TEMPERATURE"))) { |
|
1368 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1369 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1370 simulator->beer_temperature = fval; |
|
1371 xmlFree(key); |
|
1372 } |
|
1373 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_TEMP"))) { |
|
1374 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1375 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1376 simulator->cooler_temp = fval; |
|
1377 xmlFree(key); |
|
1378 } |
|
1379 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_TIME"))) { |
|
1380 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1381 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1382 simulator->cooler_time = ival; |
|
1383 xmlFree(key); |
|
1384 } |
|
1385 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_SIZE"))) { |
|
1386 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1387 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1388 simulator->cooler_size = fval; |
|
1389 xmlFree(key); |
|
1390 } |
|
1391 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_TEMP"))) { |
|
1392 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1393 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1394 simulator->heater_temp = fval; |
|
1395 xmlFree(key); |
|
1396 } |
|
1397 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_TIME"))) { |
|
1398 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1399 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1400 simulator->heater_time = ival; |
|
1401 xmlFree(key); |
|
1402 } |
|
1403 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_SIZE"))) { |
|
1404 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1405 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1406 simulator->heater_size = fval; |
|
1407 xmlFree(key); |
|
1408 } |
|
1409 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_STATE"))) { |
|
1410 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1411 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1412 simulator->heater_state = ival; |
|
1413 xmlFree(key); |
|
1414 } |
|
1415 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_STATE"))) { |
|
1416 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1417 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1418 simulator->cooler_state = ival; |
|
1419 xmlFree(key); |
|
1420 } |
|
1421 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FRIGO_ISOLATION"))) { |
|
1422 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1423 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1424 simulator->frigo_isolation = fval; |
|
1425 xmlFree(key); |
|
1426 } |
|
1427 |
|
1428 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_YEAST_HEAT"))) { |
|
1429 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1430 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1431 simulator->s_yeast_heat = fval; |
|
1432 xmlFree(key); |
|
1433 } |
|
1434 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_YEAST_STARTED"))) { |
|
1435 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1436 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1437 simulator->s_yeast_started = (time_t)ival; |
|
1438 xmlFree(key); |
|
1439 } |
|
1440 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_COOL_TEMP"))) { |
|
1441 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1442 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1443 simulator->s_cool_temp = fval; |
|
1444 xmlFree(key); |
|
1445 } |
|
1446 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_HEAT_TEMP"))) { |
|
1447 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1448 if (sscanf((const char *)key, "%f", &fval) == 1) |
|
1449 simulator->s_heat_temp = fval; |
|
1450 xmlFree(key); |
|
1451 } |
|
1452 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_COOL_CHANGED"))) { |
|
1453 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1454 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1455 simulator->s_cool_changed = (time_t)ival; |
|
1456 xmlFree(key); |
|
1457 } |
|
1458 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_HEAT_CHANGED"))) { |
|
1459 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1460 if (sscanf((const char *)key, "%d", &ival) == 1) |
|
1461 simulator->s_heat_changed = (time_t)ival; |
|
1462 xmlFree(key); |
|
1463 } |
|
1464 |
|
1465 cur = cur->next; |
|
1466 } |
|
1467 |
|
1468 if (Config.simulators == NULL) { |
|
1469 Config.simulators = simulator; |
|
1470 } else { |
|
1471 for (tmp = Config.simulators; tmp; tmp = tmp->next) { |
|
1472 if (tmp->next == NULL) { |
|
1473 tmp->next = simulator; |
|
1474 break; |
|
1475 } |
|
1476 } |
|
1477 } |
|
1478 |
|
1479 return 0; |
|
1480 } |
|
1481 |
|
1482 |
|
1483 |
|
1484 int parseSimulators(xmlDocPtr doc, xmlNodePtr cur) |
|
1485 { |
|
1486 cur = cur->xmlChildrenNode; |
|
1487 while (cur != NULL) { |
|
1488 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SIMULATOR"))) { |
|
1489 parseSimulator(doc, cur); |
|
1490 } |
|
1491 cur = cur->next; |
|
1492 } |
|
1493 return 0; |
|
1494 } |
|
1495 #endif |
1172 |
1496 |
1173 |
1497 |
1174 |
1498 |
1175 int rdconfig(void) |
1499 int rdconfig(void) |
1176 { |
1500 { |