910 |
911 |
911 if (debug) { |
912 if (debug) { |
912 /* |
913 /* |
913 * For debugging run in foreground. |
914 * For debugging run in foreground. |
914 */ |
915 */ |
915 rc = server(); |
916 do { |
|
917 rc = server(); |
|
918 } while (my_reboot == TRUE); |
916 } else { |
919 } else { |
917 /* |
920 /* |
918 * Server initialization is complete. Now we can fork the |
921 * Server initialization is complete. Now we can fork the |
919 * daemon and return to the user. We need to do a setpgrp |
922 * daemon and return to the user. We need to do a setpgrp |
920 * so that the daemon will no longer be assosiated with the |
923 * so that the daemon will no longer be assosiated with the |
950 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { |
953 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) { |
951 syslog(LOG_NOTICE, "Reopen of stderr to /dev/null failed"); |
954 syslog(LOG_NOTICE, "Reopen of stderr to /dev/null failed"); |
952 _exit(2); |
955 _exit(2); |
953 } |
956 } |
954 mypid = getpid(); |
957 mypid = getpid(); |
955 rc = server(); |
958 do { |
|
959 rc = server(); |
|
960 } while (my_reboot == TRUE); |
956 break; |
961 break; |
957 /* Not reached */ |
962 /* Not reached */ |
958 default: |
963 default: |
959 /* |
964 /* |
960 * Here we detach this process and let the child |
965 * Here we detach this process and let the child |
989 float previous_target_lo, previous_target_hi; |
994 float previous_target_lo, previous_target_hi; |
990 float LCDair, LCDbeer, LCDspL, LCDspH; |
995 float LCDair, LCDbeer, LCDspL, LCDspH; |
991 unsigned char LCDstatC, LCDstatH; |
996 unsigned char LCDstatC, LCDstatH; |
992 int LCDunit; |
997 int LCDunit; |
993 |
998 |
|
999 syslog(LOG_NOTICE, "Server process started"); |
|
1000 my_shutdown = my_reboot = FALSE; |
994 if (lockprog((char *)"thermferm")) { |
1001 if (lockprog((char *)"thermferm")) { |
995 syslog(LOG_NOTICE, "Can't lock"); |
1002 syslog(LOG_NOTICE, "Can't lock"); |
996 return 1; |
1003 return 1; |
997 } |
1004 } |
998 #ifdef HAVE_MOSQUITTO_H |
1005 #ifdef HAVE_MOSQUITTO_H |
1670 * Prevent extreme heating |
1677 * Prevent extreme heating |
1671 */ |
1678 */ |
1672 if ((unit->mode == UNITMODE_BEER) && ((unit->air_temperature / 1000.0) > (unit->PID_heat->Input + 8.0))) { |
1679 if ((unit->mode == UNITMODE_BEER) && ((unit->air_temperature / 1000.0) > (unit->PID_heat->Input + 8.0))) { |
1673 unit->PID_heat->OutP = 0.0; |
1680 unit->PID_heat->OutP = 0.0; |
1674 } |
1681 } |
1675 if (debug) |
1682 // if (debug) |
1676 fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", |
1683 // fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", |
1677 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); |
1684 // unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); |
1678 if (seconds == 60) { |
1685 if (seconds == 60) { |
1679 syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", |
1686 syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", |
1680 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); |
1687 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); |
1681 } |
1688 } |
1682 } else { |
1689 } else { |
1699 if (seconds == 60) { |
1706 if (seconds == 60) { |
1700 syslog(LOG_NOTICE, "Cool: Air=%.2f Chiller=%.2f alarm", unit->air_temperature / 1000.0, unit->chiller_temperature / 1000.0); |
1707 syslog(LOG_NOTICE, "Cool: Air=%.2f Chiller=%.2f alarm", unit->air_temperature / 1000.0, unit->chiller_temperature / 1000.0); |
1701 } |
1708 } |
1702 } |
1709 } |
1703 } |
1710 } |
1704 if (debug) |
1711 // if (debug) |
1705 fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", |
1712 // fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", |
1706 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); |
1713 // unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); |
1707 if (seconds == 60) { |
1714 if (seconds == 60) { |
1708 syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", |
1715 syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", |
1709 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); |
1716 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); |
1710 } |
1717 } |
1711 } else { |
1718 } else { |
1795 device_out(unit->cooler_address, unit->cooler_state); |
1802 device_out(unit->cooler_address, unit->cooler_state); |
1796 } else { |
1803 } else { |
1797 device_out(unit->cooler_address, 0); |
1804 device_out(unit->cooler_address, 0); |
1798 } |
1805 } |
1799 } |
1806 } |
1800 if (debug) |
1807 // if (debug) |
1801 fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n", |
1808 // fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n", |
1802 unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state); |
1809 // unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state); |
1803 |
1810 |
1804 /* |
1811 /* |
1805 * If there is a fan, and the unit door is closed, and the unit should be doing |
1812 * If there is a fan, and the unit door is closed, and the unit should be doing |
1806 * something, then turn on the global fan. |
1813 * something, then turn on the global fan. |
1807 * But if there is a chiller, do not turn it on if cooling. |
1814 * But if there is a chiller, do not turn it on if cooling. |