comparison 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
comparison
equal deleted inserted replaced
932:effadaa3a1f7 933:43055e069bd1
222 memcpy(txBufferQue, cmdString, cmdLength); 222 memcpy(txBufferQue, cmdString, cmdLength);
223 Uart1Ctrl.txBufferQueLen = cmdLength; 223 Uart1Ctrl.txBufferQueLen = cmdLength;
224 } 224 }
225 } 225 }
226 226
227 void UART_AddFletcher(uint8_t* pBuffer, uint8_t length)
228 {
229 uint8_t ck_A = 0;
230 uint8_t ck_B = 0;
231 uint8_t index = 0;
232
233
234 pBuffer += 2; /* skip sync chars */
235 for(index = 2; index < length; index++)
236 {
237 ck_A += *pBuffer++;
238 ck_B += ck_A;
239 }
240 *pBuffer++ = ck_A;
241 *pBuffer++ = ck_B;
242 }
243
227 void UART_SendCmdUbx(const uint8_t *cmd, uint8_t len) 244 void UART_SendCmdUbx(const uint8_t *cmd, uint8_t len)
228 { 245 {
229 if(len < TX_BUF_SIZE) /* A longer string is an indication for a missing 0 termination */ 246 if(len < TX_BUF_SIZE) /* A longer string is an indication for a missing 0 termination */
230 { 247 {
231 if(pGnssCtrl != NULL) 248 if(pGnssCtrl != NULL)
233 if(pGnssCtrl->dmaRxActive == 0) 250 if(pGnssCtrl->dmaRxActive == 0)
234 { 251 {
235 UART_StartDMA_Receiption(pGnssCtrl); 252 UART_StartDMA_Receiption(pGnssCtrl);
236 } 253 }
237 memcpy(pGnssCtrl->pTxBuffer, cmd, len); 254 memcpy(pGnssCtrl->pTxBuffer, cmd, len);
255 UART_AddFletcher(pGnssCtrl->pTxBuffer, len);
256 len += 2;
238 if(HAL_OK == HAL_UART_Transmit_DMA(pGnssCtrl->pHandle,pGnssCtrl->pTxBuffer,len)) 257 if(HAL_OK == HAL_UART_Transmit_DMA(pGnssCtrl->pHandle,pGnssCtrl->pTxBuffer,len))
239 { 258 {
240 pGnssCtrl->dmaTxActive = 1; 259 pGnssCtrl->dmaTxActive = 1;
241 LastCmdRequestTick = HAL_GetTick(); 260 LastCmdRequestTick = HAL_GetTick();
242 } 261 }