changeset 941:6d8ae8fbccf5 Evo_2_23

Added gnss to logbook data: The gnss position is now available in the logbook. It is stored as event (7:2) at the start of the dive. The position will be shown in the logbook page 1 in the top middle position.
author Ideenmodellierer
date Mon, 16 Dec 2024 19:06:37 +0100
parents 4a406e873a95
children 06aaccaf2e02
files Common/Inc/data_central.h Discovery/Inc/logbook.h Discovery/Src/base.c Discovery/Src/logbook.c Discovery/Src/logbook_miniLive.c Discovery/Src/show_logbook.c Discovery/Src/t7.c
diffstat 7 files changed, 118 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_central.h	Thu Dec 12 21:12:07 2024 +0100
+++ b/Common/Inc/data_central.h	Mon Dec 16 19:06:37 2024 +0100
@@ -169,6 +169,11 @@
 {
 	float fLat;
 	float fLon;
+}SGnssCoord;
+
+typedef struct
+{
+	SGnssCoord coord;
 	uint8_t alive;
 	uint8_t fixType;
 	uint8_t numSat;			/* number of available satellites */
@@ -312,6 +317,8 @@
 	int16_t info_bailoutO2;
     int16_t compassHeadingUpdate;
     uint16_t info_compassHeadingUpdate;
+    int16_t gnssPositionUpdate;
+    SGnssCoord info_gnssPosition;
 } SEvents;
 
 
--- a/Discovery/Inc/logbook.h	Thu Dec 12 21:12:07 2024 +0100
+++ b/Discovery/Inc/logbook.h	Mon Dec 16 19:06:37 2024 +0100
@@ -212,9 +212,9 @@
 uint8_t logbook_getHeader(uint8_t StepBackwards,SLogbookHeader* pLogbookHeader);
 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t*  gasid, int16_t* temperature, uint16_t* ppo2,
 							    uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout,
-								uint16_t* decostopDepth, uint16_t* tank, uint8_t* event);
+								uint16_t* decostopDepth, uint16_t* tank, SGnssCoord* pPosition, uint8_t* event);
 void logbook_test(void);
-void logbook_InitAndWrite(const SDiveState* pStateReal);
+void logbook_InitAndWrite(SDiveState* pStateReal);
 void logbook_recover_brokenlog(uint8_t headerId);
 
 uint16_t logbook_lastDive_diveNumber(void);
--- a/Discovery/Src/base.c	Thu Dec 12 21:12:07 2024 +0100
+++ b/Discovery/Src/base.c	Mon Dec 16 19:06:37 2024 +0100
@@ -571,7 +571,7 @@
             logbook_InitAndWrite(stateUsed);
 #endif
         	if(stateUsed == stateRealGetPointer())	/* Handle log entries while in dive mode*/
-                logbook_InitAndWrite(stateUsed);
+                logbook_InitAndWrite((SDiveState*)stateUsed);
         }
 #ifdef T7_DEBUG_RUNTIME
     	timeMainLoop = time_elapsed_ms(startTimeMainLoop, HAL_GetTick());
--- a/Discovery/Src/logbook.c	Thu Dec 12 21:12:07 2024 +0100
+++ b/Discovery/Src/logbook.c	Mon Dec 16 19:06:37 2024 +0100
@@ -405,6 +405,7 @@
     length++;
     eventByte1.uw = 0;
     eventByte2.uw = 0;
+    uint8_t* pdata;
     //uint16_t tmpU16 = 0;
 	const SDecoinfo * pDecoinfo; // new hw 160620
 
@@ -462,6 +463,11 @@
         eventByte1.ub.bit7 = 1;
         eventByte2.ub.bit1 = 1;
     }
+    if (state->events.gnssPositionUpdate) {
+            eventByte1.ub.bit7 = 1;
+            eventByte2.ub.bit2 = 1;
+    }
+
     //Add EventByte 1
     if(eventByte1.uw > 0)
     {
@@ -507,7 +513,18 @@
         sample[length++] = state->events.info_compassHeadingUpdate & 0xFF;
         sample[length++] = (state->events.info_compassHeadingUpdate & 0xFF00) >> 8;
     }
