Mercurial > public > ostc4
annotate Discovery/Src/tCCR.c @ 634:7c73f066cd16
Enable sensor check for Analog PPO2 mode:
Checks which may trigger a fallback warning were not activated in previous versions. Beside enabling the checks the test logic has been changed. Before the change an avarage was build automatically using the remaining both sensors if one sensor failed. The scenario that also one of the remaining sensors may be out of bounds was not covered. The new implementation allows an out of bounds detection for all sensors in parallel. In that special case the last valid value will be used until the diver takes action (Fallback warning)
author | Ideenmodellierer |
---|---|
date | Wed, 24 Feb 2021 19:18:26 +0100 |
parents | 64bf41faab83 |
children | 66c8a4ff9fc4 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/tCCR.c | |
5 /// \brief HUD data via optical port | |
6 /// \author Heinrichs Weikamp gmbh | |
7 /// \date 18-Dec-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /* Includes ------------------------------------------------------------------*/ | |
30 #include <string.h> | |
31 #include "tCCR.h" | |
32 #include "ostc.h" | |
33 #include "data_central.h" | |
34 #include "data_exchange.h" | |
35 #include "check_warning.h" | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
36 #include "configuration.h" |
634 | 37 #include <math.h> |
38 | 38 |
39 /* Private types -------------------------------------------------------------*/ | |
40 typedef struct | |
41 { | |
42 uint8_t hud_firmwareVersion; | |
43 bit8_Type status_byte; | |
44 uint16_t sensor_voltage_100uV[3]; | |
45 uint8_t sensor_ppo2_cbar[3]; | |
46 uint8_t temp1; | |
47 uint16_t battery_voltage_mV; | |
48 uint16_t checksum; | |
49 } SIrLink; | |
50 | |
634 | 51 typedef enum |
52 { | |
53 sensorOK = 0, | |
54 sensorSuspect, | |
55 SensorOutOfBounds | |
56 } sensorTrustState_t; | |
57 | |
58 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
59 #define HUD_BABBLING_IDIOT (30u) /* 30 Bytes received without break */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
60 #define HUD_RX_FRAME_LENGTH (15u) /* Length of a HUD data frame */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
61 #define HUD_RX_FRAME_BREAK_MS (100u) /* Time used to detect a gap between two byte receptions => frame start */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
62 #define HUD_RX_START_DELAY_MS (500u) /* Delay for start of RX function to avoid start of reception while a transmission is ongoing. */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
63 /* Based on an assumed cycle time by the sensor of 1 second. Started at time of last RX */ |
38 | 64 |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
65 #define BOTTLE_SENSOR_TIMEOUT (6000u) /* signal pressure budget as not received after 10 minutes (6000 * 100ms) */ |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
66 |
634 | 67 #define MAX_SENSOR_COMPARE_DEVIATION (0.15f) /* max deviation between two sensors allowed before their results are rated as suspect */ |
68 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
69 /* Private variables ---------------------------------------------------------*/ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
70 static SIrLink receiveHUD[2]; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
71 static uint8_t boolHUDdata = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
72 static uint8_t data_old__lost_connection_to_HUD = 1; |
38 | 73 |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
74 static uint8_t receiveHUDraw[16]; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
75 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
76 static uint8_t StartListeningToUART_HUD = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
77 static uint16_t HUDTimeoutCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
78 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
79 static __IO ITStatus UartReadyHUD = RESET; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
80 static uint32_t LastReceivedTick_HUD = 0; |
38 | 81 |
82 /* Private variables with external access via get_xxx() function -------------*/ | |
83 | |
84 /* Private function prototypes -----------------------------------------------*/ | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
85 static void tCCR_fallbackToFixedSetpoint(void); |
38 | 86 |
87 #ifndef USART_IR_HUD | |
88 | |
89 void tCCR_init(void) | |
90 { | |
91 } | |
92 void tCCR_control(void) | |
93 { | |
94 } | |
95 void tCCR_test(void) | |
96 { | |
97 } | |
98 void tCCR_restart(void) | |
99 { | |
100 } | |
101 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
102 { | |
103 } | |
104 float get_sensorVoltage_mV(uint8_t sensor_id) | |
105 { | |
106 } | |
107 float get_HUD_battery_voltage_V(void) | |
108 { | |
109 } | |
110 void tCCR_tick(void) | |
111 { | |
112 } | |
113 | |
114 #else | |
115 /* Exported functions --------------------------------------------------------*/ | |
116 | |
117 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
118 { | |
119 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
120 return 0; | |
121 | |
122 return (float)(receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id]) / 100.0f; | |
123 } | |
124 | |
125 float get_sensorVoltage_mV(uint8_t sensor_id) | |
126 { | |
127 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
128 return 0; | |
129 | |
130 return (float)(receiveHUD[boolHUDdata].sensor_voltage_100uV[sensor_id]) / 10.0f; | |
131 } | |
132 | |
133 float get_HUD_battery_voltage_V(void) | |
134 { | |
135 if(data_old__lost_connection_to_HUD) | |
136 return 0; | |
137 | |
138 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f; | |
139 } | |
140 | |
141 | |
563 | 142 void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3) |
38 | 143 { |
144 uint8_t sensorNotActiveBinary; | |
145 uint8_t sensorActive[3]; | |
634 | 146 sensorTrustState_t sensorState[3]; |
147 uint8_t index; | |
148 | |
38 | 149 |
150 // test1: user deactivation | |
151 sensorNotActiveBinary = stateUsed->diveSettings.ppo2sensors_deactivated; | |
152 | |
153 for(int i=0;i<3;i++) | |
154 sensorActive[i] = 1; | |
155 | |
156 if(sensorNotActiveBinary) | |
157 { | |
158 if(sensorNotActiveBinary & 1) | |
159 sensorActive[0] = 0; | |
160 | |
161 if(sensorNotActiveBinary & 2) | |
162 sensorActive[1] = 0; | |
163 | |
164 if(sensorNotActiveBinary & 4) | |
165 sensorActive[2] = 0; | |
166 } | |
167 | |
168 // test2: mV of remaining sensors | |
169 for(int i=0;i<3;i++) | |
170 { | |
634 | 171 sensorState[i] = sensorOK; |
172 | |
38 | 173 if(sensorActive[i]) |
174 { | |
563 | 175 if( (stateUsed->lifeData.sensorVoltage_mV[i] < 8) || |
176 (stateUsed->lifeData.sensorVoltage_mV[i] > 250)) | |
38 | 177 { |
178 sensorActive[i] = 0; | |
179 switch(i) | |
180 { | |
181 case 0: | |
182 sensorNotActiveBinary |= 1; | |
183 break; | |
184 case 1: | |
185 sensorNotActiveBinary |= 2; | |
186 break; | |
187 case 2: | |
188 sensorNotActiveBinary |= 4; | |
189 break; | |
190 } | |
191 } | |
192 } | |
193 } | |
194 | |
195 *outOfBouds1 = 0; | |
196 *outOfBouds2 = 0; | |
197 *outOfBouds3 = 0; | |
198 | |
199 /* with two, one or no sensor, there is nothing to compare anymore | |
200 */ | |
201 if(sensorNotActiveBinary) | |
202 { | |
203 // set outOfBounds for both tests | |
204 if(!sensorActive[0]) | |
205 *outOfBouds1 = 1; | |
206 | |
207 if(!sensorActive[1]) | |
208 *outOfBouds2 = 1; | |
209 | |
210 if(!sensorActive[2]) | |
211 *outOfBouds3 = 1; | |
212 } | |
213 else | |
214 { | |
634 | 215 /* Check two or more of Three */ |
216 /* compare every sensor with each other. If there is only one mismatch the value might be OK. In case both comparisons fail the sensor is out of bounds */ | |
217 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[1]) > MAX_SENSOR_COMPARE_DEVIATION) | |
38 | 218 { |
634 | 219 sensorState[0]++; |
220 sensorState[1]++; | |
38 | 221 } |
634 | 222 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) |
38 | 223 { |
634 | 224 sensorState[0]++; |
225 sensorState[2]++; | |
226 } | |
227 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[1] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) | |
228 { | |
229 sensorState[1]++; | |
230 sensorState[2]++; | |
38 | 231 } |
634 | 232 for(index = 0; index < 3; index++) |
38 | 233 { |
634 | 234 if(sensorState[index] == SensorOutOfBounds) |
235 { | |
236 switch(index) | |
237 { | |
238 case 0: | |
239 *outOfBouds1 = 1; | |
240 break; | |
241 case 1: | |
242 *outOfBouds2 = 1; | |
243 break; | |
244 case 2: | |
245 *outOfBouds3 = 1; | |
246 break; | |
247 default: | |
248 break; | |
249 } | |
250 } | |
38 | 251 } |
252 } | |
253 } | |
254 | |
255 | |
256 uint8_t get_ppO2SensorWeightedResult_cbar(void) | |
257 { | |
634 | 258 static uint8_t lastValidValue = 0; |
38 | 259 int8_t sensorOutOfBound[3]; |
260 uint16_t result = 0; | |
261 uint8_t count = 0; | |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
262 uint8_t retVal = 0; |
38 | 263 |
563 | 264 test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]); |
38 | 265 |
266 for(int i=0;i<3;i++) | |
267 { | |
268 if(!sensorOutOfBound[i]) | |
269 { | |
563 | 270 result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0; /* convert centibar used by HUB */ |
38 | 271 count++; |
272 } | |
273 } | |
634 | 274 if(count == 0) /* all sensors out of bounds! => return last valid value as workaround till diver takes action */ |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
275 { |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
276 set_warning_fallback(); |
634 | 277 retVal = lastValidValue; |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
278 } |
38 | 279 else |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
280 { |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
281 retVal = (uint8_t)(result / count); |
634 | 282 lastValidValue = retVal; |
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
283 } |
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
284 return retVal; |
38 | 285 } |
286 | |
287 | |
288 void tCCR_init(void) | |
289 { | |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
290 uint8_t loop; |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
291 |
38 | 292 StartListeningToUART_HUD = 1; |
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
293 |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
294 SDiveState* pDiveData = stateRealGetPointerWrite(); |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
295 for(loop=0;loop<(2*NUM_GASES+1);loop++) |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
296 { |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
297 pDiveData->lifeData.bottle_bar_age_MilliSeconds[loop] = BOTTLE_SENSOR_TIMEOUT; |
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
298 } |
38 | 299 } |
300 | |
301 | |
302 /* after 3 seconds without update from HUD | |
303 * data is considered old | |
304 */ | |
305 void tCCR_tick(void) | |
306 { | |
563 | 307 if(settingsGetPointer()->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) |
308 { | |
309 if(HUDTimeoutCount < 3 * 10) | |
310 HUDTimeoutCount++; | |
311 else | |
312 { | |
313 data_old__lost_connection_to_HUD = 1; | |
314 if(HUDTimeoutCount < 20 * 10) | |
315 HUDTimeoutCount++; | |
316 else | |
317 tCCR_fallbackToFixedSetpoint(); | |
318 } | |
319 } | |
38 | 320 } |
321 | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
322 void tCCR_SetRXIndication(void) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
323 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
324 static uint8_t floatingRXCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
325 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
326 if((UartIR_HUD_Handle.RxXferSize == HUD_RX_FRAME_LENGTH) || (UartIR_HUD_Handle.RxXferSize == HUD_RX_FRAME_LENGTH - 1)) /* we expected a complete frame */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
327 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
328 UartReadyHUD = SET; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
329 LastReceivedTick_HUD = HAL_GetTick(); |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
330 floatingRXCount = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
331 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
332 else /* follow up of error handling */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
333 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
334 if(time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_FRAME_BREAK_MS) /* Reception took a while => frame start detected */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
335 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
336 HAL_UART_Receive_IT(&UartIR_HUD_Handle, &receiveHUDraw[1], 14); /* We have already the first byte => get the missing 14 */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
337 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
338 else |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
339 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
340 if(floatingRXCount++ < HUD_BABBLING_IDIOT) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
341 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
342 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); /* Start polling of incoming bytes */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
343 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
344 else /* Significant amount of data comming in without break => disable input */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
345 { /* by not reactivation HUD RX, no recovery fromthis state */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
346 stateUsedWrite->diveSettings.ppo2sensors_deactivated = 0x07; /* Display deactivation */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
347 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
348 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
349 } |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
350 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
351 } |
38 | 352 |
353 void tCCR_restart(void) | |
354 { | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
355 HAL_UART_AbortReceive_IT(&UartIR_HUD_Handle); /* Called by the error handler. RX will be restarted by control function */ |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
356 StartListeningToUART_HUD = 1; |
38 | 357 } |
358 | |
359 | |
360 void tCCR_control(void) | |
361 { | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
362 uint16_t checksum = 0; |
457 | 363 #ifdef ENABLE_BOTTLE_SENSOR |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
364 SDiveState *pLivedata = stateRealGetPointerWrite(); |
457 | 365 #endif |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
366 |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
367 if((UartReadyHUD == RESET) && StartListeningToUART_HUD && (time_elapsed_ms(LastReceivedTick_HUD, HAL_GetTick()) > HUD_RX_START_DELAY_MS)) |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
368 { |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
369 StartListeningToUART_HUD = 0; |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
370 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, HUD_RX_FRAME_LENGTH); |
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
371 } |
38 | 372 |
373 if(UartReadyHUD == SET) | |
374 { | |
375 UartReadyHUD = RESET; | |
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
376 StartListeningToUART_HUD = 1; |
38 | 377 |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
378 /* check if received package is valid */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
379 for(int i=0;i<13;i++) |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
380 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
381 checksum += receiveHUDraw[i]; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
382 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
383 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
384 if(checksum == receiveHUD[!boolHUDdata].checksum) |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
385 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
386 #ifdef ENABLE_BOTTLE_SENSOR |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
387 if(receiveHUDraw[0] == 0xA5) /* code for pressure sensor */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
388 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
389 pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10]; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
390 pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
391 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
392 else |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
393 #endif |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
394 /* handle O2 sensor data */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
395 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
396 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
397 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
398 } |
38 | 399 |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
400 boolHUDdata = !boolHUDdata; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
401 HUDTimeoutCount = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
402 data_old__lost_connection_to_HUD = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
403 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
404 else |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
405 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
406 if(data_old__lost_connection_to_HUD) /* we lost connection, maybe due to RX shift => start single byte read to resynchronize */ |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
407 { |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
408 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
409 StartListeningToUART_HUD = 0; |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
410 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
411 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
412 memset(receiveHUDraw,0,sizeof(receiveHUDraw)); |
38 | 413 } |
414 } | |
415 | |
416 #endif | |
417 /* Private functions ---------------------------------------------------------*/ | |
418 | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
419 static void tCCR_fallbackToFixedSetpoint(void) |
38 | 420 { |
421 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.diveMode == DIVEMODE_CCR) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption)) | |
422 { | |
423 uint8_t setpointCbar, actualGasID; | |
424 | |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
425 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar; |
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
426 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint; |
38 | 427 |
272
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
428 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings; |
74a8296a2318
cleanup: simplify stateUsed usage
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
429 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); |
38 | 430 |
431 set_warning_fallback(); | |
432 } | |
433 } |