3 // #TODO : This template wasn't tested in any way with CHIP
4 // Might need a zap submodule update and / or other fixes to make it work.
14 // Creator for attribute: {{name}}, singleton
15 #define CREATOR_{{define}}_SINGLETON {{asHex ../token_id 4}}
16 #define NVM3KEY_{{define}}_SINGLETON (NVM3KEY_DOMAIN_ZIGBEE | {{asHex ../token_id 4}})
20 {{#each nonSingletons}}
21 // Creator for attribute: {{name}}, endpoint: {{../id}}
22 #define CREATOR_{{define}}_{{../id}} {{asHex ../../token_id 4}}
23 #define NVM3KEY_{{define}}_{{../id}} (NVM3KEY_DOMAIN_ZIGBEE | {{asHex ../../token_id 4}})
28 // Types for the tokens
32 typedef uint8_t tokType_{{tokenType}}[{{maxLength}}];
34 typedef {{as_underlying_type type}} tokType_{{tokenType}};
37 {{#each nonSingletons}}
39 typedef uint8_t tokType_{{tokenType}}[{{maxLength}}];
41 typedef {{as_underlying_type type}} tokType_{{tokenType}};
50 DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, { {{longDefault}} })
53 DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, {{defaultValue}})
55 DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, 0)
60 {{#each nonSingletons}}
62 DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, { {{longDefault}} })
65 DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, {{defaultValue}})
67 DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, 0)
72 #endif // DEFINETOKENS
75 // Macro snippet that loads all the attributes from tokens
76 #define GENERATED_TOKEN_LOADER(endpoint) do {\
78 uint8_t ptr[{{maxSize}}]; \
80 {{#if hasNonSingletons}}
81 uint8_t curNetwork = emberGetCurrentNetwork(); \
85 halCommonGetToken((tokType_{{tokenType}} *)ptr, TOKEN_{{define}}_SINGLETON); \
87 emberAfWriteServerAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
89 {{#unless serverSide}}
90 emberAfWriteClientAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
94 {{#if hasNonSingletons}}
95 epNetwork = emberAfNetworkIndexFromEndpoint({{id}}); \
96 if({{id}} == (endpoint) || (EMBER_BROADCAST_ENDPOINT == (endpoint) && epNetwork == curNetwork)) { \
97 {{#each nonSingletons}}
98 halCommonGetToken((tokType_{{tokenType}} *)ptr, TOKEN_{{define}}_{{../id}}); \
100 emberAfWriteServerAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
102 {{#unless serverSide}}
103 emberAfWriteClientAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
112 // Macro snippet that saves the attribute to token
113 #define GENERATED_TOKEN_SAVER do { \
114 uint8_t allZeroData[{{maxSize}}]; \
115 MEMSET(allZeroData, 0, {{maxSize}}); \
116 if ( data == NULL ) { data = allZeroData; } \
118 {{#if hasSingletons}}
119 if ( {{hexCode}} == clusterId ) { \
121 if ( {{hexCode}} == metadata->attributeId && 0x0000 == emberAfGetMfgCode(metadata) && !emberAfAttributeIsClient(metadata) ) { \
122 halCommonSetToken(TOKEN_{{define}}_SINGLETON, data); } \
128 {{#if hasNonSingletons}}
129 if ( {{id}} == endpoint ) { \
131 {{#if hasNonSingletons}}
132 if ( {{hexCode}} == clusterId ) { \
133 {{#each nonSingletons}}
134 if ( {{hexCode}} == metadata->attributeId && 0x0000 == emberAfGetMfgCode(metadata) && {{#if serverSide}}!{{/if}}emberAfAttributeIsClient(metadata) ) \
135 halCommonSetToken(TOKEN_{{define}}_{{../../id}}, data); \