600 return 1; |
589 return 1; |
601 } |
590 } |
602 } |
591 } |
603 |
592 |
604 #ifdef USE_SIMULATOR |
593 #ifdef USE_SIMULATOR |
605 if (Config.simulators) { |
594 if (Config.simulator) { |
606 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "SIMULATORS")) < 0) { |
595 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "SIMULATOR")) < 0) { |
607 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); |
596 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); |
|
597 return 1; |
|
598 } |
|
599 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_TEMPERATURE", "%f", Config.simulator->room_temperature)) < 0) { |
|
600 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
608 return 1; |
601 return 1; |
609 } |
602 } |
610 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
603 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_TEMPERATURE", "%f", Config.simulator->hlt_temperature)) < 0) { |
611 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "SIMULATOR")) < 0) { |
604 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
612 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); |
605 return 1; |
613 return 1; |
606 } |
614 } |
607 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_TEMP", "%f", Config.simulator->hlt_heater_temp)) < 0) { |
615 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VERSION", "%d", simulator->version)) < 0) { |
608 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
616 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
609 return 1; |
617 return 1; |
610 } |
618 } |
611 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_TIME", "%d", Config.simulator->hlt_heater_time)) < 0) { |
619 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", simulator->uuid)) < 0) { |
612 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
620 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
613 return 1; |
621 return 1; |
614 } |
622 } |
615 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_SIZE", "%f", Config.simulator->hlt_heater_size)) < 0) { |
623 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", simulator->name)) < 0) { |
616 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
624 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); |
617 return 1; |
625 return 1; |
618 } |
626 } |
619 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_STATE", "%d", Config.simulator->hlt_heater_state)) < 0) { |
627 |
620 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
628 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
621 return 1; |
629 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); |
622 } |
630 return 1; |
623 |
631 } |
624 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_TEMPERATURE", "%f", Config.simulator->mlt_temperature)) < 0) { |
632 } |
625 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
626 return 1; |
|
627 } |
|
628 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_TEMP", "%f", Config.simulator->mlt_heater_temp)) < 0) { |
|
629 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
630 return 1; |
|
631 } |
|
632 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_TIME", "%d", Config.simulator->mlt_heater_time)) < 0) { |
|
633 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
634 return 1; |
|
635 } |
|
636 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_SIZE", "%f", Config.simulator->mlt_heater_size)) < 0) { |
|
637 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
638 return 1; |
|
639 } |
|
640 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_STATE", "%d", Config.simulator->mlt_heater_state)) < 0) { |
|
641 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
642 return 1; |
|
643 } |
|
644 |
|
645 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HLT_TEMP", "%f", Config.simulator->s_hlt_temp)) < 0) { |
|
646 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
647 return 1; |
|
648 } |
|
649 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_MLT_TEMP", "%f", Config.simulator->s_mlt_temp)) < 0) { |
|
650 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); |
|
651 return 1; |
|
652 } |
|
653 |
633 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
654 if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
634 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); |
655 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); |
635 return 1; |
656 return 1; |
636 } |
657 } |
637 } |
658 } |
1297 |
1318 |
1298 #ifdef USE_SIMULATOR |
1319 #ifdef USE_SIMULATOR |
1299 int parseSimulator(xmlDocPtr doc, xmlNodePtr cur) |
1320 int parseSimulator(xmlDocPtr doc, xmlNodePtr cur) |
1300 { |
1321 { |
1301 xmlChar *key; |
1322 xmlChar *key; |
1302 simulator_list *simulator, *tmp; |
|
1303 int ival; |
1323 int ival; |
1304 float fval; |
1324 float fval; |
1305 |
1325 |
1306 simulator = (simulator_list *)malloc(sizeof(simulator_list)); |
1326 /* |
1307 simulator->next = NULL; |
1327 * First time, allocate memory and set defaults. |
1308 simulator->version = 1; |
1328 */ |
1309 simulator->uuid = simulator->name = NULL; |
1329 if (! Config.simulator) { |
1310 simulator->room_temperature = simulator->hlt_heater_temp = simulator->mlt_heater_temp = simulator->s_hlt_temp = simulator->s_mlt_temp = 20.0; |
1330 Config.simulator = (simulator_var *)malloc(sizeof(simulator_var)); |
1311 simulator->hlt_heater_temp = simulator->hlt_heater_size = simulator->mlt_heater_temp = simulator->mlt_heater_size = 0.0; |
1331 Config.simulator->room_temperature = Config.simulator->hlt_temperature = Config.simulator->hlt_heater_temp = \ |
1312 simulator->hlt_heater_time = simulator->mlt_heater_time = simulator->hlt_heater_state = simulator->mlt_heater_state = 0; |
1332 Config.simulator->mlt_temperature = Config.simulator->mlt_heater_temp = \ |
1313 simulator->s_hlt_temp = simulator->s_mlt_temp = 0.0; |
1333 Config.simulator->s_hlt_temp = Config.simulator->s_mlt_temp = 0.0; |
|
1334 Config.simulator->hlt_heater_size = Config.simulator->mlt_heater_size = 0.0; |
|
1335 Config.simulator->hlt_heater_time = Config.simulator->mlt_heater_time = Config.simulator->hlt_heater_state = Config.simulator->mlt_heater_state = 0; |
|
1336 } |
1314 |
1337 |
1315 cur = cur->xmlChildrenNode; |
1338 cur = cur->xmlChildrenNode; |
1316 while (cur != NULL) { |
1339 while (cur != NULL) { |
1317 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) { |
|
1318 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1319 if (xmlStrcmp(key, (const xmlChar *)"1")) { |
|
1320 xmlFree(key); |
|
1321 return 1; |
|
1322 } |
|
1323 simulator->version = 1; |
|
1324 xmlFree(key); |
|
1325 } |
|
1326 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) { |
|
1327 simulator->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1328 } |
|
1329 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { |
|
1330 simulator->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
1331 } |
|
1332 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_TEMPERATURE"))) { |
1340 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ROOM_TEMPERATURE"))) { |
1333 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1341 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1334 if (sscanf((const char *)key, "%f", &fval) == 1) |
1342 if (sscanf((const char *)key, "%f", &fval) == 1) |
1335 simulator->room_temperature = fval; |
1343 Config.simulator->room_temperature = fval; |
1336 xmlFree(key); |
1344 xmlFree(key); |
1337 } |
1345 } |
1338 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_TEMPERATURE"))) { |
1346 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_TEMPERATURE"))) { |
1339 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1347 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1340 if (sscanf((const char *)key, "%f", &fval) == 1) |
1348 if (sscanf((const char *)key, "%f", &fval) == 1) |
1341 simulator->hlt_temperature = fval; |
1349 Config.simulator->hlt_temperature = fval; |
1342 xmlFree(key); |
1350 xmlFree(key); |
1343 } |
1351 } |
1344 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_TEMP"))) { |
1352 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_TEMP"))) { |
1345 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1353 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1346 if (sscanf((const char *)key, "%f", &fval) == 1) |
1354 if (sscanf((const char *)key, "%f", &fval) == 1) |
1347 simulator->hlt_heater_temp = fval; |
1355 Config.simulator->hlt_heater_temp = fval; |
1348 xmlFree(key); |
1356 xmlFree(key); |
1349 } |
1357 } |
1350 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_TIME"))) { |
1358 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_TIME"))) { |
1351 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1359 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1352 if (sscanf((const char *)key, "%d", &ival) == 1) |
1360 if (sscanf((const char *)key, "%d", &ival) == 1) |
1353 simulator->hlt_heater_time = ival; |
1361 Config.simulator->hlt_heater_time = ival; |
1354 xmlFree(key); |
1362 xmlFree(key); |
1355 } |
1363 } |
1356 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_SIZE"))) { |
1364 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_SIZE"))) { |
1357 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1365 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1358 if (sscanf((const char *)key, "%f", &fval) == 1) |
1366 if (sscanf((const char *)key, "%f", &fval) == 1) |
1359 simulator->hlt_heater_size = fval; |
1367 Config.simulator->hlt_heater_size = fval; |
1360 xmlFree(key); |
1368 xmlFree(key); |
1361 } |
1369 } |
1362 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_STATE"))) { |
1370 if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_STATE"))) { |
1363 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1371 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1364 if (sscanf((const char *)key, "%d", &ival) == 1) |
1372 if (sscanf((const char *)key, "%d", &ival) == 1) |
1365 simulator->hlt_heater_state = ival; |
1373 Config.simulator->hlt_heater_state = ival; |
1366 xmlFree(key); |
1374 xmlFree(key); |
1367 } |
1375 } |
1368 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_TEMPERATURE"))) { |
1376 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_TEMPERATURE"))) { |
1369 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1377 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1370 if (sscanf((const char *)key, "%f", &fval) == 1) |
1378 if (sscanf((const char *)key, "%f", &fval) == 1) |
1371 simulator->mlt_temperature = fval; |
1379 Config.simulator->mlt_temperature = fval; |
1372 xmlFree(key); |
1380 xmlFree(key); |
1373 } |
1381 } |
1374 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_TEMP"))) { |
1382 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_TEMP"))) { |
1375 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1383 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1376 if (sscanf((const char *)key, "%f", &fval) == 1) |
1384 if (sscanf((const char *)key, "%f", &fval) == 1) |
1377 simulator->mlt_heater_temp = fval; |
1385 Config.simulator->mlt_heater_temp = fval; |
1378 xmlFree(key); |
1386 xmlFree(key); |
1379 } |
1387 } |
1380 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_TIME"))) { |
1388 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_TIME"))) { |
1381 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1389 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1382 if (sscanf((const char *)key, "%d", &ival) == 1) |
1390 if (sscanf((const char *)key, "%d", &ival) == 1) |
1383 simulator->mlt_heater_time = ival; |
1391 Config.simulator->mlt_heater_time = ival; |
1384 xmlFree(key); |
1392 xmlFree(key); |
1385 } |
1393 } |
1386 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_SIZE"))) { |
1394 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_SIZE"))) { |
1387 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1395 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1388 if (sscanf((const char *)key, "%f", &fval) == 1) |
1396 if (sscanf((const char *)key, "%f", &fval) == 1) |
1389 simulator->mlt_heater_size = fval; |
1397 Config.simulator->mlt_heater_size = fval; |
1390 xmlFree(key); |
1398 xmlFree(key); |
1391 } |
1399 } |
1392 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_STATE"))) { |
1400 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_STATE"))) { |
1393 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1401 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1394 if (sscanf((const char *)key, "%d", &ival) == 1) |
1402 if (sscanf((const char *)key, "%d", &ival) == 1) |
1395 simulator->mlt_heater_state = ival; |
1403 Config.simulator->mlt_heater_state = ival; |
1396 xmlFree(key); |
1404 xmlFree(key); |
1397 } |
1405 } |
1398 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_HLT_TEMP"))) { |
1406 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_HLT_TEMP"))) { |
1399 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1407 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1400 if (sscanf((const char *)key, "%f", &fval) == 1) |
1408 if (sscanf((const char *)key, "%f", &fval) == 1) |
1401 simulator->s_hlt_temp = fval; |
1409 Config.simulator->s_hlt_temp = fval; |
1402 xmlFree(key); |
1410 xmlFree(key); |
1403 } |
1411 } |
1404 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_MLT_TEMP"))) { |
1412 if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_MLT_TEMP"))) { |
1405 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1413 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
1406 if (sscanf((const char *)key, "%f", &fval) == 1) |
1414 if (sscanf((const char *)key, "%f", &fval) == 1) |
1407 simulator->s_mlt_temp = fval; |
1415 Config.simulator->s_mlt_temp = fval; |
1408 xmlFree(key); |
1416 xmlFree(key); |
1409 } |
1417 } |
1410 cur = cur->next; |
1418 cur = cur->next; |
1411 } |
1419 } |
1412 |
1420 |
1413 if (Config.simulators == NULL) { |
|
1414 Config.simulators = simulator; |
|
1415 } else { |
|
1416 for (tmp = Config.simulators; tmp; tmp = tmp->next) { |
|
1417 if (tmp->next == NULL) { |
|
1418 tmp->next = simulator; |
|
1419 break; |
|
1420 } |
|
1421 } |
|
1422 } |
|
1423 |
|
1424 return 0; |
|
1425 } |
|
1426 |
|
1427 |
|
1428 |
|
1429 int parseSimulators(xmlDocPtr doc, xmlNodePtr cur) |
|
1430 { |
|
1431 cur = cur->xmlChildrenNode; |
|
1432 while (cur != NULL) { |
|
1433 if ((!xmlStrcmp(cur->name, (const xmlChar *)"SIMULATOR"))) { |
|
1434 parseSimulator(doc, cur); |
|
1435 } |
|
1436 cur = cur->next; |
|
1437 } |
|
1438 return 0; |
1421 return 0; |
1439 } |
1422 } |
1440 #endif |
1423 #endif |
1441 |
1424 |
1442 |
1425 |