Blame view

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