changeset 955:9b29995d6619 Evo_2_23 tip

GNSS backup position: In the previous implementation a position had to be provided by the module in order to be stored in the log. This may cause a wrong position entry (default) in the log, for example if signal is lost while preparing for the dive in the water. To avoid this the last received position will be used for ~2 hours => Diver may take the dive side position before starting with the dive preparation. The last known position will be display in the GNSS position search window as well.
author Ideenmodellierer
date Wed, 01 Jan 2025 20:37:17 +0100
parents 4e4fbd73e329
children
files Common/Inc/data_exchange.h Discovery/Src/logbook.c Discovery/Src/t7.c Small_CPU/Inc/GNSS.h Small_CPU/Inc/rtc.h Small_CPU/Src/GNSS.c Small_CPU/Src/baseCPU2.c Small_CPU/Src/rtc.c Small_CPU/Src/scheduler.c Small_CPU/Src/uartProtocol_GNSS.c
diffstat 10 files changed, 67 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_exchange.h	Wed Jan 01 17:30:50 2025 +0100
+++ b/Common/Inc/data_exchange.h	Wed Jan 01 20:37:17 2025 +0100
@@ -56,6 +56,7 @@
 
 #define GNSS_ALIVE_STATE_ALIVE		(0x01u)		/* Communication to module active */
 #define GNSS_ALIVE_STATE_TIME		(0x02u)		/* Time information valid */
+#define GNSS_ALIVE_BACKUP_POS		(0x04u)		/* Backup position not older than x hours */
 
 enum MODE
 {
--- a/Discovery/Src/logbook.c	Wed Jan 01 17:30:50 2025 +0100
+++ b/Discovery/Src/logbook.c	Wed Jan 01 20:37:17 2025 +0100
@@ -1363,8 +1363,12 @@
 
 #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 */
+
+			if(pStateReal->lifeData.gnssData.alive & GNSS_ALIVE_BACKUP_POS)
+			{
+				pStateReal->events.info_gnssPosition = pStateReal->lifeData.gnssData.coord;
+			}
+			else /* no pos => define dummy */
 			{
 				pStateReal->events.info_gnssPosition.fLon = 47.77;
 				pStateReal->events.info_gnssPosition.fLat = 8.99;
--- a/Discovery/Src/t7.c	Wed Jan 01 17:30:50 2025 +0100
+++ b/Discovery/Src/t7.c	Wed Jan 01 20:37:17 2025 +0100
@@ -4049,7 +4049,7 @@
     if(stateUsed->lifeData.gnssData.fixType < 2)
     {
     	textpointer += snprintf(&text[textpointer],50,"\001Satellites\n\r");
-    	if(stateUsed->lifeData.gnssData.alive & GNSS_ALIVE_STATE_TIME)
+    	if(stateUsed->lifeData.gnssData.alive & GNSS_ALIVE_STATE_ALIVE)
     	{
     		textpointer += snprintf(&text[textpointer],50,"\001\020Status\n\r");
     	}
@@ -4096,6 +4096,11 @@
 
     		index++;
     	}
+    	if(stateUsed->lifeData.gnssData.alive & GNSS_ALIVE_BACKUP_POS)
+    	{
+    		snprintf(text,50,"\001%2.2f %2.2f", stateUsed->lifeData.gnssData.coord.fLat,stateUsed->lifeData.gnssData.coord.fLon);
+    		GFX_write_string(&FontT24, &t7cY0free, text, 3);
+    	}
     }
 
 
--- a/Small_CPU/Inc/GNSS.h	Wed Jan 01 17:30:50 2025 +0100
+++ b/Small_CPU/Inc/GNSS.h	Wed Jan 01 20:37:17 2025 +0100
@@ -93,6 +93,10 @@
 
 	uint8_t alive;
 
+	float last_fLon;	/* last known position storage and time stamp */
+	float last_fLat;
+	float last_hour;
+
 }GNSS_StateHandle;
 
 GNSS_StateHandle GNSS_Handle;
--- a/Small_CPU/Inc/rtc.h	Wed Jan 01 17:30:50 2025 +0100
+++ b/Small_CPU/Inc/rtc.h	Wed Jan 01 20:37:17 2025 +0100
@@ -40,6 +40,8 @@
 void RTC_SetTime(RTC_TimeTypeDef stimestructure);
 void RTC_SetDate(RTC_DateTypeDef sdatestructure);
 
+void RTC_GetTime(RTC_TimeTypeDef* pstimestructure);
+
 #ifdef __cplusplus
 }
 #endif
--- a/Small_CPU/Src/GNSS.c	Wed Jan 01 17:30:50 2025 +0100
+++ b/Small_CPU/Src/GNSS.c	Wed Jan 01 20:37:17 2025 +0100
@@ -29,6 +29,7 @@
 #include <string.h>
 #include "GNSS.h"
 #include "data_exchange.h"
+#include "rtc.h"
 
 union u_Short uShort;
 union i_Short iShort;
@@ -57,7 +58,6 @@
 	GNSS->vAcc = 0;
 	GNSS->gSpeed = 0;
 	GNSS->headMot = 0;
