comparison Small_CPU/Src/GNSS.c @ 932:effadaa3a1f7 Evo_2_23

Cleanup Gnss UART implementation: The first draft of the internal UART implementation was just a copy of the external UART handling. To avoid duplicated code and maintainance issue both UARTs (external/internal 6/1) share the same functions. To enable this a control structure has to be used as function input which defines the none shared resources like DMA control and rx/tx buffers
author Ideenmodellierer
date Sat, 07 Dec 2024 21:28:08 +0100
parents 5a9bc2e6112d
children 4a406e873a95
comparison
equal deleted inserted replaced
931:5a9bc2e6112d 932:effadaa3a1f7
57 GNSS->gSpeed = 0; 57 GNSS->gSpeed = 0;
58 GNSS->headMot = 0; 58 GNSS->headMot = 0;
59 } 59 }
60 60
61 /*! 61 /*!
62 * Searching for a header in data buffer and matching class and message ID to buffer data.
63 * @param GNSS Pointer to main GNSS structure.
64 */
65 uint8_t GNSS_ParseBuffer(GNSS_StateHandle *GNSS) {
66
67 uint8_t DataReceived = 0;
68
69 for (int var = 0; var <= 100; ++var) {
70 if (GNSS->uartWorkingBuffer[var] == 0xB5
71 && GNSS->uartWorkingBuffer[var + 1] == 0x62) {
72 DataReceived = 1;
73 if (GNSS->uartWorkingBuffer[var + 2] == 0x27
74 && GNSS->uartWorkingBuffer[var + 3] == 0x03) { //Look at: 32.19.1.1 u-blox 8 Receiver description
75 GNSS_ParseUniqID(GNSS);
76 } else if (GNSS->uartWorkingBuffer[var + 2] == 0x01
77 && GNSS->uartWorkingBuffer[var + 3] == 0x21) { //Look at: 32.17.14.1 u-blox 8 Receiver description
78 GNSS_ParseNavigatorData(GNSS);
79 } else if (GNSS->uartWorkingBuffer[var + 2] == 0x01
80 && GNSS->uartWorkingBuffer[var + 3] == 0x07) { //ook at: 32.17.30.1 u-blox 8 Receiver description
81 GNSS_ParsePVTData(GNSS);
82 } else if (GNSS->uartWorkingBuffer[var + 2] == 0x01
83 && GNSS->uartWorkingBuffer[var + 3] == 0x02) { // Look at: 32.17.15.1 u-blox 8 Receiver description
84 GNSS_ParsePOSLLHData(GNSS);
85 }
86 }
87 }
88 return DataReceived;
89 }
90
91 /*!
92 * Make request for unique chip ID data.
93 * @param GNSS Pointer to main GNSS structure.
94 */
95 void GNSS_GetUniqID(GNSS_StateHandle *GNSS) {
96 HAL_UART_Transmit_DMA(GNSS->huart, getDeviceID,
97 sizeof(getDeviceID) / sizeof(uint8_t));
98 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 17);
99 }
100
101 /*!
102 * Make request for UTC time solution data.
103 * @param GNSS Pointer to main GNSS structure.
104 */
105 void GNSS_GetNavigatorData(GNSS_StateHandle *GNSS) {
106 HAL_UART_Transmit_DMA(GNSS->huart, getNavigatorData,
107 sizeof(getNavigatorData) / sizeof(uint8_t));
108 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 28);
109 }
110
111 /*!
112 * Make request for geodetic position solution data.
113 * @param GNSS Pointer to main GNSS structure.
114 */
115 void GNSS_GetPOSLLHData(GNSS_StateHandle *GNSS) {
116 HAL_UART_Transmit_DMA(GNSS->huart, getPOSLLHData,
117 sizeof(getPOSLLHData) / sizeof(uint8_t));
118 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 36);
119 }
120
121 /*!
122 * Make request for navigation position velocity time solution data.
123 * @param GNSS Pointer to main GNSS structure.
124 */
125 void GNSS_GetPVTData(GNSS_StateHandle *GNSS) {
126 HAL_UART_Transmit_DMA(GNSS->huart, getPVTData,
127 sizeof(getPVTData) / sizeof(uint8_t));
128 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 100);
129 }
130
131 /*!
132 * Parse data to unique chip ID standard. 62 * Parse data to unique chip ID standard.
133 * Look at: 32.19.1.1 u-blox 8 Receiver description 63 * Look at: 32.19.1.1 u-blox 8 Receiver description
134 * @param GNSS Pointer to main GNSS structure. 64 * @param GNSS Pointer to main GNSS structure.
135 */ 65 */
136 void GNSS_ParseUniqID(GNSS_StateHandle *GNSS) { 66 void GNSS_ParseUniqID(GNSS_StateHandle *GNSS) {
137 for (int var = 0; var < 5; ++var) { 67 for (int var = 0; var < 5; ++var) {
138 GNSS->uniqueID[var] = GNSS_Handle.uartWorkingBuffer[10 + var]; 68 GNSS->uniqueID[var] = GNSS_Handle.uartWorkingBuffer[10 + var];
139 } 69 }
140 } 70 }
141 71
142 /*!
143 * Changing the GNSS mode.
144 * Look at: 32.10.19 u-blox 8 Receiver description
145 */
146 void GNSS_SetMode(GNSS_StateHandle *GNSS, short gnssMode) {
147 if (gnssMode == 0) {
148 HAL_UART_Transmit_DMA(GNSS->huart, setPortableMode,sizeof(setPortableMode) / sizeof(uint8_t));
149 } else if (gnssMode == 1) {
150 HAL_UART_Transmit_DMA(GNSS->huart, setStationaryMode,sizeof(setStationaryMode) / sizeof(uint8_t));
151 } else if (gnssMode == 2) {
152 HAL_UART_Transmit_DMA(GNSS->huart, setPedestrianMode,sizeof(setPedestrianMode) / sizeof(uint8_t));
153 } else if (gnssMode == 3) {
154 HAL_UART_Transmit_DMA(GNSS->huart, setAutomotiveMode,sizeof(setAutomotiveMode) / sizeof(uint8_t));
155 } else if (gnssMode == 4) {
156 HAL_UART_Transmit_DMA(GNSS->huart, setAutomotiveMode,sizeof(setAutomotiveMode) / sizeof(uint8_t));
157 } else if (gnssMode == 5) {
158 HAL_UART_Transmit_DMA(GNSS->huart, setAirbone1GMode,sizeof(setAirbone1GMode) / sizeof(uint8_t));
159 } else if (gnssMode == 6) {
160 HAL_UART_Transmit_DMA(GNSS->huart, setAirbone2GMode,sizeof(setAirbone2GMode) / sizeof(uint8_t));
161 } else if (gnssMode == 7) {
162 HAL_UART_Transmit_DMA(GNSS->huart, setAirbone4GMode,sizeof(setAirbone4GMode) / sizeof(uint8_t));
163 } else if (gnssMode == 8) {
164 HAL_UART_Transmit_DMA(GNSS->huart, setWirstMode,sizeof(setWirstMode) / sizeof(uint8_t));
165 } else if (gnssMode == 9) {
166 HAL_UART_Transmit_DMA(GNSS->huart, setBikeMode,sizeof(setBikeMode) / sizeof(uint8_t));
167 }
168 }
169 /*! 72 /*!
170 * Parse data to navigation position velocity time solution standard. 73 * Parse data to navigation position velocity time solution standard.
171 * Look at: 32.17.15.1 u-blox 8 Receiver description. 74 * Look at: 32.17.15.1 u-blox 8 Receiver description.
172 * @param GNSS Pointer to main GNSS structure. 75 * @param GNSS Pointer to main GNSS structure.
173 */ 76 */
339 for (int var = 0; var < 4; ++var) { 242 for (int var = 0; var < 4; ++var) {
340 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30]; 243 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30];
341 } 244 }
342 GNSS->vAcc = uLong.uLong; 245 GNSS->vAcc = uLong.uLong;
343 } 246 }
344
345 /*!
346 * Sends the basic configuration: Activation of the UBX standard, change of NMEA version to 4.10 and turn on of the Galileo system.
347 * @param GNSS Pointer to main GNSS structure.
348 */
349 void GNSS_LoadConfig(GNSS_StateHandle *GNSS) {
350 HAL_UART_Transmit_DMA(GNSS->huart, configUBX,
351 sizeof(configUBX) / sizeof(uint8_t));
352 HAL_Delay(250);
353 HAL_UART_Transmit_DMA(GNSS->huart, setNMEA410,
354 sizeof(setNMEA410) / sizeof(uint8_t));
355 HAL_Delay(250);
356 HAL_UART_Transmit_DMA(GNSS->huart, setGNSS,
357 sizeof(setGNSS) / sizeof(uint8_t));
358 HAL_Delay(250);
359 }
360
361
362
363 /*!
364 * Creates a checksum based on UBX standard.
365 * @param class Class value from UBX doc.
366 * @param messageID MessageID value from UBX doc.
367 * @param dataLength Data length value from UBX doc.
368 * @param payload Just payload.
369 * @return Returns checksum.
370 */
371 uint8_t GNSS_Checksum(uint8_t class, uint8_t messageID, uint8_t dataLength,uint8_t *payload) {
372 //todo: Look at 32.4 UBX Checksum
373 return 0;
374 }