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