Mercurial > public > ostc4
annotate Discovery/Src/data_exchange_main.c @ 577:9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Values < 0.5mv will now be handled as ppo2 = 0Bar to avaid problems (e.g. by negativ values) in the decompression calculation. In the custom display sensors with low voltage are show using '-'
author | Ideenmodellierer |
---|---|
date | Sun, 29 Nov 2020 22:58:11 +0100 |
parents | 84a4e1200726 |
children | 830de438e0b0 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file data_exchange_main.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @date 13-Oct-2014 | |
6 * @version V0.0.3 | |
7 * @since 17-Feb-2016 | |
8 | |
9 * @brief Communication with the second CPU == RTE system | |
10 * | |
11 @verbatim | |
12 ============================================================================== | |
13 ##### Version Changes ##### | |
14 ============================================================================== | |
15 160217 V0.0.3 pStateUsed->decolistXXXXX.tickstamp = HAL_GetTick(); added | |
16 150627 V0.0.2 | |
17 | |
18 ============================================================================== | |
19 ##### How to use ##### | |
20 ============================================================================== | |
21 | |
22 ============================================================================== | |
23 ##### Button, Set Time, Clear Deco etc Request ##### | |
24 ============================================================================== | |
25 was updated (151207) for buttons and clear deco at the moment only | |
26 using requestNecessary and checking in DataEX_copy_to_LifeData() | |
27 Hence if there is no confirm from the smallCPU on the data after the request | |
28 the request will be send again. | |
29 | |
30 ============================================================================== | |
31 ##### Device Data ##### | |
32 ============================================================================== | |
33 | |
34 main CPU always sends the device data info that it has at the moment | |
35 | |
36 on start it is INT32_MIN, INT32_MAX and 0 | |
37 as initialized in data_central.c variable declaration | |
38 | |
39 second small CPU gets request to send its device data | |
40 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
41 on reception the data is merged with the data in externLogbookFlash, |
38 | 42 stored on the externLogbookFlash and from now on send to small CPU |
43 | |
44 ============================================================================== | |
45 ##### Magnet Reset ##### | |
46 ============================================================================== | |
47 | |
48 @endverbatim | |
49 ****************************************************************************** | |
50 * @attention | |
51 * | |
52 * <h2><center>© COPYRIGHT(c) 2014 heinrichs weikamp</center></h2> | |
53 * | |
54 ****************************************************************************** | |
55 */ | |
56 | |
57 /* Includes ------------------------------------------------------------------*/ | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
58 #include <stdlib.h> |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
59 #include <string.h> // for memcpy |
38 | 60 #include "stm32f4xx_hal.h" |
61 #include "stdio.h" | |
62 #include "ostc.h" | |
63 #include "settings.h" | |
64 #include "data_central.h" | |
65 #include "data_exchange_main.h" | |
66 #include "base.h" | |
67 #include "decom.h" | |
68 #include "calc_crush.h" /* for vpm_init */ | |
69 #include "simulation.h" | |
70 #include "tCCR.h" | |
71 #include "timer.h" | |
72 #include "buehlmann.h" | |
73 #include "externLogbookFlash.h" | |
74 | |
556
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
75 //#define TESTBENCH |
38 | 76 |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
77 /* Exported variables --------------------------------------------------------*/ |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
78 static uint8_t wasPowerOn = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
79 static confirmbit8_Type requestNecessary = { .uw = 0 }; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
80 static uint8_t wasUpdateNotPowerOn = 0; |
38 | 81 |
82 /* Private variables with external access ------------------------------------*/ | |
83 | |
84 /* Private variables ---------------------------------------------------------*/ | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
85 static uint8_t told_reset_logik_alles_ok = 0; |
559 | 86 static hw_Info_t hw_Info; |
38 | 87 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
88 static SDataReceiveFromMaster dataOut; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
89 static SDataExchangeSlaveToMaster dataIn; |
38 | 90 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
91 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
92 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
93 static uint32_t data_old__lost_connection_to_slave_counter_total = 0; |
38 | 94 |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
95 static uint8_t DeviceDataUpdated = 0; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
96 |
38 | 97 /* Private types -------------------------------------------------------------*/ |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
98 #define UNKNOWN_TIME_HOURS 1 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
99 #define UNKNOWN_TIME_MINUTES 0 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
100 #define UNKNOWN_TIME_SECOND 0 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
101 #define UNKNOWN_DATE_DAY 1 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
102 #define UNKNOWN_DATE_MONTH 1 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
103 #define UNKNOWN_DATE_YEAR 16 |
38 | 104 |
577
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
105 #define IGNORE_O2_VOLTAGE_LEVEL_MV (0.5f) |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
106 |
38 | 107 /* Private function prototypes -----------------------------------------------*/ |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
108 static uint8_t DataEX_check_header_and_footer_ok(void); |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
109 static uint8_t DataEX_check_header_and_footer_shifted(void); |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
110 static uint8_t DataEX_check_header_and_footer_devicedata(void); |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
111 static void DataEX_check_DeviceData(void); |
38 | 112 |
113 /* Exported functions --------------------------------------------------------*/ | |
114 uint8_t DataEX_was_power_on(void) | |
115 { | |
116 return wasPowerOn; | |
117 } | |
118 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
119 static uint8_t count_DataEX_Error_Handler = 0; |
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
120 static uint8_t last_error_DataEX_Error_Handler = 0; |
38 | 121 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
122 static void DataEX_Error_Handler(uint8_t answer) |
38 | 123 { |
124 count_DataEX_Error_Handler++; | |
125 last_error_DataEX_Error_Handler = answer; | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
126 |
156
1fbdb45db701
Removed special indicator for DMA transfer error
Ideenmodellierer
parents:
154
diff
changeset
|
127 /* A wrong footer indicates a communication interrupt. State machine is waiting for new data which is not received because no new transmission is triggered */ |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
128 /* ==> Abort data exchange to enable a new RX / TX cycle */ |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
129 if(answer == HAL_BUSY) |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
130 { |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
131 HAL_SPI_Abort_IT(&cpu2DmaSpi); |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
132 } |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
133 |
38 | 134 return; |
135 } | |
136 | |
137 | |
138 uint32_t DataEX_lost_connection_count(void) | |
139 { | |
140 return data_old__lost_connection_to_slave_counter_total; | |
141 } | |
142 | |
143 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
144 SDataReceiveFromMaster *dataOutGetPointer(void) |
38 | 145 { |
146 return &dataOut; | |
147 } | |
148 | |
149 void DataEX_init(void) | |
150 { | |
151 SDiveState * pStateReal = stateRealGetPointerWrite(); | |
99 | 152 pStateReal->data_old__lost_connection_to_slave = 0; //initial value |
38 | 153 data_old__lost_connection_to_slave_counter_temp = 0; |
154 data_old__lost_connection_to_slave_counter_total = 0; | |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
155 DeviceDataUpdated = 0; |
38 | 156 |
157 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); | |
158 | |
159 dataOut.header.checkCode[0] = 0xBB; | |
208 | 160 dataOut.header.checkCode[1] = SPI_RX_STATE_OK; |
161 dataOut.header.checkCode[2] = SPI_RX_STATE_OK; | |
38 | 162 dataOut.header.checkCode[3] = 0xBB; |
163 | |
164 dataOut.footer.checkCode[0] = 0xF4; | |
165 dataOut.footer.checkCode[1] = 0xF3; | |
166 dataOut.footer.checkCode[2] = 0xF2; | |
167 dataOut.footer.checkCode[3] = 0xF1; | |
168 } | |
169 | |
170 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
171 static void DataEx_call_helper_requests(void) |
38 | 172 { |
173 static uint8_t setDateWasSend = 0; | |
174 static uint8_t setTimeWasSend = 0; | |
175 static uint8_t calibrateCompassWasSend = 0; | |
176 static uint8_t setButtonSensitivityWasSend = 0; | |
177 static uint8_t clearDecoWasSend = 0; | |
178 static uint8_t getDeviceDataWasSend = 0; | |
179 static uint8_t setAccidentFlagWasSend = 0; | |
180 static uint8_t setEndDiveWasSend = 0; | |
181 | |
182 if(getDeviceDataWasSend) | |
183 { | |
184 dataOut.getDeviceDataNow = 0; | |
185 requestNecessary.ub.devicedata = 1; | |
186 } | |
187 getDeviceDataWasSend = 0; | |
188 if(dataOut.getDeviceDataNow) | |
189 { | |
190 getDeviceDataWasSend = 1; | |
191 } | |
192 | |
193 if(setEndDiveWasSend) | |
194 { | |
195 dataOut.setEndDive = 0; | |
196 //requestNecessary.ub.XXX = 1; not implemented and no space here | |
197 } | |
198 setEndDiveWasSend = 0; | |
199 if(dataOut.setEndDive) | |
200 { | |
201 setEndDiveWasSend = 1; | |
202 } | |
203 | |
204 if(setAccidentFlagWasSend) | |
205 { | |
206 dataOut.setAccidentFlag = 0; | |
207 requestNecessary.ub.accident = 1; | |
208 } | |
209 setAccidentFlagWasSend = 0; | |
210 if(dataOut.setAccidentFlag) | |
211 { | |
212 setAccidentFlagWasSend = 1; | |
213 } | |
214 | |
215 if(setDateWasSend) | |
216 { | |
217 dataOut.setDateNow = 0; | |
218 requestNecessary.ub.date = 1; | |
219 } | |
220 setDateWasSend = 0; | |
221 if(dataOut.setDateNow) | |
222 { | |
223 setDateWasSend = 1; | |
224 } | |
225 | |
226 if(setTimeWasSend) | |
227 { | |
228 dataOut.setTimeNow = 0; | |
229 requestNecessary.ub.time = 1; | |
230 } | |
231 setTimeWasSend = 0; | |
232 if(dataOut.setTimeNow) | |
233 { | |
234 setTimeWasSend = 1; | |
235 } | |
236 | |
237 if(calibrateCompassWasSend) | |
238 { | |
239 dataOut.calibrateCompassNow = 0; | |
240 requestNecessary.ub.compass = 1; | |
241 } | |
242 calibrateCompassWasSend = 0; | |
243 if(dataOut.calibrateCompassNow) | |
244 { | |
245 calibrateCompassWasSend = 1; | |
246 } | |
247 | |
248 if(clearDecoWasSend) | |
249 { | |
250 dataOut.clearDecoNow = 0; | |
251 requestNecessary.ub.clearDeco = 1; | |
252 } | |
253 if(dataOut.clearDecoNow) | |
254 { | |
255 clearDecoWasSend = 1; | |
256 } | |
257 | |
258 if(setButtonSensitivityWasSend) | |
259 { | |
260 dataOut.setButtonSensitivityNow = 0; | |
261 requestNecessary.ub.button = 1; | |
262 } | |
263 setButtonSensitivityWasSend = 0; | |
264 if(dataOut.setButtonSensitivityNow) | |
265 { | |
266 setButtonSensitivityWasSend = 1; | |
267 } | |
268 } | |
269 | |
270 | |
271 uint8_t DataEX_call(void) | |
272 { | |
208 | 273 static uint32_t RTEOfflineCnt = 0; |
274 static uint8_t SusppressCom = 0; | |
275 | |
38 | 276 uint8_t SPI_DMA_answer = 0; |
141 | 277 |
208 | 278 if(SusppressCom) |
38 | 279 { |
208 | 280 SusppressCom--; |
38 | 281 } |
149 | 282 else |
283 { | |
208 | 284 if(data_old__lost_connection_to_slave_counter_temp >= 2) /* error reaction is triggered whenever communication could not be reestablishen within two cycles */ |
285 { | |
286 data_old__lost_connection_to_slave_counter_temp = 0; | |
287 if(DataEX_check_header_and_footer_shifted()) | |
288 { | |
289 if(RTEOfflineCnt > 1) /* RTE restarted communication after a longer silent time => restart error handling to recover */ | |
290 { | |
291 data_old__lost_connection_to_slave_counter_retry = 0; | |
292 RTEOfflineCnt = 0; | |
293 } | |
38 | 294 |
208 | 295 /* We received shifted data. Step one. Reset DMA to see if the problem is located at main */ |
296 if (data_old__lost_connection_to_slave_counter_retry == 0) | |
297 { | |
298 HAL_SPI_Abort_IT(&cpu2DmaSpi); | |
299 } | |
300 /* reset of own DMA does not work ==> request reset of slave dma by indicating shifted receiption */ | |
301 if (data_old__lost_connection_to_slave_counter_retry == 1) | |
302 { | |
303 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_SHIFTED; | |
304 } | |
305 | |
306 /* stop communication with RTE to trigger RTE timeout reaction */ | |
307 if (data_old__lost_connection_to_slave_counter_retry == 2) | |
308 { | |
309 SusppressCom = 3; | |
310 } | |
38 | 311 |
208 | 312 data_old__lost_connection_to_slave_counter_retry++; |
313 } | |
314 else | |
315 { | |
316 RTEOfflineCnt++; /* based on footer status the RTE does not seem to provide data in time */ | |
317 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OFFLINE; | |
318 } | |
319 } | |
320 #if USE_OLD_SYNC_METHOD | |
321 /* one cycle with NotChipSelect true to clear slave spi buffer */ | |
322 else | |
323 { | |
324 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
325 } | |
326 #endif | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
327 |
208 | 328 DataEx_call_helper_requests(); |
329 | |
330 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ | |
331 | |
332 if(SusppressCom == 0) | |
333 { | |
334 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
335 | |
336 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE); | |
337 if(SPI_DMA_answer != HAL_OK) | |
338 { | |
339 DataEX_Error_Handler(SPI_DMA_answer); | |
340 } | |
341 } | |
342 } | |
104 | 343 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
38 | 344 //HAL_Delay(3); |
345 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ | |
346 | |
347 return 1; | |
348 } | |
349 | |
82 | 350 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
351 static uint32_t SPI_CALLBACKS; |
82 | 352 uint32_t get_num_SPI_CALLBACKS(void){ |
353 return SPI_CALLBACKS; | |
354 } | |
355 | |
356 SDataExchangeSlaveToMaster* get_dataInPointer(void){ | |
357 return &dataIn; | |
358 } | |
359 | |
360 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) | |
361 { | |
362 if(hspi == &cpu2DmaSpi) | |
363 { | |
154 | 364 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
82 | 365 SPI_CALLBACKS+=1; |
366 } | |
367 } | |
368 | |
369 | |
38 | 370 void DateEx_copy_to_dataOut(void) |
371 { | |
372 const SDiveState * pStateReal = stateRealGetPointer(); | |
373 SSettings *settings = settingsGetPointer(); | |
374 | |
375 if(get_globalState() == StStop) | |
376 dataOut.mode = MODE_SHUTDOWN; | |
377 else | |
378 dataOut.mode = 0; | |
379 | |
380 dataOut.diveModeInfo = pStateReal->diveSettings.diveMode; // hw 170215 | |
381 | |
382 memcpy(&dataOut.data.DeviceData, stateDeviceGetPointer(), sizeof(SDevice)); | |
383 | |
384 dataOut.data.VPMconservatism = pStateReal->diveSettings.vpm_conservatism; | |
385 dataOut.data.actualGas = pStateReal->lifeData.actualGas; | |
386 dataOut.data.ambient_pressure_mbar_ceiling = (pStateReal->decolistBuehlmann.output_ceiling_meter * 100) + (pStateReal->lifeData.pressure_surface_bar * 1000); | |
387 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook; | |
388 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth; | |
389 | |
390 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar; | |
391 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad; | |
392 | |
393 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15)))) | |
394 { | |
395 dataOut.revisionHardware = 0x00; | |
396 dataOut.revisionCRCx0x7A = 0x7A; | |
397 } | |
398 else | |
399 if(hardwareDataGetPointer()->primarySerial < 0xFFFF) | |
400 { | |
401 dataOut.revisionHardware = hardwareDataGetPointer()->revision8bit; | |
402 dataOut.revisionCRCx0x7A = hardwareDataGetPointer()->revision8bit ^ 0x7A; | |
403 } | |
404 else | |
405 { | |
406 dataOut.revisionHardware = 0xFF; | |
407 dataOut.revisionCRCx0x7A = 0xFF; | |
408 } | |
409 | |
410 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok) | |
411 { | |
412 MX_tell_reset_logik_alles_ok(); | |
413 told_reset_logik_alles_ok = 1; | |
414 } | |
415 | |
416 if(DataEX_check_header_and_footer_ok() && (dataIn.power_on_reset == 1)) | |
417 { | |
418 if(!wasUpdateNotPowerOn) | |
419 wasPowerOn = 1; | |
420 | |
421 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); | |
422 setButtonResponsiveness(settings->ButtonResponsiveness); | |
423 } | |
424 } | |
425 | |
426 | |
427 void DataEX_copy_to_deco(void) | |
428 { | |
429 if(decoLock == DECO_CALC_running) | |
430 return; | |
431 | |
432 if(decoLock == DECO_CALC_init_as_is_start_of_dive) | |
433 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
434 vpm_init(&stateUsedWrite->vpm, stateUsedWrite->diveSettings.vpm_conservatism, 0, 0); |
38 | 435 buehlmann_init(); |
436 timer_init(); | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
437 resetEvents(stateUsedWrite); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
438 stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; |
38 | 439 } |
440 | |
441 if(decoLock == DECO_CALC_FINSHED_Buehlmann) | |
442 { | |
443 | |
444 } | |
445 switch(decoLock) | |
446 { | |
447 | |
448 //Deco_calculation finished | |
449 case DECO_CALC_FINSHED_vpm: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
450 memcpy(&stateUsedWrite->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
451 stateUsedWrite->decolistVPM.tickstamp = HAL_GetTick(); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
452 stateUsedWrite->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached; |
38 | 453 for(int i = 0; i< 16; i++) |
454 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
455 stateUsedWrite->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
456 stateUsedWrite->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
457 stateUsedWrite->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
458 stateUsedWrite->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
459 stateUsedWrite->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
460 stateUsedWrite->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
461 stateUsedWrite->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i]; |
38 | 462 } |
463 break; | |
464 case DECO_CALC_FINSHED_Buehlmann: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
465 memcpy(&stateUsedWrite->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
466 stateUsedWrite->decolistBuehlmann.tickstamp = HAL_GetTick(); |
38 | 467 //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
468 stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = stateDeco.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero; |
38 | 469 break; |
470 case DECO_CALC_FINSHED_FutureBuehlmann: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
471 memcpy(&stateUsedWrite->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
472 stateUsedWrite->decolistFutureBuehlmann.tickstamp = HAL_GetTick(); |
38 | 473 break; |
474 case DECO_CALC_FINSHED_Futurevpm: | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
475 memcpy(&stateUsedWrite->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
476 stateUsedWrite->decolistFutureVPM.tickstamp = HAL_GetTick(); |
38 | 477 break; |
478 } | |
479 | |
480 //Copy Inputdata from stateReal to stateDeco | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
481 memcpy(&stateDeco.lifeData,&stateUsedWrite->lifeData,sizeof(SLifeData)); |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
482 memcpy(&stateDeco.diveSettings,&stateUsedWrite->diveSettings,sizeof(SDiveSettings)); |
38 | 483 |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
484 stateDeco.vpm.deco_zone_reached = stateUsedWrite->vpm.deco_zone_reached; |
38 | 485 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm)); |
486 for(int i = 0; i< 16; i++) | |
487 { | |
288
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
488 stateDeco.vpm.max_crushing_pressure_he[i] = stateUsedWrite->vpm.max_crushing_pressure_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
489 stateDeco.vpm.max_crushing_pressure_n2[i] = stateUsedWrite->vpm.max_crushing_pressure_n2[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
490 stateDeco.vpm.adjusted_critical_radius_he[i] = stateUsedWrite->vpm.adjusted_critical_radius_he[i]; |
ba229a012ac7
cleanup: no useless checks for simulator state
Jan Mulder <jlmulder@xs4all.nl>
parents:
278
diff
changeset
|
491 stateDeco.vpm.adjusted_critical_radius_n2[i] = stateUsedWrite->vpm.adjusted_critical_radius_n2[i]; |
38 | 492 } |
493 decoLock = DECO_CALC_ready; | |
494 } | |
495 | |
496 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
497 static void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) |
38 | 498 { |
499 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
500 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
501 lineWrite->value_int32 = lineRead->value_int32; | |
502 } | |
503 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
504 static void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg) |
38 | 505 { |
506 inStimestructure.TimeFormat = RTC_HOURFORMAT_24; | |
507 | |
508 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \ | |
509 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \ | |
510 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \ | |
511 (((uint32_t)inStimestructure.TimeFormat) << 16U)); | |
512 } | |
513 | |
514 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
515 static void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg) |
38 | 516 { |
517 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \ | |
518 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \ | |
519 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ | |
520 ((uint32_t)inSdatestructure.WeekDay << 13U)); | |
521 } | |
522 | |
523 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
524 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) |
38 | 525 { |
526 RTC_DateTypeDef sdatestructure; | |
527 RTC_TimeTypeDef stimestructure; | |
528 | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
529 stimestructure.Hours = UNKNOWN_TIME_HOURS; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
530 stimestructure.Minutes = UNKNOWN_TIME_MINUTES; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
531 stimestructure.Seconds = UNKNOWN_TIME_SECOND; |
38 | 532 |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
533 sdatestructure.Date = UNKNOWN_DATE_DAY; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
534 sdatestructure.Month = UNKNOWN_DATE_MONTH; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
535 sdatestructure.Year = UNKNOWN_DATE_YEAR; |
38 | 536 setWeekday(&sdatestructure); |
537 | |
538 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); | |
539 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); | |
540 } | |
541 | |
542 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
543 static uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) |
38 | 544 { |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
545 uint8_t retval = 0; |
38 | 546 RTC_DateTypeDef sdatestructure; |
547 RTC_TimeTypeDef stimestructure; | |
548 | |
549 // from lineWrite to structure | |
550 translateDate(lineWrite->date_rtc_dr, &sdatestructure); | |
551 translateTime(lineWrite->time_rtc_tr, &stimestructure); | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
552 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
553 /* Check if date is out of range */ |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
554 if(!( (sdatestructure.Year >= 15) |
38 | 555 && (sdatestructure.Year <= 30) |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
556 && (sdatestructure.Month <= 12))) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
557 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
558 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
559 retval = 1; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
560 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
561 return retval; |
38 | 562 } |
563 | |
564 | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
565 static uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to, uint8_t defaulttofrom) |
38 | 566 { |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
567 uint8_t retval = 0; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
568 RTC_DateTypeDef sdatestructure; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
569 |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
570 /* Is value out of valid range? */ |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
571 if(!(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to)) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
572 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
573 if(defaulttofrom) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
574 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
575 lineWrite->value_int32 = from; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
576 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
577 else |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
578 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
579 lineWrite->value_int32 = to; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
580 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
581 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
582 } |
38 | 583 |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
584 /* This is just a repair function to restore metric if a corruption occurred in an older fw version */ |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
585 if(((lineWrite->value_int32 == to) && defaulttofrom ) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
586 || ((lineWrite->value_int32 == from) && !defaulttofrom )) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
587 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
588 translateDate(lineWrite->date_rtc_dr, &sdatestructure); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
589 if(sdatestructure.Year == UNKNOWN_DATE_YEAR) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
590 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
591 if(defaulttofrom) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
592 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
593 lineWrite->value_int32 = from; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
594 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
595 else |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
596 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
597 lineWrite->value_int32 = to; |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
598 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
599 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
600 } |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
601 return retval; |
38 | 602 } |
603 | |
604 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
605 static void DataEX_check_DeviceData(void) |
38 | 606 { |
607 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
608 | |
609 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles); | |
610 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles); | |
611 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->depthMaximum); | |
612 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->diveCycles); | |
613 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation); | |
614 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum); | |
615 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum); | |
616 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum); | |
617 | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
618 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
619 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
620 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
621 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
622 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
623 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100,1); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
624 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100,0); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
625 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, 2*1000, 6*1000,0); |
38 | 626 } |
627 | |
628 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
629 static void DataEX_merge_DeviceData_and_store(void) |
38 | 630 { |
631 uint16_t dataLengthRead; | |
632 SDevice DeviceDataFlash; | |
633 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
634 | |
635 dataLengthRead = ext_flash_read_devicedata((uint8_t *)&DeviceDataFlash,sizeof(SDevice)); | |
636 | |
637 if(dataLengthRead == 0) | |
638 { | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
407
diff
changeset
|
639 ext_flash_write_devicedata(false); |
38 | 640 return; |
641 } | |
642 | |
643 /* max values */ | |
644 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) | |
645 { | |
646 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
647 } | |
648 if(DeviceData->batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
649 { | |
650 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
651 } | |
652 if(DeviceData->temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
653 { | |
654 DataEX_helper_copy_deviceData(&DeviceData->temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
655 } | |
656 if(DeviceData->depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
657 { | |
658 DataEX_helper_copy_deviceData(&DeviceData->depthMaximum, &DeviceDataFlash.depthMaximum); | |
659 } | |
660 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
661 { | |
662 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles); | |
663 } | |
406
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
664 if(DeviceData->hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32) |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
665 { |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
666 DataEX_helper_copy_deviceData(&DeviceData->hoursOfOperation, &DeviceDataFlash.hoursOfOperation); |
439874690f85
Bugfix Min max values for device data checks:
ideenmodellierer
parents:
342
diff
changeset
|
667 } |
38 | 668 |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
669 |
38 | 670 /* min values */ |
671 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
672 { | |
673 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
674 } | |
675 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
676 { | |
677 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
678 } | |
679 | |
680 DataEX_check_DeviceData (); | |
421
3f7d80f37bfc
Enable sequentionel writing of device data:
ideenmodellierer
parents:
407
diff
changeset
|
681 ext_flash_write_devicedata(false); |
38 | 682 } |
683 | |
684 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
685 static void DataEX_copy_to_DeviceData(void) |
38 | 686 { |
687 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
688 SDevice * pDeviceState = stateDeviceGetPointerWrite(); | |
689 | |
690 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); | |
559 | 691 memcpy(&hw_Info, &dataInDevice->hw_Info, sizeof(dataInDevice->hw_Info)); |
692 | |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
693 DeviceDataUpdated = 1; /* indicate new data to be written to flash by background task (at last op hour count will be updated) */ |
38 | 694 } |
695 | |
696 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
697 static void DataEX_copy_to_VpmRepetitiveData(void) |
38 | 698 { |
699 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
700 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite(); | |
701 | |
702 if(dataInDevice->boolVpmRepetitiveDataValid) | |
703 { | |
704 memcpy(pVpmState, &dataInDevice->VpmRepetitiveData, sizeof(SVpmRepetitiveData)); | |
705 pVpmState->is_data_from_RTE_CPU = 1; | |
706 } | |
707 } | |
708 | |
709 | |
710 void DataEX_control_connection_while_asking_for_sleep(void) | |
711 { | |
712 if(!DataEX_check_header_and_footer_ok()) | |
713 { | |
714 if(DataEX_check_header_and_footer_devicedata()) | |
715 { | |
716 data_old__lost_connection_to_slave_counter_retry = 0; | |
717 data_old__lost_connection_to_slave_counter_temp = 0; | |
718 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 0; | |
208 | 719 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK; |
38 | 720 } |
721 else | |
722 { | |
723 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 1; | |
724 data_old__lost_connection_to_slave_counter_temp += 1; | |
725 data_old__lost_connection_to_slave_counter_total += 1; | |
726 } | |
727 } | |
728 } | |
729 | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
730 static float getSampleDepth(SDataExchangeSlaveToMaster *d, SDiveState *ds) |
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
731 { |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
732 float ambient = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
733 float surface = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
734 float depth = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
735 float density = 0; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
736 |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
737 ambient = d->data[d->boolPressureData].pressure_mbar / 1000.0f; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
738 surface = d->data[d->boolPressureData].surface_mbar / 1000.0f; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
739 density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
740 |
497
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
741 #ifdef TESTBENCH |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
742 /* do plausibility check (typically only needed at debug hardware) */ |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
743 if(ambient < 0) |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
744 { |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
745 ambient = 1.0; |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
746 } |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
747 if(surface < 0) |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
748 { |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
749 surface = 1.0; |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
750 } |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
751 #endif |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
752 ds->lifeData.pressure_ambient_bar = ambient; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
753 ds->lifeData.pressure_surface_bar = surface; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
754 depth = (ambient - surface) / (0.09807f * density); |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
755 ds->lifeData.bool_temp1 = d->data[d->boolPressureData].SPARE1; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
756 |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
757 return depth; |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
758 } |
38 | 759 |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
760 static float getTemperature(SDataExchangeSlaveToMaster *d) |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
761 { |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
762 float temp = 0; |
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
763 temp = d->data[d->boolPressureData].temperature; |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
764 |
497
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
765 #ifdef TESTBENCH |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
766 /* do plausibility check (typically only needed at debug hardware */ |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
767 if(temp < -40.0) |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
768 { |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
769 temp = 20.0; |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
770 } |
5757edda56b7
Added worst case plausibility check (disabled by compile switch)
Ideenmodellierer
parents:
451
diff
changeset
|
771 #endif |
342
ea3fda8eb93e
Removed averaging of pressure and temperatur values
ideenmodellierer
parents:
309
diff
changeset
|
772 return temp; |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
773 } |
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
774 |
38 | 775 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) |
776 { | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
777 SDiveState *pStateReal = stateRealGetPointerWrite(); |
38 | 778 static uint16_t getDeviceDataAfterStartOfMainCPU = 20; |
577
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
779 uint8_t idx; |
38 | 780 |
781 // wireless - �ltere daten aufr�umen | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
436
diff
changeset
|
782 #if 0 |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
783 for(int i=0;i<(2*NUM_GASES+1);i++) |
38 | 784 { |
785 if(pStateReal->lifeData.bottle_bar[i]) | |
786 { | |
787 if((pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] == 0) || (pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] > 60000)) | |
788 { | |
789 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] = 0; | |
790 pStateReal->lifeData.bottle_bar[i] = 0; | |
791 } | |
792 else | |
793 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] += 100; | |
794 } | |
795 } | |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
436
diff
changeset
|
796 #else |
451
c2e02b87774f
Allocate received bar value to active gas (was static allocated to gas[1])
ideenmodellierer
parents:
446
diff
changeset
|
797 if(stateRealGetPointer()->lifeData.bottle_bar_age_MilliSeconds[stateRealGetPointer()->lifeData.actualGas.GasIdInSettings] < 6000) /* max age after ten minutes */ |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
436
diff
changeset
|
798 { |
451
c2e02b87774f
Allocate received bar value to active gas (was static allocated to gas[1])
ideenmodellierer
parents:
446
diff
changeset
|
799 stateRealGetPointerWrite()->lifeData.bottle_bar_age_MilliSeconds[stateRealGetPointer()->lifeData.actualGas.GasIdInSettings]++; |
446
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
436
diff
changeset
|
800 } |
f1257a32f2d4
Introduced configuration header for variant managment:
ideenmodellierer
parents:
436
diff
changeset
|
801 #endif |
38 | 802 if(!DataEX_check_header_and_footer_ok()) |
803 { | |
804 if(DataEX_check_header_and_footer_devicedata()) | |
805 { | |
806 DataEX_copy_to_DeviceData(); | |
807 DataEX_copy_to_VpmRepetitiveData(); | |
808 data_old__lost_connection_to_slave_counter_temp = 0; | |
809 data_old__lost_connection_to_slave_counter_retry = 0; | |
275
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
810 /* Do not yet reset state. Wait till common data has been received in next cycle. Otherwise invalid data may be forwarded for processing */ |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
811 /* pStateReal->data_old__lost_connection_to_slave = 0; */ |
208 | 812 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK; |
38 | 813 } |
814 else | |
815 { | |
816 pStateReal->data_old__lost_connection_to_slave = 1; | |
817 data_old__lost_connection_to_slave_counter_temp += 1; | |
818 data_old__lost_connection_to_slave_counter_total += 1; | |
819 } | |
820 return; | |
821 } | |
141 | 822 else /* RX data OK */ |
823 { | |
824 data_old__lost_connection_to_slave_counter_temp = 0; | |
825 data_old__lost_connection_to_slave_counter_retry = 0; | |
826 pStateReal->data_old__lost_connection_to_slave = 0; | |
208 | 827 dataOut.header.checkCode[SPI_HEADER_INDEX_RX_STATE] = SPI_RX_STATE_OK; |
141 | 828 } |
38 | 829 |
830 if(getDeviceDataAfterStartOfMainCPU) | |
831 { | |
832 getDeviceDataAfterStartOfMainCPU--; | |
833 if(getDeviceDataAfterStartOfMainCPU == 0) | |
834 { | |
835 dataOut.getDeviceDataNow = 1; | |
141 | 836 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */ |
38 | 837 } |
838 } | |
839 | |
840 /* new 151207 hw */ | |
841 if(requestNecessary.uw != 0) | |
842 { | |
843 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0) | |
844 { | |
845 requestNecessary.ub.button = 0; | |
846 } | |
847 | |
848 if(requestNecessary.ub.button == 1) | |
849 { | |
850 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); | |
851 } | |
852 } | |
853 requestNecessary.uw = 0; // clear all | |
854 | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
855 float meter = 0; |
38 | 856 SSettings *pSettings; |
149 | 857 |
38 | 858 /* uint8_t IAmStolenPleaseKillMe; |
859 */ | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
860 pSettings = settingsGetPointer(); |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
861 |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
862 if(pSettings->IAmStolenPleaseKillMe > 3) |
38 | 863 { |
864 pSettings->salinity = 0; | |
865 dataIn.data[dataIn.boolPressureData].surface_mbar = 999; | |
866 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971; | |
867 dataIn.mode = MODE_DIVE; | |
868 } | |
869 | |
556
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
870 |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
871 /* internal sensor: HUD data */ |
559 | 872 if(pSettings->ppo2sensors_source == O2_SENSOR_SOURCE_OPTIC) |
556
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
873 { |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
874 for(int i=0;i<3;i++) |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
875 { |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
876 pStateReal->lifeData.ppO2Sensor_bar[i] = get_ppO2Sensor_bar(i); |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
877 pStateReal->lifeData.sensorVoltage_mV[i] = get_sensorVoltage_mV(i); |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
878 } |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
879 pStateReal->lifeData.HUD_battery_voltage_V = get_HUD_battery_voltage_V(); |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
880 } |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
881 else /* use data from external ADC */ |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
882 { |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
883 if(pStateReal->data_old__lost_connection_to_slave == 0) |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
884 { |
577
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
885 for(idx = 0; idx < 3; idx++) |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
886 { |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
887 pStateReal->lifeData.sensorVoltage_mV[idx] = dataIn.data[0].extADC_voltage[idx]; |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
888 if(pStateReal->lifeData.sensorVoltage_mV[idx] < IGNORE_O2_VOLTAGE_LEVEL_MV) |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
889 { |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
890 pStateReal->lifeData.sensorVoltage_mV[idx] = 0.0; |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
891 pStateReal->lifeData.ppO2Sensor_bar[idx] = 0; |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
892 } |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
893 else |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
894 { |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
895 pStateReal->lifeData.ppO2Sensor_bar[idx] = pStateReal->lifeData.sensorVoltage_mV[idx] * pSettings->ppo2sensors_calibCoeff[idx]; |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
896 } |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
897 |
9bb9a52d6ae5
Handle o2 voltage values < 0.5mV as invalid:
Ideenmodellierer
parents:
559
diff
changeset
|
898 } |
556
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
899 } |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
900 } |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
901 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
902 if(pStateReal->data_old__lost_connection_to_slave == 0) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
903 { |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
904 meter = getSampleDepth(&dataIn, pStateReal); |
38 | 905 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
906 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
907 pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
908 pStateReal->pressure_uTick_local_new = HAL_GetTick(); |
38 | 909 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
910 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
911 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
912 } |
38 | 913 dataOut.setAccidentFlag = 0; |
914 | |
141 | 915 if(pStateReal->data_old__lost_connection_to_slave == 0) |
38 | 916 { |
141 | 917 //Start of diveMode? |
918 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE) | |
919 { | |
920 if(modeChangeFlag) | |
921 { | |
922 *modeChangeFlag = 1; | |
923 } | |
924 if(stateUsed == stateSimGetPointer()) | |
38 | 925 { |
926 simulation_exit(); | |
927 } | |
141 | 928 // new 170508 |
38 | 929 settingsGetPointer()->bluetoothActive = 0; |
930 MX_Bluetooth_PowerOff(); | |
931 //Init dive Mode | |
141 | 932 decoLock = DECO_CALC_init_as_is_start_of_dive; |
933 pStateReal->lifeData.boolResetAverageDepth = 1; | |
38 | 934 } |
141 | 935 |
197
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
936 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
937 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
938 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
939 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes; |
c853f5d23bb7
cleanup: fix (harmless) use before assign
Jan Mulder <jlmulder@xs4all.nl>
parents:
189
diff
changeset
|
940 |
141 | 941 //End of diveMode? |
942 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE) | |
943 { | |
944 if(modeChangeFlag) | |
945 { | |
946 *modeChangeFlag = 1; | |
947 } | |
948 createDiveSettings(); | |
38 | 949 |
141 | 950 if(pStateReal->warnings.cnsHigh) |
951 { | |
952 if(pStateReal->lifeData.cns >= 130) | |
953 dataOut.setAccidentFlag += ACCIDENT_CNSLVL2; | |
954 else if(pStateReal->lifeData.cns >= 100) | |
955 dataOut.setAccidentFlag += ACCIDENT_CNS; | |
956 } | |
957 if(pStateReal->warnings.decoMissed) | |
958 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; | |
959 } | |
960 pStateReal->mode = dataIn.mode; | |
961 pStateReal->chargeStatus = dataIn.chargeStatus; | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
962 |
306
2f43419102c8
bugfix, cleanup: do not clip depth to 0
Jan Mulder <jlmulder@xs4all.nl>
parents:
288
diff
changeset
|
963 pStateReal->lifeData.depth_meter = meter; |
141 | 964 |
189
8b8074080d7b
Bugfix: average temperature on arrival from RTE instead of display time
Jan Mulder <jlmulder@xs4all.nl>
parents:
173
diff
changeset
|
965 pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn); |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
966 pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
967 if(pStateReal->mode != MODE_DIVE) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
968 pStateReal->lifeData.max_depth_meter = 0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
969 else |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
970 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
971 if(meter > pStateReal->lifeData.max_depth_meter) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
972 pStateReal->lifeData.max_depth_meter = meter; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
973 } |
38 | 974 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
975 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
976 pStateReal->decoMissed_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
977 if(dataIn.accidentFlags & ACCIDENT_CNS) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
978 pStateReal->cnsHigh_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
979 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
980 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
981 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
982 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
983 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; |
38 | 984 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
985 pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
986 if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
987 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
988 pStateReal->lifeData.compass_heading -= 180.0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
989 if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
990 } |
109
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
991 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
992 pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
993 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; |
38 | 994 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
995 pStateReal->lifeData.compass_DX_f = dataIn.data[dataIn.boolCompassData].compass_DX_f; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
996 pStateReal->lifeData.compass_DY_f = dataIn.data[dataIn.boolCompassData].compass_DY_f; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
997 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; |
38 | 998 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
999 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1000 pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1001 pStateReal->compass_uTick_local_new = HAL_GetTick(); |
539
d784f281833a
Added inertia simulation for compass heading:
Ideenmodellierer
parents:
497
diff
changeset
|
1002 compass_Inertia(pStateReal->lifeData.compass_heading); |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1003 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1004 memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar)); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1005 memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar)); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1006 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1007 if(pStateReal->mode == MODE_DIVE) |
38 | 1008 { |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1009 for(int i= 0; i <16; i++) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1010 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1011 pStateReal->vpm.max_crushing_pressure_he[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_he[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1012 pStateReal->vpm.max_crushing_pressure_n2[i] = dataIn.data[dataIn.boolCrushingData].max_crushing_pressure_n2[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1013 pStateReal->vpm.adjusted_critical_radius_he[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_he[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1014 pStateReal->vpm.adjusted_critical_radius_n2[i] = dataIn.data[dataIn.boolCrushingData].adjusted_critical_radius_n2[i]; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1015 } |
38 | 1016 } |
1017 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1018 /* battery and ambient light sensors |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1019 */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1020 pStateReal->lifeData.ambient_light_level = dataIn.data[dataIn.boolAmbientLightData].ambient_light_level; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1021 pStateReal->lifeData.battery_charge = dataIn.data[dataIn.boolBatteryData].battery_charge; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1022 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage; |
275
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1023 |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1024 /* PIC data |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1025 */ |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1026 for(int i=0;i<4;i++) |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1027 { |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1028 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i]; |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1029 } |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1030 |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1031 /* sensorErrors |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1032 */ |
189387bf23a8
Do not mark data as valid if devicedata is received.
ideenmodellierer
parents:
232
diff
changeset
|
1033 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1034 } |
38 | 1035 |
1036 /* apnea specials | |
1037 */ | |
1038 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) | |
1039 { | |
1040 if(pStateReal->mode != MODE_DIVE) | |
1041 { | |
1042 pStateReal->lifeData.apnea_total_max_depth_meter = 0; | |
1043 pStateReal->lifeData.apnea_last_dive_time_seconds = 0; | |
1044 pStateReal->lifeData.apnea_last_max_depth_meter = 0; | |
1045 } | |
1046 else | |
1047 { | |
1048 if(pStateReal->lifeData.max_depth_meter > pStateReal->lifeData.apnea_total_max_depth_meter) | |
1049 pStateReal->lifeData.apnea_total_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1050 } | |
1051 | |
1052 if(pStateReal->lifeData.dive_time_seconds > 15) | |
1053 { | |
1054 pStateReal->lifeData.apnea_last_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1055 } | |
1056 | |
1057 if(pStateReal->lifeData.counterSecondsShallowDepth) | |
1058 { | |
1059 if(pStateReal->lifeData.max_depth_meter > 1.5f) | |
1060 { | |
1061 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1062 } | |
173
05c770dc2911
Bugfix: make max depth move with current depth (part 1)
Jan Mulder <jlmulder@xs4all.nl>
parents:
156
diff
changeset
|
1063 // reset max_depth_meter, average_depth_meter and internal values |
38 | 1064 pStateReal->lifeData.max_depth_meter = 0; |
1065 pStateReal->lifeData.boolResetAverageDepth = 1; | |
1066 } | |
1067 } | |
1068 | |
308
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1069 setAvgDepth(pStateReal); |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1070 } |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1071 |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1072 void setAvgDepth(SDiveState *pStateReal) { |
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1073 |
38 | 1074 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; |
1075 float DepthNow = pStateReal->lifeData.depth_meter; | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1076 static uint32_t AvgDepthCount = 0; |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1077 static uint32_t AvgDepthTimer = 0; |
38 | 1078 uint32_t AvgSecondsSinceLast; |
1079 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
308
1203255481e4
cleanup: introduce function setAvgDepth
Jan Mulder <jlmulder@xs4all.nl>
parents:
307
diff
changeset
|
1080 |
38 | 1081 if(pStateReal->lifeData.boolResetAverageDepth) |
1082 { | |
1083 *AvgDepthValue = DepthNow; | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1084 AvgDepthCount = 0; |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1085 AvgDepthTimer = DiveTime; |
38 | 1086 pStateReal->lifeData.boolResetAverageDepth = 0; |
1087 } | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1088 else if (DiveTime > AvgDepthTimer) |
38 | 1089 { |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1090 AvgSecondsSinceLast = DiveTime - AvgDepthTimer; |
38 | 1091 for(int i=0;i<AvgSecondsSinceLast;i++) |
1092 { | |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1093 *AvgDepthValue = (*AvgDepthValue * AvgDepthCount + DepthNow) / (AvgDepthCount + 1); |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1094 AvgDepthCount += 1; |
38 | 1095 } |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1096 AvgDepthTimer = DiveTime; |
38 | 1097 } |
309
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1098 if(AvgDepthCount == 0) |
b0045281cb2d
cleanup: factor out SHelper typedef (and more)
Jan Mulder <jlmulder@xs4all.nl>
parents:
308
diff
changeset
|
1099 *AvgDepthValue = DepthNow; |
38 | 1100 } |
1101 | |
1102 | |
1103 uint8_t DataEX_check_RTE_version__needs_update(void) | |
1104 { | |
1105 if(data_old__lost_connection_to_slave_counter_retry > 10) | |
1106 return 1; | |
1107 else | |
1108 { | |
1109 if(stateRealGetPointer()->data_old__lost_connection_to_slave == 0) | |
1110 { | |
1111 setActualRTEversion(dataIn.RTE_VERSION_high, dataIn.RTE_VERSION_low); | |
1112 | |
1113 if(RTEminimum_required_high() < dataIn.RTE_VERSION_high) | |
1114 return 0; | |
1115 else | |
1116 if((RTEminimum_required_high() == dataIn.RTE_VERSION_high) && (RTEminimum_required_low() <= dataIn.RTE_VERSION_low)) | |
1117 return 0; | |
1118 else | |
1119 return 1; | |
1120 } | |
1121 else | |
1122 return 0; | |
1123 } | |
1124 } | |
1125 | |
1126 | |
1127 /* Private functions ---------------------------------------------------------*/ | |
1128 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1129 /* Check if there is an empty frame provided by RTE (all 0) or even no data provided by RTE (all 0xFF) |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1130 * If that is not the case the DMA is somehow not in sync |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1131 */ |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1132 static uint8_t DataEX_check_header_and_footer_shifted() |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1133 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1134 uint8_t ret = 1; |
141 | 1135 if((dataIn.footer.checkCode[0] == 0x00) |
1136 && (dataIn.footer.checkCode[1] == 0x00) | |
1137 && (dataIn.footer.checkCode[2] == 0x00) | |
1138 && (dataIn.footer.checkCode[3] == 0x00)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1139 |
141 | 1140 if((dataIn.footer.checkCode[0] == 0xff) |
1141 && (dataIn.footer.checkCode[1] == 0xff) | |
1142 && (dataIn.footer.checkCode[2] == 0xff) | |
1143 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1144 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1145 return ret; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1146 } |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1147 |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1148 static uint8_t DataEX_check_header_and_footer_ok(void) |
38 | 1149 { |
1150 if(dataIn.header.checkCode[0] != 0xA1) | |
1151 return 0; | |
141 | 1152 #if USE_OLD_HEADER_FORMAT |
38 | 1153 if(dataIn.header.checkCode[1] != 0xA2) |
1154 return 0; | |
1155 if(dataIn.header.checkCode[2] != 0xA3) | |
1156 return 0; | |
141 | 1157 #endif |
38 | 1158 if(dataIn.header.checkCode[3] != 0xA4) |
1159 return 0; | |
1160 if(dataIn.footer.checkCode[0] != 0xE1) | |
1161 return 0; | |
1162 if(dataIn.footer.checkCode[1] != 0xE2) | |
1163 return 0; | |
1164 if(dataIn.footer.checkCode[2] != 0xE3) | |
1165 return 0; | |
1166 if(dataIn.footer.checkCode[3] != 0xE4) | |
1167 return 0; | |
1168 | |
1169 return 1; | |
1170 } | |
1171 | |
198
878dc9e0dbc5
cleanup: another cleanup session (data_exchange_main.c)
Jan Mulder <jlmulder@xs4all.nl>
parents:
197
diff
changeset
|
1172 static uint8_t DataEX_check_header_and_footer_devicedata(void) |
38 | 1173 { |
1174 if(dataIn.header.checkCode[0] != 0xDF) | |
1175 return 0; | |
1176 if(dataIn.header.checkCode[1] != 0xDE) | |
1177 return 0; | |
1178 if(dataIn.header.checkCode[2] != 0xDD) | |
1179 return 0; | |
1180 if(dataIn.header.checkCode[3] != 0xDC) | |
1181 return 0; | |
1182 if(dataIn.footer.checkCode[0] != 0xE1) | |
1183 return 0; | |
1184 if(dataIn.footer.checkCode[1] != 0xE2) | |
1185 return 0; | |
1186 if(dataIn.footer.checkCode[2] != 0xE3) | |
1187 return 0; | |
1188 if(dataIn.footer.checkCode[3] != 0xE4) | |
1189 return 0; | |
1190 | |
1191 return 1; | |
1192 } | |
407
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1193 |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1194 void DataEX_merge_devicedata(void) |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1195 { |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1196 if(DeviceDataUpdated) |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1197 { |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1198 DeviceDataUpdated = 0; |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1199 DataEX_merge_DeviceData_and_store(); |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1200 } |
b11e50415982
Bugfix parallel call of external flash functions:
ideenmodellierer
parents:
406
diff
changeset
|
1201 } |
556
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
1202 uint8_t DataEX_external_ADC_Present(void) |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
1203 { |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
1204 uint8_t retval; |
559 | 1205 retval = hw_Info.extADC; |
556
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
1206 |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
1207 return retval; |
eb2060caca7d
Switch source of o2 sensor data depending on availability of external ADC:
Ideenmodellierer
parents:
539
diff
changeset
|
1208 } |