Fri, 09 May 2014 20:39:01 +0200
Added user log function for program data
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; |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
93 | |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
94 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
95 | Config.lcd_cols = 16; |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
96 | 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
|
97 | 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
|
98 | 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
|
99 | |
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 | 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
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | 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
|
106 | 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
|
107 | 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
|
108 | 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
|
109 | } |
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 | 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
|
111 | |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
9
diff
changeset
|
112 | #endif |
7 | 113 | } |
114 | ||
115 | ||
116 | ||
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
|
117 | int rdconfig(char *config) |
7 | 118 | { |
119 | char buf[256], *p; | |
120 | FILE *fp; | |
121 | int i, rc = 0; | |
122 | ||
123 | killconfig(); | |
124 | ||
125 | /* | |
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
|
126 | * Search config file |
7 | 127 | */ |
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 | 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
|
129 | 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
|
130 | mypath = xstrcat(mypath, config); |
7 | 131 | 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
|
132 | /* |
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 | * 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
|
134 | */ |
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 | 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
|
136 | 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
|
137 | 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
|
138 | 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
|
139 | /* |
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 | * 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
|
141 | */ |
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 | 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
|
143 | 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
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | 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
|
148 | } |
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 | } |
7 | 150 | } |
151 | ||
152 | linecnt = 0; | |
153 | while (fgets(buf, sizeof(buf) -1, fp)) { | |
154 | linecnt++; | |
155 | 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
|
156 | syslog(LOG_NOTICE, "rdconfig: %s(%d): \"%s\" - line too long", mypath, linecnt, buf); |
7 | 157 | rc = 1; |
158 | break; | |
159 | } | |
160 | *p-- = '\0'; | |
161 | while ((p >= buf) && isspace(*p)) | |
162 | *p-- = '\0'; | |
163 | k = buf; | |
164 | while (*k && isspace(*k)) | |
165 | k++; | |
166 | p = k; | |
167 | while (*p && !isspace(*p)) | |
168 | p++; | |
169 | *p++='\0'; | |
170 | v = p; | |
171 | while (*v && isspace(*v)) | |
172 | v++; | |
173 | ||
174 | if ((*k == '\0') || (*k == '#')) { | |
175 | continue; | |
176 | } | |
177 | ||
178 | for (i = 0; keytab[i].key; i++) | |
179 | if (strcasecmp(k,keytab[i].key) == 0) | |
180 | break; | |
181 | ||
182 | 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
|
183 | syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - unknown keyword", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); |
7 | 184 | rc = 1; |
185 | break; | |
186 | } else if ((keytab[i].prc(keytab[i].dest))) { | |
187 | rc = 1; | |
188 | break; | |
189 | } | |
190 | ||
191 | } | |
192 | fclose(fp); | |
193 | ||
194 | free(mypath); | |
195 | mypath = NULL; | |
196 | ||
197 | return rc; | |
198 | } | |
199 | ||
200 | ||
201 | ||
202 | static int getstr(char **dest) | |
203 | { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
204 | if (debug) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
205 | 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
|
206 | |
7 | 207 | *dest = xstrcpy(v); |
208 | return 0; | |
209 | } | |
210 | ||
211 | ||
212 | ||
213 | static int getint(char **dest) | |
214 | { | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
215 | if (debug) |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
216 | 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
|
217 | |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
218 | 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
|
219 | 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
|
220 | else |
7 | 221 | *((int*)dest)=atoi(v); |
222 | return 0; | |
223 | } | |
224 | ||
225 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
226 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
227 | static int getw1(char **dest) |
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 | char *p, *q = NULL, *r = NULL; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
230 | w1_therm **tmpm; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
231 | int rc = 0, tmpp; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
232 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
233 | for (p = v; *p && !isspace(*p); p++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
234 | if (*p) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
235 | *p++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
236 | while (*p && isspace(*p)) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
237 | p++; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
238 | if (*p == '\0') { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
239 | 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
|
240 | return 1; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
241 | } |
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 | for (q = p; *q && !isspace(*q); q++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
244 | if (*q && isspace(*q)) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
245 | if (*q) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
246 | *q++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
247 | while (*q && isspace(*q)) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
248 | q++; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
249 | |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
250 | for (r = q; *r && !isspace(*r); r++); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
251 | if (*r) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
252 | *r++ = '\0'; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
253 | rc = sscanf(p, "%d", &tmpp); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
254 | if (rc != 1) { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
255 | 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
|
256 | return 1; |
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 | if (debug) |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
259 | 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
|
260 | } |
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 | for (tmpm = (w1_therm**)dest; *tmpm; tmpm=&((*tmpm)->next)); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
263 | (*tmpm) = (w1_therm *) xmalloc(sizeof(w1_therm)); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
264 | (*tmpm)->next = NULL; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
265 | (*tmpm)->master = xstrcpy(v); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
266 | (*tmpm)->bus = tmpp; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
267 | (*tmpm)->name = xstrcpy(q); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
268 | (*tmpm)->alias = xstrcpy(r); |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
269 | (*tmpm)->present = 0; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
270 | (*tmpm)->lastval = 0; |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
24
diff
changeset
|
271 | (*tmpm)->update = 0; |
9
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 | return 0; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
274 | } |
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 | |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
278 | #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
|
279 | 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
|
280 | { |
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 | 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
|
282 | 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
|
283 | |
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 | 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
|
285 | 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
|
286 | *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
|
287 | 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
|
288 | 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 | 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
|
290 | 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
|
291 | 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
|
292 | } |
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 | 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
|
295 | 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
|
296 | 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
|
297 | *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
|
298 | 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
|
299 | 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 | |
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 | 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
|
302 | 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
|
303 | *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
|
304 | 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
|
305 | 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
|
306 | } |
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 | 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
|
309 | (*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
|
310 | (*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
|
311 | (*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
|
312 | (*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
|
313 | |
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 | 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
|
315 | } |
30
9c7119ac0455
Fix for conditional defines for wiringPi library
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
316 | #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
|
317 | |
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 | |
7 | 319 | /* |
320 | static int getbyt(char **dest) | |
321 | { | |
322 | Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v); | |
323 | if (strspn(v,"0123456789") != strlen(v)) | |
324 | Log_Msg("[rdconfig] %s(%d): %s %s - bad numeric", mypath, linecnt, S(k), S(v)); | |
325 | else | |
326 | *((Uint8*)dest)=atoi(v); | |
327 | return 0; | |
328 | } | |
329 | */ | |
330 | ||
331 | ||
332 | /* | |
333 | static int gethex(char **dest) | |
334 | { | |
335 | unsigned int val = 0; | |
336 | int rc; | |
337 | ||
338 | Log_Msg("[rdconfig] gethex: %s(%d): %s %s", mypath, linecnt, k, v); | |
339 | rc = sscanf(v, "%08x", &val); | |
340 | if (rc != 1) { | |
341 | Log_Msg("[rdconfig] %s(%d): %s %s - bad hex value", mypath, linecnt, S(k), S(v)); | |
342 | return 1; | |
343 | } | |
344 | *((int*)dest) = val; | |
345 | ||
346 | return 0; | |
347 | } | |
348 | */ | |
349 | ||
350 |