thermferm/server.c

changeset 163
3d813570a5e3
parent 158
f1b7e2ef90be
child 167
56b008563db8
equal deleted inserted replaced
162:6fc9e3f7962f 163:3d813570a5e3
346 { 346 {
347 char *opt, *filename, *p, q[2], buffer[256]; 347 char *opt, *filename, *p, q[2], buffer[256];
348 units_list *unit; 348 units_list *unit;
349 profiles_list *profile; 349 profiles_list *profile;
350 prof_step *step; 350 prof_step *step;
351 int j, ref; 351 devices_list *device;
352 DIR *fd; 352 int j;
353 FILE *fp; 353 FILE *fp;
354 struct dirent *de;
355 354
356 opt = strtok(buf, " \0"); 355 opt = strtok(buf, " \0");
357 opt = strtok(NULL, "\0"); 356 opt = strtok(NULL, "\0");
358 357
359 if (opt == NULL) { 358 if (opt == NULL) {
367 srv_send((char *)"."); 366 srv_send((char *)".");
368 return 0; 367 return 0;
369 368
370 } else if (strcmp(opt, (char *)"BUS") == 0) { 369 } else if (strcmp(opt, (char *)"BUS") == 0) {
371 /* 370 /*
372 * 1-wire bus 371 * Bus devices
373 */ 372 */
374 if ((fd = opendir((char *)"/sys/bus/w1/devices"))) { 373 srv_send((char *)"212 bus devices:");
375 srv_send((char *)"212 1-wire bus devices:"); 374 for (device = Config.devices; device; device = device->next) {
376 while ((de = readdir(fd))) { 375 srv_send((char *)"%s,%s,%d,%d,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment);
377 if (de->d_name[0] != '.') { 376 }
378 ref = 0; 377 srv_send((char *)".");
379 if (strncmp(de->d_name, (char *)"w1", 2) == 0) { 378 return 0;
380 srv_send((char *)"%s,0,NA,System device", de->d_name);
381 } else if (strncmp(de->d_name, (char *)"10", 2) == 0) {
382 if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0))
383 ref++;
384 for (unit = Config.units; unit; unit = unit->next) {
385 if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0))
386 ref++;
387 if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0))
388 ref++;
389 }
390 srv_send((char *)"%s,%d,18S20,Digital thermometer", de->d_name, ref);
391 } else if (strncmp(de->d_name, (char *)"28", 2) == 0) {
392 if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0))
393 ref++;
394 for (unit = Config.units; unit; unit = unit->next) {
395 if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0))
396 ref++;
397 if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0))
398 ref++;
399 }
400 srv_send((char *)"%s,%d,18B20,Digital thermometer", de->d_name, ref);
401 } else if (strncmp(de->d_name, (char *)"29", 2) == 0) {
402 for (unit = Config.units; unit; unit = unit->next) {
403 if (unit->io1_address && (strncmp((char *)"29", unit->io1_address, 2) == 0))
404 ref++;
405 if (unit->io2_address && (strncmp((char *)"29", unit->io2_address, 2) == 0))
406 ref++;
407 }
408 srv_send((char *)"%s,%d,2408,8 Channel addressable switch/LCD", de->d_name, ref);
409 } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) {
410 for (unit = Config.units; unit; unit = unit->next) {
411 if (unit->io1_address && (strncmp((char *)"3a", unit->io1_address, 2) == 0))
412 ref++;
413 if (unit->io2_address && (strncmp((char *)"3a", unit->io2_address, 2) == 0))
414 ref++;
415 }
416 srv_send((char *)"%s,%d,2413,Dual channel addressable switch", de->d_name, ref);
417 } else {
418 srv_send((char *)"%s,0,NA,Unknown device", de->d_name);
419 }
420 }
421 }
422 srv_send((char *)".");
423 closedir(fd);
424 return 0;
425 } else {
426 srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno));
427 return 1;
428 }
429 379
430 } else if (strcmp(opt, (char *)"LOG") == 0) { 380 } else if (strcmp(opt, (char *)"LOG") == 0) {
431 /* 381 /*
432 * Get the logfile data and emit only one line per hour. 382 * Get the logfile data and emit only one line per hour.
433 */ 383 */

mercurial