diff -r 6b80a37fdf8d -r eafb140a1ddd brewco/rdsession.c --- a/brewco/rdsession.c Wed Dec 02 17:16:41 2015 +0100 +++ b/brewco/rdsession.c Fri Dec 04 14:21:25 2015 +0100 @@ -28,6 +28,8 @@ extern int debug; +const char BREWSTEP[14][10] = { "NA", "INIT", "WAITSTART", "PREMASH", "MASHING", "IODINE", "REMOVE", "PREBOIL", "BOIL", "BOILDONE", "COOLING", "WHIRLPOOL", "CLEANUP", "DONE" }; +const char MASHSTEP[5][8] = { "NA", "PROMPT", "HEATING", "REST", "DONE" }; #define MY_ENCODING "utf-8" @@ -99,35 +101,15 @@ syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteFormatElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PREMASH", "%d", brew->premash)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BREWSTEP", "%s", BREWSTEP[brew->brewstep])) < 0) { syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHSTEP", "%d", brew->mashstep)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHSTATE", "%d", brew->mashstate)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHSTEP", "%s", MASHSTEP[brew->mashstep])) < 0) { syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "RESTTIME", "%d", brew->resttime)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IODINE", "%d", brew->iodine)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHREMOVE", "%d", brew->mashremove)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BOILHEATING", "%d", brew->boilheating)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BOILING", "%d", brew->boiling)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TIMEOUT", "%d", brew->timeout)) < 0) { syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); return 1; } @@ -135,18 +117,6 @@ syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLING", "%d", brew->cooling)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "WHIRLPOOL", "%d", brew->whirlpool)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CLEANUP", "%d", brew->cleanup)) < 0) { - syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); - return 1; - } if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "STARTTIME", "%d", (int)brew->starttime)) < 0) { syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); return 1; @@ -215,7 +185,7 @@ */ int rdsession(brew_session *brew) { - int ival; + int i, ival; char *mypath; xmlDocPtr doc; xmlNodePtr cur; @@ -273,52 +243,30 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID_UNIT"))) { brew->uuid_unit = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"PREMASH"))) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"BREWSTEP"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->premash = ival; + for (i = 0; i < 14; i++) { + if (! xmlStrcmp(key, (const xmlChar *)BREWSTEP[i])) { + brew->brewstep = i; + break; + } + } xmlFree(key); } if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHSTEP"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->mashstep = ival; + for (i = 0; i < 5; i++) { + if (! xmlStrcmp(key, (const xmlChar *)MASHSTEP[i])) { + brew->mashstep = i; + break; + } + } xmlFree(key); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHSTATE"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->mashstate = ival; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"RESTTIME"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->resttime = ival; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"IODINE"))) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIMEOUT"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) - brew->iodine = ival; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHREMOVE"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->mashremove = ival; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILHEATING"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->boilheating = ival; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILING"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->boiling = ival; + brew->timeout = ival; xmlFree(key); } if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILTIMER"))) { @@ -327,24 +275,6 @@ brew->boiltimer = ival; xmlFree(key); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLING"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->cooling = ival; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"WHIRLPOOL"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->whirlpool = ival; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"CLEANUP"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%d", &ival) == 1) - brew->cleanup = ival; - xmlFree(key); - } if ((!xmlStrcmp(cur->name, (const xmlChar *)"STARTTIME"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1)