comparison Discovery/Src/data_central.c @ 662:1b995079c045 Betatest

PSCR Mode
author heinrichs weikamp
date Tue, 14 Dec 2021 15:36:10 +0100
parents d784f281833a
children 8775d3dc6325
comparison
equal deleted inserted replaced
661:87bee7cc77b3 662:1b995079c045
69 #include "settings.h" 69 #include "settings.h"
70 #include "data_exchange_main.h" 70 #include "data_exchange_main.h"
71 #include "ostc.h" // for button adjust on hw testboard 1 71 #include "ostc.h" // for button adjust on hw testboard 1
72 #include "tCCR.h" 72 #include "tCCR.h"
73 #include "crcmodel.h" 73 #include "crcmodel.h"
74 #include "configuration.h"
74 75
75 static SDiveState stateReal = { 0 }; 76 static SDiveState stateReal = { 0 };
76 SDiveState stateSim = { 0 }; 77 SDiveState stateSim = { 0 };
77 SDiveState stateDeco = { 0 }; 78 SDiveState stateDeco = { 0 };
78 79
314 }; 315 };
315 316
316 317
317 void createDiveSettings(void) 318 void createDiveSettings(void)
318 { 319 {
320 int i;
319 SSettings* pSettings = settingsGetPointer(); 321 SSettings* pSettings = settingsGetPointer();
320 322
321 setActualGasFirst(&stateReal.lifeData); 323 setActualGasFirst(&stateReal.lifeData);
322 324
323 stateReal.diveSettings.compassHeading = pSettings->compassBearing; 325 stateReal.diveSettings.compassHeading = pSettings->compassBearing;
324 stateReal.diveSettings.ascentRate_meterperminute = 10; 326 stateReal.diveSettings.ascentRate_meterperminute = 10;
325 327
326 stateReal.diveSettings.diveMode = pSettings->dive_mode; 328 stateReal.diveSettings.diveMode = pSettings->dive_mode;
327 stateReal.diveSettings.CCR_Mode = pSettings->CCR_Mode; 329 stateReal.diveSettings.CCR_Mode = pSettings->CCR_Mode;
328 if(stateReal.diveSettings.diveMode == DIVEMODE_CCR) 330 if((stateReal.diveSettings.diveMode == DIVEMODE_PSCR) && (stateReal.diveSettings.CCR_Mode == CCRMODE_FixedSetpoint))
331 {
332 /* TODO: update selection of sensor used on/off (currently sensor/fixpoint). As PSCR has no fixed setpoint change to simulated ppo2 if sensors are not active */
333 stateReal.diveSettings.CCR_Mode = CCRMODE_Simulation;
334 }
335
336 if(isLoopMode(stateReal.diveSettings.diveMode))
329 stateReal.diveSettings.ccrOption = 1; 337 stateReal.diveSettings.ccrOption = 1;
330 else 338 else
331 stateReal.diveSettings.ccrOption = 0; 339 stateReal.diveSettings.ccrOption = 0;
332 memcpy(stateReal.diveSettings.gas, pSettings->gas,sizeof(pSettings->gas)); 340 memcpy(stateReal.diveSettings.gas, pSettings->gas,sizeof(pSettings->gas));
333 memcpy(stateReal.diveSettings.setpoint, pSettings->setpoint,sizeof(pSettings->setpoint)); 341 memcpy(stateReal.diveSettings.setpoint, pSettings->setpoint,sizeof(pSettings->setpoint));
339 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw; 347 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw;
340 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint; 348 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint;
341 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated; 349 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated;
342 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS; 350 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS;
343 351
352 stateReal.diveSettings.pscr_lung_ratio = pSettings->pscr_lung_ratio;
353 stateReal.diveSettings.pscr_o2_drop = pSettings->pscr_o2_drop;
354
355 if(stateReal.diveSettings.diveMode == DIVEMODE_PSCR)
356 {
357 for(i=0; i<5; i++)
358 {
359 stateReal.diveSettings.decogaslist[i].pscr_factor = 1.0 / stateReal.diveSettings.pscr_lung_ratio * stateReal.diveSettings.pscr_o2_drop;
360 }
361 }
362
344 decom_CreateGasChangeList(&stateReal.diveSettings, &stateReal.lifeData); // decogaslist 363 decom_CreateGasChangeList(&stateReal.diveSettings, &stateReal.lifeData); // decogaslist
345 stateReal.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; 364 stateReal.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0;
346 365
347 /* for safety */ 366 /* for safety */
348 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.last_stop_depth_bar + stateReal.diveSettings.input_next_stop_increment_depth_bar; 367 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.last_stop_depth_bar + stateReal.diveSettings.input_next_stop_increment_depth_bar;
349 /* and the proper calc */ 368 /* and the proper calc */
350 for(int i = 1; i <10; i++) 369 for(i = 1; i <10; i++)
351 { 370 {
352 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar) 371 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar)
353 { 372 {
354 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i; 373 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i;
355 break; 374 break;
387 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid; 406 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid;
388 } 407 }
389 } 408 }
390 409
391 410
411
412
392 void updateSetpointStateUsed(void) 413 void updateSetpointStateUsed(void)
393 { 414 {
394 if(stateUsed->diveSettings.diveMode != DIVEMODE_CCR) 415 if(!isLoopMode(stateReal.diveSettings.diveMode))
395 { 416 {
396 stateUsedWrite->lifeData.actualGas.setPoint_cbar = 0; 417 stateUsedWrite->lifeData.actualGas.setPoint_cbar = 0;
397 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas); 418 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas);
398 } 419 }
399 else 420 else
400 { 421 {
401 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) 422 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors)
402 { 423 {
403 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar(); 424 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar();
404 } 425 }
405 426 #ifdef ENABLE_PSCR_MODE
427 if(stateUsed->diveSettings.diveMode == DIVEMODE_PSCR) /* calculate a ppO2 value based on assumptions ( transfered approach from hwos code) */
428 {
429 stateUsedWrite->lifeData.ppo2Simulated_bar = decom_calc_SimppO2_O2based(stateUsed->lifeData.pressure_ambient_bar, stateReal.diveSettings.gas[stateUsed->lifeData.actualGas.GasIdInSettings].oxygen_percentage, stateUsed->lifeData.actualGas.pscr_factor);
430 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Simulation)
431 {
432 stateUsedWrite->lifeData.actualGas.setPoint_cbar = stateUsedWrite->lifeData.ppo2Simulated_bar * 100;
433 }
434 }
435 #endif
436 /* limit calculated value to the physically possible if needed */
406 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar) 437 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar)
407 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar; 438 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar;
408 else 439 else
409 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100; 440 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100;
410 } 441 }
415 SSettings* pSettings = settingsGetPointer(); 446 SSettings* pSettings = settingsGetPointer();
416 uint8_t start = 0; 447 uint8_t start = 0;
417 uint8_t gasId = 0; 448 uint8_t gasId = 0;
418 uint8_t setpoint_cbar = 0; 449 uint8_t setpoint_cbar = 0;
419 450
420 if(pSettings->dive_mode == DIVEMODE_CCR) 451 if(isLoopMode(pSettings->dive_mode))
421 { 452 {
422 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar; 453 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar;
423 start = NUM_OFFSET_DILUENT+1; 454 start = NUM_OFFSET_DILUENT+1;
424 } 455 }
425 else 456 else
447 lifeData->actualGas.GasIdInSettings = 0; 478 lifeData->actualGas.GasIdInSettings = 0;
448 lifeData->actualGas.nitrogen_percentage = nitrogen; 479 lifeData->actualGas.nitrogen_percentage = nitrogen;
449 lifeData->actualGas.helium_percentage =0; 480 lifeData->actualGas.helium_percentage =0;
450 lifeData->actualGas.setPoint_cbar = 0; 481 lifeData->actualGas.setPoint_cbar = 0;
451 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; 482 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0;
483 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode;
452 } 484 }
453 485
454 486
455 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) 487 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar)
456 { 488 {
464 lifeData->actualGas.GasIdInSettings = gasId; 496 lifeData->actualGas.GasIdInSettings = gasId;
465 lifeData->actualGas.nitrogen_percentage = nitrogen; 497 lifeData->actualGas.nitrogen_percentage = nitrogen;
466 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage; 498 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage;
467 lifeData->actualGas.setPoint_cbar = setpoint_cbar; 499 lifeData->actualGas.setPoint_cbar = setpoint_cbar;
468 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; 500 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0;
469 501 lifeData->actualGas.AppliedDiveMode = pSettings->dive_mode;
470 if((pSettings->dive_mode == DIVEMODE_CCR) && (gasId > NUM_OFFSET_DILUENT)) 502 lifeData->actualGas.pscr_factor = 1.0 / pSettings->pscr_lung_ratio * pSettings->pscr_o2_drop;
503 if(isLoopMode(pSettings->dive_mode) && (gasId > NUM_OFFSET_DILUENT))
471 lifeData->lastDiluent_GasIdInSettings = gasId; 504 lifeData->lastDiluent_GasIdInSettings = gasId;
472 } 505 }
473 506
474 507
475 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) 508 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar)
523 lifeData->actualGas.GasIdInSettings = 0; 556 lifeData->actualGas.GasIdInSettings = 0;
524 lifeData->actualGas.nitrogen_percentage = nitrogen; 557 lifeData->actualGas.nitrogen_percentage = nitrogen;
525 lifeData->actualGas.helium_percentage = helium; 558 lifeData->actualGas.helium_percentage = helium;
526 lifeData->actualGas.setPoint_cbar = setpoint_cbar; 559 lifeData->actualGas.setPoint_cbar = setpoint_cbar;
527 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; 560 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0;
528 561 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode;
529 } 562 }
530 563
531 void setButtonResponsiveness(uint8_t *ButtonSensitivyList) 564 void setButtonResponsiveness(uint8_t *ButtonSensitivyList)
532 { 565 {
533 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); 566 SDataReceiveFromMaster *pDataOut = dataOutGetPointer();
812 float compass_getCompensated() 845 float compass_getCompensated()
813 { 846 {
814 return compass_compensated; 847 return compass_compensated;
815 } 848 }
816 849
850 uint8_t isLoopMode(uint8_t Mode)
851 {
852 uint8_t retVal = 0;
853 if((Mode == DIVEMODE_CCR) || (Mode == DIVEMODE_PSCR))
854 {
855 retVal = 1;
856 }
857 return retVal;
858 }