Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Add ZAP templates to src/app #3733

Closed
wants to merge 11 commits into from
5 changes: 5 additions & 0 deletions src/app/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ Framework including the file you are reading right now.
This directory contains all of the cluster implementations included in the CHIP
ZCL Application Framework.

### <code>/src/app/zap-templates</code>

This directory contains all of the templates and helpers specific to CHIP for
the ZAP tool.

## Public APIs

### Attribute changes
Expand Down
26 changes: 26 additions & 0 deletions src/app/zap-templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ZAP generation templates

## What is this repo?

This directory contains generation templates for ZAP, ZCL Advanced Platform.

**IMPORTANT**: Changes to templates will affect all examples.

# Useful command for CHIP

Run ZAP with UI to configure endpoints and clusters

```
cd ./third_party/zap/repo/
node src-script/zap-start.js --logToStdout --gen ../../../src/app/zap-templates/chip-templates.json
```

Generate files in headless mode

```
cd ./third_party/zap/repo/
node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ../../../src/app/zap-templates/chip-templates.json -i <path to *.zap file> -o <Path to /gen/ folder>
```

For more information please see the documentation under `docs/` in
[ZAP](https://github.com/project-chip/zap)
17 changes: 17 additions & 0 deletions src/app/zap-templates/af-structs.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{chip_header}}

// Prevent multiple inclusion
#pragma once

#include <stdint.h>
#include "enums.h"

