From c509f11c2a96abea9ea2a0a2b52f003a3e48b7a6 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Tue, 10 May 2016 18:11:31 +0100 Subject: [PATCH] Stop TX buffer overflows. --- CWIdTX.cpp | 2 +- DMRTX.cpp | 2 +- DStarTX.cpp | 2 +- Globals.h | 3 +++ IO.cpp | 7 ++----- YSFTX.cpp | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CWIdTX.cpp b/CWIdTX.cpp index c75196f..d03af8d 100644 --- a/CWIdTX.cpp +++ b/CWIdTX.cpp @@ -101,7 +101,7 @@ void CCWIdTX::process() uint16_t space = io.getSpace(); - while (space > CYCLE_LENGTH && space < 1000U) { + while (space > CYCLE_LENGTH && space <= TX_RINGBUFFER_SIZE) { bool b = READ_BIT1(m_poBuffer, m_poPtr); if (b) io.write(TONE, CYCLE_LENGTH); diff --git a/DMRTX.cpp b/DMRTX.cpp index dd918f1..a78a966 100644 --- a/DMRTX.cpp +++ b/DMRTX.cpp @@ -113,7 +113,7 @@ void CDMRTX::process() if (m_poLen > 0U) { uint16_t space = io.getSpace(); - while (space > (4U * DMR_RADIO_SYMBOL_LENGTH) && space < 1000U) { + while (space > (4U * DMR_RADIO_SYMBOL_LENGTH) && space <= TX_RINGBUFFER_SIZE) { uint8_t c = m_poBuffer[m_poPtr]; uint8_t m = m_markBuffer[m_poPtr]; m_poPtr++; diff --git a/DStarTX.cpp b/DStarTX.cpp index 7b4bf66..c719e97 100644 --- a/DStarTX.cpp +++ b/DStarTX.cpp @@ -266,7 +266,7 @@ void CDStarTX::process() if (m_poLen > 0U) { uint16_t space = io.getSpace(); - while (space > (8U * DSTAR_RADIO_BIT_LENGTH) && space < 1000U) { + while (space > (8U * DSTAR_RADIO_BIT_LENGTH) && space <= TX_RINGBUFFER_SIZE) { uint8_t c = m_poBuffer[m_poPtr++]; writeByte(c); diff --git a/Globals.h b/Globals.h index 9199e60..b4d2dbb 100644 --- a/Globals.h +++ b/Globals.h @@ -64,6 +64,9 @@ const uint8_t MARK_NONE = 0x00U; const uint16_t RX_BLOCK_SIZE = 2U; +const uint16_t TX_RINGBUFFER_SIZE = 500U; +const uint16_t RX_RINGBUFFER_SIZE = 600U; + extern MMDVM_STATE m_modemState; extern bool m_dstarEnable; diff --git a/IO.cpp b/IO.cpp index 1c9bac7..2eb6d40 100644 --- a/IO.cpp +++ b/IO.cpp @@ -36,9 +36,6 @@ const uint16_t GMSK_FILTER_LEN = 12U; const uint16_t DC_OFFSET = 2048U; -const uint16_t TX_BUFFER_SIZE = 501U; -const uint16_t RX_BUFFER_SIZE = 601U; - #if defined(__SAM3X8E__) // An Arduino Due #if defined(ARDUINO_DUE_PAPA) @@ -105,8 +102,8 @@ m_pinDAC(PIN_DAC), m_ticker(), #endif m_started(false), -m_rxBuffer(RX_BUFFER_SIZE), -m_txBuffer(TX_BUFFER_SIZE), +m_rxBuffer(RX_RINGBUFFER_SIZE), +m_txBuffer(TX_RINGBUFFER_SIZE), m_C4FSKFilter(), m_GMSKFilter(), m_C4FSKState(), diff --git a/YSFTX.cpp b/YSFTX.cpp index 7fc1561..2ff596f 100644 --- a/YSFTX.cpp +++ b/YSFTX.cpp @@ -78,7 +78,7 @@ void CYSFTX::process() if (m_poLen > 0U) { uint16_t space = io.getSpace(); - while (space > (4U * YSF_RADIO_SYMBOL_LENGTH) && space < 1000U) { + while (space > (4U * YSF_RADIO_SYMBOL_LENGTH) && space <= TX_RINGBUFFER_SIZE) { uint8_t c = m_poBuffer[m_poPtr++]; writeByte(c);