1376 free(current->cooler_address); |
1376 free(current->cooler_address); |
1377 current->cooler_address = NULL; |
1377 current->cooler_address = NULL; |
1378 if (current->fan_address) |
1378 if (current->fan_address) |
1379 free(current->fan_address); |
1379 free(current->fan_address); |
1380 current->fan_address = NULL; |
1380 current->fan_address = NULL; |
|
1381 if (current->light_address) |
|
1382 free(current->light_address); |
|
1383 current->light_address = NULL; |
1381 if (current->door_address) |
1384 if (current->door_address) |
1382 free(current->door_address); |
1385 free(current->door_address); |
1383 current->door_address = NULL; |
1386 current->door_address = NULL; |
|
1387 if (current->psu_address) |
|
1388 free(current->psu_address); |
|
1389 current->psu_address = NULL; |
1384 if (current->profile) |
1390 if (current->profile) |
1385 free(current->profile); |
1391 free(current->profile); |
1386 current->profile = NULL; |
1392 current->profile = NULL; |
1387 free(current); |
1393 free(current); |
1388 return 1; |
1394 return 1; |
1407 free(current->fan_address); |
1413 free(current->fan_address); |
1408 current->fan_address = NULL; |
1414 current->fan_address = NULL; |
1409 if (current->door_address) |
1415 if (current->door_address) |
1410 free(current->door_address); |
1416 free(current->door_address); |
1411 current->door_address = NULL; |
1417 current->door_address = NULL; |
|
1418 if (current->light_address) |
|
1419 free(current->light_address); |
|
1420 current->light_address = NULL; |
|
1421 if (current->psu_address) |
|
1422 free(current->psu_address); |
|
1423 current->psu_address = NULL; |
1412 if (current->profile) |
1424 if (current->profile) |
1413 free(current->profile); |
1425 free(current->profile); |
1414 current->profile = NULL; |
1426 current->profile = NULL; |
1415 previous->next = current->next; |
1427 previous->next = current->next; |
1416 free(current); |
1428 free(current); |
1473 unit->uuid = malloc(37); |
1485 unit->uuid = malloc(37); |
1474 uuid_generate(uu); |
1486 uuid_generate(uu); |
1475 uuid_unparse(uu, unit->uuid); |
1487 uuid_unparse(uu, unit->uuid); |
1476 unit->name = xstrcpy(param); |
1488 unit->name = xstrcpy(param); |
1477 unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \ |
1489 unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \ |
1478 unit->fan_address = unit->door_address = unit->profile = NULL; |
1490 unit->fan_address = unit->door_address = unit->light_address = \ |
|
1491 unit->psu_address = unit->profile = NULL; |
1479 unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
1492 unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0; |
1480 unit->air_state = unit->beer_state = 1; |
1493 unit->air_state = unit->beer_state = 1; |
1481 unit->air_temperature = unit->beer_temperature = 20000; |
1494 unit->air_temperature = unit->beer_temperature = 20000; |
1482 unit->beer_set = unit->fridge_set = 20.0; |
1495 unit->beer_set = unit->fridge_set = 20.0; |
1483 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; |
1496 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = \ |
1484 unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ |
1497 unit->light_state = unit->psu_state = unit->prof_state = 0; |
1485 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; |
1498 unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ |
1486 unit->heater_usage = unit->cooler_usage = unit->fan_usage = 0; |
1499 unit->light_delay = 1; /* 15 seconds delay */ |
|
1500 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
|
1501 unit->heater_usage = unit->cooler_usage = unit->fan_usage = unit->light_usage = 0; |
1487 unit->temp_set_min = 1.0; |
1502 unit->temp_set_min = 1.0; |
1488 unit->temp_set_max = 30.0; |
1503 unit->temp_set_max = 30.0; |
1489 unit->idle_rangeH = 1.0; |
1504 unit->idle_rangeH = 1.0; |
1490 unit->idle_rangeL = -1.0; |
1505 unit->idle_rangeL = -1.0; |
1491 unit->prof_started = unit->prof_paused = unit->prof_primary_done = (time_t)0; |
1506 unit->prof_started = unit->prof_paused = unit->prof_primary_done = (time_t)0; |
1572 srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage); |
1587 srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage); |
1573 srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address); |
1588 srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address); |
1574 srv_send((char *)"FAN_STATE,%d", unit->fan_state); |
1589 srv_send((char *)"FAN_STATE,%d", unit->fan_state); |
1575 srv_send((char *)"FAN_DELAY,%d", unit->fan_delay); |
1590 srv_send((char *)"FAN_DELAY,%d", unit->fan_delay); |
1576 srv_send((char *)"FAN_USAGE,%d", unit->fan_usage); |
1591 srv_send((char *)"FAN_USAGE,%d", unit->fan_usage); |
|
1592 srv_send((char *)"LIGHT_ADDRESS,%s", unit->light_address); |
|
1593 srv_send((char *)"LIGHT_STATE,%d", unit->light_state); |
|
1594 srv_send((char *)"LIGHT_DELAY,%d", unit->light_delay); |
|
1595 srv_send((char *)"LIGHT_USAGE,%d", unit->light_usage); |
1577 srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address); |
1596 srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address); |
1578 srv_send((char *)"DOOR_STATE,%d", unit->door_state); |
1597 srv_send((char *)"DOOR_STATE,%d", unit->door_state); |
|
1598 srv_send((char *)"PSU_ADDRESS,%s", unit->psu_address); |
|
1599 srv_send((char *)"PSU_STATE,%d", unit->psu_state); |
1579 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); |
1600 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); |
1580 srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set); |
1601 srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set); |
1581 srv_send((char *)"BEER_SET,%.1f", unit->beer_set); |
1602 srv_send((char *)"BEER_SET,%.1f", unit->beer_set); |
1582 srv_send((char *)"PROFILE,%s", unit->profile); |
1603 srv_send((char *)"PROFILE,%s", unit->profile); |
1583 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started); |
1604 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started); |
1763 if (unit->fan_delay != ival) |
1784 if (unit->fan_delay != ival) |
1764 syslog(LOG_NOTICE, "Fermenter unit %s fan delay %d to %d", unit->uuid, unit->fan_delay, ival); |
1785 syslog(LOG_NOTICE, "Fermenter unit %s fan delay %d to %d", unit->uuid, unit->fan_delay, ival); |
1765 unit->fan_delay = ival; |
1786 unit->fan_delay = ival; |
1766 } |
1787 } |
1767 |
1788 |
|
1789 } else if (strcmp(kwd, (char *)"LIGHT_ADDRESS") == 0) { |
|
1790 if (val && unit->light_address && (strcmp(val, unit->light_address))) |
|
1791 syslog(LOG_NOTICE, "Fermenter unit %s light address `%s' to `%s'", unit->uuid, unit->light_address, val); |
|
1792 if (unit->light_address) { |
|
1793 device_count(FALSE, unit->light_address); |
|
1794 free(unit->light_address); |
|
1795 } |
|
1796 if (val) { |
|
1797 unit->light_address = xstrcpy(val); |
|
1798 device_count(TRUE, unit->light_address); |
|
1799 } else |
|
1800 unit->light_address = NULL; |
|
1801 |
|
1802 } else if (val && (strcmp(kwd, (char *)"LIGHT_STATE") == 0)) { |
|
1803 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) { |
|
1804 if (unit->light_state != ival) |
|
1805 syslog(LOG_NOTICE, "Fermenter unit %s light state %d to %d", unit->uuid, unit->light_state, ival); |
|
1806 unit->light_state = ival; |
|
1807 } |
|
1808 |
|
1809 } else if (val && (strcmp(kwd, (char *)"LIGHT_DELAY") == 0)) { |
|
1810 if (sscanf(val, "%d", &ival) == 1) { |
|
1811 if (unit->light_delay != ival) |
|
1812 syslog(LOG_NOTICE, "Fermenter unit %s light delay %d to %d", unit->uuid, unit->light_delay, ival); |
|
1813 unit->light_delay = ival; |
|
1814 } |
|
1815 |
1768 } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { |
1816 } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { |
1769 if (val && unit->door_address && (strcmp(val, unit->door_address))) |
1817 if (val && unit->door_address && (strcmp(val, unit->door_address))) |
1770 syslog(LOG_NOTICE, "Fermenter unit %s door address `%s' to `%s'", unit->uuid, unit->door_address, val); |
1818 syslog(LOG_NOTICE, "Fermenter unit %s door address `%s' to `%s'", unit->uuid, unit->door_address, val); |
1771 if (unit->door_address) { |
1819 if (unit->door_address) { |
1772 device_count(FALSE, unit->door_address); |
1820 device_count(FALSE, unit->door_address); |
1775 if (val) { |
1823 if (val) { |
1776 unit->door_address = xstrcpy(val); |
1824 unit->door_address = xstrcpy(val); |
1777 device_count(TRUE, unit->door_address); |
1825 device_count(TRUE, unit->door_address); |
1778 } else |
1826 } else |
1779 unit->door_address = NULL; |
1827 unit->door_address = NULL; |
|
1828 |
|
1829 } else if (strcmp(kwd, (char *)"PSU_ADDRESS") == 0) { |
|
1830 if (val && unit->psu_address && (strcmp(val, unit->psu_address))) |
|
1831 syslog(LOG_NOTICE, "Fermenter unit %s psu address `%s' to `%s'", unit->uuid, unit->psu_address, val); |
|
1832 if (unit->psu_address) { |
|
1833 device_count(FALSE, unit->psu_address); |
|
1834 free(unit->psu_address); |
|
1835 } |
|
1836 if (val) { |
|
1837 unit->psu_address = xstrcpy(val); |
|
1838 device_count(TRUE, unit->psu_address); |
|
1839 } else |
|
1840 unit->psu_address = NULL; |
1780 |
1841 |
1781 } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) { |
1842 } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) { |
1782 for (i = 0; i < 5; i++) { |
1843 for (i = 0; i < 5; i++) { |
1783 if (strcmp(val, UNITMODE[i]) == 0) { |
1844 if (strcmp(val, UNITMODE[i]) == 0) { |
1784 /* Initialize log if the unit is turned on */ |
1845 /* Initialize log if the unit is turned on */ |
1786 initlog(unit->name); |
1847 initlog(unit->name); |
1787 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); |
1848 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]); |
1788 unit->mode = i; |
1849 unit->mode = i; |
1789 /* Allways turn everything off after a mode change */ |
1850 /* Allways turn everything off after a mode change */ |
1790 unit->PID_I_err = unit->PID_err_old = 0.0; |
1851 unit->PID_I_err = unit->PID_err_old = 0.0; |
1791 unit->heater_state = unit->cooler_state = unit->fan_state = 0; |
1852 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; |
1792 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; |
1853 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
1793 device_out(unit->heater_address, unit->heater_state); |
1854 device_out(unit->heater_address, unit->heater_state); |
1794 device_out(unit->cooler_address, unit->cooler_state); |
1855 device_out(unit->cooler_address, unit->cooler_state); |
1795 device_out(unit->fan_address, unit->fan_state); |
1856 device_out(unit->fan_address, unit->fan_state); |
|
1857 device_out(unit->light_address, unit->light_state); |
1796 if (unit->mode == UNITMODE_PROFILE) { |
1858 if (unit->mode == UNITMODE_PROFILE) { |
1797 /* |
1859 /* |
1798 * Set a sane default until it will be overruled by the |
1860 * Set a sane default until it will be overruled by the |
1799 * main processing loop. |
1861 * main processing loop. |
1800 */ |
1862 */ |
1834 unit->profile = NULL; |
1896 unit->profile = NULL; |
1835 /* |
1897 /* |
1836 * Reset all output devices |
1898 * Reset all output devices |
1837 */ |
1899 */ |
1838 unit->PID_I_err = unit->PID_err_old = 0.0; |
1900 unit->PID_I_err = unit->PID_err_old = 0.0; |
1839 unit->heater_state = unit->cooler_state = unit->fan_state = 0; |
1901 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0; |
1840 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; |
1902 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; |
1841 device_out(unit->heater_address, unit->heater_state); |
1903 device_out(unit->heater_address, unit->heater_state); |
1842 device_out(unit->cooler_address, unit->cooler_state); |
1904 device_out(unit->cooler_address, unit->cooler_state); |
1843 device_out(unit->fan_address, unit->fan_state); |
1905 device_out(unit->fan_address, unit->fan_state); |
|
1906 device_out(unit->light_address, unit->light_state); |
1844 } |
1907 } |
1845 |
1908 |
1846 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { |
1909 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) { |
1847 for (i = 0; i < 5; i++) { |
1910 for (i = 0; i < 5; i++) { |
1848 if (strcmp(val, PROFSTATE[i]) == 0) { |
1911 if (strcmp(val, PROFSTATE[i]) == 0) { |