changeset 931:5a9bc2e6112d Evo_2_23

Added Sat Status Overview: In addition to the navigation data now information regarding the satelliete and signal status are visualized. To enable the a new command has been added to the communication protocol and the position view has been extended.
author Ideenmodellierer
date Tue, 03 Dec 2024 20:32:51 +0100
parents 25948e805406
children effadaa3a1f7
files Common/Inc/data_central.h Common/Inc/data_exchange.h Discovery/Src/data_exchange_main.c Discovery/Src/t7.c Small_CPU/Inc/GNSS.h Small_CPU/Inc/uartProtocol_GNSS.h Small_CPU/Inc/uart_Internal.h Small_CPU/Src/GNSS.c Small_CPU/Src/scheduler.c Small_CPU/Src/uart_Internal.c
diffstat 10 files changed, 179 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/Common/Inc/data_central.h	Tue Dec 03 20:24:06 2024 +0100
+++ b/Common/Inc/data_central.h	Tue Dec 03 20:32:51 2024 +0100
@@ -167,9 +167,12 @@
 
 typedef struct
 {
-	float Longitude;
-	float Latitude;
-} 	SPositionData;
+	float fLat;
+	float fLon;
+	uint8_t fixType;
+	uint8_t numSat;			/* number of available satellites */
+	uint8_t signalQual[4];	/* signal quality indicator for x sats */
+} SGnssInfo;
 
 
 /* struct SLifeData
@@ -253,7 +256,7 @@
 /* for PSCR Mode */
 	 float ppo2Simulated_bar;
 /* GNSS data */
-	 SPositionData gnssPosition;
+	 SGnssInfo gnssData;
 
 } 	SLifeData;
 
--- a/Common/Inc/data_exchange.h	Tue Dec 03 20:24:06 2024 +0100
+++ b/Common/Inc/data_exchange.h	Tue Dec 03 20:32:51 2024 +0100
@@ -198,8 +198,7 @@
 		//debug
 		uint32_t pressure_uTick;
 		uint32_t compass_uTick;
-		float fLat;
-		float fLon;
+		SGnssInfo gnssInfo;
 
 } 	SExchangeData;
 
--- a/Discovery/Src/data_exchange_main.c	Tue Dec 03 20:24:06 2024 +0100
+++ b/Discovery/Src/data_exchange_main.c	Tue Dec 03 20:32:51 2024 +0100
@@ -1014,8 +1014,7 @@
 		pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr;
 		pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr;
 
-		pStateReal->lifeData.gnssPosition.Latitude = dataIn.data[0].fLat;
-		pStateReal->lifeData.gnssPosition.Longitude = dataIn.data[0].fLon;
+		memcpy(&pStateReal->lifeData.gnssData, &dataIn.data[0].gnssInfo, sizeof(dataIn.data[0].gnssInfo));
 	}
 
 	if(pStateReal->data_old__lost_connection_to_slave == 0)
--- a/Discovery/Src/t7.c	Tue Dec 03 20:24:06 2024 +0100
+++ b/Discovery/Src/t7.c	Tue Dec 03 20:32:51 2024 +0100
@@ -4040,16 +4040,20 @@
     t7cY0free.WindowY0 = t7cH.WindowY0 - 5 - 2 * t7cY0free.WindowLineSpacing;
     t7cY0free.WindowNumberOfTextLines = 3;
 
+    textpointer += snprintf(&text[textpointer],50,"\001Satellites\n\r");
     textpointer += snprintf(&text[textpointer],50,"\001Longitude\n\r");
     textpointer += snprintf(&text[textpointer],50,"\001Latitude\n\r");
     GFX_write_string(&FontT24, &t7cY0free, text, 1);
 
     t7cY0free.WindowY0 -= 52;
     snprintf(text,60,
+    	"\001%d - %d %d %d %d %d\n\r"
         "\001%0.5f\n\r"
         "\001%0.5f\n\r"
-        ,stateUsed->lifeData.gnssPosition.Longitude
-		,stateUsed->lifeData.gnssPosition.Latitude );
+    	,stateUsed->lifeData.gnssData.numSat, stateUsed->lifeData.gnssData.fixType
+    	,stateUsed->lifeData.gnssData.signalQual[0],stateUsed->lifeData.gnssData.signalQual[1],stateUsed->lifeData.gnssData.signalQual[2],stateUsed->lifeData.gnssData.signalQual[3]
+        ,stateUsed->lifeData.gnssData.fLat
+		,stateUsed->lifeData.gnssData.fLon );
 
     GFX_write_string(&FontT42, &t7cY0free, text, 1);
 }
