CuteHMI - Modbus (CuteHMI.Modbus.2)
RTUServerConfig.hpp
1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_RTUSERVERCONFIG_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_RTUSERVERCONFIG_HPP
3 
4 #include "Config.hpp"
5 
6 #include <QObject>
7 #include <QString>
8 #include <QReadWriteLock>
9 #include <QtSerialPort>
10 
11 namespace cutehmi {
12 namespace modbus {
13 namespace internal {
14 
15 class CUTEHMI_MODBUS_PRIVATE RTUServerConfig:
16  public Config
17 {
18  Q_OBJECT
19 
20  public:
22 
23  static constexpr int MIN_SLAVE_ADDRESS = 1; // Can be 1 to 247 according to http://www.simplymodbus.ca/FAQ.htm
24  static constexpr int MAX_SLAVE_ADDRESS = 247; // Can be 1 to 247 according to http://www.simplymodbus.ca/FAQ.htm
25  static const char * INITIAL_PORT;
26  static constexpr QSerialPort::Parity INITIAL_PARITY = QSerialPort::NoParity;
27  static constexpr QSerialPort::BaudRate INITIAL_BAUD_RATE = QSerialPort::Baud19200;
28  static constexpr QSerialPort::DataBits INITIAL_DATA_BITS = QSerialPort::Data8;
29  static constexpr QSerialPort::StopBits INITIAL_STOP_BITS = QSerialPort::OneStop;
30  static constexpr int INITIAL_SLAVE_ADDRESS = MIN_SLAVE_ADDRESS;
31  static constexpr int INITIAL_COILS_ADDRESS_RANGE_MIN = 0;
32  static constexpr int INITIAL_COILS_ADDRESS_RANGE_MAX = 65535;
33  static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN = 0;
34  static constexpr int INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX = 65535;
35  static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN = 0;
36  static constexpr int INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX = 65535;
37  static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN = 0;
38  static constexpr int INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX = 65535;
39 
40  explicit RTUServerConfig(QObject * parent = nullptr);
41 
42  QString port() const;
43 
44  void setPort(const QString & port);
45 
46  QSerialPort::Parity parity() const;
47 
48  void setParity(QSerialPort::Parity parity);
49 
50  QSerialPort::BaudRate baudRate() const;
51 
52  void setBaudRate(QSerialPort::BaudRate baudRate);
53 
54  QSerialPort::DataBits dataBits() const;
55 
56  void setDataBits(QSerialPort::DataBits dataBits);
57 
58  QSerialPort::StopBits stopBits() const;
59 
60  void setStopBits(QSerialPort::StopBits stopBits);
61 
62  int slaveAddress() const;
63 
64  void setSlaveAddress(int address);
65 
66  AddressRange coilsAddressRange() const;
67 
68  void setCoilsAddressRange(AddressRange addressRange);
69 
70  AddressRange inputRegistersAddressRange() const;
71 
72  void setInputRegistersAddressRange(AddressRange addressRange);
73 
74  AddressRange discreteInputsAddressRange() const;
75 
76  void setDiscreteInputsAddressRange(AddressRange addressRange);
77 
78  AddressRange holdingRegistersAddressRange() const;
79 
80  void setHoldingRegistersAddressRange(AddressRange addressRange);
81 
82  private:
83  struct Members
84  {
85  QString port = INITIAL_PORT;
86  QSerialPort::Parity parity = INITIAL_PARITY;
87  QSerialPort::BaudRate baudRate = INITIAL_BAUD_RATE;
88  QSerialPort::DataBits dataBits = INITIAL_DATA_BITS;
89  QSerialPort::StopBits stopBits = INITIAL_STOP_BITS;
90  int slaveAddress = INITIAL_SLAVE_ADDRESS;
91  AddressRange coilsAddressRange = AddressRange(INITIAL_COILS_ADDRESS_RANGE_MIN, INITIAL_COILS_ADDRESS_RANGE_MAX);
92  AddressRange discreteInputsAddressRange = AddressRange(INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MIN, INITIAL_DISCRETE_INPUTS_ADDRESS_RANGE_MAX);
93  AddressRange holdingRegistersAddressRange = AddressRange(INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MIN, INITIAL_HOLDING_REGISTERS_ADDRESS_RANGE_MAX);
94  AddressRange inputRegistersAddressRange = AddressRange(INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MIN, INITIAL_INPUT_REGISTERS_ADDRESS_RANGE_MAX);
95  mutable QReadWriteLock lock;
96  };
97 
98  MPtr<Members> m;
99 };
100 
101 }
102 }
103 }
104 
105 #endif
106 
107 //(c)C: Copyright © 2019, Michał Policht <michal@policht.pl>. All rights reserved.
108 //(c)C: This file is a part of CuteHMI.
109 //(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.
110 //(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.
111 //(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/>.
std::pair< int, int >
cutehmi::modbus::internal::RTUServerConfig::AddressRange
std::pair< int, int > AddressRange
Definition: RTUServerConfig.hpp:21
cutehmi::MPtr< Members >
QObject
cutehmi
QString
cutehmi::modbus::internal::RTUServerConfig
Definition: RTUServerConfig.hpp:15
std::internal
T internal(T... args)
cutehmi::modbus::internal::Config
Definition: Config.hpp:10
cutehmi::modbus::internal::RTUServerConfig::INITIAL_PORT
static const char * INITIAL_PORT
Definition: RTUServerConfig.hpp:25
QReadWriteLock