thermferm/server.c

changeset 86
3d7a241329e2
parent 85
c3cc6e44d1a4
child 87
55f1315c94f1
equal deleted inserted replaced
85:c3cc6e44d1a4 86:3d7a241329e2
166 * LIST PROFILES 166 * LIST PROFILES
167 * LIST UNIT 167 * LIST UNIT
168 */ 168 */
169 int cmd_list(char *buf) 169 int cmd_list(char *buf)
170 { 170 {
171 char *cmd, *opt; 171 char *cmd, *opt, *mypath;
172 units_list *unit; 172 units_list *unit;
173 int i; 173 int i;
174 DIR *fd; 174 DIR *fd;
175 struct dirent *de; 175 struct dirent *de;
176 176
184 i++; 184 i++;
185 srv_send((char *)"%02d %s %-20s %-7s", i, unit->uuid, unit->name, UNITMODE[unit->mode]); 185 srv_send((char *)"%02d %s %-20s %-7s", i, unit->uuid, unit->name, UNITMODE[unit->mode]);
186 } 186 }
187 srv_send((char *)"."); 187 srv_send((char *)".");
188 } else if (strcmp(opt, (char *)"BUS") == 0) { 188 } else if (strcmp(opt, (char *)"BUS") == 0) {
189 /*
190 * 1-wire bus
191 */
189 if ((fd = opendir((char *)"/sys/bus/w1/devices"))) { 192 if ((fd = opendir((char *)"/sys/bus/w1/devices"))) {
190 srv_send((char *)"212 1-wire bus devices:"); 193 srv_send((char *)"212 1-wire bus devices:");
191 while ((de = readdir(fd))) { 194 while ((de = readdir(fd))) {
192 if (de->d_name[0] != '.') { 195 if (de->d_name[0] != '.') {
193 if (strncmp(de->d_name, (char *)"w1", 2) == 0) { 196 if (strncmp(de->d_name, (char *)"w1", 2) == 0) {
194 srv_send((char *)"%-15s system device", de->d_name); 197 srv_send((char *)"%-15s system device", de->d_name);
195 } else if (strncmp(de->d_name, (char *)"10", 2) == 0) { 198 } else if (strncmp(de->d_name, (char *)"10", 2) == 0) {
196 srv_send((char *)"%-15s 18S20 digital thermometer", de->d_name); 199 srv_send((char *)"%-15s 18S20 digital thermometer", de->d_name);
197 } else if (strncmp(de->d_name, (char *)"28", 2) == 0) { 200 } else if (strncmp(de->d_name, (char *)"28", 2) == 0) {
198 srv_send((char *)"%-15s 18B20 digital thermometer", de->d_name); 201 srv_send((char *)"%-15s 18B20 digital thermometer", de->d_name);
199 } else if (strncmp(de->d_name, (char *)"29", 2) == 0) { 202 } else if (strncmp(de->d_name, (char *)"29", 2) == 0) {
200 srv_send((char *)"%-15s 2408 8-channel addressable switch", de->d_name); 203 srv_send((char *)"%-15s 2408 8-channel addressable switch/LCD", de->d_name);
201 } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) { 204 } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) {
202 srv_send((char *)"%-15s 2413 dual channel addressable switchs", de->d_name); 205 srv_send((char *)"%-15s 2413 dual channel addressable switchs", de->d_name);
203 } else { 206 } else {
204 srv_send((char *)"%-15s unknown device", de->d_name); 207 srv_send((char *)"%-15s unknown device", de->d_name);
205 }
206 } 208 }
207 } 209 }
208 srv_send((char *)"."); 210 }
211 srv_send((char *)".");
209 closedir(fd); 212 closedir(fd);
210 } else { 213 } else {
211 srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno)); 214 srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno));
212 } 215 }
213 } else if (strcmp(opt, (char *)"PROFILES") == 0) { 216 } else if (strcmp(opt, (char *)"PROFILES") == 0) {
214 217 /*
218 * User profiles directory
219 */
220 if (getenv((char *)"USER") == NULL) {
221 mypath = xstrcpy((char *)"/root");
222 } else {
223 mypath = xstrcpy(getenv((char *)"HOME"));
224 }
225 mypath = xstrcat(mypath, (char *)"/.thermferm/profiles/");
226 mkdirs(mypath, 0755);
227 if ((fd = opendir(mypath))) {
228 srv_send((char *)"212 profiles:");
229 while ((de = readdir(fd))) {
230 if (de->d_name[0] != '.') {
231 srv_send((char *)"%s", de->d_name);
232 }
233 }
234 srv_send((char *)".");
235 closedir(fd);
236 } else {
237 srv_send((char *)"503 directory %s: %s", mypath, strerror(errno));
238 }
239 free(mypath);
240 mypath = NULL;
215 } else if (strcmp(opt, (char *)"UNIT") == 0) { 241 } else if (strcmp(opt, (char *)"UNIT") == 0) {
242 /*
243 * List configured and selected fermenter unit
244 */
216 if (current_unit == -1) { 245 if (current_unit == -1) {
217 srv_send((char *)"401 No fermenter unit selected"); 246 srv_send((char *)"401 No fermenter unit selected");
218 } else { 247 } else {
219 248
220 } 249 }

mercurial