# HG changeset patch # User ideenmodellierer # Date 1554039852 -7200 # Node ID ff59d1d07f9c1ed40271d975b42ab573b50f2a4f # Parent ce05c801b0029973798a4348de88971e81fce4fd Splitted 120 seconds UART timeout into chunks of 500ms The UART connection via Bluetooth was realized using a receive call with 120 seconds timeout. By cancellation it seemed for the user as if the connection would have been aborted. In reality the received function keeped executing the wait for RX data till timeout occure. To avaoid this the timeout has been splitted into several calls with 500ms timeout => If the user disconnects by pressing "back" the COMM function is now ended. diff -r ce05c801b002 -r ff59d1d07f9c Discovery/Src/tComm.c --- a/Discovery/Src/tComm.c Sun Mar 31 15:39:44 2019 +0200 +++ b/Discovery/Src/tComm.c Sun Mar 31 15:44:12 2019 +0200 @@ -97,16 +97,18 @@ uint8_t bluetoothActiveLastTime = 0; uint8_t StartListeningToUART = 0; -char display_text[256] = { 0 }; +unsigned char display_text[256] = { 0 }; uint8_t setForcedBluetoothName = 0; uint8_t updateSettingsAndMenuOnExit = 0; /* Private types -------------------------------------------------------------*/ -#define BYTE_DOWNLOAD_MODE (0xBB) +#define BYTE_DOWNLOAD_MODE (0xBB) #define BYTE_SERVICE_MODE (0xAA) +#define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */ + const uint8_t id_Region1_firmware = 0xFF; const uint8_t id_RTE = 0xFE; const uint8_t id_FONT = 0x10; @@ -399,6 +401,8 @@ uint8_t openComm(uint8_t aRxByte) { + SStateList status; + uint8_t timeoutCounter = 0; uint8_t answer = 0; uint8_t service_mode_last_three_bytes[3]; uint8_t service_mode_response[5] = @@ -454,10 +458,22 @@ uint8_t dbgptr = 0; debug[dbgptr++] = aRxByte; */ - while((answer == prompt4D4C(receiveStartByteUart)) && (HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 120000)== HAL_OK)) + while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS * 2)) /* Split 120 seconds timeout into 240 iterations a 500ms */ { + if(HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 500)!= HAL_OK) /* Timeout half a second */ + { + timeoutCounter++; + get_globalStateList(&status); + if (status.base != BaseComm) + { + timeoutCounter = UART_TIMEOUT_SECONDS * 2; /* Abort action triggered outside main loop => exit */ + } + } + else + { // debug[dbgptr++] = aRxByte; - answer = select_mode(aRxByte); + answer = select_mode(aRxByte); + } } set_returnFromComm(); return 1;