2 #include "CHIPClusters.h"
6 #include <app/chip-zcl-zpro-codec-api.h>
7 #include <lib/support/Span.h>
8 #include <support/ReturnMacros.h>
11 namespace Controller {
13 // TODO(#4502): onCompletion is not used by IM for now.
14 // TODO(#4503): length should be passed to commands when byte string is in argument list.
15 // TODO(#4503): Commands should take group id as an argument.
17 {{#chip_server_clusters}}
19 // {{asCamelCased name false}} Cluster Commands
20 {{#chip_server_cluster_commands}}
21 CHIP_ERROR {{asCamelCased clusterName false}}Cluster::{{asCamelCased name false}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback{{#chip_server_cluster_command_arguments}}, {{chipType}} {{asCamelCased label}}{{/chip_server_cluster_command_arguments}})
23 #ifdef CHIP_APP_USE_INTERACTION_MODEL
24 VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
25 (void) onSuccessCallback;
26 (void) onFailureCallback;
28 app::Command::CommandParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, k{{asCamelCased name false}}CommandId,
29 (chip::app::Command::CommandPathFlags::kEndpointIdValid) };
30 app::Command * ZCLcommand = mDevice->GetCommandSender();
32 TLV::TLVWriter writer = ZCLcommand->CreateCommandDataElementTLVWriter();
34 TLV::TLVType dummyType = TLV::kTLVType_NotSpecified;
35 ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag, TLV::kTLVType_Structure, dummyType));
37 {{#chip_server_cluster_command_arguments}}
39 uint8_t argSeqNumber = 0;
41 // {{asCamelCased label}}: {{asCamelCased type}}
42 {{#if (isCharString type)}}
43 ReturnErrorOnFailure(writer.PutString(TLV::ContextTag(argSeqNumber++), {{asCamelCased label}}));
45 ReturnErrorOnFailure(writer.Put(TLV::ContextTag(argSeqNumber++), {{asCamelCased label}}));
48 // Command takes no arguments.
49 {{/chip_server_cluster_command_arguments}}
51 ReturnErrorOnFailure(writer.EndContainer(dummyType));
52 ReturnErrorOnFailure(writer.Finalize());
53 ReturnErrorOnFailure(ZCLcommand->AddCommand(cmdParams));
55 return mDevice->SendCommands();
57 uint8_t seqNum = mDevice->GetNextSequenceNumber();
58 System::PacketBufferHandle encodedCommand = encode{{asCamelCased clusterName false}}Cluster{{asType name}}Command(seqNum, mEndpoint{{#chip_server_cluster_command_arguments}}, {{asCamelCased label}}{{/chip_server_cluster_command_arguments}});
59 return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
63 {{/chip_server_cluster_commands}}
64 // {{asCamelCased name false}} Cluster Attributes
65 CHIP_ERROR {{asCamelCased name false}}Cluster::DiscoverAttributes(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
67 uint8_t seqNum = mDevice->GetNextSequenceNumber();
68 System::PacketBufferHandle encodedCommand = encode{{asCamelCased name false}}ClusterDiscoverAttributes(seqNum, mEndpoint);
69 return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
71 {{#chip_server_cluster_attributes}}
72 CHIP_ERROR {{asCamelCased parent.name false}}Cluster::ReadAttribute{{asCamelCased name false}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
74 uint8_t seqNum = mDevice->GetNextSequenceNumber();
75 System::PacketBufferHandle encodedCommand = encode{{asCamelCased parent.name false}}ClusterRead{{asCamelCased name false}}Attribute(seqNum, mEndpoint);
76 return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
79 {{#if (isWritableAttribute)}}
80 CHIP_ERROR {{asCamelCased parent.name false}}Cluster::WriteAttribute{{asCamelCased name false}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, {{chipType}} value)
82 uint8_t seqNum = mDevice->GetNextSequenceNumber();
83 System::PacketBufferHandle encodedCommand = encode{{asCamelCased parent.name false}}ClusterWrite{{asCamelCased name false}}Attribute(seqNum, mEndpoint, value);
84 return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
88 {{#if (isReportableAttribute)}}
89 CHIP_ERROR {{asCamelCased parent.name false}}Cluster::ConfigureAttribute{{asCamelCased name false}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, uint16_t minInterval, uint16_t maxInterval{{#unless (isDiscreteType)}}, {{chipType}} change{{/unless}})
91 uint8_t seqNum = mDevice->GetNextSequenceNumber();
92 System::PacketBufferHandle encodedCommand = encode{{asCamelCased parent.name false}}ClusterConfigure{{asCamelCased name false}}Attribute(seqNum, mEndpoint, minInterval, maxInterval{{#unless (isDiscreteType)}}, change{{/unless}});
93 return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
96 CHIP_ERROR {{asCamelCased parent.name false}}Cluster::ReportAttribute{{asCamelCased name false}}(Callback::Cancelable * onReportCallback)
98 return RequestAttributeReporting({{asHex attributeCode 4}}, onReportCallback);
102 {{/chip_server_cluster_attributes}}
103 {{/chip_server_clusters}}
105 } // namespace Controller