CuteHMI - Modbus (CuteHMI.Modbus.4)
RTUServerConfig.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_INTERNAL_RTUSERVERCONFIG_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_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
11namespace cutehmi {
12namespace modbus {
13namespace internal {
14
15class 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
99};
100
101}
102}
103}
104
105#endif
106
107//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
108//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
109//(c)C: This file is a part of CuteHMI.
110//(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.
111//(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.
112//(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/>.
113//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
114//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
115//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
116//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Definition: Config.hpp:12
Definition: RTUServerConfig.hpp:17
static const char * INITIAL_PORT
Definition: RTUServerConfig.hpp:25
std::pair< int, int > AddressRange
Definition: RTUServerConfig.hpp:21
T internal(T... args)