TPUART: Avoid false EOP (#166)

* Made the rx loop shorter to avoid tx buffer saturation.

* sendSingleFrameByte return false on last byte

* sendSingleFrameByte return false on last byte
This commit is contained in:
mptei 2022-01-16 18:25:32 +01:00 committed by GitHub
parent bf70e162f8
commit f5feefb0f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,13 +113,14 @@ void TpUartDataLinkLayer::loop()
if (!_enabled) if (!_enabled)
return; return;
// Signals to communicate from rx part with the tx part
bool isEchoComplete = false; // Flag that a complete echo is received
uint8_t dataConnMsg = 0; // The DATA_CONN message just seen or 0
do { do {
_receiveBuffer[0] = 0x29; _receiveBuffer[0] = 0x29;
_receiveBuffer[1] = 0; _receiveBuffer[1] = 0;
uint8_t* buffer = _receiveBuffer + 2; uint8_t* buffer = _receiveBuffer + 2;
uint8_t rxByte; uint8_t rxByte;
bool isEchoComplete = false; // Flag that a complete echo is received
bool dataConnMsg = 0; // The DATA_CONN message just seen or 0
bool isEOP = (millis() - _lastByteRxTime > EOP_TIMEOUT); // Flag that an EOP gap is seen bool isEOP = (millis() - _lastByteRxTime > EOP_TIMEOUT); // Flag that an EOP gap is seen
switch (_rxState) switch (_rxState)
{ {
@ -356,6 +357,7 @@ void TpUartDataLinkLayer::loop()
default: default:
break; break;
} }
} while (_rxState == RX_L_DATA);
// Check for spurios DATA_CONN message // Check for spurios DATA_CONN message
if (dataConnMsg && _txState != TX_WAIT_CONN && _txState != TX_WAIT_ECHO) { if (dataConnMsg && _txState != TX_WAIT_CONN && _txState != TX_WAIT_ECHO) {
@ -423,7 +425,6 @@ void TpUartDataLinkLayer::loop()
} }
break; break;
} }
} while (_rxState == RX_L_DATA);
} }
bool TpUartDataLinkLayer::sendFrame(CemiFrame& frame) bool TpUartDataLinkLayer::sendFrame(CemiFrame& frame)
@ -559,13 +560,15 @@ bool TpUartDataLinkLayer::sendSingleFrameByte()
_platform.writeUart(cmd, 2); _platform.writeUart(cmd, 2);
_TxByteCnt++; _TxByteCnt++;
return true;
} }
else
// Check for last byte send
if (_TxByteCnt >= _sendBufferLength)
{ {
_TxByteCnt = 0; _TxByteCnt = 0;
return false; return false;
} }
return true;
} }
void TpUartDataLinkLayer::addFrameTxQueue(CemiFrame& frame) void TpUartDataLinkLayer::addFrameTxQueue(CemiFrame& frame)