diff --git a/src/client/runtime/client_devicerunnable.cpp b/src/client/runtime/client_devicerunnable.cpp index ba46f01..ab9b07c 100644 --- a/src/client/runtime/client_devicerunnable.cpp +++ b/src/client/runtime/client_devicerunnable.cpp @@ -227,7 +227,7 @@ bool mbClientDeviceRunnable::hasReadMessageOnDuty() for (Messages_t::Iterator it = m_readMessages.begin(); it != m_readMessages.end(); ++it) { mbClientRunMessagePtr m = *it; - if ((tm - m->timestamp()) >= m->period()) + if ((tm - m->beginTimestamp()) >= m->period()) { m_readMessages.erase(it); // remove it from queue ... m_readMessages.enqueue(m); // and push it to back of queue diff --git a/src/client/runtime/client_runmessage.cpp b/src/client/runtime/client_runmessage.cpp index e4bc913..9eb4990 100644 --- a/src/client/runtime/client_runmessage.cpp +++ b/src/client/runtime/client_runmessage.cpp @@ -37,6 +37,7 @@ mbClientRunMessage::mbClientRunMessage(mbClientRunItem *item, uint16_t maxCount, m_writeCount = 0; m_period = item->period(); m_status = Modbus::Status_Uncertain; + m_beginTimestamp = 0; m_timestamp = 0; addItemPrivate(item); m_deleteItems = false; @@ -58,6 +59,7 @@ mbClientRunMessage::mbClientRunMessage(uint16_t offset, uint16_t count, uint16_t m_period = 0; m_maxCount = maxCount; m_status = Modbus::Status_Uncertain; + m_beginTimestamp = 0; m_timestamp = 0; m_deleteItems = false; m_isCompleted = false; @@ -117,6 +119,11 @@ Modbus::StatusCode mbClientRunMessage::status() const return m_status; } +mb::Timestamp_t mbClientRunMessage::beginTimestamp() const +{ + return m_beginTimestamp; +} + mb::Timestamp_t mbClientRunMessage::timestamp() const { return m_timestamp; @@ -174,7 +181,7 @@ Modbus::StatusCode mbClientRunMessage::setData(uint16_t /*innerOffset*/, uint16_ void mbClientRunMessage::prepareToSend() { - // base implementation does nothing + m_beginTimestamp = mb::currentTimestamp(); } void mbClientRunMessage::setComplete(Modbus::StatusCode status, mb::Timestamp_t timestamp) @@ -280,6 +287,7 @@ void mbClientRunMessageRead::setComplete(Modbus::StatusCode status, mb::Timestam void mbClientRunMessageWrite::prepareToSend() { + mbClientRunMessage::prepareToSend(); for (Items_t::ConstIterator it = m_items.cbegin(); it != m_items.cend(); ++it) { mbClientRunItem *pItem = static_cast(*it); diff --git a/src/client/runtime/client_runmessage.h b/src/client/runtime/client_runmessage.h index 994850c..b3fd934 100644 --- a/src/client/runtime/client_runmessage.h +++ b/src/client/runtime/client_runmessage.h @@ -57,6 +57,7 @@ class mbClientRunMessage : public QObject int innerBufferBitSize() const; int innerBufferRegSize() const; Modbus::StatusCode status() const; + mb::Timestamp_t beginTimestamp() const; mb::Timestamp_t timestamp() const; public: @@ -111,6 +112,7 @@ class mbClientRunMessage : public QObject uint32_t m_period; uint16_t m_maxCount; Modbus::StatusCode m_status; + mb::Timestamp_t m_beginTimestamp; mb::Timestamp_t m_timestamp; uint8_t m_buff[MB_MAX_BYTES]; diff --git a/src/core/sdk/mbcore.cpp b/src/core/sdk/mbcore.cpp index 52d6647..e80670a 100644 --- a/src/core/sdk/mbcore.cpp +++ b/src/core/sdk/mbcore.cpp @@ -304,7 +304,8 @@ QString toString(Modbus::StatusCode status) case Modbus::Status_BadSerialOpen : return QStringLiteral("BadSerialOpen"); case Modbus::Status_BadSerialWrite : return QStringLiteral("BadSerialWrite"); case Modbus::Status_BadSerialRead : return QStringLiteral("BadSerialRead"); - case Modbus::Status_BadSerialReadTimeout : return QStringLiteral("Status_BadSerialReadTimeout"); + case Modbus::Status_BadSerialReadTimeout : return QStringLiteral("BadSerialReadTimeout"); + case Modbus::Status_BadSerialWriteTimeout : return QStringLiteral("BadSerialWriteTimeout"); case Modbus::Status_BadAscMissColon : return QStringLiteral("BadAscMissColon"); case Modbus::Status_BadAscMissCrLf : return QStringLiteral("BadAscMissCrLf"); case Modbus::Status_BadAscChar : return QStringLiteral("BadAscChar"); diff --git a/src/server/gui/dialogs/server_dialogaction.cpp b/src/server/gui/dialogs/server_dialogaction.cpp index 974c482..865188c 100644 --- a/src/server/gui/dialogs/server_dialogaction.cpp +++ b/src/server/gui/dialogs/server_dialogaction.cpp @@ -101,6 +101,8 @@ mbServerDialogAction::mbServerDialogAction(QWidget *parent) : // Action Increment ui->lnActionIncrement->setText(QString::number(d.incrementValue)); + ui->lnActionIncrementMin->setText(QString::number(d.incrementMin)); + ui->lnActionIncrementMax->setText(QString::number(d.incrementMax)); // Action Sine ui->lnActionSinePeriod->setText(QString::number(d.sinePeriod)); @@ -174,6 +176,8 @@ MBSETTINGS mbServerDialogAction::cachedSettings() const m[prefix+vs.dataType ] = ui->cmbDataType->currentText(); m[prefix+vs.period ] = ui->spPeriod->value(); m[prefix+vs.incrementValue ] = ui->lnActionIncrement->text(); + m[prefix+vs.incrementMin ] = ui->lnActionIncrementMin->text(); + m[prefix+vs.incrementMax ] = ui->lnActionIncrementMax->text(); m[prefix+vs.sinePeriod ] = ui->lnActionSinePeriod->text(); m[prefix+vs.sinePhaseShift ] = ui->lnActionSinePhaseShift->text(); m[prefix+vs.sineAmplitude ] = ui->lnActionSineAmplitude->text(); @@ -220,6 +224,8 @@ void mbServerDialogAction::setCachedSettings(const MBSETTINGS &m) it = m.find(prefix+vs.dataType ); if (it != end) ui->cmbDataType->setCurrentText(it.value().toString()); it = m.find(prefix+vs.period ); if (it != end) ui->spPeriod ->setValue (it.value().toInt() ); it = m.find(prefix+vs.incrementValue ); if (it != end) ui->lnActionIncrement->setText(it.value().toString()); + it = m.find(prefix+vs.incrementMin ); if (it != end) ui->lnActionIncrementMin->setText(it.value().toString()); + it = m.find(prefix+vs.incrementMax ); if (it != end) ui->lnActionIncrementMax->setText(it.value().toString()); it = m.find(prefix+vs.sinePeriod ); if (it != end) ui->lnActionSinePeriod->setText(it.value().toString()); it = m.find(prefix+vs.sinePhaseShift ); if (it != end) ui->lnActionSinePhaseShift->setText(it.value().toString()); it = m.find(prefix+vs.sineAmplitude ); if (it != end) ui->lnActionSineAmplitude->setText(it.value().toString()); @@ -339,6 +345,8 @@ void mbServerDialogAction::fillFormActionType(const MBSETTINGS &settings) { case mbServerAction::Increment: ui->lnActionIncrement->setText(settings.value(sItem.incrementValue).toString()); + ui->lnActionIncrementMin->setText(settings.value(sItem.incrementMin).toString()); + ui->lnActionIncrementMax->setText(settings.value(sItem.incrementMax).toString()); break; case mbServerAction::Sine: it = settings.find(sItem.sinePeriod ); if (it != end) ui->lnActionSinePeriod ->setText(it.value().toString()); @@ -417,6 +425,8 @@ void mbServerDialogAction::fillDataActionType(MBSETTINGS &settings) { case mbServerAction::Increment: settings[sItem.incrementValue] = ui->lnActionIncrement->text(); + settings[sItem.incrementMin ] = ui->lnActionIncrementMin->text(); + settings[sItem.incrementMax ] = ui->lnActionIncrementMax->text(); break; case mbServerAction::Sine: settings[sItem.sinePeriod ] = ui->lnActionSinePeriod->text(); diff --git a/src/server/gui/dialogs/server_dialogaction.ui b/src/server/gui/dialogs/server_dialogaction.ui index d6fc8d1..5171b3b 100644 --- a/src/server/gui/dialogs/server_dialogaction.ui +++ b/src/server/gui/dialogs/server_dialogaction.ui @@ -7,7 +7,7 @@ 0 0 242 - 450 + 454 @@ -176,6 +176,26 @@ + + + + Minimum + + + + + + + + + + Maximum + + + + + + diff --git a/src/server/project/server_action.cpp b/src/server/project/server_action.cpp index b7877a3..d5e4245 100644 --- a/src/server/project/server_action.cpp +++ b/src/server/project/server_action.cpp @@ -33,6 +33,8 @@ mbServerAction::Strings::Strings() : registerOrder (QStringLiteral("registerOrder")), extended (QStringLiteral("extended")), incrementValue (QStringLiteral("incrementValue")), + incrementMin (QStringLiteral("min")), + incrementMax (QStringLiteral("max")), sinePeriod (QStringLiteral("sinePeriod")), sinePhaseShift (QStringLiteral("sinePhaseShift")), sineAmplitude (QStringLiteral("sineAmplitude")), @@ -59,6 +61,8 @@ mbServerAction::Defaults::Defaults() : byteOrder (mb::LessSignifiedFirst), registerOrder (mb::LessSignifiedFirst), incrementValue (1), + incrementMin (0), + incrementMax (65535), sinePeriod (10000), sinePhaseShift (0), sineAmplitude (100), @@ -349,6 +353,8 @@ MBSETTINGS mbServerAction::ActionIncrement::extendedSettings() const const Strings &s = Strings::instance(); MBSETTINGS p; p[s.incrementValue] = value; + p[s.incrementMin ] = min ; + p[s.incrementMax ] = max ; return p; } @@ -357,15 +363,26 @@ void mbServerAction::ActionIncrement::setExtendedSettings(const MBSETTINGS &sett const Strings &s = Strings::instance(); auto end = settings.end(); + auto it = settings.find(s.incrementValue); if (it != end) value = it.value(); + + it = settings.find(s.incrementMin); + if (it != end) + min = it.value(); + + it = settings.find(s.incrementMax); + if (it != end) + max = it.value(); } QString mbServerAction::ActionIncrement::extendedSettingsStr() const { const Strings &s = Strings::instance(); - return QString("%1=%2").arg(s.incrementValue, value.toString()); + return QString("%1=%2;%3=%4;%5=%6").arg(s.incrementValue, value.toString(), + s.incrementMin, min.toString(), + s.incrementMax, max.toString()); } // ----------------------------------------------------------------------------------------------------------------------- diff --git a/src/server/project/server_action.h b/src/server/project/server_action.h index c3863b7..ad2a57b 100644 --- a/src/server/project/server_action.h +++ b/src/server/project/server_action.h @@ -53,6 +53,8 @@ class mbServerAction : public QObject const QString registerOrder ; const QString extended ; const QString incrementValue ; + const QString incrementMin ; + const QString incrementMax ; const QString sinePeriod ; const QString sinePhaseShift ; const QString sineAmplitude ; @@ -76,6 +78,8 @@ class mbServerAction : public QObject const mb::DataOrder byteOrder ; const mb::DataOrder registerOrder ; const int incrementValue ; + const int incrementMin ; + const int incrementMax ; const int sinePeriod ; const int sinePhaseShift ; const int sineAmplitude ; @@ -161,6 +165,8 @@ class mbServerAction : public QObject struct ActionIncrement : public ActionExtended { QVariant value; + QVariant min; + QVariant max; MBSETTINGS extendedSettings() const override; void setExtendedSettings(const MBSETTINGS &settings) override; QString extendedSettingsStr() const override; @@ -168,6 +174,8 @@ class mbServerAction : public QObject { Defaults d = Defaults::instance(); value = d.incrementValue; + min = d.incrementMin; + max = d.incrementMax; } }; diff --git a/src/server/runtime/server_runaction.h b/src/server/runtime/server_runaction.h index 08671cd..bc7dcbd 100644 --- a/src/server/runtime/server_runaction.h +++ b/src/server/runtime/server_runaction.h @@ -76,6 +76,8 @@ class mbServerRunActionIncrement : public mbServerRunActionT mbServerRunActionIncrement(const MBSETTINGS &settings) : mbServerRunActionT(settings) { m_increment = settings.value(mbServerAction::Strings::instance().incrementValue).value(); + m_min = settings.value(mbServerAction::Strings::instance().incrementMin).value(); + m_max = settings.value(mbServerAction::Strings::instance().incrementMax).value(); } public: @@ -87,6 +89,8 @@ class mbServerRunActionIncrement : public mbServerRunActionT T t = v.value(); mbServerRunAction::trySwap(&t, sizeof(t)); t += m_increment; + if ((t < m_min) || (t > m_max)) + t = m_min; mbServerRunAction::trySwap(&t, sizeof(t)); this->setValue(t); this->m_last = time; @@ -96,6 +100,8 @@ class mbServerRunActionIncrement : public mbServerRunActionT private: T m_increment; + T m_min; + T m_max; }; template