Blame view

heat.c 5.87 KB
8dca7aeb   henyxia   Automatic Pumping...
1
2
3
4
5
  #include <stdio.h>
  #include <time.h>
  #include <stdbool.h>
  #include "hvc.h"
  #include "heat.h"
11824cae   Pierre Letousey   Added automatic p...
6
  #include "pump.h"
bf0cbb04   Pierre Letousey   Automatic regulation
7
  #include "printx.h"
8dca7aeb   henyxia   Automatic Pumping...
8
  
bf0cbb04   Pierre Letousey   Automatic regulation
9
10
  #define TASK_NUMBER 32
  #define T_INIT_THRESH 40
11824cae   Pierre Letousey   Added automatic p...
11
12
  #define T_STEP_THRESH 80
  #define T_HOLD_THRESH 85 //OP is 88
8dca7aeb   henyxia   Automatic Pumping...
13
14
15
  #define INIT_HEAT_TIME 15
  #define INIT_WAIT_TIME 15
  #define STEP_HEAT_TIME 2
bf0cbb04   Pierre Letousey   Automatic regulation
16
  #define STEP_WAIT_TIME 8 //OP is 5
8dca7aeb   henyxia   Automatic Pumping...
17
  #define HOLD_HEAT_TIME 1
11824cae   Pierre Letousey   Added automatic p...
18
  #define HOLD_WAIT_TIME 8
8dca7aeb   henyxia   Automatic Pumping...
19
  #define HOLD_PUMP_HEAT_TIME 3
bf0cbb04   Pierre Letousey   Automatic regulation
20
  #define HOLD_PUMP_WAIT_TIME 5
8dca7aeb   henyxia   Automatic Pumping...
21
22
23
24
25
  
  
  //Globals
  time_t tTask;
  time_t tNow;
11824cae   Pierre Letousey   Added automatic p...
26
  float tAct;
bf0cbb04   Pierre Letousey   Automatic regulation
27
  bool task[TASK_NUMBER];
8dca7aeb   henyxia   Automatic Pumping...
28
  bool stop=false;
8dca7aeb   henyxia   Automatic Pumping...
29
  bool hold_heat=true;
8dca7aeb   henyxia   Automatic Pumping...
30
  bool eco_mode=false;
bb8c2799   henyxia   Fixed version
31
  bool stopHeat=false;
11824cae   Pierre Letousey   Added automatic p...
32
  bool heat_ok=false;
bf0cbb04   Pierre Letousey   Automatic regulation
33
34
35
  
  void initProcessHeat(void)
  {
bf0cbb04   Pierre Letousey   Automatic regulation
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  	task[0]=true;
  	for (int i_initH=1;i_initH<TASK_NUMBER;i_initH++)
  		task[i_initH]=false;
  }
  
  void actTemp(float temp)
  {
  	tAct = temp;
  }
  
  void stopAutoHeat(void)
  {
  	stopHeat = true;
  }
  
11824cae   Pierre Letousey   Added automatic p...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  void setHeatOk(void)
  {
  	heat_ok=true;
  }
  
  void resetHeatOk(void)
  {
  	heat_ok=false;
  }
  
  bool isHeatOk(void)
  {
  	return heat_ok;
  }
  
