-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
property.h
89 lines (59 loc) · 2.39 KB
/
property.h
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
#ifndef PROPERTY_H
#define PROPERTY_H
#include <QQueue>
#include <QSharedPointer>
#include <QVariant>
#include "endpoint.h"
struct PropertyRequest
{
quint16 clusterId;
QByteArray data;
};
class PropertyObject;
typedef QSharedPointer <PropertyObject> Property;
class PropertyObject : public AbstractMetaObject
{
public:
PropertyObject(const QString &name, QList <quint16> clusters = {}) :
AbstractMetaObject(name), m_clusters(clusters), m_multiple(false), m_timeout(0), m_time(0), m_transactionId(0) {}
PropertyObject(const QString &name, quint16 clusterId) :
AbstractMetaObject(name), m_clusters({clusterId}), m_multiple(false), m_timeout(0), m_time(0), m_transactionId(0) {}
virtual ~PropertyObject(void) {}
virtual void parseAttribte(quint16, quint16, const QByteArray &) {}
virtual void parseCommand(quint16, quint8, const QByteArray &) {}
virtual void resetValue(void) {}
inline QList <quint16> &clusters(void) { return m_clusters; }
inline bool multiple(void) { return m_multiple; }
inline void setMultiple(bool value) { m_multiple = value; }
inline quint32 timeout(void) { return m_timeout; }
inline void setTimeout(quint32 value) { m_timeout = value; }
inline qint64 time(void) { return m_time; }
inline void setTime(qint64 value) { m_time = value; }
inline quint8 transactionId(void) { return m_transactionId; }
inline void setTransactionId(quint8 value) { m_transactionId = value; }
inline QVariant value(void) { return m_value; }
inline void setValue(const QVariant &value) { m_value = value; }
inline void clearValue(void) { m_value.clear(); }
inline QQueue <PropertyRequest> &queue(void) { return m_queue; }
static void registerMetaTypes(void);
protected:
QList <quint16> m_clusters;
bool m_multiple;
quint32 m_timeout;
qint64 m_time;
quint8 m_transactionId;
QVariant m_value;
QQueue <PropertyRequest> m_queue;
quint8 percentage(double min, double max, double value);
QVariant enumValue(const QString &name, int index);
};
class EnumProperty : public PropertyObject
{
public:
EnumProperty(const QString &name, quint16 clusterId, quint16 attributeId) :
PropertyObject(name, clusterId), m_attributeId(attributeId) {}
void parseAttribte(quint16 clusterId, quint16 attributeId, const QByteArray &data) override;
private:
quint16 m_attributeId;
};
#endif