1
+ {{chip_header}}
2
+
3
+ #include <stdint.h>
4
+
5
+ #include "af-structs.h"
6
+ #include "call-command-handler.h"
7
+ #include "callback.h"
8
+ #include "command-id.h"
9
+ #include "util.h"
10
+
11
+ {{#all_user_clusters}}
12
+ {{#if (isEnabled enabled)}}
13
+ EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd);
14
+ {{/if}}
15
+ {{/all_user_clusters}}
16
+
17
+
18
+ static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
19
+ {
20
+ if (wasHandled)
21
+ {
22
+ return EMBER_ZCL_STATUS_SUCCESS;
23
+ }
24
+ else if (mfgSpecific)
25
+ {
26
+ return EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND;
27
+ }
28
+ else if (clusterExists)
29
+ {
30
+ return EMBER_ZCL_STATUS_UNSUP_COMMAND;
31
+ }
32
+ else
33
+ {
34
+ return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
35
+ }
36
+ }
37
+
38
+
39
+ // Main command parsing controller.
40
+ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
41
+ {
42
+ EmberAfStatus result = status(false, false, cmd->mfgSpecific);
43
+ if (cmd->direction == (uint8_t) ZCL_DIRECTION_SERVER_TO_CLIENT &&
44
+ emberAfContainsClientWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
45
+ {
46
+ switch (cmd->apsFrame->clusterId)
47
+ {
48
+ {{#all_user_clusters}}
49
+ {{#if (isEnabled enabled)}}
50
+ {{#if (isClient side) }}
51
+ case ZCL_{{asDelimitedMacro define}}_ID :
52
+ result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
53
+ break;
54
+ {{/if}}
55
+ {{/if}}
56
+ {{/all_user_clusters}}
57
+ default:
58
+ // Unrecognized cluster ID, error status will apply.
59
+ break;
60
+ }
61
+ }
62
+ else if (cmd->direction == (uint8_t) ZCL_DIRECTION_CLIENT_TO_SERVER &&
63
+ emberAfContainsServerWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
64
+ {
65
+ switch (cmd->apsFrame->clusterId)
66
+ {
67
+ {{#all_user_clusters}}
68
+ {{#if (isEnabled enabled)}}
69
+ {{#unless (isClient side) }}
70
+ case ZCL_{{asDelimitedMacro define}}_ID :
71
+ result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
72
+ break;
73
+ {{/unless}}
74
+ {{/if}}
75
+ {{/all_user_clusters}}
76
+ default:
77
+ // Unrecognized cluster ID, error status will apply.
78
+ break;
79
+ }
80
+ }
81
+ return result;
82
+ }
83
+
84
+ // Cluster specific command parsing
85
+
86
+ {{#all_user_clusters}}
87
+ {{#if (isEnabled enabled)}}
88
+ EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd)
89
+ {
90
+ bool wasHandled = false;
91
+
92
+ if (!cmd->mfgSpecific)
93
+ {
94
+ switch (cmd->commandId)
95
+ {
96
+ {{#all_user_cluster_commands}}
97
+ {{#if (isStrEqual clusterName parent.name)}}
98
+ {{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}}
99
+ case ZCL_{{asDelimitedMacro name}}_COMMAND_ID: {
100
+ {{#if (zcl_command_arguments_count this.id)}}
101
+ uint32_t argOffset = 0;
102
+ {{#zcl_command_arguments}}
103
+ {{asUnderlyingType type}} * {{asSymbol label}} = ({{asUnderlyingType type}} *)(cmd->buffer + argOffset);
104
+ {{#unless (isLastElement index count)}}
105
+ argOffset+= sizeof({{asUnderlyingType type}});
106
+ {{/unless}}
107
+ {{/zcl_command_arguments}}
108
+
109
+ wasHandled = emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback({{#zcl_command_arguments}} *{{asSymbol label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/zcl_command_arguments}});
110
+ {{else}}
111
+ wasHandled = emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback();
112
+ {{/if}}
113
+ break;
114
+ }
115
+ {{/if}}
116
+ {{/if}}
117
+ {{/all_user_cluster_commands}}
118
+ default: {
119
+ // Unrecognized command ID, error status will apply.
120
+ break;
121
+ }
122
+ }
123
+ }
124
+ return status(wasHandled, true, cmd->mfgSpecific);
125
+ }
126
+ {{/if}}
127
+ {{/all_user_clusters}}
0 commit comments