From 8f317fd332992e410a399af47d6244f933edce42 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Sun, 20 Aug 2017 11:19:58 -0300 Subject: [PATCH] Adding watchdog to host serial port --- IO.cpp | 5 +++++ IO.h | 1 + SerialPort.cpp | 43 ++++++++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/IO.cpp b/IO.cpp index f711172..fb9a325 100644 --- a/IO.cpp +++ b/IO.cpp @@ -386,6 +386,11 @@ void CIO::resetWatchdog() m_watchdog = 0U; } +uint32_t CIO::getWatchdog() +{ + return m_watchdog; +} + bool CIO::hasLockout() const { return m_lockout; diff --git a/IO.h b/IO.h index 5421881..6e243c8 100644 --- a/IO.h +++ b/IO.h @@ -52,6 +52,7 @@ public: bool hasLockout() const; void resetWatchdog(); + uint32_t getWatchdog(); private: bool m_started; diff --git a/SerialPort.cpp b/SerialPort.cpp index 3ee2f21..daf0ee9 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -421,6 +421,10 @@ void CSerialPort::process() m_ptr = 1U; m_len = 0U; } + else { + m_ptr = 0U; + m_len = 0U; + } } else if (m_ptr == 1U) { // Handle the frame length m_len = m_buffer[m_ptr] = c; @@ -645,9 +649,9 @@ void CSerialPort::process() #if defined(SERIAL_REPEATER) case MMDVM_SERIAL: { - for (uint8_t i = 3U; i < m_len; i++) - m_repeat.put(m_buffer[i]); - } + for (uint8_t i = 3U; i < m_len; i++) + m_repeat.put(m_buffer[i]); + } break; #endif @@ -663,23 +667,28 @@ void CSerialPort::process() } } + if (io.getWatchdog() >= 48000U) { + m_ptr = 0U; + m_len = 0U; + } + #if defined(SERIAL_REPEATER) - // Write any outgoing serial data - uint16_t space = m_repeat.getData(); - if (space > 0U) { - int avail = availableForWriteInt(3U); - if (avail < space) - space = avail; + // Write any outgoing serial data + uint16_t space = m_repeat.getData(); + if (space > 0U) { + int avail = availableForWriteInt(3U); + if (avail < space) + space = avail; - for (uint16_t i = 0U; i < space; i++) { - uint8_t c = m_repeat.get(); - writeInt(3U, &c, 1U); - } - } + for (uint16_t i = 0U; i < space; i++) { + uint8_t c = m_repeat.get(); + writeInt(3U, &c, 1U); + } + } - // Read any incoming serial data - while (availableInt(3U)) - readInt(3U); + // Read any incoming serial data + while (availableInt(3U)) + readInt(3U); #endif }