Skip to content

Commit

Permalink
Remove out data time threshold limit.
Browse files Browse the repository at this point in the history
Data could be sent to MTB-USB directly following one another, withnout
any delay. Buffer overflow in MTB-USB is still unsured via limit
on size of hist buffer (no more than 3 commands coyld be pending in
MTB-USB).
  • Loading branch information
horacekj committed Aug 4, 2021
1 parent 181730e commit 0248b25
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 30 deletions.
2 changes: 1 addition & 1 deletion mtb-daemon.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions src/mtbusb/mtbusb-receive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ void MtbUsb::parseMtbUsbMessage(uint8_t command_code, const std::vector<uint8_t>
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;
}
}
Expand Down Expand Up @@ -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;
}
}
Expand Down
24 changes: 1 addition & 23 deletions src/mtbusb/mtbusb-send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,11 @@ void MtbUsb::send(std::unique_ptr<const Cmd> &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<const Cmd> out = std::move(m_out.front());
log("DEQUEUE: " + out->msg(), LogLevel::Debug);
m_out.pop_front();
Expand Down
3 changes: 0 additions & 3 deletions src/mtbusb/mtbusb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/mtbusb/mtbusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -119,7 +118,6 @@ private slots:
void spHandleError(QSerialPort::SerialPortError);
void spAboutToClose();
void histTimerTick();
void outTimerTick();
void pingTimerTick();

signals:
Expand All @@ -135,7 +133,6 @@ private slots:
QSerialPort m_serialPort;
QByteArray m_readData;
QTimer m_histTimer;
QTimer m_outTimer;
QTimer m_pingTimer;
std::deque<HistoryItem> m_hist;
std::deque<std::unique_ptr<const Cmd>> m_out;
Expand Down

0 comments on commit 0248b25

Please sign in to comment.