summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2023-06-09 17:09:15 +0300
committerTarja Sundqvist <tarja.sundqvist@qt.io>2023-06-09 17:09:15 +0300
commitc41785c9f36560722b917d373ee97eed8cc4089a (patch)
treead9d2d75b46e2f316435e5e491b3bbd0daf7308c
parentb3081c36baee48b43b6285b4811dc6da451e2390 (diff)
parentdb246244f5079e87a204d3f2d46d5992ab34e181 (diff)
Merge remote-tracking branch 'origin/tqtc/lts-5.15.11' into tqtc/lts-5.15-opensourcev5.15.11-lts-lgpl
-rw-r--r--.qmake.conf2
-rw-r--r--src/serialbus/qmodbusclient.cpp8
-rw-r--r--src/serialbus/qmodbusdevice.cpp7
-rw-r--r--src/serialbus/qmodbuspdu.cpp21
-rw-r--r--src/serialbus/qmodbuspdu.h1
5 files changed, 34 insertions, 5 deletions
diff --git a/.qmake.conf b/.qmake.conf
index c0e0d61..2e81da4 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -2,4 +2,4 @@ load(qt_build_config)
CONFIG += warning_clean
DEFINES += QT_NO_FOREACH
-MODULE_VERSION = 5.15.10
+MODULE_VERSION = 5.15.11
diff --git a/src/serialbus/qmodbusclient.cpp b/src/serialbus/qmodbusclient.cpp
index 0801475..a5e3888 100644
--- a/src/serialbus/qmodbusclient.cpp
+++ b/src/serialbus/qmodbusclient.cpp
@@ -222,8 +222,12 @@ QModbusClient::QModbusClient(QModbusClientPrivate &dd, QObject *parent) :
}
/*!
- Processes a Modbus server \a response and stores the decoded information in \a data. Returns
- true on success; otherwise false.
+ Processes a Modbus server \a response and stores the decoded information in
+ \a data. Returns \c true on success; otherwise \c false.
+
+ \note The default implementation does not support all
+ \l {QModbusPdu::}{FunctionCode}s. Override this method in a custom Modbus
+ client implementations to handle the needed functions.
*/
bool QModbusClient::processResponse(const QModbusResponse &response, QModbusDataUnit *data)
{
diff --git a/src/serialbus/qmodbusdevice.cpp b/src/serialbus/qmodbusdevice.cpp
index ab8e126..58bdc6d 100644
--- a/src/serialbus/qmodbusdevice.cpp
+++ b/src/serialbus/qmodbusdevice.cpp
@@ -204,6 +204,13 @@ void QModbusDevice::setConnectionParameter(int parameter, const QVariant &value)
\value ReplyAbortedError The reply was aborted due to a disconnection of
the device.
\value UnknownError An unknown error occurred.
+
+ \note An UnknownError can also indicate that the received
+ \l {QModbusPdu::}{FunctionCode} is not supported in the current
+ implementation. In this case custom Modbus client implementations need to
+ override the \l {QModbusClient::}{processResponse()} and
+ \l {QModbusClient::}{processPrivateResponse()} methods to provide support
+ for needed functions.
*/
/*!
diff --git a/src/serialbus/qmodbuspdu.cpp b/src/serialbus/qmodbuspdu.cpp
index d97d614..e23fa7b 100644
--- a/src/serialbus/qmodbuspdu.cpp
+++ b/src/serialbus/qmodbuspdu.cpp
@@ -128,11 +128,12 @@ static QDataStream &pduFromStream(QDataStream &stream, Type type, QModbusPdu *pd
} raii = { pdu };
QModbusPdu::FunctionCode code = QModbusPdu::FunctionCode::Invalid;
- if (stream.readRawData(reinterpret_cast<char *>(&code), sizeof(quint8)) != sizeof(quint8))
+ stream >> code;
+ if (stream.status() == QDataStream::ReadPastEnd)
return stream;
pdu->setFunctionCode(code);
- if (code == QModbusPdu::Invalid || code == QModbusPdu::UndefinedFunctionCode) // shortcut
+ if (code == QModbusPdu::Invalid) // shortcut
return stream;
constexpr const int MaxPduDataSize = 252; // in bytes
@@ -623,6 +624,22 @@ void QModbusRequest::registerDataSizeCalculator(FunctionCode fc, CalcFuncPtr cal
}
/*!
+ \internal
+
+ Reads a FunctionCode from a \a stream.
+ In stream we serialize FunctionCode as one byte, so we use a temporary char
+ variable to make the code work on both little endian and big endian systems.
+ If reading from stream fails, code will retain original value.
+*/
+QDataStream &operator>>(QDataStream &stream, QModbusPdu::FunctionCode &code)
+{
+ char buffer;
+ if (stream.readRawData(&buffer, 1) == 1)
+ code = static_cast<QModbusPdu::FunctionCode>(buffer);
+ return stream;
+}
+
+/*!
\relates QModbusRequest
Reads a \a pdu from the \a stream and returns a reference to the stream.
diff --git a/src/serialbus/qmodbuspdu.h b/src/serialbus/qmodbuspdu.h
index 9372730..5bca0d3 100644
--- a/src/serialbus/qmodbuspdu.h
+++ b/src/serialbus/qmodbuspdu.h
@@ -187,6 +187,7 @@ private:
};
Q_SERIALBUS_EXPORT QDebug operator<<(QDebug debug, const QModbusPdu &pdu);
Q_SERIALBUS_EXPORT QDataStream &operator<<(QDataStream &stream, const QModbusPdu &pdu);
+Q_SERIALBUS_EXPORT QDataStream &operator>>(QDataStream &stream, QModbusPdu::FunctionCode &code);
class QModbusRequest : public QModbusPdu
{