diff --git a/mtb-daemon.pro b/mtb-daemon.pro index ed1f58c..ddd27f0 100644 --- a/mtb-daemon.pro +++ b/mtb-daemon.pro @@ -44,7 +44,7 @@ QT -= gui QT += core serialport network VERSION_MAJOR = 0 -VERSION_MINOR = 3 +VERSION_MINOR = 4 DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR" "VERSION_MINOR=$$VERSION_MINOR" diff --git a/src/mtbusb/mtbusb-receive.cpp b/src/mtbusb/mtbusb-receive.cpp index b923ab7..b2346cb 100644 --- a/src/mtbusb/mtbusb-receive.cpp +++ b/src/mtbusb/mtbusb-receive.cpp @@ -126,6 +126,8 @@ void MtbUsb::parseMtbUsbMessage(uint8_t command_code, const std::vector for (auto it = m_hist.begin(); it != m_hist.end(); ++it) { if (it->cmd.get() == cmd) { m_hist.erase(it); + if (!m_out.empty()) + this->sendNextOut(); return; } } @@ -194,6 +196,8 @@ void MtbUsb::parseMtbBusMessage(uint8_t module, uint8_t attempts, uint8_t comman for (auto it = m_hist.begin(); it != m_hist.end(); ++it) { if (it->cmd.get() == m_hist[i].cmd.get()) { m_hist.erase(it); + if (!m_out.empty()) + this->sendNextOut(); return; } } diff --git a/src/mtbusb/mtbusb-send.cpp b/src/mtbusb/mtbusb-send.cpp index b9b224e..38a1af8 100644 --- a/src/mtbusb/mtbusb-send.cpp +++ b/src/mtbusb/mtbusb-send.cpp @@ -42,33 +42,11 @@ void MtbUsb::send(std::unique_ptr &cmd, bool bypass_m_out_emptiness) log("ENQUEUE: " + cmd->msg(), LogLevel::Debug); m_out.emplace_back(std::move(cmd)); } else { - if (m_lastSent.addMSecs(_OUT_TIMER_INTERVAL) > QDateTime::currentDateTime()) { - // Last command sent too early, still space in hist buffer -> - // queue & activate timer for next send - log("ENQUEUE: " + cmd->msg(), LogLevel::Debug); - m_out.emplace_back(std::move(cmd)); - if (!m_outTimer.isActive()) - m_outTimer.start(); - } else { - write(std::move(cmd)); - } + write(std::move(cmd)); } } -void MtbUsb::outTimerTick() { - if (m_out.empty()) - m_outTimer.stop(); - else - sendNextOut(); -} - void MtbUsb::sendNextOut() { - if (m_lastSent.addMSecs(_OUT_TIMER_INTERVAL) > QDateTime::currentDateTime()) { - if (!m_outTimer.isActive()) - m_outTimer.start(); - return; - } - std::unique_ptr out = std::move(m_out.front()); log("DEQUEUE: " + out->msg(), LogLevel::Debug); m_out.pop_front(); diff --git a/src/mtbusb/mtbusb.cpp b/src/mtbusb/mtbusb.cpp index 5e080ae..0d0658f 100644 --- a/src/mtbusb/mtbusb.cpp +++ b/src/mtbusb/mtbusb.cpp @@ -13,8 +13,6 @@ MtbUsb::MtbUsb(QObject *parent) : QObject(parent) { QObject::connect(&m_serialPort, SIGNAL(aboutToClose()), this, SLOT(spAboutToClose())); QObject::connect(&m_histTimer, SIGNAL(timeout()), this, SLOT(histTimerTick())); - m_outTimer.setInterval(_OUT_TIMER_INTERVAL); - QObject::connect(&m_outTimer, SIGNAL(timeout()), this, SLOT(outTimerTick())); QObject::connect(&m_pingTimer, SIGNAL(timeout()), this, SLOT(pingTimerTick())); m_pingTimer.setInterval(_PING_SEND_PERIOD_MS); @@ -27,7 +25,6 @@ void MtbUsb::log(const QString &message, const LogLevel loglevel) { void MtbUsb::spAboutToClose() { m_histTimer.stop(); - m_outTimer.stop(); m_pingTimer.stop(); while (!m_hist.empty()) { m_hist.front().cmd->callError(CmdError::SerialPortClosed); diff --git a/src/mtbusb/mtbusb.h b/src/mtbusb/mtbusb.h index 70e4183..ec6055e 100644 --- a/src/mtbusb/mtbusb.h +++ b/src/mtbusb/mtbusb.h @@ -23,7 +23,6 @@ constexpr size_t _HIST_TIMEOUT = 300; // ms constexpr size_t _HIST_SEND_MAX = 3; constexpr size_t _BUF_IN_TIMEOUT = 50; // ms constexpr size_t _MAX_HIST_BUF_COUNT = 3; -constexpr size_t _OUT_TIMER_INTERVAL = 20; // 20 ms constexpr size_t _PING_SEND_PERIOD_MS = 5000; struct EOpenError : public MtbUsbError { @@ -119,7 +118,6 @@ private slots: void spHandleError(QSerialPort::SerialPortError); void spAboutToClose(); void histTimerTick(); - void outTimerTick(); void pingTimerTick(); signals: @@ -135,7 +133,6 @@ private slots: QSerialPort m_serialPort; QByteArray m_readData; QTimer m_histTimer; - QTimer m_outTimer; QTimer m_pingTimer; std::deque m_hist; std::deque> m_out;