8dca7aeb   henyxia   Automatic Pumping...
66
67
  void* processHeat(void* arg)
  {
bb8c2799   henyxia   Fixed version
68
  	while(!stopHeat)
8dca7aeb   henyxia   Automatic Pumping...
69
70
71
72
73
74
75
  	{
  		tNow = clock();
  		
  		//Chaufffe initiale
  		if (task[0])
  		{
  			tTask = clock();
bf0cbb04   Pierre Letousey   Automatic regulation
76
  			
8dca7aeb   henyxia   Automatic Pumping...
77
78
79
  			if (tAct < T_INIT_THRESH)
  			{
  				setHeatOn();
11824cae   Pierre Letousey   Added automatic p...
80
  				printx(INFO, BUS, "Début chauffe initiale 0\n");
8dca7aeb   henyxia   Automatic Pumping...
81
82
83
84
85
86
87
  				task[0] = false;
  				task[1] = true;
  			}
  			
  			else
  			{
  				task[0] = false;
bf0cbb04   Pierre Letousey   Automatic regulation
88
  				task[6] = true;
8dca7aeb   henyxia   Automatic Pumping...
89
90
91
92
93
  			}
  		}
  		
  		else if (task[1])
  		{
bf0cbb04   Pierre Letousey   Automatic regulation
94
95
96
97
98
99
100
  			tTask = clock();
  			task[1] = false;
  			task[2] = true;
  		}
  		
  		else if (task[2])
  		{
8dca7aeb   henyxia   Automatic Pumping...
101
102
103
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_HEAT_TIME )
  			{
  				setHeatOff();
11824cae   Pierre Letousey   Added automatic p...
104
  				printx(INFO, BUS, "Fin chauffe initiale 1\n");
bf0cbb04   Pierre Letousey   Automatic regulation
105
106
  				task[2] = false;
  				task[3] = true;
8dca7aeb   henyxia   Automatic Pumping...
107
108
109
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
110
111
112
113
114
115
116
117
  		else if (task[3])
  		{
  			tTask = clock();
  			task[3] = false;
  			task[4] = true;
  		}
  		
  		else if (task[4])
8dca7aeb   henyxia   Automatic Pumping...
118
119
120
  		{
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_WAIT_TIME )
  			{
11824cae   Pierre Letousey   Added automatic p...
121
  				printx(INFO, BUS, "Fin attente %d sec 2\n", INIT_WAIT_TIME);
bf0cbb04   Pierre Letousey   Automatic regulation
122
123
  				task[4] = false;
  				task[5] = true;
8dca7aeb   henyxia   Automatic Pumping...
124
125
126
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
127
128
129
130
131
132
133
134
135
136
137
  		
  		//Chauffe par palier
  		else if (task[5])
  		{
  			tTask = clock();
  			task[5] = false;
  			task[6] = true;
  		}
  		
  		
  		else if (task[6])
8dca7aeb   henyxia   Automatic Pumping...
138
139
140
  		{
  			if (tAct < T_STEP_THRESH)
  			{
11824cae   Pierre Letousey   Added automatic p...
141
  				printx(INFO, BUS, "Début Chauffe par palier 3\n");
8dca7aeb   henyxia   Automatic Pumping...
142
  				setHeatOn();
bf0cbb04   Pierre Letousey   Automatic regulation
143
144
  				task[6] = false;
  				task[7] = true;
8dca7aeb   henyxia   Automatic Pumping...
145
146
147
148
  			}
  			
  			else
  			{
bf0cbb04   Pierre Letousey   Automatic regulation
149
150
  				task[6] = false;
  				task[11] = true; //Numéro de tache début "Maintien au chaud"
8dca7aeb   henyxia   Automatic Pumping...
151
152
153
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
154
155
156
157
158
159
160
161
  		else if (task[7])
  		{
  			tTask = clock();
  			task[7] = false;
  			task[8] = true;
  		}
  		
  		else if (task[8])
8dca7aeb   henyxia   Automatic Pumping...
162
163
164
  		{
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_HEAT_TIME )
  			{
11824cae   Pierre Letousey   Added automatic p...
165
  				printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4\n");
8dca7aeb   henyxia   Automatic Pumping...
166
  				setHeatOff();
bf0cbb04   Pierre Letousey   Automatic regulation
167
168
  				task[8] = false;
  				task[9] = true;
8dca7aeb   henyxia   Automatic Pumping...
169
170
171
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
172
173
174
175
176
177
178
179
  		else if (task[9])
  		{
  			tTask = clock();
  			task[9] = false;
  			task[10] = true;
  		}
  		
  		else if (task[10])
8dca7aeb   henyxia   Automatic Pumping...
180
181
182
  		{
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_WAIT_TIME )
  			{
11824cae   Pierre Letousey   Added automatic p...
183
  				printx(INFO, BUS, "Fin d'attente palier intermédiaire 5\n");
bf0cbb04   Pierre Letousey   Automatic regulation
184
  				
8dca7aeb   henyxia   Automatic Pumping...
185
186
  				if ( tAct < T_STEP_THRESH )
  				{
bf0cbb04   Pierre Letousey   Automatic regulation
187
188
  					task[10] = false;
  					task[5] = true;
8dca7aeb   henyxia   Automatic Pumping...
189
190
191
192
  				}
  				
  				else
  				{
bf0cbb04   Pierre Letousey   Automatic regulation
193
194
  					task[10] = false;
  					task[11] = true;
8dca7aeb   henyxia   Automatic Pumping...
195
196
197
198
  				}
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
199
  		
8dca7aeb   henyxia   Automatic Pumping...
200
  		// Maintien au chaud
bf0cbb04   Pierre Letousey   Automatic regulation
201
202
203
204
205
206
207
208
  		else if (task[11])
  		{
  			tTask = clock();
  			task[11] = false;
  			task[12] = true;
  		}
  	
  		else if (task[12])
8dca7aeb   henyxia   Automatic Pumping...
209
  		{
11824cae   Pierre Letousey   Added automatic p...
210
211
  			printx(INFO, BUS, "Début Maintien au chaud 6\n");
  			setHeatOk();
bf0cbb04   Pierre Letousey   Automatic regulation
212
213
  			task[12]=false;
  			task[13]=true;
8dca7aeb   henyxia   Automatic Pumping...
214
215
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
216
217
218
219
220
221
222
223
  		else if (task[13])
  		{
  			tTask = clock();
  			task[13] = false;
  			task[14] = true;
  		}
  		
  		else if (task[14])
8dca7aeb   henyxia   Automatic Pumping...
224
225
226
  		{			
  			if(hold_heat)
  			{
bf0cbb04   Pierre Letousey   Automatic regulation
227
  				if( (tAct < T_HOLD_THRESH))
11824cae   Pierre Letousey   Added automatic p...
228
229
  				{			
  					if (!isPumpOn())
bf0cbb04   Pierre Letousey   Automatic regulation
230
  					{
11824cae   Pierre Letousey   Added automatic p...
231
  						printx(INFO, BUS, "Début Chauffe maintien sans pompe 7\n");
bf0cbb04   Pierre Letousey   Automatic regulation
232
233
234
235
  						setHeatOn();
  						task[14] = false;
  						task[15] = true;
  					}
8dca7aeb   henyxia   Automatic Pumping...
236
  			
bf0cbb04   Pierre Letousey   Automatic regulation
237
238
  					else 
  					{
11824cae   Pierre Letousey   Added automatic p...
239
  						printx(INFO, BUS, "Début Chauffe maintien avec pompe 7'\n");
bf0cbb04   Pierre Letousey   Automatic regulation
240
241
242
243
  						setHeatOn();
  						task[14]=false;
  						task[19]=true; //Numéro de tache "T<Thold && pumpitup"
  					}
8dca7aeb   henyxia   Automatic Pumping...
244
245
246
247
248
249
  				}
  			
  			}
  			
  			else
  			{
11824cae   Pierre Letousey   Added automatic p...
250
  				printx(INFO, BUS, "Maintien au chaud annulé 7 ' ' Go etape de fin\n");
bf0cbb04   Pierre Letousey   Automatic regulation
251
252
  				task[14]=false;
  				task[23]=true; //Sinon go étape d'attente fin
8dca7aeb   henyxia   Automatic Pumping...
253
254
255
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
256
257
258
259
260
261
262
  		else if (task[15])
  		{
  			tTask = clock();
  			task[15] = false;
  			task[16] = true;
  		}
  		
8dca7aeb   henyxia   Automatic Pumping...
263
  			//Maintien au chaud sans pompage
bf0cbb04   Pierre Letousey   Automatic regulation
264
  		else if (task[16])
8dca7aeb   henyxia   Automatic Pumping...
265
266
267
  		{
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_HEAT_TIME )
  			{
11824cae   Pierre Letousey   Added automatic p...
268
  				printx(INFO, BUS, "Fin chauffe maintien sans pompe 8\n");
8dca7aeb   henyxia   Automatic Pumping...
269
  				setHeatOff();
bf0cbb04   Pierre Letousey   Automatic regulation
270
271
  				task[16] = false;
  				task[17] = true;
8dca7aeb   henyxia   Automatic Pumping...
272
273
274
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
275
276
277
278
279
280
281
282
  		else if (task[17])
  		{
  			tTask = clock();
  			task[17] = false;
  			task[18] = true;
  		}
  		
  		else if (task[18])
8dca7aeb   henyxia   Automatic Pumping...
283
284
285
286
287
  		{
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_WAIT_TIME )
  			{
  				if ( tAct < T_HOLD_THRESH)
  				{
11824cae   Pierre Letousey   Added automatic p...
288
  					printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9\n");
bf0cbb04   Pierre Letousey   Automatic regulation
289
290
  					task[18] = false;	
  					task[11] = true; //Retour au début de "Maintien au chaud" 
8dca7aeb   henyxia   Automatic Pumping...
291
292
293
294
295
  				}
  			}
  		}
  		
  			//Maintien au chaud avec pompage
bf0cbb04   Pierre Letousey   Automatic regulation
296
297
298
299
300
301
302
303
  		else if (task[19])
  		{
  			tTask = clock();
  			task[19] = false;
  			task[20] = true;
  		}	
  			
  		else if (task[20])
8dca7aeb   henyxia   Automatic Pumping...
304
305
306
  		{
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_HEAT_TIME )
  			{
11824cae   Pierre Letousey   Added automatic p...
307
  				printx(INFO, BUS, "Fin chauffe maintien avec pompe 10\n");
8dca7aeb   henyxia   Automatic Pumping...
308
  				setHeatOff();
bf0cbb04   Pierre Letousey   Automatic regulation
309
310
  				task[20] = false;
  				task[21] = true;
8dca7aeb   henyxia   Automatic Pumping...
311
312
313
  			}
  		}
  		
bf0cbb04   Pierre Letousey   Automatic regulation
314
315
316
317
318
319
320
321
  		else if (task[21])
  		{
  			tTask = clock();
  			task[21] = false;
  			task[22] = true;
  		}
  		
  		else if (task[22])
8dca7aeb   henyxia   Automatic Pumping...
322
323
324
325
326
  		{
  			if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_WAIT_TIME )
  			{
  				if ( tAct < T_HOLD_THRESH)
  				{
11824cae   Pierre Letousey   Added automatic p...
327
  					printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11\n");
bf0cbb04   Pierre Letousey   Automatic regulation
328
329
  					task[22] = false;
  					task[11] = true; //Retour au début de "Maintien au chaud" 
8dca7aeb   henyxia   Automatic Pumping...
330
331
332
  				}			
  			}
  		}
bf0cbb04   Pierre Letousey   Automatic regulation
333
  
8dca7aeb   henyxia   Automatic Pumping...
334
  			//Fin de maintien au chaud (demandé par l'extérieur) et reboucle quand hold_heat est remis
bf0cbb04   Pierre Letousey   Automatic regulation
335
  		else if(task[23])
8dca7aeb   henyxia   Automatic Pumping...
336
337
338
339
340
341
  		{
  			setHeatOff();
  			heat_ok=false;
  			
  			if(hold_heat)
  			{
bf0cbb04   Pierre Letousey   Automatic regulation
342
343
  				task[23]=false;
  				task[0]=true; //Retour au début
8dca7aeb   henyxia   Automatic Pumping...
344
345
346
347
348
  			}
  		}
  		
  		
  		//Mode économie dnergie
bf0cbb04   Pierre Letousey   Automatic regulation
349
  		else if(task[24])
8dca7aeb   henyxia   Automatic Pumping...
350
351
352
353
354
355
356
357
358
  		{
  				//task[]=false;
  				//task[]=true;
  		}
  		
  		
  	}
  	
  	
bb8c2799   henyxia   Fixed version
359
  	return NULL;
8dca7aeb   henyxia   Automatic Pumping...
360
  }