Mercurial > public > ostc4
annotate Discovery/Src/tCCR.c @ 1046:1d7c7a36df15 GasConsumption
Bugfix OSTC5 BT and enabling fast mode:
The OSTC5 BT was operating at default speed of 115200. To enable the faster communication some init steps have been added to set speed to 460800. Having the UART enabled while the module was shut down caused problems during initialisation. To avoid these the BT UART is now initialized after the the module is powered on and deinitialized while the module is switched off.
| author | Ideenmodellierer |
|---|---|
| date | Fri, 14 Nov 2025 18:54:20 +0100 |
| parents | 8c0134a287da |
| children |
| 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" |
|
1014
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
37 #include "logbook.h" |
| 634 | 38 #include <math.h> |
| 38 | 39 |
| 40 /* Private types -------------------------------------------------------------*/ | |
| 41 typedef struct | |
| 42 { | |
| 43 uint8_t hud_firmwareVersion; | |
| 44 bit8_Type status_byte; | |
| 45 uint16_t sensor_voltage_100uV[3]; | |
| 46 uint8_t sensor_ppo2_cbar[3]; | |
| 47 uint8_t temp1; | |
| 48 uint16_t battery_voltage_mV; | |
| 49 uint16_t checksum; | |
| 50 } SIrLink; | |
| 51 | |
| 634 | 52 typedef enum |
| 53 { | |
| 54 sensorOK = 0, | |
| 55 sensorSuspect, | |
| 56 SensorOutOfBounds | |
| 57 } sensorTrustState_t; | |
| 58 | |
| 59 | |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
60 #define HUD_BABBLING_IDIOT (30u) /* 30 Bytes received without break */ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
61 #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
|
62 #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
|
63 #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
|
64 /* Based on an assumed cycle time by the sensor of 1 second. Started at time of last RX */ |
| 38 | 65 |
|
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
66 #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
|
67 |
| 634 | 68 #define MAX_SENSOR_COMPARE_DEVIATION (0.15f) /* max deviation between two sensors allowed before their results are rated as suspect */ |
| 662 | 69 #define MAX_SENSOR_VOLTAGE_MV (250u) /* max allowed voltage value for a sensor measurement */ |
| 70 | |
| 71 #ifdef ENABLE_ALTERNATIVE_SENSORTYP | |
| 72 #define MIN_SENSOR_VOLTAGE_MV (3u) /* min allowed voltage value for a sensor measurement (Inspiration, Submatix, Sentinel Typ) */ | |
| 73 #else | |
| 74 #define MIN_SENSOR_VOLTAGE_MV (8u) /* min allowed voltage value for a sensor measurement (legacy OSTC TYP) */ | |
| 75 #endif | |
| 634 | 76 |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
77 /* Private variables ---------------------------------------------------------*/ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
78 static SIrLink receiveHUD[2]; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
79 static uint8_t boolHUDdata = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
80 static uint8_t data_old__lost_connection_to_HUD = 1; |
| 38 | 81 |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
82 static uint8_t receiveHUDraw[16]; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
83 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
84 static uint8_t StartListeningToUART_HUD = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
85 static uint16_t HUDTimeoutCount = 0; |
| 655 | 86 static uint16_t ScrubberTimeoutCount = 0; |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
87 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
88 static __IO ITStatus UartReadyHUD = RESET; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
89 static uint32_t LastReceivedTick_HUD = 0; |
| 38 | 90 |
| 91 /* Private variables with external access via get_xxx() function -------------*/ | |
| 92 | |
| 93 /* Private function prototypes -----------------------------------------------*/ | |
| 635 | 94 static uint8_t tCCR_fallbackToFixedSetpoint(void); |
| 38 | 95 |
| 96 #ifndef USART_IR_HUD | |
| 97 | |
| 98 void tCCR_init(void) | |
| 99 { | |
| 100 } | |
| 101 void tCCR_control(void) | |
| 102 { | |
| 103 } | |
| 104 void tCCR_test(void) | |
| 105 { | |
| 106 } | |
| 107 void tCCR_restart(void) | |
| 108 { | |
| 109 } | |
| 110 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
| 111 { | |
| 112 } | |
| 113 float get_sensorVoltage_mV(uint8_t sensor_id) | |
| 114 { | |
| 115 } | |
| 116 float get_HUD_battery_voltage_V(void) | |
| 117 { | |
| 118 } | |
| 119 void tCCR_tick(void) | |
| 120 { | |
| 121 } | |
| 122 | |
| 123 #else | |
| 124 /* Exported functions --------------------------------------------------------*/ | |
| 125 | |
| 126 float get_ppO2Sensor_bar(uint8_t sensor_id) | |
| 127 { | |
| 128 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
| 129 return 0; | |
| 130 | |
| 131 return (float)(receiveHUD[boolHUDdata].sensor_ppo2_cbar[sensor_id]) / 100.0f; | |
| 132 } | |
| 133 | |
| 134 float get_sensorVoltage_mV(uint8_t sensor_id) | |
| 135 { | |
| 136 if((sensor_id > 2) || data_old__lost_connection_to_HUD) | |
| 137 return 0; | |
| 138 | |
| 139 return (float)(receiveHUD[boolHUDdata].sensor_voltage_100uV[sensor_id]) / 10.0f; | |
| 140 } | |
| 141 | |
| 142 float get_HUD_battery_voltage_V(void) | |
| 143 { | |
| 144 if(data_old__lost_connection_to_HUD) | |
| 145 return 0; | |
| 146 | |
| 147 return (float)(receiveHUD[boolHUDdata].battery_voltage_mV) / 1000.0f; | |
| 148 } | |
| 149 | |
| 150 | |
| 563 | 151 void test_O2_sensor_values_outOfBounds(int8_t * outOfBouds1, int8_t * outOfBouds2, int8_t * outOfBouds3) |
| 38 | 152 { |
| 153 uint8_t sensorNotActiveBinary; | |
| 154 uint8_t sensorActive[3]; | |
| 634 | 155 sensorTrustState_t sensorState[3]; |
| 156 uint8_t index; | |
| 157 | |
| 38 | 158 |
| 159 // test1: user deactivation | |
| 160 sensorNotActiveBinary = stateUsed->diveSettings.ppo2sensors_deactivated; | |
| 161 | |
| 162 for(int i=0;i<3;i++) | |
| 163 sensorActive[i] = 1; | |
| 164 | |
| 165 if(sensorNotActiveBinary) | |
| 166 { | |
| 167 if(sensorNotActiveBinary & 1) | |
| 168 sensorActive[0] = 0; | |
| 169 | |
| 170 if(sensorNotActiveBinary & 2) | |
| 171 sensorActive[1] = 0; | |
| 172 | |
| 173 if(sensorNotActiveBinary & 4) | |
| 174 sensorActive[2] = 0; | |
| 175 } | |
| 176 | |
| 177 // test2: mV of remaining sensors | |
| 744 | 178 for(index=0; index<3; index++) |
| 38 | 179 { |
| 744 | 180 sensorState[index] = sensorOK; |
| 634 | 181 |
| 744 | 182 if(sensorActive[index]) |
| 38 | 183 { |
| 797 | 184 if(((stateUsed->lifeData.extIf_sensor_map[index] == SENSOR_DIGO2M) && (((SSensorDataDiveO2*)(stateUsed->lifeData.extIf_sensor_data[index]))->status & DVO2_FATAL_ERROR)) |
| 185 || ((stateUsed->lifeData.extIf_sensor_map[index] != SENSOR_DIGO2M) | |
|
757
39ff186b6f98
Dev Bugfix: ignore analog out of bounds limits for DiveO2 sensor:
Ideenmodellierer
parents:
744
diff
changeset
|
186 && (((stateUsed->lifeData.sensorVoltage_mV[index] < MIN_SENSOR_VOLTAGE_MV) || (stateUsed->lifeData.sensorVoltage_mV[index] > MAX_SENSOR_VOLTAGE_MV))))) |
| 744 | 187 { |
| 188 sensorActive[index] = 0; | |
| 189 switch(index) | |
| 190 { | |
| 191 case 0: | |
| 192 sensorNotActiveBinary |= 1; | |
| 193 break; | |
| 194 case 1: | |
| 195 sensorNotActiveBinary |= 2; | |
| 196 break; | |
| 197 case 2: | |
| 198 sensorNotActiveBinary |= 4; | |
| 199 break; | |
| 200 } | |
| 201 } | |
| 38 | 202 } |
| 203 } | |
| 204 | |
| 205 *outOfBouds1 = 0; | |
| 206 *outOfBouds2 = 0; | |
| 207 *outOfBouds3 = 0; | |
| 208 | |
| 209 /* with two, one or no sensor, there is nothing to compare anymore | |
| 210 */ | |
| 211 if(sensorNotActiveBinary) | |
| 212 { | |
| 213 // set outOfBounds for both tests | |
| 214 if(!sensorActive[0]) | |
| 215 *outOfBouds1 = 1; | |
| 216 | |
| 217 if(!sensorActive[1]) | |
| 218 *outOfBouds2 = 1; | |
| 219 | |
| 220 if(!sensorActive[2]) | |
| 221 *outOfBouds3 = 1; | |
| 222 } | |
| 223 else | |
| 224 { | |
| 634 | 225 /* Check two or more of Three */ |
| 226 /* 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 */ | |
| 227 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[1]) > MAX_SENSOR_COMPARE_DEVIATION) | |
| 38 | 228 { |
| 634 | 229 sensorState[0]++; |
| 230 sensorState[1]++; | |
| 38 | 231 } |
| 634 | 232 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[0] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) |
| 38 | 233 { |
| 634 | 234 sensorState[0]++; |
| 235 sensorState[2]++; | |
| 236 } | |
| 237 if(fabsf(stateUsed->lifeData.ppO2Sensor_bar[1] - stateUsed->lifeData.ppO2Sensor_bar[2]) > MAX_SENSOR_COMPARE_DEVIATION) | |
| 238 { | |
| 239 sensorState[1]++; | |
| 240 sensorState[2]++; | |
| 38 | 241 } |
| 634 | 242 for(index = 0; index < 3; index++) |
| 38 | 243 { |
| 634 | 244 if(sensorState[index] == SensorOutOfBounds) |
| 245 { | |
| 246 switch(index) | |
| 247 { | |
| 248 case 0: | |
| 249 *outOfBouds1 = 1; | |
| 250 break; | |
| 251 case 1: | |
| 252 *outOfBouds2 = 1; | |
| 253 break; | |
| 254 case 2: | |
| 255 *outOfBouds3 = 1; | |
| 256 break; | |
| 257 default: | |
| 258 break; | |
| 259 } | |
| 260 } | |
| 38 | 261 } |
| 262 } | |
| 263 } | |
| 264 | |
| 635 | 265 /* this function is called out of the 100ms callback => to be considered for debouncing */ |
| 38 | 266 uint8_t get_ppO2SensorWeightedResult_cbar(void) |
| 267 { | |
| 634 | 268 static uint8_t lastValidValue = 0; |
| 38 | 269 int8_t sensorOutOfBound[3]; |
| 270 uint16_t result = 0; | |
| 271 uint8_t count = 0; | |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
272 uint8_t retVal = 0; |
| 38 | 273 |
| 563 | 274 test_O2_sensor_values_outOfBounds(&sensorOutOfBound[0], &sensorOutOfBound[1], &sensorOutOfBound[2]); |
| 38 | 275 |
| 276 for(int i=0;i<3;i++) | |
| 277 { | |
| 278 if(!sensorOutOfBound[i]) | |
| 279 { | |
| 563 | 280 result += stateUsed->lifeData.ppO2Sensor_bar[i] * 100.0; /* convert centibar used by HUB */ |
| 38 | 281 count++; |
| 282 } | |
| 283 } | |
| 634 | 284 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
|
285 { |
| 635 | 286 if(debounce_warning_fallback(100)) |
| 287 { | |
| 288 set_warning_fallback(); | |
| 289 retVal = tCCR_fallbackToFixedSetpoint(); /* this function only changes setpoint if option is enabled */ | |
| 290 } | |
| 291 if(retVal == 0) | |
| 292 { | |
| 293 retVal = lastValidValue; | |
| 294 } | |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
295 } |
| 38 | 296 else |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
297 { |
| 635 | 298 reset_debounce_warning_fallback(); |
| 299 retVal = (uint8_t)(result / count); | |
| 300 lastValidValue = retVal; | |
|
582
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
301 } |
|
64bf41faab83
Show Fallback if no valid sensor value is available:
Ideenmodellierer
parents:
563
diff
changeset
|
302 return retVal; |
| 38 | 303 } |
| 304 | |
| 305 | |
| 306 void tCCR_init(void) | |
| 307 { | |
|
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
308 uint8_t loop; |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
309 |
| 38 | 310 StartListeningToUART_HUD = 1; |
|
449
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
311 |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
312 SDiveState* pDiveData = stateRealGetPointerWrite(); |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
313 for(loop=0;loop<(2*NUM_GASES+1);loop++) |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
314 { |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
315 pDiveData->lifeData.bottle_bar_age_MilliSeconds[loop] = BOTTLE_SENSOR_TIMEOUT; |
|
91a939915bfa
Added initialization of bottle sensor data age counter
ideenmodellierer
parents:
446
diff
changeset
|
316 } |
| 38 | 317 } |
| 318 | |
| 319 | |
| 320 /* after 3 seconds without update from HUD | |
| 321 * data is considered old | |
| 322 */ | |
| 323 void tCCR_tick(void) | |
| 324 { | |
| 655 | 325 SSettings* pSettings = settingsGetPointer(); |
| 326 | |
| 327 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) | |
| 563 | 328 { |
| 329 if(HUDTimeoutCount < 3 * 10) | |
| 330 HUDTimeoutCount++; | |
| 331 else | |
| 332 { | |
| 333 data_old__lost_connection_to_HUD = 1; | |
| 334 if(HUDTimeoutCount < 20 * 10) | |
| 335 HUDTimeoutCount++; | |
| 336 else | |
| 337 tCCR_fallbackToFixedSetpoint(); | |
| 338 } | |
| 339 } | |
| 655 | 340 |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
341 // If we are in the simulator the counter is updated in `simulator.c` |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
342 if (!is_stateUsedSetToSim()) { |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
343 /* decrease scrubber timer only if we are not bailed out */ |
|
1014
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
344 if (isScrubberTimerRunning(stateUsed, pSettings)) { |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
345 ScrubberTimeoutCount++; |
|
1014
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
346 if (ScrubberTimeoutCount >= 600) { /* resolution is minutes */ |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
347 ScrubberTimeoutCount = 0; |
|
1014
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
348 |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
349 int16_t maxScrubberTime = INT16_MIN; |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
350 SScrubberData *longestScrubberData = NULL; |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
351 for (unsigned timerId = 0; timerId < 2; timerId++) { |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
352 if (pSettings->scrubberActiveId & (1 << timerId)) { |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
353 SScrubberData *scrubberData = &stateUsedWrite->scrubberDataDive[timerId]; |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
354 if (scrubberData->TimerCur > MIN_SCRUBBER_TIME) { |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
355 scrubberData->TimerCur--; |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
356 } |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
357 |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
358 if (scrubberData->TimerCur > maxScrubberTime) { |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
359 maxScrubberTime = scrubberData->TimerCur; |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
360 longestScrubberData = scrubberData; |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
361 } |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
362 |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
363 translateDate(stateUsed->lifeData.dateBinaryFormat, &scrubberData->lastDive); |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
364 } |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
365 } |
|
1014
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
366 |
|
8c0134a287da
Add a log data event to the scrubber timer at the start of the dive and every time the timer (in minutes)
heinrichsweikamp
parents:
998
diff
changeset
|
367 logScrubberState(longestScrubberData); |
|
980
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
368 } |
|
7149f372b0ba
Fix a couple of bugs in the scrubber timer:
heinrichsweikamp
parents:
924
diff
changeset
|
369 } |
| 655 | 370 } |
| 38 | 371 } |
| 372 | |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
373 void tCCR_SetRXIndication(void) |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
374 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
375 static uint8_t floatingRXCount = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
376 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
377 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
|
378 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
379 UartReadyHUD = SET; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
380 LastReceivedTick_HUD = HAL_GetTick(); |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
381 floatingRXCount = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
382 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
383 else /* follow up of error handling */ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
384 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
385 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
|
386 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
387 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
|
388 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
389 else |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
390 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
391 if(floatingRXCount++ < HUD_BABBLING_IDIOT) |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
392 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
393 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
|
394 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
395 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
|
396 { /* by not reactivation HUD RX, no recovery fromthis state */ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
397 stateUsedWrite->diveSettings.ppo2sensors_deactivated = 0x07; /* Display deactivation */ |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
398 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
399 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
400 } |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
401 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
402 } |
| 38 | 403 |
| 404 void tCCR_restart(void) | |
| 405 { | |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
406 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
|
407 StartListeningToUART_HUD = 1; |
| 38 | 408 } |
| 409 | |
| 410 | |
| 411 void tCCR_control(void) | |
| 412 { | |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
413 uint16_t checksum = 0; |
| 457 | 414 #ifdef ENABLE_BOTTLE_SENSOR |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
415 SDiveState *pLivedata = stateRealGetPointerWrite(); |
| 457 | 416 #endif |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
417 |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
418 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
|
419 { |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
420 StartListeningToUART_HUD = 0; |
|
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
421 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
|
422 } |
| 38 | 423 |
| 424 if(UartReadyHUD == SET) | |
| 425 { | |
| 426 UartReadyHUD = RESET; | |
|
322
31e471d60797
Added start of frame detection for HUD data
ideenmodellierer
parents:
272
diff
changeset
|
427 StartListeningToUART_HUD = 1; |
| 38 | 428 |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
429 /* check if received package is valid */ |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
430 for(int i=0;i<13;i++) |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
431 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
432 checksum += receiveHUDraw[i]; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
433 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
434 receiveHUD[!boolHUDdata].checksum = receiveHUDraw[13] + (256 * receiveHUDraw[14]); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
435 if(checksum == receiveHUD[!boolHUDdata].checksum) |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
436 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
437 #ifdef ENABLE_BOTTLE_SENSOR |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
438 if(receiveHUDraw[0] == 0xA5) /* code for pressure sensor */ |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
439 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
440 pLivedata->lifeData.bottle_bar[pLivedata->lifeData.actualGas.GasIdInSettings] = receiveHUDraw[10]; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
441 pLivedata->lifeData.bottle_bar_age_MilliSeconds[pLivedata->lifeData.actualGas.GasIdInSettings] = 0; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
442 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
443 else |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
444 #endif |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
445 /* handle O2 sensor data */ |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
446 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
447 memcpy(&receiveHUD[!boolHUDdata], receiveHUDraw, 11); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
448 receiveHUD[!boolHUDdata].battery_voltage_mV = receiveHUDraw[11] + (256 * receiveHUDraw[12]); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
449 } |
| 38 | 450 |
|
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
451 boolHUDdata = !boolHUDdata; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
452 HUDTimeoutCount = 0; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
453 data_old__lost_connection_to_HUD = 0; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
454 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
455 else |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
456 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
457 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
|
458 { |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
459 HAL_UART_Receive_IT(&UartIR_HUD_Handle, receiveHUDraw, 1); |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
460 StartListeningToUART_HUD = 0; |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
461 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
462 } |
|
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
322
diff
changeset
|
463 memset(receiveHUDraw,0,sizeof(receiveHUDraw)); |
| 38 | 464 } |
| 465 } | |
| 466 | |
| 467 #endif | |
| 468 /* Private functions ---------------------------------------------------------*/ | |
| 469 | |
| 635 | 470 static uint8_t tCCR_fallbackToFixedSetpoint(void) |
| 38 | 471 { |
| 635 | 472 uint8_t retVal = 0; |
| 662 | 473 uint8_t setpointCbar, actualGasID; |
| 38 | 474 |
| 662 | 475 if((stateUsed->mode == MODE_DIVE) && (stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) && (stateUsed->diveSettings.fallbackOption)) |
| 476 { | |
| 477 if(stateUsed->diveSettings.diveMode == DIVEMODE_CCR) | |
| 478 { | |
| 479 setpointCbar = stateUsed->diveSettings.setpoint[1].setpoint_cbar; | |
| 480 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_FixedSetpoint; | |
| 481 } | |
| 482 else | |
| 483 { | |
| 484 setpointCbar = stateUsed->lifeData.ppo2Simulated_bar * 100; | |
| 485 stateUsedWrite->diveSettings.CCR_Mode = CCRMODE_Simulation; | |
| 486 } | |
| 487 actualGasID = stateUsed->lifeData.actualGas.GasIdInSettings; | |
| 488 setActualGas_DM(&stateUsedWrite->lifeData,actualGasID,setpointCbar); | |
| 38 | 489 |
| 662 | 490 set_warning_fallback(); |
| 491 retVal = setpointCbar; | |
| 38 | 492 } |
| 635 | 493 return retVal; |
| 38 | 494 } |
