312 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
315 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
313 } |
316 } |
314 } |
317 } |
315 |
318 |
316 #ifdef USE_SIMULATOR |
319 #ifdef USE_SIMULATOR |
317 if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { |
320 if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN)) { |
318 if ((strcmp((char *)"SimCooler", device->address) == 0) || (strcmp((char *)"SimHeater", device->address) == 0) || |
321 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
319 (strcmp((char *)"SimFan" , device->address) == 0) || (strcmp((char *)"SimLight" , device->address) == 0)) { |
322 if ((strcmp(device->address, simulator->cooler_address) == 0) || |
320 if (value != device->value) { |
323 (strcmp(device->address, simulator->heater_address) == 0) || |
321 syslog(LOG_NOTICE, "SIM %s value=%d", device->address, value); |
324 (strcmp(device->address, simulator->fan_address) == 0) || |
322 device->value = value; |
325 (strcmp(device->address, simulator->light_address) == 0)) { |
323 device->timestamp = time(NULL); |
326 if (value != device->value) { |
324 if (strcmp((char *)"SimCooler", device->address) == 0) |
327 int rc = DEVPRESENT_UNDEF; |
325 SIMcooling = value; |
328 device->value = value; |
326 if (strcmp((char *)"SimHeater", device->address) == 0) |
329 device->timestamp = time(NULL); |
327 SIMheating = value; |
330 if (strcmp(device->address, simulator->cooler_address) == 0) { |
328 if (strcmp((char *)"SimFan", device->address) == 0) |
331 simulator->cooler_power = value; |
329 SIMfan = value; |
332 rc = simulator->cooler_present; |
330 if (strcmp((char *)"SimLight", device->address) == 0) |
333 } else if (strcmp(device->address, simulator->heater_address) == 0) { |
331 SIMlight = value; |
334 simulator->heater_power = value; |
332 devices_ws(); |
335 rc = simulator->heater_present; |
|
336 } else if (strcmp(device->address, simulator->fan_address) == 0) { |
|
337 simulator->fan_power = value; |
|
338 rc = simulator->fan_present; |
|
339 } else if (strcmp(device->address, simulator->light_address) == 0) { |
|
340 simulator->light_power = value; |
|
341 rc = simulator->light_present; |
|
342 } |
|
343 syslog(LOG_NOTICE, "SIM %s value=%d, present=%s", device->address, value, DEVPRESENT[rc]); |
|
344 device->present = rc; |
|
345 devices_ws(); |
|
346 } |
333 } |
347 } |
334 } |
348 } |
335 } |
349 } |
336 #endif |
350 #endif |
337 } else { |
351 } else { |
684 } |
701 } |
685 } |
702 } |
686 #endif |
703 #endif |
687 |
704 |
688 #ifdef USE_SIMULATOR |
705 #ifdef USE_SIMULATOR |
689 found = 0; |
706 |
690 for (device = Config.devices; device; device = device->next) { |
707 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
691 if (device->type == DEVTYPE_SIM) { |
708 for (i = 0; i < 10; i++) { |
692 found++; |
709 |
693 } |
710 found = FALSE; |
694 } |
711 for (device = Config.devices; device; device = device->next) { |
695 |
712 if ((i == 0 && strcmp(device->address, simulator->room_tempaddress) == 0) || |
696 /* |
713 (i == 1 && strcmp(device->address, simulator->air_address) == 0) || |
697 * Create simulated devices, or upgrade with new devices. |
714 (i == 2 && strcmp(device->address, simulator->beer_address) == 0) || |
698 */ |
715 (i == 3 && strcmp(device->address, simulator->heater_address) == 0) || |
699 subdevices = 10; |
716 (i == 4 && strcmp(device->address, simulator->cooler_address) == 0) || |
700 for (i = found; i < subdevices; i++) { |
717 (i == 5 && strcmp(device->address, simulator->room_humaddress) == 0) || |
701 ndev = (devices_list *)malloc(sizeof(devices_list)); |
718 (i == 6 && strcmp(device->address, simulator->chiller_address) == 0) || |
702 ndev->next = NULL; |
719 (i == 7 && strcmp(device->address, simulator->fan_address) == 0) || |
703 ndev->uuid = malloc(37); |
720 (i == 8 && strcmp(device->address, simulator->light_address) == 0) || |
704 uuid_generate(uu); |
721 (i == 9 && strcmp(device->address, simulator->beer_address2) == 0)) { |
705 uuid_unparse(uu, ndev->uuid); |
722 found = TRUE; |
706 ndev->type = DEVTYPE_SIM; |
723 break; |
707 ndev->value = ndev->offset = 0; |
724 } |
708 ndev->present = DEVPRESENT_YES; |
725 } |
709 ndev->subdevice = i; |
726 |
710 ndev->gpiopin = -1; |
727 if (found == FALSE) { |
711 ndev->comment = xstrcpy((char *)"Auto detected device"); |
728 ndev = (devices_list *)malloc(sizeof(devices_list)); |
712 ndev->timestamp = time(NULL); |
729 ndev->next = NULL; |
713 ndev->inuse = 0; |
730 ndev->uuid = malloc(37); |
714 switch (i) { |
731 uuid_generate(uu); |
715 case 0: ndev->direction = DEVDIR_IN_ANALOG; |
732 uuid_unparse(uu, ndev->uuid); |
716 ndev->address = xstrcpy((char *)"SimRoomTemp"); |
733 ndev->type = DEVTYPE_SIM; |
717 ndev->description = xstrcpy((char *)"Simulated room temperature"); |
734 ndev->value = ndev->offset = 0; |
718 break; |
735 ndev->present = DEVPRESENT_NO; |
719 case 1: ndev->direction = DEVDIR_IN_ANALOG; |
736 ndev->gpiopin = -1; |
720 ndev->address = xstrcpy((char *)"SimAirTemp"); |
737 ndev->subdevice = i; |
721 ndev->description = xstrcpy((char *)"Simulated air temperature"); |
738 ndev->comment = xstrcpy((char *)"Auto detected device"); |
722 break; |
739 ndev->timestamp = time(NULL); |
723 case 2: ndev->direction = DEVDIR_IN_ANALOG; |
740 ndev->inuse = 0; |
724 ndev->address = xstrcpy((char *)"SimBeerTemp"); |
741 |
725 ndev->description = xstrcpy((char *)"Simulated beer temperature"); |
742 switch (i) { |
726 break; |
743 case 0: ndev->direction = DEVDIR_IN_ANALOG; |
727 case 3: ndev->direction = DEVDIR_OUT_BIN; |
744 ndev->address = xstrcpy(simulator->room_tempaddress); |
728 ndev->address = xstrcpy((char *)"SimHeater"); |
745 ndev->description = xstrcpy((char *)"Simulated room temperature"); |
729 ndev->description = xstrcpy((char *)"Simulated heater"); |
746 ndev->present = DEVPRESENT_YES; |
730 break; |
747 break; |
731 case 4: ndev->direction = DEVDIR_OUT_BIN; |
748 case 1: ndev->direction = DEVDIR_IN_ANALOG; |
732 ndev->address = xstrcpy((char *)"SimCooler"); |
749 ndev->address = xstrcpy(simulator->air_address); |
733 ndev->description = xstrcpy((char *)"Simulated cooler"); |
750 ndev->description = xstrcpy((char *)"Simulated air temperature"); |
734 break; |
751 ndev->present = simulator->air_present; |
735 case 5: ndev->direction = DEVDIR_IN_ANALOG; |
752 break; |
736 ndev->address = xstrcpy((char *)"SimRoomHum"); |
753 case 2: ndev->direction = DEVDIR_IN_ANALOG; |
737 ndev->description = xstrcpy((char *)"Simulated room humidity"); |
754 ndev->address = xstrcpy(simulator->beer_address); |
738 break; |
755 ndev->description = xstrcpy((char *)"Simulated beer temperature"); |
739 case 6: ndev->direction = DEVDIR_IN_ANALOG; |
756 ndev->present = simulator->beer_present; |
740 ndev->address = xstrcpy((char *)"SimChillerTemp"); |
757 break; |
741 ndev->description = xstrcpy((char *)"Simulated Chiller temperature"); |
758 case 3: ndev->direction = DEVDIR_OUT_BIN; |
742 break; |
759 ndev->address = xstrcpy(simulator->heater_address); |
743 case 7: ndev->direction = DEVDIR_OUT_BIN; |
760 ndev->description = xstrcpy((char *)"Simulated heater"); |
744 ndev->address = xstrcpy((char *)"SimFan"); |
761 ndev->present = simulator->heater_present; |
745 ndev->description = xstrcpy((char *)"Simulated fan"); |
762 break; |
746 break; |
763 case 4: ndev->direction = DEVDIR_OUT_BIN; |
747 case 8: ndev->direction = DEVDIR_OUT_BIN; |
764 ndev->address = xstrcpy(simulator->cooler_address); |
748 ndev->address = xstrcpy((char *)"SimLight"); |
765 ndev->description = xstrcpy((char *)"Simulated cooler"); |
749 ndev->description = xstrcpy((char *)"Simulated light"); |
766 ndev->present = simulator->cooler_present; |
750 break; |
767 break; |
751 case 9: ndev->direction = DEVDIR_IN_ANALOG; |
768 case 5: ndev->direction = DEVDIR_IN_ANALOG; |
752 ndev->address = xstrcpy((char *)"SimBeerTemp2"); |
769 ndev->address = xstrcpy(simulator->room_humaddress); |
753 ndev->description = xstrcpy((char *)"Simulated beer temperature (alt)"); |
770 ndev->description = xstrcpy((char *)"Simulated room humidity"); |
754 break; |
771 ndev->present = DEVPRESENT_YES; |
755 } |
772 break; |
756 |
773 case 6: ndev->direction = DEVDIR_IN_ANALOG; |
757 syslog(LOG_NOTICE, "New Simulator device %s, subdevice %d, %s", ndev->address, ndev->subdevice, ndev->description); |
774 ndev->address = xstrcpy(simulator->chiller_address); |
758 |
775 ndev->description = xstrcpy((char *)"Simulated Chiller temperature"); |
759 if (Config.devices == NULL) { |
776 ndev->present = simulator->chiller_present; |
760 Config.devices = ndev; |
777 break; |
761 } else { |
778 case 7: ndev->direction = DEVDIR_OUT_BIN; |
762 for (device = Config.devices; device; device = device->next) { |
779 ndev->address = xstrcpy(simulator->fan_address); |
763 if (device->next == NULL) { |
780 ndev->description = xstrcpy((char *)"Simulated fan"); |
764 device->next = ndev; |
781 ndev->present = simulator->fan_present; |
765 break; |
782 break; |
|
783 case 8: ndev->direction = DEVDIR_OUT_BIN; |
|
784 ndev->address = xstrcpy(simulator->light_address); |
|
785 ndev->description = xstrcpy((char *)"Simulated light"); |
|
786 ndev->present = simulator->light_present; |
|
787 break; |
|
788 case 9: ndev->direction = DEVDIR_IN_ANALOG; |
|
789 ndev->address = xstrcpy(simulator->beer_address2); |
|
790 ndev->description = xstrcpy((char *)"Simulated beer temperature (alt)"); |
|
791 ndev->present = simulator->beer_present2; |
|
792 break; |
766 } |
793 } |
767 } |
794 |
768 } |
795 syslog(LOG_NOTICE, "New Simulator device %s, subdevice %d", ndev->address, ndev->subdevice); |
769 rc++; |
796 |
|
797 if (Config.devices == NULL) { |
|
798 Config.devices = ndev; |
|
799 } else { |
|
800 for (device = Config.devices; device; device = device->next) { |
|
801 if (device->next == NULL) { |
|
802 device->next = ndev; |
|
803 break; |
|
804 } |
|
805 } |
|
806 } |
|
807 rc++; |
|
808 } |
|
809 } |
770 } |
810 } |
771 #endif |
811 #endif |
772 |
812 |
773 return rc; |
813 return rc; |
774 } |
814 } |