--- a/Small_CPU/Inc/GNSS.h	Tue Dec 03 20:24:06 2024 +0100
+++ b/Small_CPU/Inc/GNSS.h	Tue Dec 03 20:32:51 2024 +0100
@@ -60,7 +60,7 @@
 	UART_HandleTypeDef *huart;
 
 	uint8_t uniqueID[4];
-	uint8_t uartWorkingBuffer[101];
+	uint8_t uartWorkingBuffer[255];
 
 	unsigned short year;
 	uint8_t yearBytes[2];
@@ -88,6 +88,9 @@
 	uint8_t gSpeedBytes[4];
 	signed long headMot;
 
+	uint8_t numSat;
+	uint8_t statSat[4];
+
 }GNSS_StateHandle;
 
 GNSS_StateHandle GNSS_Handle;
@@ -110,6 +113,8 @@
 
 static const uint8_t getPVTData[]={0xB5,0x62,0x01,0x07,0x00,0x00,0x08,0x19};
 
+static const uint8_t getNavSat[]={0xB5,0x62,0x01,0x35,0x00,0x00,0x36,0xA3};
+
 static const uint8_t setPortableMode[]={0xB5,0x62,0x06,0x24,0x24,0x00,0xFF,0xFF,0x00,0x03,0x00,0x00,0x00,0x00,0x10,0x27,0x00,0x00,0x05,0x00,0xFA,0x00,0xFA,0x00,0x64,0x00,0x5E,0x01,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x3C};
 
 static const uint8_t setStationaryMode[]={0xB5,0x62,0x06,0x24,0x24,0x00,0xFF,0xFF,0x02,0x03,0x00,0x00,0x00,0x00,0x10,0x27,0x00,0x00,0x05,0x00,0xFA,0x00,0xFA,0x00,0x64,0x00,0x5E,0x01,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80};
@@ -140,6 +145,7 @@
 
 void GNSS_GetNavigatorData(GNSS_StateHandle *GNSS);
 void GNSS_ParseNavigatorData(GNSS_StateHandle *GNSS);
+void GNSS_ParseNavSatData(GNSS_StateHandle *GNSS);
 
 void GNSS_GetPOSLLHData(GNSS_StateHandle *GNSS);
 void GNSS_ParsePOSLLHData(GNSS_StateHandle *GNSS);
--- a/Small_CPU/Inc/uartProtocol_GNSS.h	Tue Dec 03 20:24:06 2024 +0100
+++ b/Small_CPU/Inc/uartProtocol_GNSS.h	Tue Dec 03 20:32:51 2024 +0100
@@ -41,6 +41,7 @@
 		UART_GNSS_LOADCONF_1,
 		UART_GNSS_LOADCONF_2,
 		UART_GNSS_GET_PVT,
+		UART_GNSS_GET_SAT
   } uartGnssStatus_t;
 
   typedef enum
@@ -50,13 +51,15 @@
 	GNSSRX_DETECT_HEADER_1,
 	GNSSRX_DETECT_HEADER_2,
 	GNSSRX_DETECT_HEADER_3,
+	GNSSRX_DETECT_LENGTH_0,
+	GNSSRX_DETECT_LENGTH_1,
 	GNSSRX_DETECT_ACK_0,
 	GNSSRX_DETECT_ACK_1,
 	GNSSRX_DETECT_ACK_2,
 	GNSSRX_DETECT_ACK_3,
-	GNSSRX_READ_NAV_DATA,
-	GNSSRX_READ_PVT_DATA,
-	GNSSRX_READ_POSLLH_DATA
+	GNSSRX_READ_DATA,
+	GNSSRX_READ_CK_A,
+	GNSSRX_READ_CK_B,
   } receiveStateGnss_t;
 
 
@@ -67,9 +70,16 @@
 	GNSSCMD_LOADCONF_2,
 	GNSSCMD_GET_NAV_DATA,
 	GNSSCMD_GET_PVT_DATA,
-	GNSSCMD_GET_POSLLH_DATA
+	GNSSCMD_GET_POSLLH_DATA,
+	GNSSCMD_GET_NAVSAT_DATA
   } gnssSensorCmd_t;
 
+  typedef struct
+  {
+    uint8_t class;
+    uint8_t id;
+  } gnssRequest_s;
+
 
 void uartGnss_Control(void);
 void uartGnss_ProcessData(uint8_t data);
