brewco/rdsession.c

changeset 444
eafb140a1ddd
parent 441
bde74a8f2ad7
child 446
78e9d5234d15
equal deleted inserted replaced
443:6b80a37fdf8d 444:eafb140a1ddd
26 #include "xutil.h" 26 #include "xutil.h"
27 27
28 extern int debug; 28 extern int debug;
29 29
30 30
31 const char BREWSTEP[14][10] = { "NA", "INIT", "WAITSTART", "PREMASH", "MASHING", "IODINE", "REMOVE", "PREBOIL", "BOIL", "BOILDONE", "COOLING", "WHIRLPOOL", "CLEANUP", "DONE" };
32 const char MASHSTEP[5][8] = { "NA", "PROMPT", "HEATING", "REST", "DONE" };
31 33
32 #define MY_ENCODING "utf-8" 34 #define MY_ENCODING "utf-8"
33 35
34 36
35 int do_wrsession(brew_session *brew); 37 int do_wrsession(brew_session *brew);
97 } 99 }
98 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID_UNIT", "%s", brew->uuid_unit)) < 0) { 100 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID_UNIT", "%s", brew->uuid_unit)) < 0) {
99 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteFormatElement"); 101 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteFormatElement");
100 return 1; 102 return 1;
101 } 103 }
102 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PREMASH", "%d", brew->premash)) < 0) { 104 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BREWSTEP", "%s", BREWSTEP[brew->brewstep])) < 0) {
103 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); 105 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
104 return 1; 106 return 1;
105 } 107 }
106 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHSTEP", "%d", brew->mashstep)) < 0) { 108 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHSTEP", "%s", MASHSTEP[brew->mashstep])) < 0) {
107 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); 109 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
108 return 1; 110 return 1;
109 } 111 }
110 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHSTATE", "%d", brew->mashstate)) < 0) { 112 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TIMEOUT", "%d", brew->timeout)) < 0) {
111 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
112 return 1;
113 }
114 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "RESTTIME", "%d", brew->resttime)) < 0) {
115 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
116 return 1;
117 }
118 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IODINE", "%d", brew->iodine)) < 0) {
119 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
120 return 1;
121 }
122 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHREMOVE", "%d", brew->mashremove)) < 0) {
123 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
124 return 1;
125 }
126 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BOILHEATING", "%d", brew->boilheating)) < 0) {
127 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
128 return 1;
129 }
130 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BOILING", "%d", brew->boiling)) < 0) {
131 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); 113 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
132 return 1; 114 return 1;
133 } 115 }
134 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BOILTIMER", "%d", brew->boiltimer)) < 0) { 116 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BOILTIMER", "%d", brew->boiltimer)) < 0) {
135 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
136 return 1;
137 }
138 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLING", "%d", brew->cooling)) < 0) {
139 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
140 return 1;
141 }
142 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "WHIRLPOOL", "%d", brew->whirlpool)) < 0) {
143 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
144 return 1;
145 }
146 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CLEANUP", "%d", brew->cleanup)) < 0) {
147 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); 117 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
148 return 1; 118 return 1;
149 } 119 }
150 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "STARTTIME", "%d", (int)brew->starttime)) < 0) { 120 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "STARTTIME", "%d", (int)brew->starttime)) < 0) {
151 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); 121 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
213 * 1 - Something went wrong 183 * 1 - Something went wrong
214 * -1 - No brew session available 184 * -1 - No brew session available
215 */ 185 */
216 int rdsession(brew_session *brew) 186 int rdsession(brew_session *brew)
217 { 187 {
218 int ival; 188 int i, ival;
219 char *mypath; 189 char *mypath;
220 xmlDocPtr doc; 190 xmlDocPtr doc;
221 xmlNodePtr cur; 191 xmlNodePtr cur;
222 xmlChar *key; 192 xmlChar *key;
223 193
271 brew->uuid_recipe = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 241 brew->uuid_recipe = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
272 } 242 }
273 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID_UNIT"))) { 243 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID_UNIT"))) {
274 brew->uuid_unit = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 244 brew->uuid_unit = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
275 } 245 }
276 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PREMASH"))) { 246 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BREWSTEP"))) {
247 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
248 for (i = 0; i < 14; i++) {
249 if (! xmlStrcmp(key, (const xmlChar *)BREWSTEP[i])) {
250 brew->brewstep = i;
251 break;
252 }
253 }
254 xmlFree(key);
255 }
256 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHSTEP"))) {
257 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
258 for (i = 0; i < 5; i++) {
259 if (! xmlStrcmp(key, (const xmlChar *)MASHSTEP[i])) {
260 brew->mashstep = i;
261 break;
262 }
263 }
264 xmlFree(key);
265 }
266 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIMEOUT"))) {
277 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 267 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
278 if (sscanf((const char *)key, "%d", &ival) == 1) 268 if (sscanf((const char *)key, "%d", &ival) == 1)
279 brew->premash = ival; 269 brew->timeout = ival;
280 xmlFree(key);
281 }
282 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHSTEP"))) {
283 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
284 if (sscanf((const char *)key, "%d", &ival) == 1)
285 brew->mashstep = ival;
286 xmlFree(key);
287 }
288 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHSTATE"))) {
289 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
290 if (sscanf((const char *)key, "%d", &ival) == 1)
291 brew->mashstate = ival;
292 xmlFree(key);
293 }
294 if ((!xmlStrcmp(cur->name, (const xmlChar *)"RESTTIME"))) {
295 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
296 if (sscanf((const char *)key, "%d", &ival) == 1)
297 brew->resttime = ival;
298 xmlFree(key);
299 }
300 if ((!xmlStrcmp(cur->name, (const xmlChar *)"IODINE"))) {
301 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
302 if (sscanf((const char *)key, "%d", &ival) == 1)
303 brew->iodine = ival;
304 xmlFree(key);
305 }
306 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHREMOVE"))) {
307 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
308 if (sscanf((const char *)key, "%d", &ival) == 1)
309 brew->mashremove = ival;
310 xmlFree(key);
311 }
312 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILHEATING"))) {
313 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
314 if (sscanf((const char *)key, "%d", &ival) == 1)
315 brew->boilheating = ival;
316 xmlFree(key);
317 }
318 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILING"))) {
319 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
320 if (sscanf((const char *)key, "%d", &ival) == 1)
321 brew->boiling = ival;
322 xmlFree(key); 270 xmlFree(key);
323 } 271 }
324 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILTIMER"))) { 272 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILTIMER"))) {
325 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 273 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
326 if (sscanf((const char *)key, "%d", &ival) == 1) 274 if (sscanf((const char *)key, "%d", &ival) == 1)
327 brew->boiltimer = ival; 275 brew->boiltimer = ival;
328 xmlFree(key); 276 xmlFree(key);
329 } 277 }
330 if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLING"))) {
331 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
332 if (sscanf((const char *)key, "%d", &ival) == 1)
333 brew->cooling = ival;
334 xmlFree(key);
335 }
336 if ((!xmlStrcmp(cur->name, (const xmlChar *)"WHIRLPOOL"))) {
337 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
338 if (sscanf((const char *)key, "%d", &ival) == 1)
339 brew->whirlpool = ival;
340 xmlFree(key);
341 }
342 if ((!xmlStrcmp(cur->name, (const xmlChar *)"CLEANUP"))) {
343 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
344 if (sscanf((const char *)key, "%d", &ival) == 1)
345 brew->cleanup = ival;
346 xmlFree(key);
347 }
348 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STARTTIME"))) { 278 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STARTTIME"))) {
349 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 279 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
350 if (sscanf((const char *)key, "%d", &ival) == 1) 280 if (sscanf((const char *)key, "%d", &ival) == 1)
351 brew->starttime = (time_t)ival; 281 brew->starttime = (time_t)ival;
352 xmlFree(key); 282 xmlFree(key);

mercurial