diff -r 8b56f1b4e7ec -r 4091d4fe217f thermferm/devices.c --- a/thermferm/devices.c Wed Jul 25 14:18:39 2018 +0200 +++ b/thermferm/devices.c Wed Jul 25 20:08:13 2018 +0200 @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (C) 2014..2017 + * Copyright (C) 2014..2018 * * Michiel Broek * @@ -35,6 +35,8 @@ extern int SIMcooling; extern int SIMheating; +extern int SIMfan; +extern int SIMlight; #endif @@ -359,7 +361,8 @@ #ifdef USE_SIMULATOR if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { - if ((strcmp((char *)"SimCooler", device->address) == 0) || (strcmp((char *)"SimHeater", device->address) == 0)) { + if ((strcmp((char *)"SimCooler", device->address) == 0) || (strcmp((char *)"SimHeater", device->address) == 0) || + (strcmp((char *)"SimFan" , device->address) == 0) || (strcmp((char *)"SimLight" , device->address) == 0)) { if (value != device->value) { syslog(LOG_NOTICE, "SIM %s value=%d", device->address, value); if (debug) @@ -371,6 +374,10 @@ SIMcooling = value; if (strcmp((char *)"SimHeater", device->address) == 0) SIMheating = value; + if (strcmp((char *)"SimFan", device->address) == 0) + SIMfan = value; + if (strcmp((char *)"SimLight", device->address) == 0) + SIMlight = value; } } #endif @@ -621,66 +628,82 @@ #endif #ifdef USE_SIMULATOR - found = FALSE; + found = 0; for (device = Config.devices; device; device = device->next) { if (device->type == DEVTYPE_SIM) { - found = TRUE; - break; + found++; } } - if (found == FALSE) { - subdevices = 5; - for (i = 0; i < subdevices; i++) { - ndev = (devices_list *)malloc(sizeof(devices_list)); - ndev->next = NULL; - ndev->version = 1; - ndev->uuid = malloc(37); - uuid_generate(uu); - uuid_unparse(uu, ndev->uuid); - ndev->type = DEVTYPE_SIM; - ndev->value = ndev->offset = 0; - ndev->present = DEVPRESENT_YES; - ndev->subdevice = i; - ndev->gpiopin = -1; - ndev->comment = xstrcpy((char *)"Auto detected device"); - ndev->timestamp = time(NULL); - ndev->inuse = 0; - switch (i) { - case 0: ndev->direction = DEVDIR_IN_ANALOG; + /* + * Create simulated devices, or upgrade with new devices. + */ + subdevices = 9; + for (i = found; i < subdevices; i++) { + ndev = (devices_list *)malloc(sizeof(devices_list)); + ndev->next = NULL; + ndev->version = 1; + ndev->uuid = malloc(37); + uuid_generate(uu); + uuid_unparse(uu, ndev->uuid); + ndev->type = DEVTYPE_SIM; + ndev->value = ndev->offset = 0; + ndev->present = DEVPRESENT_YES; + ndev->subdevice = i; + ndev->gpiopin = -1; + ndev->comment = xstrcpy((char *)"Auto detected device"); + ndev->timestamp = time(NULL); + ndev->inuse = 0; + switch (i) { + case 0: ndev->direction = DEVDIR_IN_ANALOG; ndev->address = xstrcpy((char *)"SimRoomTemp"); ndev->description = xstrcpy((char *)"Simulated room temperature"); break; - case 1: ndev->direction = DEVDIR_IN_ANALOG; + case 1: ndev->direction = DEVDIR_IN_ANALOG; ndev->address = xstrcpy((char *)"SimAirTemp"); ndev->description = xstrcpy((char *)"Simulated air temperature"); break; - case 2: ndev->direction = DEVDIR_IN_ANALOG; + case 2: ndev->direction = DEVDIR_IN_ANALOG; ndev->address = xstrcpy((char *)"SimBeerTemp"); ndev->description = xstrcpy((char *)"Simulated beer temperature"); break; - case 3: ndev->direction = DEVDIR_OUT_BIN; + case 3: ndev->direction = DEVDIR_OUT_BIN; ndev->address = xstrcpy((char *)"SimHeater"); ndev->description = xstrcpy((char *)"Simulated heater"); break; - case 4: ndev->direction = DEVDIR_OUT_BIN; + case 4: ndev->direction = DEVDIR_OUT_BIN; ndev->address = xstrcpy((char *)"SimCooler"); ndev->description = xstrcpy((char *)"Simulated cooler"); break; - } + case 5: ndev->direction = DEVDIR_IN_ANALOG; + ndev->address = xstrcpy((char *)"SimRoomHum"); + ndev->description = xstrcpy((char *)"Simulated room humidity"); + break; + case 6: ndev->direction = DEVDIR_IN_ANALOG; + ndev->address = xstrcpy((char *)"SimChillerTemp"); + ndev->description = xstrcpy((char *)"Simulated Chiller temperature"); + break; + case 7: ndev->direction = DEVDIR_OUT_BIN; + ndev->address = xstrcpy((char *)"SimFan"); + ndev->description = xstrcpy((char *)"Simulated fan"); + break; + case 8: ndev->direction = DEVDIR_OUT_BIN; + ndev->address = xstrcpy((char *)"SimLight"); + ndev->description = xstrcpy((char *)"Simulated light"); + break; + } - if (Config.devices == NULL) { - Config.devices = ndev; - } else { - for (device = Config.devices; device; device = device->next) { - if (device->next == NULL) { - device->next = ndev; - break; - } + if (Config.devices == NULL) { + Config.devices = ndev; + } else { + for (device = Config.devices; device; device = device->next) { + if (device->next == NULL) { + device->next = ndev; + break; } } - rc++; } + rc++; } #endif @@ -744,16 +767,6 @@ fgets(line1, 50, fp); // Read 2 lines fgets(line2, 50, fp); fclose(fp); -// if (device->present != DEVPRESENT_YES) { -// syslog(LOG_NOTICE, "sensor %s is back", device->address); -//#ifdef HAVE_WIRINGPI_H -// piLock(LOCK_DEVICES); -//#endif -// device->present = DEVPRESENT_YES; -//#ifdef HAVE_WIRINGPI_H -// piUnlock(LOCK_DEVICES); -//#endif -// } /* * The output looks like: * 72 01 4b 46 7f ff 0e 10 57 : crc=57 YES @@ -949,6 +962,12 @@ } else if (device->subdevice == 2) { device->value = (int)((int)(simulator->beer_temperature * 1000) / 62.5) * 62.5; device->timestamp = time(NULL); + } else if (device->subdevice == 5) { + device->value = (int)((int)(simulator->room_humidity * 1000) / 500) * 500; + device->timestamp = time(NULL); + } else if (device->subdevice == 6) { + device->value = (int)((int)(simulator->chiller_temperature * 1000) / 62.5) * 62.5; + device->timestamp = time(NULL); } } #ifdef HAVE_WIRINGPI_H