Commit bf0cbb0484ac45da25be0b62eaf0efb05572fe8e

Authored by Pierre Letousey
1 parent 8ecde263

Automatic regulation

Showing 7 changed files with 202 additions and 72 deletions   Show diff stats
... ... @@ -176,6 +176,12 @@ void processCmd(char* buffer)
176 176 printx(INFO, BUS, "Processing Auto Heat to 90°C");
177 177 processHeat(NULL);
178 178 }
  179 + else if(strcmp(buffer, "stopautoheat") == 0)
  180 + {
  181 + printx(INFO, BUS, "Auto Heat has been stopped");
  182 + stopAutoHeat();
  183 + }
  184 +
179 185  
180 186 //printx(DEBUG, BUS, "STRLEN : %d and strcmp ret %d", strlen(buffer), strcmp(buffer, "quit"));
181 187 }
... ...
... ... @@ -3,33 +3,27 @@
3 3 #include <stdbool.h>
4 4 #include "hvc.h"
5 5 #include "heat.h"
  6 +#include "printx.h"
6 7  
7   -#define TASK_NUMBER 20
8   -#define T_INIT_THRESH 400
9   -#define T_STEP_THRESH 860
10   -#define T_HOLD_THRESH 880
  8 +#define TASK_NUMBER 32
  9 +#define T_INIT_THRESH 40
  10 +#define T_STEP_THRESH 80 //OP is 86
  11 +#define T_HOLD_THRESH 82 //OP is 88
11 12 #define INIT_HEAT_TIME 15
12 13 #define INIT_WAIT_TIME 15
13 14 #define STEP_HEAT_TIME 2
14   -#define STEP_WAIT_TIME 5
  15 +#define STEP_WAIT_TIME 8 //OP is 5
15 16 #define HOLD_HEAT_TIME 1
16   -#define HOLD_WAIT_TIME 2
  17 +#define HOLD_WAIT_TIME 8 //OP is 4
17 18 #define HOLD_PUMP_HEAT_TIME 3
18   -#define HOLD_PUMP_WAIT_TIME 1
  19 +#define HOLD_PUMP_WAIT_TIME 5
19 20  
20 21  
21 22 //Globals
22 23 time_t tTask;
23 24 time_t tNow;
24   -time_t tAct; //Lecture de la température du capteur
25   -bool task[TASK_NUMBER]; //A initialiser (task[0]=true, sinon false)
26   - /*for (int i=0;i<TASK_NUMBER;i++)
27   - {
28   - if (i == 0)
29   - task[i]=true;
30   - else
31   - task[i]=false;
32   - }*/
  25 +float tAct; //Lecture de la température du capteur
  26 +bool task[TASK_NUMBER];
33 27 bool stop=false;
34 28 bool heat_ok=false;
35 29 bool hold_heat=true;
... ... @@ -37,6 +31,25 @@ bool pumpitup=false; //Lecture de l&#39;état de la pompe
37 31 bool eco_mode=false;
38 32 bool stopHeat=false;
39 33  
  34 +
  35 +void initProcessHeat(void)
  36 +{
  37 + //Initialisation du tableau task
  38 + task[0]=true;
  39 + for (int i_initH=1;i_initH<TASK_NUMBER;i_initH++)
  40 + task[i_initH]=false;
  41 +}
  42 +
  43 +void actTemp(float temp)
  44 +{
  45 + tAct = temp;
  46 +}
  47 +
  48 +void stopAutoHeat(void)
  49 +{
  50 + stopHeat = true;
  51 +}
  52 +
