1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QMODBUSERVER_H |
5 | #define QMODBUSERVER_H |
6 | |
7 | #include <QtCore/qobject.h> |
8 | #include <QtCore/qvariant.h> |
9 | #include <QtSerialBus/qmodbusdataunit.h> |
10 | #include <QtSerialBus/qmodbusdevice.h> |
11 | #include <QtSerialBus/qmodbuspdu.h> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QModbusServerPrivate; |
16 | |
17 | class Q_SERIALBUS_EXPORT QModbusServer : public QModbusDevice |
18 | { |
19 | Q_OBJECT |
20 | Q_DECLARE_PRIVATE(QModbusServer) |
21 | |
22 | public: |
23 | enum Option { |
24 | DiagnosticRegister, |
25 | ExceptionStatusOffset, |
26 | DeviceBusy, |
27 | AsciiInputDelimiter, |
28 | ListenOnlyMode, |
29 | ServerIdentifier, |
30 | RunIndicatorStatus, |
31 | AdditionalData, |
32 | DeviceIdentification, |
33 | // Reserved |
34 | UserOption = 0x100 |
35 | }; |
36 | Q_ENUM(Option) |
37 | |
38 | explicit QModbusServer(QObject *parent = nullptr); |
39 | ~QModbusServer(); |
40 | |
41 | int serverAddress() const; |
42 | void setServerAddress(int serverAddress); |
43 | |
44 | virtual bool setMap(const QModbusDataUnitMap &map); |
45 | virtual bool processesBroadcast() const { return false; } |
46 | |
47 | virtual QVariant value(int option) const; |
48 | virtual bool setValue(int option, const QVariant &value); |
49 | |
50 | bool data(QModbusDataUnit *newData) const; |
51 | bool setData(const QModbusDataUnit &unit); |
52 | |
53 | bool setData(QModbusDataUnit::RegisterType table, quint16 address, quint16 data); |
54 | bool data(QModbusDataUnit::RegisterType table, quint16 address, quint16 *data) const; |
55 | |
56 | Q_SIGNALS: |
57 | void dataWritten(QModbusDataUnit::RegisterType table, int address, int size); |
58 | |
59 | protected: |
60 | QModbusServer(QModbusServerPrivate &dd, QObject *parent = nullptr); |
61 | |
62 | virtual bool writeData(const QModbusDataUnit &unit); |
63 | virtual bool readData(QModbusDataUnit *newData) const; |
64 | |
65 | virtual QModbusResponse processRequest(const QModbusPdu &request); |
66 | virtual QModbusResponse processPrivateRequest(const QModbusPdu &request); |
67 | }; |
68 | |
69 | Q_DECLARE_TYPEINFO(QModbusServer::Option, Q_PRIMITIVE_TYPE); |
70 | |
71 | QT_END_NAMESPACE |
72 | |
73 | #endif // QMODBUSERVER_H |
74 | |