mirror of
https://github.com/g4klx/MMDVM.git
synced 2026-10-11 14:24:11 +02:00
Improve the serial port parsing.
This commit is contained in:
+12
-16
@@ -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;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user