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