Mercurial > public > ostc4
annotate Discovery/Src/check_warning.c @ 411:e908b894f107 Improment_NVM
Bugfix: Limit log length in case of corrupted sample storage:
In case of a sample address reset the header would have a smaler end address as the start address. As result the length becomes very long and download e.g. via Subsurface, would seem to hang. To solve this the number of sample bytes in this use case has been limited. Tested with subsurface only. After change dowload of logs is possible again. Nevertheless the sampledata will be lost.
Minor change: "header" was used as global as well as as local variable => changed name for global variant to gheader.
author | ideenmodellierer |
---|---|
date | Mon, 13 Jan 2020 20:27:57 +0100 |
parents | 74a8296a2318 |
children | 58200d756365 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file check_warning.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @date 17-Nov-2014 | |
6 * @version V0.0.1 | |
7 * @since 17-Nov-2014 | |
8 * @brief check and set warnings for warnings | |
9 * | |
10 @verbatim | |
11 ============================================================================== | |
12 ##### How to use ##### | |
13 ============================================================================== | |
14 OSTC3 Warnings: | |
15 niedriger Batteriezustand ( | |
16 zu hoher oder zu niedriger Sauerstoffpartialdruck (ppO2) 0.2 - 1.6 | |
17 zu hoher CNS (Gefahr der Sauerstoffvergiftung) 90% | |
18 zu hohe Gradientenfaktoren 90 - 90 | |
19 Missachtung der Dekostopps (der �berschrittene Dekostopp wird rot angezeigt) 0 m | |
20 zu hohe Aufstiegsgeschwindigkeit 30 m/min | |
21 aGF-Warnung: die Berechnung der Dekompression wird �ber alternative GF-Werte durchgef�hrt | |
22 Fallback-Warnung bei ausgefallenem Sensor | |
23 | |
24 @endverbatim | |
25 ****************************************************************************** | |
26 * @attention | |
27 * | |
28 * <h2><center>© COPYRIGHT(c) 2014 heinrichs weikamp</center></h2> | |
29 * | |
30 ****************************************************************************** | |
31 */ | |
32 | |
33 /* Includes ------------------------------------------------------------------*/ | |
34 | |
35 #include "data_exchange.h" | |
36 #include "check_warning.h" | |
37 #include "settings.h" | |
38 #include "decom.h" | |
39 #include "tCCR.h" | |
40 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
41 /* Private variables with access ----------------------------------------------*/ |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
42 static uint8_t betterGasId = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
43 static uint8_t betterSetpointId = 0; |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
44 static int8_t fallback = 0; |
38 | 45 |
46 /* Private function prototypes -----------------------------------------------*/ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
47 static int8_t check_fallback(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
48 static int8_t check_ppO2(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
49 static int8_t check_O2_sensors(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
50 static int8_t check_CNS(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
51 static int8_t check_Deco(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
52 static int8_t check_AscentRate(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
53 static int8_t check_aGF(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
54 static int8_t check_BetterGas(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
55 static int8_t check_BetterSetpoint(SDiveState * pDiveState); |
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
56 static int8_t check_Battery(SDiveState * pDiveState); |
38 | 57 |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
58 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2); |
38 | 59 |
60 /* Exported functions --------------------------------------------------------*/ | |
61 | |
62 void check_warning(void) | |
63 { | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
268
diff
changeset
|
64 check_warning2(stateUsedWrite); |
38 | 65 } |
66 | |
67 | |
68 void check_warning2(SDiveState * pDiveState) | |
69 { | |
70 pDiveState->warnings.numWarnings = 0; | |
71 | |
72 pDiveState->warnings.numWarnings += check_aGF(pDiveState); | |
73 pDiveState->warnings.numWarnings += check_AscentRate(pDiveState); | |
74 pDiveState->warnings.numWarnings += check_CNS(pDiveState); | |
75 pDiveState->warnings.numWarnings += check_Deco(pDiveState); | |
76 pDiveState->warnings.numWarnings += check_ppO2(pDiveState); | |
77 pDiveState->warnings.numWarnings += check_O2_sensors(pDiveState); | |
78 pDiveState->warnings.numWarnings += check_BetterGas(pDiveState); | |
79 pDiveState->warnings.numWarnings += check_BetterSetpoint(pDiveState); | |
80 pDiveState->warnings.numWarnings += check_Battery(pDiveState); | |
81 pDiveState->warnings.numWarnings += check_fallback(pDiveState); | |
82 } | |
83 | |
84 | |
85 void set_warning_fallback(void) | |
86 { | |
87 fallback = 1; | |
88 } | |
89 | |
90 | |
91 void clear_warning_fallback(void) | |
92 { | |
93 fallback = 0; | |
94 } | |
95 | |
96 | |
97 uint8_t actualBetterGasId(void) | |
98 { | |
99 return betterGasId; | |
100 } | |
101 | |
102 | |
103 uint8_t actualBetterSetpointId(void) | |
104 { | |
105 return betterSetpointId; | |
106 } | |
107 | |
108 | |
109 uint8_t actualLeftMaxDepth(const SDiveState * pDiveState) | |
110 { | |
111 if(pDiveState->lifeData.depth_meter > (pDiveState->lifeData.max_depth_meter - 3.0f)) | |
112 return 0; | |
113 else | |
114 return 1; | |
115 } | |
116 | |
117 | |
118 /* Private functions ---------------------------------------------------------*/ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
119 static int8_t check_fallback(SDiveState * pDiveState) |
38 | 120 { |
121 if(fallback && ((pDiveState->mode != MODE_DIVE) || (pDiveState->diveSettings.diveMode != DIVEMODE_CCR))) | |
122 fallback = 0; | |
123 | |
124 pDiveState->warnings.fallback = fallback; | |
125 return pDiveState->warnings.fallback; | |
126 } | |
127 | |
128 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
129 static int8_t check_ppO2(SDiveState * pDiveState) |
38 | 130 { |
131 if(pDiveState->mode != MODE_DIVE) | |
132 { | |
133 pDiveState->warnings.ppO2Low = 0; | |
134 pDiveState->warnings.ppO2High = 0; | |
135 return 0; | |
136 } | |
137 | |
138 uint8_t localPPO2, testPPO2high; | |
139 | |
140 if(pDiveState->lifeData.ppO2 < 0) | |
141 localPPO2 = 0; | |
142 else | |
143 if(pDiveState->lifeData.ppO2 >= 2.5f) | |
144 localPPO2 = 255; | |
145 else | |
146 localPPO2 = (uint8_t)(pDiveState->lifeData.ppO2 * 100); | |
147 | |
148 if((localPPO2 + 1) <= settingsGetPointer()->ppO2_min) | |
149 pDiveState->warnings.ppO2Low = 1; | |
150 else | |
151 pDiveState->warnings.ppO2Low = 0; | |
152 | |
153 if(actualLeftMaxDepth(pDiveState)) | |
154 testPPO2high = settingsGetPointer()->ppO2_max_deco; | |
155 else | |
156 testPPO2high = settingsGetPointer()->ppO2_max_std; | |
157 | |
158 if(localPPO2 >= (testPPO2high + 1)) | |
159 pDiveState->warnings.ppO2High = 1; | |
160 else | |
161 pDiveState->warnings.ppO2High = 0; | |
162 | |
163 return pDiveState->warnings.ppO2Low + pDiveState->warnings.ppO2High; | |
164 } | |
165 | |
166 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
167 static int8_t check_O2_sensors(SDiveState * pDiveState) |
38 | 168 { |
169 pDiveState->warnings.sensorLinkLost = 0; | |
170 pDiveState->warnings.sensorOutOfBounds[0] = 0; | |
171 pDiveState->warnings.sensorOutOfBounds[1] = 0; | |
172 pDiveState->warnings.sensorOutOfBounds[2] = 0; | |
173 | |
174 if((pDiveState->diveSettings.diveMode == DIVEMODE_CCR) && (pDiveState->diveSettings.CCR_Mode == CCRMODE_Sensors)) | |
175 { | |
176 if(!get_HUD_battery_voltage_V()) | |
177 pDiveState->warnings.sensorLinkLost = 1; | |
178 | |
179 test_HUD_sensor_values_outOfBounds(&pDiveState->warnings.sensorOutOfBounds[0], &pDiveState->warnings.sensorOutOfBounds[1], &pDiveState->warnings.sensorOutOfBounds[2]); | |
180 | |
181 } | |
182 return pDiveState->warnings.sensorLinkLost | |
183 + pDiveState->warnings.sensorOutOfBounds[0] | |
184 + pDiveState->warnings.sensorOutOfBounds[1] | |
185 + pDiveState->warnings.sensorOutOfBounds[2]; | |
186 } | |
187 | |
188 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
189 static int8_t check_BetterGas(SDiveState * pDiveState) |
38 | 190 { |
191 if(stateUsed->mode != MODE_DIVE) | |
192 { | |
193 pDiveState->warnings.betterGas = 0; | |
194 betterGasId = 0; | |
195 return 0; | |
196 } | |
197 | |
198 uint8_t gasIdOffset; | |
199 uint8_t bestGasDepth, betterGasIdLocal; | |
200 | |
201 SLifeData* pLifeData = &pDiveState->lifeData; | |
202 SDiveSettings* pDiveSettings = &pDiveState->diveSettings; | |
203 | |
204 pDiveState->warnings.betterGas = 0; | |
205 betterGasId = 0; | |
206 betterGasIdLocal = pLifeData->actualGas.GasIdInSettings; | |
207 bestGasDepth = 255; | |
208 | |
209 if(pDiveSettings->diveMode == DIVEMODE_CCR) | |
210 gasIdOffset = NUM_OFFSET_DILUENT; | |
211 else | |
212 gasIdOffset = 0; | |
213 | |
214 /* life data is float, gas data is uint8 */ | |
215 if(actualLeftMaxDepth(pDiveState)) /* deco gases */ | |
216 { | |
217 for(int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) | |
218 { | |
219 if( (pDiveSettings->gas[i].note.ub.active) | |
220 && (pDiveSettings->gas[i].note.ub.deco) | |
221 && (pDiveSettings->gas[i].depth_meter) | |
222 && (pDiveSettings->gas[i].depth_meter >= (pLifeData->depth_meter - 0.01f )) | |
223 && (pDiveSettings->gas[i].depth_meter <= bestGasDepth) | |
224 ) | |
225 { | |
226 betterGasIdLocal = i; | |
227 bestGasDepth = pDiveSettings->gas[i].depth_meter; | |
228 } | |
229 } | |
230 | |
231 if(betterGasIdLocal != pLifeData->actualGas.GasIdInSettings) | |
232 { | |
233 if(!check_helper_same_oxygen_and_helium_content(&pDiveSettings->gas[betterGasIdLocal], &pDiveSettings->gas[pLifeData->actualGas.GasIdInSettings])) | |
234 { | |
235 betterGasId = betterGasIdLocal; | |
236 pDiveState->warnings.betterGas = 1; | |
237 } | |
238 } | |
239 } | |
240 else /* travel gases */ | |
241 { | |
242 bestGasDepth = 0; | |
243 //check for travalgas | |
244 for(int i=1+gasIdOffset; i<= 5+gasIdOffset; i++) | |
245 { | |
246 if( (pDiveSettings->gas[i].note.ub.active) | |
247 && (pDiveSettings->gas[i].note.ub.travel) | |
248 && (pDiveSettings->gas[i].depth_meter_travel) | |
249 && (pDiveSettings->gas[i].depth_meter_travel <= (pLifeData->depth_meter + 0.01f )) | |
250 && (pDiveSettings->gas[i].depth_meter_travel >= bestGasDepth) | |
251 ) | |
252 { | |
253 betterGasIdLocal = i; | |
254 bestGasDepth = pDiveSettings->gas[i].depth_meter; | |
255 } | |
256 } | |
257 | |
258 if(betterGasIdLocal != pLifeData->actualGas.GasIdInSettings) | |
259 { | |
260 if(!check_helper_same_oxygen_and_helium_content(&pDiveSettings->gas[betterGasIdLocal], &pDiveSettings->gas[pLifeData->actualGas.GasIdInSettings])) | |
261 { | |
262 betterGasId = betterGasIdLocal; | |
263 pDiveState->warnings.betterGas = 1; | |
264 } | |
265 } | |
266 } | |
267 return pDiveState->warnings.betterGas; | |
268 } | |
269 | |
270 /* check for better travel!!! setpoint hw 151210 | |
271 */ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
272 static int8_t check_BetterSetpoint(SDiveState * pDiveState) |
38 | 273 { |
274 pDiveState->warnings.betterSetpoint = 0; | |
275 betterSetpointId = 0; | |
276 | |
277 if((stateUsed->mode != MODE_DIVE) || (pDiveState->diveSettings.diveMode != DIVEMODE_CCR) || (pDiveState->diveSettings.CCR_Mode != CCRMODE_FixedSetpoint)) | |
278 { | |
279 return 0; | |
280 } | |
281 | |
282 uint8_t bestSetpointDepth = 0; // travel the deeper, the better | |
283 uint8_t betterSetpointIdLocal = 0; // nothing better | |
284 | |
285 if(!actualLeftMaxDepth(pDiveState)) /* travel gases */ | |
286 { | |
287 for(int i=1; i<=NUM_GASES; i++) | |
288 { | |
289 if( (pDiveState->diveSettings.setpoint[i].note.ub.active) | |
290 && (pDiveState->diveSettings.setpoint[i].depth_meter) | |
291 && (pDiveState->diveSettings.setpoint[i].depth_meter <= ( pDiveState->lifeData.depth_meter + 0.01f )) | |
292 && (pDiveState->diveSettings.setpoint[i].depth_meter >= bestSetpointDepth) | |
293 ) | |
294 { | |
295 betterSetpointIdLocal = i; | |
296 bestSetpointDepth = pDiveState->diveSettings.setpoint[i].depth_meter; | |
297 } | |
298 } | |
299 if((betterSetpointIdLocal) && (pDiveState->diveSettings.setpoint[betterSetpointIdLocal].setpoint_cbar != pDiveState->lifeData.actualGas.setPoint_cbar)) | |
300 { | |
301 betterSetpointId = betterSetpointIdLocal; | |
302 pDiveState->warnings.betterSetpoint = 1; | |
303 } | |
304 } | |
305 return pDiveState->warnings.betterSetpoint; | |
306 } | |
307 | |
308 | |
309 /* hw 151030 | |
310 */ | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
311 static int8_t check_helper_same_oxygen_and_helium_content(SGasLine * gas1, SGasLine * gas2) |
38 | 312 { |
313 if(gas1->helium_percentage != gas2->helium_percentage) | |
314 return 0; | |
315 else | |
316 if(gas1->oxygen_percentage != gas2->oxygen_percentage) | |
317 return 0; | |
318 else | |
319 return 1; | |
320 } | |
321 | |
322 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
323 static int8_t check_CNS(SDiveState * pDiveState) |
38 | 324 { |
325 if(stateUsed->mode != MODE_DIVE) | |
326 { | |
327 pDiveState->warnings.cnsHigh = 0; | |
328 return 0; | |
329 } | |
330 | |
331 if(pDiveState->lifeData.cns >= (float)(settingsGetPointer()->CNS_max)) | |
332 pDiveState->warnings.cnsHigh = 1; | |
333 else | |
334 pDiveState->warnings.cnsHigh = 0; | |
335 return pDiveState->warnings.cnsHigh; | |
336 } | |
337 | |
338 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
339 static int8_t check_Battery(SDiveState * pDiveState) |
38 | 340 { |
341 if(pDiveState->lifeData.battery_charge < 10) | |
342 pDiveState->warnings.lowBattery = 1; | |
343 else | |
344 pDiveState->warnings.lowBattery = 0; | |
345 | |
346 return pDiveState->warnings.lowBattery; | |
347 } | |
348 | |
349 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
350 static int8_t check_Deco(SDiveState * pDiveState) |
38 | 351 { |
352 if(stateUsed->mode != MODE_DIVE) | |
353 { | |
354 pDiveState->warnings.decoMissed = 0; | |
355 return 0; | |
356 } | |
357 | |
358 uint8_t depthNext = decom_get_actual_deco_stop(pDiveState); | |
359 | |
360 if(!depthNext) | |
361 pDiveState->warnings.decoMissed = 0; | |
362 else | |
363 if(pDiveState->lifeData.depth_meter + 0.1f < (float)depthNext) | |
364 pDiveState->warnings.decoMissed = 1; | |
365 else | |
366 pDiveState->warnings.decoMissed = 0; | |
367 | |
368 return pDiveState->warnings.decoMissed; | |
369 } | |
370 | |
371 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
372 static int8_t check_AscentRate(SDiveState * pDiveState) |
38 | 373 { |
374 if(stateUsed->mode != MODE_DIVE) | |
375 { | |
376 pDiveState->warnings.ascentRateHigh = 0; | |
377 return 0; | |
378 } | |
379 | |
380 float warnAscentRateFloat; | |
381 | |
382 warnAscentRateFloat = (float)(settingsGetPointer()->ascent_MeterPerMinute_max); | |
383 | |
384 if(pDiveState->lifeData.ascent_rate_meter_per_min >= warnAscentRateFloat) | |
385 pDiveState->warnings.ascentRateHigh = 1; | |
386 else | |
387 pDiveState->warnings.ascentRateHigh = 0; | |
388 return pDiveState->warnings.ascentRateHigh; | |
389 } | |
390 | |
391 | |
268
1b9847d40e81
cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
392 static int8_t check_aGF(SDiveState * pDiveState) |
38 | 393 { |
394 if(stateUsed->mode != MODE_DIVE) | |
395 { | |
396 pDiveState->warnings.aGf = 0; | |
397 return 0; | |
398 } | |
399 | |
400 pDiveState->warnings.aGf = 0; | |
401 if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE) | |
402 { | |
403 if((pDiveState->diveSettings.gf_high != settingsGetPointer()->GF_high) || (pDiveState->diveSettings.gf_low != settingsGetPointer()->GF_low)) | |
404 pDiveState->warnings.aGf = 1; | |
405 } | |
406 return pDiveState->warnings.aGf; | |
407 } | |
408 | |
409 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ | |
410 |