40 53 void* processHeat(void* arg)
41 54 {
42 55 while(!stopHeat)
... ... @@ -47,9 +60,11 @@ void* processHeat(void* arg)
47 60 if (task[0])
48 61 {
49 62 tTask = clock();
  63 +
50 64 if (tAct < T_INIT_THRESH)
51 65 {
52 66 setHeatOn();
  67 + printx(INFO, BUS, "Début chauffe initiale 0");
53 68 task[0] = false;
54 69 task[1] = true;
55 70 }
... ... @@ -57,171 +72,268 @@ void* processHeat(void* arg)
57 72 else
58 73 {
59 74 task[0] = false;
60   - task[3] = true;
  75 + task[6] = true;
61 76 }
62 77 }
63 78  
64 79 else if (task[1])
65 80 {
  81 + tTask = clock();
  82 + task[1] = false;
  83 + task[2] = true;
  84 + }
  85 +
  86 + else if (task[2])
  87 + {
66 88 if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_HEAT_TIME )
67 89 {
68 90 setHeatOff();
69   - task[1] = false;
70   - task[2] = true;
  91 + printx(INFO, BUS, "Fin chauffe initiale 1");
  92 + task[2] = false;
  93 + task[3] = true;
71 94 }
72 95 }
73 96  
74   - else if (task[2])
  97 + else if (task[3])
  98 + {
  99 + tTask = clock();
  100 + task[3] = false;
  101 + task[4] = true;
  102 + }
  103 +
  104 + else if (task[4])
75 105 {
76 106 if( ((tNow - tTask) / CLOCKS_PER_SEC) > INIT_WAIT_TIME )
77 107 {
78   - task[2] = false;
79   - task[3] = true;
  108 + printx(INFO, BUS, "Fin attente %d sec 2", INIT_WAIT_TIME);
  109 + task[4] = false;
  110 + task[5] = true;
80 111 }
81 112 }
82 113  
83   - //Chauffe par paliers
84   - else if (task[3])
  114 +
  115 + //Chauffe par palier
  116 + else if (task[5])
  117 + {
  118 + tTask = clock();
  119 + task[5] = false;
  120 + task[6] = true;
  121 + }
  122 +
  123 +
  124 + else if (task[6])
85 125 {
86 126 if (tAct < T_STEP_THRESH)
87 127 {
  128 + printx(INFO, BUS, "Début Chauffe par palier 3");
88 129 setHeatOn();
89   - task[3] = false;
90   - task[4] = true;
  130 + task[6] = false;
  131 + task[7] = true;
91 132 }
92 133  
93 134 else
94 135 {
95   - task[3] = false;
96   - task[6] = true; //Numéro de tache début "Maintien au chaud"
  136 + task[6] = false;
  137 + task[11] = true; //Numéro de tache début "Maintien au chaud"
97 138 }
98 139 }
99 140  
100   - else if (task[4])
  141 + else if (task[7])
  142 + {
  143 + tTask = clock();
  144 + task[7] = false;
  145 + task[8] = true;
  146 + }
  147 +
  148 + else if (task[8])
101 149 {
102 150 if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_HEAT_TIME )
103 151 {
  152 + printx(INFO, BUS, "Fin de chauffe palier intermédiaire 4");
104 153 setHeatOff();
105   - task[4] = false;
106   - task[5] = true;
  154 + task[8] = false;
  155 + task[9] = true;
107 156 }
108 157 }
109 158  
110   - else if (task[5])
  159 + else if (task[9])
  160 + {
  161 + tTask = clock();
  162 + task[9] = false;
  163 + task[10] = true;
  164 + }
  165 +
  166 + else if (task[10])
111 167 {
112 168 if( ((tNow - tTask) / CLOCKS_PER_SEC) > STEP_WAIT_TIME )
113 169 {
  170 + printx(INFO, BUS, "Fin d'attente palier intermédiaire 5");
  171 +
114 172 if ( tAct < T_STEP_THRESH )
115 173 {
116   - task[5] = false;
117   - task[3] = true;
  174 + task[10] = false;
  175 + task[5] = true;
118 176 }
119 177  
120 178 else
121 179 {
122   - task[5] = false;
123   - task[6] = true;
  180 + task[10] = false;
  181 + task[11] = true;
124 182 }
125 183 }
126 184 }
127 185  
  186 +
128 187 // Maintien au chaud
129   - else if (task[6])
  188 + else if (task[11])
  189 + {
  190 + tTask = clock();
  191 + task[11] = false;
  192 + task[12] = true;
  193 + }
  194 +
  195 + else if (task[12])
