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