forked from dresden-elektronik/deconz-rest-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_descriptions.h
288 lines (239 loc) · 8.09 KB
/
device_descriptions.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
/*
* Copyright (c) 2021 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 DEVICE_DESCRIPTIONS_H
#define DEVICE_DESCRIPTIONS_H
#include <QObject>
#include <QVariantMap>
#include "resource.h"
#include "sensor.h"
#define SUBDEVICE_DEFAULT_ORDER 200
class Event;
class DDF_ZclReport
{
public:
quint32 reportableChange = 0;
quint16 attributeId = 0;
quint16 minInterval = 0;
quint16 maxInterval = 0;
quint16 manufacturerCode = 0;
quint8 direction = 0;
quint8 dataType = 0;
bool valid = false;
};
inline bool operator==(const DDF_ZclReport &a, const DDF_ZclReport &b)
{
return memcmp(&a, &b, sizeof(a)) == 0;
}
inline bool operator!=(const DDF_ZclReport &a, const DDF_ZclReport &b) { return !(a == b); }
inline bool isValid(const DDF_ZclReport &rep) { return rep.valid; }
class DDF_Binding
{
public:
union
{
quint16 dstGroup;
quint64 dstExtAddress;
};
quint16 clusterId;
quint8 srcEndpoint;
quint8 dstEndpoint;
quint8 configGroup;
struct
{
unsigned int isGroupBinding : 1;
unsigned int isUnicastBinding : 1;
unsigned int pad : 6 + 24;
};
std::vector<DDF_ZclReport> reporting;
};
inline bool isValid(const DDF_Binding &bnd) { return (bnd.isUnicastBinding || bnd.isGroupBinding) && bnd.srcEndpoint != 0; }
inline bool operator==(const DDF_Binding &a, const DDF_Binding &b)
{
if (a.clusterId == b.clusterId &&
a.srcEndpoint == b.srcEndpoint &&
a.reporting == b.reporting)
{
if (a.isUnicastBinding && b.isUnicastBinding &&
a.dstExtAddress == b.dstExtAddress &&
a.dstEndpoint == b.dstEndpoint)
{
return true;
}
if (a.isGroupBinding && b.isGroupBinding && a.dstGroup == b.dstGroup)
{
return true;
}
}
return false;
}
inline bool operator!=(const DDF_Binding &a, const DDF_Binding &b) { return !(a == b); }
class DeviceDescription
{
public:
bool isValid() const { return !manufacturerNames.isEmpty() && !modelIds.empty() && !subDevices.empty(); }
QStringList modelIds;
QStringList manufacturerNames; // as reported in Basic cluster
QString vendor; // optional: friendly name of manufacturer
QString product;
QString status;
QString matchExpr;
int handle = -1; // index in container
int sleeper = -1;
class Item
{
public:
using Handle = quint32;
enum Constants {
NoRefreshInterval = -1,
InvalidItemHandle = 0
};
Item()
{
flags = 0;
}
bool isValid() const { return !name.empty() && descriptor.isValid(); }
bool operator==(const Item &other) const
{
return flags == other.flags &&
handle == other.handle &&
refreshInterval == other.refreshInterval &&
name == other.name &&
descriptor.suffix == other.descriptor.suffix &&
parseParameters == other.parseParameters &&
readParameters == other.readParameters &&
writeParameters == other.writeParameters &&
defaultValue == other.defaultValue &&
description == other.description;
}
bool operator!=(const Item &other) const { return !(*this == other); }
Handle handle = InvalidItemHandle;
union
{
struct // 16 bits flags
{
unsigned short isGenericRead : 1;
unsigned short isGenericWrite : 1;
unsigned short isGenericParse : 1;
unsigned short isPublic : 1;
unsigned short isStatic : 1;
unsigned short isImplicit : 1;
unsigned short isManaged : 1; // managed internally
unsigned short awake : 1;
unsigned short hasIsPublic : 1; // to overwrite specific values
unsigned short pad : 7;
};
unsigned short flags;
};
int refreshInterval = NoRefreshInterval;
BufString<64> name; // todo global cache
ResourceItemDescriptor descriptor;
QVariant parseParameters;
QVariant readParameters;
QVariant writeParameters;
QVariant defaultValue;
QString description;
};
class SubDevice
{
public:
bool isValid() const { return !type.isEmpty() && !restApi.isEmpty() && !uniqueId.isEmpty() && !items.empty(); }
QString type;
QString restApi;
QStringList uniqueId; // [ "$address.ext", "01", "0405"],
QVariantMap meta;
std::vector<Item> items;
SensorFingerprint fingerPrint;
};
QString path;
std::vector<SubDevice> subDevices;
std::vector<DDF_Binding> bindings;
};
class DDF_SubDeviceDescriptor
{
public:
QString type;
QString name;
QString restApi;
QStringList uniqueId;
std::vector<const char*> items; // RAttrName, etc.
int order;
};
inline bool isValid(const DDF_SubDeviceDescriptor &sub)
{
return !sub.type.isEmpty() && !sub.name.isEmpty() && !sub.restApi.isEmpty() && !sub.uniqueId.isEmpty();
}
struct DDF_FunctionDescriptor
{
struct Parameter
{
struct // 16 bits flags
{
unsigned int isOptional : 1;
unsigned int supportsArray : 1;
unsigned int isHexString : 1;
unsigned int pad : 5;
};
QString name;
QString key;
QString description;
ApiDataType dataType = DataTypeUnknown;
QVariant defaultValue = 0;
};
QString name;
QString description;
std::vector<Parameter> parameters;
};
class DeviceDescriptionsPrivate;
using DDF_Items = std::vector<DeviceDescription::Item>;
enum DDF_MatchControl
{
DDF_EvalMatchExpr,
DDF_IgnoreMatchExpr
};
class DeviceDescriptions : public QObject
{
Q_OBJECT
public:
explicit DeviceDescriptions(QObject *parent = nullptr);
~DeviceDescriptions();
void setEnabledStatusFilter(const QStringList &filter);
const QStringList &enabledStatusFilter() const;
const DeviceDescription &get(const Resource *resource, DDF_MatchControl match = DDF_EvalMatchExpr) const;
void put(const DeviceDescription &ddf);
const DeviceDescription &load(const QString &path);
const DeviceDescription::SubDevice &getSubDevice(const Resource *resource) const;
QString constantToString(const QString &constant) const;
QString stringToConstant(const QString &str) const;
QStringList constants(const QString &prefix = QString()) const;
const DDF_Items &genericItems() const;
const DeviceDescription::Item &getItem(const ResourceItem *item) const;
const DeviceDescription::Item &getGenericItem(const char *suffix) const;
const std::vector<DDF_FunctionDescriptor> &getParseFunctions() const;
const std::vector<DDF_FunctionDescriptor> &getReadFunctions() const;
const std::vector<DDF_SubDeviceDescriptor> &getSubDevices() const;
static DeviceDescriptions *instance();
public Q_SLOTS:
void handleEvent(const Event &event);
void readAll();
Q_SIGNALS:
void eventNotify(const Event&); //! Emitted \p Event needs to be enqueued in a higher layer.
void loaded();
private:
void handleDDFInitRequest(const Event &event);
Q_DECLARE_PRIVATE_D(d_ptr2, DeviceDescriptions)
DeviceDescriptionsPrivate *d_ptr2 = nullptr;
};
#define DDF_AnnoteZclParse(resource, item, ep, cl, at, eval) \
DDF_AnnoteZclParse1(__LINE__, __FILE__, resource, item, ep, cl, at, eval)
bool DDF_IsStatusEnabled(const QString &status);
void DDF_AnnoteZclParse1(int line, const char* file, const Resource *resource, ResourceItem *item, quint8 ep, quint16 clusterId, quint16 attributeId, const char *eval);
const DeviceDescription::Item &DDF_GetItem(const ResourceItem *item);
Resource::Handle R_CreateResourceHandle(const Resource *r, size_t containerIndex);
#endif // DEVICEDESCRIPTIONS_H