Mercurial > public > ostc4
annotate Discovery/Src/data_exchange_main.c @ 155:4fd8bbc7d841 FlipDisplay
Do hard sync after communication timeout > 1 second
author | Ideenmodellierer |
---|---|
date | Sun, 03 Mar 2019 17:46:50 +0100 |
parents | 1ac5033f7c7a |
children | 1fbdb45db701 |
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 | |
41 on receiption the data is merged with the data in externLogbookFlash, | |
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> |
38 | 59 #include <string.h> // for memcopy |
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 | |
75 | |
76 /* Expoted variables --------------------------------------------------------*/ | |
77 uint8_t wasPowerOn = 0; | |
78 confirmbit8_Type requestNecessary = { .uw = 0 }; | |
79 uint8_t wasUpdateNotPowerOn = 0; | |
80 | |
81 /* Private variables with external access ------------------------------------*/ | |
82 | |
83 | |
84 /* Private variables ---------------------------------------------------------*/ | |
85 uint8_t told_reset_logik_alles_ok = 0; | |
86 | |
87 SDataReceiveFromMaster dataOut; | |
88 SDataExchangeSlaveToMaster dataIn; | |
89 | |
90 uint8_t data_old__lost_connection_to_slave_counter_temp = 0; | |
91 uint8_t data_old__lost_connection_to_slave_counter_retry = 0; | |
92 uint32_t data_old__lost_connection_to_slave_counter_total = 0; | |
93 | |
94 /* Private types -------------------------------------------------------------*/ | |
95 | |
96 typedef enum | |
97 { | |
98 CPU2_TRANSFER_STOP = 0x00, /*!< */ | |
99 CPU2_TRANSFER_TEST_REQUEST = 0x01, /*!< */ | |
100 CPU2_TRANSFER_TEST_RECEIVE = 0x02, /*!< */ | |
101 CPU2_TRANSFER_SEND_OK = 0x03, /*!< */ | |
102 CPU2_TRANSFER_SEND_FALSE = 0x04, /*!< */ | |
103 CPU2_TRANSFER_DATA = 0x05, /*!< */ | |
104 }CPU2_TRANSFER_StatusTypeDef; | |
105 | |
106 const uint8_t header_test_request[4] = {0xBB, 0x00, 0x00, 0xBB}; | |
107 const uint8_t header_test_receive[4] = {0xBB, 0x01, 0x01, 0xBB}; | |
108 const uint8_t header_false[4] = {0xBB, 0xFF, 0xFF, 0xBB}; | |
109 const uint8_t header_correct[4] = {0xBB, 0xCC, 0xCC, 0xBB}; | |
110 const uint8_t header_data[4] = {0xAA, 0x01, 0x01, 0xAA}; | |
111 | |
112 /* Private function prototypes -----------------------------------------------*/ | |
113 uint8_t DataEX_check_header_and_footer_ok(void); | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
114 uint8_t DataEX_check_header_and_footer_shifted(void); |
38 | 115 uint8_t DataEX_check_header_and_footer_devicedata(void); |
116 void DataEX_check_DeviceData(void); | |
117 | |
118 /* Exported functions --------------------------------------------------------*/ | |
119 void DataEX_set_update_RTE_not_power_on(void) | |
120 { | |
121 wasUpdateNotPowerOn = 1; | |
122 } | |
123 | |
124 | |
125 uint8_t DataEX_was_power_on(void) | |
126 { | |
127 return wasPowerOn; | |
128 } | |
129 | |
130 uint8_t count_DataEX_Error_Handler = 0; | |
131 uint8_t last_error_DataEX_Error_Handler = 0; | |
132 | |
133 void DataEX_Error_Handler(uint8_t answer) | |
134 { | |
135 count_DataEX_Error_Handler++; | |
136 last_error_DataEX_Error_Handler = answer; | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
137 |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
138 /* A wrong footer indicates a communication interrupt. Statemachine is waiting for new data which is not received because no new transmission is triggered */ |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
139 /* ==> Abort data exchange to enable a new RX / TX cycle */ |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
140 if(answer == HAL_BUSY) |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
141 { |
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
142 HAL_SPI_Abort_IT(&cpu2DmaSpi); |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
143 data_old__lost_connection_to_slave_counter_total += 1000; /* add significant error offset to indicate error causing an abort event */ |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
144 } |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
145 |
38 | 146 return; |
147 } | |
148 | |
149 | |
150 uint32_t DataEX_lost_connection_count(void) | |
151 { | |
152 return data_old__lost_connection_to_slave_counter_total; | |
153 } | |
154 | |
155 | |
156 uint32_t DataEX_time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) | |
157 { | |
158 | |
159 if(ticksstart <= ticksnow) | |
160 { | |
161 return ticksnow - ticksstart; | |
162 } | |
163 else | |
164 { | |
165 return 0xFFFFFFFF - ticksstart + ticksnow; | |
166 } | |
167 | |
168 } | |
169 | |
170 SDataReceiveFromMaster * dataOutGetPointer(void) | |
171 { | |
172 return &dataOut; | |
173 } | |
174 | |
175 void DataEX_init(void) | |
176 { | |
177 SDiveState * pStateReal = stateRealGetPointerWrite(); | |
99 | 178 pStateReal->data_old__lost_connection_to_slave = 0; //initial value |
38 | 179 data_old__lost_connection_to_slave_counter_temp = 0; |
180 data_old__lost_connection_to_slave_counter_total = 0; | |
181 | |
182 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); | |
183 // old 160307: for(int i=0;i<EXCHANGE_BUFFERSIZE;i++) | |
184 // *(uint8_t *)(((uint32_t)&dataOut) + i) = 0; | |
185 | |
186 dataOut.header.checkCode[0] = 0xBB; | |
187 dataOut.header.checkCode[1] = 0x01; | |
188 dataOut.header.checkCode[2] = 0x01; | |
189 dataOut.header.checkCode[3] = 0xBB; | |
190 | |
191 dataOut.footer.checkCode[0] = 0xF4; | |
192 dataOut.footer.checkCode[1] = 0xF3; | |
193 dataOut.footer.checkCode[2] = 0xF2; | |
194 dataOut.footer.checkCode[3] = 0xF1; | |
195 } | |
196 | |
197 | |
198 void DataEx_call_helper_requests(void) | |
199 { | |
200 static uint8_t setDateWasSend = 0; | |
201 static uint8_t setTimeWasSend = 0; | |
202 static uint8_t calibrateCompassWasSend = 0; | |
203 static uint8_t setButtonSensitivityWasSend = 0; | |
204 static uint8_t clearDecoWasSend = 0; | |
205 static uint8_t getDeviceDataWasSend = 0; | |
206 static uint8_t setAccidentFlagWasSend = 0; | |
207 static uint8_t setEndDiveWasSend = 0; | |
208 | |
209 if(getDeviceDataWasSend) | |
210 { | |
211 dataOut.getDeviceDataNow = 0; | |
212 requestNecessary.ub.devicedata = 1; | |
213 } | |
214 getDeviceDataWasSend = 0; | |
215 if(dataOut.getDeviceDataNow) | |
216 { | |
217 getDeviceDataWasSend = 1; | |
218 } | |
219 | |
220 if(setEndDiveWasSend) | |
221 { | |
222 dataOut.setEndDive = 0; | |
223 //requestNecessary.ub.XXX = 1; not implemented and no space here | |
224 } | |
225 setEndDiveWasSend = 0; | |
226 if(dataOut.setEndDive) | |
227 { | |
228 setEndDiveWasSend = 1; | |
229 } | |
230 | |
231 if(setAccidentFlagWasSend) | |
232 { | |
233 dataOut.setAccidentFlag = 0; | |
234 requestNecessary.ub.accident = 1; | |
235 } | |
236 setAccidentFlagWasSend = 0; | |
237 if(dataOut.setAccidentFlag) | |
238 { | |
239 setAccidentFlagWasSend = 1; | |
240 } | |
241 | |
242 if(setDateWasSend) | |
243 { | |
244 dataOut.setDateNow = 0; | |
245 requestNecessary.ub.date = 1; | |
246 } | |
247 setDateWasSend = 0; | |
248 if(dataOut.setDateNow) | |
249 { | |
250 setDateWasSend = 1; | |
251 } | |
252 | |
253 if(setTimeWasSend) | |
254 { | |
255 dataOut.setTimeNow = 0; | |
256 requestNecessary.ub.time = 1; | |
257 } | |
258 setTimeWasSend = 0; | |
259 if(dataOut.setTimeNow) | |
260 { | |
261 setTimeWasSend = 1; | |
262 } | |
263 | |
264 if(calibrateCompassWasSend) | |
265 { | |
266 dataOut.calibrateCompassNow = 0; | |
267 requestNecessary.ub.compass = 1; | |
268 } | |
269 calibrateCompassWasSend = 0; | |
270 if(dataOut.calibrateCompassNow) | |
271 { | |
272 calibrateCompassWasSend = 1; | |
273 } | |
274 | |
275 if(clearDecoWasSend) | |
276 { | |
277 dataOut.clearDecoNow = 0; | |
278 requestNecessary.ub.clearDeco = 1; | |
279 } | |
280 if(dataOut.clearDecoNow) | |
281 { | |
282 clearDecoWasSend = 1; | |
283 } | |
284 | |
285 if(setButtonSensitivityWasSend) | |
286 { | |
287 dataOut.setButtonSensitivityNow = 0; | |
288 requestNecessary.ub.button = 1; | |
289 } | |
290 setButtonSensitivityWasSend = 0; | |
291 if(dataOut.setButtonSensitivityNow) | |
292 { | |
293 setButtonSensitivityWasSend = 1; | |
294 } | |
295 } | |
296 | |
297 | |
298 uint8_t DataEX_call(void) | |
299 { | |
300 uint8_t SPI_DMA_answer = 0; | |
141 | 301 |
87 | 302 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); |
141 | 303 |
38 | 304 if(data_old__lost_connection_to_slave_counter_temp >= 3) |
305 { | |
306 data_old__lost_connection_to_slave_counter_temp = 0; | |
141 | 307 if((DataEX_check_header_and_footer_shifted()) && (data_old__lost_connection_to_slave_counter_retry == 0)) |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
308 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
309 HAL_SPI_Abort_IT(&cpu2DmaSpi); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
310 } |
141 | 311 /* reset of own DMA does not work ==> request reset of slave dma */ |
149 | 312 if((DataEX_check_header_and_footer_shifted()) && (data_old__lost_connection_to_slave_counter_retry == 2)) |
141 | 313 { |
314 dataOut.header.checkCode[SPI_HEADER_INDEX_SLAVE] = 0xA5; | |
315 } | |
38 | 316 data_old__lost_connection_to_slave_counter_retry++; |
317 } | |
149 | 318 #if USE_OLD_SYNC_METHOD |
319 /* one cycle with NotChipSelect true to clear slave spi buffer */ | |
320 else | |
321 { | |
322 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
323 } | |
324 #endif | |
38 | 325 |
326 DataEx_call_helper_requests(); | |
327 | |
328 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ | |
329 | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
330 |
89 | 331 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE); |
38 | 332 if(SPI_DMA_answer != HAL_OK) |
149 | 333 { |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
334 DataEX_Error_Handler(SPI_DMA_answer); |
149 | 335 } |
104 | 336 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
38 | 337 //HAL_Delay(3); |
338 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ | |
339 | |
340 return 1; | |
341 } | |
342 | |
82 | 343 |
344 uint32_t SPI_CALLBACKS; | |
345 uint32_t get_num_SPI_CALLBACKS(void){ | |
346 return SPI_CALLBACKS; | |
347 } | |
348 | |
349 SDataExchangeSlaveToMaster* get_dataInPointer(void){ | |
350 return &dataIn; | |
351 } | |
352 | |
353 | |
354 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) | |
355 { | |
356 if(hspi == &cpu2DmaSpi) | |
357 { | |
154 | 358 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
82 | 359 SPI_CALLBACKS+=1; |
360 } | |
361 } | |
362 | |
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 /* | |
408 for(int i = 0; i< 16; i++) | |
409 { | |
410 dataOut.data.VPM_adjusted_critical_radius_he[i] = pStateReal->vpm.adjusted_critical_radius_he[i]; | |
411 dataOut.data.VPM_adjusted_critical_radius_n2[i] = pStateReal->vpm.adjusted_critical_radius_n2[i]; | |
412 dataOut.data.VPM_adjusted_crushing_pressure_he[i] = pStateReal->vpm.adjusted_crushing_pressure_he[i]; | |
413 dataOut.data.VPM_adjusted_crushing_pressure_n2[i] = pStateReal->vpm.adjusted_crushing_pressure_n2[i]; | |
414 dataOut.data.VPM_initial_allowable_gradient_he[i] = pStateReal->vpm.initial_allowable_gradient_he[i]; | |
415 dataOut.data.VPM_initial_allowable_gradient_n2[i] = pStateReal->vpm.initial_allowable_gradient_n2[i]; | |
416 dataOut.data.VPM_max_actual_gradient[i] = pStateReal->vpm.max_actual_gradient[i]; | |
417 } | |
418 */ | |
419 | |
420 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok) | |
421 { | |
422 MX_tell_reset_logik_alles_ok(); | |
423 told_reset_logik_alles_ok = 1; | |
424 } | |
425 | |
426 if(DataEX_check_header_and_footer_ok() && (dataIn.power_on_reset == 1)) | |
427 { | |
428 if(!wasUpdateNotPowerOn) | |
429 wasPowerOn = 1; | |
430 | |
431 RTC_DateTypeDef Sdate; | |
432 RTC_TimeTypeDef Stime; | |
433 | |
434 translateDate(settings->backup_localtime_rtc_dr, &Sdate); | |
435 translateTime(settings->backup_localtime_rtc_tr, &Stime); | |
436 | |
437 dataOut.data.newTime = Stime; | |
438 dataOut.setTimeNow = 1; | |
439 dataOut.data.newDate = Sdate; | |
440 dataOut.setDateNow = 1; | |
441 | |
442 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); | |
443 setButtonResponsiveness(settings->ButtonResponsiveness); | |
444 | |
445 // hw 160720 new lastKnownBatteryPercentage | |
446 if(!wasUpdateNotPowerOn) | |
447 { | |
448 // dataOut.data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
449 dataOut.data.newBatteryGaugePercentageFloat = 0; | |
450 dataOut.setBatteryGaugeNow = 1; | |
451 } | |
452 } | |
453 } | |
454 | |
455 | |
456 void DataEX_copy_to_deco(void) | |
457 { | |
458 SDiveState * pStateUsed; | |
459 if(decoLock == DECO_CALC_running) | |
460 return; | |
461 if(stateUsed == stateRealGetPointer()) | |
462 pStateUsed = stateRealGetPointerWrite(); | |
90 | 463 else{ |
38 | 464 pStateUsed = stateSimGetPointerWrite(); |
90 | 465 } |
38 | 466 |
467 if(decoLock == DECO_CALC_init_as_is_start_of_dive) | |
468 { | |
469 vpm_init(&pStateUsed->vpm, pStateUsed->diveSettings.vpm_conservatism, 0, 0); | |
470 buehlmann_init(); | |
471 timer_init(); | |
472 resetEvents(); | |
473 pStateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; | |
474 /* | |
475 * ToDo by Peter | |
476 * copy VPM stuff etc. pp. | |
477 * was void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm); | |
478 */ | |
479 } | |
480 | |
481 | |
482 | |
483 if(decoLock == DECO_CALC_FINSHED_Buehlmann) | |
484 { | |
485 | |
486 } | |
487 switch(decoLock) | |
488 { | |
489 | |
490 //Deco_calculation finished | |
491 case DECO_CALC_FINSHED_vpm: | |
492 memcpy(&pStateUsed->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo)); | |
493 pStateUsed->decolistVPM.tickstamp = HAL_GetTick(); | |
494 pStateUsed->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached; | |
495 for(int i = 0; i< 16; i++) | |
496 { | |
497 pStateUsed->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i]; | |
498 pStateUsed->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i]; | |
499 pStateUsed->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i]; | |
500 pStateUsed->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i]; | |
501 pStateUsed->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i]; | |
502 pStateUsed->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i]; | |
503 pStateUsed->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i]; | |
504 } | |
505 break; | |
506 case DECO_CALC_FINSHED_Buehlmann: | |
507 memcpy(&pStateUsed->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo)); | |
508 pStateUsed->decolistBuehlmann.tickstamp = HAL_GetTick(); | |
509 //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann | |
510 pStateUsed->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; | |
511 break; | |
512 case DECO_CALC_FINSHED_FutureBuehlmann: | |
513 memcpy(&pStateUsed->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo)); | |
514 pStateUsed->decolistFutureBuehlmann.tickstamp = HAL_GetTick(); | |
515 break; | |
516 case DECO_CALC_FINSHED_Futurevpm: | |
517 memcpy(&pStateUsed->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo)); | |
518 pStateUsed->decolistFutureVPM.tickstamp = HAL_GetTick(); | |
519 break; | |
520 } | |
521 | |
522 //Copy Inputdata from stateReal to stateDeco | |
523 memcpy(&stateDeco.lifeData,&pStateUsed->lifeData,sizeof(SLifeData)); | |
524 memcpy(&stateDeco.diveSettings,&pStateUsed->diveSettings,sizeof(SDiveSettings)); | |
525 | |
526 stateDeco.vpm.deco_zone_reached = pStateUsed->vpm.deco_zone_reached; | |
527 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm)); | |
528 for(int i = 0; i< 16; i++) | |
529 { | |
530 stateDeco.vpm.max_crushing_pressure_he[i] = pStateUsed->vpm.max_crushing_pressure_he[i]; | |
531 stateDeco.vpm.max_crushing_pressure_n2[i] = pStateUsed->vpm.max_crushing_pressure_n2[i]; | |
532 stateDeco.vpm.adjusted_critical_radius_he[i] = pStateUsed->vpm.adjusted_critical_radius_he[i]; | |
533 stateDeco.vpm.adjusted_critical_radius_n2[i] = pStateUsed->vpm.adjusted_critical_radius_n2[i]; | |
534 } | |
535 decoLock = DECO_CALC_ready; | |
536 } | |
537 | |
538 | |
539 void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
540 { | |
541 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
542 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
543 lineWrite->value_int32 = lineRead->value_int32; | |
544 } | |
545 | |
546 | |
547 | |
548 void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg) | |
549 { | |
550 inStimestructure.TimeFormat = RTC_HOURFORMAT_24; | |
551 | |
552 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \ | |
553 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \ | |
554 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \ | |
555 (((uint32_t)inStimestructure.TimeFormat) << 16U)); | |
556 } | |
557 | |
558 | |
559 void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg) | |
560 { | |
561 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \ | |
562 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \ | |
563 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ | |
564 ((uint32_t)inSdatestructure.WeekDay << 13U)); | |
565 } | |
566 | |
567 | |
568 | |
569 void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) | |
570 { | |
571 RTC_DateTypeDef sdatestructure; | |
572 RTC_TimeTypeDef stimestructure; | |
573 | |
574 stimestructure.Hours = 1; | |
575 stimestructure.Minutes = 0; | |
576 stimestructure.Seconds = 0; | |
577 | |
578 sdatestructure.Date = 1; | |
579 sdatestructure.Month = 1; | |
580 sdatestructure.Year = 16; | |
581 setWeekday(&sdatestructure); | |
582 | |
583 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); | |
584 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); | |
585 } | |
586 | |
587 | |
588 uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) | |
589 { | |
590 RTC_DateTypeDef sdatestructure; | |
591 RTC_TimeTypeDef stimestructure; | |
592 | |
593 // from lineWrite to structure | |
594 translateDate(lineWrite->date_rtc_dr, &sdatestructure); | |
595 translateTime(lineWrite->time_rtc_tr, &stimestructure); | |
596 | |
597 if( (sdatestructure.Year >= 15) | |
598 && (sdatestructure.Year <= 30) | |
599 && (sdatestructure.Month <= 12)) | |
600 return 0; | |
601 | |
602 | |
603 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | |
604 return 1; | |
605 } | |
606 | |
607 | |
608 uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to) | |
609 { | |
610 if(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to) | |
611 return 0; | |
612 | |
613 if(lineWrite->value_int32 < from) | |
614 lineWrite->value_int32 = from; | |
615 else | |
616 lineWrite->value_int32 = to; | |
617 | |
618 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | |
619 return 0; | |
620 } | |
621 | |
622 | |
623 void DataEX_check_DeviceData(void) | |
624 { | |
625 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
626 | |
627 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles); | |
628 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles); | |
629 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->depthMaximum); | |
630 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->diveCycles); | |
631 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation); | |
632 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum); | |
633 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum); | |
634 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum); | |
635 | |
636 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000); | |
637 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000); | |
638 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000); | |
639 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000); | |
640 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000); | |
641 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100); | |
642 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100); | |
643 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, -1*1000, 6*1000); | |
644 } | |
645 | |
646 | |
647 void DataEX_merge_DeviceData_and_store(void) | |
648 { | |
649 uint16_t dataLengthRead; | |
650 SDevice DeviceDataFlash; | |
651 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
652 | |
653 dataLengthRead = ext_flash_read_devicedata((uint8_t *)&DeviceDataFlash,sizeof(SDevice)); | |
654 | |
655 if(dataLengthRead == 0) | |
656 { | |
657 ext_flash_write_devicedata(); | |
658 return; | |
659 } | |
660 | |
661 /* | |
662 SDeviceLine batteryChargeCycles; | |
663 SDeviceLine batteryChargeCompleteCycles; | |
664 SDeviceLine temperatureMinimum; | |
665 SDeviceLine temperatureMaximum; | |
666 SDeviceLine depthMaximum; | |
667 SDeviceLine diveCycles; | |
668 SDeviceLine voltageMinimum; | |
669 */ | |
670 | |
671 /* max values */ | |
672 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) | |
673 { | |
674 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
675 } | |
676 if(DeviceData->batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
677 { | |
678 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
679 } | |
680 if(DeviceData->temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
681 { | |
682 DataEX_helper_copy_deviceData(&DeviceData->temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
683 } | |
684 if(DeviceData->depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
685 { | |
686 DataEX_helper_copy_deviceData(&DeviceData->depthMaximum, &DeviceDataFlash.depthMaximum); | |
687 } | |
688 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
689 { | |
690 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles); | |
691 } | |
692 | |
693 /* min values */ | |
694 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
695 { | |
696 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
697 } | |
698 // Voltage minimum, keep limit to 2.0 Volt; hw 09.09.2015 | |
699 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
700 { | |
701 if(DeviceDataFlash.voltageMinimum.value_int32 > 2000) // do not copy back 2000 and below | |
702 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
703 } | |
704 if(DeviceData->voltageMinimum.value_int32 < 2000) | |
705 DeviceData->voltageMinimum.value_int32 = 2000; | |
706 | |
707 DataEX_check_DeviceData (); | |
708 ext_flash_write_devicedata(); | |
709 } | |
710 | |
711 | |
712 void DataEX_copy_to_DeviceData(void) | |
713 { | |
714 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
715 SDevice * pDeviceState = stateDeviceGetPointerWrite(); | |
716 | |
717 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); | |
718 } | |
719 | |
720 | |
721 void DataEX_copy_to_VpmRepetitiveData(void) | |
722 { | |
723 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
724 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite(); | |
725 | |
726 if(dataInDevice->boolVpmRepetitiveDataValid) | |
727 { | |
728 memcpy(pVpmState, &dataInDevice->VpmRepetitiveData, sizeof(SVpmRepetitiveData)); | |
729 pVpmState->is_data_from_RTE_CPU = 1; | |
730 } | |
731 } | |
732 | |
733 | |
734 void DataEX_control_connection_while_asking_for_sleep(void) | |
735 { | |
736 if(!DataEX_check_header_and_footer_ok()) | |
737 { | |
738 if(DataEX_check_header_and_footer_devicedata()) | |
739 { | |
740 data_old__lost_connection_to_slave_counter_retry = 0; | |
741 data_old__lost_connection_to_slave_counter_temp = 0; | |
742 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 0; | |
743 } | |
744 else | |
745 { | |
746 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 1; | |
747 data_old__lost_connection_to_slave_counter_temp += 1; | |
748 data_old__lost_connection_to_slave_counter_total += 1; | |
749 } | |
750 } | |
751 } | |
752 | |
753 | |
754 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) | |
755 { | |
756 SDiveState * pStateReal = stateRealGetPointerWrite(); | |
757 static uint16_t getDeviceDataAfterStartOfMainCPU = 20; | |
758 | |
759 /* internal sensor: HUD data | |
760 */ | |
761 for(int i=0;i<3;i++) | |
762 { | |
763 pStateReal->lifeData.ppO2Sensor_bar[i] = get_ppO2Sensor_bar(i); | |
764 pStateReal->lifeData.sensorVoltage_mV[i] = get_sensorVoltage_mV(i); | |
765 } | |
766 pStateReal->lifeData.HUD_battery_voltage_V = get_HUD_battery_voltage_V(); | |
767 | |
768 | |
769 // wireless - �ltere daten aufr�umen | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
770 for(int i=0;i<(2*NUM_GASES+1);i++) |
38 | 771 { |
772 if(pStateReal->lifeData.bottle_bar[i]) | |
773 { | |
774 if((pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] == 0) || (pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] > 60000)) | |
775 { | |
776 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] = 0; | |
777 pStateReal->lifeData.bottle_bar[i] = 0; | |
778 } | |
779 else | |
780 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] += 100; | |
781 } | |
782 } | |
783 | |
784 /* Why? hw 8.6.2015 | |
785 if(DataEX_check_header_and_footer_ok() && dataIn.power_on_reset) | |
786 { | |
787 return; | |
788 } | |
789 */ | |
790 if(!DataEX_check_header_and_footer_ok()) | |
791 { | |
792 if(DataEX_check_header_and_footer_devicedata()) | |
793 { | |
794 DataEX_copy_to_DeviceData(); | |
795 DataEX_merge_DeviceData_and_store(); | |
796 DataEX_copy_to_VpmRepetitiveData(); | |
797 data_old__lost_connection_to_slave_counter_temp = 0; | |
798 data_old__lost_connection_to_slave_counter_retry = 0; | |
799 pStateReal->data_old__lost_connection_to_slave = 0; | |
800 } | |
801 else | |
802 { | |
803 pStateReal->data_old__lost_connection_to_slave = 1; | |
804 data_old__lost_connection_to_slave_counter_temp += 1; | |
805 data_old__lost_connection_to_slave_counter_total += 1; | |
806 } | |
807 return; | |
808 } | |
141 | 809 else /* RX data OK */ |
810 { | |
811 data_old__lost_connection_to_slave_counter_temp = 0; | |
812 data_old__lost_connection_to_slave_counter_retry = 0; | |
813 pStateReal->data_old__lost_connection_to_slave = 0; | |
814 } | |
38 | 815 |
141 | 816 /* update SPI communication tokens */ |
817 dataOut.header.checkCode[SPI_HEADER_INDEX_SLAVE] = dataIn.header.checkCode[SPI_HEADER_INDEX_SLAVE]; | |
818 dataOut.header.checkCode[SPI_HEADER_INDEX_MASTER] = (dataOut.header.checkCode[SPI_HEADER_INDEX_MASTER] + 1) & 0x7F; | |
819 | |
38 | 820 if(getDeviceDataAfterStartOfMainCPU) |
821 { | |
822 getDeviceDataAfterStartOfMainCPU--; | |
823 if(getDeviceDataAfterStartOfMainCPU == 0) | |
824 { | |
825 dataOut.getDeviceDataNow = 1; | |
141 | 826 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */ |
38 | 827 } |
828 } | |
829 | |
830 /* new 151207 hw */ | |
831 if(requestNecessary.uw != 0) | |
832 { | |
833 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0) | |
834 { | |
835 requestNecessary.ub.button = 0; | |
836 } | |
837 | |
838 if(requestNecessary.ub.button == 1) | |
839 { | |
840 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); | |
841 } | |
842 /* | |
843 } | |
844 if((dataIn.confirmRequest.ub.clearDeco != 1) && (requestNecessary.ub.clearDeco == 1)) | |
845 { | |
846 clearDeco(); // is dataOut.clearDecoNow = 1; | |
847 } | |
848 */ | |
849 } | |
850 requestNecessary.uw = 0; // clear all | |
851 | |
852 float ambient, surface, density, meter; | |
853 SSettings *pSettings; | |
854 | |
149 | 855 ambient = 0; |
856 surface = 0; | |
857 meter = 0; | |
858 | |
38 | 859 /* uint8_t IAmStolenPleaseKillMe; |
860 */ | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
861 pSettings = settingsGetPointer(); |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
862 |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
863 if(pSettings->IAmStolenPleaseKillMe > 3) |
38 | 864 { |
865 pSettings->salinity = 0; | |
866 dataIn.data[dataIn.boolPressureData].surface_mbar = 999; | |
867 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971; | |
868 dataIn.mode = MODE_DIVE; | |
869 } | |
870 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
871 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
|
872 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
873 ambient = dataIn.data[dataIn.boolPressureData].pressure_mbar / 1000.0f; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
874 surface = dataIn.data[dataIn.boolPressureData].surface_mbar / 1000.0f; |
38 | 875 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
876 density = ((float)( 100 + pSettings->salinity)) / 100.0f; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
877 meter = (ambient - surface); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
878 meter /= (0.09807f * density); |
38 | 879 |
880 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
881 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
882 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
|
883 pStateReal->pressure_uTick_local_new = HAL_GetTick(); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
884 |
141 | 885 /* what was the code behind this if statement ? */ |
886 /* if(ambient < (surface + 0.04f)) */ | |
38 | 887 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
888 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
|
889 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
|
890 } |
38 | 891 dataOut.setAccidentFlag = 0; |
892 | |
141 | 893 if(pStateReal->data_old__lost_connection_to_slave == 0) |
38 | 894 { |
141 | 895 //Start of diveMode? |
896 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE) | |
897 { | |
898 if(modeChangeFlag) | |
899 { | |
900 *modeChangeFlag = 1; | |
901 } | |
902 if(stateUsed == stateSimGetPointer()) | |
38 | 903 { |
904 simulation_exit(); | |
905 } | |
141 | 906 // new 170508 |
38 | 907 settingsGetPointer()->bluetoothActive = 0; |
908 MX_Bluetooth_PowerOff(); | |
909 //Init dive Mode | |
141 | 910 decoLock = DECO_CALC_init_as_is_start_of_dive; |
911 pStateReal->lifeData.boolResetAverageDepth = 1; | |
912 pStateReal->lifeData.boolResetStopwatch = 1; | |
38 | 913 } |
141 | 914 |
915 //End of diveMode? | |
916 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE) | |
917 { | |
918 if(modeChangeFlag) | |
919 { | |
920 *modeChangeFlag = 1; | |
921 } | |
922 createDiveSettings(); | |
38 | 923 |
141 | 924 if(pStateReal->warnings.cnsHigh) |
925 { | |
926 if(pStateReal->lifeData.cns >= 130) | |
927 dataOut.setAccidentFlag += ACCIDENT_CNSLVL2; | |
928 else if(pStateReal->lifeData.cns >= 100) | |
929 dataOut.setAccidentFlag += ACCIDENT_CNS; | |
930 } | |
931 if(pStateReal->warnings.decoMissed) | |
932 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; | |
933 } | |
934 pStateReal->mode = dataIn.mode; | |
935 pStateReal->chargeStatus = dataIn.chargeStatus; | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
936 |
141 | 937 pStateReal->lifeData.pressure_ambient_bar = ambient; |
938 pStateReal->lifeData.pressure_surface_bar = surface; | |
939 if(is_ambient_pressure_close_to_surface(&pStateReal->lifeData)) | |
940 { | |
941 pStateReal->lifeData.depth_meter = 0; | |
942 } | |
943 else | |
944 { | |
945 pStateReal->lifeData.depth_meter = meter; | |
946 } | |
947 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
948 pStateReal->lifeData.temperature_celsius = dataIn.data[dataIn.boolPressureData].temperature; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
949 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
|
950 if(pStateReal->mode != MODE_DIVE) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
951 pStateReal->lifeData.max_depth_meter = 0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
952 else |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
953 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
954 if(meter > pStateReal->lifeData.max_depth_meter) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
955 pStateReal->lifeData.max_depth_meter = meter; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
956 } |
38 | 957 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
958 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
959 pStateReal->decoMissed_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
960 if(dataIn.accidentFlags & ACCIDENT_CNS) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
961 pStateReal->cnsHigh_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
962 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
963 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
|
964 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
|
965 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
966 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; |
38 | 967 |
109
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
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 |
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
976 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
977 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
|
978 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; |
38 | 979 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
980 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
|
981 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
|
982 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; |
38 | 983 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
984 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
985 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
|
986 pStateReal->compass_uTick_local_new = HAL_GetTick(); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
987 |
141 | 988 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
989 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; |
141 | 990 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes; |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
991 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes; |
38 | 992 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
993 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
|
994 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
|
995 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
996 if(pStateReal->mode == MODE_DIVE) |
38 | 997 { |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
998 for(int i= 0; i <16; i++) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
999 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1000 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
|
1001 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
|
1002 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
|
1003 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
|
1004 } |
38 | 1005 } |
1006 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1007 /* battery and ambient light sensors |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1008 */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1009 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
|
1010 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
|
1011 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1012 } |
38 | 1013 /* now in ext_flash_write_settings() // hw 161027 |
1014 * if((pStateReal->lifeData.battery_charge > 1) && !DataEX_was_power_on() && ((uint8_t)(pStateReal->lifeData.battery_charge) != 0x10)) // get rid of 16% (0x10) | |
1015 * pSettings->lastKnownBatteryPercentage = (uint8_t)(pStateReal->lifeData.battery_charge); | |
1016 */ | |
1017 | |
1018 /* OC and CCR but no sensors -> moved to updateSetpointStateUsed(); | |
1019 float oxygen = 0; | |
1020 if(pStateReal->diveSettings.diveMode == 0) | |
1021 { | |
1022 oxygen = 1.00f; | |
1023 oxygen -= ((float)pStateReal->lifeData.actualGas.nitrogen_percentage)/100.0f; | |
1024 oxygen -= ((float)pStateReal->lifeData.actualGas.helium_percentage)/100.0f; | |
1025 pStateReal->lifeData.ppO2 = pStateReal->lifeData.pressure_ambient_bar * oxygen; | |
1026 } | |
1027 else if(pStateReal->diveSettings.diveMode == 1) | |
1028 { | |
1029 pStateReal->lifeData.ppO2 = ((float)pStateReal->lifeData.actualGas.setPoint_cbar) /100; | |
1030 } | |
1031 */ | |
1032 | |
1033 /* apnea specials | |
1034 */ | |
1035 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) | |
1036 { | |
1037 if(pStateReal->mode != MODE_DIVE) | |
1038 { | |
1039 pStateReal->lifeData.apnea_total_max_depth_meter = 0; | |
1040 pStateReal->lifeData.apnea_last_dive_time_seconds = 0; | |
1041 pStateReal->lifeData.apnea_last_max_depth_meter = 0; | |
1042 } | |
1043 else | |
1044 { | |
1045 if(pStateReal->lifeData.max_depth_meter > pStateReal->lifeData.apnea_total_max_depth_meter) | |
1046 pStateReal->lifeData.apnea_total_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1047 } | |
1048 | |
1049 if(pStateReal->lifeData.dive_time_seconds > 15) | |
1050 { | |
1051 pStateReal->lifeData.apnea_last_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1052 } | |
1053 | |
1054 if(pStateReal->lifeData.counterSecondsShallowDepth) | |
1055 { | |
1056 if(pStateReal->lifeData.max_depth_meter > 1.5f) | |
1057 { | |
1058 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1059 } | |
1060 // eset max_depth_meter, average_depth_meter and internal values | |
1061 pStateReal->lifeData.max_depth_meter = 0; | |
1062 pStateReal->lifeData.boolResetAverageDepth = 1; | |
1063 pStateReal->lifeData.boolResetStopwatch = 1; | |
1064 } | |
1065 } | |
1066 | |
1067 /* average depth | |
1068 */ | |
1069 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; | |
1070 float DepthNow = pStateReal->lifeData.depth_meter; | |
1071 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count; | |
1072 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; | |
1073 uint32_t AvgSecondsSinceLast; | |
1074 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
1075 | |
1076 if(pStateReal->lifeData.boolResetAverageDepth) | |
1077 { | |
1078 *AvgDepthValue = DepthNow; | |
1079 *AvgDepthCount = 1; | |
1080 *AvgDepthTimer = DiveTime; | |
1081 pStateReal->lifeData.boolResetAverageDepth = 0; | |
1082 } | |
1083 else if (DiveTime > *AvgDepthTimer) | |
1084 { | |
1085 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; | |
1086 for(int i=0;i<AvgSecondsSinceLast;i++) | |
1087 { | |
1088 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); | |
1089 *AvgDepthCount += 1; | |
1090 } | |
1091 *AvgDepthTimer = DiveTime; | |
1092 } | |
1093 if(*AvgDepthCount == 0) | |
1094 *AvgDepthValue = 0; | |
1095 | |
1096 | |
1097 /* stop watch | |
1098 */ | |
1099 if(pStateReal->lifeData.boolResetStopwatch) | |
1100 { | |
1101 pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1102 pStateReal->lifeData.boolResetStopwatch = 0; | |
1103 } | |
1104 pStateReal->lifeData.stopwatch_seconds = pStateReal->lifeData.dive_time_seconds - pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds; | |
1105 | |
1106 /* wireless data | |
1107 */ | |
1108 uint16_t wirelessData[4][3]; | |
1109 for(int i=0;i<4;i++) | |
1110 { | |
1111 pStateReal->lifeData.wireless_data[i].ageInMilliSeconds = dataIn.data[dataIn.boolWirelessData].wireless_data[i].ageInMilliSeconds; | |
1112 pStateReal->lifeData.wireless_data[i].status = dataIn.data[dataIn.boolWirelessData].wireless_data[i].status; | |
1113 pStateReal->lifeData.wireless_data[i].numberOfBytes = dataIn.data[dataIn.boolWirelessData].wireless_data[i].numberOfBytes; | |
1114 for(int j=0;j<12;j++) | |
1115 pStateReal->lifeData.wireless_data[i].data[j] = dataIn.data[dataIn.boolWirelessData].wireless_data[i].data[j]; | |
1116 } | |
1117 | |
1118 /* old stuff | |
1119 // crc - is done in RTE 160325 | |
1120 // size at the moment 4 bytes + one empty + crc -> minimum 5 bytes (+ crc) | |
1121 // kopieren: Id, Wert, Alter | |
1122 for(int i=0;i<4;i++) | |
1123 { | |
1124 uint8_t numberOfBytes = pStateReal->lifeData.wireless_data[i].numberOfBytes - 1; | |
1125 | |
1126 if((numberOfBytes < 5) || (numberOfBytes > 7)) | |
1127 { | |
1128 wirelessData[i][0] = 0; | |
1129 wirelessData[i][1] = 0; | |
1130 wirelessData[i][2] = 0; | |
1131 } | |
1132 else | |
1133 { | |
1134 if((crc32c_checksum(pStateReal->lifeData.wireless_data[i].data, numberOfBytes, 0, 0) & 0xFF)!= pStateReal->lifeData.wireless_data[i].data[numberOfBytes]) | |
1135 { | |
1136 // no crc is send at the moment | |
1137 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1]; | |
1138 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4]; | |
1139 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1140 | |
1141 // wirelessData[i][0] = 0; | |
1142 // wirelessData[i][1] = 0; | |
1143 // wirelessData[i][2] = 0; | |
1144 | |
1145 } | |
1146 | |
1147 else | |
1148 { | |
1149 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1]; | |
1150 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4]; | |
1151 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1152 } | |
1153 } | |
1154 } | |
1155 */ | |
1156 // neu 160412 | |
1157 for(int i=0;i<4;i++) | |
1158 { | |
1159 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10) | |
1160 { | |
1161 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] >> 4) & 0x7F; | |
1162 wirelessData[i][1] = 0; | |
1163 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1164 } | |
1165 else | |
1166 { | |
1167 wirelessData[i][0] = 0; | |
1168 wirelessData[i][1] = 0; | |
1169 wirelessData[i][2] = 0; | |
1170 } | |
1171 } | |
1172 | |
1173 // aussortieren doppelte ids, j�ngster datensatz ist relevant | |
1174 for(int i=0;i<3;i++) | |
1175 { | |
1176 if(wirelessData[i][0]) | |
1177 { | |
1178 for(int j=i+1; j<4; j++) | |
1179 { | |
1180 if(wirelessData[i][0] == wirelessData[j][0]) | |
1181 { | |
1182 if(wirelessData[i][2] > wirelessData[j][2]) | |
1183 { | |
1184 wirelessData[i][0] = wirelessData[j][0]; | |
1185 wirelessData[i][1] = wirelessData[j][1]; | |
1186 wirelessData[i][2] = wirelessData[j][2]; | |
1187 } | |
1188 wirelessData[j][0] = 0; | |
1189 wirelessData[j][1] = 0; | |
1190 wirelessData[j][2] = 0; | |
1191 } | |
1192 } | |
1193 } | |
1194 } | |
1195 /* | |
1196 // neu 160325 | |
1197 for(int i=0;i<4;i++) | |
1198 { | |
1199 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10) | |
1200 { | |
1201 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1]; | |
1202 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4]; | |
1203 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1204 } | |
1205 else | |
1206 { | |
1207 wirelessData[i][0] = 0; | |
1208 wirelessData[i][1] = 0; | |
1209 wirelessData[i][2] = 0; | |
1210 } | |
1211 } | |
1212 | |
1213 // aussortieren doppelte ids, j�ngster datensatz ist relevant | |
1214 for(int i=0;i<3;i++) | |
1215 { | |
1216 if(wirelessData[i][0]) | |
1217 { | |
1218 for(int j=i+1; j<4; j++) | |
1219 { | |
1220 if(wirelessData[i][0] == wirelessData[j][0]) | |
1221 { | |
1222 if(wirelessData[i][2] > wirelessData[j][2]) | |
1223 { | |
1224 wirelessData[i][0] = wirelessData[j][0]; | |
1225 wirelessData[i][1] = wirelessData[j][1]; | |
1226 wirelessData[i][2] = wirelessData[j][2]; | |
1227 } | |
1228 wirelessData[j][0] = 0; | |
1229 wirelessData[j][1] = 0; | |
1230 wirelessData[j][2] = 0; | |
1231 } | |
1232 } | |
1233 } | |
1234 } | |
1235 */ | |
1236 /* old | |
1237 // copy to lifeData | |
1238 for(int i=0;i<4;i++) | |
1239 { | |
1240 if((wirelessData[i][0]) && (wirelessData[i][2]) && (wirelessData[i][2] < 60000)) | |
1241 { | |
1242 for(int j=1;j<=(2*NUM_GASES+1);j++) | |
1243 { | |
1244 if(pStateReal->diveSettings.gas[j].bottle_wireless_id == wirelessData[i][0]) | |
1245 { | |
1246 pStateReal->lifeData.bottle_bar[j] = wirelessData[i][1]; | |
1247 pStateReal->lifeData.bottle_bar_age_MilliSeconds[j] = wirelessData[i][2]; | |
1248 break; | |
1249 } | |
1250 } | |
1251 } | |
1252 } | |
1253 */ | |
1254 | |
1255 | |
1256 /* PIC data | |
1257 */ | |
1258 for(int i=0;i<4;i++) | |
1259 { | |
1260 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i]; | |
1261 } | |
1262 | |
1263 /* sensorErrors | |
1264 */ | |
1265 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; | |
1266 } | |
1267 | |
1268 | |
1269 uint8_t DataEX_check_RTE_version__needs_update(void) | |
1270 { | |
1271 if(data_old__lost_connection_to_slave_counter_retry > 10) | |
1272 return 1; | |
1273 else | |
1274 { | |
1275 if(stateRealGetPointer()->data_old__lost_connection_to_slave == 0) | |
1276 { | |
1277 setActualRTEversion(dataIn.RTE_VERSION_high, dataIn.RTE_VERSION_low); | |
1278 | |
1279 if(RTEminimum_required_high() < dataIn.RTE_VERSION_high) | |
1280 return 0; | |
1281 else | |
1282 if((RTEminimum_required_high() == dataIn.RTE_VERSION_high) && (RTEminimum_required_low() <= dataIn.RTE_VERSION_low)) | |
1283 return 0; | |
1284 else | |
1285 return 1; | |
1286 } | |
1287 else | |
1288 return 0; | |
1289 } | |
1290 } | |
1291 | |
1292 | |
1293 /* Private functions ---------------------------------------------------------*/ | |
1294 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1295 /* Check if there is an empty frame providec by RTE (all 0) or even no data provided by RTE (all 0xFF) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1296 * 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
|
1297 */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1298 uint8_t DataEX_check_header_and_footer_shifted() |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1299 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1300 uint8_t ret = 1; |
141 | 1301 if((dataIn.footer.checkCode[0] == 0x00) |
1302 && (dataIn.footer.checkCode[1] == 0x00) | |
1303 && (dataIn.footer.checkCode[2] == 0x00) | |
1304 && (dataIn.footer.checkCode[3] == 0x00)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1305 |
141 | 1306 if((dataIn.footer.checkCode[0] == 0xff) |
1307 && (dataIn.footer.checkCode[1] == 0xff) | |
1308 && (dataIn.footer.checkCode[2] == 0xff) | |
1309 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1310 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1311 return ret; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1312 } |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1313 |
38 | 1314 uint8_t DataEX_check_header_and_footer_ok(void) |
1315 { | |
1316 if(dataIn.header.checkCode[0] != 0xA1) | |
1317 return 0; | |
141 | 1318 #if USE_OLD_HEADER_FORMAT |
38 | 1319 if(dataIn.header.checkCode[1] != 0xA2) |
1320 return 0; | |
1321 if(dataIn.header.checkCode[2] != 0xA3) | |
1322 return 0; | |
141 | 1323 #endif |
38 | 1324 if(dataIn.header.checkCode[3] != 0xA4) |
1325 return 0; | |
1326 if(dataIn.footer.checkCode[0] != 0xE1) | |
1327 return 0; | |
1328 if(dataIn.footer.checkCode[1] != 0xE2) | |
1329 return 0; | |
1330 if(dataIn.footer.checkCode[2] != 0xE3) | |
1331 return 0; | |
1332 if(dataIn.footer.checkCode[3] != 0xE4) | |
1333 return 0; | |
1334 | |
1335 return 1; | |
1336 } | |
1337 | |
1338 uint8_t DataEX_check_header_and_footer_devicedata(void) | |
1339 { | |
1340 if(dataIn.header.checkCode[0] != 0xDF) | |
1341 return 0; | |
1342 if(dataIn.header.checkCode[1] != 0xDE) | |
1343 return 0; | |
1344 if(dataIn.header.checkCode[2] != 0xDD) | |
1345 return 0; | |
1346 if(dataIn.header.checkCode[3] != 0xDC) | |
1347 return 0; | |
1348 if(dataIn.footer.checkCode[0] != 0xE1) | |
1349 return 0; | |
1350 if(dataIn.footer.checkCode[1] != 0xE2) | |
1351 return 0; | |
1352 if(dataIn.footer.checkCode[2] != 0xE3) | |
1353 return 0; | |
1354 if(dataIn.footer.checkCode[3] != 0xE4) | |
1355 return 0; | |
1356 | |
1357 return 1; | |
1358 } | |
1359 | |
1360 | |
1361 |