Mercurial > public > ostc4
annotate Discovery/Src/data_exchange_main.c @ 149:e1d66bc78f9a FlipDisplay
Eliminate warnings
author | Ideenmodellierer |
---|---|
date | Sat, 02 Mar 2019 17:42:06 +0100 |
parents | 30d855ea60d8 |
children | 1ac5033f7c7a |
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 |
38 | 302 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
141 | 303 delayMicros(10); //~exchange time(+20% reserve) |
87 | 304 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); |
141 | 305 |
38 | 306 if(data_old__lost_connection_to_slave_counter_temp >= 3) |
307 { | |
308 data_old__lost_connection_to_slave_counter_temp = 0; | |
141 | 309 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
|
310 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
311 HAL_SPI_Abort_IT(&cpu2DmaSpi); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
312 } |
141 | 313 /* reset of own DMA does not work ==> request reset of slave dma */ |
149 | 314 if((DataEX_check_header_and_footer_shifted()) && (data_old__lost_connection_to_slave_counter_retry == 2)) |
141 | 315 { |
316 dataOut.header.checkCode[SPI_HEADER_INDEX_SLAVE] = 0xA5; | |
317 } | |
38 | 318 data_old__lost_connection_to_slave_counter_retry++; |
319 } | |
149 | 320 #if USE_OLD_SYNC_METHOD |
321 /* one cycle with NotChipSelect true to clear slave spi buffer */ | |
322 else | |
323 { | |
324 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET); | |
325 } | |
326 #endif | |
38 | 327 |
328 DataEx_call_helper_requests(); | |
329 | |
330 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_RESET); /* only for testing with Oscilloscope */ | |
331 | |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
332 |
89 | 333 SPI_DMA_answer = HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE); |
38 | 334 if(SPI_DMA_answer != HAL_OK) |
149 | 335 { |
133
acc98f5bd8c4
Intoduced transfer abort function for data exchange recovery
Ideenmodellierer
parents:
115
diff
changeset
|
336 DataEX_Error_Handler(SPI_DMA_answer); |
149 | 337 } |
104 | 338 // HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); |
38 | 339 //HAL_Delay(3); |
340 //HAL_GPIO_WritePin(OSCILLOSCOPE2_GPIO_PORT,OSCILLOSCOPE2_PIN,GPIO_PIN_SET); /* only for testing with Oscilloscope */ | |
341 | |
342 return 1; | |
343 } | |
344 | |
82 | 345 |
346 uint32_t SPI_CALLBACKS; | |
347 uint32_t get_num_SPI_CALLBACKS(void){ | |
348 return SPI_CALLBACKS; | |
349 } | |
350 | |
351 SDataExchangeSlaveToMaster* get_dataInPointer(void){ | |
352 return &dataIn; | |
353 } | |
354 | |
355 | |
356 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) | |
357 { | |
358 | |
359 | |
360 if(hspi == &cpu2DmaSpi) | |
361 { | |
362 SPI_CALLBACKS+=1; | |
363 } | |
364 } | |
365 | |
366 | |
367 | |
368 | |
369 | |
38 | 370 void DateEx_copy_to_dataOut(void) |
371 { | |
372 const SDiveState * pStateReal = stateRealGetPointer(); | |
373 SSettings *settings = settingsGetPointer(); | |
374 | |
375 if(get_globalState() == StStop) | |
376 dataOut.mode = MODE_SHUTDOWN; | |
377 else | |
378 dataOut.mode = 0; | |
379 | |
380 dataOut.diveModeInfo = pStateReal->diveSettings.diveMode; // hw 170215 | |
381 | |
382 memcpy(&dataOut.data.DeviceData, stateDeviceGetPointer(), sizeof(SDevice)); | |
383 | |
384 dataOut.data.VPMconservatism = pStateReal->diveSettings.vpm_conservatism; | |
385 dataOut.data.actualGas = pStateReal->lifeData.actualGas; | |
386 dataOut.data.ambient_pressure_mbar_ceiling = (pStateReal->decolistBuehlmann.output_ceiling_meter * 100) + (pStateReal->lifeData.pressure_surface_bar * 1000); | |
387 dataOut.data.divetimeToCreateLogbook = settings->divetimeToCreateLogbook; | |
388 dataOut.data.timeoutDiveReachedZeroDepth = settings->timeoutDiveReachedZeroDepth; | |
389 | |
390 dataOut.data.offsetPressureSensor_mbar = settings->offsetPressure_mbar; | |
391 dataOut.data.offsetTemperatureSensor_centiDegree = settings->offsetTemperature_centigrad; | |
392 | |
393 if((hardwareDataGetPointer()->primarySerial <= 32) || (((hardwareDataGetPointer()->primarySerial == 72) && (hardwareDataGetPointer()->secondarySerial == 15)))) | |
394 { | |
395 dataOut.revisionHardware = 0x00; | |
396 dataOut.revisionCRCx0x7A = 0x7A; | |
397 } | |
398 else | |
399 if(hardwareDataGetPointer()->primarySerial < 0xFFFF) | |
400 { | |
401 dataOut.revisionHardware = hardwareDataGetPointer()->revision8bit; | |
402 dataOut.revisionCRCx0x7A = hardwareDataGetPointer()->revision8bit ^ 0x7A; | |
403 } | |
404 else | |
405 { | |
406 dataOut.revisionHardware = 0xFF; | |
407 dataOut.revisionCRCx0x7A = 0xFF; | |
408 } | |
409 | |
410 /* | |
411 for(int i = 0; i< 16; i++) | |
412 { | |
413 dataOut.data.VPM_adjusted_critical_radius_he[i] = pStateReal->vpm.adjusted_critical_radius_he[i]; | |
414 dataOut.data.VPM_adjusted_critical_radius_n2[i] = pStateReal->vpm.adjusted_critical_radius_n2[i]; | |
415 dataOut.data.VPM_adjusted_crushing_pressure_he[i] = pStateReal->vpm.adjusted_crushing_pressure_he[i]; | |
416 dataOut.data.VPM_adjusted_crushing_pressure_n2[i] = pStateReal->vpm.adjusted_crushing_pressure_n2[i]; | |
417 dataOut.data.VPM_initial_allowable_gradient_he[i] = pStateReal->vpm.initial_allowable_gradient_he[i]; | |
418 dataOut.data.VPM_initial_allowable_gradient_n2[i] = pStateReal->vpm.initial_allowable_gradient_n2[i]; | |
419 dataOut.data.VPM_max_actual_gradient[i] = pStateReal->vpm.max_actual_gradient[i]; | |
420 } | |
421 */ | |
422 | |
423 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok) | |
424 { | |
425 MX_tell_reset_logik_alles_ok(); | |
426 told_reset_logik_alles_ok = 1; | |
427 } | |
428 | |
429 if(DataEX_check_header_and_footer_ok() && (dataIn.power_on_reset == 1)) | |
430 { | |
431 if(!wasUpdateNotPowerOn) | |
432 wasPowerOn = 1; | |
433 | |
434 RTC_DateTypeDef Sdate; | |
435 RTC_TimeTypeDef Stime; | |
436 | |
437 translateDate(settings->backup_localtime_rtc_dr, &Sdate); | |
438 translateTime(settings->backup_localtime_rtc_tr, &Stime); | |
439 | |
440 dataOut.data.newTime = Stime; | |
441 dataOut.setTimeNow = 1; | |
442 dataOut.data.newDate = Sdate; | |
443 dataOut.setDateNow = 1; | |
444 | |
445 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); | |
446 setButtonResponsiveness(settings->ButtonResponsiveness); | |
447 | |
448 // hw 160720 new lastKnownBatteryPercentage | |
449 if(!wasUpdateNotPowerOn) | |
450 { | |
451 // dataOut.data.newBatteryGaugePercentageFloat = settingsGetPointer()->lastKnownBatteryPercentage; | |
452 dataOut.data.newBatteryGaugePercentageFloat = 0; | |
453 dataOut.setBatteryGaugeNow = 1; | |
454 } | |
455 } | |
456 } | |
457 | |
458 | |
459 void DataEX_copy_to_deco(void) | |
460 { | |
461 SDiveState * pStateUsed; | |
462 if(decoLock == DECO_CALC_running) | |
463 return; | |
464 if(stateUsed == stateRealGetPointer()) | |
465 pStateUsed = stateRealGetPointerWrite(); | |
90 | 466 else{ |
38 | 467 pStateUsed = stateSimGetPointerWrite(); |
90 | 468 } |
38 | 469 |
470 if(decoLock == DECO_CALC_init_as_is_start_of_dive) | |
471 { | |
472 vpm_init(&pStateUsed->vpm, pStateUsed->diveSettings.vpm_conservatism, 0, 0); | |
473 buehlmann_init(); | |
474 timer_init(); | |
475 resetEvents(); | |
476 pStateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; | |
477 /* | |
478 * ToDo by Peter | |
479 * copy VPM stuff etc. pp. | |
480 * was void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm); | |
481 */ | |
482 } | |
483 | |
484 | |
485 | |
486 if(decoLock == DECO_CALC_FINSHED_Buehlmann) | |
487 { | |
488 | |
489 } | |
490 switch(decoLock) | |
491 { | |
492 | |
493 //Deco_calculation finished | |
494 case DECO_CALC_FINSHED_vpm: | |
495 memcpy(&pStateUsed->decolistVPM,&stateDeco.decolistVPM,sizeof(SDecoinfo)); | |
496 pStateUsed->decolistVPM.tickstamp = HAL_GetTick(); | |
497 pStateUsed->vpm.deco_zone_reached = stateDeco.vpm.deco_zone_reached; | |
498 for(int i = 0; i< 16; i++) | |
499 { | |
500 pStateUsed->vpm.adjusted_critical_radius_he[i] = stateDeco.vpm.adjusted_critical_radius_he[i]; | |
501 pStateUsed->vpm.adjusted_critical_radius_n2[i] = stateDeco.vpm.adjusted_critical_radius_n2[i]; | |
502 pStateUsed->vpm.adjusted_crushing_pressure_he[i] = stateDeco.vpm.adjusted_crushing_pressure_he[i]; | |
503 pStateUsed->vpm.adjusted_crushing_pressure_n2[i] = stateDeco.vpm.adjusted_crushing_pressure_n2[i]; | |
504 pStateUsed->vpm.initial_allowable_gradient_he[i] = stateDeco.vpm.initial_allowable_gradient_he[i]; | |
505 pStateUsed->vpm.initial_allowable_gradient_n2[i] = stateDeco.vpm.initial_allowable_gradient_n2[i]; | |
506 pStateUsed->vpm.max_actual_gradient[i] = stateDeco.vpm.max_actual_gradient[i]; | |
507 } | |
508 break; | |
509 case DECO_CALC_FINSHED_Buehlmann: | |
510 memcpy(&pStateUsed->decolistBuehlmann,&stateDeco.decolistBuehlmann,sizeof(SDecoinfo)); | |
511 pStateUsed->decolistBuehlmann.tickstamp = HAL_GetTick(); | |
512 //Copy Data to be stored if regular Buehlmann, not FutureBuehlmann | |
513 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; | |
514 break; | |
515 case DECO_CALC_FINSHED_FutureBuehlmann: | |
516 memcpy(&pStateUsed->decolistFutureBuehlmann,&stateDeco.decolistFutureBuehlmann,sizeof(SDecoinfo)); | |
517 pStateUsed->decolistFutureBuehlmann.tickstamp = HAL_GetTick(); | |
518 break; | |
519 case DECO_CALC_FINSHED_Futurevpm: | |
520 memcpy(&pStateUsed->decolistFutureVPM,&stateDeco.decolistFutureVPM,sizeof(SDecoinfo)); | |
521 pStateUsed->decolistFutureVPM.tickstamp = HAL_GetTick(); | |
522 break; | |
523 } | |
524 | |
525 //Copy Inputdata from stateReal to stateDeco | |
526 memcpy(&stateDeco.lifeData,&pStateUsed->lifeData,sizeof(SLifeData)); | |
527 memcpy(&stateDeco.diveSettings,&pStateUsed->diveSettings,sizeof(SDiveSettings)); | |
528 | |
529 stateDeco.vpm.deco_zone_reached = pStateUsed->vpm.deco_zone_reached; | |
530 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm)); | |
531 for(int i = 0; i< 16; i++) | |
532 { | |
533 stateDeco.vpm.max_crushing_pressure_he[i] = pStateUsed->vpm.max_crushing_pressure_he[i]; | |
534 stateDeco.vpm.max_crushing_pressure_n2[i] = pStateUsed->vpm.max_crushing_pressure_n2[i]; | |
535 stateDeco.vpm.adjusted_critical_radius_he[i] = pStateUsed->vpm.adjusted_critical_radius_he[i]; | |
536 stateDeco.vpm.adjusted_critical_radius_n2[i] = pStateUsed->vpm.adjusted_critical_radius_n2[i]; | |
537 } | |
538 decoLock = DECO_CALC_ready; | |
539 } | |
540 | |
541 | |
542 void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) | |
543 { | |
544 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; | |
545 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; | |
546 lineWrite->value_int32 = lineRead->value_int32; | |
547 } | |
548 | |
549 | |
550 | |
551 void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg) | |
552 { | |
553 inStimestructure.TimeFormat = RTC_HOURFORMAT_24; | |
554 | |
555 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \ | |
556 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \ | |
557 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \ | |
558 (((uint32_t)inStimestructure.TimeFormat) << 16U)); | |
559 } | |
560 | |
561 | |
562 void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg) | |
563 { | |
564 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \ | |
565 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \ | |
566 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ | |
567 ((uint32_t)inSdatestructure.WeekDay << 13U)); | |
568 } | |
569 | |
570 | |
571 | |
572 void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) | |
573 { | |
574 RTC_DateTypeDef sdatestructure; | |
575 RTC_TimeTypeDef stimestructure; | |
576 | |
577 stimestructure.Hours = 1; | |
578 stimestructure.Minutes = 0; | |
579 stimestructure.Seconds = 0; | |
580 | |
581 sdatestructure.Date = 1; | |
582 sdatestructure.Month = 1; | |
583 sdatestructure.Year = 16; | |
584 setWeekday(&sdatestructure); | |
585 | |
586 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); | |
587 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); | |
588 } | |
589 | |
590 | |
591 uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) | |
592 { | |
593 RTC_DateTypeDef sdatestructure; | |
594 RTC_TimeTypeDef stimestructure; | |
595 | |
596 // from lineWrite to structure | |
597 translateDate(lineWrite->date_rtc_dr, &sdatestructure); | |
598 translateTime(lineWrite->time_rtc_tr, &stimestructure); | |
599 | |
600 if( (sdatestructure.Year >= 15) | |
601 && (sdatestructure.Year <= 30) | |
602 && (sdatestructure.Month <= 12)) | |
603 return 0; | |
604 | |
605 | |
606 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | |
607 return 1; | |
608 } | |
609 | |
610 | |
611 uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to) | |
612 { | |
613 if(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to) | |
614 return 0; | |
615 | |
616 if(lineWrite->value_int32 < from) | |
617 lineWrite->value_int32 = from; | |
618 else | |
619 lineWrite->value_int32 = to; | |
620 | |
621 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); | |
622 return 0; | |
623 } | |
624 | |
625 | |
626 void DataEX_check_DeviceData(void) | |
627 { | |
628 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
629 | |
630 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles); | |
631 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles); | |
632 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->depthMaximum); | |
633 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->diveCycles); | |
634 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->hoursOfOperation); | |
635 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMaximum); | |
636 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->temperatureMinimum); | |
637 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->voltageMinimum); | |
638 | |
639 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCompleteCycles, 0, 10000); | |
640 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->batteryChargeCycles, 0, 20000); | |
641 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->depthMaximum, 0, (500*100)+1000); | |
642 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->diveCycles, 0, 20000); | |
643 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->hoursOfOperation, 0, 1000000); | |
644 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMaximum, -30*100, 150*100); | |
645 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100); | |
646 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, -1*1000, 6*1000); | |
647 } | |
648 | |
649 | |
650 void DataEX_merge_DeviceData_and_store(void) | |
651 { | |
652 uint16_t dataLengthRead; | |
653 SDevice DeviceDataFlash; | |
654 SDevice *DeviceData = stateDeviceGetPointerWrite(); | |
655 | |
656 dataLengthRead = ext_flash_read_devicedata((uint8_t *)&DeviceDataFlash,sizeof(SDevice)); | |
657 | |
658 if(dataLengthRead == 0) | |
659 { | |
660 ext_flash_write_devicedata(); | |
661 return; | |
662 } | |
663 | |
664 /* | |
665 SDeviceLine batteryChargeCycles; | |
666 SDeviceLine batteryChargeCompleteCycles; | |
667 SDeviceLine temperatureMinimum; | |
668 SDeviceLine temperatureMaximum; | |
669 SDeviceLine depthMaximum; | |
670 SDeviceLine diveCycles; | |
671 SDeviceLine voltageMinimum; | |
672 */ | |
673 | |
674 /* max values */ | |
675 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) | |
676 { | |
677 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); | |
678 } | |
679 if(DeviceData->batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) | |
680 { | |
681 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCycles, &DeviceDataFlash.batteryChargeCycles); | |
682 } | |
683 if(DeviceData->temperatureMaximum.value_int32 < DeviceDataFlash.temperatureMaximum.value_int32) | |
684 { | |
685 DataEX_helper_copy_deviceData(&DeviceData->temperatureMaximum, &DeviceDataFlash.temperatureMaximum); | |
686 } | |
687 if(DeviceData->depthMaximum.value_int32 < DeviceDataFlash.depthMaximum.value_int32) | |
688 { | |
689 DataEX_helper_copy_deviceData(&DeviceData->depthMaximum, &DeviceDataFlash.depthMaximum); | |
690 } | |
691 if(DeviceData->diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) | |
692 { | |
693 DataEX_helper_copy_deviceData(&DeviceData->diveCycles, &DeviceDataFlash.diveCycles); | |
694 } | |
695 | |
696 /* min values */ | |
697 if(DeviceData->temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) | |
698 { | |
699 DataEX_helper_copy_deviceData(&DeviceData->temperatureMinimum, &DeviceDataFlash.temperatureMinimum); | |
700 } | |
701 // Voltage minimum, keep limit to 2.0 Volt; hw 09.09.2015 | |
702 if(DeviceData->voltageMinimum.value_int32 > DeviceDataFlash.voltageMinimum.value_int32) | |
703 { | |
704 if(DeviceDataFlash.voltageMinimum.value_int32 > 2000) // do not copy back 2000 and below | |
705 DataEX_helper_copy_deviceData(&DeviceData->voltageMinimum, &DeviceDataFlash.voltageMinimum); | |
706 } | |
707 if(DeviceData->voltageMinimum.value_int32 < 2000) | |
708 DeviceData->voltageMinimum.value_int32 = 2000; | |
709 | |
710 DataEX_check_DeviceData (); | |
711 ext_flash_write_devicedata(); | |
712 } | |
713 | |
714 | |
715 void DataEX_copy_to_DeviceData(void) | |
716 { | |
717 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
718 SDevice * pDeviceState = stateDeviceGetPointerWrite(); | |
719 | |
720 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); | |
721 } | |
722 | |
723 | |
724 void DataEX_copy_to_VpmRepetitiveData(void) | |
725 { | |
726 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; | |
727 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite(); | |
728 | |
729 if(dataInDevice->boolVpmRepetitiveDataValid) | |
730 { | |
731 memcpy(pVpmState, &dataInDevice->VpmRepetitiveData, sizeof(SVpmRepetitiveData)); | |
732 pVpmState->is_data_from_RTE_CPU = 1; | |
733 } | |
734 } | |
735 | |
736 | |
737 void DataEX_control_connection_while_asking_for_sleep(void) | |
738 { | |
739 if(!DataEX_check_header_and_footer_ok()) | |
740 { | |
741 if(DataEX_check_header_and_footer_devicedata()) | |
742 { | |
743 data_old__lost_connection_to_slave_counter_retry = 0; | |
744 data_old__lost_connection_to_slave_counter_temp = 0; | |
745 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 0; | |
746 } | |
747 else | |
748 { | |
749 stateRealGetPointerWrite()->data_old__lost_connection_to_slave = 1; | |
750 data_old__lost_connection_to_slave_counter_temp += 1; | |
751 data_old__lost_connection_to_slave_counter_total += 1; | |
752 } | |
753 } | |
754 } | |
755 | |
756 | |
757 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) | |
758 { | |
759 SDiveState * pStateReal = stateRealGetPointerWrite(); | |
760 static uint16_t getDeviceDataAfterStartOfMainCPU = 20; | |
761 | |
762 /* internal sensor: HUD data | |
763 */ | |
764 for(int i=0;i<3;i++) | |
765 { | |
766 pStateReal->lifeData.ppO2Sensor_bar[i] = get_ppO2Sensor_bar(i); | |
767 pStateReal->lifeData.sensorVoltage_mV[i] = get_sensorVoltage_mV(i); | |
768 } | |
769 pStateReal->lifeData.HUD_battery_voltage_V = get_HUD_battery_voltage_V(); | |
770 | |
771 | |
772 // wireless - �ltere daten aufr�umen | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
773 for(int i=0;i<(2*NUM_GASES+1);i++) |
38 | 774 { |
775 if(pStateReal->lifeData.bottle_bar[i]) | |
776 { | |
777 if((pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] == 0) || (pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] > 60000)) | |
778 { | |
779 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] = 0; | |
780 pStateReal->lifeData.bottle_bar[i] = 0; | |
781 } | |
782 else | |
783 pStateReal->lifeData.bottle_bar_age_MilliSeconds[i] += 100; | |
784 } | |
785 } | |
786 | |
787 /* Why? hw 8.6.2015 | |
788 if(DataEX_check_header_and_footer_ok() && dataIn.power_on_reset) | |
789 { | |
790 return; | |
791 } | |
792 */ | |
793 if(!DataEX_check_header_and_footer_ok()) | |
794 { | |
795 if(DataEX_check_header_and_footer_devicedata()) | |
796 { | |
797 DataEX_copy_to_DeviceData(); | |
798 DataEX_merge_DeviceData_and_store(); | |
799 DataEX_copy_to_VpmRepetitiveData(); | |
800 data_old__lost_connection_to_slave_counter_temp = 0; | |
801 data_old__lost_connection_to_slave_counter_retry = 0; | |
802 pStateReal->data_old__lost_connection_to_slave = 0; | |
803 } | |
804 else | |
805 { | |
806 pStateReal->data_old__lost_connection_to_slave = 1; | |
807 data_old__lost_connection_to_slave_counter_temp += 1; | |
808 data_old__lost_connection_to_slave_counter_total += 1; | |
809 } | |
810 return; | |
811 } | |
141 | 812 else /* RX data OK */ |
813 { | |
814 data_old__lost_connection_to_slave_counter_temp = 0; | |
815 data_old__lost_connection_to_slave_counter_retry = 0; | |
816 pStateReal->data_old__lost_connection_to_slave = 0; | |
817 } | |
38 | 818 |
141 | 819 /* update SPI communication tokens */ |
820 dataOut.header.checkCode[SPI_HEADER_INDEX_SLAVE] = dataIn.header.checkCode[SPI_HEADER_INDEX_SLAVE]; | |
821 dataOut.header.checkCode[SPI_HEADER_INDEX_MASTER] = (dataOut.header.checkCode[SPI_HEADER_INDEX_MASTER] + 1) & 0x7F; | |
822 | |
38 | 823 if(getDeviceDataAfterStartOfMainCPU) |
824 { | |
825 getDeviceDataAfterStartOfMainCPU--; | |
826 if(getDeviceDataAfterStartOfMainCPU == 0) | |
827 { | |
828 dataOut.getDeviceDataNow = 1; | |
141 | 829 getDeviceDataAfterStartOfMainCPU = 10*60*10; /* * 100ms = 60 second => update device data every 10 minutes */ |
38 | 830 } |
831 } | |
832 | |
833 /* new 151207 hw */ | |
834 if(requestNecessary.uw != 0) | |
835 { | |
836 if(((dataIn.confirmRequest.uw) & CRBUTTON) != 0) | |
837 { | |
838 requestNecessary.ub.button = 0; | |
839 } | |
840 | |
841 if(requestNecessary.ub.button == 1) | |
842 { | |
843 setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); | |
844 } | |
845 /* | |
846 } | |
847 if((dataIn.confirmRequest.ub.clearDeco != 1) && (requestNecessary.ub.clearDeco == 1)) | |
848 { | |
849 clearDeco(); // is dataOut.clearDecoNow = 1; | |
850 } | |
851 */ | |
852 } | |
853 requestNecessary.uw = 0; // clear all | |
854 | |
855 float ambient, surface, density, meter; | |
856 SSettings *pSettings; | |
857 | |
149 | 858 ambient = 0; |
859 surface = 0; | |
860 meter = 0; | |
861 | |
38 | 862 /* uint8_t IAmStolenPleaseKillMe; |
863 */ | |
51
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
864 pSettings = settingsGetPointer(); |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
865 |
8f8ea3a32e82
Resolved warnings pointing to possible invalid memory access
Ideenmodellierer
parents:
38
diff
changeset
|
866 if(pSettings->IAmStolenPleaseKillMe > 3) |
38 | 867 { |
868 pSettings->salinity = 0; | |
869 dataIn.data[dataIn.boolPressureData].surface_mbar = 999; | |
870 dataIn.data[dataIn.boolPressureData].pressure_mbar = 98971; | |
871 dataIn.mode = MODE_DIVE; | |
872 } | |
873 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
874 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
|
875 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
876 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
|
877 surface = dataIn.data[dataIn.boolPressureData].surface_mbar / 1000.0f; |
38 | 878 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
879 density = ((float)( 100 + pSettings->salinity)) / 100.0f; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
880 meter = (ambient - surface); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
881 meter /= (0.09807f * density); |
38 | 882 |
883 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
884 pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
885 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
|
886 pStateReal->pressure_uTick_local_new = HAL_GetTick(); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
887 |
141 | 888 /* what was the code behind this if statement ? */ |
889 /* if(ambient < (surface + 0.04f)) */ | |
38 | 890 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
891 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
|
892 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
|
893 } |
38 | 894 dataOut.setAccidentFlag = 0; |
895 | |
141 | 896 if(pStateReal->data_old__lost_connection_to_slave == 0) |
38 | 897 { |
141 | 898 //Start of diveMode? |
899 if(pStateReal->mode != MODE_DIVE && dataIn.mode == MODE_DIVE) | |
900 { | |
901 if(modeChangeFlag) | |
902 { | |
903 *modeChangeFlag = 1; | |
904 } | |
905 if(stateUsed == stateSimGetPointer()) | |
38 | 906 { |
907 simulation_exit(); | |
908 } | |
141 | 909 // new 170508 |
38 | 910 settingsGetPointer()->bluetoothActive = 0; |
911 MX_Bluetooth_PowerOff(); | |
912 //Init dive Mode | |
141 | 913 decoLock = DECO_CALC_init_as_is_start_of_dive; |
914 pStateReal->lifeData.boolResetAverageDepth = 1; | |
915 pStateReal->lifeData.boolResetStopwatch = 1; | |
38 | 916 } |
141 | 917 |
918 //End of diveMode? | |
919 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE) | |
920 { | |
921 if(modeChangeFlag) | |
922 { | |
923 *modeChangeFlag = 1; | |
924 } | |
925 createDiveSettings(); | |
38 | 926 |
141 | 927 if(pStateReal->warnings.cnsHigh) |
928 { | |
929 if(pStateReal->lifeData.cns >= 130) | |
930 dataOut.setAccidentFlag += ACCIDENT_CNSLVL2; | |
931 else if(pStateReal->lifeData.cns >= 100) | |
932 dataOut.setAccidentFlag += ACCIDENT_CNS; | |
933 } | |
934 if(pStateReal->warnings.decoMissed) | |
935 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; | |
936 } | |
937 pStateReal->mode = dataIn.mode; | |
938 pStateReal->chargeStatus = dataIn.chargeStatus; | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
939 |
141 | 940 pStateReal->lifeData.pressure_ambient_bar = ambient; |
941 pStateReal->lifeData.pressure_surface_bar = surface; | |
942 if(is_ambient_pressure_close_to_surface(&pStateReal->lifeData)) | |
943 { | |
944 pStateReal->lifeData.depth_meter = 0; | |
945 } | |
946 else | |
947 { | |
948 pStateReal->lifeData.depth_meter = meter; | |
949 } | |
950 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
951 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
|
952 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
|
953 if(pStateReal->mode != MODE_DIVE) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
954 pStateReal->lifeData.max_depth_meter = 0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
955 else |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
956 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
957 if(meter > pStateReal->lifeData.max_depth_meter) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
958 pStateReal->lifeData.max_depth_meter = meter; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
959 } |
38 | 960 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
961 if(dataIn.accidentFlags & ACCIDENT_DECOSTOP) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
962 pStateReal->decoMissed_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
963 if(dataIn.accidentFlags & ACCIDENT_CNS) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
964 pStateReal->cnsHigh_at_the_end_of_dive = 1; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
965 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
966 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
|
967 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
|
968 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
969 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; |
38 | 970 |
109
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
971 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
972 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
|
973 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
|
974 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
975 pStateReal->lifeData.compass_heading -= 180.0; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
976 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
|
977 } |
109
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
978 |
65a6e352ce08
Consider computer heading in case of a flipped display
Ideenmodellierer
parents:
51
diff
changeset
|
979 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
980 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
|
981 pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; |
38 | 982 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
983 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
|
984 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
|
985 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; |
38 | 986 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
987 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
988 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
|
989 pStateReal->compass_uTick_local_new = HAL_GetTick(); |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
990 |
141 | 991 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
|
992 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; |
141 | 993 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
|
994 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes; |
38 | 995 |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
996 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
|
997 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
|
998 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
999 if(pStateReal->mode == MODE_DIVE) |
38 | 1000 { |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1001 for(int i= 0; i <16; i++) |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1002 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 } |
38 | 1008 } |
1009 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1010 /* battery and ambient light sensors |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1011 */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1012 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
|
1013 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
|
1014 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
|
1015 } |
38 | 1016 /* now in ext_flash_write_settings() // hw 161027 |
1017 * if((pStateReal->lifeData.battery_charge > 1) && !DataEX_was_power_on() && ((uint8_t)(pStateReal->lifeData.battery_charge) != 0x10)) // get rid of 16% (0x10) | |
1018 * pSettings->lastKnownBatteryPercentage = (uint8_t)(pStateReal->lifeData.battery_charge); | |
1019 */ | |
1020 | |
1021 /* OC and CCR but no sensors -> moved to updateSetpointStateUsed(); | |
1022 float oxygen = 0; | |
1023 if(pStateReal->diveSettings.diveMode == 0) | |
1024 { | |
1025 oxygen = 1.00f; | |
1026 oxygen -= ((float)pStateReal->lifeData.actualGas.nitrogen_percentage)/100.0f; | |
1027 oxygen -= ((float)pStateReal->lifeData.actualGas.helium_percentage)/100.0f; | |
1028 pStateReal->lifeData.ppO2 = pStateReal->lifeData.pressure_ambient_bar * oxygen; | |
1029 } | |
1030 else if(pStateReal->diveSettings.diveMode == 1) | |
1031 { | |
1032 pStateReal->lifeData.ppO2 = ((float)pStateReal->lifeData.actualGas.setPoint_cbar) /100; | |
1033 } | |
1034 */ | |
1035 | |
1036 /* apnea specials | |
1037 */ | |
1038 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) | |
1039 { | |
1040 if(pStateReal->mode != MODE_DIVE) | |
1041 { | |
1042 pStateReal->lifeData.apnea_total_max_depth_meter = 0; | |
1043 pStateReal->lifeData.apnea_last_dive_time_seconds = 0; | |
1044 pStateReal->lifeData.apnea_last_max_depth_meter = 0; | |
1045 } | |
1046 else | |
1047 { | |
1048 if(pStateReal->lifeData.max_depth_meter > pStateReal->lifeData.apnea_total_max_depth_meter) | |
1049 pStateReal->lifeData.apnea_total_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1050 } | |
1051 | |
1052 if(pStateReal->lifeData.dive_time_seconds > 15) | |
1053 { | |
1054 pStateReal->lifeData.apnea_last_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1055 } | |
1056 | |
1057 if(pStateReal->lifeData.counterSecondsShallowDepth) | |
1058 { | |
1059 if(pStateReal->lifeData.max_depth_meter > 1.5f) | |
1060 { | |
1061 pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; | |
1062 } | |
1063 // eset max_depth_meter, average_depth_meter and internal values | |
1064 pStateReal->lifeData.max_depth_meter = 0; | |
1065 pStateReal->lifeData.boolResetAverageDepth = 1; | |
1066 pStateReal->lifeData.boolResetStopwatch = 1; | |
1067 } | |
1068 } | |
1069 | |
1070 /* average depth | |
1071 */ | |
1072 float *AvgDepthValue = &pStateReal->lifeData.average_depth_meter; | |
1073 float DepthNow = pStateReal->lifeData.depth_meter; | |
1074 uint32_t *AvgDepthCount = &pStateReal->lifeData.internal.average_depth_meter_Count; | |
1075 uint32_t *AvgDepthTimer = &pStateReal->lifeData.internal.average_depth_last_update_dive_time_seconds_without_surface_time; | |
1076 uint32_t AvgSecondsSinceLast; | |
1077 uint32_t DiveTime = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
1078 | |
1079 if(pStateReal->lifeData.boolResetAverageDepth) | |
1080 { | |
1081 *AvgDepthValue = DepthNow; | |
1082 *AvgDepthCount = 1; | |
1083 *AvgDepthTimer = DiveTime; | |
1084 pStateReal->lifeData.boolResetAverageDepth = 0; | |
1085 } | |
1086 else if (DiveTime > *AvgDepthTimer) | |
1087 { | |
1088 AvgSecondsSinceLast = DiveTime - *AvgDepthTimer; | |
1089 for(int i=0;i<AvgSecondsSinceLast;i++) | |
1090 { | |
1091 *AvgDepthValue = (*AvgDepthValue * *AvgDepthCount + DepthNow) / (*AvgDepthCount + 1); | |
1092 *AvgDepthCount += 1; | |
1093 } | |
1094 *AvgDepthTimer = DiveTime; | |
1095 } | |
1096 if(*AvgDepthCount == 0) | |
1097 *AvgDepthValue = 0; | |
1098 | |
1099 | |
1100 /* stop watch | |
1101 */ | |
1102 if(pStateReal->lifeData.boolResetStopwatch) | |
1103 { | |
1104 pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds = pStateReal->lifeData.dive_time_seconds; | |
1105 pStateReal->lifeData.boolResetStopwatch = 0; | |
1106 } | |
1107 pStateReal->lifeData.stopwatch_seconds = pStateReal->lifeData.dive_time_seconds - pStateReal->lifeData.internal.stopwatch_start_at_this_dive_time_seconds; | |
1108 | |
1109 /* wireless data | |
1110 */ | |
1111 uint16_t wirelessData[4][3]; | |
1112 for(int i=0;i<4;i++) | |
1113 { | |
1114 pStateReal->lifeData.wireless_data[i].ageInMilliSeconds = dataIn.data[dataIn.boolWirelessData].wireless_data[i].ageInMilliSeconds; | |
1115 pStateReal->lifeData.wireless_data[i].status = dataIn.data[dataIn.boolWirelessData].wireless_data[i].status; | |
1116 pStateReal->lifeData.wireless_data[i].numberOfBytes = dataIn.data[dataIn.boolWirelessData].wireless_data[i].numberOfBytes; | |
1117 for(int j=0;j<12;j++) | |
1118 pStateReal->lifeData.wireless_data[i].data[j] = dataIn.data[dataIn.boolWirelessData].wireless_data[i].data[j]; | |
1119 } | |
1120 | |
1121 /* old stuff | |
1122 // crc - is done in RTE 160325 | |
1123 // size at the moment 4 bytes + one empty + crc -> minimum 5 bytes (+ crc) | |
1124 // kopieren: Id, Wert, Alter | |
1125 for(int i=0;i<4;i++) | |
1126 { | |
1127 uint8_t numberOfBytes = pStateReal->lifeData.wireless_data[i].numberOfBytes - 1; | |
1128 | |
1129 if((numberOfBytes < 5) || (numberOfBytes > 7)) | |
1130 { | |
1131 wirelessData[i][0] = 0; | |
1132 wirelessData[i][1] = 0; | |
1133 wirelessData[i][2] = 0; | |
1134 } | |
1135 else | |
1136 { | |
1137 if((crc32c_checksum(pStateReal->lifeData.wireless_data[i].data, numberOfBytes, 0, 0) & 0xFF)!= pStateReal->lifeData.wireless_data[i].data[numberOfBytes]) | |
1138 { | |
1139 // no crc is send at the moment | |
1140 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1]; | |
1141 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4]; | |
1142 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1143 | |
1144 // wirelessData[i][0] = 0; | |
1145 // wirelessData[i][1] = 0; | |
1146 // wirelessData[i][2] = 0; | |
1147 | |
1148 } | |
1149 | |
1150 else | |
1151 { | |
1152 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1]; | |
1153 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4]; | |
1154 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1155 } | |
1156 } | |
1157 } | |
1158 */ | |
1159 // neu 160412 | |
1160 for(int i=0;i<4;i++) | |
1161 { | |
1162 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10) | |
1163 { | |
1164 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] >> 4) & 0x7F; | |
1165 wirelessData[i][1] = 0; | |
1166 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1167 } | |
1168 else | |
1169 { | |
1170 wirelessData[i][0] = 0; | |
1171 wirelessData[i][1] = 0; | |
1172 wirelessData[i][2] = 0; | |
1173 } | |
1174 } | |
1175 | |
1176 // aussortieren doppelte ids, j�ngster datensatz ist relevant | |
1177 for(int i=0;i<3;i++) | |
1178 { | |
1179 if(wirelessData[i][0]) | |
1180 { | |
1181 for(int j=i+1; j<4; j++) | |
1182 { | |
1183 if(wirelessData[i][0] == wirelessData[j][0]) | |
1184 { | |
1185 if(wirelessData[i][2] > wirelessData[j][2]) | |
1186 { | |
1187 wirelessData[i][0] = wirelessData[j][0]; | |
1188 wirelessData[i][1] = wirelessData[j][1]; | |
1189 wirelessData[i][2] = wirelessData[j][2]; | |
1190 } | |
1191 wirelessData[j][0] = 0; | |
1192 wirelessData[j][1] = 0; | |
1193 wirelessData[j][2] = 0; | |
1194 } | |
1195 } | |
1196 } | |
1197 } | |
1198 /* | |
1199 // neu 160325 | |
1200 for(int i=0;i<4;i++) | |
1201 { | |
1202 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10) | |
1203 { | |
1204 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1]; | |
1205 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4]; | |
1206 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds; | |
1207 } | |
1208 else | |
1209 { | |
1210 wirelessData[i][0] = 0; | |
1211 wirelessData[i][1] = 0; | |
1212 wirelessData[i][2] = 0; | |
1213 } | |
1214 } | |
1215 | |
1216 // aussortieren doppelte ids, j�ngster datensatz ist relevant | |
1217 for(int i=0;i<3;i++) | |
1218 { | |
1219 if(wirelessData[i][0]) | |
1220 { | |
1221 for(int j=i+1; j<4; j++) | |
1222 { | |
1223 if(wirelessData[i][0] == wirelessData[j][0]) | |
1224 { | |
1225 if(wirelessData[i][2] > wirelessData[j][2]) | |
1226 { | |
1227 wirelessData[i][0] = wirelessData[j][0]; | |
1228 wirelessData[i][1] = wirelessData[j][1]; | |
1229 wirelessData[i][2] = wirelessData[j][2]; | |
1230 } | |
1231 wirelessData[j][0] = 0; | |
1232 wirelessData[j][1] = 0; | |
1233 wirelessData[j][2] = 0; | |
1234 } | |
1235 } | |
1236 } | |
1237 } | |
1238 */ | |
1239 /* old | |
1240 // copy to lifeData | |
1241 for(int i=0;i<4;i++) | |
1242 { | |
1243 if((wirelessData[i][0]) && (wirelessData[i][2]) && (wirelessData[i][2] < 60000)) | |
1244 { | |
1245 for(int j=1;j<=(2*NUM_GASES+1);j++) | |
1246 { | |
1247 if(pStateReal->diveSettings.gas[j].bottle_wireless_id == wirelessData[i][0]) | |
1248 { | |
1249 pStateReal->lifeData.bottle_bar[j] = wirelessData[i][1]; | |
1250 pStateReal->lifeData.bottle_bar_age_MilliSeconds[j] = wirelessData[i][2]; | |
1251 break; | |
1252 } | |
1253 } | |
1254 } | |
1255 } | |
1256 */ | |
1257 | |
1258 | |
1259 /* PIC data | |
1260 */ | |
1261 for(int i=0;i<4;i++) | |
1262 { | |
1263 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i]; | |
1264 } | |
1265 | |
1266 /* sensorErrors | |
1267 */ | |
1268 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; | |
1269 } | |
1270 | |
1271 | |
1272 uint8_t DataEX_check_RTE_version__needs_update(void) | |
1273 { | |
1274 if(data_old__lost_connection_to_slave_counter_retry > 10) | |
1275 return 1; | |
1276 else | |
1277 { | |
1278 if(stateRealGetPointer()->data_old__lost_connection_to_slave == 0) | |
1279 { | |
1280 setActualRTEversion(dataIn.RTE_VERSION_high, dataIn.RTE_VERSION_low); | |
1281 | |
1282 if(RTEminimum_required_high() < dataIn.RTE_VERSION_high) | |
1283 return 0; | |
1284 else | |
1285 if((RTEminimum_required_high() == dataIn.RTE_VERSION_high) && (RTEminimum_required_low() <= dataIn.RTE_VERSION_low)) | |
1286 return 0; | |
1287 else | |
1288 return 1; | |
1289 } | |
1290 else | |
1291 return 0; | |
1292 } | |
1293 } | |
1294 | |
1295 | |
1296 /* Private functions ---------------------------------------------------------*/ | |
1297 | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1298 /* 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
|
1299 * 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
|
1300 */ |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1301 uint8_t DataEX_check_header_and_footer_shifted() |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1302 { |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1303 uint8_t ret = 1; |
141 | 1304 if((dataIn.footer.checkCode[0] == 0x00) |
1305 && (dataIn.footer.checkCode[1] == 0x00) | |
1306 && (dataIn.footer.checkCode[2] == 0x00) | |
1307 && (dataIn.footer.checkCode[3] == 0x00)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1308 |
141 | 1309 if((dataIn.footer.checkCode[0] == 0xff) |
1310 && (dataIn.footer.checkCode[1] == 0xff) | |
1311 && (dataIn.footer.checkCode[2] == 0xff) | |
1312 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; } | |
137
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1313 |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1314 return ret; |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1315 } |
9eda5a75c5fd
Only copy data if data connection to RTE is valid
Ideenmodellierer
parents:
133
diff
changeset
|
1316 |
38 | 1317 uint8_t DataEX_check_header_and_footer_ok(void) |
1318 { | |
1319 if(dataIn.header.checkCode[0] != 0xA1) | |
1320 return 0; | |
141 | 1321 #if USE_OLD_HEADER_FORMAT |
38 | 1322 if(dataIn.header.checkCode[1] != 0xA2) |
1323 return 0; | |
1324 if(dataIn.header.checkCode[2] != 0xA3) | |
1325 return 0; | |
141 | 1326 #endif |
38 | 1327 if(dataIn.header.checkCode[3] != 0xA4) |
1328 return 0; | |
1329 if(dataIn.footer.checkCode[0] != 0xE1) | |
1330 return 0; | |
1331 if(dataIn.footer.checkCode[1] != 0xE2) | |
1332 return 0; | |
1333 if(dataIn.footer.checkCode[2] != 0xE3) | |
1334 return 0; | |
1335 if(dataIn.footer.checkCode[3] != 0xE4) | |
1336 return 0; | |
1337 | |
1338 return 1; | |
1339 } | |
1340 | |
1341 uint8_t DataEX_check_header_and_footer_devicedata(void) | |
1342 { | |
1343 if(dataIn.header.checkCode[0] != 0xDF) | |
1344 return 0; | |
1345 if(dataIn.header.checkCode[1] != 0xDE) | |
1346 return 0; | |
1347 if(dataIn.header.checkCode[2] != 0xDD) | |
1348 return 0; | |
1349 if(dataIn.header.checkCode[3] != 0xDC) | |
1350 return 0; | |
1351 if(dataIn.footer.checkCode[0] != 0xE1) | |
1352 return 0; | |
1353 if(dataIn.footer.checkCode[1] != 0xE2) | |
1354 return 0; | |
1355 if(dataIn.footer.checkCode[2] != 0xE3) | |
1356 return 0; | |
1357 if(dataIn.footer.checkCode[3] != 0xE4) | |
1358 return 0; | |
1359 | |
1360 return 1; | |
1361 } | |
1362 | |
1363 | |
1364 |