Tue, 20 May 2014 22:42:26 +0200
Updated dependencies
7 | 1 | /***************************************************************************** |
32
3bac8fd4173d
Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents:
30
diff
changeset
|
2 | * Copyright (C) 2014 |
7 | 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 **); |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
38 | #ifdef HAVE_WIRINGPI_H |
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
|
39 | static int getrcs(char **); |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
40 | #endif |
7 | 41 | //static int getbyt(char **); |
42 | //static int gethex(char **); | |
43 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
44 | #define XSTR(x) #x |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
45 | #define STR(x) XSTR(x) |
7 | 46 | |
47 | /* | |
48 | * System configuration table | |
49 | */ | |
50 | key_list keytab[] = { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
51 | {(char *)"mosq_host", getstr, &Config.mosq_host}, |
7 | 52 | {(char *)"mosq_port", getint, (char **)&Config.mosq_port}, |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
53 | {(char *)"w1therm", getw1, (char **)&Config.w1therms}, |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
54 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
55 | {(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
|
56 | {(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
|
57 | {(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
|
58 | {(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
|
59 | {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
60 | #endif |
7 | 61 | {NULL, NULL, NULL} |
62 | }; | |
63 | ||
64 | ||
65 | ||
66 | void killconfig(void) | |
67 | { | |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
68 | w1_therm *tmp1, *old1; |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
69 | #ifdef HAVE_WIRINGPI_H |
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
|
70 | rc_switch *tmp2, *old2; |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
71 | #endif |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
72 | |
7 | 73 | if (Config.name) |
74 | free(Config.name); | |
75 | Config.name = NULL; | |
76 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
77 | if (Config.mosq_host) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
78 | free(Config.mosq_host); |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
79 | Config.mosq_host= (char *)"localhost"; |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
80 | Config.mosq_port = 1883; |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
81 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
82 | for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
83 | old1 = tmp1->next; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
84 | if (tmp1->master) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
85 | free(tmp1->master); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
86 | if (tmp1->name) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
87 | free(tmp1->name); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
88 | if (tmp1->alias) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
89 | free(tmp1->alias); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
90 | free(tmp1); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
91 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
92 | Config.w1therms = NULL; |
43 | 93 | Config.my_port = 6554; |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
94 | |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
95 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
96 | Config.lcd_cols = 16; |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
97 | 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
|
98 | 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
|
99 | 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
|
100 | |
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 | 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
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | 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
|
106 | 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
|
107 | 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
|
108 | 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
|
109 | 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
|
110 | } |
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
|
111 | 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
|
112 | |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
113 | #endif |
7 | 114 | } |
115 | ||
116 | ||
117 | ||
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
|
118 | int rdconfig(char *config) |
7 | 119 | { |
120 | char buf[256], *p; | |
121 | FILE *fp; | |
122 | int i, rc = 0; | |
123 | ||
124 | killconfig(); | |
125 | ||
126 | /* | |
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
|
127 | * Search config file |
7 | 128 | */ |
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
|
129 | 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
|
130 | 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
|
131 | mypath = xstrcat(mypath, config); |
7 | 132 | 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
|
133 | /* |
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 | * 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
|
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 | 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
|
137 | 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
|
138 | 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
|
139 | 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
|
140 | /* |
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 | * 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
|
142 | */ |
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 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | 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
|
149 | } |
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
|
150 | } |
7 | 151 | } |
152 | ||
153 | linecnt = 0; | |
154 | while (fgets(buf, sizeof(buf) -1, fp)) { | |
155 | linecnt++; | |
156 | 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
|
157 | syslog(LOG_NOTICE, "rdconfig: %s(%d): \"%s\" - line too long", mypath, linecnt, buf); |
7 | 158 | rc = 1; |
159 | break; | |
160 | } | |
161 | *p-- = '\0'; | |
162 | while ((p >= buf) && isspace(*p)) | |
163 | *p-- = '\0'; | |
164 | k = buf; | |
165 | while (*k && isspace(*k)) | |
166 | k++; | |
167 | p = k; | |
168 | while (*p && !isspace(*p)) | |
169 | p++; | |
170 | *p++='\0'; | |
171 | v = p; | |
172 | while (*v && isspace(*v)) | |
173 | v++; | |
174 | ||
175 | if ((*k == '\0') || (*k == '#')) { | |
176 | continue; | |
177 | } | |
178 | ||
179 | for (i = 0; keytab[i].key; i++) | |
180 | if (strcasecmp(k,keytab[i].key) == 0) | |
181 | break; | |
182 | ||
183 | 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
|
184 | syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - unknown keyword", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
7 | 185 | rc = 1; |
186 | break; | |
187 | } else if ((keytab[i].prc(keytab[i].dest))) { | |
188 | rc = 1; | |
189 | break; | |
190 | } | |
191 | ||
192 | } | |
193 | fclose(fp); | |
194 | ||
195 | free(mypath); | |
196 | mypath = NULL; | |
197 | ||
198 | return rc; | |
199 | } | |
200 | ||
201 | ||
202 | ||
203 | static int getstr(char **dest) | |
204 | { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
205 | if (debug) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
206 | 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
|
207 | |
7 | 208 | *dest = xstrcpy(v); |
209 | return 0; | |
210 | } | |
211 | ||
212 | ||
213 | ||
214 | static int getint(char **dest) | |
215 | { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
216 | if (debug) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
217 | 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
|
218 | |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
219 | 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
|
220 | 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
|
221 | else |
7 | 222 | *((int*)dest)=atoi(v); |
223 | return 0; | |
224 | } | |
225 | ||
226 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
227 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
228 | static int getw1(char **dest) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
229 | { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
230 | char *p, *q = NULL, *r = NULL; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
231 | w1_therm **tmpm; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
232 | int rc = 0, tmpp; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
233 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
234 | for (p = v; *p && !isspace(*p); p++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
235 | if (*p) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
236 | *p++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
237 | while (*p && isspace(*p)) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
238 | p++; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
239 | if (*p == '\0') { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
240 | 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
|
241 | return 1; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
242 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
243 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
244 | for (q = p; *q && !isspace(*q); q++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
245 | if (*q && isspace(*q)) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
246 | if (*q) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
247 | *q++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
248 | while (*q && isspace(*q)) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
249 | q++; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
250 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
251 | for (r = q; *r && !isspace(*r); r++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
252 | if (*r) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
253 | *r++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
254 | rc = sscanf(p, "%d", &tmpp); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
255 | if (rc != 1) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
256 | 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
|
257 | return 1; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
258 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
259 | if (debug) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
260 | 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
|
261 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
262 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
263 | for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next)); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
264 | (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm)); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
265 | (*tmpm)->next = NULL; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
266 | (*tmpm)->master = xstrcpy(v); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
267 | (*tmpm)->bus = tmpp; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
268 | (*tmpm)->name = xstrcpy(q); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
269 | (*tmpm)->alias = xstrcpy(r); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
270 | (*tmpm)->present = 0; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
271 | (*tmpm)->lastval = 0; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
272 | (*tmpm)->update = 0; |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
273 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
274 | return 0; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
275 | } |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
276 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
277 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
278 | |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
279 | #ifdef HAVE_WIRINGPI_H |
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
|
280 | 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
|
281 | { |
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 | 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
|
283 | 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
|
284 | |
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 | 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
|
286 | 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
|
287 | *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
|
288 | 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
|
289 | 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
|
290 | 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
|
291 | 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
|
292 | 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
|
293 | } |
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 | |
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 | 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
|
296 | 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
|
297 | 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
|
298 | *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
|
299 | 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
|
300 | 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
|
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 | 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
|
303 | 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
|
304 | *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
|
305 | 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
|
306 | 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
|
307 | } |
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 | 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
|
310 | (*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
|
311 | (*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
|
312 | (*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
|
313 | (*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
|
314 | |
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
|
315 | 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
|
316 | } |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
317 | #endif |
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
|
318 | |
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
|
319 | |
7 | 320 | /* |
321 | static int getbyt(char **dest) | |
322 | { | |
323 | Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v); | |
324 | if (strspn(v,"0123456789") != strlen(v)) | |
325 | Log_Msg("[rdconfig] %s(%d): %s %s - bad numeric", mypath, linecnt, S(k), S(v)); | |
326 | else | |
327 | *((Uint8*)dest)=atoi(v); | |
328 | return 0; | |
329 | } | |
330 | */ | |
331 | ||
332 | ||
333 | /* | |
334 | static int gethex(char **dest) | |
335 | { | |
336 | unsigned int val = 0; | |
337 | int rc; | |
338 | ||
339 | Log_Msg("[rdconfig] gethex: %s(%d): %s %s", mypath, linecnt, k, v); | |
340 | rc = sscanf(v, "%08x", &val); | |
341 | if (rc != 1) { | |
342 | Log_Msg("[rdconfig] %s(%d): %s %s - bad hex value", mypath, linecnt, S(k), S(v)); | |
343 | return 1; | |
344 | } | |
345 | *((int*)dest) = val; | |
346 | ||
347 | return 0; | |
348 | } | |
349 | */ | |
350 | ||
351 |