Mercurial > public > ostc4
comparison Discovery/Src/data_central.c @ 696:cc542448fb28
Merge
author | heinrichsweikamp |
---|---|
date | Fri, 19 Aug 2022 11:30:24 +0200 |
parents | 6f5a18bb25be |
children | 8a2337c7af52 |
comparison
equal
deleted
inserted
replaced
661:87bee7cc77b3 | 696:cc542448fb28 |
---|---|
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 | |
321 setActualGasFirst(&stateReal.lifeData); | |
322 | 322 |
323 stateReal.diveSettings.compassHeading = pSettings->compassBearing; | 323 stateReal.diveSettings.compassHeading = pSettings->compassBearing; |
324 stateReal.diveSettings.ascentRate_meterperminute = 10; | 324 stateReal.diveSettings.ascentRate_meterperminute = 10; |
325 | 325 |
326 stateReal.diveSettings.diveMode = pSettings->dive_mode; | 326 stateReal.diveSettings.diveMode = pSettings->dive_mode; |
327 stateReal.diveSettings.CCR_Mode = pSettings->CCR_Mode; | 327 stateReal.diveSettings.CCR_Mode = pSettings->CCR_Mode; |
328 if(stateReal.diveSettings.diveMode == DIVEMODE_CCR) | 328 if((stateReal.diveSettings.diveMode == DIVEMODE_PSCR) && (stateReal.diveSettings.CCR_Mode == CCRMODE_FixedSetpoint)) |
329 { | |
330 /* 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 */ | |
331 stateReal.diveSettings.CCR_Mode = CCRMODE_Simulation; | |
332 } | |
333 | |
334 if(isLoopMode(stateReal.diveSettings.diveMode)) | |
329 stateReal.diveSettings.ccrOption = 1; | 335 stateReal.diveSettings.ccrOption = 1; |
330 else | 336 else |
331 stateReal.diveSettings.ccrOption = 0; | 337 stateReal.diveSettings.ccrOption = 0; |
332 memcpy(stateReal.diveSettings.gas, pSettings->gas,sizeof(pSettings->gas)); | 338 memcpy(stateReal.diveSettings.gas, pSettings->gas,sizeof(pSettings->gas)); |
333 memcpy(stateReal.diveSettings.setpoint, pSettings->setpoint,sizeof(pSettings->setpoint)); | 339 memcpy(stateReal.diveSettings.setpoint, pSettings->setpoint,sizeof(pSettings->setpoint)); |
340 | |
341 setActualGasFirst(&stateReal.lifeData); | |
342 | |
334 stateReal.diveSettings.gf_high = pSettings->GF_high; | 343 stateReal.diveSettings.gf_high = pSettings->GF_high; |
335 stateReal.diveSettings.gf_low = pSettings->GF_low; | 344 stateReal.diveSettings.gf_low = pSettings->GF_low; |
336 stateReal.diveSettings.input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f; | 345 stateReal.diveSettings.input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f; |
337 stateReal.diveSettings.last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0f; | 346 stateReal.diveSettings.last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0f; |
338 stateReal.diveSettings.vpm_conservatism = pSettings->VPM_conservatism.ub.standard; | 347 stateReal.diveSettings.vpm_conservatism = pSettings->VPM_conservatism.ub.standard; |
339 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw; | 348 stateReal.diveSettings.deco_type.uw = pSettings->deco_type.uw; |
340 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint; | 349 stateReal.diveSettings.fallbackOption = pSettings->fallbackToFixedSetpoint; |
341 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated; | 350 stateReal.diveSettings.ppo2sensors_deactivated = pSettings->ppo2sensors_deactivated; |
342 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS; | 351 stateReal.diveSettings.future_TTS_minutes = pSettings->future_TTS; |
343 | 352 |
353 stateReal.diveSettings.pscr_lung_ratio = pSettings->pscr_lung_ratio; | |
354 stateReal.diveSettings.pscr_o2_drop = pSettings->pscr_o2_drop; | |
355 | |
356 if(stateReal.diveSettings.diveMode == DIVEMODE_PSCR) | |
357 { | |
358 for(i=0; i<5; i++) | |
359 { | |
360 stateReal.diveSettings.decogaslist[i].pscr_factor = 1.0 / stateReal.diveSettings.pscr_lung_ratio * stateReal.diveSettings.pscr_o2_drop; | |
361 } | |
362 } | |
363 | |
344 decom_CreateGasChangeList(&stateReal.diveSettings, &stateReal.lifeData); // decogaslist | 364 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; | 365 stateReal.diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = 0; |
346 | 366 |
347 /* for safety */ | 367 /* 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; | 368 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 */ | 369 /* and the proper calc */ |
350 for(int i = 1; i <10; i++) | 370 for(i = 1; i <10; i++) |
351 { | 371 { |
352 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar) | 372 if(stateReal.diveSettings.input_next_stop_increment_depth_bar * i > stateReal.diveSettings.last_stop_depth_bar) |
353 { | 373 { |
354 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i; | 374 stateReal.diveSettings.input_second_to_last_stop_depth_bar = stateReal.diveSettings.input_next_stop_increment_depth_bar * i; |
355 break; | 375 break; |
387 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid; | 407 pSimData->vpm.repetitive_variables_not_valid = pVpmData->repetitive_variables_not_valid; |
388 } | 408 } |
389 } | 409 } |
390 | 410 |
391 | 411 |
412 | |
413 | |
392 void updateSetpointStateUsed(void) | 414 void updateSetpointStateUsed(void) |
393 { | 415 { |
394 if(stateUsed->diveSettings.diveMode != DIVEMODE_CCR) | 416 if(!isLoopMode(stateUsed->diveSettings.diveMode)) |
395 { | 417 { |
396 stateUsedWrite->lifeData.actualGas.setPoint_cbar = 0; | 418 stateUsedWrite->lifeData.actualGas.setPoint_cbar = 0; |
397 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas); | 419 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas); |
398 } | 420 } |
399 else | 421 else |
400 { | 422 { |
401 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) | 423 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) |
402 { | 424 { |
403 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar(); | 425 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar(); |
404 } | 426 } |
405 | 427 #ifdef ENABLE_PSCR_MODE |
428 if(stateUsed->diveSettings.diveMode == DIVEMODE_PSCR) /* calculate a ppO2 value based on assumptions ( transfered approach from hwos code) */ | |
429 { | |
430 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); | |
431 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Simulation) | |
432 { | |
433 stateUsedWrite->lifeData.actualGas.setPoint_cbar = stateUsedWrite->lifeData.ppo2Simulated_bar * 100; | |
434 } | |
435 } | |
436 #endif | |
437 /* limit calculated value to the physically possible if needed */ | |
406 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar) | 438 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar) |
407 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar; | 439 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar; |
408 else | 440 else |
409 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100; | 441 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100; |
410 } | 442 } |
415 SSettings* pSettings = settingsGetPointer(); | 447 SSettings* pSettings = settingsGetPointer(); |
416 uint8_t start = 0; | 448 uint8_t start = 0; |
417 uint8_t gasId = 0; | 449 uint8_t gasId = 0; |
418 uint8_t setpoint_cbar = 0; | 450 uint8_t setpoint_cbar = 0; |
419 | 451 |
420 if(pSettings->dive_mode == DIVEMODE_CCR) | 452 if(isLoopMode(pSettings->dive_mode)) |
421 { | 453 { |
422 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar; | 454 setpoint_cbar = pSettings->setpoint[1].setpoint_cbar; |
423 start = NUM_OFFSET_DILUENT+1; | 455 start = NUM_OFFSET_DILUENT+1; |
424 } | 456 } |
425 else | 457 else |
447 lifeData->actualGas.GasIdInSettings = 0; | 479 lifeData->actualGas.GasIdInSettings = 0; |
448 lifeData->actualGas.nitrogen_percentage = nitrogen; | 480 lifeData->actualGas.nitrogen_percentage = nitrogen; |
449 lifeData->actualGas.helium_percentage =0; | 481 lifeData->actualGas.helium_percentage =0; |
450 lifeData->actualGas.setPoint_cbar = 0; | 482 lifeData->actualGas.setPoint_cbar = 0; |
451 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | 483 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; |
484 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; | |
452 } | 485 } |
453 | 486 |
454 | 487 |
455 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | 488 void setActualGas(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) |
456 { | 489 { |
464 lifeData->actualGas.GasIdInSettings = gasId; | 497 lifeData->actualGas.GasIdInSettings = gasId; |
465 lifeData->actualGas.nitrogen_percentage = nitrogen; | 498 lifeData->actualGas.nitrogen_percentage = nitrogen; |
466 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage; | 499 lifeData->actualGas.helium_percentage = pSettings->gas[gasId].helium_percentage; |
467 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | 500 lifeData->actualGas.setPoint_cbar = setpoint_cbar; |
468 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | 501 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; |
469 | 502 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
470 if((pSettings->dive_mode == DIVEMODE_CCR) && (gasId > NUM_OFFSET_DILUENT)) | 503 lifeData->actualGas.pscr_factor = 1.0 / pSettings->pscr_lung_ratio * pSettings->pscr_o2_drop; |
504 if(isLoopMode(pSettings->dive_mode) && (gasId > NUM_OFFSET_DILUENT)) | |
471 lifeData->lastDiluent_GasIdInSettings = gasId; | 505 lifeData->lastDiluent_GasIdInSettings = gasId; |
472 } | 506 } |
473 | 507 |
474 | 508 |
475 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) | 509 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) |
523 lifeData->actualGas.GasIdInSettings = 0; | 557 lifeData->actualGas.GasIdInSettings = 0; |
524 lifeData->actualGas.nitrogen_percentage = nitrogen; | 558 lifeData->actualGas.nitrogen_percentage = nitrogen; |
525 lifeData->actualGas.helium_percentage = helium; | 559 lifeData->actualGas.helium_percentage = helium; |
526 lifeData->actualGas.setPoint_cbar = setpoint_cbar; | 560 lifeData->actualGas.setPoint_cbar = setpoint_cbar; |
527 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; | 561 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; |
528 | 562 lifeData->actualGas.AppliedDiveMode = stateUsed->diveSettings.diveMode; |
529 } | 563 } |
530 | 564 |
531 void setButtonResponsiveness(uint8_t *ButtonSensitivyList) | 565 void setButtonResponsiveness(uint8_t *ButtonSensitivyList) |
532 { | 566 { |
533 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); | 567 SDataReceiveFromMaster *pDataOut = dataOutGetPointer(); |
812 float compass_getCompensated() | 846 float compass_getCompensated() |
813 { | 847 { |
814 return compass_compensated; | 848 return compass_compensated; |
815 } | 849 } |
816 | 850 |
851 uint8_t isLoopMode(uint8_t Mode) | |
852 { | |
853 uint8_t retVal = 0; | |
854 if((Mode == DIVEMODE_CCR) || (Mode == DIVEMODE_PSCR)) | |
855 { | |
856 retVal = 1; | |
857 } | |
858 return retVal; | |
859 } |