130 196 {
  197 + printx(INFO, BUS, "Début Maintien au chaud 6");
131 198 heat_ok = true;
132   - task[6]=false;
133   - task[7]=true;
  199 + task[12]=false;
  200 + task[13]=true;
134 201 }
135 202  
136   - else if (task[7])
  203 + else if (task[13])
  204 + {
  205 + tTask = clock();
  206 + task[13] = false;
  207 + task[14] = true;
  208 + }
  209 +
  210 + else if (task[14])
137 211 {
138 212 if(hold_heat)
139 213 {
140   - if( (tAct < T_HOLD_THRESH) && !pumpitup)
  214 + if( (tAct < T_HOLD_THRESH))
141 215 {
142   - setHeatOn();
143   - task[7] = false;
144   - task[8] = true;
145   - }
  216 + if (!pumpitup)
  217 + {
  218 + printx(INFO, BUS, "Début Chauffe maintien sans pompe 7");
  219 + setHeatOn();
  220 + task[14] = false;
  221 + task[15] = true;
  222 + }
146 223  
147   - else if ( (tAct < T_HOLD_THRESH) && pumpitup)
148   - {
149   - setHeatOn();
150   - task[7]=false;
151   - task[10]=true; //Numéro de tache "T<Thold && pumpitup"
  224 + else
  225 + {
  226 + printx(INFO, BUS, "Début Chauffe maintien avec pompe 7'");
  227 + setHeatOn();
  228 + task[14]=false;
  229 + task[19]=true; //Numéro de tache "T<Thold && pumpitup"
  230 + }
152 231 }
153 232  
154 233 }
155 234  
156 235 else
157 236 {
158   - task[6]=false;
159   - task[12]=true; //Sinon go étape d'attente fin
  237 + printx(INFO, BUS, "Maintien au chaud annulé 7 ' ' Go etape de fin");
  238 + task[14]=false;
  239 + task[23]=true; //Sinon go étape d'attente fin
160 240 }
161 241 }
162 242  
  243 + else if (task[15])
  244 + {
  245 + tTask = clock();
  246 + task[15] = false;
  247 + task[16] = true;
  248 + }
  249 +
163 250 //Maintien au chaud sans pompage
164   - else if (task[8])
  251 + else if (task[16])
165 252 {
166 253 if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_HEAT_TIME )
167 254 {
  255 + printx(INFO, BUS, "Fin chauffe maintien sans pompe 8");
168 256 setHeatOff();
169   - task[8] = false;
170   - task[9] = true;
  257 + task[16] = false;
  258 + task[17] = true;
171 259 }
172 260 }
173 261  
174   - else if (task[9])
  262 + else if (task[17])
  263 + {
  264 + tTask = clock();
  265 + task[17] = false;
  266 + task[18] = true;
  267 + }
  268 +
  269 + else if (task[18])
175 270 {
176 271 if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_WAIT_TIME )
177 272 {
178 273 if ( tAct < T_HOLD_THRESH)
179 274 {
180   - task[9] = false;
181   - task[7] = true; //Retour au début de "Maintien au chaud"
  275 + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien 9");
  276 + task[18] = false;
  277 + task[11] = true; //Retour au début de "Maintien au chaud"
182 278 }
183 279 }
184 280 }
185 281  
186 282 //Maintien au chaud avec pompage
187   - else if (task[10])
  283 + else if (task[19])
  284 + {
  285 + tTask = clock();
  286 + task[19] = false;
  287 + task[20] = true;
  288 + }
  289 +
  290 + else if (task[20])
188 291 {
189 292 if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_HEAT_TIME )
190 293 {
  294 + printx(INFO, BUS, "Fin chauffe maintien avec pompe 10");
191 295 setHeatOff();
192   - task[10] = false;
193   - task[11] = true;
  296 + task[20] = false;
  297 + task[21] = true;
194 298 }
195 299 }
196 300  
197   - else if (task[11])
  301 + else if (task[21])
  302 + {
  303 + tTask = clock();
  304 + task[21] = false;
  305 + task[22] = true;
  306 + }
  307 +
  308 + else if (task[22])
