diff Small_CPU/Src/uart.c @ 933:43055e069bd1 Evo_2_23

UART Gnss: Added fletcher calculation: Communication is verified using the Fletcher check. In the example code the commands were har coded including the check bytes. To make definition of new commands easier the check bytes are now calculated at runtime. This may be referted to hardcoded values once the implementation is getting a mature state.
author Ideenmodellierer
date Sun, 08 Dec 2024 17:38:16 +0100
parents effadaa3a1f7
children 3029f0332f4f
line wrap: on
line diff
--- a/Small_CPU/Src/uart.c	Sat Dec 07 21:28:08 2024 +0100
+++ b/Small_CPU/Src/uart.c	Sun Dec 08 17:38:16 2024 +0100
@@ -224,6 +224,23 @@
 	}
 }
 
+void UART_AddFletcher(uint8_t* pBuffer, uint8_t length)
+{
+	uint8_t ck_A = 0;
+	uint8_t ck_B = 0;
+	uint8_t index = 0;
+
+
+	pBuffer += 2; /* skip sync chars */
+	for(index = 2; index < length; index++)
+	{
+		ck_A += *pBuffer++;
+		ck_B += ck_A;
+	}
+	*pBuffer++ = ck_A;
+	*pBuffer++ = ck_B;
+}
+
 void UART_SendCmdUbx(const uint8_t *cmd, uint8_t len)
 {
 	if(len < TX_BUF_SIZE)		/* A longer string is an indication for a missing 0 termination */
@@ -235,6 +252,8 @@
 				UART_StartDMA_Receiption(pGnssCtrl);
 			}
 			memcpy(pGnssCtrl->pTxBuffer, cmd, len);
+			UART_AddFletcher(pGnssCtrl->pTxBuffer, len);
+			len += 2;
 			if(HAL_OK == HAL_UART_Transmit_DMA(pGnssCtrl->pHandle,pGnssCtrl->pTxBuffer,len))
 			{
 				pGnssCtrl->dmaTxActive = 1;