brewco/rdsession.c

changeset 473
fdd30e935079
parent 472
55bcbf92ecab
child 474
fe1c3e3e90dc
equal deleted inserted replaced
472:55bcbf92ecab 473:fdd30e935079
27 27
28 extern int debug; 28 extern int debug;
29 extern char *etcpath; 29 extern char *etcpath;
30 30
31 31
32 const char BREWSTEP[23][11] = { "NA", "INIT", "WATEROK", "PRIME", "WAITSTART", 32 const char BREWSTEP[16][10] = { "NA", "INIT", "WATEROK", "PRIME", "WAITSTART",
33 "PREMASH", "MASHING", "IODINE", "REMOVE", "PREBOIL", 33 "PREMASH", "MASHING", "REMOVE", "PREBOIL", "BOIL",
34 "BOIL", "BOILDONE", "HOPSTAND1", "COOLING1", "WHIRLPOOL1", 34 "BOILDONE", "COOLING", "HOPSTAND", "WHIRLPOOL", "CLEANUP",
35 "COOLING2", "HOPSTAND2", "COOLING3", "HOPSTAND3", "COOLING", 35 "DONE" };
36 "WHIRLPOOL", "CLEANUP", "DONE" }; 36 const char MASHSTEP[8][11] = { "MASH-IN", "PHYTASE", "GLUCANASE", "PROTEASE", "B-AMYLASE", "A-AMYLASE1", "A-AMYLASE2", "MASH-OUT" };
37 const char MASHSTEP[5][8] = { "NA", "PROMPT", "HEATING", "REST", "DONE" };
38 37
39 #define MY_ENCODING "utf-8" 38 #define MY_ENCODING "utf-8"
40 39
41 40
42 int do_wrsession(brew_session *brew); 41 int do_wrsession(brew_session *brew);
84 83
85 /* 84 /*
86 * Start an element named "BREWCO". Since thist is the first 85 * Start an element named "BREWCO". Since thist is the first
87 * element, this will be the root element of the document. 86 * element, this will be the root element of the document.
88 */ 87 */
89 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREWCO_BREW")) < 0) { 88 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREWCO")) < 0) {
89 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartElement");
90 return 1;
91 }
92 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREW")) < 0) {
90 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartElement"); 93 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartElement");
91 return 1; 94 return 1;
92 } 95 }
93 96
94 /* 97 /*
131 return 1; 134 return 1;
132 } 135 }
133 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENDTIME", "%d", (int)brew->endtime)) < 0) { 136 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENDTIME", "%d", (int)brew->endtime)) < 0) {
134 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); 137 syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement");
135 return 1; 138 return 1;
139 }
140
141 /*
142 * Close the element named BREW.
143 */
144 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
145 syslog(LOG_NOTICE, "wrrecipes: error at xmlTextWriterEndElement");
146 return 1;
136 } 147 }
137 148
138 /* 149 /*
139 * All done, close any open elements 150 * All done, close any open elements
140 */ 151 */
189 int rdsession(brew_session *brew) 200 int rdsession(brew_session *brew)
190 { 201 {
191 int i, ival; 202 int i, ival;
192 char *mypath; 203 char *mypath;
193 xmlDocPtr doc; 204 xmlDocPtr doc;
194 xmlNodePtr cur; 205 xmlNodePtr cur, s1cur;
195 xmlChar *key; 206 xmlChar *key;
196 207
197 /* 208 /*
198 * Search config file 209 * Search config file
199 */ 210 */
230 /* 241 /*
231 * Parse session 242 * Parse session
232 */ 243 */
233 cur = cur->xmlChildrenNode; 244 cur = cur->xmlChildrenNode;
234 while (cur != NULL) { 245 while (cur != NULL) {
235 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID_RECIPE"))) { 246
236 brew->uuid_recipe = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 247 if ((! xmlStrcmp(cur->name, (const xmlChar*)"BREW"))) {
237 } 248 s1cur = cur->xmlChildrenNode;
238 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID_UNIT"))) { 249 while (s1cur != NULL) {
239 brew->uuid_unit = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 250
240 } 251 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"UUID_RECIPE"))) {
241 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { 252 brew->uuid_recipe = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
242 brew->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 253 }
243 } 254 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"UUID_UNIT"))) {
244 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BREWSTEP"))) { 255 brew->uuid_unit = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
245 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 256 }
246 for (i = 0; i < 23; i++) { 257 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"NAME"))) {
247 if (! xmlStrcmp(key, (const xmlChar *)BREWSTEP[i])) { 258 brew->name = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
248 brew->brewstep = i; 259 }
249 break; 260 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"BREWSTEP"))) {
250 } 261 key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
262 for (i = 0; i < 15; i++) {
263 if (! xmlStrcmp(key, (const xmlChar *)BREWSTEP[i])) {
264 brew->brewstep = i;
265 break;
266 }
267 }
268 xmlFree(key);
269 }
270 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"MASHSTEP"))) {
271 key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
272 for (i = 0; i < 8; i++) {
273 if (! xmlStrcmp(key, (const xmlChar *)MASHSTEP[i])) {
274 brew->mashstep = i;
275 break;
276 }
277 }
278 xmlFree(key);
279 }
280 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"TIMEOUT"))) {
281 key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
282 if (sscanf((const char *)key, "%d", &ival) == 1)
283 brew->timeout = ival;
284 xmlFree(key);
285 }
286 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"BOILTIMER"))) {
287 key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
288 if (sscanf((const char *)key, "%d", &ival) == 1)
289 brew->boiltimer = ival;
290 xmlFree(key);
291 }
292 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"STARTTIME"))) {
293 key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
294 if (sscanf((const char *)key, "%d", &ival) == 1)
295 brew->starttime = (time_t)ival;
296 xmlFree(key);
297 }
298 if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"ENDTIME"))) {
299 key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1);
300 if (sscanf((const char *)key, "%d", &ival) == 1)
301 brew->endtime = (time_t)ival;
302 xmlFree(key);
303 }
304 s1cur = s1cur->next;
251 } 305 }
252 xmlFree(key);
253 }
254 if ((!xmlStrcmp(cur->name, (const xmlChar *)"MASHSTEP"))) {
255 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
256 for (i = 0; i < 5; i++) {
257 if (! xmlStrcmp(key, (const xmlChar *)MASHSTEP[i])) {
258 brew->mashstep = i;
259 break;
260 }
261 }
262 xmlFree(key);
263 }
264 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TIMEOUT"))) {
265 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
266 if (sscanf((const char *)key, "%d", &ival) == 1)
267 brew->timeout = ival;
268 xmlFree(key);
269 }
270 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BOILTIMER"))) {
271 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
272 if (sscanf((const char *)key, "%d", &ival) == 1)
273 brew->boiltimer = ival;
274 xmlFree(key);
275 }
276 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STARTTIME"))) {
277 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
278 if (sscanf((const char *)key, "%d", &ival) == 1)
279 brew->starttime = (time_t)ival;
280 xmlFree(key);
281 }
282 if ((!xmlStrcmp(cur->name, (const xmlChar *)"ENDTIME"))) {
283 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
284 if (sscanf((const char *)key, "%d", &ival) == 1)
285 brew->endtime = (time_t)ival;
286 xmlFree(key);
287 } 306 }
288 cur = cur->next; 307 cur = cur->next;
289 } 308 }
290 xmlFreeDoc(doc); 309 xmlFreeDoc(doc);
291 310

mercurial