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