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 |
|
54 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, |
51 {(char *)"lcd_cols", getint, (char **)&Config.lcd_cols}, |
55 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, |
52 {(char *)"lcd_rows", getint, (char **)&Config.lcd_rows}, |
56 {(char *)"rx433", getint, (char **)&Config.rx433}, |
|
57 {(char *)"tx433", getint, (char **)&Config.tx433}, |
53 {(char *)"tx433", getint, (char **)&Config.tx433}, |
58 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, |
54 {(char *)"rcswitch", getrcs, (char **)&Config.rcswitch}, |
59 #endif |
|
60 {NULL, NULL, NULL} |
55 {NULL, NULL, NULL} |
61 }; |
56 }; |
62 |
57 |
63 |
58 |
64 |
59 |
65 void killconfig(void) |
60 void killconfig(void) |
66 { |
61 { |
67 w1_therm *tmp1, *old1; |
62 w1_therm *tmp1, *old1; |
68 #ifdef HAVE_WIRINGPI_H |
|
69 rc_switch *tmp2, *old2; |
63 rc_switch *tmp2, *old2; |
70 #endif |
|
71 |
64 |
72 if (Config.name) |
65 if (Config.name) |
73 free(Config.name); |
66 free(Config.name); |
74 Config.name = NULL; |
67 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 |
68 |
81 for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) { |
69 for (tmp1 = Config.w1therms; tmp1; tmp1 = old1) { |
82 old1 = tmp1->next; |
70 old1 = tmp1->next; |
83 if (tmp1->master) |
71 if (tmp1->master) |
84 free(tmp1->master); |
72 free(tmp1->master); |
107 tmp2->alias = NULL; |
93 tmp2->alias = NULL; |
108 free(tmp2); |
94 free(tmp2); |
109 } |
95 } |
110 Config.rcswitch = NULL; |
96 Config.rcswitch = NULL; |
111 |
97 |
112 #endif |
98 defaultControlSettings(); |
|
99 } |
|
100 |
|
101 |
|
102 |
|
103 int wrconfig(char *config) |
|
104 { |
|
105 int rc = 0; |
|
106 FILE *fp; |
|
107 w1_therm *tmp1; |
|
108 rc_switch *tmp2; |
|
109 |
|
110 mypath = xstrcpy(getenv((char *)"HOME")); |
|
111 mypath = xstrcat(mypath, (char *)"/mbsepi-apps/"); |
|
112 mypath = xstrcat(mypath, config); |
|
113 |
|
114 if (debug) |
|
115 fprintf(stdout, "Writing %s\n", mypath); |
|
116 |
|
117 if ((fp = fopen(mypath, "w")) == NULL) { |
|
118 syslog(LOG_NOTICE, "could not rewrite %s", mypath); |
|
119 return 1; |
|
120 } |
|
121 |
|
122 fprintf(fp, "# Configuration file for thermferm %s\n", VERSION); |
|
123 fprintf(fp, "\n"); |
|
124 |
|
125 fprintf(fp, "# Radio controllers 433 MHz.\n"); |
|
126 fprintf(fp, "#\n"); |
|
127 fprintf(fp, "tx433 %d\n", Config.tx433); |
|
128 fprintf(fp, "\n"); |
|
129 |
|
130 fprintf(fp, "# LCD display\n"); |
|
131 fprintf(fp, "#\n"); |
|
132 fprintf(fp, "lcd_cols %d\n", Config.lcd_cols); |
|
133 fprintf(fp, "lcd_rows %d\n", Config.lcd_rows); |
|
134 fprintf(fp, "\n"); |
|
135 |
|
136 fprintf(fp, "# DS18B20 temperature sensors on the 1-wire bus.\n"); |
|
137 fprintf(fp, "#\n"); |
|
138 fprintf(fp, "# kwd master bus name alias\n"); |
|
139 for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) { |
|
140 fprintf(fp, "w1therm %s %d %s %s\n", tmp1->master, tmp1->bus, tmp1->name, tmp1->alias); |
|
141 } |
|
142 fprintf(fp, "\n"); |
|
143 |
|
144 fprintf(fp, "# RC switches that we want to control.\n"); |
|
145 fprintf(fp, "#\n"); |
|
146 fprintf(fp, "# kwd address alias\n"); |
|
147 for (tmp2 = Config.rcswitch; tmp2; tmp2 = tmp2->next) { |
|
148 fprintf(fp, "rcswitch %s %s\n", tmp2->address, tmp2->alias); |
|
149 } |
|
150 fprintf(fp, "\n"); |
|
151 |
|
152 fprintf(fp, "# End of generated configuration\n"); |
|
153 fclose(fp); |
|
154 syslog(LOG_NOTICE, "Written %s rc=%d", mypath, rc); |
|
155 free(mypath); |
|
156 mypath = NULL; |
|
157 |
|
158 return rc; |
113 } |
159 } |
114 |
160 |
115 |
161 |
116 |
162 |
117 int rdconfig(char *config) |
163 int rdconfig(char *config) |