comparison Discovery/Src/data_central.c @ 273:5fe136480a47

Merged in janlmulder/ostc4/write-from-sim (pull request #20) Cleanup and debug capabilty to write logbook from simulator
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Sun, 28 Apr 2019 07:05:23 +0000
parents 1303747b5ba2
children 54d14bc2083c
comparison
equal deleted inserted replaced
267:cf6ad20380fb 273:5fe136480a47
98 { 98 {
99 .repetitive_variables_not_valid = 1, 99 .repetitive_variables_not_valid = 1,
100 .is_data_from_RTE_CPU = 0, 100 .is_data_from_RTE_CPU = 0,
101 }; 101 };
102 102
103 const SDiveState * stateUsed = &stateReal; 103 const SDiveState *stateUsed = &stateReal;
104 104 SDiveState *stateUsedWrite = &stateReal;
105 105
106 void set_stateUsedToReal(void) 106 void set_stateUsedToReal(void)
107 { 107 {
108 stateUsed = &stateReal; 108 stateUsed = stateUsedWrite = &stateReal;
109 } 109 }
110 110
111 void set_stateUsedToSim(void) 111 void set_stateUsedToSim(void)
112 { 112 {
113 stateUsed = &stateSim; 113 stateUsed = stateUsedWrite = &stateSim;
114 } 114 }
115 115
116 _Bool is_stateUsedSetToSim(void) 116 _Bool is_stateUsedSetToSim(void)
117 { 117 {
118 return stateUsed == &stateSim; 118 return stateUsed == &stateSim;
456 } 456 }
457 457
458 458
459 void updateSetpointStateUsed(void) 459 void updateSetpointStateUsed(void)
460 { 460 {
461 SLifeData *pLifeDataWrite;
462
463 if(is_stateUsedSetToSim())
464 pLifeDataWrite = &stateSimGetPointerWrite()->lifeData;
465 else
466 pLifeDataWrite = &stateRealGetPointerWrite()->lifeData;
467
468 if(stateUsed->diveSettings.diveMode != DIVEMODE_CCR) 461 if(stateUsed->diveSettings.diveMode != DIVEMODE_CCR)
469 { 462 {
470 pLifeDataWrite->actualGas.setPoint_cbar = 0; 463 stateUsedWrite->lifeData.actualGas.setPoint_cbar = 0;
471 pLifeDataWrite->ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas); 464 stateUsedWrite->lifeData.ppO2 = decom_calc_ppO2(stateUsed->lifeData.pressure_ambient_bar, &stateUsed->lifeData.actualGas);
472 } 465 }
473 else 466 else
474 { 467 {
475 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors) 468 if(stateUsed->diveSettings.CCR_Mode == CCRMODE_Sensors)
476 { 469 {
477 pLifeDataWrite->actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar(); 470 stateUsedWrite->lifeData.actualGas.setPoint_cbar = get_ppO2SensorWeightedResult_cbar();
478 } 471 }
479 472
480 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar) 473 if((stateUsed->lifeData.pressure_ambient_bar * 100) < stateUsed->lifeData.actualGas.setPoint_cbar)
481 pLifeDataWrite->ppO2 = stateUsed->lifeData.pressure_ambient_bar; 474 stateUsedWrite->lifeData.ppO2 = stateUsed->lifeData.pressure_ambient_bar;
482 else 475 else
483 pLifeDataWrite->ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100; 476 stateUsedWrite->lifeData.ppO2 = ((float)stateUsed->lifeData.actualGas.setPoint_cbar) / 100;
484 } 477 }
485 } 478 }
486
487 /*
488 void fallbackToFixedSetpoints(SLifeData *lifeData)
489 {
490
491 }
492 */
493 479
494 void setActualGasFirst(SLifeData *lifeData) 480 void setActualGasFirst(SLifeData *lifeData)
495 { 481 {
496 SSettings* pSettings = settingsGetPointer(); 482 SSettings* pSettings = settingsGetPointer();
497 uint8_t start = 0; 483 uint8_t start = 0;
553 } 539 }
554 540
555 541
556 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar) 542 void setActualGas_DM(SLifeData *lifeData, uint8_t gasId, uint8_t setpoint_cbar)
557 { 543 {
558 //Real dive => Set events for logbook
559 if(stateUsed == stateRealGetPointer())
560 {
561 SDiveState * pStateUsed;
562 pStateUsed = stateRealGetPointerWrite();
563
564 if(stateUsed->diveSettings.ccrOption && gasId < 6) 544 if(stateUsed->diveSettings.ccrOption && gasId < 6)
565 { 545 {
566 if(lifeData->actualGas.GasIdInSettings != gasId) 546 if(lifeData->actualGas.GasIdInSettings != gasId)
567 { 547 {
568 SSettings* pSettings = settingsGetPointer(); 548 SSettings* pSettings = settingsGetPointer();
569 pStateUsed->events.bailout = 1; 549 stateUsedWrite->events.bailout = 1;
570 pStateUsed->events.info_bailoutO2 = pSettings->gas[gasId].oxygen_percentage; 550 stateUsedWrite->events.info_bailoutO2 = pSettings->gas[gasId].oxygen_percentage;
571 pStateUsed->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage; 551 stateUsedWrite->events.info_bailoutHe = pSettings->gas[gasId].helium_percentage;
572 } 552 }
573 } 553 }
574 else 554 else
575 { 555 {
576 if(lifeData->actualGas.GasIdInSettings != gasId) 556 if(lifeData->actualGas.GasIdInSettings != gasId)
577 { 557 {
578 pStateUsed->events.gasChange = 1; 558 stateUsedWrite->events.gasChange = 1;
579 pStateUsed->events.info_GasChange = gasId; 559 stateUsedWrite->events.info_GasChange = gasId;
580 } 560 }
581 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) 561 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar)
582 { 562 {
583 // setPoint_cbar = 255 -> change to sensor mode 563 // setPoint_cbar = 255 -> change to sensor mode
584 pStateUsed->events.setpointChange = 1; 564 stateUsedWrite->events.setpointChange = 1;
585 pStateUsed->events.info_SetpointChange = setpoint_cbar; 565 stateUsedWrite->events.info_SetpointChange = setpoint_cbar;
586 } 566 }
587 } 567 }
588 }
589 setActualGas(lifeData, gasId, setpoint_cbar); 568 setActualGas(lifeData, gasId, setpoint_cbar);
590 } 569 }
591 570
592 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar) 571 void setActualGas_ExtraGas(SLifeData *lifeData, uint8_t oxygen, uint8_t helium, uint8_t setpoint_cbar)
593 { 572 {
595 574
596 nitrogen = 100; 575 nitrogen = 100;
597 nitrogen -= oxygen; 576 nitrogen -= oxygen;
598 nitrogen -= helium; 577 nitrogen -= helium;
599 578
600 //Real dive => Set events for logbook
601 if(stateUsed == stateRealGetPointer())
602 {
603 SDiveState * pStateUsed;
604 pStateUsed = stateRealGetPointerWrite();
605 if((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium)) 579 if((lifeData->actualGas.nitrogen_percentage != nitrogen) || (lifeData->actualGas.helium_percentage != helium))
606 { 580 {
607 pStateUsed->events.manuelGasSet = 1; 581 stateUsedWrite->events.manuelGasSet = 1;
608 pStateUsed->events.info_manuelGasSetHe = helium; 582 stateUsedWrite->events.info_manuelGasSetHe = helium;
609 pStateUsed->events.info_manuelGasSetO2 = oxygen; 583 stateUsedWrite->events.info_manuelGasSetO2 = oxygen;
610 } 584 }
611 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar) 585 if( lifeData->actualGas.setPoint_cbar != setpoint_cbar)
612 { 586 {
613 pStateUsed->events.setpointChange = 1; 587 stateUsedWrite->events.setpointChange = 1;
614 pStateUsed->events.info_SetpointChange = setpoint_cbar; 588 stateUsedWrite->events.info_SetpointChange = setpoint_cbar;
615 } 589 }
616 }
617 lifeData->actualGas.GasIdInSettings = 0; 590 lifeData->actualGas.GasIdInSettings = 0;
618 lifeData->actualGas.nitrogen_percentage = nitrogen; 591 lifeData->actualGas.nitrogen_percentage = nitrogen;
619 lifeData->actualGas.helium_percentage = helium; 592 lifeData->actualGas.helium_percentage = helium;
620 lifeData->actualGas.setPoint_cbar = setpoint_cbar; 593 lifeData->actualGas.setPoint_cbar = setpoint_cbar;
621 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0; 594 lifeData->actualGas.change_during_ascent_depth_meter_otherwise_zero = 0;
773 return stateUsed->vpm.deco_zone_reached; 746 return stateUsed->vpm.deco_zone_reached;
774 747
775 } 748 }
776 749
777 750
778 void resetEvents(void) 751 void resetEvents(const SDiveState *pStateUsed)
779 { 752 {
780 SDiveState * pStateUsed; 753 memset((void *)&pStateUsed->events, 0, sizeof(SEvents));
781 if(stateUsed == stateRealGetPointer())
782 {
783 pStateUsed = stateRealGetPointerWrite();
784 }
785 else
786 {
787 pStateUsed = stateSimGetPointerWrite();
788 }
789 memset(&pStateUsed->events,0, sizeof(SEvents));
790 } 754 }
791 755
792 756
793 /* This is derived from crc32b but does table lookup. First the table 757 /* This is derived from crc32b but does table lookup. First the table
794 itself is calculated, if it has not yet been set up. 758 itself is calculated, if it has not yet been set up.