Mon, 05 May 2014 23:33:31 +0200
Added coolers program, first draft
7 | 1 | /***************************************************************************** |
2 | * Copyright (C) 2008-2014 | |
3 | * | |
4 | * Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
6 | * This file is part of the mbsePi-apps | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * mbsePi-apps is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with EC-65K; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
21 | *****************************************************************************/ | |
22 | ||
23 | #include "../config.h" | |
24 | #include "mbselib.h" | |
25 | ||
26 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
27 | bool debug = FALSE; |
7 | 28 | static char *mypath; |
29 | static char *k, *v; | |
30 | static int linecnt = 0; | |
31 | sys_config Config; /* System configuration */ | |
32 | ||
33 | ||
34 | ||
35 | static int getstr(char **); | |
36 | static int getint(char **); | |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
37 | static int getw1(char **); |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
38 | static int getrcs(char **); |
7 | 39 | //static int getbyt(char **); |
40 | //static int gethex(char **); | |
41 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
42 | #define XSTR(x) #x |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
43 | #define STR(x) XSTR(x) |
7 | 44 | |
45 | /* | |
46 | * System configuration table | |
47 | */ | |
48 | key_list keytab[] = { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
49 | {(char *)"mosq_host", getstr, &Config.mosq_host}, |
7 | 50 | {(char *)"mosq_port", getint, (char **)&Config.mosq_port}, |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
51 | {(char *)"w1therm", getw1, (char **)&Config.w1therms}, |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
52 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
53 | {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
54 | {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
55 | {(char *)"rx433", getint, (char **)&Config.rx433}, |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
56 | {(char *)"tx433", getint, (char **)&Config.tx433}, |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
57 | {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
58 | #endif |
7 | 59 | {NULL, NULL, NULL} |
60 | }; | |
61 | ||
62 | ||
63 | ||
64 | void killconfig(void) | |
65 | { | |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
66 | w1_therm *tmp1, *old1; |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
67 | rc_switch *tmp2, *old2; |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
68 | |
7 | 69 | if (Config.name) |
70 | free(Config.name); | |
71 | Config.name = NULL; | |
72 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
73 | if (Config.mosq_host) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
74 | free(Config.mosq_host); |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
75 | Config.mosq_host= (char *)"localhost"; |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
76 | Config.mosq_port = 1883; |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
77 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
78 | for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
79 | old1 = tmp1->next; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
80 | if (tmp1->master) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
81 | free(tmp1->master); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
82 | if (tmp1->name) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
83 | free(tmp1->name); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
84 | if (tmp1->alias) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
85 | free(tmp1->alias); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
86 | free(tmp1); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
87 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
88 | Config.w1therms = NULL; |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
89 | |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
90 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
91 | Config.lcd_cols = 16; |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
92 | Config.lcd_rows = 2; |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
93 | Config.rx433 = -1; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
94 | Config.tx433 = -1; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
95 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
96 | for (tmp2 = Config.rcswitch; tmp2; tmp2 = old2) { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
97 | old2 = tmp2->next; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
98 | if (tmp2->address) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
99 | free(tmp2->address); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
100 | tmp2->address = NULL; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
101 | if (tmp2->alias) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
102 | free(tmp2->alias); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
103 | tmp2->alias = NULL; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
104 | free(tmp2); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
105 | } |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
106 | Config.rcswitch = NULL; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
107 | |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
108 | #endif |
7 | 109 | } |
110 | ||
111 | ||
112 | ||
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
113 | int rdconfig(char *config) |
7 | 114 | { |
115 | char buf[256], *p; | |
116 | FILE *fp; | |
117 | int i, rc = 0; | |
118 | ||
119 | killconfig(); | |
120 | ||
121 | /* | |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
122 | * Search config file |
7 | 123 | */ |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
124 | mypath = xstrcpy(getenv((char *)"HOME")); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
125 | mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
126 | mypath = xstrcat(mypath, config); |
7 | 127 | if ((fp = fopen(mypath, "r")) == NULL) { |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
128 | /* |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
129 | * Not in the users home directory |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
130 | */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
131 | free(mypath); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
132 | mypath = xstrcpy((char *)"/etc/mbsepi-apps/"); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
133 | mypath = xstrcat(mypath, config); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
134 | if ((fp = fopen(mypath, "r")) == NULL) { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
135 | /* |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
136 | * Try /usr/local/etc |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
137 | */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
138 | free(mypath); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
139 | mypath = xstrcpy((char *)"/usr/local/etc/mbsepi-apps/"); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
140 | mypath = xstrcat(mypath, config); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
141 | if ((fp = fopen(mypath, "r")) == NULL) { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
142 | syslog(LOG_NOTICE, "rdconfig: could not open %s", mypath); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
143 | return 1; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
144 | } |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
145 | } |
7 | 146 | } |
147 | ||
148 | linecnt = 0; | |
149 | while (fgets(buf, sizeof(buf) -1, fp)) { | |
150 | linecnt++; | |
151 | if (*(p = buf + strlen(buf) -1) != '\n') { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
152 | syslog(LOG_NOTICE, "rdconfig: %s(%d): \"%s\" - line too long", mypath, linecnt, buf); |
7 | 153 | rc = 1; |
154 | break; | |
155 | } | |
156 | *p-- = '\0'; | |
157 | while ((p >= buf) && isspace(*p)) | |
158 | *p-- = '\0'; | |
159 | k = buf; | |
160 | while (*k && isspace(*k)) | |
161 | k++; | |
162 | p = k; | |
163 | while (*p && !isspace(*p)) | |
164 | p++; | |
165 | *p++='\0'; | |
166 | v = p; | |
167 | while (*v && isspace(*v)) | |
168 | v++; | |
169 | ||
170 | if ((*k == '\0') || (*k == '#')) { | |
171 | continue; | |
172 | } | |
173 | ||
174 | for (i = 0; keytab[i].key; i++) | |
175 | if (strcasecmp(k,keytab[i].key) == 0) | |
176 | break; | |
177 | ||
178 | if (keytab[i].key == NULL) { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
179 | syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - unknown keyword", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
7 | 180 | rc = 1; |
181 | break; | |
182 | } else if ((keytab[i].prc(keytab[i].dest))) { | |
183 | rc = 1; | |
184 | break; | |
185 | } | |
186 | ||
187 | } | |
188 | fclose(fp); | |
189 | ||
190 | free(mypath); | |
191 | mypath = NULL; | |
192 | ||
193 | return rc; | |
194 | } | |
195 | ||
196 | ||
197 | ||
198 | static int getstr(char **dest) | |
199 | { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
200 | if (debug) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
201 | syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
202 | |
7 | 203 | *dest = xstrcpy(v); |
204 | return 0; | |
205 | } | |
206 | ||
207 | ||
208 | ||
209 | static int getint(char **dest) | |
210 | { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
211 | if (debug) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
212 | syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
213 | |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
214 | if (strspn(v,"0123456789") != strlen(v)) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
215 | syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
216 | else |
7 | 217 | *((int*)dest)=atoi(v); |
218 | return 0; | |
219 | } | |
220 | ||
221 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
222 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
223 | static int getw1(char **dest) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
224 | { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
225 | char *p, *q = NULL, *r = NULL; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
226 | w1_therm **tmpm; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
227 | int rc = 0, tmpp; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
228 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
229 | for (p = v; *p && !isspace(*p); p++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
230 | if (*p) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
231 | *p++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
232 | while (*p && isspace(*p)) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
233 | p++; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
234 | if (*p == '\0') { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
235 | syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
236 | return 1; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
237 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
238 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
239 | for (q = p; *q && !isspace(*q); q++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
240 | if (*q && isspace(*q)) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
241 | if (*q) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
242 | *q++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
243 | while (*q && isspace(*q)) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
244 | q++; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
245 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
246 | for (r = q; *r && !isspace(*r); r++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
247 | if (*r) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
248 | *r++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
249 | rc = sscanf(p, "%d", &tmpp); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
250 | if (rc != 1) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
251 | syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s is not a integer value", mypath, linecnt, p); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
252 | return 1; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
253 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
254 | if (debug) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
255 | syslog(LOG_NOTICE, "rdconfig: getw1: %s(%d): %s %d %s %s", mypath, linecnt, v, tmpp, q, r); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
256 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
257 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
258 | for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next)); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
259 | (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm)); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
260 | (*tmpm)->next = NULL; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
261 | (*tmpm)->master = xstrcpy(v); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
262 | (*tmpm)->bus = tmpp; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
263 | (*tmpm)->name = xstrcpy(q); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
264 | (*tmpm)->alias = xstrcpy(r); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
265 | (*tmpm)->present = 0; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
266 | (*tmpm)->lastval = 0; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
267 | (*tmpm)->update = 0; |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
268 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
269 | return 0; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
270 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
271 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
272 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
273 | |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
274 | static int getrcs(char **dest) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
275 | { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
276 | char *p, *q = NULL, *r = NULL; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
277 | rc_switch **tmpm; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
278 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
279 | for (p = v; *p && !isspace(*p); p++); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
280 | if (*p) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
281 | *p++ = '\0'; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
282 | while (*p && isspace(*p)) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
283 | p++; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
284 | if (*p == '\0') { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
285 | syslog(LOG_NOTICE, "rdconfig: %s(%d): less then two tokens", mypath, linecnt); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
286 | return 1; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
287 | } |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
288 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
289 | for (q = p; *q && !isspace(*q); q++); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
290 | if (*q && isspace(*q)) { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
291 | if (*q) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
292 | *q++ = '\0'; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
293 | while (*q && isspace(*q)) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
294 | q++; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
295 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
296 | for (r = q; *r && !isspace(*r); r++); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
297 | if (*r) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
298 | *r++ = '\0'; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
299 | if (debug) |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
300 | syslog(LOG_NOTICE, "rdconfig: getrcs: %s(%d): %s %s", mypath, linecnt, v, p); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
301 | } |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
302 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
303 | for (tmpm = (rc_switch**)dest; *tmpm; tmpm=&((*tmpm)->next)); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
304 | (*tmpm) = (rc_switch *) xmalloc(sizeof(rc_switch)); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
305 | (*tmpm)->next = NULL; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
306 | (*tmpm)->address = xstrcpy(v); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
307 | (*tmpm)->alias = xstrcpy(p); |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
308 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
309 | return 0; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
310 | } |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
311 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
312 | |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
313 | |
7 | 314 | /* |
315 | static int getbyt(char **dest) | |
316 | { | |
317 | Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v); | |
318 | if (strspn(v,"0123456789") != strlen(v)) | |
319 | Log_Msg("[rdconfig] %s(%d): %s %s - bad numeric", mypath, linecnt, S(k), S(v)); | |
320 | else | |
321 | *((Uint8*)dest)=atoi(v); | |
322 | return 0; | |
323 | } | |
324 | */ | |
325 | ||
326 | ||
327 | /* | |
328 | static int gethex(char **dest) | |
329 | { | |
330 | unsigned int val = 0; | |
331 | int rc; | |
332 | ||
333 | Log_Msg("[rdconfig] gethex: %s(%d): %s %s", mypath, linecnt, k, v); | |
334 | rc = sscanf(v, "%08x", &val); | |
335 | if (rc != 1) { | |
336 | Log_Msg("[rdconfig] %s(%d): %s %s - bad hex value", mypath, linecnt, S(k), S(v)); | |
337 | return 1; | |
338 | } | |
339 | *((int*)dest) = val; | |
340 | ||
341 | return 0; | |
342 | } | |
343 | */ | |
344 | ||
345 |