thermferm/rdconfig.c

changeset 54
c06190a58f22
parent 53
37623517e0ef
child 55
11d7cc3bdf31
equal deleted inserted replaced
53:37623517e0ef 54:c06190a58f22
35 static int getint(char **); 35 static int getint(char **);
36 static int getw1(char **); 36 static int getw1(char **);
37 #ifdef HAVE_WIRINGPI_H 37 #ifdef HAVE_WIRINGPI_H
38 static int getrcs(char **); 38 static int getrcs(char **);
39 #endif 39 #endif
40 static int getuch(char **);
41 static int getfloat(char **);
40 //static int getbyt(char **); 42 //static int getbyt(char **);
41 //static int gethex(char **); 43 //static int gethex(char **);
42 44
43 #define XSTR(x) #x 45 #define XSTR(x) #x
44 #define STR(x) XSTR(x) 46 #define STR(x) XSTR(x)
45 47
46 /* 48 /*
47 * System configuration table 49 * System configuration table
48 */ 50 */
49 key_list keytab[] = { 51 key_list keytab[] = {
50 {(char *)"w1therm", getw1, (char **)&Config.w1therms}, 52 {(char *)"w1therm", getw1, (char **)&Config.w1therms},
51 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, 53 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols},
52 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, 54 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows},
53 {(char *)"tx433", getint, (char **)&Config.tx433}, 55 {(char *)"tx433", getint, (char **)&Config.tx433},
54 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, 56 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch},
55 {NULL, NULL, NULL} 57 {(char *)"cs_mode", getuch, (char **)&Config.cs_mode},
58 {(char *)"cs_beerSet", getfloat, (char **)&Config.cs_beerSet},
59 {(char *)"cs_fridgeSet", getfloat, (char **)&Config.cs_fridgeSet},
60 {(char *)"cs_heatEstimator", getfloat, (char **)&Config.cs_heatEstimator},
61 {(char *)"cs_coolEstimator", getfloat, (char **)&Config.cs_coolEstimator},
62 {(char *)"cc_tempFormat", getuch, (char **)&Config.cc_tempFormat},
63 {(char *)"cc_tempSetMin", getfloat, (char **)&Config.cc_tempSetMin},
64 {(char *)"cc_tempSetMax", getfloat, (char **)&Config.cc_tempSetMax},
65 {(char *)"cc_idleRangeH", getfloat, (char **)&Config.cc_idleRangeH},
66 {(char *)"cc_idleRangeL", getfloat, (char **)&Config.cc_idleRangeL},
67 {NULL, NULL, NULL}
56 }; 68 };
57 69
58 70
59 71
60 void killconfig(void) 72 void killconfig(void)
94 free(tmp2); 106 free(tmp2);
95 } 107 }
96 Config.rcswitch = NULL; 108 Config.rcswitch = NULL;
97 109
98 defaultControlSettings(); 110 defaultControlSettings();
111 defaultControlConstants();
99 } 112 }
100 113
101 114
102 115
103 int wrconfig(char *config) 116 int wrconfig(char *config)
145 fprintf(fp, "#\n"); 158 fprintf(fp, "#\n");
146 fprintf(fp, "# kwd address alias\n"); 159 fprintf(fp, "# kwd address alias\n");
147 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) { 160 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) {
148 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias); 161 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias);
149 } 162 }
163 fprintf(fp, "\n");
164
165 fprintf(fp, "# Control Settings.\n");
166 fprintf(fp, "#\n");
167 fprintf(fp, "cs_mode %c\n", Config.cs_mode);
168 fprintf(fp, "cs_beerSet %.1f\n", Config.cs_beerSet);
169 fprintf(fp, "cs_fridgeSet %.1f\n", Config.cs_fridgeSet);
170 fprintf(fp, "cs_heatEstimator %.1f\n", Config.cs_heatEstimator);
171 fprintf(fp, "cs_coolEstimator %.1f\n", Config.cs_coolEstimator);
172 fprintf(fp, "\n");
173
174 fprintf(fp, "# Control Constants.\n");
175 fprintf(fp, "#\n");
176 fprintf(fp, "cc_tempFormat %c\n", Config.cc_tempFormat);
177 fprintf(fp, "cc_tempSetMin %.1f\n", Config.cc_tempSetMin);
178 fprintf(fp, "cc_tempSetMax %.1f\n", Config.cc_tempSetMax);
179 fprintf(fp, "cc_idleRangeH %.1f\n", Config.cc_idleRangeH);
180 fprintf(fp, "cc_idleRangeL %.1f\n", Config.cc_idleRangeL);
150 fprintf(fp, "\n"); 181 fprintf(fp, "\n");
151 182
152 fprintf(fp, "# End of generated configuration\n"); 183 fprintf(fp, "# End of generated configuration\n");
153 fclose(fp); 184 fclose(fp);
154 syslog(LOG_NOTICE, "Written %s rc=%d", mypath, rc); 185 syslog(LOG_NOTICE, "Written %s rc=%d", mypath, rc);
360 return 0; 391 return 0;
361 } 392 }
362 #endif 393 #endif
363 394
364 395
396
397 static int getuch(char **dest)
398 {
399 if (debug)
400 syslog(LOG_NOTICE, "rdconfig: getuch: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
401
402 if (isalnum(v[0])) {
403 *((unsigned char*)dest) = v[0];
404 } else {
405 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad character", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
406 }
407 return 0;
408 }
409
410
411
412 static int getfloat(char **dest)
413 {
414 float val = 0.0;
415 int rc;
416
417 if (debug)
418 syslog(LOG_NOTICE, "rdconfig: getfloat: %s(%d): %s %s", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
419
420 rc = sscanf(v, "%f", &val);
421 if (rc != 1) {
422 syslog(LOG_NOTICE, "rdconfig: %s(%d): %s %s - bad float value", mypath, linecnt, MBSE_SS(k), MBSE_SS(v));
423 return 1;
424 }
425 *((float*)dest) = val;
426
427 return 0;
428 }
429
430
365 /* 431 /*
366 static int getbyt(char **dest) 432 static int getbyt(char **dest)
367 { 433 {
368 Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v); 434 Log_Msg("[rdconfig] getbyt: %s(%d): %s %s", mypath, linecnt, k, v);
369 if (strspn(v,"0123456789") != strlen(v)) 435 if (strspn(v,"0123456789") != strlen(v))

mercurial