--- a/Small_CPU/Inc/uart_Internal.h	Tue Dec 03 20:24:06 2024 +0100
+++ b/Small_CPU/Inc/uart_Internal.h	Tue Dec 03 20:32:51 2024 +0100
@@ -25,7 +25,7 @@
 #include "stm32f4xx_hal.h"
 
 
-#define BUFFER_NODATA_LOW	(0x15)		/* The read function needs a signiture which indicates that no data for processing is available.*/
+#define BUFFER_NODATA_LOW	(0x15)		/* The read function needs a signature which indicates that no data for processing is available.*/
 #define BUFFER_NODATA_HIGH  (0xA5)
 
 
--- a/Small_CPU/Src/GNSS.c	Tue Dec 03 20:24:06 2024 +0100
+++ b/Small_CPU/Src/GNSS.c	Tue Dec 03 20:32:51 2024 +0100
@@ -26,6 +26,7 @@
  ******************************************************************************
  */
 
+#include <string.h>
 #include "GNSS.h"
 
 union u_Short uShort;
@@ -241,6 +242,55 @@
  * Look at: 32.17.30.1 u-blox 8 Receiver description.
  * @param GNSS Pointer to main GNSS structure.
  */
+void GNSS_ParseNavSatData(GNSS_StateHandle *GNSS) {
+
+	uint8_t loop = 0;
+	uint8_t searchIndex = 0;
+	uint8_t statIndex = 0;	/* only 4 state information will be forwarded */
+	uint8_t signalQuality = 0;
+	GNSS->numSat = GNSS_Handle.uartWorkingBuffer[11];
+
+	memset(GNSS->statSat, 0, sizeof(GNSS->statSat));
+
+	if(GNSS->numSat > 0)
+	{
+		searchIndex = 0;
+		while((searchIndex < GNSS->numSat) && (statIndex < 4))	/* get good signal quality */
+		{
+			signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
+			if(signalQuality > 4)
+			{
+				GNSS->statSat[statIndex++] = signalQuality;
+			}
+			if(statIndex == 4) break;
+			searchIndex++;
+		}
+		searchIndex = 0;
+		while((searchIndex < GNSS->numSat) && (statIndex < 4))	/* get medium signal quality */
+		{
+			signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
+			if((signalQuality > 2) && (signalQuality <= 4))
+			{
+				GNSS->statSat[statIndex++] = signalQuality;
+			}
+			if(statIndex == 4) break;
+			searchIndex++;
+		}
+		searchIndex = 0;
+		while((searchIndex < GNSS->numSat) && (statIndex < 4))	/* get poor signal quality */
+		{
+			signalQuality = (GNSS_Handle.uartWorkingBuffer[22 + searchIndex * 12] & 0x7);
+			if(signalQuality <= 2)
+			{
+				GNSS->statSat[statIndex++] = signalQuality;
+			}
+			if(statIndex == 4) break;
+			searchIndex++;
+		}
+		loop++;
+	}
+}
+
 void GNSS_ParseNavigatorData(GNSS_StateHandle *GNSS) {
 	uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[18];
 	uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[19];
@@ -252,6 +302,7 @@
 	GNSS->sec = GNSS_Handle.uartWorkingBuffer[24];
 }
 
+
 /*!
  * Parse data to geodetic position solution standard.
  * Look at: 32.17.14.1 u-blox 8 Receiver description.
--- a/Small_CPU/Src/scheduler.c	Tue Dec 03 20:24:06 2024 +0100
+++ b/Small_CPU/Src/scheduler.c	Tue Dec 03 20:32:51 2024 +0100
@@ -1747,8 +1747,11 @@
 
 void copyGNSSdata(void)
 {
-	global.dataSendToMaster.data[0].fLat = GNSS_Handle.fLat;
-	global.dataSendToMaster.data[0].fLon = GNSS_Handle.fLon;
+	global.dataSendToMaster.data[0].gnssInfo.fLat = GNSS_Handle.fLat;
+	global.dataSendToMaster.data[0].gnssInfo.fLon = GNSS_Handle.fLon;
+	global.dataSendToMaster.data[0].gnssInfo.fixType = GNSS_Handle.fixType;
+	global.dataSendToMaster.data[0].gnssInfo.numSat = GNSS_Handle.numSat;
+	memcpy(&global.dataSendToMaster.data[0].gnssInfo.signalQual,&GNSS_Handle.statSat, sizeof(GNSS_Handle.statSat));
 }
 
 
--- a/Small_CPU/Src/uart_Internal.c	Tue Dec 03 20:24:06 2024 +0100
+++ b/Small_CPU/Src/uart_Internal.c	Tue Dec 03 20:32:51 2024 +0100
@@ -29,14 +29,15 @@
 
 
 static uint8_t isEndIndication6(uint8_t index);
-static uint8_t gnssState = UART_GNSS_INIT;
+static uartGnssStatus_t gnssState = UART_GNSS_INIT;
+static gnssRequest_s activeRequest = {0,0};
 
 /* Private variables ---------------------------------------------------------*/
 
 
 #define TX_BUF_SIZE				(40u)		/* max length for commands */
