Mercurial > public > ostc4
annotate Small_CPU/Src/uartProtocol_GNSS.c @ 927:908d9a8e8c84 Evo_2_23
Cleanup Internal Uart:
The internal UART was using the wrong UART RX channel. In addition the compile switches have been updated to allow GNSS data flow if new GPIO config is available or if GNSS is enabled for the external UART.
author | Ideenmodellierer |
---|---|
date | Tue, 26 Nov 2024 21:01:13 +0100 |
parents | 7c996354b8ac |
children |
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 |
919 | 30 #if defined ENABLE_GNSS || defined ENABLE_GNSS_SUPPORT |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
31 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
32 static receiveStateGnss_t rxState = GNSSRX_READY; |
919 | 33 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */ |
34 | |
35 static uint8_t writeIndex = 0; | |
36 | |
37 static uint8_t dataToRead = 0; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
38 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
39 void ConvertByteToHexString(uint8_t byte, char* str) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
40 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
41 uint8_t worker = 0; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
42 uint8_t digit = 0; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
43 uint8_t digitCnt = 1; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
44 |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
45 worker = byte; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
46 while((worker!=0) && (digitCnt != 255)) |
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 digit = worker % 16; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
49 if( digit < 10) |
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 += '0'; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
52 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
53 else |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
54 { |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
55 digit += 'A' - 10; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
56 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
57 str[digitCnt--]= digit; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
58 worker = worker / 16; |
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 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
61 |
919 | 62 |
63 void uartGnss_SendCmd(uint8_t GnssCmd) | |
64 { | |
922 | 65 const uint8_t* pData; |
919 | 66 uint8_t txLength = 0; |
67 | |
68 switch (GnssCmd) | |
69 { | |
70 case GNSSCMD_LOADCONF_0: pData = configUBX; | |
71 txLength = sizeof(configUBX) / sizeof(uint8_t); | |
72 break; | |
73 case GNSSCMD_LOADCONF_1: pData = setNMEA410; | |
74 txLength = sizeof(setNMEA410) / sizeof(uint8_t); | |
75 break; | |
76 case GNSSCMD_LOADCONF_2: pData = setGNSS; | |
77 txLength = sizeof(setGNSS) / sizeof(uint8_t); | |
78 break; | |
79 case GNSSCMD_GET_PVT_DATA: pData = getPVTData; | |
80 txLength = sizeof(getPVTData) / sizeof(uint8_t); | |
81 break; | |
82 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData; | |
83 txLength = sizeof(getNavigatorData) / sizeof(uint8_t); | |
84 break; | |
85 | |
86 default: | |
87 break; | |
88 } | |
89 if(txLength != 0) | |
90 { | |
91 UART_SendCmdUbx(pData, txLength); | |
92 } | |
93 } | |
94 | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
95 void uartGnss_Control(void) |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
96 { |
919 | 97 static uint32_t warmupTick = 0; |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
98 |
919 | 99 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); |
100 uartGnssStatus_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
101 |
919 | 102 switch (localComState) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
103 { |
919 | 104 case UART_GNSS_INIT: localComState = UART_GNSS_WARMUP; |
105 warmupTick = HAL_GetTick(); | |
106 UART_clearRxBuffer(); | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
107 break; |
919 | 108 case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000) |
109 { | |
110 localComState = UART_GNSS_LOADCONF_0; | |
111 } | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
112 break; |
919 | 113 case UART_GNSS_LOADCONF_0: uartGnss_SendCmd(GNSSCMD_LOADCONF_0); |
114 localComState = UART_GNSS_LOADCONF_1; | |
115 rxState = GNSSRX_DETECT_ACK_0; | |
116 break; | |
117 case UART_GNSS_LOADCONF_1: uartGnss_SendCmd(GNSSCMD_LOADCONF_1); | |
118 localComState = UART_GNSS_LOADCONF_2; | |
119 rxState = GNSSRX_DETECT_ACK_0; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
120 break; |
919 | 121 case UART_GNSS_LOADCONF_2: uartGnss_SendCmd(GNSSCMD_LOADCONF_2); |
122 localComState = UART_GNSS_IDLE; | |
123 rxState = GNSSRX_DETECT_ACK_0; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
124 break; |
919 | 125 case UART_GNSS_IDLE: uartGnss_SendCmd(GNSSCMD_GET_PVT_DATA); |
126 localComState = UART_GNSS_GET_PVT; | |
127 rxState = GNSSRX_DETECT_HEADER_0; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
128 break; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
129 default: |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
130 break; |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
131 } |
919 | 132 |
133 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState); | |
134 | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
135 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
136 |
919 | 137 void uartGnss_ProcessData(uint8_t data) |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
138 { |
919 | 139 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); |
140 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; | |
141 switch(rxState) | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
142 { |
919 | 143 case GNSSRX_DETECT_ACK_0: |
144 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5) | |
145 { | |
146 writeIndex = 0; | |
147 memset(GNSS_Handle.uartWorkingBuffer,0, sizeof(GNSS_Handle.uartWorkingBuffer)); | |
148 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; | |
149 rxState++; | |
150 } | |
151 break; | |
152 case GNSSRX_DETECT_ACK_1: | |
153 case GNSSRX_DETECT_HEADER_1: if(data == 0x62) | |
154 { | |
155 rxState++; | |
156 } | |
157 else | |
158 { | |
159 rxState = GNSSRX_DETECT_HEADER_0; | |
160 } | |
161 break; | |
162 case GNSSRX_DETECT_ACK_2: if(data == 0x05) | |
163 { | |
164 rxState++; | |
165 } | |
166 else | |
167 { | |
168 rxState = GNSSRX_DETECT_HEADER_0; | |
169 } | |
170 break; | |
171 case GNSSRX_DETECT_ACK_3: if((data == 0x01) || (data == 0x00)) | |
172 { | |
173 GnssConnected = 1; | |
174 rxState = GNSSRX_READY; | |
175 } | |
176 else | |
177 { | |
178 rxState = GNSSRX_DETECT_HEADER_0; | |
179 } | |
180 break; | |
181 case GNSSRX_DETECT_HEADER_2: if(data == 0x01) | |
182 { | |
183 rxState++; | |
184 } | |
185 else | |
186 { | |
187 rxState = GNSSRX_DETECT_HEADER_0; | |
188 } | |
189 break; | |
190 case GNSSRX_DETECT_HEADER_3: | |
191 switch(data) | |
192 { | |
193 case 0x21: rxState = GNSSRX_READ_NAV_DATA; | |
194 dataToRead = 20; | |
195 break; | |
196 case 0x07: rxState = GNSSRX_READ_PVT_DATA; | |
197 dataToRead = 92; | |
198 break; | |
199 case 0x02: rxState = GNSSRX_READ_POSLLH_DATA; | |
200 break; | |
201 default: rxState = GNSSRX_DETECT_HEADER_0; | |
202 break; | |
203 } | |
204 break; | |
205 case GNSSRX_READ_NAV_DATA: | |
206 case GNSSRX_READ_PVT_DATA: | |
207 case GNSSRX_READ_POSLLH_DATA: if(dataToRead > 0) | |
208 { | |
209 dataToRead--; | |
210 } | |
211 else | |
212 { | |
213 switch(rxState) | |
214 { | |
215 case GNSSRX_READ_NAV_DATA: GNSS_ParseNavigatorData(&GNSS_Handle); | |
216 break; | |
217 case GNSSRX_READ_PVT_DATA: GNSS_ParsePVTData(&GNSS_Handle); | |
218 break; | |
219 case GNSSRX_READ_POSLLH_DATA: GNSS_ParsePOSLLHData(&GNSS_Handle); | |
220 break; | |
221 default: rxState = GNSSRX_DETECT_HEADER_0; | |
222 break; | |
223 } | |
224 rxState = GNSSRX_DETECT_HEADER_0; | |
225 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,UART_GNSS_IDLE); | |
226 } | |
227 break; | |
228 default: rxState = GNSSRX_READY; | |
229 break; | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
230 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
231 } |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
232 |
919 | 233 uint8_t uartGnss_isSensorConnected() |
234 { | |
235 return GnssConnected; | |
236 } | |
237 | |
899
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
238 #endif |
2225c467f1e9
Added data path and visualization for position data:
Ideenmodellierer
parents:
diff
changeset
|
239 |