diff -r 4387a6b11eb3 -r 37623517e0ef thermferm/rdconfig.c --- a/thermferm/rdconfig.c Sun May 25 22:37:23 2014 +0200 +++ b/thermferm/rdconfig.c Sun May 25 23:29:07 2014 +0200 @@ -47,16 +47,11 @@ * System configuration table */ key_list keytab[] = { - {(char *)"mosq_host", getstr, &Config.mosq_host}, - {(char *)"mosq_port", getint, (char **)&Config.mosq_port}, {(char *)"w1therm", getw1, (char **)&Config.w1therms}, -#ifdef HAVE_WIRINGPI_H {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, - {(char *)"rx433", getint, (char **)&Config.rx433}, {(char *)"tx433", getint, (char **)&Config.tx433}, {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, -#endif {NULL, NULL, NULL} }; @@ -65,19 +60,12 @@ void killconfig(void) { w1_therm *tmp1, *old1; -#ifdef HAVE_WIRINGPI_H rc_switch *tmp2, *old2; -#endif if (Config.name) free(Config.name); Config.name = NULL; - if (Config.mosq_host) - free(Config.mosq_host); - Config.mosq_host= (char *)"localhost"; - Config.mosq_port = 1883; - for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) { old1 = tmp1->next; if (tmp1->master) @@ -91,10 +79,8 @@ Config.w1therms = NULL; Config.my_port = 6554; -#ifdef HAVE_WIRINGPI_H Config.lcd_cols = 16; Config.lcd_rows = 2; - Config.rx433 = -1; Config.tx433 = -1; for (tmp2 = Config.rcswitch; tmp2; tmp2 = old2) { @@ -109,7 +95,67 @@ } Config.rcswitch = NULL; -#endif + defaultControlSettings(); +} + + + +int wrconfig(char *config) +{ + int rc = 0; + FILE *fp; + w1_therm *tmp1; + rc_switch *tmp2; + + mypath = xstrcpy(getenv((char *)"HOME")); + mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); + mypath = xstrcat(mypath, config); + + if (debug) + fprintf(stdout, "Writing %s\n", mypath); + + if ((fp = fopen(mypath, "w")) == NULL) { + syslog(LOG_NOTICE, "could not rewrite %s", mypath); + return 1; + } + + fprintf(fp, "# Configuration file for thermferm %s\n", VERSION); + fprintf(fp, "\n"); + + fprintf(fp, "# Radio controllers 433 MHz.\n"); + fprintf(fp, "#\n"); + fprintf(fp, "tx433 %d\n", Config.tx433); + fprintf(fp, "\n"); + + fprintf(fp, "# LCD display\n"); + fprintf(fp, "#\n"); + fprintf(fp, "lcd_cols %d\n", Config.lcd_cols); + fprintf(fp, "lcd_rows %d\n", Config.lcd_rows); + fprintf(fp, "\n"); + + fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n"); + fprintf(fp, "#\n"); + fprintf(fp, "# kwd master bus name alias\n"); + for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) { + fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias); + } + fprintf(fp, "\n"); + + fprintf(fp, "# RC switches that we want to control.\n"); + fprintf(fp, "#\n"); + fprintf(fp, "# kwd address alias\n"); + for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) { + fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias); + } + fprintf(fp, "\n"); + + fprintf(fp, "# End of generated configuration\n"); + fclose(fp); + syslog(LOG_NOTICE, "Written %s rc=%d", mypath, rc); + free(mypath); + mypath = NULL; + + return rc; }