diff --git a/SerialPort.cpp b/SerialPort.cpp index faf72a4..3092ef6 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -394,26 +394,22 @@ void CSerialPort::process() while (availableInt(1U)) { uint8_t c = readInt(1U); - if (m_ptr == 0U && c == MMDVM_FRAME_START) { - // Handle the frame start correctly - m_buffer[0U] = c; - m_ptr = 1U; - m_len = 0U; - } else if (m_ptr > 0U) { + if (m_ptr == 0U) { + if (c == MMDVM_FRAME_START) { + // Handle the frame start correctly + m_buffer[0U] = c; + m_ptr = 1U; + m_len = 0U; + } + } else if (m_ptr == 1U) { + // Handle the frame length + m_len = m_buffer[m_ptr] = c; + m_ptr = 2U; + } else { // Any other bytes are added to the buffer m_buffer[m_ptr] = c; m_ptr++; - // Once we have enough bytes, calculate the expected length - if (m_ptr == 2U) - m_len = m_buffer[1U]; - - if (m_ptr == 3U && m_len > 250U) { - sendNAK(3U); - m_ptr = 0U; - m_len = 0U; - } - // The full packet has been received, process it if (m_ptr == m_len) { uint8_t err = 2U; diff --git a/SerialPort.h b/SerialPort.h index 527ff64..455dfdb 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -57,7 +57,7 @@ public: void writeAssert(bool cond, const char* text, const char* file, long line); private: - uint8_t m_buffer[250U]; + uint8_t m_buffer[256U]; uint8_t m_ptr; uint8_t m_len;