465 val = strtok(NULL, "\0"); |
450 val = strtok(NULL, "\0"); |
466 if (kwd && val) { |
451 if (kwd && val) { |
467 if (strcmp(kwd, (char *)"TYPE") == 0) { |
452 if (strcmp(kwd, (char *)"TYPE") == 0) { |
468 for (i = 0; i < 8; i++) { |
453 for (i = 0; i < 8; i++) { |
469 if (strcmp(val, DEVTYPE[i]) == 0) { |
454 if (strcmp(val, DEVTYPE[i]) == 0) { |
470 #ifdef HAVE_WIRINGPI_H |
455 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
471 piLock(LOCK_DEVICES); |
|
472 #endif |
|
473 if (device->type != i) |
456 if (device->type != i) |
474 syslog(LOG_NOTICE, "Device %s changed type %s to %s", device->uuid, DEVTYPE[device->type], DEVTYPE[i]); |
457 syslog(LOG_NOTICE, "Device %s changed type %s to %s", device->uuid, DEVTYPE[device->type], DEVTYPE[i]); |
475 device->type = i; |
458 device->type = i; |
476 #ifdef HAVE_WIRINGPI_H |
459 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
477 piUnlock(LOCK_DEVICES); |
|
478 #endif |
|
479 break; |
460 break; |
480 } |
461 } |
481 } |
462 } |
482 |
463 |
483 } else if (strcmp(kwd, (char *)"DIRECTION") == 0) { |
464 } else if (strcmp(kwd, (char *)"DIRECTION") == 0) { |
484 for (i = 0; i < 7; i++) { |
465 for (i = 0; i < 7; i++) { |
485 if (strcmp(val, DEVDIR[i]) == 0) { |
466 if (strcmp(val, DEVDIR[i]) == 0) { |
486 #ifdef HAVE_WIRINGPI_H |
467 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
487 piLock(LOCK_DEVICES); |
|
488 #endif |
|
489 if (device->direction != i) |
468 if (device->direction != i) |
490 syslog(LOG_NOTICE, "Device %s changed direction %s to %s", device->uuid, DEVDIR[device->type], DEVDIR[i]); |
469 syslog(LOG_NOTICE, "Device %s changed direction %s to %s", device->uuid, DEVDIR[device->type], DEVDIR[i]); |
491 device->direction = i; |
470 device->direction = i; |
492 #ifdef HAVE_WIRINGPI_H |
471 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
493 piUnlock(LOCK_DEVICES); |
|
494 #endif |
|
495 break; |
472 break; |
496 } |
473 } |
497 } |
474 } |
498 |
475 |
499 } else if (strcmp(kwd, (char *)"VALUE") == 0) { |
476 } else if (strcmp(kwd, (char *)"VALUE") == 0) { |
500 if (sscanf(val, "%d", &ival) == 1) { |
477 if (sscanf(val, "%d", &ival) == 1) { |
501 #ifdef HAVE_WIRINGPI_H |
478 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
502 piLock(LOCK_DEVICES); |
|
503 #endif |
|
504 if (device->value != ival) |
479 if (device->value != ival) |
505 syslog(LOG_NOTICE, "Device %s changed value %d to %d", device->uuid, device->value, ival); |
480 syslog(LOG_NOTICE, "Device %s changed value %d to %d", device->uuid, device->value, ival); |
506 device->value = ival; |
481 device->value = ival; |
507 #ifdef HAVE_WIRINGPI_H |
482 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
508 piUnlock(LOCK_DEVICES); |
|
509 #endif |
|
510 } |
483 } |
511 |
484 |
512 } else if (strcmp(kwd, (char *)"OFFSET") == 0) { |
485 } else if (strcmp(kwd, (char *)"OFFSET") == 0) { |
513 if (sscanf(val, "%d", &ival) == 1) { |
486 if (sscanf(val, "%d", &ival) == 1) { |
514 #ifdef HAVE_WIRINGPI_H |
487 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
515 piLock(LOCK_DEVICES); |
|
516 #endif |
|
517 if (device->offset != ival) |
488 if (device->offset != ival) |
518 syslog(LOG_NOTICE, "Device %s changed offset %d to %d", device->uuid, device->offset, ival); |
489 syslog(LOG_NOTICE, "Device %s changed offset %d to %d", device->uuid, device->offset, ival); |
519 device->offset = ival; |
490 device->offset = ival; |
520 #ifdef HAVE_WIRINGPI_H |
491 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
521 piUnlock(LOCK_DEVICES); |
|
522 #endif |
|
523 } |
492 } |
524 |
493 |
525 } else if (strcmp(kwd, (char *)"PRESENT") == 0) { |
494 } else if (strcmp(kwd, (char *)"PRESENT") == 0) { |
526 for (i = 0; i < 4; i++) { |
495 for (i = 0; i < 4; i++) { |
527 if (strcmp(val, DEVPRESENT[i]) == 0) { |
496 if (strcmp(val, DEVPRESENT[i]) == 0) { |
528 #ifdef HAVE_WIRINGPI_H |
497 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
529 piLock(LOCK_DEVICES); |
|
530 #endif |
|
531 if (device->present != i) |
498 if (device->present != i) |
532 syslog(LOG_NOTICE, "Device %s changed present %s to %s", device->uuid, DEVPRESENT[device->present], DEVPRESENT[i]); |
499 syslog(LOG_NOTICE, "Device %s changed present %s to %s", device->uuid, DEVPRESENT[device->present], DEVPRESENT[i]); |
533 device->present = i; |
500 device->present = i; |
534 #ifdef HAVE_WIRINGPI_H |
501 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
535 piUnlock(LOCK_DEVICES); |
|
536 #endif |
|
537 break; |
502 break; |
538 } |
503 } |
539 } |
504 } |
540 |
505 |
541 } else if (strcmp(kwd, (char *)"ADDRESS") == 0) { |
506 } else if (strcmp(kwd, (char *)"ADDRESS") == 0) { |
542 #ifdef HAVE_WIRINGPI_H |
507 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
543 piLock(LOCK_DEVICES); |
|
544 #endif |
|
545 if (device->address) { |
508 if (device->address) { |
546 if (strcmp(device->address, val)) |
509 if (strcmp(device->address, val)) |
547 syslog(LOG_NOTICE, "Device %s changed address `%s' to `%s'", device->uuid, device->address, val); |
510 syslog(LOG_NOTICE, "Device %s changed address `%s' to `%s'", device->uuid, device->address, val); |
548 free(device->address); |
511 free(device->address); |
549 } |
512 } |
550 device->address = xstrcpy(val); |
513 device->address = xstrcpy(val); |
551 #ifdef HAVE_WIRINGPI_H |
514 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
552 piUnlock(LOCK_DEVICES); |
|
553 #endif |
|
554 |
515 |
555 } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) { |
516 } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) { |
556 if (sscanf(val, "%d", &ival) == 1) { |
517 if (sscanf(val, "%d", &ival) == 1) { |
557 #ifdef HAVE_WIRINGPI_H |
518 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
558 piLock(LOCK_DEVICES); |
|
559 #endif |
|
560 if (device->subdevice != ival) |
519 if (device->subdevice != ival) |
561 syslog(LOG_NOTICE, "Device %s changed subdevice %d to %d", device->uuid, device->subdevice, ival); |
520 syslog(LOG_NOTICE, "Device %s changed subdevice %d to %d", device->uuid, device->subdevice, ival); |
562 device->subdevice = ival; |
521 device->subdevice = ival; |
563 #ifdef HAVE_WIRINGPI_H |
522 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
564 piUnlock(LOCK_DEVICES); |
|
565 #endif |
|
566 } |
523 } |
567 |
524 |
568 } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) { |
525 } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) { |
569 if (sscanf(val, "%d", &ival) == 1) { |
526 if (sscanf(val, "%d", &ival) == 1) { |
570 #ifdef HAVE_WIRINGPI_H |
527 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
571 piLock(LOCK_DEVICES); |
|
572 #endif |
|
573 if (device->gpiopin != ival) |
528 if (device->gpiopin != ival) |
574 syslog(LOG_NOTICE, "Device %s changed gpiopin %d to %d", device->uuid, device->gpiopin, ival); |
529 syslog(LOG_NOTICE, "Device %s changed gpiopin %d to %d", device->uuid, device->gpiopin, ival); |
575 device->gpiopin = ival; |
530 device->gpiopin = ival; |
576 #ifdef HAVE_WIRINGPI_H |
531 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
577 piUnlock(LOCK_DEVICES); |
|
578 #endif |
|
579 } |
532 } |
580 |
533 |
581 } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) { |
534 } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) { |
582 #ifdef HAVE_WIRINGPI_H |
535 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
583 piLock(LOCK_DEVICES); |
|
584 #endif |
|
585 if (device->description) { |
536 if (device->description) { |
586 if (strcmp(device->description, val)) |
537 if (strcmp(device->description, val)) |
587 syslog(LOG_NOTICE, "Device %s changed description `%s' to `%s'", device->uuid, device->description, val); |
538 syslog(LOG_NOTICE, "Device %s changed description `%s' to `%s'", device->uuid, device->description, val); |
588 free(device->description); |
539 free(device->description); |
589 } |
540 } |
590 device->description = xstrcpy(val); |
541 device->description = xstrcpy(val); |
591 #ifdef HAVE_WIRINGPI_H |
542 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
592 piUnlock(LOCK_DEVICES); |
|
593 #endif |
|
594 |
543 |
595 } else if (strcmp(kwd, (char *)"COMMENT") == 0) { |
544 } else if (strcmp(kwd, (char *)"COMMENT") == 0) { |
596 #ifdef HAVE_WIRINGPI_H |
545 pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
597 piLock(LOCK_DEVICES); |
|
598 #endif |
|
599 if (device->comment) { |
546 if (device->comment) { |
600 if (strcmp(device->comment, val)) |
547 if (strcmp(device->comment, val)) |
601 syslog(LOG_NOTICE, "Device %s changed comment `%s' to `%s'", device->uuid, device->comment, val); |
548 syslog(LOG_NOTICE, "Device %s changed comment `%s' to `%s'", device->uuid, device->comment, val); |
602 free(device->comment); |
549 free(device->comment); |
603 } |
550 } |
604 device->comment = xstrcpy(val); |
551 device->comment = xstrcpy(val); |
605 #ifdef HAVE_WIRINGPI_H |
552 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
606 piUnlock(LOCK_DEVICES); |
|
607 #endif |
|
608 |
553 |
609 } |
554 } |
610 } |
555 } |
611 } |
556 } |
612 } |
557 } |