Blame view

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