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