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_P_H
5#define QMODBUSERVER_P_H
6
7#include <QtSerialBus/qmodbusdataunit.h>
8#include <QtSerialBus/qmodbusserver.h>
9
10#include <private/qmodbuscommevent_p.h>
11#include <private/qmodbusdevice_p.h>
12#include <private/qmodbus_symbols_p.h>
13
14#include <array>
15#include <deque>
16
17//
18// W A R N I N G
19// -------------
20//
21// This file is not part of the Qt API. It exists purely as an
22// implementation detail. This header file may change from version to
23// version without notice, or even be removed.
24//
25// We mean it.
26//
27
28QT_BEGIN_NAMESPACE
29
30class QModbusServerPrivate : public QModbusDevicePrivate
31{
32 Q_DECLARE_PUBLIC(QModbusServer)
33
34public:
35 enum Counter {
36 CommEvent = 0x0001,
37 BusMessage = Diagnostics::ReturnBusMessageCount,
38 BusCommunicationError = Diagnostics::ReturnBusCommunicationErrorCount,
39 BusExceptionError = Diagnostics::ReturnBusExceptionErrorCount,
40 ServerMessage = Diagnostics::ReturnServerMessageCount,
41 ServerNoResponse = Diagnostics::ReturnServerNoResponseCount,
42 ServerNAK = Diagnostics::ReturnServerNAKCount,
43 ServerBusy = Diagnostics::ReturnServerBusyCount,
44 BusCharacterOverrun = Diagnostics::ReturnBusCharacterOverrunCount
45 };
46
47 QModbusServerPrivate()
48 : m_counters()
49 {
50 }
51
52 bool setMap(const QModbusDataUnitMap &map);
53
54 void resetCommunicationCounters() { m_counters.fill(u: 0u); }
55 void incrementCounter(QModbusServerPrivate::Counter counter) { m_counters[counter]++; }
56
57 QModbusResponse processRequest(const QModbusPdu &request);
58
59 QModbusResponse processReadCoilsRequest(const QModbusRequest &request);
60 QModbusResponse processReadDiscreteInputsRequest(const QModbusRequest &request);
61 QModbusResponse readBits(const QModbusPdu &request, QModbusDataUnit::RegisterType unitType);
62
63 QModbusResponse processReadHoldingRegistersRequest(const QModbusRequest &request);
64 QModbusResponse processReadInputRegistersRequest(const QModbusRequest &request);
65 QModbusResponse readBytes(const QModbusPdu &request, QModbusDataUnit::RegisterType unitType);
66
67 QModbusResponse processWriteSingleCoilRequest(const QModbusRequest &request);
68 QModbusResponse processWriteSingleRegisterRequest(const QModbusRequest &request);
69 QModbusResponse writeSingle(const QModbusPdu &request, QModbusDataUnit::RegisterType unitType);
70
71 QModbusResponse processReadExceptionStatusRequest(const QModbusRequest &request);
72 QModbusResponse processDiagnosticsRequest(const QModbusRequest &request);
73 QModbusResponse processGetCommEventCounterRequest(const QModbusRequest &request);
74 QModbusResponse processGetCommEventLogRequest(const QModbusRequest &request);
75 QModbusResponse processWriteMultipleCoilsRequest(const QModbusRequest &request);
76 QModbusResponse processWriteMultipleRegistersRequest(const QModbusRequest &request);
77 QModbusResponse processReportServerIdRequest(const QModbusRequest &request);
78 QModbusResponse processMaskWriteRegisterRequest(const QModbusRequest &request);
79 QModbusResponse processReadWriteMultipleRegistersRequest(const QModbusRequest &request);
80 QModbusResponse processReadFifoQueueRequest(const QModbusRequest &request);
81 QModbusResponse processEncapsulatedInterfaceTransportRequest(const QModbusRequest &request);
82
83 void storeModbusCommEvent(const QModbusCommEvent &eventByte);
84
85 int m_serverAddress = 1;
86 std::array<quint16, 20> m_counters;
87 QHash<int, QVariant> m_serverOptions;
88 QModbusDataUnitMap m_modbusDataUnitMap;
89 std::deque<quint8> m_commEventLog;
90};
91
92QT_END_NAMESPACE
93
94#endif // QMODBUSERVER_P_H
95

source code of qtserialbus/src/serialbus/qmodbusserver_p.h