Removed unneded TX_WAIT_ECHO state; fixed echo detection (#188)

This commit is contained in:
mptei 2022-03-01 17:30:54 +01:00 committed by GitHub
parent 4f17ed4b5d
commit 145c354110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,7 +85,6 @@
enum { enum {
TX_IDLE, TX_IDLE,
TX_FRAME, TX_FRAME,
TX_WAIT_ECHO,
TX_WAIT_CONN TX_WAIT_CONN
}; };
@ -138,7 +137,6 @@ void TpUartDataLinkLayer::loop()
// Loop once and repeat as long we have rx data available // Loop once and repeat as long we have rx data available
do { do {
// Signals to communicate from rx part with the tx part // 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 uint8_t dataConnMsg = 0; // The DATA_CONN message just seen or 0
#ifdef KNX_WAIT_FOR_ADDR #ifdef KNX_WAIT_FOR_ADDR
@ -296,22 +294,14 @@ void TpUartDataLinkLayer::loop()
if (_RxByteCnt == 7) if (_RxByteCnt == 7)
{ {
//Destination Address + payload available //Destination Address + payload available
//check if echo //check if echo; ignore repeat bit of control byte
if (_sendBuffer != nullptr && (!((buffer[0] ^ _sendBuffer[0]) & ~0x20) && !memcmp(buffer + _convert + 1, _sendBuffer + 1, 5))) _isEcho = (_sendBuffer != nullptr && (!((buffer[0] ^ _sendBuffer[0]) & ~0x20) && !memcmp(buffer + _convert + 1, _sendBuffer + 1, 5)));
{ //ignore repeated bit of control byte
_isEcho = true;
}
else
{
_isEcho = false;
}
//convert into Extended.ind //convert into Extended.ind
if (_convert) if (_convert)
{ {
uint8_t payloadLength = buffer[6] & 0x0F;
buffer[1] = buffer[6] & 0xF0; buffer[1] = buffer[6] & 0xF0;
buffer[6] = payloadLength; buffer[6] &= 0x0F;
} }
if (!_isEcho) if (!_isEcho)
@ -358,22 +348,10 @@ void TpUartDataLinkLayer::loop()
if (_RxByteCnt == buffer[6] + 7 + 2) if (_RxByteCnt == buffer[6] + 7 + 2)
{ {
//complete Frame received, payloadLength+1 for TCPI +1 for CRC //complete Frame received, payloadLength+1 for TCPI +1 for CRC
//check if crc is correct
if (rxByte == (uint8_t)(~_xorSum)) if (rxByte == (uint8_t)(~_xorSum))
{ {
//check if crc is correct if (!_isEcho)
if (_isEcho && _sendBuffer != NULL)
{
//check if it is realy an echo, rx_crc = tx_crc
if (rxByte == _sendBuffer[_sendBufferLength - 1])
_isEcho = true;
else
_isEcho = false;
}
if (_isEcho)
{
isEchoComplete = true;
}
else
{ {
_receiveBuffer[0] = 0x29; _receiveBuffer[0] = 0x29;
_receiveBuffer[1] = 0; _receiveBuffer[1] = 0;
@ -428,8 +406,8 @@ void TpUartDataLinkLayer::loop()
} while (_rxState == RX_L_ADDR && (stayInRx || _platform.uartAvailable())); } while (_rxState == RX_L_ADDR && (stayInRx || _platform.uartAvailable()));
// 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) {
println("got unexpected L_DATA_CON"); println("unexpected L_DATA_CON");
} }
switch (_txState) switch (_txState)
@ -450,9 +428,9 @@ void TpUartDataLinkLayer::loop()
if (sendSingleFrameByte() == false) if (sendSingleFrameByte() == false)
{ {
_waitConfirmStartTime = millis(); _waitConfirmStartTime = millis();
_txState = TX_WAIT_ECHO; _txState = TX_WAIT_CONN;
#ifdef DBG_TRACE #ifdef DBG_TRACE
println("TX_WAIT_ECHO"); println("TX_WAIT_CONN");
#endif #endif
} }
else else
@ -461,22 +439,10 @@ void TpUartDataLinkLayer::loop()
} }
} }
break; break;
case TX_WAIT_ECHO:
case TX_WAIT_CONN: case TX_WAIT_CONN:
if (isEchoComplete) if (dataConnMsg)
{ {
_txState = TX_WAIT_CONN; dataConBytesReceived(_receiveBuffer, _RxByteCnt + 2, (dataConnMsg & SUCCESS));
#ifdef DBG_TRACE
println("TX_WAIT_CONN");
#endif
}
else if (dataConnMsg)
{
bool waitEcho = (_txState == TX_WAIT_ECHO);
if (waitEcho) {
println("L_DATA_CON without echo");
}
dataConBytesReceived(_receiveBuffer, _RxByteCnt + 2, !waitEcho && ((dataConnMsg & SUCCESS) > 0));
delete[] _sendBuffer; delete[] _sendBuffer;
_sendBuffer = 0; _sendBuffer = 0;
_sendBufferLength = 0; _sendBufferLength = 0;