Skip to content

Commit

Permalink
reenable sendframe handling
Browse files Browse the repository at this point in the history
reenable rxProcess in loop
fixes a memory leak
  • Loading branch information
traxanos committed Apr 4, 2024
1 parent 7b910eb commit e65afeb
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/knx/tpuart_data_link_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,11 @@ void TpUartDataLinkLayer::setFrameRepetition(uint8_t nack, uint8_t busy)

bool TpUartDataLinkLayer::sendFrame(CemiFrame &cemiFrame)
{
// if (!_connected)
// {
// dataConReceived(cemiFrame, false);
// return false;
// }
if (!_connected || _monitoring)
{
dataConReceived(cemiFrame, false);
return false;
}

TpFrame *tpFrame = new TpFrame(cemiFrame);
// printHex(" TP>: ", tpFrame->data(), tpFrame->size());
Expand Down Expand Up @@ -686,9 +686,14 @@ bool TpUartDataLinkLayer::reset()
_rxInvalidFrameCounter = 0;
_rxUnkownControlCounter = 0;
if (_txFrame != nullptr)
_txFrame->reset();
{
_txFrame = nullptr;
delete _txFrame;
}
if (_rxFrame != nullptr)
{
_rxFrame->reset();
}
_rxState = RX_IDLE;
_txState = TX_IDLE;
_connected = false;
Expand Down Expand Up @@ -792,7 +797,6 @@ void TpUartDataLinkLayer::processTxQueue()
if (_rxState != RX_IDLE)
return;

//
if (_txState != TX_IDLE)
return;

Expand All @@ -806,16 +810,23 @@ void TpUartDataLinkLayer::processTxQueue()
_txFrameQueue.back = nullptr;
}

// free old frame
if (_txFrame != nullptr)
delete _txFrame;

// use frame from queue and delete queue entry
_txFrame = entry->frame;
delete entry;

_txState = TX_FRAME;
_txLastTime = millis();

#ifdef DEBUG_TP_FRAMES
print("Outbound: ");
printFrame(_txFrame);
println();
#endif
_txState = TX_FRAME;
_txLastTime = millis();

delete entry;
processTxFrameBytes();
}
}
Expand Down Expand Up @@ -875,7 +886,7 @@ void TpUartDataLinkLayer::loop()
_tpState = 0;
}

// processRx();
processRx();
#ifdef USE_TP_RX_QUEUE
processRxQueue();
#endif
Expand Down

0 comments on commit e65afeb

Please sign in to comment.