-	GNSS->alive = 0;
 }
 
 /*!
@@ -80,6 +80,8 @@
 
 	static float searchCnt = 1.0;
 
+	RTC_TimeTypeDef sTimeNow;
+
 	uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[10];
 	GNSS->yearBytes[0]=GNSS_Handle.uartWorkingBuffer[10];
 	uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[11];
@@ -143,7 +145,7 @@
 
 	if(GNSS->alive & GNSS_ALIVE_STATE_ALIVE)							/* alive */
 	{
-		GNSS->alive &= !GNSS_ALIVE_STATE_ALIVE;
+		GNSS->alive &= ~GNSS_ALIVE_STATE_ALIVE;
 	}
 	else
 	{
@@ -155,7 +157,16 @@
 	}
 	else
 	{
-		GNSS->alive &= !GNSS_ALIVE_STATE_TIME;
+		GNSS->alive &= ~GNSS_ALIVE_STATE_TIME;
+	}
+
+	if(GNSS->fixType >= 2)
+	{
+		RTC_GetTime(&sTimeNow);
+		GNSS->alive |= GNSS_ALIVE_BACKUP_POS;
+		GNSS->last_fLat = GNSS->fLat;
+		GNSS->last_fLon = GNSS->fLon;
+		GNSS->last_hour = sTimeNow.Hours;
 	}
 }
 
--- a/Small_CPU/Src/baseCPU2.c	Wed Jan 01 17:30:50 2025 +0100
+++ b/Small_CPU/Src/baseCPU2.c	Wed Jan 01 20:37:17 2025 +0100
@@ -383,6 +383,12 @@
 	GPIO_Power_MainCPU_Init();
 	global.mode = MODE_TEST;
 #endif
+
+	GNSS_Handle.alive = 0;			/* only init at startup (outside init function) */
+	GNSS_Handle.last_fLat = 0.0;
+	GNSS_Handle.last_fLon = 0.0;
+	GNSS_Handle.last_hour = 0;
+
 	while (1) {
 /*		printf("Global mode = %d\n", global.mode); */
 
--- a/Small_CPU/Src/rtc.c	Wed Jan 01 17:30:50 2025 +0100
+++ b/Small_CPU/Src/rtc.c	Wed Jan 01 20:37:17 2025 +0100
@@ -29,6 +29,12 @@
 static void RTC_Error_Handler(void);
 
 
+
+void RTC_GetTime(RTC_TimeTypeDef* pstimestructure)
+{
+	HAL_RTC_GetTime(&RTCHandle, pstimestructure, RTC_FORMAT_BIN);
+}
+
 void RTC_SetTime(RTC_TimeTypeDef stimestructure)
 {
 
--- a/Small_CPU/Src/scheduler.c	Wed Jan 01 17:30:50 2025 +0100
+++ b/Small_CPU/Src/scheduler.c	Wed Jan 01 20:37:17 2025 +0100
@@ -1794,6 +1794,8 @@
 
 void copyGNSSdata(void)
 {
+	RTC_TimeTypeDef sTimeNow;
+
 	global.dataSendToMaster.data[0].gnssInfo.coord.fLat = GNSS_Handle.fLat;
 	global.dataSendToMaster.data[0].gnssInfo.coord.fLon = GNSS_Handle.fLon;
 	global.dataSendToMaster.data[0].gnssInfo.fixType = GNSS_Handle.fixType;
@@ -1807,6 +1809,23 @@
 
 	global.dataSendToMaster.data[0].gnssInfo.alive = GNSS_Handle.alive;
 
+	if(( GNSS_Handle.fixType < 2) && (GNSS_Handle.alive & GNSS_ALIVE_BACKUP_POS))		/* fallback to last known position ? */
+	{
+		RTC_GetTime(&sTimeNow);
+		if(GNSS_Handle.last_hour > sTimeNow.Hours)
+		{
+			sTimeNow.Hours += 24;	/* compensate date change */
+		}
+		if(sTimeNow.Hours - GNSS_Handle.last_hour > 2)
+		{
+			GNSS_Handle.alive &= ~GNSS_ALIVE_BACKUP_POS;		/* position outdated */
+		}
+		else
+		{
+			global.dataSendToMaster.data[0].gnssInfo.coord.fLat = GNSS_Handle.last_fLat;
+			global.dataSendToMaster.data[0].gnssInfo.coord.fLon = GNSS_Handle.last_fLon;
+		}
+	}
 	memcpy(&global.dataSendToMaster.data[0].gnssInfo.signalQual,&GNSS_Handle.statSat, sizeof(GNSS_Handle.statSat));
 }
 
--- a/Small_CPU/Src/uartProtocol_GNSS.c	Wed Jan 01 17:30:50 2025 +0100
+++ b/Small_CPU/Src/uartProtocol_GNSS.c	Wed Jan 01 20:37:17 2025 +0100
@@ -289,7 +289,9 @@
 													break;
 												case UART_GNSS_LOADCONF_2:	gnssState = UART_GNSS_SETMODE_MOBILE;
 													break;
-												case UART_GNSS_SETMODE_MOBILE: gnssState = UART_GNSS_PWRUP;
+												case UART_GNSS_SETMODE_MOBILE:	rxState = GNSSRX_DETECT_ACK_0;
+																				UART_Gnss_SendCmd(GNSSCMD_MODE_NORMAL);
+																				gnssState = UART_GNSS_PWRUP;
 													break;
 												default:
 													break;