22
33#include < bit>
44
5- DataPoint::DataPoint () : DataPoint(QString(), Device::cFirstDeviceId, ModbusDataType::Type::UNSIGNED_16 )
5+ DataPoint::DataPoint () : DataPoint(QString(), Device::cFirstDeviceId)
66{
77}
88
9- DataPoint::DataPoint (QString const & address, deviceId_t deviceId, ModbusDataType::Type type)
10- : _address(address), _deviceId(deviceId), _type(type)
9+ DataPoint::DataPoint (QString const & address, deviceId_t deviceId) : _address(address), _deviceId(deviceId)
1110{
1211}
1312
@@ -16,74 +15,16 @@ QString DataPoint::address() const
1615 return _address;
1716}
1817
19- void DataPoint::setAddress (const QString& address)
20- {
21- _address = address;
22- }
23-
2418deviceId_t DataPoint::deviceId () const
2519{
2620 return _deviceId;
2721}
2822
29- void DataPoint::setDeviceId (deviceId_t deviceId)
30- {
31- _deviceId = deviceId;
32- }
33-
34- void DataPoint::setType (ModbusDataType::Type type)
35- {
36- _type = type;
37- }
38-
39- ModbusDataType::Type DataPoint::type () const
40- {
41- return _type;
42- }
43-
4423QString DataPoint::description () const
4524{
4625 QString connStr = QString (" device id %1" ).arg (deviceId ());
4726
48- return QString (" %1, %2, %3" ).arg (_address, ModbusDataType::description (_type), connStr);
49- }
50-
51- double DataPoint::processValue (uint16_t lowerRegister, uint16_t upperRegister, bool int32LittleEndian) const
52- {
53- double processedResult = 0u ;
54-
55- if (ModbusDataType::isFloat (_type))
56- {
57- uint32_t combinedValue = convertEndianness (int32LittleEndian, lowerRegister, upperRegister);
58-
59- processedResult = convertUint32ToFloat (combinedValue);
60- }
61- else if (ModbusDataType::is32Bit (_type))
62- {
63- uint32_t combinedValue = convertEndianness (int32LittleEndian, lowerRegister, upperRegister);
64-
65- if (ModbusDataType::isUnsigned (_type))
66- {
67- processedResult = static_cast <double >(static_cast <quint32>(combinedValue));
68- }
69- else
70- {
71- processedResult = static_cast <double >(static_cast <qint32>(combinedValue));
72- }
73- }
74- else
75- {
76- if (ModbusDataType::isUnsigned (_type))
77- {
78- processedResult = static_cast <double >(static_cast <quint16>(lowerRegister));
79- }
80- else
81- {
82- processedResult = static_cast <double >(static_cast <qint16>(lowerRegister));
83- }
84- }
85-
86- return processedResult;
27+ return QString (" %1, %2" ).arg (_address, connStr);
8728}
8829
8930DataPoint& DataPoint::operator =(const DataPoint& dataPoint)
@@ -96,15 +37,14 @@ DataPoint& DataPoint::operator=(const DataPoint& dataPoint)
9637
9738 _address = dataPoint.address ();
9839 _deviceId = dataPoint.deviceId ();
99- _type = dataPoint.type ();
10040
10141 // return the existing object so we can chain this operator
10242 return *this ;
10343}
10444
10545bool operator ==(const DataPoint& dp1, const DataPoint& dp2)
10646{
107- if ((dp1._address == dp2._address ) && (dp1._deviceId == dp2._deviceId ) && (dp1. _type == dp2. _type ) )
47+ if ((dp1._address == dp2._address ) && (dp1._deviceId == dp2._deviceId ))
10848 {
10949 return true ;
11050 }
@@ -131,36 +71,4 @@ QString DataPoint::dumpListToString(QList<DataPoint> list)
13171 dStream << list;
13272
13373 return str;
134- }
135-
136- uint32_t DataPoint::convertEndianness (bool bLittleEndian, quint16 value, quint16 nextValue) const
137- {
138- uint32_t combinedValue;
139- if (bLittleEndian)
140- {
141- combinedValue = (static_cast <uint32_t >(nextValue) << 16 ) | value;
142- }
143- else
144- {
145- combinedValue = (static_cast <uint32_t >(value) << 16 ) | nextValue;
146- }
147-
148- return combinedValue;
149- }
150-
151- double DataPoint::convertUint32ToFloat (quint32 value) const
152- {
153- const double doubleValue = std::bit_cast<float >(value);
154-
155- switch (std::fpclassify (doubleValue))
156- {
157- case FP_INFINITE:
158- case FP_NAN:
159- case FP_ZERO:
160- return 0 .0f ;
161- case FP_NORMAL:
162- case FP_SUBNORMAL:
163- default :
164- return doubleValue;
165- }
166- }
74+ }
0 commit comments