comparison Discovery/Src/data_exchange_main.c @ 200:7116c0ffb862

Merged in janlmulder/ostc4/div-fixes-cleaup-2 (pull request #8) 2 (simple) bugfixes and again some cleanup
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Fri, 22 Mar 2019 08:15:30 +0000
parents 878dc9e0dbc5
children 9fc06e1e0f66
comparison
equal deleted inserted replaced
195:05df3b395615 200:7116c0ffb862
36 on start it is INT32_MIN, INT32_MAX and 0 36 on start it is INT32_MIN, INT32_MAX and 0
37 as initialized in data_central.c variable declaration 37 as initialized in data_central.c variable declaration
38 38
39 second small CPU gets request to send its device data 39 second small CPU gets request to send its device data
40 40
41 on receiption the data is merged with the data in externLogbookFlash, 41 on reception the data is merged with the data in externLogbookFlash,
42 stored on the externLogbookFlash and from now on send to small CPU 42 stored on the externLogbookFlash and from now on send to small CPU
43 43
44 ============================================================================== 44 ==============================================================================
45 ##### Magnet Reset ##### 45 ##### Magnet Reset #####
46 ============================================================================== 46 ==============================================================================
54 ****************************************************************************** 54 ******************************************************************************
55 */ 55 */
56 56
57 /* Includes ------------------------------------------------------------------*/ 57 /* Includes ------------------------------------------------------------------*/
58 #include <stdlib.h> 58 #include <stdlib.h>
59 #include <string.h> // for memcopy 59 #include <string.h> // for memcpy
60 #include "stm32f4xx_hal.h" 60 #include "stm32f4xx_hal.h"
61 #include "stdio.h" 61 #include "stdio.h"
62 #include "ostc.h" 62 #include "ostc.h"
63 #include "settings.h" 63 #include "settings.h"
64 #include "data_central.h" 64 #include "data_central.h"
72 #include "buehlmann.h" 72 #include "buehlmann.h"
73 #include "externLogbookFlash.h" 73 #include "externLogbookFlash.h"
74 74
75 75
76 /* Exported variables --------------------------------------------------------*/ 76 /* Exported variables --------------------------------------------------------*/
77 uint8_t wasPowerOn = 0; 77 static uint8_t wasPowerOn = 0;
78 confirmbit8_Type requestNecessary = { .uw = 0 }; 78 static confirmbit8_Type requestNecessary = { .uw = 0 };
79 uint8_t wasUpdateNotPowerOn = 0; 79 static uint8_t wasUpdateNotPowerOn = 0;
80 80
81 /* Private variables with external access ------------------------------------*/ 81 /* Private variables with external access ------------------------------------*/
82 82
83
84 /* Private variables ---------------------------------------------------------*/ 83 /* Private variables ---------------------------------------------------------*/
85 uint8_t told_reset_logik_alles_ok = 0; 84 static uint8_t told_reset_logik_alles_ok = 0;
86 85
87 SDataReceiveFromMaster dataOut; 86 static SDataReceiveFromMaster dataOut;
88 SDataExchangeSlaveToMaster dataIn; 87 static SDataExchangeSlaveToMaster dataIn;
89 88
90 uint8_t data_old__lost_connection_to_slave_counter_temp = 0; 89 static uint8_t data_old__lost_connection_to_slave_counter_temp = 0;
91 uint8_t data_old__lost_connection_to_slave_counter_retry = 0; 90 static uint8_t data_old__lost_connection_to_slave_counter_retry = 0;
92 uint32_t data_old__lost_connection_to_slave_counter_total = 0; 91 static uint32_t data_old__lost_connection_to_slave_counter_total = 0;
93 92
94 /* Private types -------------------------------------------------------------*/ 93 /* Private types -------------------------------------------------------------*/
95 94
96 typedef enum
97 {
98 CPU2_TRANSFER_STOP = 0x00, /*!< */
99 CPU2_TRANSFER_TEST_REQUEST = 0x01, /*!< */
100 CPU2_TRANSFER_TEST_RECEIVE = 0x02, /*!< */
101 CPU2_TRANSFER_SEND_OK = 0x03, /*!< */
102 CPU2_TRANSFER_SEND_FALSE = 0x04, /*!< */
103 CPU2_TRANSFER_DATA = 0x05, /*!< */
104 }CPU2_TRANSFER_StatusTypeDef;
105
106 const uint8_t header_test_request[4] = {0xBB, 0x00, 0x00, 0xBB};
107 const uint8_t header_test_receive[4] = {0xBB, 0x01, 0x01, 0xBB};
108 const uint8_t header_false[4] = {0xBB, 0xFF, 0xFF, 0xBB};
109 const uint8_t header_correct[4] = {0xBB, 0xCC, 0xCC, 0xBB};
110 const uint8_t header_data[4] = {0xAA, 0x01, 0x01, 0xAA};
111
112 /* Private function prototypes -----------------------------------------------*/ 95 /* Private function prototypes -----------------------------------------------*/
113 uint8_t DataEX_check_header_and_footer_ok(void); 96 static uint8_t DataEX_check_header_and_footer_ok(void);
114 uint8_t DataEX_check_header_and_footer_shifted(void); 97 static uint8_t DataEX_check_header_and_footer_shifted(void);
115 uint8_t DataEX_check_header_and_footer_devicedata(void); 98 static uint8_t DataEX_check_header_and_footer_devicedata(void);
116 void DataEX_check_DeviceData(void); 99 static void DataEX_check_DeviceData(void);
117 100
118 /* Exported functions --------------------------------------------------------*/ 101 /* Exported functions --------------------------------------------------------*/
119 void DataEX_set_update_RTE_not_power_on(void)
120 {
121 wasUpdateNotPowerOn = 1;
122 }
123
124 102
125 uint8_t DataEX_was_power_on(void) 103 uint8_t DataEX_was_power_on(void)
126 { 104 {
127 return wasPowerOn; 105 return wasPowerOn;
128 } 106 }
129 107
130 uint8_t count_DataEX_Error_Handler = 0; 108 static uint8_t count_DataEX_Error_Handler = 0;
131 uint8_t last_error_DataEX_Error_Handler = 0; 109 static uint8_t last_error_DataEX_Error_Handler = 0;
132 110
133 void DataEX_Error_Handler(uint8_t answer) 111 static void DataEX_Error_Handler(uint8_t answer)
134 { 112 {
135 count_DataEX_Error_Handler++; 113 count_DataEX_Error_Handler++;
136 last_error_DataEX_Error_Handler = answer; 114 last_error_DataEX_Error_Handler = answer;
137 115
138 /* A wrong footer indicates a communication interrupt. State machine is waiting for new data which is not received because no new transmission is triggered */ 116 /* A wrong footer indicates a communication interrupt. State machine is waiting for new data which is not received because no new transmission is triggered */
150 { 128 {
151 return data_old__lost_connection_to_slave_counter_total; 129 return data_old__lost_connection_to_slave_counter_total;
152 } 130 }
153 131
154 132
155 uint32_t DataEX_time_elapsed_ms(uint32_t ticksstart,uint32_t ticksnow) 133 SDataReceiveFromMaster *dataOutGetPointer(void)
156 {
157
158 if(ticksstart <= ticksnow)
159 {
160 return ticksnow - ticksstart;
161 }
162 else
163 {
164 return 0xFFFFFFFF - ticksstart + ticksnow;
165 }
166
167 }
168
169 SDataReceiveFromMaster * dataOutGetPointer(void)
170 { 134 {
171 return &dataOut; 135 return &dataOut;
172 } 136 }
173 137
174 void DataEX_init(void) 138 void DataEX_init(void)
177 pStateReal->data_old__lost_connection_to_slave = 0; //initial value 141 pStateReal->data_old__lost_connection_to_slave = 0; //initial value
178 data_old__lost_connection_to_slave_counter_temp = 0; 142 data_old__lost_connection_to_slave_counter_temp = 0;
179 data_old__lost_connection_to_slave_counter_total = 0; 143 data_old__lost_connection_to_slave_counter_total = 0;
180 144
181 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster)); 145 memset((void *)&dataOut, 0, sizeof(SDataReceiveFromMaster));
182 // old 160307: for(int i=0;i<EXCHANGE_BUFFERSIZE;i++)
183 // *(uint8_t *)(((uint32_t)&dataOut) + i) = 0;
184 146
185 dataOut.header.checkCode[0] = 0xBB; 147 dataOut.header.checkCode[0] = 0xBB;
186 dataOut.header.checkCode[1] = 0x01; 148 dataOut.header.checkCode[1] = 0x01;
187 dataOut.header.checkCode[2] = 0x01; 149 dataOut.header.checkCode[2] = 0x01;
188 dataOut.header.checkCode[3] = 0xBB; 150 dataOut.header.checkCode[3] = 0xBB;
192 dataOut.footer.checkCode[2] = 0xF2; 154 dataOut.footer.checkCode[2] = 0xF2;
193 dataOut.footer.checkCode[3] = 0xF1; 155 dataOut.footer.checkCode[3] = 0xF1;
194 } 156 }
195 157
196 158
197 void DataEx_call_helper_requests(void) 159 static void DataEx_call_helper_requests(void)
198 { 160 {
199 static uint8_t setDateWasSend = 0; 161 static uint8_t setDateWasSend = 0;
200 static uint8_t setTimeWasSend = 0; 162 static uint8_t setTimeWasSend = 0;
201 static uint8_t calibrateCompassWasSend = 0; 163 static uint8_t calibrateCompassWasSend = 0;
202 static uint8_t setButtonSensitivityWasSend = 0; 164 static uint8_t setButtonSensitivityWasSend = 0;
338 300
339 return 1; 301 return 1;
340 } 302 }
341 303
342 304
343 uint32_t SPI_CALLBACKS; 305 static uint32_t SPI_CALLBACKS;
344 uint32_t get_num_SPI_CALLBACKS(void){ 306 uint32_t get_num_SPI_CALLBACKS(void){
345 return SPI_CALLBACKS; 307 return SPI_CALLBACKS;
346 } 308 }
347 309
348 SDataExchangeSlaveToMaster* get_dataInPointer(void){ 310 SDataExchangeSlaveToMaster* get_dataInPointer(void){
356 { 318 {
357 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); 319 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
358 SPI_CALLBACKS+=1; 320 SPI_CALLBACKS+=1;
359 } 321 }
360 } 322 }
361
362
363
364 323
365 324
366 void DateEx_copy_to_dataOut(void) 325 void DateEx_copy_to_dataOut(void)
367 { 326 {
368 const SDiveState * pStateReal = stateRealGetPointer(); 327 const SDiveState * pStateReal = stateRealGetPointer();
400 else 359 else
401 { 360 {
402 dataOut.revisionHardware = 0xFF; 361 dataOut.revisionHardware = 0xFF;
403 dataOut.revisionCRCx0x7A = 0xFF; 362 dataOut.revisionCRCx0x7A = 0xFF;
404 } 363 }
405
406 /*
407 for(int i = 0; i< 16; i++)
408 {
409 dataOut.data.VPM_adjusted_critical_radius_he[i] = pStateReal->vpm.adjusted_critical_radius_he[i];
410 dataOut.data.VPM_adjusted_critical_radius_n2[i] = pStateReal->vpm.adjusted_critical_radius_n2[i];
411 dataOut.data.VPM_adjusted_crushing_pressure_he[i] = pStateReal->vpm.adjusted_crushing_pressure_he[i];
412 dataOut.data.VPM_adjusted_crushing_pressure_n2[i] = pStateReal->vpm.adjusted_crushing_pressure_n2[i];
413 dataOut.data.VPM_initial_allowable_gradient_he[i] = pStateReal->vpm.initial_allowable_gradient_he[i];
414 dataOut.data.VPM_initial_allowable_gradient_n2[i] = pStateReal->vpm.initial_allowable_gradient_n2[i];
415 dataOut.data.VPM_max_actual_gradient[i] = pStateReal->vpm.max_actual_gradient[i];
416 }
417 */
418 364
419 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok) 365 if(DataEX_check_header_and_footer_ok() && !told_reset_logik_alles_ok)
420 { 366 {
421 MX_tell_reset_logik_alles_ok(); 367 MX_tell_reset_logik_alles_ok();
422 told_reset_logik_alles_ok = 1; 368 told_reset_logik_alles_ok = 1;
474 * ToDo by Peter 420 * ToDo by Peter
475 * copy VPM stuff etc. pp. 421 * copy VPM stuff etc. pp.
476 * was void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm); 422 * was void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm);
477 */ 423 */
478 } 424 }
479
480
481 425
482 if(decoLock == DECO_CALC_FINSHED_Buehlmann) 426 if(decoLock == DECO_CALC_FINSHED_Buehlmann)
483 { 427 {
484 428
485 } 429 }
533 } 477 }
534 decoLock = DECO_CALC_ready; 478 decoLock = DECO_CALC_ready;
535 } 479 }
536 480
537 481
538 void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) 482 static void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead)
539 { 483 {
540 lineWrite->date_rtc_dr = lineRead->date_rtc_dr; 484 lineWrite->date_rtc_dr = lineRead->date_rtc_dr;
541 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; 485 lineWrite->time_rtc_tr = lineRead->time_rtc_tr;
542 lineWrite->value_int32 = lineRead->value_int32; 486 lineWrite->value_int32 = lineRead->value_int32;
543 } 487 }
544 488
545 489 static void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg)
546
547 void DataEX_helper_SetTime(RTC_TimeTypeDef inStimestructure, uint32_t *outTimetmpreg)
548 { 490 {
549 inStimestructure.TimeFormat = RTC_HOURFORMAT_24; 491 inStimestructure.TimeFormat = RTC_HOURFORMAT_24;
550 492
551 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \ 493 *outTimetmpreg = (uint32_t)(((uint32_t)RTC_ByteToBcd2(inStimestructure.Hours) << 16U) | \
552 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \ 494 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Minutes) << 8U) | \
553 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \ 495 ((uint32_t)RTC_ByteToBcd2(inStimestructure.Seconds)) | \
554 (((uint32_t)inStimestructure.TimeFormat) << 16U)); 496 (((uint32_t)inStimestructure.TimeFormat) << 16U));
555 } 497 }
556 498
557 499
558 void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg) 500 static void DataEX_helper_SetDate(RTC_DateTypeDef inSdatestructure, uint32_t *outDatetmpreg)
559 { 501 {
560 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \ 502 *outDatetmpreg = (((uint32_t)RTC_ByteToBcd2(inSdatestructure.Year) << 16U) | \
561 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \ 503 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Month) << 8U) | \
562 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \ 504 ((uint32_t)RTC_ByteToBcd2(inSdatestructure.Date)) | \
563 ((uint32_t)inSdatestructure.WeekDay << 13U)); 505 ((uint32_t)inSdatestructure.WeekDay << 13U));
564 } 506 }
565 507
566 508
567 509
568 void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) 510 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite)
569 { 511 {
570 RTC_DateTypeDef sdatestructure; 512 RTC_DateTypeDef sdatestructure;
571 RTC_TimeTypeDef stimestructure; 513 RTC_TimeTypeDef stimestructure;
572 514
573 stimestructure.Hours = 1; 515 stimestructure.Hours = 1;
582 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); 524 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr);
583 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); 525 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr);
584 } 526 }
585 527
586 528
587 uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite) 529 static uint8_t DataEX_helper_Check_And_Correct_Date_deviceData(SDeviceLine *lineWrite)
588 { 530 {
589 RTC_DateTypeDef sdatestructure; 531 RTC_DateTypeDef sdatestructure;
590 RTC_TimeTypeDef stimestructure; 532 RTC_TimeTypeDef stimestructure;
591 533
592 // from lineWrite to structure 534 // from lineWrite to structure
602 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); 544 DataEX_helper_set_Unknown_Date_deviceData(lineWrite);
603 return 1; 545 return 1;
604 } 546 }
605 547
606 548
607 uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to) 549 static uint8_t DataEX_helper_Check_And_Correct_Value_deviceData(SDeviceLine *lineWrite, int32_t from, int32_t to)
608 { 550 {
609 if(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to) 551 if(lineWrite->value_int32 >= from && lineWrite->value_int32 <= to)
610 return 0; 552 return 0;
611 553
612 if(lineWrite->value_int32 < from) 554 if(lineWrite->value_int32 < from)
617 DataEX_helper_set_Unknown_Date_deviceData(lineWrite); 559 DataEX_helper_set_Unknown_Date_deviceData(lineWrite);
618 return 0; 560 return 0;
619 } 561 }
620 562
621 563
622 void DataEX_check_DeviceData(void) 564 static void DataEX_check_DeviceData(void)
623 { 565 {
624 SDevice *DeviceData = stateDeviceGetPointerWrite(); 566 SDevice *DeviceData = stateDeviceGetPointerWrite();
625 567
626 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles); 568 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCompleteCycles);
627 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles); 569 DataEX_helper_Check_And_Correct_Date_deviceData(&DeviceData->batteryChargeCycles);
641 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100); 583 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->temperatureMinimum, -30*100, 150*100);
642 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, -1*1000, 6*1000); 584 DataEX_helper_Check_And_Correct_Value_deviceData(&DeviceData->voltageMinimum, -1*1000, 6*1000);
643 } 585 }
644 586
645 587
646 void DataEX_merge_DeviceData_and_store(void) 588 static void DataEX_merge_DeviceData_and_store(void)
647 { 589 {
648 uint16_t dataLengthRead; 590 uint16_t dataLengthRead;
649 SDevice DeviceDataFlash; 591 SDevice DeviceDataFlash;
650 SDevice *DeviceData = stateDeviceGetPointerWrite(); 592 SDevice *DeviceData = stateDeviceGetPointerWrite();
651 593
655 { 597 {
656 ext_flash_write_devicedata(); 598 ext_flash_write_devicedata();
657 return; 599 return;
658 } 600 }
659 601
660 /*
661 SDeviceLine batteryChargeCycles;
662 SDeviceLine batteryChargeCompleteCycles;
663 SDeviceLine temperatureMinimum;
664 SDeviceLine temperatureMaximum;
665 SDeviceLine depthMaximum;
666 SDeviceLine diveCycles;
667 SDeviceLine voltageMinimum;
668 */
669
670 /* max values */ 602 /* max values */
671 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) 603 if(DeviceData->batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32)
672 { 604 {
673 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); 605 DataEX_helper_copy_deviceData(&DeviceData->batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles);
674 } 606 }
706 DataEX_check_DeviceData (); 638 DataEX_check_DeviceData ();
707 ext_flash_write_devicedata(); 639 ext_flash_write_devicedata();
708 } 640 }
709 641
710 642
711 void DataEX_copy_to_DeviceData(void) 643 static void DataEX_copy_to_DeviceData(void)
712 { 644 {
713 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; 645 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn;
714 SDevice * pDeviceState = stateDeviceGetPointerWrite(); 646 SDevice * pDeviceState = stateDeviceGetPointerWrite();
715 647
716 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice)); 648 memcpy(pDeviceState, &dataInDevice->DeviceData[dataInDevice->boolDeviceData], sizeof(SDevice));
717 } 649 }
718 650
719 651
720 void DataEX_copy_to_VpmRepetitiveData(void) 652 static void DataEX_copy_to_VpmRepetitiveData(void)
721 { 653 {
722 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn; 654 SDataExchangeSlaveToMasterDeviceData * dataInDevice = (SDataExchangeSlaveToMasterDeviceData *)&dataIn;
723 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite(); 655 SVpmRepetitiveData * pVpmState = stateVpmRepetitiveDataGetPointerWrite();
724 656
725 if(dataInDevice->boolVpmRepetitiveDataValid) 657 if(dataInDevice->boolVpmRepetitiveDataValid)
918 decoLock = DECO_CALC_init_as_is_start_of_dive; 850 decoLock = DECO_CALC_init_as_is_start_of_dive;
919 pStateReal->lifeData.boolResetAverageDepth = 1; 851 pStateReal->lifeData.boolResetAverageDepth = 1;
920 pStateReal->lifeData.boolResetStopwatch = 1; 852 pStateReal->lifeData.boolResetStopwatch = 1;
921 } 853 }
922 854
855 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns;
856 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu;
857 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes;
858 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes;
859
923 //End of diveMode? 860 //End of diveMode?
924 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE) 861 if(pStateReal->mode == MODE_DIVE && dataIn.mode != MODE_DIVE)
925 { 862 {
926 if(modeChangeFlag) 863 if(modeChangeFlag)
927 { 864 {
969 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds; 906 pStateReal->lifeData.dive_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].divetime_seconds;
970 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time; 907 pStateReal->lifeData.dive_time_seconds_without_surface_time = (int32_t)dataIn.data[dataIn.boolTimeData].dive_time_seconds_without_surface_time;
971 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth; 908 pStateReal->lifeData.counterSecondsShallowDepth = dataIn.data[dataIn.boolTimeData].counterSecondsShallowDepth;
972 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds; 909 pStateReal->lifeData.surface_time_seconds = (int32_t)dataIn.data[dataIn.boolTimeData].surfacetime_seconds;
973 910
974
975 pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading; 911 pStateReal->lifeData.compass_heading = dataIn.data[dataIn.boolCompassData].compass_heading;
976 if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */ 912 if(settingsGetPointer()->FlipDisplay) /* consider that diver is targeting into the opposite direction */
977 { 913 {
978 pStateReal->lifeData.compass_heading -= 180.0; 914 pStateReal->lifeData.compass_heading -= 180.0;
979 if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0; 915 if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0;
987 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f; 923 pStateReal->lifeData.compass_DZ_f = dataIn.data[dataIn.boolCompassData].compass_DZ_f;
988 924
989 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new; 925 pStateReal->compass_uTick_old = pStateReal->compass_uTick_new;
990 pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick; 926 pStateReal->compass_uTick_new = dataIn.data[dataIn.boolCompassData].compass_uTick;
991 pStateReal->compass_uTick_local_new = HAL_GetTick(); 927 pStateReal->compass_uTick_local_new = HAL_GetTick();
992
993 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns;
994 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu;
995 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes;
996 pStateReal->lifeData.desaturation_time_minutes = dataIn.data[dataIn.boolToxicData].desaturation_time_minutes;
997 928
998 memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar)); 929 memcpy(pStateReal->lifeData.tissue_nitrogen_bar, dataIn.data[dataIn.boolTisssueData].tissue_nitrogen_bar,sizeof(pStateReal->lifeData.tissue_nitrogen_bar));
999 memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar)); 930 memcpy(pStateReal->lifeData.tissue_helium_bar, dataIn.data[dataIn.boolTisssueData].tissue_helium_bar,sizeof(pStateReal->lifeData.tissue_helium_bar));
1000 931
1001 if(pStateReal->mode == MODE_DIVE) 932 if(pStateReal->mode == MODE_DIVE)
1013 */ 944 */
1014 pStateReal->lifeData.ambient_light_level = dataIn.data[dataIn.boolAmbientLightData].ambient_light_level; 945 pStateReal->lifeData.ambient_light_level = dataIn.data[dataIn.boolAmbientLightData].ambient_light_level;
1015 pStateReal->lifeData.battery_charge = dataIn.data[dataIn.boolBatteryData].battery_charge; 946 pStateReal->lifeData.battery_charge = dataIn.data[dataIn.boolBatteryData].battery_charge;
1016 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage; 947 pStateReal->lifeData.battery_voltage = dataIn.data[dataIn.boolBatteryData].battery_voltage;
1017 } 948 }
1018 /* now in ext_flash_write_settings() // hw 161027
1019 * if((pStateReal->lifeData.battery_charge > 1) && !DataEX_was_power_on() && ((uint8_t)(pStateReal->lifeData.battery_charge) != 0x10)) // get rid of 16% (0x10)
1020 * pSettings->lastKnownBatteryPercentage = (uint8_t)(pStateReal->lifeData.battery_charge);
1021 */
1022
1023 /* OC and CCR but no sensors -> moved to updateSetpointStateUsed();
1024 float oxygen = 0;
1025 if(pStateReal->diveSettings.diveMode == 0)
1026 {
1027 oxygen = 1.00f;
1028 oxygen -= ((float)pStateReal->lifeData.actualGas.nitrogen_percentage)/100.0f;
1029 oxygen -= ((float)pStateReal->lifeData.actualGas.helium_percentage)/100.0f;
1030 pStateReal->lifeData.ppO2 = pStateReal->lifeData.pressure_ambient_bar * oxygen;
1031 }
1032 else if(pStateReal->diveSettings.diveMode == 1)
1033 {
1034 pStateReal->lifeData.ppO2 = ((float)pStateReal->lifeData.actualGas.setPoint_cbar) /100;
1035 }
1036 */
1037 949
1038 /* apnea specials 950 /* apnea specials
1039 */ 951 */
1040 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) 952 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea)
1041 { 953 {
1118 pStateReal->lifeData.wireless_data[i].numberOfBytes = dataIn.data[dataIn.boolWirelessData].wireless_data[i].numberOfBytes; 1030 pStateReal->lifeData.wireless_data[i].numberOfBytes = dataIn.data[dataIn.boolWirelessData].wireless_data[i].numberOfBytes;
1119 for(int j=0;j<12;j++) 1031 for(int j=0;j<12;j++)
1120 pStateReal->lifeData.wireless_data[i].data[j] = dataIn.data[dataIn.boolWirelessData].wireless_data[i].data[j]; 1032 pStateReal->lifeData.wireless_data[i].data[j] = dataIn.data[dataIn.boolWirelessData].wireless_data[i].data[j];
1121 } 1033 }
1122 1034
1123 /* old stuff
1124 // crc - is done in RTE 160325
1125 // size at the moment 4 bytes + one empty + crc -> minimum 5 bytes (+ crc)
1126 // kopieren: Id, Wert, Alter
1127 for(int i=0;i<4;i++)
1128 {
1129 uint8_t numberOfBytes = pStateReal->lifeData.wireless_data[i].numberOfBytes - 1;
1130
1131 if((numberOfBytes < 5) || (numberOfBytes > 7))
1132 {
1133 wirelessData[i][0] = 0;
1134 wirelessData[i][1] = 0;
1135 wirelessData[i][2] = 0;
1136 }
1137 else
1138 {
1139 if((crc32c_checksum(pStateReal->lifeData.wireless_data[i].data, numberOfBytes, 0, 0) & 0xFF)!= pStateReal->lifeData.wireless_data[i].data[numberOfBytes])
1140 {
1141 // no crc is send at the moment
1142 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1];
1143 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4];
1144 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
1145
1146 // wirelessData[i][0] = 0;
1147 // wirelessData[i][1] = 0;
1148 // wirelessData[i][2] = 0;
1149
1150 }
1151
1152 else
1153 {
1154 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1];
1155 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4];
1156 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
1157 }
1158 }
1159 }
1160 */
1161 // neu 160412 1035 // neu 160412
1162 for(int i=0;i<4;i++) 1036 for(int i=0;i<4;i++)
1163 { 1037 {
1164 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10) 1038 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10)
1165 { 1039 {
1195 wirelessData[j][2] = 0; 1069 wirelessData[j][2] = 0;
1196 } 1070 }
1197 } 1071 }
1198 } 1072 }
1199 } 1073 }
1200 /* 1074
1201 // neu 160325
1202 for(int i=0;i<4;i++)
1203 {
1204 if(pStateReal->lifeData.wireless_data[i].numberOfBytes == 10)
1205 {
1206 wirelessData[i][0] = (pStateReal->lifeData.wireless_data[i].data[0] * 256) + pStateReal->lifeData.wireless_data[i].data[1];
1207 wirelessData[i][1] = (pStateReal->lifeData.wireless_data[i].data[3] * 256) + pStateReal->lifeData.wireless_data[i].data[4];
1208 wirelessData[i][2] = pStateReal->lifeData.wireless_data[i].ageInMilliSeconds;
1209 }
1210 else
1211 {
1212 wirelessData[i][0] = 0;
1213 wirelessData[i][1] = 0;
1214 wirelessData[i][2] = 0;
1215 }
1216 }
1217
1218 // aussortieren doppelte ids, j�ngster datensatz ist relevant
1219 for(int i=0;i<3;i++)
1220 {
1221 if(wirelessData[i][0])
1222 {
1223 for(int j=i+1; j<4; j++)
1224 {
1225 if(wirelessData[i][0] == wirelessData[j][0])
1226 {
1227 if(wirelessData[i][2] > wirelessData[j][2])
1228 {
1229 wirelessData[i][0] = wirelessData[j][0];
1230 wirelessData[i][1] = wirelessData[j][1];
1231 wirelessData[i][2] = wirelessData[j][2];
1232 }
1233 wirelessData[j][0] = 0;
1234 wirelessData[j][1] = 0;
1235 wirelessData[j][2] = 0;
1236 }
1237 }
1238 }
1239 }
1240 */
1241 /* old
1242 // copy to lifeData
1243 for(int i=0;i<4;i++)
1244 {
1245 if((wirelessData[i][0]) && (wirelessData[i][2]) && (wirelessData[i][2] < 60000))
1246 {
1247 for(int j=1;j<=(2*NUM_GASES+1);j++)
1248 {
1249 if(pStateReal->diveSettings.gas[j].bottle_wireless_id == wirelessData[i][0])
1250 {
1251 pStateReal->lifeData.bottle_bar[j] = wirelessData[i][1];
1252 pStateReal->lifeData.bottle_bar_age_MilliSeconds[j] = wirelessData[i][2];
1253 break;
1254 }
1255 }
1256 }
1257 }
1258 */
1259
1260
1261 /* PIC data 1075 /* PIC data
1262 */ 1076 */
1263 for(int i=0;i<4;i++) 1077 for(int i=0;i<4;i++)
1264 { 1078 {
1265 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i]; 1079 pStateReal->lifeData.buttonPICdata[i] = dataIn.data[dataIn.boolPICdata].button_setting[i];
1295 } 1109 }
1296 1110
1297 1111
1298 /* Private functions ---------------------------------------------------------*/ 1112 /* Private functions ---------------------------------------------------------*/
1299 1113
1300 /* Check if there is an empty frame providec by RTE (all 0) or even no data provided by RTE (all 0xFF) 1114 /* Check if there is an empty frame provided by RTE (all 0) or even no data provided by RTE (all 0xFF)
1301 * If that is not the case the DMA is somehow not in sync 1115 * If that is not the case the DMA is somehow not in sync
1302 */ 1116 */
1303 uint8_t DataEX_check_header_and_footer_shifted() 1117 static uint8_t DataEX_check_header_and_footer_shifted()
1304 { 1118 {
1305 uint8_t ret = 1; 1119 uint8_t ret = 1;
1306 if((dataIn.footer.checkCode[0] == 0x00) 1120 if((dataIn.footer.checkCode[0] == 0x00)
1307 && (dataIn.footer.checkCode[1] == 0x00) 1121 && (dataIn.footer.checkCode[1] == 0x00)
1308 && (dataIn.footer.checkCode[2] == 0x00) 1122 && (dataIn.footer.checkCode[2] == 0x00)
1314 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; } 1128 && (dataIn.footer.checkCode[3] == 0xff)) { ret = 0; }
1315 1129
1316 return ret; 1130 return ret;
1317 } 1131 }
1318 1132
1319 uint8_t DataEX_check_header_and_footer_ok(void) 1133 static uint8_t DataEX_check_header_and_footer_ok(void)
1320 { 1134 {
1321 if(dataIn.header.checkCode[0] != 0xA1) 1135 if(dataIn.header.checkCode[0] != 0xA1)
1322 return 0; 1136 return 0;
1323 #if USE_OLD_HEADER_FORMAT 1137 #if USE_OLD_HEADER_FORMAT
1324 if(dataIn.header.checkCode[1] != 0xA2) 1138 if(dataIn.header.checkCode[1] != 0xA2)
1338 return 0; 1152 return 0;
1339 1153
1340 return 1; 1154 return 1;
1341 } 1155 }
1342 1156
1343 uint8_t DataEX_check_header_and_footer_devicedata(void) 1157 static uint8_t DataEX_check_header_and_footer_devicedata(void)
1344 { 1158 {
1345 if(dataIn.header.checkCode[0] != 0xDF) 1159 if(dataIn.header.checkCode[0] != 0xDF)
1346 return 0; 1160 return 0;
1347 if(dataIn.header.checkCode[1] != 0xDE) 1161 if(dataIn.header.checkCode[1] != 0xDE)
1348 return 0; 1162 return 0;
1359 if(dataIn.footer.checkCode[3] != 0xE4) 1173 if(dataIn.footer.checkCode[3] != 0xE4)
1360 return 0; 1174 return 0;
1361 1175
1362 return 1; 1176 return 1;
1363 } 1177 }
1364
1365
1366