changeset 901:e4e9acfde839 Evo_2_23

Bugfix simulator/planer: For deco calculation two structures are used. The calculation structure and the input structure. During simulation fast forward (+5min) the input structure is manipulated. Especially for vpm calculation it could happen that the input structure was manipulated and then overwritten by the calculation structure => deco and tts may have wrong values. To avoid this thedeco calculation status is now checked before doing the FF manupulation. Based an calculation state deco or input structures are manipulated. Surface time stamp in planer view: The planer used its own (buggy) implementation for calculation of tts. The timestamp for the surface arrival did not match the bottom time + TTS. The new implementation uses the tts calculated by the deco loop for generation of surface time stamp.
author Ideenmodellierer
date Wed, 02 Oct 2024 22:07:13 +0200
parents 6a7701f66b16
children d4622533271d
files Discovery/Src/simulation.c
diffstat 1 files changed, 39 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/simulation.c	Tue Oct 01 14:18:21 2024 +0200
+++ b/Discovery/Src/simulation.c	Wed Oct 02 22:07:13 2024 +0200
@@ -93,6 +93,8 @@
 
 	copyDiveSettingsToSim();
     copyVpmRepetetiveDataToSim();
+    vpm_table_init();
+
   //vpm_init(&stateSimGetPointerWrite()->vpm,  stateSimGetPointerWrite()->diveSettings.vpm_conservatism, 0, 0);
     stateSimGetPointerWrite()->lifeData.counterSecondsShallowDepth = 0;
     stateSimGetPointerWrite()->mode = MODE_DIVE;
@@ -162,7 +164,17 @@
 
     if(checkOncePerSecond)
     {
+        int now =  current_second();
+        if( last_second == now)
+                return;
+        last_second = now;
 
+        if(!two_second)
+            two_second = 1;
+        else
+        {
+            two_second = 0;
+        }
         pSettings = settingsGetPointer();
         for(index = 0; index < 3; index++)
         {
@@ -199,21 +211,18 @@
         pDiveState->lifeData.bottle_bar[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar[pRealState->lifeData.actualGas.GasIdInSettings];
         pDiveState->lifeData.bottle_bar_age_MilliSeconds[pDiveState->lifeData.actualGas.GasIdInSettings] = pRealState->lifeData.bottle_bar_age_MilliSeconds[pRealState->lifeData.actualGas.GasIdInSettings];
 #endif
-        int now =  current_second();
-        if( last_second == now)
-                return;
-        last_second = now;
-
-        if(!two_second)
-            two_second = 1;
-        else
-        {
-            two_second = 0;
-        }
     }
     else if(pDiveState->lifeData.depth_meter <= (float)(decom_get_actual_deco_stop(pDiveState) + 0.001))
-      sim_reduce_deco_time_one_second(pDiveState);
-
+    {
+    	if(decoLock == DECO_CALC_FINSHED_vpm)
+    	{
+    		sim_reduce_deco_time_one_second(&stateDeco);
+    	}
+    	else
+    	{
+    		sim_reduce_deco_time_one_second(pDiveState);
+    	}
+    }
 
     pDiveState->lifeData.dive_time_seconds += 1;
     pDiveState->lifeData.pressure_ambient_bar = sim_get_ambient_pressure(pDiveState);
@@ -425,20 +434,28 @@
 static void sim_reduce_deco_time_one_second(SDiveState* pDiveState)
 {
     SDecoinfo* pDecoinfo;
+    int8_t index = 0;
+
+
     if(pDiveState->diveSettings.deco_type.ub.standard == GF_MODE)
         pDecoinfo = &pDiveState->decolistBuehlmann;
     else
         pDecoinfo = &pDiveState->decolistVPM;
 
     //Reduce deco time of deepest stop by one second
-    for(int i = DECOINFO_STRUCT_MAX_STOPS -1 ;i >= 0; i--)
+    for(index = DECOINFO_STRUCT_MAX_STOPS -1 ;index >= 0; index--)
     {
-        if(pDecoinfo->output_stop_length_seconds[i] > 0)
+        if(pDecoinfo->output_stop_length_seconds[index] > 0)
         {
-            pDecoinfo->output_stop_length_seconds[i]--;
+            pDecoinfo->output_stop_length_seconds[index]--;
             break;
         }
     }
+    /* update TTS */
+    if(pDecoinfo->output_time_to_surface_seconds)
+    {
+    	pDecoinfo->output_time_to_surface_seconds--;
+    }
 }
 
 SDecoinfo* simulation_decoplaner(uint16_t depth_meter, uint16_t intervall_time_minutes, uint16_t dive_time_minutes, uint8_t *gasChangeListDepthGas20x2)
@@ -688,24 +705,14 @@
     outputSummary->timeToFirstStop = (uint16_t)timeSummary;
     outputSummary->depthMeterFirstStop = actualDepthPoint;
 
-    //ascent
-    nextDepthPoint = 0;
-    timeThis = 0;
-    if(actualDepthPoint > nextDepthPoint) // only if deco
+    if(decoInfoInput->output_time_to_surface_seconds)
     {
-        // ascent time
-        timeThis = ((float)(actualDepthPoint - nextDepthPoint)) / sim_ascent_rate_meter_per_min_local;
-
-        // deco stop time
-        for(ptrDecoInfo=0;ptrDecoInfo < DECOINFO_STRUCT_MAX_STOPS; ptrDecoInfo++)
-        {
-            timeThis += decoInfoInput->output_stop_length_seconds[ptrDecoInfo] / 60;
-            if(!decoInfoInput->output_stop_length_seconds[ptrDecoInfo]) break;
-        }
+    	outputSummary->timeToSurface = outputSummary->timeAtBottom + (decoInfoInput->output_time_to_surface_seconds / 60);
     }
-    timeSummary += timeThis;
-    outputSummary->timeToSurface = (uint16_t)timeSummary;
-
+    else
+    {
+    	outputSummary->timeToSurface = outputSummary->timeToFirstStop;
+    }
 }