| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtSerialBus module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #ifndef QMODBUSERVER_H |
| 38 | #define QMODBUSERVER_H |
| 39 | |
| 40 | #include <QtCore/qobject.h> |
| 41 | #include <QtCore/qvariant.h> |
| 42 | #include <QtSerialBus/qmodbusdataunit.h> |
| 43 | #include <QtSerialBus/qmodbusdevice.h> |
| 44 | #include <QtSerialBus/qmodbuspdu.h> |
| 45 | |
| 46 | QT_BEGIN_NAMESPACE |
| 47 | |
| 48 | class QModbusServerPrivate; |
| 49 | |
| 50 | class Q_SERIALBUS_EXPORT QModbusServer : public QModbusDevice |
| 51 | { |
| 52 | Q_OBJECT |
| 53 | Q_DECLARE_PRIVATE(QModbusServer) |
| 54 | |
| 55 | public: |
| 56 | enum Option { |
| 57 | DiagnosticRegister, |
| 58 | ExceptionStatusOffset, |
| 59 | DeviceBusy, |
| 60 | AsciiInputDelimiter, |
| 61 | ListenOnlyMode, |
| 62 | ServerIdentifier, |
| 63 | RunIndicatorStatus, |
| 64 | AdditionalData, |
| 65 | DeviceIdentification, |
| 66 | // Reserved |
| 67 | UserOption = 0x100 |
| 68 | }; |
| 69 | Q_ENUM(Option) |
| 70 | |
| 71 | explicit QModbusServer(QObject *parent = nullptr); |
| 72 | ~QModbusServer(); |
| 73 | |
| 74 | int serverAddress() const; |
| 75 | void setServerAddress(int serverAddress); |
| 76 | |
| 77 | virtual bool setMap(const QModbusDataUnitMap &map); |
| 78 | virtual bool processesBroadcast() const { return false; } |
| 79 | |
| 80 | virtual QVariant value(int option) const; |
| 81 | virtual bool setValue(int option, const QVariant &value); |
| 82 | |
| 83 | bool data(QModbusDataUnit *newData) const; |
| 84 | bool setData(const QModbusDataUnit &unit); |
| 85 | |
| 86 | bool setData(QModbusDataUnit::RegisterType table, quint16 address, quint16 data); |
| 87 | bool data(QModbusDataUnit::RegisterType table, quint16 address, quint16 *data) const; |
| 88 | |
| 89 | Q_SIGNALS: |
| 90 | void dataWritten(QModbusDataUnit::RegisterType table, int address, int size); |
| 91 | |
| 92 | protected: |
| 93 | QModbusServer(QModbusServerPrivate &dd, QObject *parent = nullptr); |
| 94 | |
| 95 | virtual bool writeData(const QModbusDataUnit &unit); |
| 96 | virtual bool readData(QModbusDataUnit *newData) const; |
| 97 | |
| 98 | virtual QModbusResponse processRequest(const QModbusPdu &request); |
| 99 | virtual QModbusResponse processPrivateRequest(const QModbusPdu &request); |
| 100 | }; |
| 101 | |
| 102 | Q_DECLARE_TYPEINFO(QModbusServer::Option, Q_PRIMITIVE_TYPE); |
| 103 | |
| 104 | QT_END_NAMESPACE |
| 105 | |
| 106 | #endif // QMODBUSERVER_H |
| 107 | |