changeset 458:5dd996ed8611 minor_improvments

Added ppO2 to dummy profile data: PPO2 calculation based on the first gas has been added to the dummy profile to enable drawing of the graph at log page four As this increased the number of parameters to be passed to the sub functions, the complete dive header is passed as reference instead of single members to increase the code maintanability
author ideenmodellierer
date Sat, 28 Mar 2020 21:41:47 +0100
parents 4bd01f48c285
children 7ac0e76dbd6a
files Discovery/Inc/logbook.h Discovery/Src/logbook.c Discovery/Src/tComm.c
diffstat 3 files changed, 76 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/logbook.h	Tue Mar 24 22:32:48 2020 +0100
+++ b/Discovery/Inc/logbook.h	Sat Mar 28 21:41:47 2020 +0100
@@ -30,6 +30,8 @@
 #include "data_central.h"
 #include "settings.h"
 
+#define NUM_GAS		(5)	/* number of selectable gases */
+
 typedef struct
 {
     uint8_t setpoint_cbar;
@@ -65,7 +67,7 @@
     int16_t  minTemp;
     uint16_t surfacePressure_mbar;
     uint16_t desaturationTime;
-    SGasListLog gasordil[5];
+    SGasListLog gasordil[NUM_GAS];
     uint8_t  firmwareVersionLow;
     uint8_t  firmwareVersionHigh;
     uint16_t batteryVoltage;
@@ -73,7 +75,7 @@
     uint8_t  gfAtBeginning;
     uint8_t  gfAtEnd;
     uint16_t personalDiveCount;
-    SSetpointLog setpoint[5];
+    SSetpointLog setpoint[NUM_GAS];
     uint16_t maxCNS;
     uint16_t averageDepth_mbar;
     uint16_t total_diveTime_seconds;
@@ -114,7 +116,7 @@
     uint8_t minTemp[2];
     uint8_t surfacePressure_mbar[2];
     uint8_t desaturationTime[2];
-    uint8_t gasordil[5*4];
+    uint8_t gasordil[NUM_GAS*4];
     uint8_t firmwareVersionLow;
     uint8_t firmwareVersionHigh;
     uint8_t batteryVoltage[2];
@@ -217,7 +219,7 @@
 void logbook_recover_brokenlog(uint8_t headerId);
 
 uint16_t logbook_lastDive_diveNumber(void);
-uint16_t logbook_fillDummySampleBuffer(uint16_t diveMinutes, uint8_t diveSeconds, uint16_t maxDepth, uint8_t lastDecostop_m, int16_t minTemp);
+uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader);
 void logbook_readDummySamples(uint8_t* pTarget, uint16_t length);
 
 #endif /* LOGBOOK_H */
--- a/Discovery/Src/logbook.c	Tue Mar 24 22:32:48 2020 +0100
+++ b/Discovery/Src/logbook.c	Sat Mar 28 21:41:47 2020 +0100
@@ -103,7 +103,7 @@
 static void logbook_SetLastStop(float last_stop_depth_bar);
 static void logbook_writedata(void * data, int length_byte);
 static void logbook_UpdateHeader(const SDiveState * pStateReal);
-static void logbook_createDummyProfile(uint16_t maxDepth, uint8_t lastDecostop_m, int16_t minTemp, uint16_t length, uint16_t* depth, int16_t* temperature);
+static void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2);
 
 /* Exported functions --------------------------------------------------------*/
 
@@ -528,6 +528,7 @@
 					length += 1;
 					sample[length] = 0;
 					length += 1;
+					pDecoinfo = &stateUsed->decolistBuehlmann;	/* use GF per default if something went wrong */
 				}
 					
 				if(pDecoinfo->output_ndl_seconds > 0)
@@ -952,11 +953,11 @@
 
     //logbook_getHeader(&header);
     SLogbookHeader header;
-    int iNum;
-    int firstgasid = 0;
-    int retVal = 0;
-    int compression = 0;
-     int i;
+    int16_t iNum;
+    int16_t firstgasid = 0;
+    uint16_t retVal = 0;
+    int16_t compression = 0;
+    int16_t i;
    // uint32_t diveTime_seconds;
     int32_t depthVal = 0;
     int16_t  gasidVal = 0;
