-
Notifications
You must be signed in to change notification settings - Fork 0
/
HPSensor.cpp
105 lines (86 loc) · 2.93 KB
/
HPSensor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "HPSensor.hpp"
HPSensor::HPSensor(QObject *parent, QList<QVariant> args)
: QObject{parent},
_name{args.at(0).toString()},
_id{static_cast<quint16>(args.at(1).toUInt(nullptr))},
_nodeID{static_cast<quint16>(args.at(2).toUInt(nullptr))}
{
}
void HPSensor::onHPSensorReceivedFD(const QList<QByteArray> &data)
{
qInfo() << "Enter HPSensor::onHPSensorReceivedFD function with object ID: " << _id;
for(int i = 0; i < data.length(); i = i + 14)
{
if(_id == data.at(i).toUInt(nullptr,16))
{
setSensorState(data.at(i+1).toUInt(nullptr,16));
quint64 sensorTimeStamp = static_cast<quint64>(data.at(i+9).toUInt(nullptr,16)) +
(static_cast<quint64>(data.at(i+8).toUInt(nullptr,16)) << 8) +
(static_cast<quint64>(data.at(i+7).toUInt(nullptr,16)) << 16) +
(static_cast<quint64>(data.at(i+6).toUInt(nullptr,16)) << 24) +
(static_cast<quint64>(data.at(i+5).toUInt(nullptr,16)) << 32) +
(static_cast<quint64>(data.at(i+4).toUInt(nullptr,16)) << 40) +
(static_cast<quint64>(data.at(i+3).toUInt(nullptr,16)) << 48) +
(static_cast<quint64>(data.at(i+2).toUInt(nullptr,16)) << 56);
setTimestamp(sensorTimeStamp);
quint8 u_8x4[4] = { static_cast<quint8>(data.at(i+10).toUInt(nullptr,16)),
static_cast<quint8>(data.at(i+11).toUInt(nullptr,16)),
static_cast<quint8>(data.at(i+12).toUInt(nullptr,16)),
static_cast<quint8>(data.at(i+13).toUInt(nullptr,16))
};
float currentOutputValue = 0.0f;
memcpy(¤tOutputValue, u_8x4, 4);
setOutputValue(currentOutputValue);
break;
}
}
}
QString HPSensor::name() const
{
return _name;
}
quint16 HPSensor::id() const
{
return _id;
}
quint16 HPSensor::nodeID() const
{
return _nodeID;
}
QVariant HPSensor::sensorState() const
{
return _sensorState;
}
void HPSensor::setSensorState(QVariant newSensorState)
{
if (_sensorState == newSensorState)
return;
_sensorState = newSensorState;
emit sensorStateChanged();
}
float HPSensor::outputValue() const
{
return _outputValue;
}
void HPSensor::setOutputValue(float newOutputValue)
{
if (qFuzzyCompare(_outputValue, newOutputValue))
return;
_outputValue = newOutputValue;
emit outputValueChanged();
}
quint64 HPSensor::timestamp() const
{
return _timestamp;
}
void HPSensor::setTimestamp(quint64 newTimestamp)
{
if (_timestamp == newTimestamp)
return;
_timestamp = newTimestamp;
emit timestampChanged();
}
void HPSensor::emitUpdateGraphQML_outputValue()
{
emit updateGraphQML_outputValue(static_cast<float>(_timestamp)/1'000'000, _outputValue);
}