Mercurial > public > ostc4
comparison Small_CPU/Src/uart_Internal.c @ 931:5a9bc2e6112d Evo_2_23
Added Sat Status Overview:
In addition to the navigation data now information regarding the satelliete and signal status are visualized. To enable the a new command has been added to the communication protocol and the position view has been extended.
author | Ideenmodellierer |
---|---|
date | Tue, 03 Dec 2024 20:32:51 +0100 |
parents | 908d9a8e8c84 |
children | effadaa3a1f7 |
comparison
equal
deleted
inserted
replaced
930:25948e805406 | 931:5a9bc2e6112d |
---|---|
27 #include "data_exchange.h" | 27 #include "data_exchange.h" |
28 #include <string.h> /* memset */ | 28 #include <string.h> /* memset */ |
29 | 29 |
30 | 30 |
31 static uint8_t isEndIndication6(uint8_t index); | 31 static uint8_t isEndIndication6(uint8_t index); |
32 static uint8_t gnssState = UART_GNSS_INIT; | 32 static uartGnssStatus_t gnssState = UART_GNSS_INIT; |
33 static gnssRequest_s activeRequest = {0,0}; | |
33 | 34 |
34 /* Private variables ---------------------------------------------------------*/ | 35 /* Private variables ---------------------------------------------------------*/ |
35 | 36 |
36 | 37 |
37 #define TX_BUF_SIZE (40u) /* max length for commands */ | 38 #define TX_BUF_SIZE (40u) /* max length for commands */ |
38 #define CHUNK_SIZE (25u) /* the DMA will handle chunk size transfers */ | 39 #define CHUNK_SIZE (50u) /* the DMA will handle chunk size transfers */ |
39 #define CHUNKS_PER_BUFFER (6u) | 40 #define CHUNKS_PER_BUFFER (3u) |
40 | 41 |
41 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */ | 42 #define REQUEST_INT_SENSOR_MS (1500) /* Minimum time interval for cyclic sensor data requests per sensor (UART mux) */ |
42 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */ | 43 #define COMMAND_TX_DELAY (30u) /* The time the sensor needs to recover from a invalid command request */ |
43 #define TIMEOUT_SENSOR_ANSWER (300) /* Time till a request is repeated if no answer was received */ | 44 #define TIMEOUT_SENSOR_ANSWER (300) /* Time till a request is repeated if no answer was received */ |
44 | 45 |
46 static receiveStateGnss_t rxState = GNSSRX_READY; | 47 static receiveStateGnss_t rxState = GNSSRX_READY; |
47 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */ | 48 static uint8_t GnssConnected = 0; /* Binary indicator if a sensor is connected or not */ |
48 | 49 |
49 static uint8_t writeIndex = 0; | 50 static uint8_t writeIndex = 0; |
50 | 51 |
51 static uint8_t dataToRead = 0; | 52 static uint16_t dataToRead = 0; |
52 | 53 |
53 DMA_HandleTypeDef hdma_usart6_rx, hdma_usart6_tx; | 54 DMA_HandleTypeDef hdma_usart6_rx, hdma_usart6_tx; |
54 | 55 |
55 uint8_t tx6Buffer[CHUNK_SIZE]; /* tx uses less bytes */ | 56 uint8_t tx6Buffer[CHUNK_SIZE]; /* tx uses less bytes */ |
56 uint8_t tx6BufferQue[TX_BUF_SIZE]; /* In MUX mode command may be send shortly after each other => allow q 1 entry que */ | 57 uint8_t tx6BufferQue[TX_BUF_SIZE]; /* In MUX mode command may be send shortly after each other => allow q 1 entry que */ |
274 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) | 275 if(futureIndex >= CHUNK_SIZE * CHUNKS_PER_BUFFER) |
275 { | 276 { |
276 futureIndex = 0; | 277 futureIndex = 0; |
277 } | 278 } |
278 | 279 |
279 if((!isEndIndication6(localRX)) || (!isEndIndication6(futureIndex))) do | 280 if(!isEndIndication6(futureIndex)) |
281 { | |
282 moreData = 1; | |
283 } | |
284 | |
285 if((!isEndIndication6(localRX)) || (moreData)) | |
286 do | |
280 { | 287 { |
281 while((!isEndIndication6(localRX)) || (moreData)) | 288 while((!isEndIndication6(localRX)) || (moreData)) |
282 { | 289 { |
283 moreData = 0; | 290 moreData = 0; |
284 UART6_Gnss_ProcessData(rxBufferUart6[localRX]); | 291 UART6_Gnss_ProcessData(rxBufferUart6[localRX]); |
346 txLength = sizeof(getPVTData) / sizeof(uint8_t); | 353 txLength = sizeof(getPVTData) / sizeof(uint8_t); |
347 break; | 354 break; |
348 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData; | 355 case GNSSCMD_GET_NAV_DATA: pData = getNavigatorData; |
349 txLength = sizeof(getNavigatorData) / sizeof(uint8_t); | 356 txLength = sizeof(getNavigatorData) / sizeof(uint8_t); |
350 break; | 357 break; |
351 | 358 case GNSSCMD_GET_NAVSAT_DATA: pData = getNavSat; |
359 txLength = sizeof(getNavSat) / sizeof(uint8_t); | |
360 break; | |
352 default: | 361 default: |
353 break; | 362 break; |
354 } | 363 } |
355 if(txLength != 0) | 364 if(txLength != 0) |
356 { | 365 { |
366 activeRequest.class = pData[2]; | |
367 activeRequest.id = pData[3]; | |
357 UART6_SendCmdUbx(pData, txLength); | 368 UART6_SendCmdUbx(pData, txLength); |
358 } | 369 } |
359 } | 370 } |
360 | 371 |
361 void UART6_Gnss_Control(void) | 372 void UART6_Gnss_Control(void) |
362 { | 373 { |
363 static uint32_t warmupTick = 0; | 374 static uint32_t warmupTick = 0; |
375 static uint8_t dataToggle = 0; | |
364 | 376 |
365 switch (gnssState) | 377 switch (gnssState) |
366 { | 378 { |
367 case UART_GNSS_INIT: gnssState = UART_GNSS_WARMUP; | 379 case UART_GNSS_INIT: gnssState = UART_GNSS_WARMUP; |
368 warmupTick = HAL_GetTick(); | 380 warmupTick = HAL_GetTick(); |
383 break; | 395 break; |
384 case UART_GNSS_LOADCONF_2: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_2); | 396 case UART_GNSS_LOADCONF_2: UART6_Gnss_SendCmd(GNSSCMD_LOADCONF_2); |
385 gnssState = UART_GNSS_IDLE; | 397 gnssState = UART_GNSS_IDLE; |
386 rxState = GNSSRX_DETECT_ACK_0; | 398 rxState = GNSSRX_DETECT_ACK_0; |
387 break; | 399 break; |
388 case UART_GNSS_IDLE: UART6_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA); | 400 case UART_GNSS_IDLE: if(dataToggle) |
389 gnssState = UART_GNSS_GET_PVT; | 401 { |
390 rxState = GNSSRX_DETECT_HEADER_0; | 402 UART6_Gnss_SendCmd(GNSSCMD_GET_PVT_DATA); |
403 gnssState = UART_GNSS_GET_PVT; | |
404 rxState = GNSSRX_DETECT_HEADER_0; | |
405 dataToggle = 0; | |
406 } | |
407 else | |
408 { | |
409 UART6_Gnss_SendCmd(GNSSCMD_GET_NAVSAT_DATA); | |
410 gnssState = UART_GNSS_GET_SAT; | |
411 rxState = GNSSRX_DETECT_HEADER_0; | |
412 dataToggle = 1; | |
413 } | |
391 break; | 414 break; |
392 default: | 415 default: |
393 break; | 416 break; |
394 } | 417 } |
395 } | 418 } |
396 | 419 |
397 void UART6_Gnss_ProcessData(uint8_t data) | 420 void UART6_Gnss_ProcessData(uint8_t data) |
398 { | 421 { |
422 static uint16_t rxLength = 0; | |
423 static uint8_t ck_A = 0; | |
424 static uint8_t ck_B = 0; | |
425 static uint8_t ck_A_Ref = 0; | |
426 static uint8_t ck_B_Ref = 0; | |
427 | |
399 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; | 428 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; |
429 if((rxState >= GNSSRX_DETECT_HEADER_2) && (rxState < GNSSRX_READ_CK_A)) | |
430 { | |
431 ck_A += data; | |
432 ck_B += ck_A; | |
433 } | |
434 | |
400 switch(rxState) | 435 switch(rxState) |
401 { | 436 { |
402 case GNSSRX_DETECT_ACK_0: | 437 case GNSSRX_DETECT_ACK_0: |
403 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5) | 438 case GNSSRX_DETECT_HEADER_0: if(data == 0xB5) |
404 { | 439 { |
405 writeIndex = 0; | 440 writeIndex = 0; |
406 memset(GNSS_Handle.uartWorkingBuffer,0, sizeof(GNSS_Handle.uartWorkingBuffer)); | 441 memset(GNSS_Handle.uartWorkingBuffer,0xff, sizeof(GNSS_Handle.uartWorkingBuffer)); |
407 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; | 442 GNSS_Handle.uartWorkingBuffer[writeIndex++] = data; |
408 rxState++; | 443 rxState++; |
444 ck_A = 0; | |
445 ck_B = 0; | |
409 } | 446 } |
410 break; | 447 break; |
411 case GNSSRX_DETECT_ACK_1: | 448 case GNSSRX_DETECT_ACK_1: |
412 case GNSSRX_DETECT_HEADER_1: if(data == 0x62) | 449 case GNSSRX_DETECT_HEADER_1: if(data == 0x62) |
413 { | 450 { |
435 else | 472 else |
436 { | 473 { |
437 rxState = GNSSRX_DETECT_HEADER_0; | 474 rxState = GNSSRX_DETECT_HEADER_0; |
438 } | 475 } |
439 break; | 476 break; |
440 case GNSSRX_DETECT_HEADER_2: if(data == 0x01) | 477 case GNSSRX_DETECT_HEADER_2: if(data == activeRequest.class) |
441 { | 478 { |
442 rxState++; | 479 rxState++; |
443 } | 480 } |
444 else | 481 else |
445 { | 482 { |
446 rxState = GNSSRX_DETECT_HEADER_0; | 483 rxState = GNSSRX_DETECT_HEADER_0; |
447 } | 484 } |
448 break; | 485 break; |
449 case GNSSRX_DETECT_HEADER_3: | 486 case GNSSRX_DETECT_HEADER_3: if(data == activeRequest.id) |
450 switch(data) | 487 { |
451 { | 488 rxState = GNSSRX_DETECT_LENGTH_0; |
452 case 0x21: rxState = GNSSRX_READ_NAV_DATA; | 489 } |
453 dataToRead = 20; | 490 else |
454 break; | 491 { |
455 case 0x07: rxState = GNSSRX_READ_PVT_DATA; | 492 rxState = GNSSRX_DETECT_HEADER_0; |
456 dataToRead = 92; | 493 } |
457 break; | 494 break; |
458 case 0x02: rxState = GNSSRX_READ_POSLLH_DATA; | 495 case GNSSRX_DETECT_LENGTH_0: rxLength = GNSS_Handle.uartWorkingBuffer[4]; |
459 break; | 496 rxState = GNSSRX_DETECT_LENGTH_1; |
460 default: rxState = GNSSRX_DETECT_HEADER_0; | 497 break; |
461 break; | 498 case GNSSRX_DETECT_LENGTH_1: rxLength += (GNSS_Handle.uartWorkingBuffer[5] << 8); |
462 } | 499 rxState = GNSSRX_READ_DATA; |
463 break; | 500 dataToRead = rxLength; |
464 case GNSSRX_READ_NAV_DATA: | 501 break; |
465 case GNSSRX_READ_PVT_DATA: | 502 case GNSSRX_READ_DATA: if(dataToRead > 0) |
466 case GNSSRX_READ_POSLLH_DATA: if(dataToRead > 0) | |
467 { | 503 { |
468 dataToRead--; | 504 dataToRead--; |
469 } | 505 } |
470 else | 506 if(dataToRead == 0) |
471 { | 507 { |
472 switch(rxState) | 508 rxState = GNSSRX_READ_CK_A; |
473 { | |
474 case GNSSRX_READ_NAV_DATA: GNSS_ParseNavigatorData(&GNSS_Handle); | |
475 break; | |
476 case GNSSRX_READ_PVT_DATA: GNSS_ParsePVTData(&GNSS_Handle); | |
477 break; | |
478 case GNSSRX_READ_POSLLH_DATA: GNSS_ParsePOSLLHData(&GNSS_Handle); | |
479 break; | |
480 default: rxState = GNSSRX_DETECT_HEADER_0; | |
481 break; | |
482 } | |
483 rxState = GNSSRX_DETECT_HEADER_0; | |
484 gnssState = UART_GNSS_IDLE; | |
485 } | 509 } |
486 break; | 510 break; |
511 case GNSSRX_READ_CK_A: ck_A_Ref = data; | |
512 rxState++; | |
513 break; | |
514 case GNSSRX_READ_CK_B: ck_B_Ref = data; | |
515 if((ck_A_Ref == ck_A) && (ck_B_Ref == ck_B)) | |
516 { | |
517 switch(gnssState) | |
518 { | |
519 case UART_GNSS_GET_PVT:GNSS_ParsePVTData(&GNSS_Handle); | |
520 break; | |
521 case UART_GNSS_GET_SAT: GNSS_ParseNavSatData(&GNSS_Handle); | |
522 break; | |
523 default: | |
524 break; | |
525 } | |
526 } | |
527 rxState = GNSSRX_DETECT_HEADER_0; | |
528 gnssState = UART_GNSS_IDLE; | |
529 break; | |
530 | |
487 default: rxState = GNSSRX_READY; | 531 default: rxState = GNSSRX_READY; |
488 break; | 532 break; |
489 } | 533 } |
490 } | 534 } |
491 | 535 |
527 lastRequestTick = tick; | 571 lastRequestTick = tick; |
528 TriggerTick = tick; | 572 TriggerTick = tick; |
529 retryRequest = 0; | 573 retryRequest = 0; |
530 timeToTrigger = 1; | 574 timeToTrigger = 1; |
531 | 575 |
532 if((gnssState == UART_GNSS_GET_PVT)) /* timeout */ | 576 if((gnssState == UART_GNSS_GET_SAT) || (gnssState == UART_GNSS_GET_PVT)) /* timeout */ |
533 { | 577 { |
534 gnssState = UART_GNSS_IDLE; | 578 gnssState = UART_GNSS_IDLE; |
535 } | 579 } |
536 timeToTrigger = 1; | 580 timeToTrigger = 1; |
537 } | 581 } |