-
+    if (state->events.gnssPositionUpdate) {
+    	pdata = (uint8_t*)&state->events.info_gnssPosition.fLon;
+        sample[length++] = *pdata++;
+        sample[length++] = *pdata++;
+        sample[length++] = *pdata++;
+        sample[length++] = *pdata++;
+        pdata = (uint8_t*)&state->events.info_gnssPosition.fLat;
+        sample[length++] = *pdata++;
+        sample[length++] = *pdata++;
+        sample[length++] = *pdata++;
+        sample[length++] = *pdata++;
+    }
 
     if(divisor.temperature == 0)
     {
@@ -688,7 +705,8 @@
   * @return bytes read / 0 = reading Error
   */
 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2,
-						   int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank, uint8_t* event)
+						   int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank,
+						   SGnssCoord* pPosition, uint8_t* event)
 {
 	int length = 0;
 	_Bool bEvent = 0;
@@ -700,6 +718,8 @@
 	uint8_t tempU8 = 0;
 	uint16_t temp = 0;
 	uint16_t bytesRead = 0;
+	uint32_t tempU32 = 0;
+	uint8_t index = 0;
 
 	if(gasid)
 		*gasid = -1;
@@ -816,6 +836,34 @@
 				if(gasid)
 						*gasid = 0;
 			}
+			/* gnss position start dive */
+			if(eventByte2.ub.bit2)
+			{
+				tempU32 = 0;
+				for(index = 0; index < 4; index++)
+				{
+					ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+					bytesRead +=1;
+					length -= 1;
+					tempU32 |= (tempU8 << (index * 8));
+				}
+				if(tempU32 != 0xffffffff)
+				{
+					memcpy(&pPosition->fLon, &tempU32, 4);
+				}
+				tempU32 = 0;
+				for(index = 0; index < 4; index++)
+				{
+					ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+					bytesRead +=1;
+					length -= 1;
+					tempU32 |= (tempU8 << (index * 8));
+				}
+				if(tempU32 != 0xffffffff)
+				{
+					memcpy(&pPosition->fLat, &tempU32, 4);
+				}
+			}
 	}
 
 	if(divisor.temperature == 0)
@@ -958,7 +1006,7 @@
   */
 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t*  gasid, int16_t* temperature, uint16_t* ppo2,
 							    uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout,
-								uint16_t* decostopDepth, uint16_t* tank, uint8_t* event)
+								uint16_t* decostopDepth, uint16_t* tank, SGnssCoord* pPosition, uint8_t* event)
 {
      //Test read
     //SLogbookHeader header;
@@ -995,6 +1043,9 @@
 	uint16_t tankVal = 0;
 	uint32_t small_profileLength = 0;
 	uint8_t eventdata;
+	SGnssCoord posCoord;
+	posCoord.fLat = 0.0;
+	posCoord.fLon = 0.0;
 
      SManualGas manualGasVal;
      SManualGas manualGasLast;
@@ -1075,7 +1126,7 @@
 				ext_flash_set_entry_point();
 				divisorBackup = divisor;
 				retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
-									&bailoutVal, &decostepDepthVal, &tankVal, &eventdata);
+									&bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
 
 				if(retVal == 0)
 				{
@@ -1083,7 +1134,7 @@
 						ext_flash_reopen_read_sample_at_entry_point();
 						divisor = divisorBackup;
 						retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal,
-											&manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &eventdata);
+											&manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
 
 						if(retVal == 0)
 								break;
@@ -1223,6 +1274,10 @@
 					}
 				}
 		}
