comparison Small_CPU/Src/uartProtocol_GNSS.c @ 936:3029f0332f4f Evo_2_23

GNSS introduced power saving mode: In the previous implementation the modul always did a cold start. In the new one the power saving functions of the module are activated. The module will be switched to intervall mode while entering sleep. If the computer remains in sleep for a long time then the GNSS modul will be switchen of completly.
author Ideenmodellierer
date Sun, 08 Dec 2024 22:03:07 +0100
parents effadaa3a1f7
children f41974734268
comparison
equal deleted inserted replaced
935:f2494a708f52 936:3029f0332f4f
33 static uartGnssStatus_t gnssState = UART_GNSS_INIT; 33 static uartGnssStatus_t gnssState = UART_GNSS_INIT;
34 static gnssRequest_s activeRequest = {0,0}; 34 static gnssRequest_s activeRequest = {0,0};
35 35
36 static receiveStateGnss_t rxState = GNSSRX_READY; 36 static receiveStateGnss_t rxState = GNSSRX_READY;
37 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */ 37 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */
38
39 static uint8_t writeIndex = 0; 38 static uint8_t writeIndex = 0;
40
41 static uint8_t dataToRead = 0; 39 static uint8_t dataToRead = 0;
40 static uint8_t ReqPowerDown = 0;
42 41
43 void ConvertByteToHexString(uint8_t byte, char* str) 42 void ConvertByteToHexString(uint8_t byte, char* str)
44 { 43 {
45 uint8_t worker = 0; 44 uint8_t worker = 0;
46 uint8_t digit = 0; 45 uint8_t digit = 0;
61 str[digitCnt--]= digit; 60 str[digitCnt--]= digit;
62 worker = worker / 16; 61 worker = worker / 16;
63 } 62 }
64 } 63 }
65 64
65 void uartGnss_ReqPowerDown(uint8_t request)
66 {
67 if(GnssConnected)
68 {
69 ReqPowerDown = 1;
70 }
71 }
66 72
67 uartGnssStatus_t uartGnss_GetState() 73 uartGnssStatus_t uartGnss_GetState()
68 { 74 {
69 return gnssState; 75 return gnssState;
70 } 76 }
96 txLength = sizeof(getNavigatorData) / sizeof(uint8_t); 102 txLength = sizeof(getNavigatorData) / sizeof(uint8_t);
97 break; 103 break;
98 case GNSSCMD_GET_NAVSAT_DATA: pData = getNavSat; 104 case GNSSCMD_GET_NAVSAT_DATA: pData = getNavSat;
99 txLength = sizeof(getNavSat) / sizeof(uint8_t); 105 txLength = sizeof(getNavSat) / sizeof(uint8_t);
100 break; 106 break;
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;
101 default: 116 default:
102 break; 117 break;
103 } 118 }
104 if(txLength != 0) 119 if(txLength != 0)
105 { 120 {
113 { 128 {
114 static uint32_t warmupTick = 0; 129 static uint32_t warmupTick = 0;
115 static uint8_t dataToggle = 0; 130 static uint8_t dataToggle = 0;
116 uint8_t activeSensor = 0; 131 uint8_t activeSensor = 0;
117 sUartComCtrl* pUartCtrl = UART_GetGnssCtrl(); 132 sUartComCtrl* pUartCtrl = UART_GetGnssCtrl();
118 // uartGnssStatus_t localComState;
119 133
120 if(pUartCtrl == &Uart1Ctrl) 134 if(pUartCtrl == &Uart1Ctrl)
121 { 135 {
122 activeSensor = externalInterface_GetActiveUartSensor(); 136 activeSensor = externalInterface_GetActiveUartSensor();
123 gnssState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET); 137 gnssState = externalInterface_GetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET);
141 rxState = GNSSRX_DETECT_ACK_0; 155 rxState = GNSSRX_DETECT_ACK_0;
142 break; 156 break;
143 case UART_GNSS_LOADCONF_2: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_2); 157 case UART_GNSS_LOADCONF_2: UART_Gnss_SendCmd(GNSSCMD_LOADCONF_2);
144 rxState = GNSSRX_DETECT_ACK_0; 158 rxState = GNSSRX_DETECT_ACK_0;
145 break; 159 break;
146 case UART_GNSS_IDLE: if(dataToggle) 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)
147 { 174 {
148 UART_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA); 175 UART_Gnss_SendCmd(GNSSCMD_MODE_PWS);
149 gnssState = UART_GNSS_GET_PVT; 176 gnssState = UART_GNSS_PWRDOWN;
150 rxState = GNSSRX_DETECT_HEADER_0; 177 rxState = GNSSRX_DETECT_ACK_0;
151 dataToggle = 0;
152 } 178 }
153 else 179 else
154 { 180 {
155 UART_Gnss_SendCmd(GNSSCMD_GET_NAVSAT_DATA); 181 if(dataToggle)
156 gnssState = UART_GNSS_GET_SAT; 182 {
157 rxState = GNSSRX_DETECT_HEADER_0; 183 UART_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA);
158 dataToggle = 1; 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 }
159 } 195 }
160 break; 196 break;
161 default: 197 default:
162 break; 198 break;
163 } 199 }
165 { 201 {
166 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,gnssState); 202 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,gnssState);
167 } 203 }
168 204
169 } 205 }
206
170 207
171 void uartGnss_ProcessData(uint8_t data) 208 void uartGnss_ProcessData(uint8_t data)
172 { 209 {
173 static uint16_t rxLength = 0; 210 static uint16_t rxLength = 0;
174 static uint8_t ck_A = 0; 211 static uint8_t ck_A = 0;
175 static uint8_t ck_B = 0; 212 static uint8_t ck_B = 0;
176 static uint8_t ck_A_Ref = 0; 213 static uint8_t ck_A_Ref = 0;
177 static uint8_t ck_B_Ref = 0; 214 static uint8_t ck_B_Ref = 0;
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 }
178 224
179 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; 225 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data;
180 if((rxState >= GNSSRX_DETECT_HEADER_2) && (rxState < GNSSRX_READ_CK_A)) 226 if((rxState >= GNSSRX_DETECT_HEADER_2) && (rxState < GNSSRX_READ_CK_A))
181 { 227 {
182 ck_A += data; 228 ck_A += data;
215 rxState = GNSSRX_DETECT_HEADER_0; 261 rxState = GNSSRX_DETECT_HEADER_0;
216 } 262 }
217 break; 263 break;
218 case GNSSRX_DETECT_ACK_3: if((data == 0x01)) 264 case GNSSRX_DETECT_ACK_3: if((data == 0x01))
219 { 265 {
220 if((gnssState >= UART_GNSS_LOADCONF_0) && (gnssState <= UART_GNSS_LOADCONF_2)) 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))
221 { 282 {
222 if(gnssState == UART_GNSS_LOADCONF_2) 283 if(gnssState == UART_GNSS_LOADCONF_2)
223 { 284 {
224 gnssState = UART_GNSS_IDLE; 285 gnssState = UART_GNSS_IDLE;
225 } 286 }
227 { 288 {
228 gnssState++; 289 gnssState++;
229 } 290 }
230 } 291 }
231 GnssConnected = 1; 292 GnssConnected = 1;
232 rxState = GNSSRX_READY;
233 } 293 }
234 else 294 else
235 { 295 {
236 rxState = GNSSRX_DETECT_HEADER_0; 296 rxState = GNSSRX_DETECT_HEADER_0;
237 } 297 }
291 break; 351 break;
292 352
293 default: rxState = GNSSRX_READY; 353 default: rxState = GNSSRX_READY;
294 break; 354 break;
295 } 355 }
356 if(pUartCtrl == &Uart1Ctrl)
357 {
358 externalInterface_SetSensorState(activeSensor + EXT_INTERFACE_MUX_OFFSET,gnssState);
359 }
296 } 360 }
297 361
298 uint8_t uartGnss_isSensorConnected() 362 uint8_t uartGnss_isSensorConnected()
299 { 363 {
300 return GnssConnected; 364 return GnssConnected;