# HG changeset patch # User Michiel Broek # Date 1449235285 -3600 # Node ID eafb140a1ddddec6d14b87adcf9563896b975cde # Parent 6b80a37fdf8d3c1ff991df3d8abbdb917040ccbe Better brew state field names. diff -r 6b80a37fdf8d -r eafb140a1ddd brewco/brewco.c --- a/brewco/brewco.c Wed Dec 02 17:16:41 2015 +0100 +++ b/brewco/brewco.c Fri Dec 04 14:21:25 2015 +0100 @@ -247,7 +247,6 @@ */ prompt(0, NULL); prompt(101, NULL); - prompt(300, (char *)"---\001-\002-\003-\004-\005-\006-\007----"); prompt(401, NULL); key = keywait(); if (key == KEY_ENTER) diff -r 6b80a37fdf8d -r eafb140a1ddd brewco/brewco.h --- a/brewco/brewco.h Wed Dec 02 17:16:41 2015 +0100 +++ b/brewco/brewco.h Fri Dec 04 14:21:25 2015 +0100 @@ -280,6 +280,20 @@ * Brewing state file ~/.brewco/var/brewing.xml * If present a brew session is running */ +#define STEP_NA 0 /* Not in any step yet */ +#define STEP_BREWINIT 1 /* Initialize brew */ +#define STEP_WAITSTART 2 /* Wait for starttime */ +#define STEP_PREMASH 3 /* Pre-mash */ +#define STEP_MASHING 4 /* Mash steps */ +#define STEP_IODINE 5 /* Iodine test */ +#define STEP_MASHREMOVE 6 /* Remove mash */ +#define STEP_PREBOIL 7 /* Heating before boil */ +#define STEP_BOILING 8 /* Boil */ +#define STEP_BOILDONE 9 /* Boil done, hopstand */ +#define STEP_COOLING 10 /* Cooling */ +#define STEP_WHIRLPOOL 11 /* Whirlpool */ +#define STEP_CLEANUP 12 /* Cleanup */ +#define STEP_BREWDONE 13 /* Final step */ #define MAISH_NA 0 /* Not in any state yet */ #define MASIH_PROMPT 1 /* Prompt the user */ @@ -288,21 +302,14 @@ #define MAISH_DONE 4 /* This step is done */ + typedef struct _brew_session { char *uuid_recipe; /* Brewing this recipe */ char *uuid_unit; /* Brewing unit */ - int premash; /* In premash state */ - int mashstep; /* In or into maishstep or -1 */ - int mashstate; /* State this step is in */ - int resttime; /* Rest time downcouner */ - int iodine; /* Mash iodine test */ - int mashremove; /* Mash remove step */ - int boilheating; /* Heat for boiling */ - int boiling; /* Boiling started */ + int brewstep; /* Main steps */ + int mashstep; /* Mash step */ + int timeout; /* Generic time downcouner */ int boiltimer; /* Boiling downcount */ - int cooling; /* Cooling phase */ - int whirlpool; /* Whirlpool phase */ - int cleanup; /* Cleanup phase */ time_t starttime; /* Start of brew */ time_t endtime; /* End of brew */ } brew_session; 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)