Mercurial > public > ostc4
comparison Small_CPU/Src/GNSS.c @ 887:17f02ac9da67 Evo_2_23
adding GNSS code
author | heinrichsweikamp |
---|---|
date | Tue, 03 Sep 2024 15:30:53 +0200 |
parents | |
children | 2225c467f1e9 |
comparison
equal
deleted
inserted
replaced
886:d398ecc7d103 | 887:17f02ac9da67 |
---|---|
1 /* | |
2 * GNSS.c | |
3 * | |
4 * Created on: 03.10.2020 | |
5 * Author: SimpleMethod | |
6 * | |
7 *Copyright 2020 SimpleMethod | |
8 * | |
9 *Permission is hereby granted, free of charge, to any person obtaining a copy of | |
10 *this software and associated documentation files (the "Software"), to deal in | |
11 *the Software without restriction, including without limitation the rights to | |
12 *use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
13 *of the Software, and to permit persons to whom the Software is furnished to do | |
14 *so, subject to the following conditions: | |
15 * | |
16 *The above copyright notice and this permission notice shall be included in all | |
17 *copies or substantial portions of the Software. | |
18 * | |
19 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
22 *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
25 *THE SOFTWARE. | |
26 ****************************************************************************** | |
27 */ | |
28 | |
29 #include "GNSS.h" | |
30 | |
31 union u_Short uShort; | |
32 union i_Short iShort; | |
33 union u_Long uLong; | |
34 union i_Long iLong; | |
35 | |
36 /*! | |
37 * Structure initialization. | |
38 * @param GNSS Pointer to main GNSS structure. | |
39 * @param huart Pointer to uart handle. | |
40 */ | |
41 void GNSS_Init(GNSS_StateHandle *GNSS, UART_HandleTypeDef *huart) { | |
42 GNSS->huart = huart; | |
43 GNSS->year = 0; | |
44 GNSS->month = 0; | |
45 GNSS->day = 0; | |
46 GNSS->hour = 0; | |
47 GNSS->min = 0; | |
48 GNSS->sec = 0; | |
49 GNSS->fixType = 0; | |
50 GNSS->lon = 0; | |
51 GNSS->lat = 0; | |
52 GNSS->height = 0; | |
53 GNSS->hMSL = 0; | |
54 GNSS->hAcc = 0; | |
55 GNSS->vAcc = 0; | |
56 GNSS->gSpeed = 0; | |
57 GNSS->headMot = 0; | |
58 } | |
59 | |
60 /*! | |
61 * Searching for a header in data buffer and matching class and message ID to buffer data. | |
62 * @param GNSS Pointer to main GNSS structure. | |
63 */ | |
64 void GNSS_ParseBuffer(GNSS_StateHandle *GNSS) { | |
65 | |
66 for (int var = 0; var <= 100; ++var) { | |
67 if (GNSS->uartWorkingBuffer[var] == 0xB5 | |
68 && GNSS->uartWorkingBuffer[var + 1] == 0x62) { | |
69 if (GNSS->uartWorkingBuffer[var + 2] == 0x27 | |
70 && GNSS->uartWorkingBuffer[var + 3] == 0x03) { //Look at: 32.19.1.1 u-blox 8 Receiver description | |
71 GNSS_ParseUniqID(GNSS); | |
72 } else if (GNSS->uartWorkingBuffer[var + 2] == 0x01 | |
73 && GNSS->uartWorkingBuffer[var + 3] == 0x21) { //Look at: 32.17.14.1 u-blox 8 Receiver description | |
74 GNSS_ParseNavigatorData(GNSS); | |
75 } else if (GNSS->uartWorkingBuffer[var + 2] == 0x01 | |
76 && GNSS->uartWorkingBuffer[var + 3] == 0x07) { //ook at: 32.17.30.1 u-blox 8 Receiver description | |
77 GNSS_ParsePVTData(GNSS); | |
78 } else if (GNSS->uartWorkingBuffer[var + 2] == 0x01 | |
79 && GNSS->uartWorkingBuffer[var + 3] == 0x02) { // Look at: 32.17.15.1 u-blox 8 Receiver description | |
80 GNSS_ParsePOSLLHData(GNSS); | |
81 } | |
82 } | |
83 } | |
84 } | |
85 | |
86 /*! | |
87 * Make request for unique chip ID data. | |
88 * @param GNSS Pointer to main GNSS structure. | |
89 */ | |
90 void GNSS_GetUniqID(GNSS_StateHandle *GNSS) { | |
91 HAL_UART_Transmit_DMA(GNSS->huart, getDeviceID, | |
92 sizeof(getDeviceID) / sizeof(uint8_t)); | |
93 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 17); | |
94 } | |
95 | |
96 /*! | |
97 * Make request for UTC time solution data. | |
98 * @param GNSS Pointer to main GNSS structure. | |
99 */ | |
100 void GNSS_GetNavigatorData(GNSS_StateHandle *GNSS) { | |
101 HAL_UART_Transmit_DMA(GNSS->huart, getNavigatorData, | |
102 sizeof(getNavigatorData) / sizeof(uint8_t)); | |
103 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 28); | |
104 } | |
105 | |
106 /*! | |
107 * Make request for geodetic position solution data. | |
108 * @param GNSS Pointer to main GNSS structure. | |
109 */ | |
110 void GNSS_GetPOSLLHData(GNSS_StateHandle *GNSS) { | |
111 HAL_UART_Transmit_DMA(GNSS->huart, getPOSLLHData, | |
112 sizeof(getPOSLLHData) / sizeof(uint8_t)); | |
113 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 36); | |
114 } | |
115 | |
116 /*! | |
117 * Make request for navigation position velocity time solution data. | |
118 * @param GNSS Pointer to main GNSS structure. | |
119 */ | |
120 void GNSS_GetPVTData(GNSS_StateHandle *GNSS) { | |
121 HAL_UART_Transmit_DMA(GNSS->huart, getPVTData, | |
122 sizeof(getPVTData) / sizeof(uint8_t)); | |
123 HAL_UART_Receive_IT(GNSS->huart, GNSS_Handle.uartWorkingBuffer, 100); | |
124 } | |
125 | |
126 /*! | |
127 * Parse data to unique chip ID standard. | |
128 * Look at: 32.19.1.1 u-blox 8 Receiver description | |
129 * @param GNSS Pointer to main GNSS structure. | |
130 */ | |
131 void GNSS_ParseUniqID(GNSS_StateHandle *GNSS) { | |
132 for (int var = 0; var < 5; ++var) { | |
133 GNSS->uniqueID[var] = GNSS_Handle.uartWorkingBuffer[10 + var]; | |
134 } | |
135 } | |
136 | |
137 /*! | |
138 * Changing the GNSS mode. | |
139 * Look at: 32.10.19 u-blox 8 Receiver description | |
140 */ | |
141 void GNSS_SetMode(GNSS_StateHandle *GNSS, short gnssMode) { | |
142 if (gnssMode == 0) { | |
143 HAL_UART_Transmit_DMA(GNSS->huart, setPortableMode,sizeof(setPortableMode) / sizeof(uint8_t)); | |
144 } else if (gnssMode == 1) { | |
145 HAL_UART_Transmit_DMA(GNSS->huart, setStationaryMode,sizeof(setStationaryMode) / sizeof(uint8_t)); | |
146 } else if (gnssMode == 2) { | |
147 HAL_UART_Transmit_DMA(GNSS->huart, setPedestrianMode,sizeof(setPedestrianMode) / sizeof(uint8_t)); | |
148 } else if (gnssMode == 3) { | |
149 HAL_UART_Transmit_DMA(GNSS->huart, setAutomotiveMode,sizeof(setAutomotiveMode) / sizeof(uint8_t)); | |
150 } else if (gnssMode == 4) { | |
151 HAL_UART_Transmit_DMA(GNSS->huart, setAutomotiveMode,sizeof(setAutomotiveMode) / sizeof(uint8_t)); | |
152 } else if (gnssMode == 5) { | |
153 HAL_UART_Transmit_DMA(GNSS->huart, setAirbone1GMode,sizeof(setAirbone1GMode) / sizeof(uint8_t)); | |
154 } else if (gnssMode == 6) { | |
155 HAL_UART_Transmit_DMA(GNSS->huart, setAirbone2GMode,sizeof(setAirbone2GMode) / sizeof(uint8_t)); | |
156 } else if (gnssMode == 7) { | |
157 HAL_UART_Transmit_DMA(GNSS->huart, setAirbone4GMode,sizeof(setAirbone4GMode) / sizeof(uint8_t)); | |
158 } else if (gnssMode == 8) { | |
159 HAL_UART_Transmit_DMA(GNSS->huart, setWirstMode,sizeof(setWirstMode) / sizeof(uint8_t)); | |
160 } else if (gnssMode == 9) { | |
161 HAL_UART_Transmit_DMA(GNSS->huart, setBikeMode,sizeof(setBikeMode) / sizeof(uint8_t)); | |
162 } | |
163 } | |
164 /*! | |
165 * Parse data to navigation position velocity time solution standard. | |
166 * Look at: 32.17.15.1 u-blox 8 Receiver description. | |
167 * @param GNSS Pointer to main GNSS structure. | |
168 */ | |
169 void GNSS_ParsePVTData(GNSS_StateHandle *GNSS) { | |
170 uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[10]; | |
171 GNSS->yearBytes[0]=GNSS_Handle.uartWorkingBuffer[10]; | |
172 uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[11]; | |
173 GNSS->yearBytes[1]=GNSS_Handle.uartWorkingBuffer[11]; | |
174 GNSS->year = uShort.uShort; | |
175 GNSS->month = GNSS_Handle.uartWorkingBuffer[12]; | |
176 GNSS->day = GNSS_Handle.uartWorkingBuffer[13]; | |
177 GNSS->hour = GNSS_Handle.uartWorkingBuffer[14]; | |
178 GNSS->min = GNSS_Handle.uartWorkingBuffer[15]; | |
179 GNSS->sec = GNSS_Handle.uartWorkingBuffer[16]; | |
180 GNSS->fixType = GNSS_Handle.uartWorkingBuffer[26]; | |
181 | |
182 for (int var = 0; var < 4; ++var) { | |
183 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30]; | |
184 GNSS->lonBytes[var]= GNSS_Handle.uartWorkingBuffer[var + 30]; | |
185 } | |
186 GNSS->lon = iLong.iLong; | |
187 GNSS->fLon=(float)iLong.iLong/10000000.0; | |
188 for (int var = 0; var < 4; ++var) { | |
189 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 34]; | |
190 GNSS->latBytes[var]=GNSS_Handle.uartWorkingBuffer[var + 34]; | |
191 } | |
192 GNSS->lat = iLong.iLong; | |
193 GNSS->fLat=(float)iLong.iLong/10000000.0; | |
194 for (int var = 0; var < 4; ++var) { | |
195 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 38]; | |
196 } | |
197 GNSS->height = iLong.iLong; | |
198 | |
199 for (int var = 0; var < 4; ++var) { | |
200 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 42]; | |
201 GNSS->hMSLBytes[var] = GNSS_Handle.uartWorkingBuffer[var + 42]; | |
202 } | |
203 GNSS->hMSL = iLong.iLong; | |
204 | |
205 for (int var = 0; var < 4; ++var) { | |
206 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 46]; | |
207 } | |
208 GNSS->hAcc = uLong.uLong; | |
209 | |
210 for (int var = 0; var < 4; ++var) { | |
211 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 50]; | |
212 } | |
213 GNSS->vAcc = uLong.uLong; | |
214 | |
215 for (int var = 0; var < 4; ++var) { | |
216 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 66]; | |
217 GNSS->gSpeedBytes[var] = GNSS_Handle.uartWorkingBuffer[var + 66]; | |
218 } | |
219 GNSS->gSpeed = iLong.iLong; | |
220 | |
221 for (int var = 0; var < 4; ++var) { | |
222 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 70]; | |
223 } | |
224 GNSS->headMot = iLong.iLong * 1e-5; // todo I'm not sure this good options. | |
225 } | |
226 | |
227 /*! | |
228 * Parse data to UTC time solution standard. | |
229 * Look at: 32.17.30.1 u-blox 8 Receiver description. | |
230 * @param GNSS Pointer to main GNSS structure. | |
231 */ | |
232 void GNSS_ParseNavigatorData(GNSS_StateHandle *GNSS) { | |
233 uShort.bytes[0] = GNSS_Handle.uartWorkingBuffer[18]; | |
234 uShort.bytes[1] = GNSS_Handle.uartWorkingBuffer[19]; | |
235 GNSS->year = uShort.uShort; | |
236 GNSS->month = GNSS_Handle.uartWorkingBuffer[20]; | |
237 GNSS->day = GNSS_Handle.uartWorkingBuffer[21]; | |
238 GNSS->hour = GNSS_Handle.uartWorkingBuffer[22]; | |
239 GNSS->min = GNSS_Handle.uartWorkingBuffer[23]; | |
240 GNSS->sec = GNSS_Handle.uartWorkingBuffer[24]; | |
241 } | |
242 | |
243 /*! | |
244 * Parse data to geodetic position solution standard. | |
245 * Look at: 32.17.14.1 u-blox 8 Receiver description. | |
246 * @param GNSS Pointer to main GNSS structure. | |
247 */ | |
248 void GNSS_ParsePOSLLHData(GNSS_StateHandle *GNSS) { | |
249 for (int var = 0; var < 4; ++var) { | |
250 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 10]; | |
251 } | |
252 GNSS->lon = iLong.iLong; | |
253 GNSS->fLon=(float)iLong.iLong/10000000.0; | |
254 | |
255 for (int var = 0; var < 4; ++var) { | |
256 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 14]; | |
257 } | |
258 GNSS->lat = iLong.iLong; | |
259 GNSS->fLat=(float)iLong.iLong/10000000.0; | |
260 | |
261 for (int var = 0; var < 4; ++var) { | |
262 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 18]; | |
263 } | |
264 GNSS->height = iLong.iLong; | |
265 | |
266 for (int var = 0; var < 4; ++var) { | |
267 iLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 22]; | |
268 } | |
269 GNSS->hMSL = iLong.iLong; | |
270 | |
271 for (int var = 0; var < 4; ++var) { | |
272 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 26]; | |
273 } | |
274 GNSS->hAcc = uLong.uLong; | |
275 | |
276 for (int var = 0; var < 4; ++var) { | |
277 uLong.bytes[var] = GNSS_Handle.uartWorkingBuffer[var + 30]; | |
278 } | |
279 GNSS->vAcc = uLong.uLong; | |
280 } | |
281 | |
282 /*! | |
283 * Sends the basic configuration: Activation of the UBX standard, change of NMEA version to 4.10 and turn on of the Galileo system. | |
284 * @param GNSS Pointer to main GNSS structure. | |
285 */ | |
286 void GNSS_LoadConfig(GNSS_StateHandle *GNSS) { | |
287 HAL_UART_Transmit_DMA(GNSS->huart, configUBX, | |
288 sizeof(configUBX) / sizeof(uint8_t)); | |
289 HAL_Delay(250); | |
290 HAL_UART_Transmit_DMA(GNSS->huart, setNMEA410, | |
291 sizeof(setNMEA410) / sizeof(uint8_t)); | |
292 HAL_Delay(250); | |
293 HAL_UART_Transmit_DMA(GNSS->huart, setGNSS, | |
294 sizeof(setGNSS) / sizeof(uint8_t)); | |
295 HAL_Delay(250); | |
296 } | |
297 | |
298 | |
299 | |
300 /*! | |
301 * Creates a checksum based on UBX standard. | |
302 * @param class Class value from UBX doc. | |
303 * @param messageID MessageID value from UBX doc. | |
304 * @param dataLength Data length value from UBX doc. | |
305 * @param payload Just payload. | |
306 * @return Returns checksum. | |
307 */ | |
308 uint8_t GNSS_Checksum(uint8_t class, uint8_t messageID, uint8_t dataLength,uint8_t *payload) { | |
309 //todo: Look at 32.4 UBX Checksum | |
310 return 0; | |
311 } |