-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzcl_private.h
337 lines (301 loc) · 9.1 KB
/
zcl_private.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
* Copyright (c) 2012-2023 dresden elektronik ingenieurtechnik gmbh.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
*/
#ifndef ZCL_PRIVATE_H
#define ZCL_PRIVATE_H
#include <QString>
#include <QIcon>
#include <cinttypes>
#include "deconz/declspec.h"
namespace deCONZ
{
class Enumeration
{
public:
Enumeration() :
m_id(0xFFFF)
{
}
Enumeration(uint id, const QString &name) :
m_id(id),
m_name(name)
{
}
uint id() const { return m_id; }
const QString &name() const { return m_name; }
void setValue(uint key, const QString &name) { m_values[key] = name; }
QString getValueName(uint key)
{
if (m_values.contains(key))
return m_values[key];
return QString();
}
const QHash<uint, QString> &values() const { return m_values; }
private:
QHash<uint, QString> m_values;
uint m_id;
QString m_name;
};
class ZclAttributePrivate
{
public:
ZclAttributePrivate();
static constexpr int PoolSize = 64; // for ZclMemory
uint16_t m_id = 0xFFFF;
uint8_t m_dataType = 0xFF;
uint8_t m_subType = 0xFF;
QString m_name;
QString m_description;
ZclAccess m_access = ZclRead;
uint8_t m_enumerationId = 0xFF; //!< Id of a enumeration repository.
uint8_t m_numericBase = 10; //!< For numeric data types.
bool m_required = false; //!< True if mandatory.
bool m_avail = true; //!< Attribute is available in the cluster.
union {
int idx; //!< index into a list
uint64_t bitmap; //!< bitmap bits set
} m_valueState;
/*!
May hold a value or the static content like enumeration or
bitmap values. If so the m_valueInfo.(idx|bitmap) is used
to optain the real value.
*/
QVariant m_value;
NumericUnion m_numericValue{}; //!< Numeric data.
std::vector<int> m_valuePos;
QStringList m_valueNames;
int64_t m_lastRead = -1;
/*!
If this is a list here is the attribute id wich holds the list size.
if set to 0xFFFF this is no list.
*/
uint16_t m_listSizeAttr = 0xFFFF;
int m_listSize = 0; //!< Current size of the list.
// reporting
uint16_t m_minReportInterval = 0; //!< Minimum reporting interval.
uint16_t m_maxReportInterval = 0xFFFF; //!< Maximum reporting interval.
uint16_t m_reportTimeout = 0; //!< Report timeout period.
NumericUnion m_reportableChange{}; //!< Reportable change.
ZclAttribute::FormatHint m_formatHint = ZclAttribute::DefaultFormat;
int m_rangeMin = 0;
int m_rangeMax = 0;
quint16 m_manufacturerCode = 0;
quint16 m_attrSetId = 0xFFFF;
quint16 m_attrSetManufacturerCode = 0;
};
class ZclAttributeSetPrivate
{
public:
ZclAttributeSetPrivate();
uint16_t id;
QString description;
quint16 manufacturerCode;
std::vector<int> attributeIndexes;
};
class ZclClusterPrivate
{
public:
ZclClusterPrivate();
uint16_t id;
uint16_t oppositeId;
uint16_t manufacturerCode;
QString name;
QString description;
bool isZcl;
bool isServer;
std::vector<ZclAttribute> attributes;
std::vector<ZclAttributeSet> attributeSets;
std::vector<ZclCommand> commands;
};
class ZclFramePrivate
{
public:
static constexpr int PoolSize = 16; // for ZclMemory
uint8_t valid = 0;
uint8_t frameControl = 0;
uint16_t manufacturerCode = 0xFFFF;
uint8_t seqNumber = 0;
uint8_t commandId = 0;
QByteArray payload;
};
class ZclDataTypePrivate
{
public:
/*! Data kind of the data type. */
enum DataKind
{
UnknownData,
AnalogData,
DiscreteData
};
ZclDataTypePrivate();
uint8_t m_id;
QString m_name;
QString m_shortname;
int m_length;
DataKind m_analogDiscrete;
};
class ZclCommandPrivate
{
public:
ZclCommandPrivate();
uint8_t m_id;
uint16_t m_manufacturerId;
uint8_t m_responseId;
QString m_name;
bool m_required;
bool m_recv;
QString m_description;
bool m_isProfileWide;
bool m_disableDefaultResponse;
std::vector<ZclAttribute> m_payload;
};
// TODO: place in private header and hide in public release
class DECONZ_DLLSPEC ZclDomain
{
public:
ZclDomain() : m_useZcl(true) { }
ZclDomain(const QString &name, const QString &description) :
m_useZcl(true),
m_name(name),
m_description(description)
{
#ifdef ZCL_LOAD_DBG
qDebug("Domain: %s %04X-%04X -- %s", qPrintable(name), qPrintable(description));
#endif
}
bool useZcl() const { return m_useZcl; }
void setUseZcl(bool useZcl) { m_useZcl = useZcl; }
const QString &name() const { return m_name; }
void setName(const QString &name) { m_name = name; }
const QString &description() const { return m_description; }
void setDescription(const QString &description) { m_description = description; }
const QHash<uint32_t, ZclCluster> &inClusters() const { return m_inClusters; }
const QHash<uint32_t, ZclCluster> &outClusters() const { return m_outClusters; }
bool isValid() const { return !m_name.isEmpty(); }
private:
friend class ZclDataBase;
bool m_useZcl;
QString m_name;
QString m_description;
QHash<uint32_t, ZclCluster> m_inClusters;
QHash<uint32_t, ZclCluster> m_outClusters;
};
class DECONZ_DLLSPEC ZclDevice
{
public:
ZclDevice() : m_deviceId(0xFFFF), m_profileId(0xFFFF) {}
ZclDevice(uint16_t id, const QString &name, const QString &description, const QIcon &icon) :
m_deviceId(id),
m_profileId(0xFFFF),
m_name(name),
m_description(description),
m_icon(icon)
{
#ifdef ZCL_LOAD_DBG
qDebug("ZclDevice: %04X %s -- %s", id, qPrintable(name), qPrintable(description));
#endif
}
uint16_t id() const { return m_deviceId; }
void setId(uint16_t id) { m_deviceId = id; }
uint16_t profileId() const { return m_profileId; }
void setProfileId(uint16_t id) { m_profileId = id; }
const QString &name() const { return m_name; }
const QString &description() const { return m_description; }
const QIcon &icon() const { return m_icon; }
private:
uint16_t m_deviceId;
uint16_t m_profileId;
QString m_name;
QString m_description;
QIcon m_icon;
};
// TODO: place in private header and hide in public release
class DECONZ_DLLSPEC ZclProfile
{
public:
ZclProfile() : m_id(0xFFFF) {}
ZclProfile(uint16_t id, const QString &name, const QString &description, const QIcon &icon) :
m_id(id),
m_name(name),
m_description(description),
m_icon(icon)
{
#ifdef ZCL_LOAD_DBG
qDebug("Profile: %04X %s -- %s", id, qPrintable(name), qPrintable(description));
#endif
}
uint16_t id() const { return m_id; }
void setId(uint16_t id) { m_id = id; }
const QString &name() const { return m_name; }
void setName(const QString &name) { m_name = name; }
const QString &description() const { return m_description; }
void setDescription(const QString &description) { m_description = description; }
const QIcon &icon() const { return m_icon; }
void setIcon(const QIcon &icon) { m_icon = icon; }
const std::vector<ZclDomain> &domains() const { return m_domains; }
void addDomain(const ZclDomain &domain);
bool isValid() const { return (m_id != 0xFFFF); }
private:
friend class ZclDataBase;
uint16_t m_id;
QString m_name;
QString m_description;
QIcon m_icon;
std::vector<ZclDomain> m_domains;
};
// TODO: place in private header and hide in public release
class DECONZ_DLLSPEC ZclDataBase
{
public:
ZclDataBase();
~ZclDataBase();
ZclCluster inCluster(uint16_t profileId, uint16_t clusterId, quint16 mfcode);
ZclCluster outCluster(uint16_t profileId, uint16_t clusterId, quint16 mfcode);
const ZclDataType &dataType(uint8_t id) const;
const ZclDataType &dataType(const QString &shortName) const;
ZclProfile profile(uint16_t id);
ZclDomain domain(const QString &name);
void addDomain(const ZclDomain &domain);
void addProfile(const ZclProfile &profile);
ZclDevice device(uint16_t profileId, uint16_t deviceId);
bool getEnumeration(uint id, deCONZ::Enumeration &out)
{
for (const auto &e : m_enums)
{
if (e.id() == id)
{
out = e;
return true;
}
}
return false;
}
void load(const QString &dbfile);
void initDbFile(const QString &zclFile);
void reloadAll(const QString &zclFile);
void clear();
bool knownDataType(uint8_t id);
private:
std::vector<deCONZ::Enumeration> m_enums;
ZclCluster m_unknownCluster;
ZclDataType m_unknownDataType;
std::vector<ZclDataType> m_dataTypes;
std::vector<ZclDomain> m_domains;
QHash<uint16_t, ZclProfile> m_profiles;
/*!
The device list is ordered. Private profile
devices comes first. (device.profileId() != 0xFFFF).
*/
std::vector<ZclDevice> m_devices;
QString m_iconPath;
};
DECONZ_DLLSPEC ZclDataBase * zclDataBase();
} //namespace deCONZ
#endif // ZCL_PRIVATE_H