-#define CHUNK_SIZE				(25u)		/* the DMA will handle chunk size transfers */
-#define CHUNKS_PER_BUFFER		(6u)
+#define CHUNK_SIZE				(50u)		/* the DMA will handle chunk size transfers */
+#define CHUNKS_PER_BUFFER		(3u)
 
 #define REQUEST_INT_SENSOR_MS	(1500)		/* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */
 #define COMMAND_TX_DELAY		(30u)		/* The time the sensor needs to recover from a invalid command request */
@@ -48,7 +49,7 @@
 
 static uint8_t writeIndex = 0;
 
-static uint8_t dataToRead = 0;
+static uint16_t dataToRead = 0;
 
 DMA_HandleTypeDef  hdma_usart6_rx, hdma_usart6_tx;
 
@@ -276,7 +277,13 @@
 		futureIndex = 0;
 	}
 
-	if((!isEndIndication6(localRX)) || (!isEndIndication6(futureIndex)))	do
+	if(!isEndIndication6(futureIndex))
+	{
+		moreData = 1;
+	}
+
+	if((!isEndIndication6(localRX)) || (moreData))
+	do
 	{
 		while((!isEndIndication6(localRX)) || (moreData))
 		{
@@ -348,12 +355,16 @@
 		case GNSSCMD_GET_NAV_DATA:	pData = getNavigatorData;
 									txLength = sizeof(getNavigatorData) / sizeof(uint8_t);
 			break;
-
+		case GNSSCMD_GET_NAVSAT_DATA: pData = getNavSat;
+									  txLength = sizeof(getNavSat) / sizeof(uint8_t);
+			break;
 		default:
 			break;
 	}
 	if(txLength != 0)
 	{
+		activeRequest.class = pData[2];
+		activeRequest.id = pData[3];
 		UART6_SendCmdUbx(pData, txLength);
 	}
 }
@@ -361,6 +372,7 @@
 void UART6_Gnss_Control(void)
 {
 	static uint32_t warmupTick = 0;
+	static uint8_t dataToggle = 0;
 
 	switch (gnssState)
 	{
@@ -385,9 +397,20 @@
 									gnssState = UART_GNSS_IDLE;
 									rxState = GNSSRX_DETECT_ACK_0;
 				break;
-		case UART_GNSS_IDLE:		UART6_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA);
-									gnssState = UART_GNSS_GET_PVT;
-									rxState = GNSSRX_DETECT_HEADER_0;
+		case UART_GNSS_IDLE:		if(dataToggle)
+									{
+										UART6_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA);
+										gnssState = UART_GNSS_GET_PVT;
+										rxState = GNSSRX_DETECT_HEADER_0;
+										dataToggle = 0;
+									}
+									else
+									{
+										UART6_Gnss_SendCmd(GNSSCMD_GET_NAVSAT_DATA);
+										gnssState = UART_GNSS_GET_SAT;
+										rxState = GNSSRX_DETECT_HEADER_0;
+										dataToggle = 1;
+									}
 				break;
 		default:
 				break;
