25 |
25 |
26 #ifdef USE_SIMULATOR |
26 #ifdef USE_SIMULATOR |
27 |
27 |
28 extern int my_shutdown; |
28 extern int my_shutdown; |
29 extern int debug; |
29 extern int debug; |
|
30 extern sys_config Config; |
30 |
31 |
31 |
32 |
32 |
33 |
33 #ifdef HAVE_WIRINGPI_H |
34 #ifdef HAVE_WIRINGPI_H |
34 PI_THREAD (my_simulator_loop) |
35 PI_THREAD (my_simulator_loop) |
35 #else |
36 #else |
36 void *my_simulator_loop(void *threadid) |
37 void *my_simulator_loop(void *threadid) |
37 #endif |
38 #endif |
38 { |
39 { |
|
40 simulator_list *simulator; |
|
41 time_t now, last = (time_t)0; |
|
42 int seconds = 0; |
|
43 double k_room_air, sqm_room_air, thick_room_air, heat_transfer; |
|
44 double t_change, vhc_air = 0.00121, vhc_water = 4.1796; |
39 |
45 |
40 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
46 syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
41 if (debug) |
47 if (debug) |
42 fprintf(stdout, "Thread my_simulator_loop started\n"); |
48 fprintf(stdout, "Thread my_simulator_loop started\n"); |
43 |
49 |
44 for (;;) { |
50 for (;;) { |
|
51 for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
|
52 if (my_shutdown) |
|
53 break; |
45 |
54 |
46 if (my_shutdown) |
55 now = time(NULL); |
47 break; |
56 if (now != last) { |
|
57 last = now; |
|
58 /* |
|
59 * Each second |
|
60 */ |
|
61 seconds++; |
48 |
62 |
49 usleep(100000); |
63 /* |
|
64 * First, calculate temperature difference between the room and the air in the |
|
65 * fridge. We use the volume air to roughly calculate the total area between |
|
66 * the in and outside. Calculate the effect and shift the air temperature towards |
|
67 * the room temperature. |
|
68 */ |
|
69 sqm_room_air = (cbrtl(simulator->volume_air) * cbrtl(simulator->volume_air) * 6) / 100; /* square meters all fridge sides */ |
|
70 thick_room_air = 0.02; /* 4 cm walls */ |
|
71 k_room_air = 0.03; /* Polystrene */ |
|
72 heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; |
|
73 if (heat_transfer != 0) |
|
74 t_change = vhc_air / (heat_transfer * (simulator->volume_air * 1000)); |
|
75 else |
|
76 t_change = 0.0; |
|
77 simulator->air_temperature = simulator->air_temperature + t_change; |
|
78 fprintf(stdout, "room_air=%f room=%f air=%.15f heat_transfer=%f t_change=%.15f\n", |
|
79 sqm_room_air, simulator->room_temperature, simulator->air_temperature, heat_transfer, t_change); |
|
80 |
|
81 /* |
|
82 * If heating, calculate temperature of the heating plate. If heating is off but |
|
83 * the plate is warmer then the air, calculate the cooling down temperature. |
|
84 * Finally, calculate the new air and plate temperature. |
|
85 */ |
|
86 |
|
87 /* |
|
88 * If cooling, calculate temperature of the cooling plate. If cooling is off but |
|
89 * the plate is colder then the air, calculate the warming up temperature. |
|
90 * Finsally, calculate the new air and plate temperature. |
|
91 */ |
|
92 |
|
93 /* |
|
94 * Calculate the extra beer temperatur rise to simulate the heat produced by the |
|
95 * fermentation process. Peak about one day after start and slowly decrease after |
|
96 * that. |
|
97 */ |
|
98 |
|
99 /* |
|
100 * Calculate final temperature of the beer and the air. |
|
101 */ |
|
102 |
|
103 } |
|
104 usleep(100000); |
|
105 } |
|
106 usleep(50000); |
50 } |
107 } |
51 |
108 |
52 syslog(LOG_NOTICE, "Thread my_simulator_loop stopped"); |
109 syslog(LOG_NOTICE, "Thread my_simulator_loop stopped"); |
53 if (debug) |
110 if (debug) |
54 fprintf(stdout, "Thread my_simulator_loop stopped\n"); |
111 fprintf(stdout, "Thread my_simulator_loop stopped\n"); |