thermferm/rdconfig.c

changeset 570
1e0192b295b9
parent 566
776a605befa5
child 578
d694abd9d809
equal deleted inserted replaced
569:9c69d43bfb06 570:1e0192b295b9
1 /***************************************************************************** 1 /*****************************************************************************
2 * Copyright (C) 2014-2018 2 * Copyright (C) 2014-2019
3 * 3 *
4 * Michiel Broek <mbroek at mbse dot eu> 4 * Michiel Broek <mbroek at mbse dot eu>
5 * 5 *
6 * This file is part of the mbsePi-apps 6 * This file is part of the mbsePi-apps
7 * 7 *
39 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" }; 39 const char DEVPRESENT[4][6] = { "UNDEF", "NO", "YES", "ERROR" };
40 const char DEVDIR[7][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM", "INTERN" }; 40 const char DEVDIR[7][11] = { "UNDEF", "IN_BIN", "OUT_BIN", "IN_ANALOG", "OUT_ANALOG", "OUT_PWM", "INTERN" };
41 const char PIDMODE[3][5] = { "NONE", "AUTO", "BOO" }; 41 const char PIDMODE[3][5] = { "NONE", "AUTO", "BOO" };
42 42
43 43
44
45 int parseSteps(xmlDocPtr doc, xmlNodePtr cur, prof_step **step);
46
44 void killconfig(void) 47 void killconfig(void)
45 { 48 {
46 units_list *tmp2, *oldtmp2; 49 units_list *tmp2, *oldtmp2;
47 profiles_list *tmp3, *oldtmp3; 50 prof_step *step, *oldstep;
48 prof_step *tmp4, *oldtmp4;
49 devices_list *device, *olddev; 51 devices_list *device, *olddev;
50 #ifdef USE_SIMULATOR 52 #ifdef USE_SIMULATOR
51 simulator_list *simulator, *oldsim; 53 simulator_list *simulator, *oldsim;
52 #endif 54 #endif
53 55
106 free(tmp2->light_address); 108 free(tmp2->light_address);
107 if (tmp2->door_address) 109 if (tmp2->door_address)
108 free(tmp2->door_address); 110 free(tmp2->door_address);
109 if (tmp2->psu_address) 111 if (tmp2->psu_address)
110 free(tmp2->psu_address); 112 free(tmp2->psu_address);
111 if (tmp2->profile) 113 if (tmp2->profile_uuid)
112 free(tmp2->profile); 114 free(tmp2->profile_uuid);
115 if (tmp2->profile_name)
116 free(tmp2->profile_name);
117 if (tmp2->profile_steps) {
118 for (step = tmp2->profile_steps; step; step = oldstep) {
119 if (step->name)
120 free(step->name);
121 oldstep = step->next;
122 free(step);
123 }
124 }
113 if (tmp2->PID_cool) 125 if (tmp2->PID_cool)
114 free(tmp2->PID_cool); 126 free(tmp2->PID_cool);
115 if (tmp2->PID_heat) 127 if (tmp2->PID_heat)
116 free(tmp2->PID_heat); 128 free(tmp2->PID_heat);
117 free(tmp2); 129 free(tmp2);
118 } 130 }
119 Config.units = NULL; 131 Config.units = NULL;
120
121 for (tmp3 = Config.profiles; tmp3; tmp3 = oldtmp3) {
122 oldtmp3 = tmp3->next;
123 if (tmp3->uuid)
124 free(tmp3->uuid);
125 if (tmp3->name)
126 free(tmp3->name);
127 if (tmp3->steps) {
128 for (tmp4 = tmp3->steps; tmp4; tmp4 = oldtmp4) {
129 oldtmp4 = tmp4->next;
130 free(tmp4);
131 }
132 }
133 free(tmp3);
134 }
135 Config.profiles = NULL;
136 132
137 for (device = Config.devices; device; device = olddev) { 133 for (device = Config.devices; device; device = olddev) {
138 olddev = device->next; 134 olddev = device->next;
139 if (device->uuid) 135 if (device->uuid)
140 free(device->uuid); 136 free(device->uuid);
173 FILE *fp; 169 FILE *fp;
174 char *mypath = NULL; 170 char *mypath = NULL;
175 xmlTextWriterPtr writer; 171 xmlTextWriterPtr writer;
176 xmlBufferPtr buf; 172 xmlBufferPtr buf;
177 units_list *tmp3; 173 units_list *tmp3;
178 profiles_list *tmp4;
179 prof_step *tmp5; 174 prof_step *tmp5;
180 devices_list *device; 175 devices_list *device;
181 #ifdef USE_SIMULATOR 176 #ifdef USE_SIMULATOR
182 simulator_list *simulator; 177 simulator_list *simulator;
183 #endif 178 #endif
206 return 1; 201 return 1;
207 } 202 }
208 203
209 /* 204 /*
210 * Start the document with the xml default for the version, 205 * Start the document with the xml default for the version,
211 * encoding ISO 8859-1 and the default for the standalone 206 * encoding UTF-8 and the default for the standalone declaration.
212 * declaration.
213 */ 207 */
214 if ((rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL)) < 0) { 208 xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
215 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartDocument");
216 return 1;
217 }
218 209
219 /* 210 /*
220 * Start an element named "THERMFERM". Since thist is the first 211 * Start an element named "THERMFERM". Since thist is the first
221 * element, this will be the root element of the document. 212 * element, this will be the root element of the document.
222 */ 213 */
223 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "THERMFERM")) < 0) { 214 xmlTextWriterStartElement(writer, BAD_CAST "THERMFERM");
224 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); 215
225 return 1; 216 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", Config.name);
226 } 217 xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.uuid);
227 218 xmlTextWriterWriteFormatElement(writer, BAD_CAST "LISTEN_PORT", "%d", Config.my_port);
228 /* 219 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat);
229 * Add an attribute with name "VERSION" and value "1" to THERMFERM. 220
230 */ 221 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_ADDRESS", "%s", Config.temp_address);
231 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) { 222 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_STATE", "%d", Config.temp_state);
232 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); 223 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_VALUE", "%d", Config.temp_value);
233 return 1; 224 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_ADDRESS", "%s", Config.hum_address);
234 } 225 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_STATE", "%d", Config.hum_state);
235 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", Config.name)) < 0) { 226 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_VALUE", "%d", Config.hum_value);
236 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 227 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_HUM_IDX", "%d", Config.temp_hum_idx);
237 return 1; 228
238 } 229 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit);
239 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.uuid)) < 0) { 230
240 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 231 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_HOST", "%s", Config.mqtt_host);
241 return 1; 232 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PORT", "%d", Config.mqtt_port);
242 }
243 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LISTEN_PORT", "%d", Config.my_port)) < 0) {
244 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
245 return 1;
246 }
247 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMPFORMAT", "%c", Config.tempFormat)) < 0) {
248 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
249 return 1;
250 }
251 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_ADDRESS", "%s", Config.temp_address)) < 0) {
252 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
253 return 1;
254 }
255 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_STATE", "%d", Config.temp_state)) < 0) {
256 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
257 return 1;
258 }
259 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_VALUE", "%d", Config.temp_value)) < 0) {
260 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
261 return 1;
262 }
263 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_ADDRESS", "%s", Config.hum_address)) < 0) {
264 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
265 return 1;
266 }
267 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_STATE", "%d", Config.hum_state)) < 0) {
268 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
269 return 1;
270 }
271 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HUM_VALUE", "%d", Config.hum_value)) < 0) {
272 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
273 return 1;
274 }
275 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_HUM_IDX", "%d", Config.temp_hum_idx)) < 0) {
276 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
277 return 1;
278 }
279 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NEXT_UNIT", "%d", Config.next_unit)) < 0) {
280 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
281 return 1;
282 }
283 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_HOST", "%s", Config.mqtt_host)) < 0) {
284 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
285 return 1;
286 }
287 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PORT", "%d", Config.mqtt_port)) < 0) {
288 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
289 return 1;
290 }
291 if (Config.mqtt_username && Config.mqtt_password) { 233 if (Config.mqtt_username && Config.mqtt_password) {
292 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_USER", "%s", Config.mqtt_username)) < 0) { 234 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_USER", "%s", Config.mqtt_username);
293 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 235 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PASS", "%s", Config.mqtt_password);
294 return 1;
295 }
296 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MQTT_PASS", "%s", Config.mqtt_password)) < 0) {
297 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
298 return 1;
299 }
300 } 236 }
301 237
302 /* 238 /*
303 * Start an element named "LCDS" as child of THERMFERM. 239 * Start an element named "LCDS" as child of THERMFERM.
304 */ 240 */
305 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCDS")) < 0) { 241 xmlTextWriterStartElement(writer, BAD_CAST "LCDS");
306 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
307 return 1;
308 }
309 /* 242 /*
310 * Start one LCD. It is possible to connect 7 LCD displays on the i2c bus. 243 * Start one LCD. It is possible to connect 7 LCD displays on the i2c bus.
311 * However this program doesn't use more then one yet. 244 * However this program doesn't use more then one yet.
312 */ 245 */
313 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCD")) < 0) { 246 xmlTextWriterStartElement(writer, BAD_CAST "LCD");
314 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); 247 xmlTextWriterWriteFormatElement(writer, BAD_CAST "ADDRESS", "0x%x", Config.lcd_address);
315 return 1; 248 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COLUMNS", "%d", Config.lcd_cols);
316 } 249 xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROWS", "%d", Config.lcd_rows);
317 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) { 250 xmlTextWriterEndElement(writer); // close LCD
318 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); 251 xmlTextWriterEndElement(writer); // close LCDS
319 return 1;
320 }
321 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ADDRESS", "0x%x", Config.lcd_address)) < 0) {
322 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
323 return 1;
324 }
325 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COLUMNS", "%d", Config.lcd_cols)) < 0) {
326 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
327 return 1;
328 }
329 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROWS", "%d", Config.lcd_rows)) < 0) {
330 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
331 return 1;
332 }
333 /*
334 * Close the element named LCD.
335 */
336 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
337 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
338 return 1;
339 }
340 /*
341 * Close the element LCDS.
342 */
343 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
344 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
345 return 1;
346 }
347 252
348 /* 253 /*
349 * Fermenter units 254 * Fermenter units
350 */ 255 */
351 if (Config.units) { 256 if (Config.units) {
352 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "FERMENTERS")) < 0) { 257 xmlTextWriterStartElement(writer, BAD_CAST "FERMENTERS");
353 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
354 return 1;
355 }
356 for (tmp3 = Config.units; tmp3; tmp3 = tmp3->next) { 258 for (tmp3 = Config.units; tmp3; tmp3 = tmp3->next) {
357 /* 259 xmlTextWriterStartElement(writer, BAD_CAST "FERMENTER");
358 * Only configuration items are written, measured values and states 260 xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", tmp3->uuid);
359 * are written to a state file. 261 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_UUID", "%s", tmp3->product_uuid);
360 */ 262 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_CODE", "%s", tmp3->product_code);
361 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "UNIT")) < 0) { 263 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_NAME", "%s", tmp3->product_name);
362 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); 264 xmlTextWriterWriteFormatElement(writer, BAD_CAST "ALIAS", "%s", tmp3->alias);
363 return 1; 265 xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", tmp3->volume);
364 } 266
365 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) {
366 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
367 return 1;
368 }
369 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", tmp3->uuid)) < 0) {
370 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
371 return 1;
372 }
373 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_UUID", "%s", tmp3->product_uuid)) < 0) {
374 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
375 return 1;
376 }
377 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_CODE", "%s", tmp3->product_code)) < 0) {
378 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
379 return 1;
380 }
381 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRODUCT_NAME", "%s", tmp3->product_name)) < 0) {
382 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
383 return 1;
384 }
385 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ALIAS", "%s", tmp3->alias)) < 0) {
386 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
387 return 1;
388 }
389 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", tmp3->volume)) < 0) {
390 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
391 return 1;
392 }
393 if (tmp3->air_address) { 267 if (tmp3->air_address) {
394 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", tmp3->air_address)) < 0)) { 268 xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", tmp3->air_address);
395 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 269 xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_STATE", "%d", tmp3->air_state);
396 return 1; 270 xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%d", tmp3->air_temperature);
397 } 271 xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_IDX", "%d", tmp3->air_idx);
398 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_STATE", "%d", tmp3->air_state)) < 0)) { 272 }
399 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 273 if (tmp3->beer_address) {
400 return 1; 274 xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", tmp3->beer_address);
275 xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_STATE", "%d", tmp3->beer_state);
276 xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%d", tmp3->beer_temperature);
277 xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_IDX", "%d", tmp3->beer_idx);
278 }
279 if (tmp3->chiller_address) {
280 xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_ADDRESS", "%s", tmp3->chiller_address);
281 xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_STATE", "%d", tmp3->chiller_state);
282 xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_TEMPERATURE", "%d", tmp3->chiller_temperature);
283 xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_IDX", "%d", tmp3->chiller_idx);
284 }
285 if (tmp3->heater_address) {
286 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_ADDRESS", "%s", tmp3->heater_address);
287 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_STATE", "%d", tmp3->heater_state);
288 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_DELAY", "%d", tmp3->heater_delay);
289 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_USAGE", "%d", tmp3->heater_usage);
290 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_IDX", "%d", tmp3->heater_idx);
291 }
292 if (tmp3->cooler_address) {
293 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_ADDRESS", "%s", tmp3->cooler_address);
294 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_STATE", "%d", tmp3->cooler_state);
295 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_DELAY", "%d", tmp3->cooler_delay);
296 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_USAGE", "%d", tmp3->cooler_usage);
297 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_IDX", "%d", tmp3->cooler_idx);
298 }
299 if (tmp3->fan_address) {
300 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_ADDRESS", "%s", tmp3->fan_address);
301 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_STATE", "%d", tmp3->fan_state);
302 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_DELAY", "%d", tmp3->fan_delay);
303 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_USAGE", "%d", tmp3->fan_usage);
304 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_IDX", "%d", tmp3->fan_idx);
305 }
306 if (tmp3->light_address) {
307 xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_ADDRESS", "%s", tmp3->light_address);
308 xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_STATE", "%d", tmp3->light_state);
309 xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_DELAY", "%d", tmp3->light_delay);
310 xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_USAGE", "%d", tmp3->light_usage);
311 xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_IDX", "%d", tmp3->light_idx);
312 }
313 if (tmp3->door_address) {
314 xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_ADDRESS", "%s", tmp3->door_address);
315 xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_STATE", "%d", tmp3->door_state);
316 xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_IDX", "%d", tmp3->door_idx);
317 }
318 if (tmp3->psu_address) {
319 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_ADDRESS", "%s", tmp3->psu_address);
320 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_STATE", "%d", tmp3->psu_state);
321 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_IDX", "%d", tmp3->psu_idx);
322 }
323 xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[tmp3->mode] );
324 xmlTextWriterWriteFormatElement(writer, BAD_CAST "STAGE", "%s", UNITSTAGE[tmp3->stage] );
325 xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", tmp3->beer_set);
326 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_SET", "%.1f", tmp3->fridge_set);
327 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MIN", "%.1f", tmp3->temp_set_min);
328 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MAX", "%.1f", tmp3->temp_set_max);
329
330 if (tmp3->profile_uuid) {
331 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE_UUID", "%s", tmp3->profile_uuid);
332 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE_NAME", "%s", tmp3->profile_name);
333 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE_INITTEMP_LO", "%.1f", tmp3->profile_inittemp_lo);
334 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE_INITTEMP_HI", "%.1f", tmp3->profile_inittemp_hi);
335 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE_FRIDGE_MODE", "%d", tmp3->profile_fridge_mode);
336 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE_DURATION", "%d", tmp3->profile_duration);
337 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE_TOTALSTEPS", "%d", tmp3->profile_totalsteps);
338 if (tmp3->profile_steps) {
339 xmlTextWriterStartElement(writer, BAD_CAST "PROFILE_STEPS");
340 for (tmp5 = tmp3->profile_steps; tmp5; tmp5 = tmp5->next) {
341 xmlTextWriterStartElement(writer, BAD_CAST "PROFILE_STEP");
342 if (tmp5->name)
343 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", tmp5->name);
344 xmlTextWriterWriteFormatElement(writer, BAD_CAST "RESTTIME", "%d", tmp5->resttime);
345 xmlTextWriterWriteFormatElement(writer, BAD_CAST "STEPTIME", "%d", tmp5->steptime);
346 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TARGET_LO", "%.1f", tmp5->target_lo);
347 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TARGET_HI", "%.1f", tmp5->target_hi);
348 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_MODE", "%d", tmp5->fridge_mode);
349 xmlTextWriterEndElement(writer); // close PROFILE_STEP
350 }
351 xmlTextWriterEndElement(writer); // close PROFILE_STEPS
401 } 352 }
402 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%d", tmp3->air_temperature)) < 0)) { 353 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_STARTED", "%d", (unsigned int)tmp3->prof_started);
403 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 354 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PAUSED", "%d", (unsigned int)tmp3->prof_paused);
404 return 1; 355 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_STATE", "%s", PROFSTATE[tmp3->prof_state] );
405 } 356 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PEAK_ABS", "%.3f", tmp3->prof_peak_abs);
406 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_IDX", "%d", tmp3->air_idx)) < 0)) { 357 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PEAK_REL", "%.3f", tmp3->prof_peak_rel);
407 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 358 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PRIMARY_DONE", "%d", (unsigned int)tmp3->prof_primary_done);
408 return 1;
409 }
410 }
411 if (tmp3->beer_address) {
412 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", tmp3->beer_address)) < 0)) {
413 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
414 return 1;
415 }
416 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_STATE", "%d", tmp3->beer_state)) < 0)) {
417 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
418 return 1;
419 }
420 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%d", tmp3->beer_temperature)) < 0)) {
421 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
422 return 1;
423 }
424 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_IDX", "%d", tmp3->beer_idx)) < 0)) {
425 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
426 return 1;
427 }
428 }
429 if (tmp3->chiller_address) {
430 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_ADDRESS", "%s", tmp3->chiller_address)) < 0)) {
431 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
432 return 1;
433 }
434 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_STATE", "%d", tmp3->chiller_state)) < 0)) {
435 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
436 return 1;
437 }
438 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_TEMPERATURE", "%d", tmp3->chiller_temperature)) < 0)) {
439 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
440 return 1;
441 }
442 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_IDX", "%d", tmp3->chiller_idx)) < 0)) {
443 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
444 return 1;
445 }
446 }
447 if (tmp3->heater_address) {
448 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_ADDRESS", "%s", tmp3->heater_address)) < 0)) {
449 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
450 return 1;
451 }
452 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_STATE", "%d", tmp3->heater_state)) < 0)) {
453 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
454 return 1;
455 }
456 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_DELAY", "%d", tmp3->heater_delay)) < 0)) {
457 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
458 return 1;
459 }
460 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_USAGE", "%d", tmp3->heater_usage)) < 0)) {
461 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
462 return 1;
463 }
464 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_IDX", "%d", tmp3->heater_idx)) < 0)) {
465 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
466 return 1;
467 }
468 }
469 if (tmp3->cooler_address) {
470 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_ADDRESS", "%s", tmp3->cooler_address)) < 0)) {
471 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
472 return 1;
473 }
474 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_STATE", "%d", tmp3->cooler_state)) < 0)) {
475 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
476 return 1;
477 }
478 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_DELAY", "%d", tmp3->cooler_delay)) < 0)) {
479 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
480 return 1;
481 }
482 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_USAGE", "%d", tmp3->cooler_usage)) < 0)) {
483 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
484 return 1;
485 }
486 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_IDX", "%d", tmp3->cooler_idx)) < 0)) {
487 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
488 return 1;
489 }
490 }
491 if (tmp3->fan_address) {
492 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_ADDRESS", "%s", tmp3->fan_address)) < 0)) {
493 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
494 return 1;
495 }
496 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_STATE", "%d", tmp3->fan_state)) < 0)) {
497 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
498 return 1;
499 }
500 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_DELAY", "%d", tmp3->fan_delay)) < 0)) {
501 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
502 return 1;
503 }
504 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_USAGE", "%d", tmp3->fan_usage)) < 0)) {
505 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
506 return 1;
507 }
508 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_IDX", "%d", tmp3->fan_idx)) < 0)) {
509 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
510 return 1;
511 }
512 }
513 if (tmp3->light_address) {
514 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_ADDRESS", "%s", tmp3->light_address)) < 0)) {
515 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
516 return 1;
517 }
518 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_STATE", "%d", tmp3->light_state)) < 0)) {
519 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
520 return 1;
521 }
522 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_DELAY", "%d", tmp3->light_delay)) < 0)) {
523 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
524 return 1;
525 }
526 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_USAGE", "%d", tmp3->light_usage)) < 0)) {
527 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
528 return 1;
529 }
530 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LIGHT_IDX", "%d", tmp3->light_idx)) < 0)) {
531 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
532 return 1;
533 }
534 }
535 if (tmp3->door_address) {
536 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_ADDRESS", "%s", tmp3->door_address)) < 0)) {
537 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
538 return 1;
539 }
540 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_STATE", "%d", tmp3->door_state)) < 0)) {
541 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
542 return 1;
543 }
544 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_IDX", "%d", tmp3->door_idx)) < 0)) {
545 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
546 return 1;
547 }
548 }
549 if (tmp3->psu_address) {
550 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_ADDRESS", "%s", tmp3->psu_address)) < 0)) {
551 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
552 return 1;
553 }
554 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_STATE", "%d", tmp3->psu_state)) < 0)) {
555 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
556 return 1;
557 }
558 if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PSU_IDX", "%d", tmp3->psu_idx)) < 0)) {
559 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
560 return 1;
561 }
562 }
563 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[tmp3->mode] )) < 0) {
564 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
565 return 1;
566 }
567 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "STAGE", "%s", UNITSTAGE[tmp3->stage] )) < 0) {
568 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
569 return 1;
570 }
571 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", tmp3->beer_set)) < 0) {
572 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
573 return 1;
574 }
575 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_SET", "%.1f", tmp3->fridge_set)) < 0) {
576 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
577 return 1;
578 }
579 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MIN", "%.1f", tmp3->temp_set_min)) < 0) {
580 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
581 return 1;
582 }
583 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MAX", "%.1f", tmp3->temp_set_max)) < 0) {
584 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
585 return 1;
586 }
587 if (tmp3->profile) {
588 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE", "%s", tmp3->profile)) < 0) {
589 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
590 return 1;
591 }
592 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_STARTED", "%d", (unsigned int)tmp3->prof_started)) < 0) {
593 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
594 return 1;
595 }
596 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PAUSED", "%d", (unsigned int)tmp3->prof_paused)) < 0) {
597 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
598 return 1;
599 }
600 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_STATE", "%s", PROFSTATE[tmp3->prof_state] )) < 0) {
601 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
602 return 1;
603 }
604 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PEAK_ABS", "%.3f", tmp3->prof_peak_abs)) < 0) {
605 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
606 return 1;
607 }
608 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PEAK_REL", "%.3f", tmp3->prof_peak_rel)) < 0) {
609 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
610 return 1;
611 }
612 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROF_PRIMARY_DONE", "%d", (unsigned int)tmp3->prof_primary_done)) < 0) {
613 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
614 return 1;
615 }
616 } 359 }
617 if (tmp3->PID_cool) { 360 if (tmp3->PID_cool) {
618 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_IMAX", "%.2f", tmp3->PID_cool->iMax)) < 0) { 361 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_IMAX", "%.2f", tmp3->PID_cool->iMax);
619 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 362 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_IGAIN", "%.3f", tmp3->PID_cool->iGain);
620 return 1; 363 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_PGAIN", "%.3f", tmp3->PID_cool->pGain);
621 } 364 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_DGAIN", "%.3f", tmp3->PID_cool->dGain);
622 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_IGAIN", "%.3f", tmp3->PID_cool->iGain)) < 0) { 365 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_IDLERANGE", "%.2f", tmp3->PID_cool->idleRange);
623 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 366 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_INPUT", "%.2f", tmp3->PID_cool->Input);
624 return 1; 367 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_ERR", "%.2f", tmp3->PID_cool->Err);
625 } 368 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_ISTATE", "%.2f", tmp3->PID_cool->iState);
626 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_PGAIN", "%.3f", tmp3->PID_cool->pGain)) < 0) { 369 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_SETP", "%.2f", tmp3->PID_cool->SetP);
627 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 370 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_OUTP", "%.2f", tmp3->PID_cool->OutP);
628 return 1; 371 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_MODE", "%s", PIDMODE[tmp3->PID_cool->Mode]);
629 } 372 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_TYPE", "COOL");
630 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_DGAIN", "%.3f", tmp3->PID_cool->dGain)) < 0) {
631 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
632 return 1;
633 }
634 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_IDLERANGE", "%.2f", tmp3->PID_cool->idleRange)) < 0) {
635 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
636 return 1;
637 }
638 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_INPUT", "%.2f", tmp3->PID_cool->Input)) < 0) {
639 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
640 return 1;
641 }
642 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_ERR", "%.2f", tmp3->PID_cool->Err)) < 0) {
643 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
644 return 1;
645 }
646 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_ISTATE", "%.2f", tmp3->PID_cool->iState)) < 0) {
647 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
648 return 1;
649 }
650 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_SETP", "%.2f", tmp3->PID_cool->SetP)) < 0) {
651 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
652 return 1;
653 }
654 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_OUTP", "%.2f", tmp3->PID_cool->OutP)) < 0) {
655 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
656 return 1;
657 }
658 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_MODE", "%s", PIDMODE[tmp3->PID_cool->Mode])) < 0) {
659 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
660 return 1;
661 }
662 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDC_TYPE", "COOL")) < 0) {
663 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
664 return 1;
665 }
666 } 373 }
667 if (tmp3->PID_heat) { 374 if (tmp3->PID_heat) {
668 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_IMAX", "%.2f", tmp3->PID_heat->iMax)) < 0) { 375 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_IMAX", "%.2f", tmp3->PID_heat->iMax);
669 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 376 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_IGAIN", "%.3f", tmp3->PID_heat->iGain);
670 return 1; 377 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_PGAIN", "%.3f", tmp3->PID_heat->pGain);
671 } 378 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_DGAIN", "%.3f", tmp3->PID_heat->dGain);
672 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_IDLERANGE", "%.2f", tmp3->PID_heat->idleRange)) < 0) { 379 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_IDLERANGE", "%.2f", tmp3->PID_heat->idleRange);
673 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 380 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_INPUT", "%.2f", tmp3->PID_heat->Input);
674 return 1; 381 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_ERR", "%.2f", tmp3->PID_heat->Err);
675 } 382 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_ISTATE", "%.2f", tmp3->PID_heat->iState);
676 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_IGAIN", "%.3f", tmp3->PID_heat->iGain)) < 0) { 383 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_SETP", "%.2f", tmp3->PID_heat->SetP);
677 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 384 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_OUTP", "%.2f", tmp3->PID_heat->OutP);
678 return 1; 385 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_MODE", "%s", PIDMODE[tmp3->PID_heat->Mode]);
679 } 386 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_TYPE", "HEAT");
680 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_PGAIN", "%.3f", tmp3->PID_heat->pGain)) < 0) { 387 }
681 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 388 xmlTextWriterEndElement(writer); // close FERMENTER
682 return 1; 389 }
683 } 390 xmlTextWriterEndElement(writer); // close FERMENTERS
684 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_DGAIN", "%.3f", tmp3->PID_heat->dGain)) < 0) {
685 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
686 return 1;
687 }
688 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_INPUT", "%.2f", tmp3->PID_heat->Input)) < 0) {
689 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
690 return 1;
691 }
692 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_ERR", "%.2f", tmp3->PID_heat->Err)) < 0) {
693 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
694 return 1;
695 }
696 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_ISTATE", "%.2f", tmp3->PID_heat->iState)) < 0) {
697 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
698 return 1;
699 }
700 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_SETP", "%.2f", tmp3->PID_heat->SetP)) < 0) {
701 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
702 return 1;
703 }
704 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_OUTP", "%.2f", tmp3->PID_heat->OutP)) < 0) {
705 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
706 return 1;
707 }
708 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_MODE", "%s", PIDMODE[tmp3->PID_heat->Mode])) < 0) {
709 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
710 return 1;
711 }
712 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PIDH_TYPE", "HEAT")) < 0) {
713 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
714 return 1;
715 }
716 }
717 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
718 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
719 return 1;
720 }
721 }
722 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
723 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
724 return 1;
725 }
726 }
727
728 /*
729 * Fermenting profiles
730 */
731 if (Config.profiles) {
732 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "PROFILES")) < 0) {
733 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
734 return 1;
735 }
736 for (tmp4 = Config.profiles; tmp4; tmp4 = tmp4->next) {
737 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "PROFILE")) < 0) {
738 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
739 return 1;
740 }
741 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) {
742 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
743 return 1;
744 }
745 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", tmp4->uuid)) < 0) {
746 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
747 return 1;
748 }
749 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", tmp4->name)) < 0) {
750 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
751 return 1;
752 }
753 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BUSY", "%d", tmp4->busy)) < 0) {
754 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
755 return 1;
756 }
757 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "INITTEMP_LO", "%.1f", tmp4->inittemp_lo)) < 0) {
758 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
759 return 1;
760 }
761 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "INITTEMP_HI", "%.1f", tmp4->inittemp_hi)) < 0) {
762 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
763 return 1;
764 }
765 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_MODE", "%d", tmp4->fridge_mode)) < 0) {
766 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
767 return 1;
768 }
769 if (tmp4->steps) {
770 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "STEPS")) < 0) {
771 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
772 return 1;
773 }
774 for (tmp5 = tmp4->steps; tmp5; tmp5 = tmp5->next) {
775 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "STEP")) < 0) {
776 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
777 return 1;
778 }
779 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) {
780 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
781 return 1;
782 }
783 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "RESTTIME", "%d", tmp5->resttime)) < 0) {
784 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
785 return 1;
786 }
787 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "STEPTIME", "%d", tmp5->steptime)) < 0) {
788 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
789 return 1;
790 }
791 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TARGET_LO", "%.1f", tmp5->target_lo)) < 0) {
792 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
793 return 1;
794 }
795 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TARGET_HI", "%.1f", tmp5->target_hi)) < 0) {
796 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
797 return 1;
798 }
799 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_MODE", "%d", tmp5->fridge_mode)) < 0) {
800 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
801 return 1;
802 }
803 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
804 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
805 return 1;
806 }
807 }
808 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
809 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
810 return 1;
811 }
812 }
813 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
814 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
815 return 1;
816 }
817 }
818 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
819 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
820 return 1;
821 }
822 } 391 }
823 392
824 if (Config.devices) { 393 if (Config.devices) {
825 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "DEVICES")) < 0) { 394 xmlTextWriterStartElement(writer, BAD_CAST "DEVICES");
826 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
827 return 1;
828 }
829 #ifdef HAVE_WIRINGPI_H 395 #ifdef HAVE_WIRINGPI_H
830 piLock(LOCK_DEVICES); 396 piLock(LOCK_DEVICES);
831 #endif 397 #endif
832 for (device = Config.devices; device; device = device->next) { 398 for (device = Config.devices; device; device = device->next) {
833 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "DEVICE")) < 0) { 399 xmlTextWriterStartElement(writer, BAD_CAST "DEVICE");
834 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); 400 xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", device->uuid);
835 return 1; 401 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TYPE", "%s", DEVTYPE[device->type]);
836 } 402 xmlTextWriterWriteFormatElement(writer, BAD_CAST "DIRECTION", "%s", DEVDIR[device->direction]);
837 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VERSION", "%d", device->version)) < 0) { 403 xmlTextWriterWriteFormatElement(writer, BAD_CAST "VALUE", "%d", device->value);
838 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); 404 xmlTextWriterWriteFormatElement(writer, BAD_CAST "OFFSET", "%d", device->offset);
839 return 1; 405 xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRESENT", "%s", DEVPRESENT[device->present]);
840 } 406 xmlTextWriterWriteFormatElement(writer, BAD_CAST "ADDRESS", "%s", device->address);
841 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", device->uuid)) < 0) { 407 xmlTextWriterWriteFormatElement(writer, BAD_CAST "SUBDEVICE", "%d", device->subdevice);
842 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 408 xmlTextWriterWriteFormatElement(writer, BAD_CAST "GPIOPIN", "%d", device->gpiopin);
843 return 1; 409 xmlTextWriterWriteFormatElement(writer, BAD_CAST "DESCRIPTION", "%s", device->description);
844 } 410 xmlTextWriterWriteFormatElement(writer, BAD_CAST "INUSE", "%d", device->inuse);
845 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TYPE", "%s", DEVTYPE[device->type])) < 0) { 411 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COMMENT", "%s", device->comment);
846 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 412 xmlTextWriterWriteFormatElement(writer, BAD_CAST "TIMESTAMP", "%d", (int)device->timestamp);
847 return 1; 413 xmlTextWriterEndElement(writer); // close DEVICE
848 }
849 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DIRECTION", "%s", DEVDIR[device->direction])) < 0) {
850 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
851 return 1;
852 }
853 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VALUE", "%d", device->value)) < 0) {
854 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
855 return 1;
856 }
857 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "OFFSET", "%d", device->offset)) < 0) {
858 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
859 return 1;
860 }
861 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRESENT", "%s", DEVPRESENT[device->present])) < 0) {
862 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
863 return 1;
864 }
865 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ADDRESS", "%s", device->address)) < 0) {
866 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
867 return 1;
868 }
869 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "SUBDEVICE", "%d", device->subdevice)) < 0) {
870 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
871 return 1;
872 }
873 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "GPIOPIN", "%d", device->gpiopin)) < 0) {
874 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
875 return 1;
876 }
877 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DESCRIPTION", "%s", device->description)) < 0) {
878 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
879 return 1;
880 }
881 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "INUSE", "%d", device->inuse)) < 0) {
882 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
883 return 1;
884 }
885 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COMMENT", "%s", device->comment)) < 0) {
886 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
887 return 1;
888 }
889 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TIMESTAMP", "%d", (int)device->timestamp)) < 0) {
890 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
891 return 1;
892 }
893 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
894 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
895 return 1;
896 }
897 } 414 }
898 #ifdef HAVE_WIRINGPI_H 415 #ifdef HAVE_WIRINGPI_H
899 piUnlock(LOCK_DEVICES); 416 piUnlock(LOCK_DEVICES);
900 #endif 417 #endif
901 418 xmlTextWriterEndElement(writer); // close DEVICES
902 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
903 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
904 return 1;
905 }
906 } 419 }
907 420
908 #ifdef USE_SIMULATOR 421 #ifdef USE_SIMULATOR
909 if (Config.simulators) { 422 if (Config.simulators) {
910 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "SIMULATORS")) < 0) { 423 xmlTextWriterStartElement(writer, BAD_CAST "SIMULATORS");
911 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
912 return 1;
913 }
914 for (simulator = Config.simulators; simulator; simulator = simulator->next) { 424 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
915 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "SIMULATOR")) < 0) { 425 xmlTextWriterStartElement(writer, BAD_CAST "SIMULATOR");
916 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement"); 426 xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", simulator->uuid);
917 return 1; 427 xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", simulator->name);
918 } 428 xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_AIR", "%d", simulator->volume_air);
919 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VERSION", "%d", simulator->version)) < 0) { 429 xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_BEER", "%d", simulator->volume_beer);
920 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); 430 xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_TEMPERATURE", "%.1f", simulator->room_temperature);
921 return 1; 431 xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_HUMIDITY", "%.1f", simulator->room_humidity);
922 } 432 xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%f", simulator->air_temperature);
923 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", simulator->uuid)) < 0) { 433 xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%f", simulator->beer_temperature);
924 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 434 xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_TEMPERATURE", "%f", simulator->chiller_temperature);
925 return 1; 435 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TEMP", "%f", simulator->cooler_temp);
926 } 436 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TIME", "%d", simulator->cooler_time);
927 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", simulator->name)) < 0) { 437 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_SIZE", "%.3f", simulator->cooler_size);
928 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); 438 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TEMP", "%f", simulator->heater_temp);
929 return 1; 439 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TIME", "%d", simulator->heater_time);
930 } 440 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_SIZE", "%.3f", simulator->heater_size);
931 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_AIR", "%d", simulator->volume_air)) < 0) { 441 xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_STATE", "%d", simulator->heater_state);
932 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); 442 xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_STATE", "%d", simulator->cooler_state);
933 return 1; 443 xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIGO_ISOLATION", "%.3f", simulator->frigo_isolation);
934 } 444 xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_HEAT", "%f", simulator->s_yeast_heat);
935 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME_BEER", "%d", simulator->volume_beer)) < 0) { 445 xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_STARTED", "%d", (int)simulator->s_yeast_started);
936 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); 446 xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_COOL_TEMP", "%f", simulator->s_cool_temp);
937 return 1; 447 xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HEAT_TEMP", "%f", simulator->s_heat_temp);
938 } 448 xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_COOL_CHANGED", "%d", (int)simulator->s_cool_changed);
939 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_TEMPERATURE", "%.1f", simulator->room_temperature)) < 0) { 449 xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HEAT_CHANGED", "%d", (int)simulator->s_heat_changed);
940 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); 450 xmlTextWriterEndElement(writer);
941 return 1; 451 }
942 } 452 xmlTextWriterEndElement(writer);
943 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROOM_HUMIDITY", "%.1f", simulator->room_humidity)) < 0) {
944 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
945 return 1;
946 }
947 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_TEMPERATURE", "%f", simulator->air_temperature)) < 0) {
948 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
949 return 1;
950 }
951 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_TEMPERATURE", "%f", simulator->beer_temperature)) < 0) {
952 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
953 return 1;
954 }
955 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CHILLER_TEMPERATURE", "%f", simulator->chiller_temperature)) < 0) {
956 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
957 return 1;
958 }
959 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TEMP", "%f", simulator->cooler_temp)) < 0) {
960 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
961 return 1;
962 }
963 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_TIME", "%d", simulator->cooler_time)) < 0) {
964 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
965 return 1;
966 }
967 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_SIZE", "%.3f", simulator->cooler_size)) < 0) {
968 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
969 return 1;
970 }
971 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TEMP", "%f", simulator->heater_temp)) < 0) {
972 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
973 return 1;
974 }
975 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_TIME", "%d", simulator->heater_time)) < 0) {
976 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
977 return 1;
978 }
979 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_SIZE", "%.3f", simulator->heater_size)) < 0) {
980 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
981 return 1;
982 }
983 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_STATE", "%d", simulator->heater_state)) < 0) {
984 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
985 return 1;
986 }
987 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_STATE", "%d", simulator->cooler_state)) < 0) {
988 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
989 return 1;
990 }
991 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIGO_ISOLATION", "%.3f", simulator->frigo_isolation)) < 0) {
992 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
993 return 1;
994 }
995 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_HEAT", "%f", simulator->s_yeast_heat)) < 0) {
996 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
997 return 1;
998 }
999 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_YEAST_STARTED", "%d", (int)simulator->s_yeast_started)) < 0) {
1000 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
1001 return 1;
1002 }
1003 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_COOL_TEMP", "%f", simulator->s_cool_temp)) < 0) {
1004 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
1005 return 1;
1006 }
1007 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HEAT_TEMP", "%f", simulator->s_heat_temp)) < 0) {
1008 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
1009 return 1;
1010 }
1011 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_COOL_CHANGED", "%d", (int)simulator->s_cool_changed)) < 0) {
1012 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
1013 return 1;
1014 }
1015 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HEAT_CHANGED", "%d", (int)simulator->s_heat_changed)) < 0) {
1016 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
1017 return 1;
1018 }
1019 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
1020 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
1021 return 1;
1022 }
1023 }
1024 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
1025 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
1026 return 1;
1027 }
1028 } 453 }
1029 #endif 454 #endif
1030 455
1031 /* 456 /*
1032 * All done, close any open elements 457 * All done, close any open elements
1068 493
1069 494
1070 495
1071 int wrconfig(void) 496 int wrconfig(void)
1072 { 497 {
1073 int rc; 498 int rc = do_wrconfig();
1074
1075 rc = do_wrconfig();
1076 syslog(LOG_NOTICE, "Rewritten configuration, rc=%d", rc); 499 syslog(LOG_NOTICE, "Rewritten configuration, rc=%d", rc);
1077 return rc; 500 return rc;
1078 } 501 }
1079 502
1080 503
1139 float val; 562 float val;
1140 units_list *unit, *tmp; 563 units_list *unit, *tmp;
1141 564
1142 unit = (units_list *)malloc(sizeof(units_list)); 565 unit = (units_list *)malloc(sizeof(units_list));
1143 unit->next = NULL; 566 unit->next = NULL;
1144 unit->version = 1;
1145 unit->uuid = unit->product_uuid = unit->product_code = unit->product_name = unit->event_msg = \ 567 unit->uuid = unit->product_uuid = unit->product_code = unit->product_name = unit->event_msg = \
1146 unit->alias = unit->air_address = unit->beer_address = unit->chiller_address = unit->heater_address = \ 568 unit->alias = unit->air_address = unit->beer_address = unit->chiller_address = unit->heater_address = \
1147 unit->cooler_address = unit->fan_address = unit->door_address = \ 569 unit->cooler_address = unit->fan_address = unit->door_address = \
1148 unit->light_address = unit->psu_address = unit->profile = NULL; 570 unit->light_address = unit->psu_address = unit->profile_uuid = unit->profile_name = NULL;
1149 unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0; 571 unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
1150 unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = unit->beer_set = unit->fridge_set = 20.0; 572 unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = unit->beer_set = \
573 unit->fridge_set = unit->profile_inittemp_lo = unit->profile_inittemp_hi = 20.0;
1151 unit->air_state = unit->beer_state = unit->chiller_state = 1; // missing 574 unit->air_state = unit->beer_state = unit->chiller_state = 1; // missing
1152 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \ 575 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \
1153 unit->light_state = unit->psu_state = unit->mode = unit->prof_state = unit->stage = 0; 576 unit->light_state = unit->psu_state = unit->mode = unit->prof_state = unit->stage = 0;
1154 unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \ 577 unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \
1155 unit->door_idx = unit->light_idx = unit->psu_idx = 0; 578 unit->door_idx = unit->light_idx = unit->psu_idx = unit->profile_fridge_mode = \
579 unit->profile_duration = unit->profile_totalsteps = 0;
580 unit->profile_steps = NULL;
1156 unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ 581 unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */
1157 unit->light_delay = 1; /* 15 seconds delay */ 582 unit->light_delay = 1; /* 15 seconds delay */
1158 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 583 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
1159 unit->heater_usage = unit->cooler_usage = unit->fan_usage = unit->light_usage = 0; 584 unit->heater_usage = unit->cooler_usage = unit->fan_usage = unit->light_usage = 0;
1160 unit->temp_set_min = 1.0; 585 unit->temp_set_min = 1.0;
1166 InitPID(unit->PID_cool, PID_TYPE_COOL); 591 InitPID(unit->PID_cool, PID_TYPE_COOL);
1167 InitPID(unit->PID_heat, PID_TYPE_HEAT); 592 InitPID(unit->PID_heat, PID_TYPE_HEAT);
1168 593
1169 cur = cur->xmlChildrenNode; 594 cur = cur->xmlChildrenNode;
1170 while (cur != NULL) { 595 while (cur != NULL) {
1171 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
1172 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1173 if (xmlStrcmp(key, (const xmlChar *)"1")) {
1174 xmlFree(key);
1175 return 1;
1176 }
1177 unit->version = 1;
1178 xmlFree(key);
1179 }
1180 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) { 596 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) {
1181 unit->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 597 unit->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1182 }
1183 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
1184 /*
1185 * Upgrade to product code and name
1186 */
1187 char *oldname = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1188 if (strstr(oldname, (char *)" ")) {
1189 unit->product_code = xstrcpy(strtok(oldname, " "));
1190 unit->product_name = xstrcpy(strtok(NULL, "\0"));
1191 } else {
1192 unit->product_code = xstrcpy((char *)"000000");
1193 unit->product_name = xstrcpy(oldname);
1194 }
1195 } 598 }
1196 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_UUID"))) { 599 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_UUID"))) {
1197 unit->product_uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 600 unit->product_uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1198 } 601 }
1199 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_CODE"))) { 602 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRODUCT_CODE"))) {
1418 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 821 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1419 if (sscanf((const char *)key, "%f", &val) == 1) 822 if (sscanf((const char *)key, "%f", &val) == 1)
1420 unit->temp_set_max = val; 823 unit->temp_set_max = val;
1421 xmlFree(key); 824 xmlFree(key);
1422 } 825 }
1423 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_KP"))) { 826 // if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_KP"))) {
1424 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 827 // key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1425 if (sscanf((const char *)key, "%f", &val) == 1) 828 // if (sscanf((const char *)key, "%f", &val) == 1)
1426 unit->PID_cool->pGain = unit->PID_heat->pGain = val; /* Upgrade config */ 829 // unit->PID_cool->pGain = unit->PID_heat->pGain = val; /* Upgrade config */
1427 xmlFree(key); 830 // xmlFree(key);
1428 } 831 // }
1429 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_KD"))) { 832 // if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_KD"))) {
1430 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 833 // key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1431 if (sscanf((const char *)key, "%f", &val) == 1) 834 // if (sscanf((const char *)key, "%f", &val) == 1)
1432 unit->PID_cool->dGain = unit->PID_heat->dGain = val; /* Upgrade config */ 835 // unit->PID_cool->dGain = unit->PID_heat->dGain = val; /* Upgrade config */
1433 xmlFree(key); 836 // xmlFree(key);
1434 } 837 // }
1435 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_KI"))) { 838 // if ((!xmlStrcmp(cur->name, (const xmlChar *)"PID_KI"))) {
1436 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 839 // key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1437 if (sscanf((const char *)key, "%f", &val) == 1) 840 // if (sscanf((const char *)key, "%f", &val) == 1)
1438 unit->PID_cool->iGain = unit->PID_heat->iGain = val; /* Upgrade config */ 841 // unit->PID_cool->iGain = unit->PID_heat->iGain = val; /* Upgrade config */
1439 xmlFree(key); 842 // xmlFree(key);
1440 } 843 // }
1441 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PIDC_IMAX"))) { 844 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PIDC_IMAX"))) {
1442 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 845 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1443 if (sscanf((const char *)key, "%f", &val) == 1) 846 if (sscanf((const char *)key, "%f", &val) == 1)
1444 unit->PID_cool->iMax = val; 847 unit->PID_cool->iMax = val;
1445 xmlFree(key); 848 xmlFree(key);
1576 break; 979 break;
1577 } 980 }
1578 } 981 }
1579 xmlFree(key); 982 xmlFree(key);
1580 } 983 }
1581 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE"))) { 984 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_UUID"))) {
1582 unit->profile = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 985 unit->profile_uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1583 } 986 }
987 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_NAME"))) {
988 unit->profile_name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
989 }
990 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_INITTEMP_LO"))) {
991 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
992 if (sscanf((const char *)key, "%f", &val) == 1)
993 unit->profile_inittemp_lo = val;
994 xmlFree(key);
995 }
996 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_INITTEMP_HI"))) {
997 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
998 if (sscanf((const char *)key, "%f", &val) == 1)
999 unit->profile_inittemp_hi = val;
1000 xmlFree(key);
1001 }
1002 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_FRIDGE_MODE"))) {
1003 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1004 if (sscanf((const char *)key, "%d", &ival) == 1)
1005 unit->profile_fridge_mode = ival;
1006 xmlFree(key);
1007 }
1008 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_DURATION"))) {
1009 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1010 if (sscanf((const char *)key, "%d", &ival) == 1)
1011 unit->profile_duration = ival;
1012 xmlFree(key);
1013 }
1014 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_TOTALSTEPS"))) {
1015 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1016 if (sscanf((const char *)key, "%d", &ival) == 1)
1017 unit->profile_totalsteps = ival;
1018 xmlFree(key);
1019 }
1020 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_STEPS"))) {
1021 parseSteps(doc, cur, &(unit)->profile_steps);
1022 }
1023
1584 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROF_STARTED"))) { 1024 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROF_STARTED"))) {
1585 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1025 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1586 if (sscanf((const char *)key, "%d", &ival) == 1) 1026 if (sscanf((const char *)key, "%d", &ival) == 1)
1587 unit->prof_started = ival; 1027 unit->prof_started = ival;
1588 xmlFree(key); 1028 xmlFree(key);
1642 1082
1643 int parseFermenters(xmlDocPtr doc, xmlNodePtr cur) 1083 int parseFermenters(xmlDocPtr doc, xmlNodePtr cur)
1644 { 1084 {
1645 cur = cur->xmlChildrenNode; 1085 cur = cur->xmlChildrenNode;
1646 while (cur != NULL) { 1086 while (cur != NULL) {
1647 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UNIT"))) { 1087 // Accept the wrong UNIT name as well as FERMENTER
1088 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UNIT")) || (!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTER"))) {
1648 parseUnit(doc, cur); 1089 parseUnit(doc, cur);
1649 } 1090 }
1650 cur = cur->next; 1091 cur = cur->next;
1651 } 1092 }
1652 return 0; 1093 return 0;
1661 float val; 1102 float val;
1662 prof_step *step, *tmp; 1103 prof_step *step, *tmp;
1663 1104
1664 step = (prof_step *)malloc(sizeof(prof_step)); 1105 step = (prof_step *)malloc(sizeof(prof_step));
1665 step->next = NULL; 1106 step->next = NULL;
1666 step->version = 1; 1107 step->name = NULL;
1667 step->steptime = step->resttime = step->fridge_mode = 0; 1108 step->steptime = step->resttime = step->fridge_mode = 0;
1668 step->target_lo = step->target_hi = 20.0; 1109 step->target_lo = step->target_hi = 20.0;
1669 1110
1670 cur = cur->xmlChildrenNode; 1111 cur = cur->xmlChildrenNode;
1671 while (cur != NULL) { 1112 while (cur != NULL) {
1672 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) { 1113 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
1673 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1114 step->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1674 if (xmlStrcmp(key, (const xmlChar *)"1")) {
1675 xmlFree(key);
1676 return 1;
1677 }
1678 step->version = 1;
1679 xmlFree(key);
1680 } 1115 }
1681 if ((!xmlStrcmp(cur->name, (const xmlChar *)"RESTTIME"))) { 1116 if ((!xmlStrcmp(cur->name, (const xmlChar *)"RESTTIME"))) {
1682 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1117 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1683 if (sscanf((const char *)key, "%d", &ival) == 1) 1118 if (sscanf((const char *)key, "%d", &ival) == 1)
1684 step->resttime = ival; 1119 step->resttime = ival;
1686 } 1121 }
1687 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEPTIME"))) { 1122 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEPTIME"))) {
1688 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1123 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1689 if (sscanf((const char *)key, "%d", &ival) == 1) 1124 if (sscanf((const char *)key, "%d", &ival) == 1)
1690 step->steptime = ival; 1125 step->steptime = ival;
1691 xmlFree(key);
1692 }
1693 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TARGET"))) { /* Upgrade from single values */
1694 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1695 if (sscanf((const char *)key, "%f", &val) == 1) {
1696 step->target_lo = val - 0.2;
1697 step->target_hi = val + 0.2;
1698 }
1699 xmlFree(key); 1126 xmlFree(key);
1700 } 1127 }
1701 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TARGET_LO"))) { 1128 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TARGET_LO"))) {
1702 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1129 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1703 if (sscanf((const char *)key, "%f", &val) == 1) 1130 if (sscanf((const char *)key, "%f", &val) == 1)
1736 1163
1737 int parseSteps(xmlDocPtr doc, xmlNodePtr cur, prof_step **step) 1164 int parseSteps(xmlDocPtr doc, xmlNodePtr cur, prof_step **step)
1738 { 1165 {
1739 cur = cur->xmlChildrenNode; 1166 cur = cur->xmlChildrenNode;
1740 while (cur != NULL) { 1167 while (cur != NULL) {
1741 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEP"))) { 1168 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE_STEP"))) {
1742 parseStep(doc, cur, step); 1169 parseStep(doc, cur, step);
1743 }
1744 cur = cur->next;
1745 }
1746 return 0;
1747 }
1748
1749
1750
1751 int parseProfile(xmlDocPtr doc, xmlNodePtr cur)
1752 {
1753 xmlChar *key;
1754 profiles_list *profile, *tmp;
1755 int ival;
1756 float fval;
1757
1758 profile = (profiles_list *)malloc(sizeof(profiles_list));
1759 profile->next = NULL;
1760 profile->version = 1;
1761 profile->uuid = profile->name = NULL;
1762 profile->busy = profile->fridge_mode = 0;
1763 profile->inittemp_lo = profile->inittemp_hi = 20.0;
1764 profile->steps = NULL;
1765
1766 cur = cur->xmlChildrenNode;
1767 while (cur != NULL) {
1768 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
1769 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1770 if (xmlStrcmp(key, (const xmlChar *)"1")) {
1771 xmlFree(key);
1772 return 1;
1773 }
1774 profile->version = 1;
1775 xmlFree(key);
1776 }
1777 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) {
1778 profile->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1779 }
1780 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
1781 profile->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1782 }
1783 if ((!xmlStrcmp(cur->name, (const xmlChar *)"BUSY"))) {
1784 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1785 if (sscanf((const char *)key, "%d", &ival) == 1)
1786 profile->busy = ival;
1787 xmlFree(key);
1788 }
1789 if ((!xmlStrcmp(cur->name, (const xmlChar *)"INITTEMP"))) { /* Upgrade from single temp */
1790 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1791 if (sscanf((const char *)key, "%f", &fval) == 1) {
1792 profile->inittemp_lo = fval - 0.2;
1793 profile->inittemp_hi = fval + 0.2;
1794 }
1795 xmlFree(key);
1796 }
1797 if ((!xmlStrcmp(cur->name, (const xmlChar *)"INITTEMP_LO"))) {
1798 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1799 if (sscanf((const char *)key, "%f", &fval) == 1)
1800 profile->inittemp_lo = fval;
1801 xmlFree(key);
1802 }
1803 if ((!xmlStrcmp(cur->name, (const xmlChar *)"INITTEMP_HI"))) {
1804 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1805 if (sscanf((const char *)key, "%f", &fval) == 1)
1806 profile->inittemp_hi = fval;
1807 xmlFree(key);
1808 }
1809 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FRIDGE_MODE"))) {
1810 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1811 if (sscanf((const char *)key, "%d", &ival) == 1)
1812 profile->fridge_mode = ival;
1813 xmlFree(key);
1814 }
1815 if ((!xmlStrcmp(cur->name, (const xmlChar *)"STEPS"))) {
1816 parseSteps(doc, cur, &(profile)->steps);
1817 }
1818 cur = cur->next;
1819 }
1820
1821 if (Config.profiles == NULL) {
1822 Config.profiles = profile;
1823 } else {
1824 for (tmp = Config.profiles; tmp; tmp = tmp->next) {
1825 if (tmp->next == NULL) {
1826 tmp->next = profile;
1827 break;
1828 }
1829 }
1830 }
1831
1832 return 0;
1833 }
1834
1835
1836
1837 int parseProfiles(xmlDocPtr doc, xmlNodePtr cur)
1838 {
1839 cur = cur->xmlChildrenNode;
1840 while (cur != NULL) {
1841 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILE"))) {
1842 parseProfile(doc, cur);
1843 } 1170 }
1844 cur = cur->next; 1171 cur = cur->next;
1845 } 1172 }
1846 return 0; 1173 return 0;
1847 } 1174 }
1854 devices_list *device, *tmp; 1181 devices_list *device, *tmp;
1855 int i, ival; 1182 int i, ival;
1856 1183
1857 device = (devices_list *)malloc(sizeof(devices_list)); 1184 device = (devices_list *)malloc(sizeof(devices_list));
1858 device->next = NULL; 1185 device->next = NULL;
1859 device->version = 1;
1860 device->uuid = device->address = device->description = device->comment = NULL; 1186 device->uuid = device->address = device->description = device->comment = NULL;
1861 device->type = device->direction = device->present = device->subdevice = device->inuse = device->offset = 0; 1187 device->type = device->direction = device->present = device->subdevice = device->inuse = device->offset = 0;
1862 device->gpiopin = -1; 1188 device->gpiopin = -1;
1863 device->timestamp = (time_t)0; 1189 device->timestamp = (time_t)0;
1864 1190
1865 cur = cur->xmlChildrenNode; 1191 cur = cur->xmlChildrenNode;
1866 while (cur != NULL) { 1192 while (cur != NULL) {
1867 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
1868 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1869 if (xmlStrcmp(key, (const xmlChar *)"1")) {
1870 xmlFree(key);
1871 return 1;
1872 }
1873 device->version = 1;
1874 xmlFree(key);
1875 }
1876 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) { 1193 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) {
1877 device->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1194 device->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1878 } 1195 }
1879 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) { 1196 if ((!xmlStrcmp(cur->name, (const xmlChar *)"TYPE"))) {
1880 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1197 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
1993 int ival; 1310 int ival;
1994 float fval; 1311 float fval;
1995 1312
1996 simulator = (simulator_list *)malloc(sizeof(simulator_list)); 1313 simulator = (simulator_list *)malloc(sizeof(simulator_list));
1997 simulator->next = NULL; 1314 simulator->next = NULL;
1998 simulator->version = 1;
1999 simulator->uuid = simulator->name = NULL; 1315 simulator->uuid = simulator->name = NULL;
2000 simulator->volume_air = simulator->volume_beer = 0; 1316 simulator->volume_air = simulator->volume_beer = 0;
2001 simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->s_cool_temp = simulator->s_heat_temp = 20.0; 1317 simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->s_cool_temp = simulator->s_heat_temp = 20.0;
2002 simulator->chiller_temperature = 1.5; 1318 simulator->chiller_temperature = 1.5;
2003 simulator->room_humidity = 49.2; 1319 simulator->room_humidity = 49.2;
2006 simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (time_t)0; 1322 simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (time_t)0;
2007 simulator->s_yeast_heat = simulator->s_cool_temp = simulator->s_heat_temp = 0.0; 1323 simulator->s_yeast_heat = simulator->s_cool_temp = simulator->s_heat_temp = 0.0;
2008 1324
2009 cur = cur->xmlChildrenNode; 1325 cur = cur->xmlChildrenNode;
2010 while (cur != NULL) { 1326 while (cur != NULL) {
2011 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
2012 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
2013 if (xmlStrcmp(key, (const xmlChar *)"1")) {
2014 xmlFree(key);
2015 return 1;
2016 }
2017 simulator->version = 1;
2018 xmlFree(key);
2019 }
2020 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) { 1327 if ((!xmlStrcmp(cur->name, (const xmlChar *)"UUID"))) {
2021 simulator->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1328 simulator->uuid = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
2022 } 1329 }
2023 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { 1330 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
2024 simulator->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1331 simulator->name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
2246 /* 1553 /*
2247 * Parse configuration 1554 * Parse configuration
2248 */ 1555 */
2249 cur = cur->xmlChildrenNode; 1556 cur = cur->xmlChildrenNode;
2250 while (cur != NULL) { 1557 while (cur != NULL) {
2251 if ((!xmlStrcmp(cur->name, (const xmlChar *)"VERSION"))) {
2252 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
2253 if (xmlStrcmp(key, (const xmlChar *)"1")) {
2254 xmlFree(key);
2255 syslog(LOG_NOTICE, "XML file %s is not a valid version", mypath);
2256 return 1;
2257 }
2258 xmlFree(key);
2259 }
2260 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) { 1558 if ((!xmlStrcmp(cur->name, (const xmlChar *)"NAME"))) {
2261 Config.name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1559 Config.name = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
2262 } 1560 }
2263 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LISTEN_PORT"))) { 1561 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LISTEN_PORT"))) {
2264 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); 1562 key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
2312 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) { 1610 if ((!xmlStrcmp(cur->name, (const xmlChar *)"LCDS"))) {
2313 parseLCDs(doc, cur); 1611 parseLCDs(doc, cur);
2314 } 1612 }
2315 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTERS"))) { 1613 if ((!xmlStrcmp(cur->name, (const xmlChar *)"FERMENTERS"))) {
2316 parseFermenters(doc, cur); 1614 parseFermenters(doc, cur);
2317 }
2318 if ((!xmlStrcmp(cur->name, (const xmlChar *)"PROFILES"))) {
2319 parseProfiles(doc, cur);
2320 } 1615 }
2321 if ((!xmlStrcmp(cur->name, (const xmlChar *)"DEVICES"))) { 1616 if ((!xmlStrcmp(cur->name, (const xmlChar *)"DEVICES"))) {
2322 parseDevices(doc, cur); 1617 parseDevices(doc, cur);
2323 } 1618 }
2324 #ifdef USE_SIMULATOR 1619 #ifdef USE_SIMULATOR

mercurial