{{#zcl_structs}}

// Struct for {{label}}
typedef struct _{{asType label}} {
{{#zcl_struct_items}}
{{ident}}{{asUnderlyingType type}} {{asSymbol label}};
{{/zcl_struct_items}}
} {{asUnderlyingType label}};
{{/zcl_structs}}
53 changes: 53 additions & 0 deletions src/app/zap-templates/att-storage.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{chip_header}}

// Prevent multiple inclusion
#pragma once

// Attribute masks modify how attributes are used by the framework
//
// Attribute that has this mask is NOT read-only
#define ATTRIBUTE_MASK_WRITABLE (0x01)
// Attribute that has this mask is saved to a token
#define ATTRIBUTE_MASK_TOKENIZE (0x02)
// Attribute that has this mask has a min/max values
#define ATTRIBUTE_MASK_MIN_MAX (0x04)
// Manufacturer specific attribute
#define ATTRIBUTE_MASK_MANUFACTURER_SPECIFIC (0x08)
// Attribute deferred to external storage
#define ATTRIBUTE_MASK_EXTERNAL_STORAGE (0x10)
// Attribute is singleton
#define ATTRIBUTE_MASK_SINGLETON (0x20)
// Attribute is a client attribute
#define ATTRIBUTE_MASK_CLIENT (0x40)

// Cluster masks modify how clusters are used by the framework
//
// Does this cluster have init function?
#define CLUSTER_MASK_INIT_FUNCTION (0x01)
// Does this cluster have attribute changed function?
#define CLUSTER_MASK_ATTRIBUTE_CHANGED_FUNCTION (0x02)
// Does this cluster have default response function?
#define CLUSTER_MASK_DEFAULT_RESPONSE_FUNCTION (0x04)
// Does this cluster have message sent function?
#define CLUSTER_MASK_MESSAGE_SENT_FUNCTION (0x08)
// Does this cluster have manufacturer specific attribute changed function?
#define CLUSTER_MASK_MANUFACTURER_SPECIFIC_ATTRIBUTE_CHANGED_FUNCTION (0x10)
// Does this cluster have pre-attribute changed function?
#define CLUSTER_MASK_PRE_ATTRIBUTE_CHANGED_FUNCTION (0x20)
// Cluster is a server
#define CLUSTER_MASK_SERVER (0x40)
// Cluster is a client
#define CLUSTER_MASK_CLIENT (0x80)

// Command masks modify meanings of commands
//
// Is sending of this client command supported
#define COMMAND_MASK_OUTGOING_CLIENT (0x01)
// Is sending of this server command supported
#define COMMAND_MASK_OUTGOING_SERVER (0x02)
// Is receiving of this client command supported
#define COMMAND_MASK_INCOMING_CLIENT (0x04)
// Is receiving of this server command supported
#define COMMAND_MASK_INCOMING_SERVER (0x08)
// Is this command manufacturer specific?
#define COMMAND_MASK_MANUFACTURER_SPECIFIC (0x10)
27 changes: 27 additions & 0 deletions src/app/zap-templates/attribute-id.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{chip_header}}

// Prevent multiple inclusion
#pragma once

{{#zcl_clusters}}
// Attribute ids for cluster: {{label}}

{{#zcl_attributes_client}}
{{#first}}
// Client attributes
{{/first}}
#define ZCL_{{asDelimitedMacro define}}_ATTRIBUTE_ID ({{asHex code 4}})
{{#last}}

{{/last}}
{{/zcl_attributes_client}}
{{#zcl_attributes_server}}
{{#first}}
// Server attributes
{{/first}}
#define ZCL_{{asDelimitedMacro define}}_ATTRIBUTE_ID ({{asHex code 4}})
{{#last}}

{{/last}}
{{/zcl_attributes_server}}
{{/zcl_clusters}}
20 changes: 20 additions & 0 deletions src/app/zap-templates/attribute-type.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{chip_header}}

// Prevent multiple inclusion
#pragma once

// ZCL attribute types
enum {
{{#zcl_atomics}}
{{ident}}ZCL_{{asDelimitedMacro name}}_ATTRIBUTE_TYPE = {{asHex atomicId 2}}, // {{description}}
{{/zcl_atomics}}
};

// ZCL attribute sizes
#define ZAP_GENERATED_ATTRIBUTE_SIZES { \
{{#zcl_atomics}}
{{#if size}}
{{ident}}ZCL_{{asDelimitedMacro name}}_ATTRIBUTE_TYPE, {{size}}, \
{{/if}}
{{/zcl_atomics}}
}
127 changes: 127 additions & 0 deletions src/app/zap-templates/call-command-handler-src.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{{chip_header}}

#include <stdint.h>

#include "af-structs.h"
#include "call-command-handler.h"
#include "callback.h"
#include "command-id.h"
#include "util.h"

{{#all_user_clusters}}
{{#if (isEnabled enabled)}}
EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd);
{{/if}}
{{/all_user_clusters}}


static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
{
if (wasHandled)
{
return EMBER_ZCL_STATUS_SUCCESS;
}
else if (mfgSpecific)
{
return EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND;
}
else if (clusterExists)
{
return EMBER_ZCL_STATUS_UNSUP_COMMAND;
}
else
{
return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
}
}


// Main command parsing controller.
EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
{
EmberAfStatus result = status(false, false, cmd->mfgSpecific);
if (cmd->direction == (uint8_t) ZCL_DIRECTION_SERVER_TO_CLIENT &&
emberAfContainsClientWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
{
switch (cmd->apsFrame->clusterId)
{
{{#all_user_clusters}}
{{#if (isEnabled enabled)}}
{{#if (isClient side) }}
case ZCL_{{asDelimitedMacro define}}_ID :
result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
break;
{{/if}}
{{/if}}
{{/all_user_clusters}}
default:
// Unrecognized cluster ID, error status will apply.
break;
}
}
else if (cmd->direction == (uint8_t) ZCL_DIRECTION_CLIENT_TO_SERVER &&
emberAfContainsServerWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
{
switch (cmd->apsFrame->clusterId)
{
{{#all_user_clusters}}
{{#if (isEnabled enabled)}}
{{#unless (isClient side) }}
case ZCL_{{asDelimitedMacro define}}_ID :
result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd);
break;
{{/unless}}
{{/if}}
{{/all_user_clusters}}
default:
// Unrecognized cluster ID, error status will apply.
break;
}
}
return result;
}

// Cluster specific command parsing

{{#all_user_clusters}}
{{#if (isEnabled enabled)}}
EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd)
{
bool wasHandled = false;

if (!cmd->mfgSpecific)
{
switch (cmd->commandId)
{
{{#all_user_cluster_commands}}
{{#if (isStrEqual clusterName parent.name)}}
{{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}}
case ZCL_{{asDelimitedMacro name}}_COMMAND_ID: {
{{#if (zcl_command_arguments_count this.id)}}
uint32_t argOffset = 0;
{{#zcl_command_arguments}}
{{asUnderlyingType type}} * {{asSymbol label}} = ({{asUnderlyingType type}} *)(cmd->buffer + argOffset);
{{#unless (isLastElement index count)}}
argOffset+= sizeof({{asUnderlyingType type}});
{{/unless}}
{{/zcl_command_arguments}}

wasHandled = emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback({{#zcl_command_arguments}} *{{asSymbol label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/zcl_command_arguments}});
{{else}}
wasHandled = emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback();
{{/if}}
break;
}
{{/if}}
{{/if}}
{{/all_user_cluster_commands}}
default: {
// Unrecognized command ID, error status will apply.
break;
}
}
}
return status(wasHandled, true, cmd->mfgSpecific);
}
{{/if}}
{{/all_user_clusters}}
6 changes: 6 additions & 0 deletions src/app/zap-templates/call-command-handler.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{chip_header}}

// Prevent multiple inclusion
#pragma once

#include "af-types.h"
67 changes: 67 additions & 0 deletions src/app/zap-templates/callback-stub-src.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{chip_header}}

#include "callback.h"
#include "cluster-id.h"

// Cluster Init Functions
void emberAfClusterInitCallback(uint8_t endpoint, EmberAfClusterId clusterId)
{
switch (clusterId)
{
{{#all_user_clusters_names}}
case ZCL_{{asDelimitedMacro define}}_ID :
emberAf{{asCamelCased name false}}ClusterInitCallback(endpoint);
break;
{{/all_user_clusters_names}}
default:
// Unrecognized cluster ID
break;
}
}

{{#all_user_clusters_names}}
void __attribute__((weak)) emberAf{{asCamelCased name false}}ClusterInitCallback(uint8_t endpoint)
{
// To prevent warning
(void) endpoint;
}
{{/all_user_clusters_names}}

// Cluster Command callback

{{#all_user_clusters}}
{{#if (isEnabled enabled)}}
{{#all_user_cluster_commands}}
{{#if (isStrEqual clusterName parent.name)}}
{{#if (isCommandAvailable parent.side incoming outgoing commandSource)}}
/**
* @brief {{parent.name}} Cluster {{name}} Command callback
{{#if (zcl_command_arguments_count this.id)}}
{{#zcl_command_arguments}}
* @param {{asCamelCased label}}
{{/zcl_command_arguments}}
{{/if}}
*/

{{#if (zcl_command_arguments_count this.id)}}
bool __attribute__((weak)) emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback({{#zcl_command_arguments}} {{asUnderlyingType type}} {{asSymbol label}}{{#unless (isLastElement index count)}}, {{/unless}}{{/zcl_command_arguments}})
{
// To prevent warning
{{#zcl_command_arguments}}
(void) {{asSymbol label}};
{{/zcl_command_arguments}}

return false;
}
{{else}}
bool __attribute__((weak)) emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback(void)
{
return false;
}
{{/if}}

{{/if}}
{{/if}}
{{/all_user_cluster_commands}}
{{/if}}
{{/all_user_clusters}}
Loading