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