thermometers/rdconfig.c

changeset 144
3446371e0bdb
parent 51
a03b6dac5398
child 145
1396350141cf
equal deleted inserted replaced
143:54f9b5d39e4c 144:3446371e0bdb
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23 #include "thermometers.h" 23 #include "thermometers.h"
24 24
25 25
26 bool debug = FALSE; 26 int debug = FALSE;
27 static char *mypath; 27 static char *mypath;
28 static char *k, *v; 28 static char *k, *v;
29 static int linecnt = 0; 29 static int linecnt = 0;
30 sys_config Config; /* System configuration */ 30 sys_config Config; /* System configuration */
31 31
32 32
33 33
34 static int getw1(char **);
35 #ifdef HAVE_WIRINGPI_H
34 static int getstr(char **); 36 static int getstr(char **);
35 static int getint(char **); 37 static int getint(char **);
36 static int getw1(char **);
37 #ifdef HAVE_WIRINGPI_H
38 static int getrcs(char **); 38 static int getrcs(char **);
39 #endif 39 #endif
40 //static int getbyt(char **); 40 //static int getbyt(char **);
41 //static int gethex(char **); 41 //static int gethex(char **);
42 42
45 45
46 /* 46 /*
47 * System configuration table 47 * System configuration table
48 */ 48 */
49 key_list keytab[] = { 49 key_list keytab[] = {
50 {(char *)"mosq_host", getstr, &Config.mosq_host},
51 {(char *)"mosq_port", getint, (char **)&Config.mosq_port},
52 {(char *)"w1therm", getw1, (char **)&Config.w1therms}, 50 {(char *)"w1therm", getw1, (char **)&Config.w1therms},
53 #ifdef HAVE_WIRINGPI_H 51 #ifdef HAVE_WIRINGPI_H
54 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, 52 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols},
55 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, 53 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows},
56 {(char *)"rx433", getint, (char **)&Config.rx433}, 54 {(char *)"rx433", getint, (char **)&Config.rx433},
70 #endif 68 #endif
71 69
72 if (Config.name) 70 if (Config.name)
73 free(Config.name); 71 free(Config.name);
74 Config.name = NULL; 72 Config.name = NULL;
75
76 if (Config.mosq_host)
77 free(Config.mosq_host);
78 Config.mosq_host= (char *)"localhost";
79 Config.mosq_port = 1883;
80 73
81 for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) { 74 for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) {
82 old1 = tmp1->next; 75 old1 = tmp1->next;
83 if (tmp1->master) 76 if (tmp1->master)
84 free(tmp1->master); 77 free(tmp1->master);
197 return rc; 190 return rc;
198 } 191 }
199 192
200 193
201 194
195 #ifdef HAVE_WIRINGPI_H
202 static int getstr(char **dest) 196 static int getstr(char **dest)
203 { 197 {
204 if (debug) 198 if (debug)
205 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); 199 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
206 200
219 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); 213 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
220 else 214 else
221 *((int*)dest)=atoi(v); 215 *((int*)dest)=atoi(v);
222 return 0; 216 return 0;
223 } 217 }
218 #endif
224 219
225 220
226 221
227 static int getw1(char **dest) 222 static int getw1(char **dest)
228 { 223 {

mercurial