comparison Discovery/Src/tComm.c @ 221:486dddfba7ce

Merged in Ideenmodellierer/ostc4/Improve_IPC_Sync (pull request #12) Improve IPC Sync
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Mon, 01 Apr 2019 09:01:09 +0000
parents ff59d1d07f9c
children 2c0b502b0a72
comparison
equal deleted inserted replaced
216:7012a521fa95 221:486dddfba7ce
95 95
96 uint8_t receiveStartByteUart = 0; 96 uint8_t receiveStartByteUart = 0;
97 uint8_t bluetoothActiveLastTime = 0; 97 uint8_t bluetoothActiveLastTime = 0;
98 98
99 uint8_t StartListeningToUART = 0; 99 uint8_t StartListeningToUART = 0;
100 char display_text[256] = { 0 }; 100 unsigned char display_text[256] = { 0 };
101 101
102 uint8_t setForcedBluetoothName = 0; 102 uint8_t setForcedBluetoothName = 0;
103 103
104 uint8_t updateSettingsAndMenuOnExit = 0; 104 uint8_t updateSettingsAndMenuOnExit = 0;
105 105
106 /* Private types -------------------------------------------------------------*/ 106 /* Private types -------------------------------------------------------------*/
107 #define BYTE_DOWNLOAD_MODE (0xBB) 107 #define BYTE_DOWNLOAD_MODE (0xBB)
108 #define BYTE_SERVICE_MODE (0xAA) 108 #define BYTE_SERVICE_MODE (0xAA)
109
110 #define UART_TIMEOUT_SECONDS (120u) /* Timeout for keeping connection open and waiting for data */
109 111
110 const uint8_t id_Region1_firmware = 0xFF; 112 const uint8_t id_Region1_firmware = 0xFF;
111 const uint8_t id_RTE = 0xFE; 113 const uint8_t id_RTE = 0xFE;
112 const uint8_t id_FONT = 0x10; 114 const uint8_t id_FONT = 0x10;
113 const uint8_t id_FONT_OLD = 0x00; 115 const uint8_t id_FONT_OLD = 0x00;
397 } 399 }
398 400
399 401
400 uint8_t openComm(uint8_t aRxByte) 402 uint8_t openComm(uint8_t aRxByte)
401 { 403 {
404 SStateList status;
405 uint8_t timeoutCounter = 0;
402 uint8_t answer = 0; 406 uint8_t answer = 0;
403 uint8_t service_mode_last_three_bytes[3]; 407 uint8_t service_mode_last_three_bytes[3];
404 uint8_t service_mode_response[5] = 408 uint8_t service_mode_response[5] =
405 { 409 {
406 0x4B, 410 0x4B,
452 /* 456 /*
453 uint8_t debug[256] = {0}; 457 uint8_t debug[256] = {0};
454 uint8_t dbgptr = 0; 458 uint8_t dbgptr = 0;
455 debug[dbgptr++] = aRxByte; 459 debug[dbgptr++] = aRxByte;
456 */ 460 */
457 while((answer == prompt4D4C(receiveStartByteUart)) && (HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 120000)== HAL_OK)) 461 while((answer == prompt4D4C(receiveStartByteUart)) && (timeoutCounter < UART_TIMEOUT_SECONDS * 2)) /* Split 120 seconds timeout into 240 iterations a 500ms */
458 { 462 {
463 if(HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxByte, 1, 500)!= HAL_OK) /* Timeout half a second */
464 {
465 timeoutCounter++;
466 get_globalStateList(&status);
467 if (status.base != BaseComm)
468 {
469 timeoutCounter = UART_TIMEOUT_SECONDS * 2; /* Abort action triggered outside main loop => exit */
470 }
471 }
472 else
473 {
459 // debug[dbgptr++] = aRxByte; 474 // debug[dbgptr++] = aRxByte;
460 answer = select_mode(aRxByte); 475 answer = select_mode(aRxByte);
476 }
461 } 477 }
462 set_returnFromComm(); 478 set_returnFromComm();
463 return 1; 479 return 1;
464 } 480 }
465 481