Mercurial > public > ostc4
comparison Small_CPU/Src/uartProtocol_GNSS.c @ 919:c0553dd70608 Evo_2_23
GNSS support for external UART interface:
An ubox gps module may now be connected to the external UART. Per default the functionality is disabled using the compile switch ENABLE_GNSS_SUPPORT
author | Ideenmodellierer |
---|---|
date | Sun, 03 Nov 2024 15:43:04 +0100 |
parents | 2225c467f1e9 |
children | 7c996354b8ac |
comparison
equal
deleted
inserted
replaced
918:f72613a152dd | 919:c0553dd70608 |
---|---|
22 #include <string.h> | 22 #include <string.h> |
23 #include "scheduler.h" | 23 #include "scheduler.h" |
24 #include <uartProtocol_GNSS.h> | 24 #include <uartProtocol_GNSS.h> |
25 #include "uart.h" | 25 #include "uart.h" |
26 #include "GNSS.h" | 26 #include "GNSS.h" |
27 | 27 #include "configuration.h" |
28 #ifdef ENABLE_GNSS | 28 #include "externalInterface.h" |
29 | 29 |
30 static uartGnssStatus_t gnssOpState = UART_GNSS_INIT; | 30 #if defined ENABLE_GNSS || defined ENABLE_GNSS_SUPPORT |
31 | |
31 static receiveStateGnss_t rxState = GNSSRX_READY; | 32 static receiveStateGnss_t rxState = GNSSRX_READY; |
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; | |
32 | 38 |
33 void ConvertByteToHexString(uint8_t byte, char* str) | 39 void ConvertByteToHexString(uint8_t byte, char* str) |
34 { | 40 { |
35 uint8_t worker = 0; | 41 uint8_t worker = 0; |
36 uint8_t digit = 0; | 42 uint8_t digit = 0; |
51 str[digitCnt--]= digit; | 57 str[digitCnt--]= digit; |
52 worker = worker / 16; | 58 worker = worker / 16; |
53 } | 59 } |
54 } | 60 } |
55 | 61 |
62 | |
63 void uartGnss_SendCmd(uint8_t GnssCmd) | |
64 { | |
65 uint8_t* pData; | |
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 | |
56 void uartGnss_Control(void) | 95 void uartGnss_Control(void) |
57 { | 96 { |
58 static uint32_t delayStartTick = 0; | 97 static uint32_t warmupTick = 0; |
59 | 98 |
60 uint32_t tick = HAL_GetTick(); | 99 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); |
61 | 100 uartGnssStatus_t localComState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); |
62 switch (gnssOpState) | 101 |
63 { | 102 switch (localComState) |
64 case UART_GNSS_INIT: delayStartTick = tick; | 103 { |
65 gnssOpState = UART_GNSS_LOAD; | 104 case UART_GNSS_INIT: localComState = UART_GNSS_WARMUP; |
66 break; | 105 warmupTick = HAL_GetTick(); |
67 case UART_GNSS_LOAD: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 1000) | 106 UART_clearRxBuffer(); |
68 { | 107 break; |
69 GNSS_LoadConfig(&GNSS_Handle); | 108 case UART_GNSS_WARMUP: if(time_elapsed_ms(warmupTick,HAL_GetTick()) > 1000) |
70 gnssOpState = UART_GNSS_GET_ID; | 109 { |
71 delayStartTick = tick; | 110 localComState = UART_GNSS_LOADCONF_0; |
72 } | 111 } |
73 break; | 112 break; |
74 case UART_GNSS_GET_ID: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 250) | 113 case UART_GNSS_LOADCONF_0: uartGnss_SendCmd(GNSSCMD_LOADCONF_0); |
75 { | 114 localComState = UART_GNSS_LOADCONF_1; |
76 GNSS_GetUniqID(&GNSS_Handle); | 115 rxState = GNSSRX_DETECT_ACK_0; |
77 gnssOpState = UART_GNSS_IDLE; | 116 break; |
78 rxState = GNSSRX_RECEIVING; | 117 case UART_GNSS_LOADCONF_1: uartGnss_SendCmd(GNSSCMD_LOADCONF_1); |
79 delayStartTick = tick; | 118 localComState = UART_GNSS_LOADCONF_2; |
80 } | 119 rxState = GNSSRX_DETECT_ACK_0; |
81 break; | 120 break; |
82 case UART_GNSS_IDLE: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 1000) | 121 case UART_GNSS_LOADCONF_2: uartGnss_SendCmd(GNSSCMD_LOADCONF_2); |
83 { | 122 localComState = UART_GNSS_IDLE; |
84 GNSS_GetPVTData(&GNSS_Handle); | 123 rxState = GNSSRX_DETECT_ACK_0; |
85 gnssOpState = UART_GNSS_OPERATING; | 124 break; |
86 rxState = GNSSRX_RECEIVING; | 125 case UART_GNSS_IDLE: uartGnss_SendCmd(GNSSCMD_GET_PVT_DATA); |
87 delayStartTick = tick; | 126 localComState = UART_GNSS_GET_PVT; |
88 } | 127 rxState = GNSSRX_DETECT_HEADER_0; |
89 break; | |
90 case UART_GNSS_OPERATING: if(time_elapsed_ms(delayStartTick,HAL_GetTick()) > 1000) | |
91 { | |
92 gnssOpState = UART_GNSS_IDLE; /* simple error handling => start next request */ | |
93 rxState = GNSSRX_READY; | |
94 } | |
95 break; | 128 break; |
96 default: | 129 default: |
97 break; | 130 break; |
98 } | 131 } |
99 } | 132 |
100 | 133 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,localComState); |
101 void uartGnss_ProcessData(void) | 134 |
102 { | 135 } |
103 if(rxState == GNSSRX_RECEIVING) | 136 |
104 { | 137 void uartGnss_ProcessData(uint8_t data) |
105 if(GNSS_ParseBuffer(&GNSS_Handle)) | 138 { |
106 { | 139 uint8_t activeSensor = externalInterface_GetActiveUartSensor(); |
107 gnssOpState = UART_GNSS_IDLE; | 140 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; |
108 } | 141 switch(rxState) |
109 } | 142 { |
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; | |
230 } | |
231 } | |
232 | |
233 uint8_t uartGnss_isSensorConnected() | |
234 { | |
235 return GnssConnected; | |
110 } | 236 } |
111 | 237 |
112 #endif | 238 #endif |
113 | 239 |