+		if(pPosition)
+		{
+			memcpy(pPosition, &posCoord, sizeof(posCoord));
+		}
 	}
 	else
 	{
@@ -1251,7 +1306,7 @@
  *          and finishes logbook after end of dive
 *********************************************************************************/
 
-void logbook_InitAndWrite(const SDiveState *pStateReal)
+void logbook_InitAndWrite(SDiveState *pStateReal)
 {
 	SSettings *pSettings = settingsGetPointer();
 	static uint8_t bDiveMode = 0;
@@ -1268,6 +1323,7 @@
 			pSettings->totalDiveCounter++;
 			logbook_initNewdiveProfile(pStateReal,settingsGetPointer());
 			min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius;
+
 			//Write logbook sample
 			logbook_writeSample(pStateReal);
 			resetEvents(pStateReal);
@@ -1304,6 +1360,17 @@
 
 				ext_flash_CloseSector();	/* this is just a repair function which invalidates a not used sector in case a log maintenance was called before dive */
 				bDiveMode = 3;
+
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+			pStateReal->events.gnssPositionUpdate = 1;
+			pStateReal->events.info_gnssPosition = pStateReal->lifeData.gnssData.coord;
+			if((pStateReal->events.info_gnssPosition.fLat == 0.0) && (pStateReal->events.info_gnssPosition.fLon == 0.0)) /* no pos => define dummy */
+			{
+				pStateReal->events.info_gnssPosition.fLon = 47.77;
+				pStateReal->events.info_gnssPosition.fLat = 8.99;
+			}
+#endif
+
 			}
 			if(bDiveMode == 3)
 				logbook_UpdateHeader(pStateReal);
@@ -1798,7 +1865,11 @@
     int32_t sensor2Val = 0;
     int32_t sensor3Val = 0;
     int32_t cnsVal = 0;
-     SManualGas manualGasVal;
+    SManualGas manualGasVal;
+    int16_t decostepDepthVal = 0;
+	uint16_t tankVal = 0;
+	uint8_t eventdata;
+	SGnssCoord posCoord;
 
 		//uint16_t* ppo2, uint16_t* cns#
      uint32_t bytesRead = 0;
@@ -1818,21 +1889,22 @@
 
         ext_flash_set_entry_point();
         divisorBackup = divisor;
-				retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL);
+		retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
+							&bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata);
         if(retVal == 0)
         {
           //Error try to read again!!!
           ext_flash_reopen_read_sample_at_entry_point();
           divisor = divisorBackup;
-					retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL);
-
+		  retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
+								&bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
           if(retVal == 0)
           {
               //Error try to read again!!!
               ext_flash_reopen_read_sample_at_entry_point();
               divisor = divisorBackup;
-							retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL);
-
+			  retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
+				 				&bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata);
               if(retVal == 0)
               {
                 ext_flash_reopen_read_sample_at_entry_point();
--- a/Discovery/Src/logbook_miniLive.c	Thu Dec 12 21:12:07 2024 +0100
+++ b/Discovery/Src/logbook_miniLive.c	Mon Dec 16 19:06:37 2024 +0100
@@ -367,7 +367,7 @@
     	ReplayDataOffset = StepBackwards;
 		logbook_getHeader(StepBackwards ,&logbookHeader);
 
-		dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, ReplayDepthData,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ReplayMarkerData);
+		dataLength = logbook_readSampleData(StepBackwards, DEPTH_DATA_LENGTH, ReplayDepthData,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, ReplayMarkerData);
 
 	/* check if a marker is provided. If not disable marker functionality for the replay block */
 		for(index = 0; index < dataLength; index++)
--- a/Discovery/Src/show_logbook.c	Thu Dec 12 21:12:07 2024 +0100
+++ b/Discovery/Src/show_logbook.c	Mon Dec 16 19:06:37 2024 +0100
@@ -444,6 +444,10 @@
     int16_t tempdata[1000] = { 0 };
     uint16_t tankdata[1000] = { 0 };
 