@@ -1190,7 +1191,7 @@
 	}
 	else
 	{
-		logbook_createDummyProfile(header.maxDepth, header.lastDecostop_m, header.minTemp, numSamples, depth, temperature);
+		logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2);
 		iNum = numSamples;
 	}
 		
@@ -1479,8 +1480,7 @@
 		&&(pHead->pBeginProfileData[1] == 0)
 		&&(pHead->pBeginProfileData[2] == 0))
 	{
-		dummyLength = logbook_fillDummySampleBuffer(pHead->diveTimeMinutes, pHead->diveTimeSeconds,pHead->maxDepth
-													,pHead->lastDecostop_m, pHead->minTemp);
+		dummyLength = logbook_fillDummySampleBuffer(pHead);
 
 		data2.u32bit = data.u32bit + dummyLength;	/* calc new end address (which is equal to dummyLength) */
 		data.u32bit = data2.u32bit;				    /* data is used below to represent the length */
@@ -1636,8 +1636,7 @@
 		&&(pHead->pBeginProfileData[1] == 0)
 		&&(pHead->pBeginProfileData[2] == 0))
 	{
-		dummyLength = logbook_fillDummySampleBuffer(pHead->diveTimeMinutes, pHead->diveTimeSeconds,pHead->maxDepth
-													,pHead->lastDecostop_m, pHead->minTemp);
+		dummyLength = logbook_fillDummySampleBuffer(pHead);
 
 		data2.u32bit = data.u32bit + dummyLength;	/* calc new end address (which is equal to dummyLength) */
 		data.u32bit = data2.u32bit;				    /* data is used below to represent the length */
@@ -1787,7 +1786,7 @@
     ext_flash_close_new_dive_log((uint8_t *)&header);
 }
 
-void logbook_createDummyProfile(uint16_t maxDepth, uint8_t lastDecostop_m, int16_t minTemp, uint16_t length, uint16_t* depth, int16_t* temperature)
+void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2)
 {
 	uint8_t	 drawDeco = 1;
 	uint16_t index = 0;
@@ -1797,31 +1796,66 @@
 	uint16_t simDecentStep = 0;
 	uint16_t simAcentDepth = 0;
 	uint16_t simAcentStep = 0;
+	float ambiant_pressure_bar = 0;
 
-	simDecentStep = maxDepth / (length / 6);						/* first 1/6 for descend */
-	simAcentStep = maxDepth / (length / 3);							/* first 1/3 for ascend */
+	simDecentStep = pHeader->maxDepth / (length / 6);							/* first 1/6 for descend */
+	simAcentStep = pHeader->maxDepth / (length / 3);							/* first 1/3 for ascend */
+
+	SGas gas;
+
 
-	while((index < length) && (simDecentDepth < maxDepth))				/* draw decent */
+	if(ppo2)
+	{
+		/* find first gas ID */
+		for(index = 0; index < NUM_GAS; index++)
+		{
+			if(pHeader->gasordil[index].note.ub.first)
+				break;
+		}
+		if(index != NUM_GAS)
+		{
+			gas.helium_percentage = pHeader->gasordil[index].helium_percentage;
+			gas.nitrogen_percentage = 100 -  gas.helium_percentage - pHeader->gasordil[index].oxygen_percentage;
+		}
+	}
+
+	while((index < length) && (simDecentDepth < pHeader->maxDepth))			/* draw decent */
 	{
 		depth[index] = simDecentDepth;
-		temperature[index] = minTemp;
+		temperature[index] = pHeader->minTemp;
+		if(ppo2)
+		{
+			ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+			ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+		}
 		index++;
 		simDecentDepth += simDecentStep;
 	}
 	indexDescenStop = index;
 	index = length -1;
-	while((index > indexDescenStop) && (simAcentDepth < maxDepth))				/* draw ascend including max deco stop */
+	while((index > indexDescenStop) && (simAcentDepth < pHeader->maxDepth))				/* draw ascend including max deco stop */
 	{
 		depth[index] = simAcentDepth;
-		temperature[index] = minTemp;
-		if((drawDeco) && (simAcentDepth < lastDecostop_m))						/* draw deco step */
+		temperature[index] = pHeader->minTemp;
+		if(ppo2)
+		{
+			ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+			ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+		}
+		if((drawDeco) && (simAcentDepth < pHeader->lastDecostop_m))						/* draw deco step */
 		{
 			drawDeco = length / 10;
-			while (drawDeco)
+			while(drawDeco)
 			{
 				index--;
 				depth[index] = simAcentDepth;
-				temperature[index] = minTemp;
+				temperature[index] = pHeader->minTemp;
+				if(ppo2)
+				{
+					ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+					ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+				}
+				drawDeco--;
 			}
 		}
 		index--;
@@ -1831,8 +1865,13 @@
 	index = indexDescenStop;
 	while(index <= indexAscendStart)												/* draw isobar dive phase */
 	{
-		depth[index] = maxDepth;
-		temperature[index] = minTemp;
+		depth[index] = pHeader->maxDepth;
+		temperature[index] = pHeader->minTemp;
+		if(ppo2)
+		{
+			ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+			ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+		}
 		index++;
 	}
 }
@@ -1875,15 +1914,16 @@
 }
 
 
