CuteHMI - Modbus (CuteHMI.Modbus.2)
TCPServerConfig.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_TCPSERVERCONFIG_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_TCPSERVERCONFIG_HPP
3 
4 #include "Config.hpp"
5 
6 #include <QObject>
7 #include <QString>
8 #include <QReadWriteLock>
9 
10 namespace cutehmi {
11 namespace modbus {
12 namespace internal {
13 
14 class CUTEHMI_MODBUS_PRIVATE TCPServerConfig:
15  public Config
16 {
17  Q_OBJECT
18 
19  public:
21 
22  static constexpr int MIN_SLAVE_ADDRESS = 1; // Can be 1 to 247 according to http://www.simplymodbus.ca/FAQ.htm
23  static constexpr int MAX_SLAVE_ADDRESS = 247; // Can be 1 to 247 according to http://www.simplymodbus.ca/FAQ.htm
24  static const char * INITIAL_HOST;
25  static constexpr int INITIAL_PORT = 502;
26  static constexpr int INITIAL_SLAVE_ADDRESS = MIN_SLAVE_ADDRESS;
27  static constexpr quint16 INITIAL_COILS_ADDRESS_RANGE_MIN = 0;
28  static constexpr quint16 INITIAL_COILS_ADDRESS_RANGE_MAX = 65535;
29  static constexpr quint16 INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN = 0;
30  static constexpr quint16 INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX = 65535;
31  static constexpr quint16 INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN = 0;
32  static constexpr quint16 INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX = 65535;
33  static constexpr quint16 INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN = 0;
34  static constexpr quint16 INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX = 65535;
35 
36  explicit TCPServerConfig(QObject * parent = nullptr);
37 
38  QString host() const;
39 
40  void setHost(const QString & host);
41 
42  int port() const;
43 
44  void setPort(int port);
45 
46  int slaveAddress() const;
47 
48  void setSlaveAddress(int address);
49 
50  AddressRange coilsAddressRange() const;
51 
52  void setCoilsAddressRange(AddressRange addressRange);
53 
54  AddressRange inputRegistersAddressRange() const;
55 
56  void setInputRegistersAddressRange(AddressRange addressRange);
57 
58  AddressRange discreteInputsAddressRange() const;
59 
60  void setDiscreteInputsAddressRange(AddressRange addressRange);
61 
62  AddressRange holdingRegistersAddressRange() const;
63 
64  void setHoldingRegistersAddressRange(AddressRange addressRange);
65 
66  private:
67  struct Members
68  {
69  QString host = INITIAL_HOST;
70  int port = INITIAL_PORT;
71  int slaveAddress = INITIAL_SLAVE_ADDRESS;
72  AddressRange coilsAddressRange = AddressRange(INITIAL_COILS_ADDRESS_RANGE_MIN, INITIAL_COILS_ADDRESS_RANGE_MAX);
73  AddressRange discreteInputsAddressRange = AddressRange(INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN, INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX);
74  AddressRange holdingRegistersAddressRange = AddressRange(INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN, INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX);
75  AddressRange inputRegistersAddressRange = AddressRange(INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN, INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX);
76  mutable QReadWriteLock lock;
77  };
78 
79  MPtr<Members> m;
80 };
81 
82 }
83 }
84 }
85 
86 #endif
87 
88 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
89 //(c)C: This file is a part of CuteHMI.
90 //(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
91 //(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
92 //(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
cutehmi::modbus::internal::TCPServerConfig
Definition: TCPServerConfig.hpp:14
std::pair< quint16, quint16 >
cutehmi::modbus::internal::TCPServerConfig::INITIAL_HOST
static const char * INITIAL_HOST
Definition: TCPServerConfig.hpp:24
cutehmi::MPtr< Members >
QObject
cutehmi
QString
std::internal
T internal(T... args)
cutehmi::modbus::internal::Config
Definition: Config.hpp:10
cutehmi::modbus::internal::TCPServerConfig::AddressRange
std::pair< quint16, quint16 > AddressRange
Definition: TCPServerConfig.hpp:20
QReadWriteLock