diff Discovery/Src/simulation.c @ 910:7bd347bdaa81 Evo_2_23

Devbugfix Sample time resolution for longer dives: If a dive is longer than the provided replay buffer then the sample data is compressed. This compression was not considered in the previous version. As result the dive was replayed with double speed because a single sample were interpretated as 2 seconds instead of e.g. 4 seconds for a compressed sample. The comprassion rate is now considered in the simulator replay function
author Ideenmodellierer
date Tue, 15 Oct 2024 19:12:05 +0200
parents 46a21ff3f5ab
children 4d98fb2a178e
line wrap: on
line diff
--- a/Discovery/Src/simulation.c	Tue Oct 15 19:07:19 2024 +0200
+++ b/Discovery/Src/simulation.c	Tue Oct 15 19:12:05 2024 +0200
@@ -380,20 +380,33 @@
     float depth_meter = pDiveState->lifeData.depth_meter;
     float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar;
     static uint8_t sampleToggle = 0;
+	static float sim_ascent_rate_meter_per_min_local = 0;
+	uint8_t sampleTime = getReplayDataResolution();
 
-    if(simReplayActive) /* precondition: function is called once per second, sample rate is 2 seconds */
+    if(simReplayActive) /* precondition: function is called once per second, sample rate is a multiple of second */
     {
     	if(sampleToggle == 0)
     	{
-    		sampleToggle = 1;
+    		sampleToggle = sampleTime - 1;
     		sim_aim_depth_meter = (float)(*pReplayData++/100.0);
-    		sim_descent_rate_meter_per_min = (sim_aim_depth_meter - depth_meter) * 30;
+    		if(sim_aim_depth_meter > depth_meter)
+    		{
+    			sim_descent_rate_meter_per_min = (sim_aim_depth_meter - depth_meter) * (60 / sampleTime);
+    		}
+    		else
+    		{
+    			sim_ascent_rate_meter_per_min_local = (depth_meter - sim_aim_depth_meter) * (60 / sampleTime);
+    		}
     	}
     	else
     	{
-    		sampleToggle = 0;
+    		sampleToggle--;
     	}
     }
+    else
+    {
+    	sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute;
+    }
 
     if(depth_meter < sim_aim_depth_meter)
     {
@@ -404,16 +417,16 @@
     else if(depth_meter > sim_aim_depth_meter)
     {
 
-        depth_meter -=  pDiveState->diveSettings.ascentRate_meterperminute / 60;
+        depth_meter -=  sim_ascent_rate_meter_per_min_local / 60;
         if(depth_meter < sim_aim_depth_meter)
             depth_meter = sim_aim_depth_meter;
 
         if(sim_heed_decostops && depth_meter < actual_deco_stop)
         {
-            if(actual_deco_stop < (depth_meter +  pDiveState->diveSettings.ascentRate_meterperminute / 60))
+            if(actual_deco_stop < (depth_meter +  sim_ascent_rate_meter_per_min_local / 60))
                  depth_meter = actual_deco_stop;
             else
-                depth_meter +=  pDiveState->diveSettings.ascentRate_meterperminute / 60;
+                depth_meter += sim_ascent_rate_meter_per_min_local / 60;
         }
 
    }
@@ -552,6 +565,11 @@
         /* this does modify the cns now 11.06.2015 */
         vpm_calc(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->vpm,&pDiveState->decolistVPM, DECOSTOPS);
         pDiveState->lifeData.cns += vpm_get_CNS();
+
+        while(decoLock == DECO_CALC_FINSHED_vpm)
+        {
+        	HAL_Delay(2);	/* The deco data is copied during the timer ISR => wait till this has happened */
+        }
         return &pDiveState->decolistVPM;
     }
 }