CuteHMI - Modbus (CuteHMI.Modbus.4)
TCPServerConfig.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_INTERNAL_TCPSERVERCONFIG_HPP
2#define H_EXTENSIONS_CUTEHMI_MODBUS_4_INCLUDE_CUTEHMI_MODBUS_INTERNAL_TCPSERVERCONFIG_HPP
3
4#include "Config.hpp"
5
6#include <QObject>
7#include <QString>
8#include <QReadWriteLock>
9
10namespace cutehmi {
11namespace modbus {
12namespace internal {
13
14class 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
80};
81
82}
83}
84}
85
86#endif
87
88//(c)C: Copyright © 2022, Michał Policht <michal@policht.pl>. All rights reserved.
89//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
90//(c)C: This file is a part of CuteHMI.
91//(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.
92//(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.
93//(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/>.
94//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
95//(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:
96//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
97//(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: TCPServerConfig.hpp:16
std::pair< quint16, quint16 > AddressRange
Definition: TCPServerConfig.hpp:20
static const char * INITIAL_HOST
Definition: TCPServerConfig.hpp:24
T internal(T... args)