391 } |
396 } |
392 } |
397 } |
393 } |
398 } |
394 #endif |
399 #endif |
395 |
400 |
|
401 #ifdef USE_SIMULATOR |
|
402 found = FALSE; |
|
403 for (device = Config.devices; device; device = device->next) { |
|
404 if (device->type == DEVTYPE_SIM) { |
|
405 found = TRUE; |
|
406 break; |
|
407 } |
|
408 } |
|
409 |
|
410 if (found == FALSE) { |
|
411 subdevices = 5; |
|
412 for (i = 0; i < subdevices; i++) { |
|
413 ndev = (devices_list *)malloc(sizeof(devices_list)); |
|
414 ndev->next = NULL; |
|
415 ndev->version = 1; |
|
416 ndev->uuid = malloc(37); |
|
417 uuid_generate(uu); |
|
418 uuid_unparse(uu, ndev->uuid); |
|
419 ndev->type = DEVTYPE_SIM; |
|
420 ndev->value = ndev->offset = 0; |
|
421 ndev->present = DEVPRESENT_YES; |
|
422 ndev->subdevice = i; |
|
423 ndev->gpiopin = -1; |
|
424 ndev->comment = xstrcpy((char *)"Auto detected device"); |
|
425 ndev->timestamp = time(NULL); |
|
426 ndev->inuse = 0; |
|
427 switch (i) { |
|
428 case 0: ndev->direction = DEVDIR_IN_ANALOG; |
|
429 ndev->address = xstrcpy((char *)"SimRoomTemp"); |
|
430 ndev->description = xstrcpy((char *)"Simulated room temperature"); |
|
431 break; |
|
432 case 1: ndev->direction = DEVDIR_IN_ANALOG; |
|
433 ndev->address = xstrcpy((char *)"SimAirTemp"); |
|
434 ndev->description = xstrcpy((char *)"Simulated air temperature"); |
|
435 break; |
|
436 case 2: ndev->direction = DEVDIR_IN_ANALOG; |
|
437 ndev->address = xstrcpy((char *)"SimBeerTemp"); |
|
438 ndev->description = xstrcpy((char *)"Simulated beer temperature"); |
|
439 break; |
|
440 case 3: ndev->direction = DEVDIR_OUT_ANALOG; |
|
441 ndev->address = xstrcpy((char *)"SimHeater"); |
|
442 ndev->description = xstrcpy((char *)"Simulated heater"); |
|
443 break; |
|
444 case 4: ndev->direction = DEVDIR_OUT_ANALOG; |
|
445 ndev->address = xstrcpy((char *)"SimCooler"); |
|
446 ndev->description = xstrcpy((char *)"Simulated cooler"); |
|
447 break; |
|
448 } |
|
449 |
|
450 if (Config.devices == NULL) { |
|
451 Config.devices = ndev; |
|
452 } else { |
|
453 for (device = Config.devices; device; device = device->next) { |
|
454 if (device->next == NULL) { |
|
455 device->next = ndev; |
|
456 break; |
|
457 } |
|
458 } |
|
459 } |
|
460 rc++; |
|
461 } |
|
462 } |
|
463 #endif |
|
464 |
396 return rc; |
465 return rc; |
397 } |
466 } |
398 |
467 |
399 |
468 |
400 |
469 |
534 } |
603 } |
535 piUnlock(LOCK_DEVICES); |
604 piUnlock(LOCK_DEVICES); |
536 } |
605 } |
537 break; |
606 break; |
538 #endif |
607 #endif |
539 |
608 #ifdef USE_SIMULATOR |
|
609 case DEVTYPE_SIM: |
|
610 #ifdef HAVE_WIRINGPI_H |
|
611 piLock(LOCK_DEVICES); |
|
612 #endif |
|
613 if (device->subdevice == 0) { |
|
614 device->value = 20000; |
|
615 device->timestamp = time(NULL); |
|
616 } else if (device->subdevice == 1) { |
|
617 device->value = 20125; |
|
618 device->timestamp = time(NULL); |
|
619 } else if (device->subdevice == 2) { |
|
620 device->value = 20250; |
|
621 device->timestamp = time(NULL); |
|
622 } |
|
623 #ifdef HAVE_WIRINGPI_H |
|
624 piUnlock(LOCK_DEVICES); |
|
625 #endif |
|
626 break; |
|
627 #endif |
540 default: |
628 default: |
541 break; |
629 break; |
542 } |
630 } |
543 |
631 |
544 /* |
632 /* |