thermferm/rdconfig.c

changeset 66
805f1d285acd
parent 58
e8e7b46b705b
child 69
df5d983dab1b
equal deleted inserted replaced
65:a08a1fce439e 66:805f1d285acd
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *****************************************************************************/ 21 *****************************************************************************/
22 22
23 #include "thermferm.h" 23 #include "thermferm.h"
24 24
25 #ifdef HAVE_WIRINGPI_H
26 25
27 bool debug = FALSE; 26 bool debug = FALSE;
28 static char *mypath; 27 static char *mypath;
29 static char *k, *v; 28 static char *k, *v;
30 static int linecnt = 0; 29 static int linecnt = 0;
31 sys_config Config; /* System configuration */ 30 sys_config Config; /* System configuration */
32 31
33 32
34 33
35 static int getstr(char **); 34 //static int getstr(char **);
36 static int getint(char **); 35 //static int getint(char **);
37 static int getw1(char **); 36 static int getw1(char **);
37 #ifdef HAVE_WIRINGPI_H
38 static int getrcs(char **); 38 static int getrcs(char **);
39 #endif
39 static int getuch(char **); 40 static int getuch(char **);
40 static int getfloat(char **); 41 static int getfloat(char **);
41 //static int getbyt(char **); 42 //static int getbyt(char **);
42 //static int gethex(char **); 43 //static int gethex(char **);
43 44
47 /* 48 /*
48 * System configuration table 49 * System configuration table
49 */ 50 */
50 key_list keytab[] = { 51 key_list keytab[] = {
51 {(char *)"w1therm", getw1, (char **)&Config.w1therms}, 52 {(char *)"w1therm", getw1, (char **)&Config.w1therms},
53 #ifdef HAVE_WIRINGPI_H
52 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, 54 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols},
53 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, 55 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows},
54 {(char *)"tx433", getint, (char **)&Config.tx433}, 56 {(char *)"tx433", getint, (char **)&Config.tx433},
55 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, 57 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch},
58 #endif
56 {(char *)"cs_mode", getuch, (char **)&Config.cs_mode}, 59 {(char *)"cs_mode", getuch, (char **)&Config.cs_mode},
57 {(char *)"cs_beerSet", getfloat, (char **)&Config.cs_beerSet}, 60 {(char *)"cs_beerSet", getfloat, (char **)&Config.cs_beerSet},
58 {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet}, 61 {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet},
59 {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator}, 62 {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator},
60 {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator}, 63 {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator},
69 72
70 73
71 void killconfig(void) 74 void killconfig(void)
72 { 75 {
73 w1_therm *tmp1, *old1; 76 w1_therm *tmp1, *old1;
77 #ifdef HAVE_WIRINGPI_H
74 rc_switch *tmp2, *old2; 78 rc_switch *tmp2, *old2;
79 #endif
75 80
76 if (Config.name) 81 if (Config.name)
77 free(Config.name); 82 free(Config.name);
78 Config.name = NULL; 83 Config.name = NULL;
79 84
88 free(tmp1); 93 free(tmp1);
89 } 94 }
90 Config.w1therms = NULL; 95 Config.w1therms = NULL;
91 Config.my_port = 6554; 96 Config.my_port = 6554;
92 97
98 #ifdef HAVE_WIRINGPI_H
93 Config.lcd_cols = 16; 99 Config.lcd_cols = 16;
94 Config.lcd_rows = 2; 100 Config.lcd_rows = 2;
95 Config.tx433 = -1; 101 Config.tx433 = -1;
96 102
97 for (tmp2 = Config.rcswitch; tmp2; tmp2 = old2) { 103 for (tmp2 = Config.rcswitch; tmp2; tmp2 = old2) {
103 free(tmp2->alias); 109 free(tmp2->alias);
104 tmp2->alias = NULL; 110 tmp2->alias = NULL;
105 free(tmp2); 111 free(tmp2);
106 } 112 }
107 Config.rcswitch = NULL; 113 Config.rcswitch = NULL;
114 #endif
108 115
109 defaultControlSettings(); 116 defaultControlSettings();
110 defaultControlConstants(); 117 defaultControlConstants();
111 } 118 }
112 119
115 int wrconfig(char *config) 122 int wrconfig(char *config)
116 { 123 {
117 int rc = 0; 124 int rc = 0;
118 FILE *fp; 125 FILE *fp;
119 w1_therm *tmp1; 126 w1_therm *tmp1;
127 #ifdef HAVE_WIRINGPI_H
120 rc_switch *tmp2; 128 rc_switch *tmp2;
129 #endif
121 130
122 if (getenv((char *)"USER") == NULL) { 131 if (getenv((char *)"USER") == NULL) {
123 mypath = xstrcpy((char *)"/root"); 132 mypath = xstrcpy((char *)"/root");
124 } else { 133 } else {
125 mypath = xstrcpy(getenv((char *)"HOME")); 134 mypath = xstrcpy(getenv((char *)"HOME"));
136 } 145 }
137 146
138 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION); 147 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION);
139 fprintf(fp, "\n"); 148 fprintf(fp, "\n");
140 149
150 #ifdef HAVE_WIRINGPI_H
141 fprintf(fp, "# Radio controllers 433 MHz.\n"); 151 fprintf(fp, "# Radio controllers 433 MHz.\n");
142 fprintf(fp, "#\n"); 152 fprintf(fp, "#\n");
143 fprintf(fp, "tx433 %d\n", Config.tx433); 153 fprintf(fp, "tx433 %d\n", Config.tx433);
144 fprintf(fp, "\n"); 154 fprintf(fp, "\n");
145 155
146 fprintf(fp, "# LCD display\n"); 156 fprintf(fp, "# LCD display\n");
147 fprintf(fp, "#\n"); 157 fprintf(fp, "#\n");
148 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols); 158 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols);
149 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows); 159 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows);
150 fprintf(fp, "\n"); 160 fprintf(fp, "\n");
161 #endif
151 162
152 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n"); 163 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n");
153 fprintf(fp, "#\n"); 164 fprintf(fp, "#\n");
154 fprintf(fp, "# kwd master bus name alias\n"); 165 fprintf(fp, "# kwd master bus name alias\n");
155 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) { 166 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
156 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias); 167 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias);
157 } 168 }
158 fprintf(fp, "\n"); 169 fprintf(fp, "\n");
159 170
171 #ifdef HAVE_WIRINGPI_H
160 fprintf(fp, "# RC switches that we want to control.\n"); 172 fprintf(fp, "# RC switches that we want to control.\n");
161 fprintf(fp, "#\n"); 173 fprintf(fp, "#\n");
162 fprintf(fp, "# kwd address alias\n"); 174 fprintf(fp, "# kwd address alias\n");
163 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) { 175 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) {
164 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias); 176 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias);
165 } 177 }
166 fprintf(fp, "\n"); 178 fprintf(fp, "\n");
179 #endif
167 180
168 fprintf(fp, "# Control Settings.\n"); 181 fprintf(fp, "# Control Settings.\n");
169 fprintf(fp, "#\n"); 182 fprintf(fp, "#\n");
170 fprintf(fp, "cs_mode %c\n", Config.cs_mode); 183 fprintf(fp, "cs_mode %c\n", Config.cs_mode);
171 fprintf(fp, "cs_beerSet %.1f\n", Config.cs_beerSet); 184 fprintf(fp, "cs_beerSet %.1f\n", Config.cs_beerSet);
284 return rc; 297 return rc;
285 } 298 }
286 299
287 300
288 301
302 /*
289 static int getstr(char **dest) 303 static int getstr(char **dest)
290 { 304 {
291 if (debug) 305 if (debug)
292 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); 306 syslog(LOG_NOTICE, "rdconfig: getstr: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
293 307
294 *dest = xstrcpy(v); 308 *dest = xstrcpy(v);
295 return 0; 309 return 0;
296 } 310 }
297 311 */
298 312
299 313
314
315 /*
300 static int getint(char **dest) 316 static int getint(char **dest)
301 { 317 {
302 if (debug) 318 if (debug)
303 syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); 319 syslog(LOG_NOTICE, "rdconfig: getint: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
304 320
306 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v)); 322 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad numeric", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
307 else 323 else
308 *((int*)dest)=atoi(v); 324 *((int*)dest)=atoi(v);
309 return 0; 325 return 0;
310 } 326 }
327 */
311 328
312 329
313 330
314 static int getw1(char **dest) 331 static int getw1(char **dest)
315 { 332 {
360 return 0; 377 return 0;
361 } 378 }
362 379
363 380
364 381
382 #ifdef HAVE_WIRINGPI_H
365 static int getrcs(char **dest) 383 static int getrcs(char **dest)
366 { 384 {
367 char *p, *q = NULL, *r = NULL; 385 char *p, *q = NULL, *r = NULL;
368 rc_switch **tmpm; 386 rc_switch **tmpm;
369 387
397 (*tmpm)->address = xstrcpy(v); 415 (*tmpm)->address = xstrcpy(v);
398 (*tmpm)->alias = xstrcpy(p); 416 (*tmpm)->alias = xstrcpy(p);
399 417
400 return 0; 418 return 0;
401 } 419 }
420 #endif
402 421
403 422
404 423
405 static int getuch(char **dest) 424 static int getuch(char **dest)
406 { 425 {
465 484
466 return 0; 485 return 0;
467 } 486 }
468 */ 487 */
469 488
470 #endif 489
471

mercurial