Mercurial > public > ostc4
comparison Discovery/Src/tComm.c @ 434:f68f2c4d71c7 Improve_BatteryGasGauge
Reduced timeout for common UART communication:
OSTC will slow down significant in case of a problem in Bluetoothconnection => reduces timeout which do not need to last one second
author | ideenmodellierer |
---|---|
date | Sun, 23 Feb 2020 21:13:28 +0100 |
parents | 7bcbbaa42cbf |
children | 5e38b09d2c45 |
comparison
equal
deleted
inserted
replaced
433:aa286a4926c2 | 434:f68f2c4d71c7 |
---|---|
104 | 104 |
105 /* Private types -------------------------------------------------------------*/ | 105 /* Private types -------------------------------------------------------------*/ |
106 #define BYTE_DOWNLOAD_MODE (0xBB) | 106 #define BYTE_DOWNLOAD_MODE (0xBB) |
107 #define BYTE_SERVICE_MODE (0xAA) | 107 #define BYTE_SERVICE_MODE (0xAA) |
108 | 108 |
109 #define UART_OPERATION_TIMEOUT (500u) /* Timeout for common read / write operations (ms) */ | |
109 #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ | 110 #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ |
110 #define UART_TIMEOUT_LARGE_BLOCK (6000u) /* Timeout (ms) for reception of an 16K data block (typical RX time ~4,5seconds) */ | 111 #define UART_TIMEOUT_LARGE_BLOCK (6000u) /* Timeout (ms) for reception of an 16K data block (typical RX time ~4,5seconds) */ |
111 | 112 |
112 #define UART_CMD_BUF_SIZE (20u) /* size of buffer for command exchange */ | 113 #define UART_CMD_BUF_SIZE (20u) /* size of buffer for command exchange */ |
113 | 114 |
442 | 443 |
443 HAL_UART_AbortReceive_IT(&UartHandle); | 444 HAL_UART_AbortReceive_IT(&UartHandle); |
444 do | 445 do |
445 { | 446 { |
446 HAL_Delay(200); | 447 HAL_Delay(200); |
447 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, 1000)== HAL_OK) | 448 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEscapeSequence, 3, UART_OPERATION_TIMEOUT)== HAL_OK) |
448 { | 449 { |
449 answer = tComm_CheckAnswerOK(); | 450 answer = tComm_CheckAnswerOK(); |
450 } | 451 } |
451 retrycnt--; | 452 retrycnt--; |
452 } | 453 } |
453 while((answer != HAL_OK) && (retrycnt > 0)); | 454 while((answer != HAL_OK) && (retrycnt > 0)); |
454 | 455 |
455 if(answer == HAL_OK) | 456 if(answer == HAL_OK) |
456 { | 457 { |
457 answer = HAL_ERROR; | 458 answer = HAL_ERROR; |
458 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxDisconnect,sizeDisconnect , 1000)== HAL_OK) | 459 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxDisconnect,sizeDisconnect , UART_OPERATION_TIMEOUT)== HAL_OK) |
459 { | 460 { |
460 answer = HAL_ERROR; | 461 answer = HAL_ERROR; |
461 if(tComm_CheckAnswerOK() == HAL_OK) | 462 if(tComm_CheckAnswerOK() == HAL_OK) |
462 { | 463 { |
463 answer = HAL_ERROR; | 464 answer = HAL_ERROR; |
464 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, 1000) == HAL_OK) /* exit terminal mode */ | 465 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBufferEnd, 4, UART_OPERATION_TIMEOUT) == HAL_OK) /* exit terminal mode */ |
465 { | 466 { |
466 answer = tComm_CheckAnswerOK(); | 467 answer = tComm_CheckAnswerOK(); |
467 } | 468 } |
468 } | 469 } |
469 } | 470 } |
534 answer = prompt4D4C(receiveStartByteUart); | 535 answer = prompt4D4C(receiveStartByteUart); |
535 } | 536 } |
536 | 537 |
537 while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS)) /* try receive once a second */ | 538 while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS)) /* try receive once a second */ |
538 { | 539 { |
539 if(HAL_UART_Receive(&UartHandle, (uint8_t*)&localRx, 1, 1000)!= HAL_OK) | 540 if(HAL_UART_Receive(&UartHandle, (uint8_t*)&localRx, 1, UART_OPERATION_TIMEOUT)!= HAL_OK) |
540 { | 541 { |
541 timeoutCounter++; | 542 timeoutCounter++; |
542 get_globalStateList(&status); | 543 get_globalStateList(&status); |
543 if (status.base != BaseComm) | 544 if (status.base != BaseComm) |
544 { | 545 { |
664 case 0x86: // hw overwrite entire logbook memory | 665 case 0x86: // hw overwrite entire logbook memory |
665 case 0x87: // hw ext_flash_repair_SPECIAL_dive_numbers_starting_count_with memory(x) | 666 case 0x87: // hw ext_flash_repair_SPECIAL_dive_numbers_starting_count_with memory(x) |
666 | 667 |
667 #endif | 668 #endif |
668 case 0xC1: // Start low-level bootloader | 669 case 0xC1: // Start low-level bootloader |
669 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, 1000)!= HAL_OK) | 670 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, 1, UART_OPERATION_TIMEOUT)!= HAL_OK) |
670 return 0; | 671 return 0; |
671 break; | 672 break; |
672 default: | 673 default: |
673 break; | 674 break; |
674 } | 675 } |
1924 uint8_t result = HAL_OK; | 1925 uint8_t result = HAL_OK; |
1925 uint8_t index = 0; | 1926 uint8_t index = 0; |
1926 uint8_t answer; | 1927 uint8_t answer; |
1927 | 1928 |
1928 memset(aRxBuffer,0,UART_CMD_BUF_SIZE); | 1929 memset(aRxBuffer,0,UART_CMD_BUF_SIZE); |
1929 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, sizeAnswer, 1000) == HAL_OK) | 1930 if(HAL_UART_Receive(&UartHandle, (uint8_t*)aRxBuffer, sizeAnswer, UART_OPERATION_TIMEOUT) == HAL_OK) |
1930 { | 1931 { |
1931 do | 1932 do |
1932 { | 1933 { |
1933 if(answerOkay[index] != aRxBuffer[index]) | 1934 if(answerOkay[index] != aRxBuffer[index]) |
1934 { | 1935 { |
2096 CmdSize = strlen(TxBuffer); | 2097 CmdSize = strlen(TxBuffer); |
2097 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000) == HAL_OK) | 2098 if(HAL_UART_Transmit(&UartHandle, (uint8_t*)TxBuffer,CmdSize, 2000) == HAL_OK) |
2098 { | 2099 { |
2099 if(BmTmpConfig == BM_CONFIG_ECHO) /* echo is not yet turned off => read and discard echo */ | 2100 if(BmTmpConfig == BM_CONFIG_ECHO) /* echo is not yet turned off => read and discard echo */ |
2100 { | 2101 { |
2101 HAL_UART_Receive(&UartHandle, (uint8_t*)TxBuffer, CmdSize, 1000); | 2102 HAL_UART_Receive(&UartHandle, (uint8_t*)TxBuffer, CmdSize, UART_OPERATION_TIMEOUT); |
2102 } | 2103 } |
2103 | 2104 |
2104 result = tComm_CheckAnswerOK(); | 2105 result = tComm_CheckAnswerOK(); |
2105 | 2106 |
2106 | 2107 |