+    SGnssCoord posCoord;
+    posCoord.fLat = 0.0;
+    posCoord.fLon = 0.0;
+
 #ifdef ENABLE_BOTTLE_SENSOR
     uint16_t bottlePressureStart = 0;
     uint16_t bottlePressureEnd = 0;
@@ -451,7 +455,7 @@
 #endif
 
     uint16_t dataLength = 0;
-    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tankdata,NULL);
+    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, tankdata, &posCoord, NULL);
 
     //Print Date
     uint8_t year = logbookHeader.dateYear;
@@ -462,6 +466,14 @@
 
     Gfx_write_label_var(hgfx, 30, 250,10, &FontT42,CLUT_GasSensor1,text);
 
+#if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+    if((posCoord.fLat != 0.0) || (posCoord.fLon != 0.0))
+    {
+    	snprintf(text, 20, "%2.4f - %2.4f", posCoord.fLat, posCoord.fLon );
+    	Gfx_write_label_var(hgfx, 300, 500,10, &FontT42,CLUT_GasSensor1,text);
+    }
+#endif
+
 
     // Print logbook number with offset
     if(settingsGetPointer()->logbookOffset)
@@ -740,7 +752,7 @@
     uint16_t decoDepthdata[1000];
     uint16_t *pDecoDepthData = 0;
 
-    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, decoDepthdata, NULL, NULL);
+    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, tempdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, decoDepthdata, NULL, NULL, NULL);
 
         for(int i = 0; i<dataLength; i++)
         {
@@ -905,7 +917,7 @@
     uint16_t dataLength = 0;
     uint16_t depthdata[1000];
     uint8_t  gasdata[1000];
-    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+    dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
 
     char msg[15];
     char gas_name[15];
@@ -1035,15 +1047,15 @@
 
 
         if(!isLoopMode(logbookHeader.diveMode))
-            dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+            dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         else
         {
         	switch(logbookHeader.CCRmode)
         	{
         		case CCRMODE_FixedSetpoint:
-        		default:				dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, setpoint, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+        		default:				dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, setpoint, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         				break;
-        		case CCRMODE_Sensors:	dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, NULL, sensor1, sensor2, sensor3, NULL, NULL, NULL, NULL, NULL);
+        		case CCRMODE_Sensors:	dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata, gasdata, NULL, NULL, NULL, sensor1, sensor2, sensor3, NULL, NULL, NULL, NULL, NULL, NULL);
         								if(!check_data_array_empty(sensor1))
         								{
         									sensorDataAvailable[0] = 1;
@@ -1060,22 +1072,22 @@
         								{
         									if(sensorDataAvailable[0] == 0)
         									{
-        										logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+        										logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         										sensorDataAvailable[0] = 1;
         									}
         									else if(sensorDataAvailable[1] == 0)
         									{
-        										logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+        										logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         										sensorDataAvailable[1] = 1;
         									}
         									else if(sensorDataAvailable[2] == 0)
         									{
-        										logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+        										logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, sensor3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         										sensorDataAvailable[2] = 1;
         									}
         								}
         		    	break;
-        		case CCRMODE_Simulation: dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
+        		case CCRMODE_Simulation: dataLength = logbook_readSampleData(StepBackwards, 1000, depthdata,gasdata, NULL, ppO2data, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
         				break;
         	}
         }
--- a/Discovery/Src/t7.c	Thu Dec 12 21:12:07 2024 +0100
+++ b/Discovery/Src/t7.c	Mon Dec 16 19:06:37 2024 +0100
@@ -4072,7 +4072,7 @@
     	snprintf(text,60,
     			"\001%0.5f\n\r"
     			"\001%0.5f\n\r"
-    			,stateUsed->lifeData.gnssData.fLat ,stateUsed->lifeData.gnssData.fLon);
+    			,stateUsed->lifeData.gnssData.coord.fLat ,stateUsed->lifeData.gnssData.coord.fLon);
     }
     GFX_write_string(&FontT42, &t7cY0free, text, 1);