198 309 {
199 310 if( ((tNow - tTask) / CLOCKS_PER_SEC) > HOLD_PUMP_WAIT_TIME )
200 311 {
201 312 if ( tAct < T_HOLD_THRESH)
202 313 {
203   - task[11] = false;
204   - task[7] = true; //Retour au début de "Maintien au chaud"
  314 + printx(INFO, BUS, "Fin d'attente chauffe intermédiaire maintien avec pompe 11");
  315 + task[22] = false;
  316 + task[11] = true; //Retour au début de "Maintien au chaud"
205 317 }
206 318 }
207 319 }
208   -
  320 +
209 321 //Fin de maintien au chaud (demandé par l'extérieur) et reboucle quand hold_heat est remis
210   - else if(task[12])
  322 + else if(task[23])
211 323 {
212 324 setHeatOff();
213 325 heat_ok=false;
214 326  
215 327 if(hold_heat)
216 328 {
217   - task[12]=false;
218   - task[1]=true; //Retour au début
  329 + task[23]=false;
  330 + task[0]=true; //Retour au début
219 331 }
220 332 }
221 333  
222 334  
223 335 //Mode économie d'énergie
224   - else if(task[13])
  336 + else if(task[24])
225 337 {
226 338 //task[]=false;
227 339 //task[]=true;
... ...
1 1 #ifndef __HEAT_H__
2 2 #define __HEAT_H__
3 3  
  4 +void initProcessHeat(void);
4 5 void* processHeat(void*);
  6 +void actTemp(float);
  7 +void stopAutoHeat(void);
5 8  
6 9 #endif
... ...
... ... @@ -134,6 +134,7 @@ void* processHVC(void* we)
134 134 data = getData(&hvc_fd);
135 135 setTemp(data);
136 136 temp = 25 + (((float)(80*data)))/255;
  137 + actTemp(temp);
137 138 printx(DEBUG, HVC, "TEMP %f\n", temp);
138 139 if(tHeatTimer > 0)
139 140 {
... ...
... ... @@ -5,6 +5,7 @@
5 5 #include "nfc.h"
6 6 #include "bus.h"
7 7 #include "hvc.h"
  8 +#include "heat.h"
8 9  
9 10 #include <unistd.h>
10 11  
... ... @@ -43,8 +44,15 @@ int main(void)
43 44 printx(ERROR, MAIN, "Unable to start the HVC interface\n");
44 45 return 4;
45 46 }
  47 +<<<<<<< Updated upstream
46 48 pthread_create(&tHVC, NULL, processHVC, NULL);*/
47 49 //initProcessHeat();
  50 +=======
  51 + pthread_create(&tHVC, NULL, processHVC, NULL);
  52 + initProcessHeat();
  53 + setPumpOn();
  54 + processHeat(NULL);
  55 +>>>>>>> Stashed changes
48 56  
49 57 pthread_join(tUI, NULL);
50 58 closeLog();
... ...
... ... @@ -62,7 +62,7 @@ void* drawUI(void* we)
62 62 {
63 63 while(!uiStop)
64 64 {
65   - processScreen();
  65 + //processScreen();
66 66 usleep(SCREEN_TIME);
67 67 }
68 68  
... ... @@ -83,7 +83,7 @@ void initUILog()
83 83 mainPid = getpid();
84 84 uid[0]='\0';
85 85 uidDate[0]='\0';
86   - initUSB();
  86 + //initUSB();
87 87 }
88 88  
89 89 void setStartTime(char* sT)
... ...
... ... @@ -108,7 +108,7 @@ bool initUSB(void)
108 108 return false;
109 109 }
110 110  
111   - printf("%d devices detected\n", cnt);
  111 + printf("%d devices detected\n", (int)cnt);
112 112 printf("List of compatible devices detected\n");
113 113  
114 114 for (int i = 0; i < cnt; i++)
... ...