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