fixes modulo in rx queue

This commit is contained in:
Marco Scholl 2024-08-03 21:27:00 +02:00
parent e69f63611a
commit 84a0ce3c22
No known key found for this signature in database

View File

@ -1204,19 +1204,19 @@ void TpUartDataLinkLayer::processRxQueue()
void TpUartDataLinkLayer::pushByteToRxQueue(uint8_t byte)
{
_rxBuffer[_rxBufferFront] = byte;
_rxBufferFront = (_rxBufferFront + 1) % MAX_RX_QUEUE_BYTES;
_rxBufferFront = (_rxBufferFront + 1) % (MAX_RX_QUEUE_BYTES);
}
uint8_t TpUartDataLinkLayer::pullByteFromRxQueue()
{
uint8_t byte = _rxBuffer[_rxBufferRear];
_rxBufferRear = (_rxBufferRear + 1) % MAX_RX_QUEUE_BYTES;
_rxBufferRear = (_rxBufferRear + 1) % (MAX_RX_QUEUE_BYTES);
return byte;
}
uint16_t TpUartDataLinkLayer::availableInRxQueue()
{
return ((_rxBufferFront == _rxBufferRear) ? MAX_RX_QUEUE_BYTES : (((MAX_RX_QUEUE_BYTES - _rxBufferFront) + _rxBufferRear) % MAX_RX_QUEUE_BYTES)) - 1;
return ((_rxBufferFront == _rxBufferRear) ? (MAX_RX_QUEUE_BYTES) : ((((MAX_RX_QUEUE_BYTES) - _rxBufferFront) + _rxBufferRear) % (MAX_RX_QUEUE_BYTES))) - 1;
}
#endif