-uint16_t logbook_fillDummySampleBuffer(uint16_t diveMinutes, uint8_t diveSeconds, uint16_t maxDepth, uint8_t lastDecostop_m, int16_t minTemp)
+uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader)
 {
 	uint16_t depthArray[DUMMY_SAMPLES];
 	int16_t temperatureArray[DUMMY_SAMPLES];
+	uint16_t ppo2Array[DUMMY_SAMPLES];
 
 	uint16_t index = 0;
 	uint16_t dummyBufferSize = 0;
 	uint16_t dummyProfileLength = 0;
-	uint32_t overallSecond = diveMinutes * 60 + diveSeconds;
+	uint32_t overallSecond = pHeader->diveTimeMinutes * 60 + pHeader->diveTimeSeconds;
 
 	logbook_resetDummy();
 	clear_divisor();
@@ -1936,7 +1976,7 @@
 		dummyProfileLength = overallSecond / smallDummyHeader.samplingRate_seconds;
 	}
 	logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader));
-	logbook_createDummyProfile(maxDepth, lastDecostop_m, minTemp, dummyProfileLength, depthArray, temperatureArray);
+	logbook_createDummyProfile(pHeader,dummyProfileLength, depthArray, temperatureArray, ppo2Array );
 
 	for (index = 0; index < dummyProfileLength; index++)
 	{
--- a/Discovery/Src/tComm.c	Tue Mar 24 22:32:48 2020 +0100
+++ b/Discovery/Src/tComm.c	Sat Mar 28 21:41:47 2020 +0100
@@ -583,7 +583,6 @@
 #else
     uint8_t dummyForBootloader[256] = {0};
 #endif
-
     uint8_t count;
     uint8_t aTxBuffer[128];
     uint8_t aRxBuffer[68];
@@ -1183,9 +1182,11 @@
         if(HAL_UART_Transmit(&UartHandle, (uint8_t*)plogbookHeaderOSTC3, 256,5000)!= HAL_OK)
             return 0;
 
-        if(logbookHeader.pBeginProfileData[0]==0)	/* no sample information */
+        if((logbookHeader.pBeginProfileData[0]==0)	/* no sample information */
+        	&& (logbookHeader.pBeginProfileData[1]==0)
+			&& (logbookHeader.pBeginProfileData[2]==0))
         {
-        	sampleTotalLength = logbook_fillDummySampleBuffer(logbookHeader.diveTimeMinutes, logbookHeader.diveTimeSeconds, logbookHeader.maxDepth, logbookHeader.lastDecostop_m, logbookHeader.minTemp);
+        	sampleTotalLength = logbook_fillDummySampleBuffer(&logbookHeader);
 			while(sampleTotalLength >= 128)
 			{
 				logbook_readDummySamples(aTxBuffer,128);