diff Discovery/Src/data_exchange_main.c @ 342:ea3fda8eb93e FlightMode_Improvment

Removed averaging of pressure and temperatur values On RTE side data was copied once a second while the average function is called several time a second => no real averaging. In generell a datta value should be processed only once (in RTE) and then only be consumption. Otherwise a risk of inconsistent computations could be raised
author ideenmodellierer
date Tue, 01 Oct 2019 19:13:41 +0200
parents b0045281cb2d
children 439874690f85
line wrap: on
line diff
--- a/Discovery/Src/data_exchange_main.c	Mon Aug 19 11:42:31 2019 +0000
+++ b/Discovery/Src/data_exchange_main.c	Tue Oct 01 19:13:41 2019 +0200
@@ -693,40 +693,31 @@
 	}
 }
 
-#define AVERAGE_COUNT	4
 static float getSampleDepth(SDataExchangeSlaveToMaster *d, SDiveState *ds)
 {
-	static uint8_t c = 0;
-	static float ambient[AVERAGE_COUNT] = {0};
-	static float surface[AVERAGE_COUNT]= {0};
-	static float depth[AVERAGE_COUNT]= {0};
-
-	ambient[c] = d->data[d->boolPressureData].pressure_mbar / 1000.0f;
-	surface[c] = d->data[d->boolPressureData].surface_mbar / 1000.0f;
-	float density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f;
+	float ambient = 0;
+	float surface = 0;
+	float depth = 0;
+	float density = 0;
 
-	ds->lifeData.pressure_ambient_bar = (ambient[0] + ambient[1] + ambient[2] + ambient[3])/4.0f;
-	ds->lifeData.pressure_surface_bar = (surface[0] + surface[1] + surface[2] + surface[3])/4.0f;
-	depth[c] = (ambient[c] - surface[c]) / (0.09807f * density);
+	ambient = d->data[d->boolPressureData].pressure_mbar / 1000.0f;
+	surface = d->data[d->boolPressureData].surface_mbar / 1000.0f;
+	density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f;
 
-	c++;
-	if (c == AVERAGE_COUNT) c = 0;
+	ds->lifeData.pressure_ambient_bar = ambient;
+	ds->lifeData.pressure_surface_bar = surface;
+	depth = (ambient - surface) / (0.09807f * density);
+	ds->lifeData.bool_temp1 = d->data[d->boolPressureData].SPARE1;
 
-	return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f;
+	return depth;
 }
 
-#define TEMP_AVERAGE_COUNT	3
 static float getTemperature(SDataExchangeSlaveToMaster *d)
 {
-	static uint8_t c = 0;
-	static float temp[TEMP_AVERAGE_COUNT] = {0};
-
-	temp[c] = d->data[d->boolPressureData].temperature;
+	float temp = 0;
+	temp = d->data[d->boolPressureData].temperature;
 
-	c++;
-	if (c == TEMP_AVERAGE_COUNT) c = 0;
-
-	return (temp[0] + temp[1] + temp[2])/3.0f;
+	return temp;
 }
 
 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag)