From c2e5453f8dbe6b55577b267cea5e74a5d611d627 Mon Sep 17 00:00:00 2001 From: jepenven-silabs <67962328+jepenven-silabs@users.noreply.github.com> Date: Tue, 10 Nov 2020 11:43:40 -0500 Subject: [PATCH] Add ZAP templates to src/app (#3638) * Moved templates out of PR #3464 * fix PR comments * Moved template to src/app * Fix PR comments * Renamed src/app/zap to src/app/zap-templates * removed CLI define * Switch to pragma once * Restyled by whitespace * Restyled by clang-format * Restyled by prettier-json * Restyled by prettier-markdown Co-authored-by: Restyled.io --- src/app/docs/README.md | 5 + src/app/zap-templates/README.md | 26 ++++ src/app/zap-templates/af-structs.zapt | 17 +++ src/app/zap-templates/att-storage.zapt | 53 ++++++++ src/app/zap-templates/attribute-id.zapt | 27 ++++ src/app/zap-templates/attribute-type.zapt | 20 +++ .../call-command-handler-src.zapt | 127 ++++++++++++++++++ .../zap-templates/call-command-handler.zapt | 6 + src/app/zap-templates/callback-stub-src.zapt | 67 +++++++++ src/app/zap-templates/callback.zapt | 53 ++++++++ src/app/zap-templates/chip-templates.json | 72 ++++++++++ .../zap-templates/client-command-macro.zapt | 6 + src/app/zap-templates/cluster-id.zapt | 11 ++ src/app/zap-templates/command-id.zapt | 19 +++ src/app/zap-templates/endpoint_config.zapt | 6 + src/app/zap-templates/enums.zapt | 23 ++++ src/app/zap-templates/gen_config.zapt | 18 +++ src/app/zap-templates/helper-chip.js | 83 ++++++++++++ src/app/zap-templates/print-cluster.zapt | 24 ++++ 19 files changed, 663 insertions(+) create mode 100644 src/app/zap-templates/README.md create mode 100644 src/app/zap-templates/af-structs.zapt create mode 100644 src/app/zap-templates/att-storage.zapt create mode 100644 src/app/zap-templates/attribute-id.zapt create mode 100644 src/app/zap-templates/attribute-type.zapt create mode 100644 src/app/zap-templates/call-command-handler-src.zapt create mode 100644 src/app/zap-templates/call-command-handler.zapt create mode 100644 src/app/zap-templates/callback-stub-src.zapt create mode 100644 src/app/zap-templates/callback.zapt create mode 100644 src/app/zap-templates/chip-templates.json create mode 100644 src/app/zap-templates/client-command-macro.zapt create mode 100644 src/app/zap-templates/cluster-id.zapt create mode 100644 src/app/zap-templates/command-id.zapt create mode 100644 src/app/zap-templates/endpoint_config.zapt create mode 100644 src/app/zap-templates/enums.zapt create mode 100644 src/app/zap-templates/gen_config.zapt create mode 100644 src/app/zap-templates/helper-chip.js create mode 100644 src/app/zap-templates/print-cluster.zapt diff --git a/src/app/docs/README.md b/src/app/docs/README.md index afaca66c2370d2..307f787ac5177d 100644 --- a/src/app/docs/README.md +++ b/src/app/docs/README.md @@ -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. +### /src/app/zap-templates + +This directory contains all of the templates and helpers specific to CHIP for +the ZAP tool. + ## Public APIs ### Attribute changes diff --git a/src/app/zap-templates/README.md b/src/app/zap-templates/README.md new file mode 100644 index 00000000000000..0b51ba643be11c --- /dev/null +++ b/src/app/zap-templates/README.md @@ -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 -o +``` + +For more information please see the documentation under `docs/` in +[ZAP](https://github.com/project-chip/zap) diff --git a/src/app/zap-templates/af-structs.zapt b/src/app/zap-templates/af-structs.zapt new file mode 100644 index 00000000000000..e662044f78bdf1 --- /dev/null +++ b/src/app/zap-templates/af-structs.zapt @@ -0,0 +1,17 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +#include +#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}} diff --git a/src/app/zap-templates/att-storage.zapt b/src/app/zap-templates/att-storage.zapt new file mode 100644 index 00000000000000..b0491aa268a312 --- /dev/null +++ b/src/app/zap-templates/att-storage.zapt @@ -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) diff --git a/src/app/zap-templates/attribute-id.zapt b/src/app/zap-templates/attribute-id.zapt new file mode 100644 index 00000000000000..203aa4c1a22f19 --- /dev/null +++ b/src/app/zap-templates/attribute-id.zapt @@ -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}} diff --git a/src/app/zap-templates/attribute-type.zapt b/src/app/zap-templates/attribute-type.zapt new file mode 100644 index 00000000000000..d7319af9e1c99d --- /dev/null +++ b/src/app/zap-templates/attribute-type.zapt @@ -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}} +} diff --git a/src/app/zap-templates/call-command-handler-src.zapt b/src/app/zap-templates/call-command-handler-src.zapt new file mode 100644 index 00000000000000..4fac1a5f31b442 --- /dev/null +++ b/src/app/zap-templates/call-command-handler-src.zapt @@ -0,0 +1,127 @@ +{{chip_header}} + +#include + +#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}} \ No newline at end of file diff --git a/src/app/zap-templates/call-command-handler.zapt b/src/app/zap-templates/call-command-handler.zapt new file mode 100644 index 00000000000000..6ab97918f1a89c --- /dev/null +++ b/src/app/zap-templates/call-command-handler.zapt @@ -0,0 +1,6 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +#include "af-types.h" diff --git a/src/app/zap-templates/callback-stub-src.zapt b/src/app/zap-templates/callback-stub-src.zapt new file mode 100644 index 00000000000000..24f843e81f7f0f --- /dev/null +++ b/src/app/zap-templates/callback-stub-src.zapt @@ -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}} \ No newline at end of file diff --git a/src/app/zap-templates/callback.zapt b/src/app/zap-templates/callback.zapt new file mode 100644 index 00000000000000..5dd06a9d53fa45 --- /dev/null +++ b/src/app/zap-templates/callback.zapt @@ -0,0 +1,53 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +#include "af-structs.h" +#include "af-types.h" + +/** @brief Cluster Init + * + * This function is called when a specific cluster is initialized. It gives the + * application an opportunity to take care of cluster initialization procedures. + * It is called exactly once for each endpoint where cluster is present. + * + * @param endpoint Ver.: always + * @param clusterId Ver.: always + */ +void emberAfClusterInitCallback(uint8_t endpoint, EmberAfClusterId clusterId); + +// Cluster Init Functions +{{#all_user_clusters_names}} +void emberAf{{asCamelCased name false}}ClusterInitCallback(uint8_t endpoint); +{{/all_user_clusters_names}} + + +// Cluster Commands 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 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}}); +{{else}} +bool emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}}Callback(void); +{{/if}} + + +{{/if}} +{{/if}} +{{/all_user_cluster_commands}} +{{/if}} +{{/all_user_clusters}} diff --git a/src/app/zap-templates/chip-templates.json b/src/app/zap-templates/chip-templates.json new file mode 100644 index 00000000000000..3d46473c12855b --- /dev/null +++ b/src/app/zap-templates/chip-templates.json @@ -0,0 +1,72 @@ +{ + "name": "CHIP templates", + "version": "chip-v1", + "helpers": ["helper-chip.js"], + "templates": [ + { + "path": "af-structs.zapt", + "name": "ZCL af-structs header", + "output": "af-structs.h" + }, + { + "path": "att-storage.zapt", + "name": "ZCL att-storage header", + "output": "att-storage.h" + }, + { + "path": "attribute-id.zapt", + "name": "ZCL attribute-id header", + "output": "attribute-id.h" + }, + { + "path": "attribute-type.zapt", + "name": "ZCL attribute-type header", + "output": "attribute-type.h" + }, + { + "path": "call-command-handler-src.zapt", + "name": "ZCL call-command-handler source", + "output": "call-command-handler.c" + }, + { + "path": "call-command-handler.zapt", + "name": "ZCL call-command-handler header", + "output": "call-command-handler.h" + }, + { + "path": "callback-stub-src.zapt", + "name": "ZCL callback-stub source", + "output": "callback-stub.c" + }, + { + "path": "callback.zapt", + "name": "ZCL callback header", + "output": "callback.h" + }, + { + "path": "cluster-id.zapt", + "name": "ZCL cluster-id header", + "output": "cluster-id.h" + }, + { + "path": "command-id.zapt", + "name": "ZCL command-id header", + "output": "command-id.h" + }, + { + "path": "enums.zapt", + "name": "ZCL enums header", + "output": "enums.h" + }, + { + "path": "gen_config.zapt", + "name": "ZCL gen_config header", + "output": "gen_config.h" + }, + { + "path": "print-cluster.zapt", + "name": "ZCL print-cluster header", + "output": "print-cluster.h" + } + ] +} diff --git a/src/app/zap-templates/client-command-macro.zapt b/src/app/zap-templates/client-command-macro.zapt new file mode 100644 index 00000000000000..fba147fa7ab0d7 --- /dev/null +++ b/src/app/zap-templates/client-command-macro.zapt @@ -0,0 +1,6 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +// TODO issue #3637 diff --git a/src/app/zap-templates/cluster-id.zapt b/src/app/zap-templates/cluster-id.zapt new file mode 100644 index 00000000000000..4331eb3b5ffe90 --- /dev/null +++ b/src/app/zap-templates/cluster-id.zapt @@ -0,0 +1,11 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +{{#zcl_clusters}} + +// Definitions for cluster: {{label}} +#define ZCL_{{asDelimitedMacro define}}_ID ({{asHex code 4}}) + +{{/zcl_clusters}} diff --git a/src/app/zap-templates/command-id.zapt b/src/app/zap-templates/command-id.zapt new file mode 100644 index 00000000000000..74a95c5a707fbe --- /dev/null +++ b/src/app/zap-templates/command-id.zapt @@ -0,0 +1,19 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +// Global, non-cluster-specific commands +{{#zcl_global_commands}} +#define ZCL_{{asDelimitedMacro label}}_COMMAND_ID ({{asHex code 2}}) +{{/zcl_global_commands}} + +{{#zcl_clusters}} + +{{#zcl_commands}} +{{#first}} +// Commands for cluster: {{parent.label}} +{{/first}} +#define ZCL_{{asDelimitedMacro label}}_COMMAND_ID ({{asHex code 2}}) +{{/zcl_commands}} +{{/zcl_clusters}} diff --git a/src/app/zap-templates/endpoint_config.zapt b/src/app/zap-templates/endpoint_config.zapt new file mode 100644 index 00000000000000..fba147fa7ab0d7 --- /dev/null +++ b/src/app/zap-templates/endpoint_config.zapt @@ -0,0 +1,6 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +// TODO issue #3637 diff --git a/src/app/zap-templates/enums.zapt b/src/app/zap-templates/enums.zapt new file mode 100644 index 00000000000000..729329ae2aa38d --- /dev/null +++ b/src/app/zap-templates/enums.zapt @@ -0,0 +1,23 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +// ZCL enums + +{{#zcl_enums}} + +// Enum for {{label}} +typedef enum { +{{#zcl_enum_items}} +{{ident}}EMBER_ZCL_{{asDelimitedMacro parent.label}}_{{asDelimitedMacro label}} = {{value}}, +{{/zcl_enum_items}} +} EmberAf{{asType label}}; +{{/zcl_enums}} + +{{#zcl_bitmaps}} +{{#zcl_bitmap_items}} +#define EMBER_AF_{{asDelimitedMacro parent.label}}_{{asDelimitedMacro label}} ({{mask}}) +#define EMBER_AF_{{asDelimitedMacro parent.label}}_{{asDelimitedMacro label}}_OFFSET ({{asOffset mask}}) +{{/zcl_bitmap_items}} +{{/zcl_bitmaps}} diff --git a/src/app/zap-templates/gen_config.zapt b/src/app/zap-templates/gen_config.zapt new file mode 100644 index 00000000000000..5cc04b04c1588f --- /dev/null +++ b/src/app/zap-templates/gen_config.zapt @@ -0,0 +1,18 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +// User options for plugin Binding Table Library +#define EMBER_BINDING_TABLE_SIZE 10 + +/**** Network Section ****/ +#define EMBER_SUPPORTED_NETWORKS (1) + + +#define EMBER_APS_UNICAST_MESSAGE_COUNT 10 + +/**** Cluster endpoint counts ****/ +{{#all_user_clusters}} +#define EMBER_AF_{{asDelimitedMacro define}}_{{asDelimitedMacro side}}_ENDPOINT_COUNT ({{user_endpoint_count_by_cluster id side}}) +{{/all_user_clusters}} diff --git a/src/app/zap-templates/helper-chip.js b/src/app/zap-templates/helper-chip.js new file mode 100644 index 00000000000000..13b78afe17232a --- /dev/null +++ b/src/app/zap-templates/helper-chip.js @@ -0,0 +1,83 @@ +/* + * + * Copyright (c) 2020 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * This module contains the API for templating. For more detailed instructions, read {@tutorial template-tutorial} + * + * @module Templating API: toplevel utility helpers + */ + +/** + * Produces the top-of-the-file header for a C file. + * + * @returns The header content + */ +function chip_header() { + return ` + /* + * + * Copyright (c) 2020 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */`; +} + +function isClient(side) { return 0 == side.localeCompare("client"); } + +function isServer(side) { return 0 == side.localeCompare("server"); } + +function isStrEqual(str1, str2) { return 0 == str1.localeCompare(str2); } + +function isLastElement(index, count) { return index == count - 1; } + +function isEnabled(enable) { return 1 == enable; } + +function isCommandAvailable(clusterSide, incoming, outgoing, source, name) { + if (0 == clusterSide.localeCompare(source)) { + return false; + } + + if (isClient(clusterSide) && outgoing) { + return true; + } else if (isServer(clusterSide) && incoming) { + return true; + } + return false; +} + +// WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! +// +// Note: these exports are public API. Templates that might have been created in the past and are +// available in the wild might depend on these names. +// If you rename the functions, you need to still maintain old exports list. +exports.chip_header = chip_header; +exports.isClient = isClient; +exports.isServer = isServer; +exports.isStrEqual = isStrEqual; +exports.isLastElement = isLastElement; +exports.isEnabled = isEnabled; +exports.isCommandAvailable = isCommandAvailable; diff --git a/src/app/zap-templates/print-cluster.zapt b/src/app/zap-templates/print-cluster.zapt new file mode 100644 index 00000000000000..7bed5cca10f338 --- /dev/null +++ b/src/app/zap-templates/print-cluster.zapt @@ -0,0 +1,24 @@ +{{chip_header}} + +// Prevent multiple inclusion +#pragma once + +// This is the mapping of IDs to cluster names assuming a format according +// to the "EmberAfClusterName" defined in the ZCL header. +// The names of clusters that are not present, are removed. + +{{#zcl_clusters}} +#if defined(ZCL_USING_{{asDelimitedMacro this.define}}_SERVER) || defined(ZCL_USING_{{asDelimitedMacro this.define}}_CLIENT) + #define CHIP_PRINTCLUSTER_{{asDelimitedMacro this.define}} {ZCL_{{asDelimitedMacro this.define}}_ID, {{this.code}}, "{{this.label}}" }, +#else + #define CHIP_PRINTCLUSTER_{{asDelimitedMacro this.define}} +#endif + +{{/zcl_clusters}} + +#define CLUSTER_IDS_TO_NAMES \ +{{#zcl_clusters}} + CHIP_PRINTCLUSTER_{{asDelimitedMacro this.define}} \ +{{/zcl_clusters}} + +#define MAX_CLUSTER_NAME_LENGTH {{zcl_cluster_largest_label_length}}