comparison Discovery/Src/data_exchange_main.c @ 981:c6c781a2e85b default tip

Merge into default
author heinrichsweikamp
date Tue, 11 Feb 2025 18:12:00 +0100 (45 hours ago)
parents 3420e3ba698d
children
comparison
equal deleted inserted replaced
871:f7318457df4d 981:c6c781a2e85b
70 #include "simulation.h" 70 #include "simulation.h"
71 #include "tCCR.h" 71 #include "tCCR.h"
72 #include "timer.h" 72 #include "timer.h"
73 #include "buehlmann.h" 73 #include "buehlmann.h"
74 #include "externLogbookFlash.h" 74 #include "externLogbookFlash.h"
75 #include "vpm.h"
76 #include "check_warning.h"
75 77
76 /* #define TESTBENCH */ 78 /* #define TESTBENCH */
77 79
78 /* Exported variables --------------------------------------------------------*/ 80 /* Exported variables --------------------------------------------------------*/
79 static uint8_t wasPowerOn = 0; 81 static uint8_t wasPowerOn = 0;
408 break; 410 break;
409 case SENSOR_DIGO2M: SensorActive[SENSOR_DIGO2] = 1; 411 case SENSOR_DIGO2M: SensorActive[SENSOR_DIGO2] = 1;
410 break; 412 break;
411 case SENSOR_CO2: SensorActive[SENSOR_CO2] = 1; 413 case SENSOR_CO2: SensorActive[SENSOR_CO2] = 1;
412 break; 414 break;
415 #if defined ENABLE_GPIO_V2 || defined ENABLE_GNSS_SUPPORT
416 case SENSOR_GNSS: SensorActive[SENSOR_GNSS] = 1;
417 break;
418 #endif
413 #ifdef ENABLE_SENTINEL_MODE 419 #ifdef ENABLE_SENTINEL_MODE
414 case SENSOR_SENTINEL: SensorActive[SENSOR_SENTINEL] = 1; 420 case SENSOR_SENTINEL: SensorActive[SENSOR_SENTINEL] = 1;
415 break; 421 break;
416 #endif 422 #endif
417 default: 423 default:
421 427
422 if(SensorActive[SENSOR_ANALOG]) 428 if(SensorActive[SENSOR_ANALOG])
423 { 429 {
424 externalInterface_Cmd |= EXT_INTERFACE_ADC_ON | EXT_INTERFACE_33V_ON; 430 externalInterface_Cmd |= EXT_INTERFACE_ADC_ON | EXT_INTERFACE_33V_ON;
425 } 431 }
426 if(SensorActive[SENSOR_DIGO2]) 432 if((SensorActive[SENSOR_DIGO2]) || (SensorActive[SENSOR_CO2])|| (SensorActive[SENSOR_GNSS]))
427 { 433 {
428 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_O2; 434 externalInterface_Cmd |= EXT_INTERFACE_33V_ON;
429 }
430 else if(SensorActive[SENSOR_CO2]) /* TODO: at the moment only one serial sensor is supported => else condition. to be changed once multiplexing is available */
431 {
432 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2; /* CO2 sensor has to be activated via auto detection */
433 } 435 }
434 436
435 #ifdef ENABLE_SENTINEL_MODE 437 #ifdef ENABLE_SENTINEL_MODE
436 if(SensorActive[SENSOR_SENTINEL]) 438 if(SensorActive[SENSOR_SENTINEL])
437 { 439 {
438 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_SENTINEL; 440 externalInterface_Cmd |= EXT_INTERFACE_33V_ON;
439 externalInterface_Cmd &= (~EXT_INTERFACE_ADC_ON); 441 externalInterface_Cmd &= (~EXT_INTERFACE_ADC_ON);
442 }
443 #endif
444
445 #ifdef ENABLE_GPIO_V2
446 if(getBuzzerActivationState())
447 {
448 externalInterface_Cmd |= EXT_INTERFACE_BUZZER_ON;
440 } 449 }
441 #endif 450 #endif
442 451
443 dataOut.data.externalInterface_Cmd = externalInterface_Cmd; 452 dataOut.data.externalInterface_Cmd = externalInterface_Cmd;
444 externalInterface_Cmd = 0; 453 externalInterface_Cmd = 0;
471 if(!wasUpdateNotPowerOn) 480 if(!wasUpdateNotPowerOn)
472 wasPowerOn = 1; 481 wasPowerOn = 1;
473 482
474 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness); 483 settingsHelperButtonSens_keepPercentageValues(settingsGetPointerStandard()->ButtonResponsiveness[3], settings->ButtonResponsiveness);
475 setButtonResponsiveness(settings->ButtonResponsiveness); 484 setButtonResponsiveness(settings->ButtonResponsiveness);
476 DataEX_setExtInterface_Cmd(EXT_INTERFACE_COPY_SENSORMAP); 485 DataEX_setExtInterface_Cmd(EXT_INTERFACE_COPY_SENSORMAP, 0);
477 } 486 }
478 } 487 }
479 488
480 489
481 void DataEX_copy_to_deco(void) 490 void DataEX_copy_to_deco(void)
482 { 491 {
483 if(decoLock == DECO_CALC_running) 492 if(decoLock == DECO_CALC_running)
484 return; 493 return;
485 494
486 if(decoLock == DECO_CALC_init_as_is_start_of_dive) 495 if(decoLock == DECO_CALC_init_as_is_start_of_dive)
487 { 496 {
497 vpm_table_init();
488 vpm_init(&stateUsedWrite->vpm, stateUsedWrite->diveSettings.vpm_conservatism, 0, 0); 498 vpm_init(&stateUsedWrite->vpm, stateUsedWrite->diveSettings.vpm_conservatism, 0, 0);
489 buehlmann_init(); 499 buehlmann_init();
490 timer_init(); 500 timer_init();
491 resetEvents(stateUsedWrite); 501 resetEvents(stateUsedWrite);
492 stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; 502 stateUsedWrite->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0;
493 } 503 }
494 504
495 if(decoLock == DECO_CALC_FINSHED_Buehlmann) 505 if(decoLock == DECO_CALC_FINSHED_Buehlmann)
496 { 506 {
497 507
498 } 508 }
499 switch(decoLock) 509 switch(decoLock)
500 { 510 {
532 } 542 }
533 543
534 //Copy Inputdata from stateReal to stateDeco 544 //Copy Inputdata from stateReal to stateDeco
535 memcpy(&stateDeco.lifeData,&stateUsedWrite->lifeData,sizeof(SLifeData)); 545 memcpy(&stateDeco.lifeData,&stateUsedWrite->lifeData,sizeof(SLifeData));
536 memcpy(&stateDeco.diveSettings,&stateUsedWrite->diveSettings,sizeof(SDiveSettings)); 546 memcpy(&stateDeco.diveSettings,&stateUsedWrite->diveSettings,sizeof(SDiveSettings));
547 memcpy(&stateDeco.decolistVPM,&stateUsedWrite->decolistVPM,sizeof(SDecoinfo));
537 548
538 stateDeco.vpm.deco_zone_reached = stateUsedWrite->vpm.deco_zone_reached; 549 stateDeco.vpm.deco_zone_reached = stateUsedWrite->vpm.deco_zone_reached;
539 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm)); 550 // memcpy(&stateDeco.vpm,&pStateUsed->vpm,sizeof(SVpm));
540 for(int i = 0; i< 16; i++) 551 for(int i = 0; i< 16; i++)
541 { 552 {
542 stateDeco.vpm.max_crushing_pressure_he[i] = stateUsedWrite->vpm.max_crushing_pressure_he[i]; 553 stateDeco.vpm.max_crushing_pressure_he[i] = stateUsedWrite->vpm.max_crushing_pressure_he[i];
543 stateDeco.vpm.max_crushing_pressure_n2[i] = stateUsedWrite->vpm.max_crushing_pressure_n2[i]; 554 stateDeco.vpm.max_crushing_pressure_n2[i] = stateUsedWrite->vpm.max_crushing_pressure_n2[i];
544 stateDeco.vpm.adjusted_critical_radius_he[i] = stateUsedWrite->vpm.adjusted_critical_radius_he[i]; 555 stateDeco.vpm.adjusted_critical_radius_he[i] = stateUsedWrite->vpm.adjusted_critical_radius_he[i];
545 stateDeco.vpm.adjusted_critical_radius_n2[i] = stateUsedWrite->vpm.adjusted_critical_radius_n2[i]; 556 stateDeco.vpm.adjusted_critical_radius_n2[i] = stateUsedWrite->vpm.adjusted_critical_radius_n2[i];
546 } 557 }
547 decoLock = DECO_CALC_ready; 558 decoLock = DECO_CALC_ready;
548 } 559 }
549 560
550 561
551 static void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead) 562 static void DataEX_helper_copy_deviceData(SDeviceLine *lineWrite, const SDeviceLine *lineRead)
552 { 563 {
578 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite) 589 static void DataEX_helper_set_Unknown_Date_deviceData(SDeviceLine *lineWrite)
579 { 590 {
580 RTC_DateTypeDef sdatestructure; 591 RTC_DateTypeDef sdatestructure;
581 RTC_TimeTypeDef stimestructure; 592 RTC_TimeTypeDef stimestructure;
582 593
594 const SFirmwareData *pFirmwareInfo;
595 pFirmwareInfo = firmwareDataGetPointer();
596
583 stimestructure.Hours = UNKNOWN_TIME_HOURS; 597 stimestructure.Hours = UNKNOWN_TIME_HOURS;
584 stimestructure.Minutes = UNKNOWN_TIME_MINUTES; 598 stimestructure.Minutes = UNKNOWN_TIME_MINUTES;
585 stimestructure.Seconds = UNKNOWN_TIME_SECOND; 599 stimestructure.Seconds = UNKNOWN_TIME_SECOND;
586 600
587 sdatestructure.Date = UNKNOWN_DATE_DAY; 601 sdatestructure.Date = UNKNOWN_DATE_DAY;
588 sdatestructure.Month = UNKNOWN_DATE_MONTH; 602 sdatestructure.Month = UNKNOWN_DATE_MONTH;
589 sdatestructure.Year = UNKNOWN_DATE_YEAR; 603 sdatestructure.Year = pFirmwareInfo->release_year;
590 setWeekday(&sdatestructure); 604 setWeekday(&sdatestructure);
591 605
592 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr); 606 DataEX_helper_SetTime(stimestructure, &lineWrite->time_rtc_tr);
593 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr); 607 DataEX_helper_SetDate(sdatestructure, &lineWrite->date_rtc_dr);
594 } 608 }
1008 pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick; 1022 pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick;
1009 pStateReal->pressure_uTick_local_new = HAL_GetTick(); 1023 pStateReal->pressure_uTick_local_new = HAL_GetTick();
1010 1024
1011 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr; 1025 pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr;
1012 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr; 1026 pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr;
1027
1028 memcpy(&pStateReal->lifeData.gnssData, &dataIn.data[0].gnssInfo, sizeof(dataIn.data[0].gnssInfo));
1013 } 1029 }
1014 1030
1015 if(pStateReal->data_old__lost_connection_to_slave == 0) 1031 if(pStateReal->data_old__lost_connection_to_slave == 0)
1016 { 1032 {
1017 //Start of diveMode? 1033 //Start of diveMode?
1031 settingsGetPointer()->bluetoothActive = 0; 1047 settingsGetPointer()->bluetoothActive = 0;
1032 MX_Bluetooth_PowerOff(); 1048 MX_Bluetooth_PowerOff();
1033 //Init dive Mode 1049 //Init dive Mode
1034 decoLock = DECO_CALC_init_as_is_start_of_dive; 1050 decoLock = DECO_CALC_init_as_is_start_of_dive;
1035 pStateReal->lifeData.boolResetAverageDepth = 1; 1051 pStateReal->lifeData.boolResetAverageDepth = 1;
1052
1053 memcpy(pStateReal->scrubberDataDive, pSettings->scrubberData, sizeof(pStateReal->scrubberDataDive));
1036 } 1054 }
1037 1055
1038 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns; 1056 pStateReal->lifeData.cns = dataIn.data[dataIn.boolToxicData].cns;
1039 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu; 1057 pStateReal->lifeData.otu = dataIn.data[dataIn.boolToxicData].otu;
1040 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes; 1058 pStateReal->lifeData.no_fly_time_minutes = dataIn.data[dataIn.boolToxicData].no_fly_time_minutes;
1058 else if(pStateReal->lifeData.cns >= 100) 1076 else if(pStateReal->lifeData.cns >= 100)
1059 dataOut.setAccidentFlag += ACCIDENT_CNS; 1077 dataOut.setAccidentFlag += ACCIDENT_CNS;
1060 } 1078 }
1061 if(pStateReal->warnings.decoMissed) 1079 if(pStateReal->warnings.decoMissed)
1062 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP; 1080 dataOut.setAccidentFlag += ACCIDENT_DECOSTOP;
1081
1082 memcpy(pSettings->scrubberData, pStateReal->scrubberDataDive, sizeof(pStateReal->scrubberDataDive)); /* Store value of current usage */
1063 } 1083 }
1064 pStateReal->mode = dataIn.mode; 1084 pStateReal->mode = dataIn.mode;
1065 pStateReal->chargeStatus = dataIn.chargeStatus; 1085 pStateReal->chargeStatus = dataIn.chargeStatus;
1066 1086
1067 pStateReal->lifeData.depth_meter = meter; 1087 pStateReal->lifeData.depth_meter = meter;
1157 /* sensorErrors 1177 /* sensorErrors
1158 */ 1178 */
1159 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; 1179 pStateReal->sensorErrorsRTE = dataIn.sensorErrors;
1160 1180
1161 /* data from CO2 sensor */ 1181 /* data from CO2 sensor */
1162 pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm * 10; /* Scale factor depends on sensor */ 1182 pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm;
1163 pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength; 1183 pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength;
1164 1184
1165 #ifdef ENABLE_EXTERNAL_PRESSURE 1185 #ifdef ENABLE_EXTERNAL_PRESSURE
1166 CO2Corr = 2.811*pow(10,-38)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,6)- 9.817*pow(10,-32)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,5)+1.304*pow(10,-25)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,4) 1186 CO2Corr = 2.811*pow(10,-38)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,6)- 9.817*pow(10,-32)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,5)+1.304*pow(10,-25)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,4)
1167 -8.216*pow(10,-20)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,3)+2.311*pow(10,-14)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,2) - 2.195*pow(10,-9)*pStateReal->lifeData.CO2_data.CO2_ppm - 1.471*pow(10,-3); 1187 -8.216*pow(10,-20)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,3)+2.311*pow(10,-14)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,2) - 2.195*pow(10,-9)*pStateReal->lifeData.CO2_data.CO2_ppm - 1.471*pow(10,-3);
1341 retval = hw_Info.extADC; 1361 retval = hw_Info.extADC;
1342 1362
1343 return retval; 1363 return retval;
1344 } 1364 }
1345 1365
1346 void DataEX_setExtInterface_Cmd(uint16_t Cmd) 1366 void DataEX_setExtInterface_Cmd(uint16_t Cmd, uint8_t sensorId)
1347 { 1367 {
1348 externalInterface_Cmd = Cmd; 1368 if(sensorId < EXT_INTERFACE_SENSOR_CNT - 1)
1369 {
1370 externalInterface_Cmd |= Cmd;
1371 externalInterface_Cmd |= sensorId << 8;
1372 }
1373
1349 return; 1374 return;
1350 } 1375 }
1351 1376