thermferm/rdconfig.c

Wed, 25 Jun 2014 16:16:47 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 25 Jun 2014 16:16:47 +0200
changeset 76
d2c7b32f27d6
parent 75
4b976601737d
child 77
143077e54255
permissions
-rw-r--r--

Can now write the fermenter units configurations

51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2014
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with EC-65K; see the file COPYING. If not, write to the Free
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "thermferm.h"
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
26 int debug = FALSE;
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 static char *mypath;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 static char *k, *v;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 static int linecnt = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 sys_config Config; /* System configuration */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
32 #define MY_ENCODING "utf-8"
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
76
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
34 const char UNITMODE[5][8] = { "OFF", "NONE", "FRIDGE", "BEER", "PROFILE" };
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
36 //static int getstr(char **);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 static int getw1(char **);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
38 #ifdef HAVE_WIRINGPI_H
69
df5d983dab1b Fixed compilation
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
39 static int getint(char **);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
40 #endif
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
41 static int getuch(char **);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
42 static int getfloat(char **);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 //static int getbyt(char **);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 //static int gethex(char **);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 #define XSTR(x) #x
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 #define STR(x) XSTR(x)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 * System configuration table
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 key_list keytab[] = {
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
53 {(char *)"w1therm", getw1, (char **)&Config.w1therms},
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
54 #ifdef HAVE_WIRINGPI_H
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
55 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
56 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows},
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
57 #endif
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
58 {(char *)"cs_mode", getuch, (char **)&Config.cs_mode},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
59 {(char *)"cs_beerSet", getfloat, (char **)&Config.cs_beerSet},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
60 {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
61 {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
62 {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
63 {(char *)"cc_tempFormat", getuch, (char **)&Config.cc_tempFormat},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
64 {(char *)"cc_tempSetMin", getfloat, (char **)&Config.cc_tempSetMin},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
65 {(char *)"cc_tempSetMax", getfloat, (char **)&Config.cc_tempSetMax},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
66 {(char *)"cc_idleRangeH", getfloat, (char **)&Config.cc_idleRangeH},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
67 {(char *)"cc_idleRangeL", getfloat, (char **)&Config.cc_idleRangeL},
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
68 {NULL, NULL, NULL}
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 };
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 void killconfig(void)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 w1_therm *tmp1, *old1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77 if (Config.name)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 free(Config.name);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 Config.name = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 old1 = tmp1->next;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83 if (tmp1->master)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 free(tmp1->master);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 if (tmp1->name)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 free(tmp1->name);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 if (tmp1->alias)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 free(tmp1->alias);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 free(tmp1);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 Config.w1therms = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 Config.my_port = 6554;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
94 #ifdef HAVE_WIRINGPI_H
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 Config.lcd_cols = 16;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 Config.lcd_rows = 2;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
97 #endif
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
99 defaultControlSettings();
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
100 defaultControlConstants();
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
101 }
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
102
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
103
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
104
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
105 int wrconfig(char *config, char *confxml)
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
106 {
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
107 int rc = 0;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
108 FILE *fp;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
109 xmlTextWriterPtr writer;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
110 xmlBufferPtr buf;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
111 w1_therm *tmp1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
112 units_list *tmp3;
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
113
56
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
114 if (getenv((char *)"USER") == NULL) {
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
115 mypath = xstrcpy((char *)"/root");
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
116 } else {
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
117 mypath = xstrcpy(getenv((char *)"HOME"));
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
118 }
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
119 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
120 mypath = xstrcat(mypath, config);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
121
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
122 if (debug)
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
123 fprintf(stdout, "Writing %s\n", mypath);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
124
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
125 if ((fp = fopen(mypath, "w")) == NULL) {
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
126 syslog(LOG_NOTICE, "could not rewrite %s", mypath);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
127 return 1;
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
128 }
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
129
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
130 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
131 fprintf(fp, "\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
132
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
133 #ifdef HAVE_WIRINGPI_H
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
134 fprintf(fp, "# LCD display\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
135 fprintf(fp, "#\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
136 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
137 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
138 fprintf(fp, "\n");
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
139 #endif
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
140
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
141 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
142 fprintf(fp, "#\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
143 fprintf(fp, "# kwd master bus name alias\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
144 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
145 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
146 }
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
147 fprintf(fp, "\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
148
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
149 fprintf(fp, "# Control Settings.\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
150 fprintf(fp, "#\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
151 fprintf(fp, "cs_mode %c\n", Config.cs_mode);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
152 fprintf(fp, "cs_beerSet %.1f\n", Config.cs_beerSet);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
153 fprintf(fp, "cs_fridgeSet %.1f\n", Config.cs_fridgeSet);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
154 fprintf(fp, "cs_heatEstimator %.1f\n", Config.cs_heatEstimator);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
155 fprintf(fp, "cs_coolEstimator %.1f\n", Config.cs_coolEstimator);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
156 fprintf(fp, "\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
157
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
158 fprintf(fp, "# Control Constants.\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
159 fprintf(fp, "#\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
160 fprintf(fp, "cc_tempFormat %c\n", Config.cc_tempFormat);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
161 fprintf(fp, "cc_tempSetMin %.1f\n", Config.cc_tempSetMin);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
162 fprintf(fp, "cc_tempSetMax %.1f\n", Config.cc_tempSetMax);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
163 fprintf(fp, "cc_idleRangeH %.1f\n", Config.cc_idleRangeH);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
164 fprintf(fp, "cc_idleRangeL %.1f\n", Config.cc_idleRangeL);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
165 fprintf(fp, "\n");
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
166
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
167 fprintf(fp, "# End of generated configuration\n");
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
168 fclose(fp);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
169 syslog(LOG_NOTICE, "Written %s rc=%d", mypath, rc);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
170 free(mypath);
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
171 mypath = NULL;
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
172
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
173
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
174 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
175 * Create a new XML buffer, to which the XML document will be written
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
176 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
177 if ((buf = xmlBufferCreate()) == NULL) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
178 syslog(LOG_NOTICE, "wrconfig: error creating the xml buffer");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
179 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
180 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
181
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
182 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
183 * Create a new XmlWriter for memory, with no compression.
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
184 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
185 if ((writer = xmlNewTextWriterMemory(buf, 0)) == NULL) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
186 syslog(LOG_NOTICE, "wrconfig: error creating the xml writer");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
187 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
188 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
189
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
190 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
191 * Use indentation instead of one long line
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
192 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
193 if ((rc = xmlTextWriterSetIndent(writer, 2)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
194 syslog(LOG_NOTICE, "wrconfig: error setting Indent");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
195 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
196 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
197
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
198 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
199 * Start the document with the xml default for the version,
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
200 * encoding ISO 8859-1 and the default for the standalone
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
201 * declaration.
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
202 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
203 if ((rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
204 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartDocument");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
205 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
206 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
207
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
208 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
209 * Start an element named "THERMFERM". Since thist is the first
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
210 * element, this will be the root element of the document.
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
211 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
212 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "THERMFERM")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
213 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
214 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
215 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
216
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
217 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
218 * Add an attribute with name "VERSION" and value "1" to THERMFERM.
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
219 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
220 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
221 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
222 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
223 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
224
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
225 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "LISTEN_PORT", "%d", Config.my_port)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
226 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
227 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
228 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
229
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
230 #ifdef HAVE_WIRINGPI_H
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
231 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
232 * Start an element named "LCDS" as child of THERMFERM.
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
233 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
234 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCDS")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
235 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
236 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
237 }
76
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
238 /*
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
239 * Start one LCD. It is possible to connect 7 LCD displays on the i2c bus.
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
240 * However this program doesn't use more then one yet.
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
241 */
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
242 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "LCD")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
243 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
244 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
245 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
246 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
247 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
248 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
249 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
250 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COLUMNS", "%d", Config.lcd_cols)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
251 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
252 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
253 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
254 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ROWS", "%d", Config.lcd_rows)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
255 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
256 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
257 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
258 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
259 * Close the element named LCD.
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
260 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
261 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
262 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
263 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
264 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
265 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
266 * Close the element LCDS.
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
267 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
268 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
269 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
270 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
271 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
272 #endif
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
273
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
274 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
275 * Fermenter units
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
276 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
277 if (Config.units) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
278 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "FERMENTERS")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
279 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
280 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
281 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
282 for (tmp3 = Config.units; tmp3; tmp3 = tmp3->next) {
76
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
283 /*
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
284 * Only configuration items are written, measured values and states
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
285 * are written to a state file.
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
286 */
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
287 if ((rc = xmlTextWriterStartElement(writer, BAD_CAST "UNIT")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
288 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterStartElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
289 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
290 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
291 if ((rc = xmlTextWriterWriteElement(writer, BAD_CAST "VERSION", BAD_CAST "1")) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
292 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
293 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
294 }
76
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
295 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
296 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
297 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
298 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
299 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%s", Config.units->uuid)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
300 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
301 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
302 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
303 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "NAME", "%s", MBSE_SS(Config.units->name))) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
304 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
305 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
306 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
307 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "VOLUME", "%.1f", Config.units->volume)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
308 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
309 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
310 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
311 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "AIR_ADDRESS", "%s", MBSE_SS(Config.units->air_address))) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
312 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
313 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
314 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
315 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_ADDRESS", "%s", MBSE_SS(Config.units->beer_address))) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
316 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
317 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
318 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
319 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO1_ADDRESS", "%s", MBSE_SS(Config.units->io1_address))) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
320 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
321 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
322 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
323 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IO2_ADDRESS", "%s", MBSE_SS(Config.units->io2_address))) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
324 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
325 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
326 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
327 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER", "%s", Config.units->heater_available ? "YES":"NO")) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
328 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
329 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
330 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
331 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER", "%s", Config.units->cooler_available? "YES":"NO")) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
332 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
333 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
334 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
335 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN", "%s", Config.units->fan_available ? "YES":"NO")) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
336 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
337 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
338 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
339 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MODE", "%s", UNITMODE[Config.units->mode] )) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
340 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
341 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
342 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
343 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "BEER_SET", "%.1f", Config.units->beer_set)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
344 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
345 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
346 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
347 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FRIDGE_SET", "%.1f", Config.units->fridge_set)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
348 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
349 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
350 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
351 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MIN", "%.1f", Config.units->temp_set_min)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
352 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
353 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
354 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
355 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "TEMP_SET_MAX", "%.1f", Config.units->temp_set_max)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
356 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
357 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
358 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
359 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_L", "%.1f", Config.units->idle_rangeL)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
360 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
361 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
362 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
363 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "IDLE_RANGE_H", "%.1f", Config.units->idle_rangeH)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
364 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
365 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
366 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
367 if (Config.units->profile) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
368 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PROFILE", "%s", Config.units->profile)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
369 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
370 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
371 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
372 if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "UUID", "%d", (unsigned int)Config.units->prof_started)) < 0) {
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
373 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
374 return 1;
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
375 }
d2c7b32f27d6 Can now write the fermenter units configurations
Michiel Broek <mbroek@mbse.eu>
parents: 75
diff changeset
376 }
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
377 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
378 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
379 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
380 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
381 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
382 if ((rc = xmlTextWriterEndElement(writer)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
383 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
384 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
385 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
386 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
387
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
388 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
389 * All done, close any open elements
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
390 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
391 if ((rc = xmlTextWriterEndDocument(writer)) < 0) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
392 syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndDocument");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
393 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
394 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
395 xmlFreeTextWriter(writer);
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
396
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
397 /*
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
398 * Now write the XML configuration
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
399 */
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
400 if (getenv((char *)"USER") == NULL) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
401 mypath = xstrcpy((char *)"/root");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
402 } else {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
403 mypath = xstrcpy(getenv((char *)"HOME"));
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
404 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
405 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
406 mypath = xstrcat(mypath, confxml);
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
407
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
408 if (debug)
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
409 fprintf(stdout, "Writing %s\n", mypath);
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
410
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
411 if ((fp = fopen(mypath, "w")) == NULL) {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
412 syslog(LOG_NOTICE, "could not rewrite %s", mypath);
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
413 return 1;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
414 }
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
415
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
416 fprintf(fp, "%s", (const char *) buf->content);
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
417 fclose(fp);
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
418 xmlBufferFree(buf);
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
419
53
37623517e0ef Added writing configuration
Michiel Broek <mbroek@mbse.eu>
parents: 51
diff changeset
420 return rc;
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 int rdconfig(char *config)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 char buf[256], *p;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 FILE *fp;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429 int i, rc = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431 killconfig();
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
432
56
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
433 syslog(LOG_NOTICE, "HOME='%s' USER='%s' LOGNAME='%s'", MBSE_SS(getenv((char *)"HOME")), MBSE_SS(getenv((char *)"USER")), MBSE_SS(getenv((char *)"LOGNAME")));
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
434
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 * Search config file
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 */
56
f7711c6ac93c Workaround for empty environment at system boot
Michiel Broek <mbroek@mbse.eu>
parents: 55
diff changeset
438 if (getenv((char *)"USER") == NULL) {
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
439 mypath = xstrcpy((char *)"/root");
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
440 } else {
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
441 mypath = xstrcpy(getenv((char *)"HOME"));
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
442 }
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/");
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 mypath = xstrcat(mypath, config);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445 if ((fp = fopen(mypath, "r")) == NULL) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 * Not in the users home directory
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 free(mypath);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450 mypath = xstrcpy((char *)"/etc/mbsepi-apps/");
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451 mypath = xstrcat(mypath, config);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
452 if ((fp = fopen(mypath, "r")) == NULL) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
454 * Try /usr/local/etc
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 free(mypath);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
457 mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/");
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 mypath = xstrcat(mypath, config);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 if ((fp = fopen(mypath, "r")) == NULL) {
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
460 syslog(LOG_NOTICE, "rdconfig: could find %s", config);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
463 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 }
55
11d7cc3bdf31 If /home/mbroek is not set, assume root user.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
465 syslog(LOG_NOTICE, "rdconfig: using %s", mypath);
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467 linecnt = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 while (fgets(buf, sizeof(buf) -1, fp)) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
469 linecnt++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 if (*(p = buf + strlen(buf) -1) != '\n') {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 syslog(LOG_NOTICE, "rdconfig: %s(%d): \"%s\" - line too long", mypath, linecnt, buf);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 rc = 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 *p-- = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 while ((p >= buf) && isspace(*p))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477 *p-- = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 k = buf;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 while (*k && isspace(*k))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 k++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 p = k;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 while (*p && !isspace(*p))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 p++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 *p++='\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 v = p;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 while (*v && isspace(*v))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 v++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 if ((*k == '\0') || (*k == '#')) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490 continue;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
492
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
493 for (i = 0; keytab[i].key; i++)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 if (strcasecmp(k,keytab[i].key) == 0)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
495 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 if (keytab[i].key == NULL) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - unknown keyword", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499 rc = 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501 } else if ((keytab[i].prc(keytab[i].dest))) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 rc = 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 break;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507 fclose(fp);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 free(mypath);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510 mypath = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 return rc;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
517 /*
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518 static int getstr(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520 if (debug)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
522
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523 *dest = xstrcpy(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 }
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 58
diff changeset
526 */
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529
69
df5d983dab1b Fixed compilation
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
530 #ifdef HAVE_WIRINGPI_H
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531 static int getint(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 if (debug)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536 if (strspn(v,"0123456789") != strlen(v))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
537 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 else
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539 *((int*)dest)=atoi(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 }
69
df5d983dab1b Fixed compilation
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
542 #endif
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
543
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546 static int getw1(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
547 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548 char *p, *q = NULL, *r = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 w1_therm **tmpm;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550 int rc = 0, tmpp;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 for (p = v; *p && !isspace(*p); p++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 if (*p)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554 *p++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555 while (*p && isspace(*p))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 p++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557 if (*p == '\0') {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 for (q = p; *q && !isspace(*q); q++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563 if (*q && isspace(*q)) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564 if (*q)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 *q++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 while (*q && isspace(*q))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 q++;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569 for (r = q; *r && !isspace(*r); r++);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 if (*r)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 *r++ = '\0';
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 rc = sscanf(p, "%d", &tmpp);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 if (rc != 1) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s is not a integer value", mypath, linecnt, p);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577 if (debug)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
578 syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s %d %s %s", mypath, linecnt, v, tmpp, q, r);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 (*tmpm)->next = NULL;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584 (*tmpm)->master = xstrcpy(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 (*tmpm)->bus = tmpp;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 (*tmpm)->name = xstrcpy(q);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 (*tmpm)->alias = xstrcpy(r);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
588 (*tmpm)->present = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 (*tmpm)->lastval = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 (*tmpm)->update = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596
54
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
597 static int getuch(char **dest)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
598 {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
599 if (debug)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
600 syslog(LOG_NOTICE, "rdconfig: getuch: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
601
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
602 if (isalnum(v[0])) {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
603 *((unsigned char*)dest) = v[0];
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
604 } else {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
605 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad character", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
606 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
607 return 0;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
608 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
609
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
610
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
611
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
612 static int getfloat(char **dest)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
613 {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
614 float val = 0.0;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
615 int rc;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
616
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
617 if (debug)
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
618 syslog(LOG_NOTICE, "rdconfig: getfloat: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
619
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
620 rc = sscanf(v, "%f", &val);
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
621 if (rc != 1) {
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
622 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad float value", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
623 return 1;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
624 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
625 *((float*)dest) = val;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
626
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
627 return 0;
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
628 }
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
629
c06190a58f22 More configuration changes. Writing settings implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 53
diff changeset
630
51
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
631 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632 static int getbyt(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
634 Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
635 if (strspn(v,"0123456789") != strlen(v))
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
636 Log_Msg("[rdconfig] %s(%d): %s %s - bad numeric", mypath, linecnt, S(k), S(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637 else
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
638 *((Uint8*)dest)=atoi(v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
639 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
644 /*
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
645 static int gethex(char **dest)
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
646 {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
647 unsigned int val = 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
648 int rc;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
649
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
650 Log_Msg("[rdconfig] gethex: %s(%d): %s %s", mypath, linecnt, k, v);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
651 rc = sscanf(v, "%08x", &val);
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
652 if (rc != 1) {
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
653 Log_Msg("[rdconfig] %s(%d): %s %s - bad hex value", mypath, linecnt, S(k), S(v));
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
654 return 1;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
656 *((int*)dest) = val;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
657
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658 return 0;
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659 }
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
660 */
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
661
a03b6dac5398 Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
662

mercurial