mirror of https://github.com/g4klx/MMDVM.git
Improve the serial port parsing.
This commit is contained in:
parent
81ec23eccc
commit
48c83b19c6
|
@ -394,26 +394,22 @@ void CSerialPort::process()
|
||||||
while (availableInt(1U)) {
|
while (availableInt(1U)) {
|
||||||
uint8_t c = readInt(1U);
|
uint8_t c = readInt(1U);
|
||||||
|
|
||||||
if (m_ptr == 0U && c == MMDVM_FRAME_START) {
|
if (m_ptr == 0U) {
|
||||||
|
if (c == MMDVM_FRAME_START) {
|
||||||
// Handle the frame start correctly
|
// Handle the frame start correctly
|
||||||
m_buffer[0U] = c;
|
m_buffer[0U] = c;
|
||||||
m_ptr = 1U;
|
m_ptr = 1U;
|
||||||
m_len = 0U;
|
m_len = 0U;
|
||||||
} else if (m_ptr > 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
|
// Any other bytes are added to the buffer
|
||||||
m_buffer[m_ptr] = c;
|
m_buffer[m_ptr] = c;
|
||||||
m_ptr++;
|
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
|
// The full packet has been received, process it
|
||||||
if (m_ptr == m_len) {
|
if (m_ptr == m_len) {
|
||||||
uint8_t err = 2U;
|
uint8_t err = 2U;
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
void writeAssert(bool cond, const char* text, const char* file, long line);
|
void writeAssert(bool cond, const char* text, const char* file, long line);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t m_buffer[250U];
|
uint8_t m_buffer[256U];
|
||||||
uint8_t m_ptr;
|
uint8_t m_ptr;
|
||||||
uint8_t m_len;
|
uint8_t m_len;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue