1 #ifndef H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_QTSERVERMIXIN_HPP
2 #define H_EXTENSIONS_CUTEHMI_MODBUS_2_INCLUDE_CUTEHMI_MODBUS_INTERNAL_QTSERVERMIXIN_HPP
8 #include <QModbusDataUnitMap>
14 template <
typename DERIVED>
18 bool setMap(
const QModbusDataUnitMap & map);
25 const DERIVED & derived()
const;
30 template <
typename DERIVED>
40 template<
typename DERIVED>
49 case QModbusDataUnit::Coils:
50 for (quint16 index = 0, address =
static_cast<quint16
>(newData->
startAddress()); index <
static_cast<quint16
>(newData->
valueCount()); index++, address++) {
54 newData->
setValue(
static_cast<int>(index), derived().m->coilData->value(address)->value());
58 case QModbusDataUnit::DiscreteInputs:
59 for (quint16 index = 0, address =
static_cast<quint16
>(newData->
startAddress()); index <
static_cast<quint16
>(newData->
valueCount()); index++, address++) {
63 newData->
setValue(
static_cast<int>(index), derived().m->discreteInputData->value(address)->value());
67 case QModbusDataUnit::HoldingRegisters:
68 for (quint16 index = 0, address =
static_cast<quint16
>(newData->
startAddress()); index <
static_cast<quint16
>(newData->
valueCount()); index++, address++) {
72 newData->
setValue(
static_cast<int>(index), derived().m->holdingRegisterData->value(address)->value());
76 case QModbusDataUnit::InputRegisters:
77 for (quint16 index = 0, address =
static_cast<quint16
>(newData->
startAddress()); index <
static_cast<quint16
>(newData->
valueCount()); index++, address++) {
81 newData->
setValue(
static_cast<int>(index), derived().m->inputRegisterData->value(address)->value());
93 template<
typename DERIVED>
102 case QModbusDataUnit::Coils:
103 for (quint16 index = 0, address =
static_cast<quint16
>(newData.
startAddress()); index <
static_cast<quint16
>(newData.
valueCount()); index++, address++) {
107 derived().m->coilData->value(address)->setValue(
static_cast<bool>(newData.
value(
static_cast<int>(index))));
111 case QModbusDataUnit::DiscreteInputs:
112 for (quint16 index = 0, address =
static_cast<quint16
>(newData.
startAddress()); index <
static_cast<quint16
>(newData.
valueCount()); index++, address++) {
116 derived().m->discreteInputData->value(address)->setValue(
static_cast<bool>(newData.
value(
static_cast<int>(index))));
120 case QModbusDataUnit::HoldingRegisters:
121 for (quint16 index = 0, address =
static_cast<quint16
>(newData.
startAddress()); index <
static_cast<quint16
>(newData.
valueCount()); index++, address++) {
125 derived().m->holdingRegisterData->value(address)->setValue(newData.
value(
static_cast<int>(index)));
129 case QModbusDataUnit::InputRegisters:
130 for (quint16 index = 0, address =
static_cast<quint16
>(newData.
startAddress()); index <
static_cast<quint16
>(newData.
valueCount()); index++, address++) {
134 derived().m->inputRegisterData->value(address)->setValue(newData.
value(
static_cast<int>(index)));
161 template <
typename DERIVED>
164 return static_cast<const DERIVED &
>(*this);
167 template <
typename DERIVED>
168 DERIVED & QtServerMixin<DERIVED>::derived()
170 return static_cast<DERIVED &
>(*this);