-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
commands.zapt
644 lines (539 loc) · 22.6 KB
/
commands.zapt
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
{{> header}}
#pragma once
#include <cstdint>
#include <string>
#include <type_traits>
#include <app-common/zap-generated/cluster-objects.h>
#include <app/data-model/DecodableList.h>
#include <app/data-model/Nullable.h>
#include <commands/clusters/ModelCommand.h>
#include <commands/common/CommandInvoker.h>
#include <lib/core/CHIPSafeCasts.h>
#include <lib/support/BytesToHex.h>
#include <lib/support/Span.h>
#include <lib/support/TypeTraits.h>
#include <zap-generated/CHIPClientCallbacks.h>
#include <zap-generated/CHIPClusters.h>
// Value logging functions. The non-generated ones depend on the
// generated ones, so are placed here.
namespace {
{{#zcl_clusters}}
{{#zcl_structs}}
CHIP_ERROR LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns=parent.name isArgument=true}} value);
{{/zcl_structs}}
{{/zcl_clusters}}
#if CHIP_PROGRESS_LOGGING
std::string IndentStr(size_t indent)
{
std::string str;
for (size_t i = 0; i < indent; ++i) {
str.append(" ");
}
return str;
}
#endif // CHIP_PROGRESS_LOGGING
template <typename X, typename std::enable_if_t<std::is_integral<X>::value && !std::is_same<std::remove_cv_t<std::remove_reference_t<X>>, bool>::value, int> = 0>
CHIP_ERROR LogValue(const char * label, size_t indent, X value)
{
ChipLogProgress(chipTool, "%s%s: %s", IndentStr(indent).c_str(), label, std::to_string(value).c_str());
return CHIP_NO_ERROR;
}
template <typename X, typename std::enable_if_t<std::is_floating_point<X>::value, int> = 0>
CHIP_ERROR LogValue(const char * label, size_t indent, X value)
{
ChipLogProgress(chipTool, "%s%s: %s", IndentStr(indent).c_str(), label, std::to_string(value).c_str());
return CHIP_NO_ERROR;
}
CHIP_ERROR LogValue(const char * label, size_t indent, bool value)
{
ChipLogProgress(chipTool, "%s%s: %s", IndentStr(indent).c_str(), label, value ? "TRUE" : "FALSE");
return CHIP_NO_ERROR;
}
template <typename X, typename std::enable_if_t<std::is_enum<X>::value, int> = 0>
CHIP_ERROR LogValue(const char * label, size_t indent, X value)
{
return LogValue(label, indent, chip::to_underlying(value));
}
CHIP_ERROR LogValue(const char * label, size_t indent, chip::CharSpan value)
{
ChipLogProgress(chipTool, "%s%s: %.*s", IndentStr(indent).c_str(), label, static_cast<int>(value.size()), value.data());
return CHIP_NO_ERROR;
}
CHIP_ERROR LogValue(const char * label, size_t indent, chip::ByteSpan value)
{
ChipLogProgress(chipTool, "%s%s: %zu", IndentStr(indent).c_str(), label, value.size());
return CHIP_NO_ERROR;
}
template <typename X>
CHIP_ERROR LogValue(const char * label, size_t indent, chip::BitFlags<X> value)
{
return LogValue(label, indent, value.Raw());
}
template <typename T>
CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::DataModel::DecodableList<T> & value)
{
size_t count = 0;
CHIP_ERROR err = value.ComputeSize(&count);
if (err != CHIP_NO_ERROR)
{
return err;
}
ChipLogProgress(chipTool, "%s%s: %zu entries", IndentStr(indent).c_str(), label, count);
auto iter = value.begin();
size_t i = 0;
while (iter.Next())
{
++i;
std::string itemLabel = std::string("[") + std::to_string(i) + "]";
ReturnErrorOnFailure(LogValue(itemLabel.c_str(), indent + 1, iter.GetValue()));
}
if (iter.GetStatus() != CHIP_NO_ERROR)
{
ChipLogProgress(chipTool, "%sList truncated due to invalid value", IndentStr(indent+1).c_str());
}
return iter.GetStatus();
}
template <typename T>
CHIP_ERROR LogValue(const char * label, size_t indent, const chip::app::DataModel::Nullable<T> & value)
{
if (!value.IsNull())
{
return LogValue(label, indent, value.Value());
}
ChipLogProgress(chipTool, "%s%s: null", IndentStr(indent).c_str(), label);
return CHIP_NO_ERROR;
}
template <typename T>
CHIP_ERROR LogValue(const char * label, size_t indent, const chip::Optional<T> & value)
{
if (value.HasValue())
{
return LogValue(label, indent, value.Value());
}
return CHIP_NO_ERROR;
}
// We output helpers for all structs here, including ones we might not actually
// be logging.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
{{#zcl_clusters}}
{{#zcl_structs}}
CHIP_ERROR LogValue(const char * label, size_t indent, {{zapTypeToDecodableClusterObjectType name ns=parent.name isArgument=true}} value)
{
ChipLogProgress(chipTool, "%s%s: {", IndentStr(indent).c_str(), label);
{{#zcl_struct_items}}
{
CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}});
if (err != CHIP_NO_ERROR)
{
ChipLogProgress(chipTool, "%sStruct truncated due to invalid value for '{{asUpperCamelCase label}}'", IndentStr(indent + 1).c_str());
return err;
}
}
{{/zcl_struct_items}}
ChipLogProgress(chipTool, "%s}", IndentStr(indent).c_str());
return CHIP_NO_ERROR;
}
{{/zcl_structs}}
{{/zcl_clusters}}
#pragma GCC diagnostic pop
} // anonymous namespace
static void OnDefaultSuccessResponseWithoutExit(void * context)
{
ChipLogProgress(chipTool, "Default Success Response");
}
static void OnDefaultSuccessResponse(void * context)
{
ChipLogProgress(chipTool, "Default Success Response");
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnDefaultFailureResponse(void * context, uint8_t status)
{
ChipLogProgress(chipTool, "Default Failure Response: 0x%02x", status);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_ERROR_INTERNAL);
}
static void OnDefaultSuccess(void * context, const chip::app::DataModel::NullObjectType & data)
{
OnDefaultSuccessResponse(context);
};
static void OnDefaultFailure(void * context, EmberAfStatus status)
{
OnDefaultFailureResponse(context, status);
};
static void OnBooleanAttributeReport(void * context, bool value)
{
ChipLogProgress(chipTool, "Boolean attribute Response: %d", value);
}
static void OnBooleanAttributeResponse(void * context, bool value)
{
OnBooleanAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt8uAttributeReport(void * context, uint8_t value)
{
ChipLogProgress(chipTool, "Int8u attribute Response: %" PRIu8, value);
}
static void OnInt8uAttributeResponse(void * context, uint8_t value)
{
OnInt8uAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt16uAttributeReport(void * context, uint16_t value)
{
ChipLogProgress(chipTool, "Int16u attribute Response: %" PRIu16, value);
}
static void OnInt16uAttributeResponse(void * context, uint16_t value)
{
OnInt16uAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt32uAttributeReport(void * context, uint32_t value)
{
ChipLogProgress(chipTool, "Int32u attribute Response: %" PRIu32, value);
}
static void OnInt32uAttributeResponse(void * context, uint32_t value)
{
OnInt32uAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt64uAttributeReport(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int64u attribute Response: %" PRIu64, value);
}
static void OnInt64uAttributeResponse(void * context, uint64_t value)
{
OnInt64uAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt8sAttributeReport(void * context, int8_t value)
{
ChipLogProgress(chipTool, "Int8s attribute Response: %" PRId8, value);
}
static void OnInt8sAttributeResponse(void * context, int8_t value)
{
OnInt8sAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt16sAttributeReport(void * context, int16_t value)
{
ChipLogProgress(chipTool, "Int16s attribute Response: %" PRId16, value);
}
static void OnInt16sAttributeResponse(void * context, int16_t value)
{
OnInt16sAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt32sAttributeReport(void * context, int32_t value)
{
ChipLogProgress(chipTool, "Int32s attribute Response: %" PRId32, value);
}
static void OnInt32sAttributeResponse(void * context, int32_t value)
{
OnInt32sAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnInt64sAttributeReport(void * context, int64_t value)
{
ChipLogProgress(chipTool, "Int64s attribute Response: %" PRId64, value);
}
static void OnInt64sAttributeResponse(void * context, int64_t value)
{
OnInt64sAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnFloatAttributeReport(void * context, float value)
{
ChipLogProgress(chipTool, "Float attribute Response: %f", value);
}
static void OnFloatAttributeResponse(void * context, float value)
{
OnFloatAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnDoubleAttributeReport(void * context, double value)
{
ChipLogProgress(chipTool, "Double attribute Response: %f", value);
}
static void OnDoubleAttributeResponse(void * context, double value)
{
OnDoubleAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnOctetStringAttributeReport(void * context, const chip::ByteSpan value)
{
char buffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
if (CHIP_NO_ERROR == chip::Encoding::BytesToUppercaseHexString(value.data(), value.size(), &buffer[0], CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE)) {
ChipLogProgress(chipTool, "OctetString attribute Response: %s", buffer);
} else {
ChipLogProgress(chipTool, "OctetString attribute Response len: %zu", value.size());
}
}
static void OnOctetStringAttributeResponse(void * context, const chip::ByteSpan value)
{
OnOctetStringAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
static void OnCharStringAttributeReport(void * context, const chip::CharSpan value)
{
ChipLogProgress(chipTool, "CharString attribute Response: %.*s", static_cast<int>(value.size()), value.data());
}
static void OnCharStringAttributeResponse(void * context, const chip::CharSpan value)
{
OnCharStringAttributeReport(context, value);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#if isList}}
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list)
{
CHIP_ERROR err = LogValue("On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse", 0, list);
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(err);
}
{{/if}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}
{{#chip_client_clusters}}
{{#chip_cluster_responses}}
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}Success(void * context, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & data)
{
ChipLogProgress(Zcl, "Received {{asUpperCamelCase name}}:");
CHIP_ERROR err = CHIP_NO_ERROR;
{{#chip_cluster_response_arguments}}
if (err == CHIP_NO_ERROR) {
err = LogValue("{{asLowerCamelCase label}}", 1, data.{{asLowerCamelCase label}});
}
{{/chip_cluster_response_arguments}}
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(err);
};
{{/chip_cluster_responses}}
{{/chip_client_clusters}}
{{> clusters_header}}
{{#chip_client_clusters}}
{{> cluster_header}}
{{#chip_cluster_commands}}
/*
* Command {{asUpperCamelCase name}}
*/
class {{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}: public ModelCommand
{
public:
{{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}(): ModelCommand("{{asDelimitedCommand name}}")
{
{{#chip_cluster_command_arguments}}
{{~#*inline "field"}}mRequest.{{asLowerCamelCase label}}{{/inline~}}
{{#if isArray}}
// {{label}} Array parsing is not supported yet
{{else if isStruct}}
// {{label}} Struct parsing is not supported yet
{{else if (isString type)}}
AddArgument("{{asUpperCamelCase label}}", &{{>field}});
{{else}}
AddArgument("{{asUpperCamelCase label}}", {{asTypeMinValue type}}, {{asTypeMaxValue type}},
{{~#if ./isEnum}}reinterpret_cast<std::underlying_type_t<decltype({{>field}})> *>(&{{>field}})
{{else ./isBitmap}}reinterpret_cast<std::underlying_type_t<chip::app::Clusters::{{asUpperCamelCase parent.clusterName}}::{{asUpperCamelCase type}}> *>(&{{>field}})
{{else}}&{{>field}}
{{/if~}}
);
{{/if}}
{{/chip_cluster_command_arguments}}
ModelCommand::AddArguments();
}
CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 8}}) command ({{asHex code 8}}) on endpoint %" PRIu8, endpointId);
{{#chip_cluster_command_non_expanded_arguments}}
{{#if isArray}}
{{! TODO Implement complex types parsing in order to properly set the request parameters }}
mRequest.{{asLowerCamelCase label}} = {{zapTypeToEncodableClusterObjectType type ns=parent.parent.name}}();
{{/if}}
{{/chip_cluster_command_non_expanded_arguments}}
return chip::Controller::InvokeCommand(device, this, {{#if hasSpecificResponse}}On{{asUpperCamelCase parent.name}}{{asUpperCamelCase response.name}}Success{{else}}OnDefaultSuccess{{/if}}, OnDefaultFailure, endpointId, mRequest
{{#if mustUseTimedInvoke}}
{{!TODO figure out where to get useful timeout values here. For
now, pick 10 seconds.}}
, 10000
{{/if}}
);
}
private:
chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::Type mRequest;
};
{{/chip_cluster_commands}}
{{#chip_server_cluster_attributes}}
{{! TODO: Various types (floats, structs) not supported here. }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
/*
* Attribute {{asUpperCamelCase name}}
*/
class Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public ModelCommand
{
public:
Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): ModelCommand("read")
{
AddArgument("attr-name", "{{asDelimitedCommand (asUpperCamelCase name)}}");
ModelCommand::AddArguments();
}
~Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}()
{
delete onSuccessCallback;
delete onFailureCallback;
}
CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 4}}) command (0x00) on endpoint %" PRIu8, endpointId);
chip::Controller::{{asUpperCamelCase parent.name}}Cluster cluster;
cluster.Associate(device, endpointId);
return cluster.ReadAttribute{{asUpperCamelCase name}}(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}
private:
{{#if isList}}
chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback> * onSuccessCallback = new chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback>(On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse, this);
{{else}}
chip::Callback::Callback<{{chipCallback.name}}AttributeCallback> * onSuccessCallback = new chip::Callback::Callback<{{chipCallback.name}}AttributeCallback>(On{{chipCallback.name}}AttributeResponse, this);
{{/if}}
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback = new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};
{{#if isWritableAttribute}}
{{! No list support for writing yet. Need to figure out how to represent the
values. }}
{{#unless isList}}
class Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public ModelCommand
{
public:
Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): ModelCommand("write")
{
AddArgument("attr-name", "{{asDelimitedCommand (asUpperCamelCase name)}}");
{{#if isArray}}
// {{label}} Array parsing is not supported yet
{{else if isStruct}}
// {{label}} Struct parsing is not supported yet
{{else if (isString type)}}
AddArgument("attr-value", &mValue);
{{else}}
AddArgument("attr-value", {{asTypeMinValue type}}, {{asTypeMaxValue type}}, &mValue);
{{/if}}
ModelCommand::AddArguments();
}
~Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}()
{
delete onSuccessCallback;
delete onFailureCallback;
}
CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 4}}) command (0x01) on endpoint %" PRIu8, endpointId);
chip::Controller::{{asUpperCamelCase parent.name}}Cluster cluster;
cluster.Associate(device, endpointId);
return cluster.WriteAttribute{{asUpperCamelCase name}}(onSuccessCallback->Cancel(), onFailureCallback->Cancel(), mValue);
}
private:
chip::Callback::Callback<DefaultSuccessCallback> * onSuccessCallback = new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback = new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
{{chipType}} mValue;
};
{{/unless}}
{{/if}}
{{#if isReportableAttribute}}
{{#unless isList}}
class Report{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}: public ModelCommand
{
public:
Report{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}(): ModelCommand("report")
{
AddArgument("attr-name", "{{asDelimitedCommand (asUpperCamelCase name)}}");
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("wait", 0, 1, &mWait);
ModelCommand::AddArguments();
}
~Report{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}()
{
delete onSuccessCallback;
delete onSuccessCallbackWithoutExit;
delete onFailureCallback;
delete onReportCallback;
}
CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster ({{asHex parent.code 4}}) command (0x06) on endpoint %" PRIu8, endpointId);
chip::Controller::{{asUpperCamelCase parent.name}}Cluster cluster;
cluster.Associate(device, endpointId);
ReturnErrorOnFailure(cluster.ReportAttribute{{asUpperCamelCase name}}(onReportCallback->Cancel()));
chip::Callback::Cancelable * successCallback = mWait ? onSuccessCallbackWithoutExit->Cancel() : onSuccessCallback->Cancel();
return cluster.SubscribeAttribute{{asUpperCamelCase name}}(successCallback, onFailureCallback->Cancel(), mMinInterval, mMaxInterval);
}
chip::System::Clock::Timeout GetWaitDuration() const override
{
return chip::System::Clock::Seconds16(mWait ? UINT16_MAX : 10);
}
private:
chip::Callback::Callback<DefaultSuccessCallback> * onSuccessCallback = new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponse, this);
chip::Callback::Callback<DefaultSuccessCallback> * onSuccessCallbackWithoutExit = new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponseWithoutExit, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback = new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
chip::Callback::Callback<{{chipCallback.name}}AttributeCallback> * onReportCallback = new chip::Callback::Callback<{{chipCallback.name}}AttributeCallback>(On{{chipCallback.name}}AttributeReport, this);
uint16_t mMinInterval;
uint16_t mMaxInterval;
bool mWait;
};
{{/unless}}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}
/*----------------------------------------------------------------------------*\
| Register all Clusters commands |
\*----------------------------------------------------------------------------*/
{{#chip_client_clusters}}
void registerCluster{{asUpperCamelCase name}}(Commands & commands)
{
const char * clusterName = "{{asUpperCamelCase name}}";
commands_list clusterCommands = {
{{#chip_cluster_commands}}
make_unique<{{asUpperCamelCase clusterName}}{{asUpperCamelCase name}}>(), //
{{/chip_cluster_commands}}
{{#chip_server_cluster_attributes}}
{{! TODO: Various types (floats, structs) not supported here. }}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
make_unique<Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(), //
{{#if isWritableAttribute}}
{{! No list support for writing yet. Need to figure out how to
represent the values. }}
{{#unless isList}}
make_unique<Write{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(), //
{{/unless}}
{{/if}}
{{#if isReportableAttribute}}
{{#unless isList}}
make_unique<Report{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}>(), //
{{/unless}}
{{/if}}
{{/unless}}
{{/chip_server_cluster_attributes}}
};
commands.Register(clusterName, clusterCommands);
}
{{/chip_client_clusters}}
void registerClusters(Commands & commands)
{
{{#chip_client_clusters}}
registerCluster{{asUpperCamelCase name}}(commands);
{{/chip_client_clusters}}
}