Mercurial > public > ostc4
annotate Small_CPU/Src/uartProtocol_GNSS.c @ 937:d461d9e89e3c Evo_2_23
Compile switch for RTE sleep debug:
there was already a compiler switch for enabling debugging while RTE is in sleep but the switches were distributed across the code => to make selection easier they are now part of the configuration.h
author | Ideenmodellierer |
---|---|
date | Tue, 10 Dec 2024 20:59:37 +0100 |
parents | 3029f0332f4f |
children | f41974734268 |
rev | line source |
---|---|
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
1 /** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
2 ****************************************************************************** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
3 * @file uartProtocol_GNSS.c |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
4 * @author heinrichs weikamp gmbh |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
5 * @version V0.0.1 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
6 * @date 30-Sep-2024 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
7 * @brief Interface functionality operation of GNSS devices |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
8 * |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
9 @verbatim |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
10 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
11 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
12 @endverbatim |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
13 ****************************************************************************** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
14 * @attention |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
15 * |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
16 * <h2><center>© COPYRIGHT(c) 2024 heinrichs weikamp</center></h2> |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
17 * |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
18 ****************************************************************************** |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
19 */ |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
20 /* Includes ------------------------------------------------------------------*/ |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
21 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
22 #include <string.h> |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
23 #include "scheduler.h" |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
24 #include <uartProtocol_GNSS.h> |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
25 #include "uart.h" |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
26 #include "GNSS.h" |
919 | 27 #include "configuration.h" |
28 #include "externalInterface.h" | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
29 |
932 | 30 |
31 #if defined ENABLE_GNSS || defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2 | |
32 | |
33 static uartGnssStatus_t gnssState = UART_GNSS_INIT; | |
34 static gnssRequest_s activeRequest = {0,0}; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
35 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
36 static receiveStateGnss_t rxState = GNSSRX_READY; |
919 | 37 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */ |
38 static uint8_t writeIndex = 0; | |
39 static uint8_t dataToRead = 0; | |
936 | 40 static uint8_t ReqPowerDown = 0; |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
41 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
42 void ConvertByteToHexString(uint8_t byte, char* str) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
43 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
44 uint8_t worker = 0; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
45 uint8_t digit = 0; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
46 uint8_t digitCnt = 1; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
47 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
48 worker = byte; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
49 while((worker!=0) && (digitCnt != 255)) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
50 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
51 digit = worker % 16; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
52 if( digit < 10) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
53 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
54 digit += '0'; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
55 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
56 else |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
57 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
58 digit += 'A' - 10; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
59 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
60 str[digitCnt--]= digit; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
61 worker = worker / 16; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
62 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
63 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
64 |
936 | 65 void uartGnss_ReqPowerDown(uint8_t request) |
66 { | |
67 if(GnssConnected) | |
68 { | |
69 ReqPowerDown = 1; | |
70 } | |
71 } | |
919 | 72 |
932 | 73 uartGnssStatus_t uartGnss_GetState() |
74 { | |
75 return gnssState; | |
76 } | |
77 void uartGnss_SetState(uartGnssStatus_t newState) | |
78 { | |
79 gnssState = newState; | |
80 } | |
81 | |
82 void UART_Gnss_SendCmd(uint8_t GnssCmd) | |
919 | 83 { |
922 | 84 const uint8_t* pData; |
919 | 85 uint8_t txLength = 0; |
86 | |
87 switch (GnssCmd) | |
88 { | |
89 case GNSSCMD_LOADCONF_0: pData = configUBX; | |
90 txLength = sizeof(configUBX) / sizeof(uint8_t); | |
91 break; | |
92 case GNSSCMD_LOADCONF_1: pData = setNMEA410; | |
93 txLength = sizeof(setNMEA410) / sizeof(uint8_t); | |
94 break; | |
95 case GNSSCMD_LOADCONF_2: pData = setGNSS; | |
96 txLength = sizeof(setGNSS) / sizeof(uint8_t); | |
97 break; | |
98 case GNSSCMD_GET_PVT_DATA: pData = getPVTData; | |
99 txLength = sizeof(getPVTData) / sizeof(uint8_t); | |
100 break; | |
101 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData; | |
102 txLength = sizeof(getNavigatorData) / sizeof(uint8_t); | |
103 break; | |
932 | 104 case GNSSCMD_GET_NAVSAT_DATA: pData = getNavSat; |
105 txLength = sizeof(getNavSat) / sizeof(uint8_t); | |
106 break; | |
936 | 107 case GNSSCMD_MODE_PWS: pData = setPowerLow; |
108 txLength = sizeof(setPowerLow) / sizeof(uint8_t); | |
109 break; | |
110 case GNSSCMD_MODE_NORMAL: pData = setPowerNormal; | |
111 txLength = sizeof(setPowerNormal) / sizeof(uint8_t); | |
112 break; | |
113 case GNSSCMD_SET_CONFIG: pData = setConfig; | |
114 txLength = sizeof(setConfig) / sizeof(uint8_t); | |
115 break; | |
919 | 116 default: |
117 break; | |
118 } | |
119 if(txLength != 0) | |
120 { | |
932 | 121 activeRequest.class = pData[2]; |
122 activeRequest.id = pData[3]; | |
919 | 123 UART_SendCmdUbx(pData, txLength); |
124 } | |
125 } | |
126 | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
127 void uartGnss_Control(void) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
128 { |
919 | 129 static uint32_t warmupTick = 0; |
932 | 130 static uint8_t dataToggle = 0; |
131 uint8_t activeSensor = 0; | |
132 sUartComCtrl* pUartCtrl = UART_GetGnssCtrl(); | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
133 |
932 | 134 if(pUartCtrl == &Uart1Ctrl) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
135 { |
932 | 136 activeSensor = externalInterface_GetActiveUartSensor(); |
137 gnssState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); | |
138 } | |
139 | |
140 switch (gnssState) | |
141 { | |
142 case UART_GNSS_INIT: gnssState = UART_GNSS_WARMUP; | |
919 | 143 warmupTick = HAL_GetTick(); |
932 | 144 UART_clearRxBuffer(pUartCtrl); |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
145 break; |
919 | 146 case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000) |
147 { | |
932 | 148 gnssState = UART_GNSS_LOADCONF_0; |
919 | 149 } |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
150 break; |
932 | 151 case UART_GNSS_LOADCONF_0: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_0); |
152 rxState = GNSSRX_DETECT_ACK_0; | |
153 break; | |
154 case UART_GNSS_LOADCONF_1: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_1); | |
155 rxState = GNSSRX_DETECT_ACK_0; | |
156 break; | |
157 case UART_GNSS_LOADCONF_2: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_2); | |
919 | 158 rxState = GNSSRX_DETECT_ACK_0; |
159 break; | |
936 | 160 case UART_GNSS_PWRDOWN: UART_Gnss_SendCmd(GNSSCMD_MODE_PWS); |
161 rxState = GNSSRX_DETECT_ACK_0; | |
162 break; | |
163 | |
164 case UART_GNSS_PWRUP: | |
165 case UART_GNSS_INACTIVE: UART_Gnss_SendCmd(GNSSCMD_MODE_NORMAL); | |
166 rxState = GNSSRX_DETECT_ACK_0; | |
167 gnssState = UART_GNSS_PWRUP; | |
168 break; | |
169 case UART_GNSS_SETCONF: UART_Gnss_SendCmd(GNSSCMD_SET_CONFIG); | |
170 rxState = GNSSRX_DETECT_ACK_0; | |
171 break; | |
172 | |
173 case UART_GNSS_IDLE: if(ReqPowerDown) | |
932 | 174 { |
936 | 175 UART_Gnss_SendCmd(GNSSCMD_MODE_PWS); |
176 gnssState = UART_GNSS_PWRDOWN; | |
177 rxState = GNSSRX_DETECT_ACK_0; | |
932 | 178 } |
179 else | |
180 { | |
936 | 181 if(dataToggle) |
182 { | |
183 UART_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA); | |
184 gnssState = UART_GNSS_GET_PVT; | |
185 rxState = GNSSRX_DETECT_HEADER_0; | |
186 dataToggle = 0; | |
187 } | |
188 else | |
189 { | |
190 UART_Gnss_SendCmd(GNSSCMD_GET_NAVSAT_DATA); | |
191 gnssState = UART_GNSS_GET_SAT; | |
192 rxState = GNSSRX_DETECT_HEADER_0; | |
193 dataToggle = 1; | |
194 } | |
932 | 195 } |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
196 break; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
197 default: |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
198 break; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
199 } |
932 | 200 if(pUartCtrl == &Uart1Ctrl) |
201 { | |
202 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,gnssState); | |
203 } | |
919 | 204 |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
205 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
206 |
936 | 207 |
919 | 208 void uartGnss_ProcessData(uint8_t data) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
209 { |
932 | 210 static uint16_t rxLength = 0; |
211 static uint8_t ck_A = 0; | |
212 static uint8_t ck_B = 0; | |
213 static uint8_t ck_A_Ref = 0; | |
214 static uint8_t ck_B_Ref = 0; | |
936 | 215 uint8_t activeSensor = 0; |
216 | |
217 sUartComCtrl* pUartCtrl = UART_GetGnssCtrl(); | |
218 | |
219 if(pUartCtrl == &Uart1Ctrl) | |
220 { | |
221 activeSensor = externalInterface_GetActiveUartSensor(); | |
222 gnssState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); | |
223 } | |
932 | 224 |
919 | 225 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; |
932 | 226 if((rxState >= GNSSRX_DETECT_HEADER_2) && (rxState < GNSSRX_READ_CK_A)) |
227 { | |
228 ck_A += data; | |
229 ck_B += ck_A; | |
230 } | |
231 | |
919 | 232 switch(rxState) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
233 { |
919 | 234 case GNSSRX_DETECT_ACK_0: |
235 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5) | |
236 { | |
237 writeIndex = 0; | |
932 | 238 memset(GNSS_Handle.uartWorkingBuffer,0xff, sizeof(GNSS_Handle.uartWorkingBuffer)); |
919 | 239 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; |
240 rxState++; | |
932 | 241 ck_A = 0; |
242 ck_B = 0; | |
919 | 243 } |
244 break; | |
245 case GNSSRX_DETECT_ACK_1: | |
246 case GNSSRX_DETECT_HEADER_1: if(data == 0x62) | |
247 { | |
248 rxState++; | |
249 } | |
250 else | |
251 { | |
252 rxState = GNSSRX_DETECT_HEADER_0; | |
253 } | |
254 break; | |
255 case GNSSRX_DETECT_ACK_2: if(data == 0x05) | |
256 { | |
257 rxState++; | |
258 } | |
259 else | |
260 { | |
261 rxState = GNSSRX_DETECT_HEADER_0; | |
262 } | |
263 break; | |
932 | 264 case GNSSRX_DETECT_ACK_3: if((data == 0x01)) |
919 | 265 { |
936 | 266 rxState = GNSSRX_READY; |
267 if(gnssState == UART_GNSS_PWRUP) | |
268 { | |
269 gnssState = UART_GNSS_IDLE; | |
270 } | |
271 else if(gnssState == UART_GNSS_PWRDOWN) | |
272 { | |
273 rxState = GNSSRX_DETECT_ACK_0; | |
274 UART_Gnss_SendCmd(GNSSCMD_SET_CONFIG); | |
275 gnssState = UART_GNSS_SETCONF; | |
276 } | |
277 else if(gnssState == UART_GNSS_SETCONF) | |
278 { | |
279 gnssState = UART_GNSS_INACTIVE; | |
280 } | |
281 else if((gnssState >= UART_GNSS_LOADCONF_0) && (gnssState <= UART_GNSS_LOADCONF_2)) | |
932 | 282 { |
283 if(gnssState == UART_GNSS_LOADCONF_2) | |
284 { | |
285 gnssState = UART_GNSS_IDLE; | |
286 } | |
287 else | |
288 { | |
289 gnssState++; | |
290 } | |
291 } | |
919 | 292 GnssConnected = 1; |
293 } | |
294 else | |
295 { | |
296 rxState = GNSSRX_DETECT_HEADER_0; | |
297 } | |
298 break; | |
932 | 299 case GNSSRX_DETECT_HEADER_2: if(data == activeRequest.class) |
919 | 300 { |
301 rxState++; | |
302 } | |
303 else | |
304 { | |
305 rxState = GNSSRX_DETECT_HEADER_0; | |
306 } | |
307 break; | |
932 | 308 case GNSSRX_DETECT_HEADER_3: if(data == activeRequest.id) |
309 { | |
310 rxState = GNSSRX_DETECT_LENGTH_0; | |
311 } | |
312 else | |
919 | 313 { |
932 | 314 rxState = GNSSRX_DETECT_HEADER_0; |
919 | 315 } |
932 | 316 break; |
317 case GNSSRX_DETECT_LENGTH_0: rxLength = GNSS_Handle.uartWorkingBuffer[4]; | |
318 rxState = GNSSRX_DETECT_LENGTH_1; | |
319 break; | |
320 case GNSSRX_DETECT_LENGTH_1: rxLength += (GNSS_Handle.uartWorkingBuffer[5] << 8); | |
321 rxState = GNSSRX_READ_DATA; | |
322 dataToRead = rxLength; | |
323 break; | |
324 case GNSSRX_READ_DATA: if(dataToRead > 0) | |
919 | 325 { |
326 dataToRead--; | |
327 } | |
932 | 328 if(dataToRead == 0) |
919 | 329 { |
932 | 330 rxState = GNSSRX_READ_CK_A; |
919 | 331 } |
332 break; | |
932 | 333 case GNSSRX_READ_CK_A: ck_A_Ref = data; |
334 rxState++; | |
335 break; | |
336 case GNSSRX_READ_CK_B: ck_B_Ref = data; | |
337 if((ck_A_Ref == ck_A) && (ck_B_Ref == ck_B)) | |
338 { | |
339 switch(gnssState) | |
340 { | |
341 case UART_GNSS_GET_PVT:GNSS_ParsePVTData(&GNSS_Handle); | |
342 break; | |
343 case UART_GNSS_GET_SAT: GNSS_ParseNavSatData(&GNSS_Handle); | |
344 break; | |
345 default: | |
346 break; | |
347 } | |
348 } | |
349 rxState = GNSSRX_DETECT_HEADER_0; | |
350 gnssState = UART_GNSS_IDLE; | |
351 break; | |
352 | |
919 | 353 default: rxState = GNSSRX_READY; |
354 break; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
355 } |
936 | 356 if(pUartCtrl == &Uart1Ctrl) |
357 { | |
358 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,gnssState); | |
359 } | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
360 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
361 |
919 | 362 uint8_t uartGnss_isSensorConnected() |
363 { | |
364 return GnssConnected; | |
365 } | |
366 | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
367 #endif |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
368 |