@@ -396,16 +419,30 @@
 
 void UART6_Gnss_ProcessData(uint8_t data)
 {
+	static uint16_t rxLength = 0;
+	static uint8_t ck_A = 0;
+	static uint8_t ck_B = 0;
+	static uint8_t ck_A_Ref = 0;
+	static uint8_t ck_B_Ref = 0;
+
 	GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
+	if((rxState >= GNSSRX_DETECT_HEADER_2) && (rxState < GNSSRX_READ_CK_A))
+	{
+		ck_A += data;
+		ck_B += ck_A;
+	}
+
 	switch(rxState)
 	{
 		case GNSSRX_DETECT_ACK_0:
 		case GNSSRX_DETECT_HEADER_0:	if(data == 0xB5)
 										{
 											writeIndex = 0;
-											memset(GNSS_Handle.uartWorkingBuffer,0, sizeof(GNSS_Handle.uartWorkingBuffer));
+											memset(GNSS_Handle.uartWorkingBuffer,0xff, sizeof(GNSS_Handle.uartWorkingBuffer));
 											GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
 											rxState++;
+											ck_A = 0;
+											ck_B = 0;
 										}
 			break;
 		case GNSSRX_DETECT_ACK_1:
@@ -437,7 +474,7 @@
 											rxState = GNSSRX_DETECT_HEADER_0;
 										}
 			break;
-		case GNSSRX_DETECT_HEADER_2:	if(data == 0x01)
+		case GNSSRX_DETECT_HEADER_2:	if(data == activeRequest.class)
 			 	 	 	 	 	 	 	{
 											rxState++;
 			 	 	 	 	 	 	 	}
@@ -446,44 +483,51 @@
 											rxState = GNSSRX_DETECT_HEADER_0;
 										}
 			break;
-		case GNSSRX_DETECT_HEADER_3:
-										switch(data)
+		case GNSSRX_DETECT_HEADER_3:	if(data == activeRequest.id)
+ 	 	 								{
+											rxState = GNSSRX_DETECT_LENGTH_0;
+ 	 	 								}
+										else
 										{
-											case 0x21: rxState = GNSSRX_READ_NAV_DATA;
-														dataToRead = 20;
-												break;
-											case 0x07:	rxState = GNSSRX_READ_PVT_DATA;
-														dataToRead = 92;
-												break;
-											case 0x02:  rxState = GNSSRX_READ_POSLLH_DATA;
-												break;
-											default: 	rxState = GNSSRX_DETECT_HEADER_0;
-												break;
+											rxState = GNSSRX_DETECT_HEADER_0;
 										}
-			break;
-			case GNSSRX_READ_NAV_DATA:
-			case GNSSRX_READ_PVT_DATA:
-			case GNSSRX_READ_POSLLH_DATA:		if(dataToRead > 0)
+				break;
+			case GNSSRX_DETECT_LENGTH_0:	rxLength = GNSS_Handle.uartWorkingBuffer[4];
+											rxState = GNSSRX_DETECT_LENGTH_1;
+				break;
+			case GNSSRX_DETECT_LENGTH_1:    rxLength += (GNSS_Handle.uartWorkingBuffer[5] << 8);
+											rxState = GNSSRX_READ_DATA;
+											dataToRead = rxLength;
+				break;
+			case GNSSRX_READ_DATA:				if(dataToRead > 0)
 												{
 													dataToRead--;
 												}
-												else
+												if(dataToRead == 0)
 												{
-														switch(rxState)
-														{
-															case GNSSRX_READ_NAV_DATA: GNSS_ParseNavigatorData(&GNSS_Handle);
-																break;
-															case GNSSRX_READ_PVT_DATA:	GNSS_ParsePVTData(&GNSS_Handle);
-																break;
-															case GNSSRX_READ_POSLLH_DATA:  GNSS_ParsePOSLLHData(&GNSS_Handle);
-																break;
-															default: 	rxState = GNSSRX_DETECT_HEADER_0;
-																break;
-														}
-														rxState = GNSSRX_DETECT_HEADER_0;
-														gnssState = UART_GNSS_IDLE;
+													rxState = GNSSRX_READ_CK_A;
 												}
 				break;
+			case GNSSRX_READ_CK_A:				ck_A_Ref = data;
+												rxState++;
+				break;
+			case GNSSRX_READ_CK_B:				ck_B_Ref = data;
+												if((ck_A_Ref == ck_A) && (ck_B_Ref == ck_B))
+												{
+													switch(gnssState)
+													{
+														case UART_GNSS_GET_PVT:GNSS_ParsePVTData(&GNSS_Handle);
+															break;
+														case UART_GNSS_GET_SAT: GNSS_ParseNavSatData(&GNSS_Handle);
+															break;
+														default:
+															break;
+													}
+												}
+												rxState = GNSSRX_DETECT_HEADER_0;
+												gnssState = UART_GNSS_IDLE;
+				break;
+
 		default:	rxState = GNSSRX_READY;
 			break;
 	}
@@ -529,7 +573,7 @@
 			retryRequest = 0;
 			timeToTrigger = 1;
 
-			if((gnssState == UART_GNSS_GET_PVT))	/* timeout */
+			if((gnssState == UART_GNSS_GET_SAT) || (gnssState == UART_GNSS_GET_PVT))	/* timeout */
 			{
 				gnssState = UART_GNSS_IDLE;
 			}