Sat, 26 Dec 2015 21:45:44 +0100
The brew state machine is complete, works but is not bugfree
441 | 1 | /***************************************************************************** |
2 | * Copyright (C) 2015 | |
3 | * | |
4 | * Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
6 | * This file is part of the mbsePi-apps | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * mbsePi-apps is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
21 | *****************************************************************************/ | |
22 | ||
23 | #include "brewco.h" | |
24 | #include "rdsession.h" | |
446
78e9d5234d15
Switched to PID code from Arduino
Michiel Broek <mbroek@mbse.eu>
parents:
444
diff
changeset
|
25 | #include "util.h" |
441 | 26 | #include "xutil.h" |
27 | ||
28 | extern int debug; | |
464
4a624c071ca9
Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents:
446
diff
changeset
|
29 | extern char *etcpath; |
441 | 30 | |
31 | ||
473
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
32 | const char BREWSTEP[16][10] = { "NA", "INIT", "WATEROK", "PRIME", "WAITSTART", |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
33 | "PREMASH", "MASHING", "REMOVE", "PREBOIL", "BOIL", |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
34 | "BOILDONE", "COOLING", "HOPSTAND", "WHIRLPOOL", "CLEANUP", |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
35 | "DONE" }; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
36 | const char MASHSTEP[8][11] = { "MASH-IN", "PHYTASE", "GLUCANASE", "PROTEASE", "B-AMYLASE", "A-AMYLASE1", "A-AMYLASE2", "MASH-OUT" }; |
441 | 37 | |
38 | #define MY_ENCODING "utf-8" | |
39 | ||
40 | ||
41 | int do_wrsession(brew_session *brew); | |
42 | int do_wrsession(brew_session *brew) | |
43 | { | |
44 | int rc = 0; | |
45 | FILE *fp; | |
46 | char *mypath = NULL; | |
47 | xmlTextWriterPtr writer; | |
48 | xmlBufferPtr buf; | |
49 | ||
50 | /* | |
51 | * Create a new XML buffer, to which the XML document will be written | |
52 | */ | |
53 | if ((buf = xmlBufferCreate()) == NULL) { | |
54 | syslog(LOG_NOTICE, "wrsession: error creating the xml buffer"); | |
55 | return 1; | |
56 | } | |
57 | ||
58 | /* | |
59 | * Create a new XmlWriter for memory, with no compression. | |
60 | */ | |
61 | if ((writer = xmlNewTextWriterMemory(buf, 0)) == NULL) { | |
62 | syslog(LOG_NOTICE, "wrsession: error creating the xml writer"); | |
63 | return 1; | |
64 | } | |
65 | ||
66 | /* | |
67 | * Use indentation instead of one long line | |
68 | */ | |
69 | if ((rc = xmlTextWriterSetIndent(writer, 2)) < 0) { | |
70 | syslog(LOG_NOTICE, "wrsession: error setting Indent"); | |
71 | return 1; | |
72 | } | |
73 | ||
74 | /* | |
75 | * Start the document with the xml default for the version, | |
76 | * encoding ISO 8859-1 and the default for the standalone | |
77 | * declaration. | |
78 | */ | |
79 | if ((rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL)) < 0) { | |
80 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartDocument"); | |
81 | return 1; | |
82 | } | |
83 | ||
84 | /* | |
85 | * Start an element named "BREWCO". Since thist is the first | |
86 | * element, this will be the root element of the document. | |
87 | */ | |
473
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
88 | if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREWCO")) < 0) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
89 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartElement"); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
90 | return 1; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
91 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
92 | if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "BREW")) < 0) { |
441 | 93 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterStartElement"); |
94 | return 1; | |
95 | } | |
96 | ||
97 | /* | |
98 | * Add an attribute with name "VERSION" and value "1" to BRWCO. | |
99 | */ | |
100 | if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) { | |
101 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); | |
102 | return 1; | |
103 | } | |
104 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID_RECIPE", "%s", brew->uuid_recipe)) < 0) { | |
105 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteFormatElement"); | |
106 | return 1; | |
107 | } | |
108 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID_UNIT", "%s", brew->uuid_unit)) < 0) { | |
109 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteFormatElement"); | |
110 | return 1; | |
111 | } | |
472
55bcbf92ecab
Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents:
470
diff
changeset
|
112 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", brew->name)) < 0) { |
55bcbf92ecab
Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents:
470
diff
changeset
|
113 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteFormatElement"); |
55bcbf92ecab
Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents:
470
diff
changeset
|
114 | return 1; |
55bcbf92ecab
Added initial part of the brew automation.
Michiel Broek <mbroek@mbse.eu>
parents:
470
diff
changeset
|
115 | } |
444
eafb140a1ddd
Better brew state field names.
Michiel Broek <mbroek@mbse.eu>
parents:
441
diff
changeset
|
116 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BREWSTEP", "%s", BREWSTEP[brew->brewstep])) < 0) { |
441 | 117 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); |
118 | return 1; | |
119 | } | |
444
eafb140a1ddd
Better brew state field names.
Michiel Broek <mbroek@mbse.eu>
parents:
441
diff
changeset
|
120 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MASHSTEP", "%s", MASHSTEP[brew->mashstep])) < 0) { |
441 | 121 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); |
122 | return 1; | |
123 | } | |
444
eafb140a1ddd
Better brew state field names.
Michiel Broek <mbroek@mbse.eu>
parents:
441
diff
changeset
|
124 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TIMEOUT", "%d", brew->timeout)) < 0) { |
441 | 125 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); |
126 | return 1; | |
127 | } | |
128 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BOILTIMER", "%d", brew->boiltimer)) < 0) { | |
129 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); | |
130 | return 1; | |
131 | } | |
132 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "STARTTIME", "%d", (int)brew->starttime)) < 0) { | |
133 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); | |
134 | return 1; | |
135 | } | |
136 | if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENDTIME", "%d", (int)brew->endtime)) < 0) { | |
137 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterWriteElement"); | |
138 | return 1; | |
139 | } | |
140 | ||
473
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
141 | /* |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
142 | * Close the element named BREW. |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
143 | */ |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
144 | if ((rc = xmlTextWriterEndElement(writer)) < 0) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
145 | syslog(LOG_NOTICE, "wrrecipes: error at xmlTextWriterEndElement"); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
146 | return 1; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
147 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
148 | |
441 | 149 | /* |
150 | * All done, close any open elements | |
151 | */ | |
152 | if ((rc = xmlTextWriterEndDocument(writer)) < 0) { | |
153 | syslog(LOG_NOTICE, "wrsession: error at xmlTextWriterEndDocument"); | |
154 | return 1; | |
155 | } | |
156 | xmlFreeTextWriter(writer); | |
157 | ||
158 | /* | |
159 | * Now write the XML configuration | |
160 | */ | |
464
4a624c071ca9
Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents:
446
diff
changeset
|
161 | mypath = xstrcpy(etcpath); |
441 | 162 | mypath = xstrcat(mypath, (char *)"brewing.xml"); |
163 | ||
164 | if (debug) | |
165 | fprintf(stdout, "Writing %s\n", mypath); | |
166 | ||
167 | if ((fp = fopen(mypath, "w")) == NULL) { | |
168 | syslog(LOG_NOTICE, "could not rewrite %s", mypath); | |
169 | free(mypath); | |
170 | return 1; | |
171 | } | |
172 | free(mypath); | |
173 | ||
174 | fprintf(fp, "%s", (const char *) buf->content); | |
175 | fclose(fp); | |
176 | xmlBufferFree(buf); | |
177 | ||
178 | return 0; | |
179 | } | |
180 | ||
181 | ||
182 | ||
183 | int wrsession(brew_session *brew) | |
184 | { | |
185 | int rc; | |
186 | ||
187 | rc = do_wrsession(brew); | |
188 | syslog(LOG_NOTICE, "Rewritten brewsession, rc=%d", rc); | |
189 | return rc; | |
190 | } | |
191 | ||
192 | ||
193 | ||
194 | /* | |
195 | * Returns: | |
196 | * 0 - All is well, session loaded. | |
197 | * 1 - Something went wrong | |
198 | * -1 - No brew session available | |
199 | */ | |
200 | int rdsession(brew_session *brew) | |
201 | { | |
444
eafb140a1ddd
Better brew state field names.
Michiel Broek <mbroek@mbse.eu>
parents:
441
diff
changeset
|
202 | int i, ival; |
441 | 203 | char *mypath; |
204 | xmlDocPtr doc; | |
473
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
205 | xmlNodePtr cur, s1cur; |
441 | 206 | xmlChar *key; |
207 | ||
208 | /* | |
209 | * Search config file | |
210 | */ | |
464
4a624c071ca9
Added file copy. Move home directory detection to the main program function. During opening of the main configuration file, backups are made, 10 revisions in total.
Michiel Broek <mbroek@mbse.eu>
parents:
446
diff
changeset
|
211 | mypath = xstrcpy(etcpath); |
441 | 212 | mypath = xstrcat(mypath, (char *)"brewing.xml"); |
213 | ||
214 | /* | |
215 | * See if we have a brewing state file. | |
216 | */ | |
217 | if (file_exist(mypath, W_OK)) { | |
218 | syslog(LOG_NOTICE, "rdsession: %s not found, good.", mypath); | |
219 | free(mypath); | |
220 | return -1; | |
221 | } | |
222 | ||
223 | if ((doc = xmlParseFile(mypath)) == NULL) { | |
224 | syslog(LOG_NOTICE, "rdsession: %s not found, should not happen.", mypath); | |
225 | free(mypath); | |
226 | return -1; | |
227 | } | |
228 | syslog(LOG_NOTICE, "rdsession: using %s", mypath); | |
229 | ||
230 | if ((cur = xmlDocGetRootElement(doc)) == NULL) { | |
231 | syslog(LOG_NOTICE, "XML file %s empty.", mypath); | |
232 | xmlFreeDoc(doc); | |
233 | return 1; | |
234 | } | |
235 | if (xmlStrcmp(cur->name, (const xmlChar*)"BREWCO")) { | |
236 | syslog(LOG_NOTICE, "XML file %s is not a valid configuration file.", mypath); | |
237 | xmlFreeDoc(doc); | |
238 | return 1; | |
239 | } | |
240 | ||
241 | /* | |
242 | * Parse session | |
243 | */ | |
244 | cur = cur->xmlChildrenNode; | |
245 | while (cur != NULL) { | |
473
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
246 | |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
247 | if ((! xmlStrcmp(cur->name, (const xmlChar*)"BREW"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
248 | s1cur = cur->xmlChildrenNode; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
249 | while (s1cur != NULL) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
250 | |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
251 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"UUID_RECIPE"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
252 | brew->uuid_recipe = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
253 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
254 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"UUID_UNIT"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
255 | brew->uuid_unit = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
444
eafb140a1ddd
Better brew state field names.
Michiel Broek <mbroek@mbse.eu>
parents:
441
diff
changeset
|
256 | } |
473
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
257 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"NAME"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
258 | brew->name = (char *)xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
259 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
260 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"BREWSTEP"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
261 | key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
262 | for (i = 0; i < 15; i++) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
263 | if (! xmlStrcmp(key, (const xmlChar *)BREWSTEP[i])) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
264 | brew->brewstep = i; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
265 | break; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
266 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
267 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
268 | xmlFree(key); |
444
eafb140a1ddd
Better brew state field names.
Michiel Broek <mbroek@mbse.eu>
parents:
441
diff
changeset
|
269 | } |
473
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
270 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"MASHSTEP"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
271 | key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
272 | for (i = 0; i < 8; i++) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
273 | if (! xmlStrcmp(key, (const xmlChar *)MASHSTEP[i])) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
274 | brew->mashstep = i; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
275 | break; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
276 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
277 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
278 | xmlFree(key); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
279 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
280 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"TIMEOUT"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
281 | key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
282 | if (sscanf((const char *)key, "%d", &ival) == 1) |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
283 | brew->timeout = ival; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
284 | xmlFree(key); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
285 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
286 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"BOILTIMER"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
287 | key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
288 | if (sscanf((const char *)key, "%d", &ival) == 1) |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
289 | brew->boiltimer = ival; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
290 | xmlFree(key); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
291 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
292 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"STARTTIME"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
293 | key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
294 | if (sscanf((const char *)key, "%d", &ival) == 1) |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
295 | brew->starttime = (time_t)ival; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
296 | xmlFree(key); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
297 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
298 | if ((!xmlStrcmp(s1cur->name, (const xmlChar *)"ENDTIME"))) { |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
299 | key = xmlNodeListGetString(doc, s1cur->xmlChildrenNode, 1); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
300 | if (sscanf((const char *)key, "%d", &ival) == 1) |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
301 | brew->endtime = (time_t)ival; |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
302 | xmlFree(key); |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
303 | } |
fdd30e935079
The brew state machine is complete, works but is not bugfree
Michiel Broek <mbroek@mbse.eu>
parents:
472
diff
changeset
|
304 | s1cur = s1cur->next; |
444
eafb140a1ddd
Better brew state field names.
Michiel Broek <mbroek@mbse.eu>
parents:
441
diff
changeset
|
305 | } |
441 | 306 | } |
307 | cur = cur->next; | |
308 | } | |
309 | xmlFreeDoc(doc); | |
310 | ||
311 | free(mypath); | |
312 | mypath = NULL; | |
313 | ||
314 | return 0; | |
315 | } | |
316 | ||
317 | ||
318 |