From 6288a987e28002be551e72e637aacf388f1a9448 Mon Sep 17 00:00:00 2001 From: jfpenven Date: Tue, 3 Nov 2020 22:09:25 -0500 Subject: [PATCH 01/11] Moved templates out of PR #3464 --- third_party/zap/templates/README.md | 26 ++++ third_party/zap/templates/af-structs.zapt | 20 +++ third_party/zap/templates/att-storage.zapt | 52 +++++++ third_party/zap/templates/attribute-id.zapt | 30 ++++ third_party/zap/templates/attribute-type.zapt | 22 +++ .../templates/call-command-handler-src.zapt | 129 ++++++++++++++++++ .../zap/templates/call-command-handler.zapt | 9 ++ .../zap/templates/callback-stub-src.zapt | 69 ++++++++++ third_party/zap/templates/callback.zapt | 56 ++++++++ third_party/zap/templates/chip-templates.json | 81 +++++++++++ .../zap/templates/client-command-macro.zapt | 3 + third_party/zap/templates/cluster-id.zapt | 13 ++ third_party/zap/templates/command-id.zapt | 21 +++ .../zap/templates/endpoint_config.zapt | 4 + third_party/zap/templates/enums.zapt | 25 ++++ third_party/zap/templates/gen_config.zapt | 23 ++++ third_party/zap/templates/helper-chip.js | 93 +++++++++++++ third_party/zap/templates/print-cluster.zapt | 30 ++++ 18 files changed, 706 insertions(+) create mode 100644 third_party/zap/templates/README.md create mode 100644 third_party/zap/templates/af-structs.zapt create mode 100644 third_party/zap/templates/att-storage.zapt create mode 100644 third_party/zap/templates/attribute-id.zapt create mode 100644 third_party/zap/templates/attribute-type.zapt create mode 100644 third_party/zap/templates/call-command-handler-src.zapt create mode 100644 third_party/zap/templates/call-command-handler.zapt create mode 100644 third_party/zap/templates/callback-stub-src.zapt create mode 100644 third_party/zap/templates/callback.zapt create mode 100644 third_party/zap/templates/chip-templates.json create mode 100644 third_party/zap/templates/client-command-macro.zapt create mode 100644 third_party/zap/templates/cluster-id.zapt create mode 100644 third_party/zap/templates/command-id.zapt create mode 100644 third_party/zap/templates/endpoint_config.zapt create mode 100644 third_party/zap/templates/enums.zapt create mode 100644 third_party/zap/templates/gen_config.zapt create mode 100644 third_party/zap/templates/helper-chip.js create mode 100644 third_party/zap/templates/print-cluster.zapt diff --git a/third_party/zap/templates/README.md b/third_party/zap/templates/README.md new file mode 100644 index 00000000000000..9ef77d74cf13cc --- /dev/null +++ b/third_party/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. + +# Usefull command for CHIP + +Run ZAP with UI to configure endpoints and clusters + +``` + +node src-script/zap-start.js --logToStdout --gen ../templates/chip-templates.json +``` + +Generate files in headless mode + +``` + +node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ../templates/chip_templates.json -i -o +``` + +For more information please see the documentation under +third_party/zap/repo/docs/ diff --git a/third_party/zap/templates/af-structs.zapt b/third_party/zap/templates/af-structs.zapt new file mode 100644 index 00000000000000..c4c426b35e5d61 --- /dev/null +++ b/third_party/zap/templates/af-structs.zapt @@ -0,0 +1,20 @@ +{{chip_header}} + + +#ifndef SILABS_EMBER_AF_STRUCTS +#define SILABS_EMBER_AF_STRUCTS + +#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}} + +#endif // SILABS_EMBER_AF_STRUCTS \ No newline at end of file diff --git a/third_party/zap/templates/att-storage.zapt b/third_party/zap/templates/att-storage.zapt new file mode 100644 index 00000000000000..a6448d329e0f7d --- /dev/null +++ b/third_party/zap/templates/att-storage.zapt @@ -0,0 +1,52 @@ +{{chip_header}} + +// Enclosing macro to prevent multiple inclusion +#ifndef SILABS_ATTRIBUTE_STORAGE_GEN +#define SILABS_ATTRIBUTE_STORAGE_GEN + +// 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) +#endif // SILABS_ATTRIBUTE_STORAGE_GEN \ No newline at end of file diff --git a/third_party/zap/templates/attribute-id.zapt b/third_party/zap/templates/attribute-id.zapt new file mode 100644 index 00000000000000..62dc6e94443ced --- /dev/null +++ b/third_party/zap/templates/attribute-id.zapt @@ -0,0 +1,30 @@ +{{chip_header}} + +// Enclosing macro to prevent multiple inclusion +#ifndef ZAP_EMBER_ATTRIBUTE_ID +#define ZAP_EMBER_ATTRIBUTE_ID + +{{#zcl_clusters}} +// Attribute id 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}} + +#endif // ZAP_EMBER_ATTRIBUTE_ID \ No newline at end of file diff --git a/third_party/zap/templates/attribute-type.zapt b/third_party/zap/templates/attribute-type.zapt new file mode 100644 index 00000000000000..20fdc106ec8c8c --- /dev/null +++ b/third_party/zap/templates/attribute-type.zapt @@ -0,0 +1,22 @@ +{{chip_header}} + +#ifndef __ZAP_ATTRIBUTE_TYPE__ +#define __ZAP_ATTRIBUTE_TYPE__ + +// 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}} +} + +#endif // __ZAP_ATTRIBUTE_TYPE__ \ No newline at end of file diff --git a/third_party/zap/templates/call-command-handler-src.zapt b/third_party/zap/templates/call-command-handler-src.zapt new file mode 100644 index 00000000000000..12c2992ec046af --- /dev/null +++ b/third_party/zap/templates/call-command-handler-src.zapt @@ -0,0 +1,129 @@ +{{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 (isEnable 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 (isEnable 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 (isEnable 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 (isEnable 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/third_party/zap/templates/call-command-handler.zapt b/third_party/zap/templates/call-command-handler.zapt new file mode 100644 index 00000000000000..0bfd72443eb511 --- /dev/null +++ b/third_party/zap/templates/call-command-handler.zapt @@ -0,0 +1,9 @@ +{{chip_header}} + + +#ifndef CALL_COMMAND_HANDLER +#define CALL_COMMAND_HANDLER + +#include "af-types.h" + +#endif //CALL_COMMAND_HANDLER diff --git a/third_party/zap/templates/callback-stub-src.zapt b/third_party/zap/templates/callback-stub-src.zapt new file mode 100644 index 00000000000000..d065e3243b6497 --- /dev/null +++ b/third_party/zap/templates/callback-stub-src.zapt @@ -0,0 +1,69 @@ +{{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 (isEnable 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/third_party/zap/templates/callback.zapt b/third_party/zap/templates/callback.zapt new file mode 100644 index 00000000000000..572cc9a80be6ec --- /dev/null +++ b/third_party/zap/templates/callback.zapt @@ -0,0 +1,56 @@ +{{chip_header}} + + +#ifndef ZCL_CALLBACK_HEADER +#define ZCL_CALLBACK_HEADER + +#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 (isEnable 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}} + +#endif //ZCL_CALLBACK_HEADER \ No newline at end of file diff --git a/third_party/zap/templates/chip-templates.json b/third_party/zap/templates/chip-templates.json new file mode 100644 index 00000000000000..ac1058c788d396 --- /dev/null +++ b/third_party/zap/templates/chip-templates.json @@ -0,0 +1,81 @@ +{ + "name": "Test templates", + "version": "test-v1", + "options": { + "testOption": { + "code1": "label1", + "code2": "label2", + "code3": "label3", + "code4": "label4", + "code5": "label5" + } + }, + "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/third_party/zap/templates/client-command-macro.zapt b/third_party/zap/templates/client-command-macro.zapt new file mode 100644 index 00000000000000..c6a5ffa29d7d6c --- /dev/null +++ b/third_party/zap/templates/client-command-macro.zapt @@ -0,0 +1,3 @@ +{{chip_header}} + +// TODO issue #3637 diff --git a/third_party/zap/templates/cluster-id.zapt b/third_party/zap/templates/cluster-id.zapt new file mode 100644 index 00000000000000..7982e7fd03f996 --- /dev/null +++ b/third_party/zap/templates/cluster-id.zapt @@ -0,0 +1,13 @@ +{{chip_header}} + +#ifndef __ZAP_CLUSTER_ID__ +#define __ZAP_CLUSTER_ID__ + +{{#zcl_clusters}} + +// Definitions for cluster: {{label}} +#define ZCL_{{asDelimitedMacro define}}_ID ({{asHex code 4}}) + +{{/zcl_clusters}} + +#endif // __ZAP_CLUSTER_ID__ \ No newline at end of file diff --git a/third_party/zap/templates/command-id.zapt b/third_party/zap/templates/command-id.zapt new file mode 100644 index 00000000000000..ad723a7ac5bd8f --- /dev/null +++ b/third_party/zap/templates/command-id.zapt @@ -0,0 +1,21 @@ +{{chip_header}} + +#ifndef __ZAP_GEN_ID__ +#define __ZAP_GEN_ID__ + +// 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}} + +#endif // __ZAP_GEN_ID__ \ No newline at end of file diff --git a/third_party/zap/templates/endpoint_config.zapt b/third_party/zap/templates/endpoint_config.zapt new file mode 100644 index 00000000000000..f0d0d6e27c76ee --- /dev/null +++ b/third_party/zap/templates/endpoint_config.zapt @@ -0,0 +1,4 @@ +{{chip_header}} + + +// TODO issue #3637 diff --git a/third_party/zap/templates/enums.zapt b/third_party/zap/templates/enums.zapt new file mode 100644 index 00000000000000..a0df907da3a729 --- /dev/null +++ b/third_party/zap/templates/enums.zapt @@ -0,0 +1,25 @@ +{{chip_header}} + +#ifndef __ZAP_EMBER_ENUMS__ +#define __ZAP_EMBER_ENUMS__ + +// 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}} + +#endif //__ZAP_EMBER_ENUMS__ \ No newline at end of file diff --git a/third_party/zap/templates/gen_config.zapt b/third_party/zap/templates/gen_config.zapt new file mode 100644 index 00000000000000..37a219e3e83ced --- /dev/null +++ b/third_party/zap/templates/gen_config.zapt @@ -0,0 +1,23 @@ +{{chip_header}} + +#ifndef __ZAP_GEN_CONFIG__ +#define __ZAP_GEN_CONFIG__ +// 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 + +/**** CLI Section ****/ +#define EMBER_AF_GENERATE_CLI + + +/**** 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}} + +#endif // __ZAP_GEN_CONFIG__ \ No newline at end of file diff --git a/third_party/zap/templates/helper-chip.js b/third_party/zap/templates/helper-chip.js new file mode 100644 index 00000000000000..97ae38a56c8811 --- /dev/null +++ b/third_party/zap/templates/helper-chip.js @@ -0,0 +1,93 @@ +/* +* +* 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 isEnable(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.isEnable = isEnable; +exports.isCommandAvailable = isCommandAvailable; diff --git a/third_party/zap/templates/print-cluster.zapt b/third_party/zap/templates/print-cluster.zapt new file mode 100644 index 00000000000000..7dba648146ba10 --- /dev/null +++ b/third_party/zap/templates/print-cluster.zapt @@ -0,0 +1,30 @@ +{{chip_header}} + + +// Enclosing macro to prevent multiple inclusion +#ifndef SILABS_PRINT_CLUSTER +#define SILABS_PRINT_CLUSTER + + +// 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 SILABS_PRINTCLUSTER_{{asDelimitedMacro this.define}} {ZCL_{{asDelimitedMacro this.define}}_ID, {{this.code}}, "{{this.label}}" }, +#else + #define SILABS_PRINTCLUSTER_{{asDelimitedMacro this.define}} +#endif + +{{/zcl_clusters}} + +#define CLUSTER_IDS_TO_NAMES \ +{{#zcl_clusters}} + SILABS_PRINTCLUSTER_{{asDelimitedMacro this.define}} \ +{{/zcl_clusters}} + +#define MAX_CLUSTER_NAME_LENGTH {{zcl_cluster_largest_label_length}} + +// Enclosing macro to prevent multiple inclusion +#endif // SILABS_PRINT_CLUSTER From c746990fbe55e96ef9078087791b8a013517ff62 Mon Sep 17 00:00:00 2001 From: jfpenven Date: Wed, 4 Nov 2020 09:05:29 -0500 Subject: [PATCH 02/11] fix PR comments --- third_party/zap/templates/README.md | 8 ++++---- third_party/zap/templates/call-command-handler-src.zapt | 8 ++++---- third_party/zap/templates/callback-stub-src.zapt | 2 +- third_party/zap/templates/callback.zapt | 2 +- third_party/zap/templates/gen_config.zapt | 1 + third_party/zap/templates/helper-chip.js | 4 ++-- third_party/zap/templates/print-cluster.zapt | 6 +++--- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/third_party/zap/templates/README.md b/third_party/zap/templates/README.md index 9ef77d74cf13cc..6819e1c4ea9e8c 100644 --- a/third_party/zap/templates/README.md +++ b/third_party/zap/templates/README.md @@ -6,21 +6,21 @@ This directory contains generation templates for ZAP, ZCL Advanced Platform. **IMPORTANT**: Changes to templates will affect all examples. -# Usefull command for CHIP +# 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 ../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 ../templates/chip_templates.json -i -o ``` For more information please see the documentation under -third_party/zap/repo/docs/ +`docs/` in [ZAP](https://github.com/project-chip/zap) diff --git a/third_party/zap/templates/call-command-handler-src.zapt b/third_party/zap/templates/call-command-handler-src.zapt index 12c2992ec046af..4798b822247723 100644 --- a/third_party/zap/templates/call-command-handler-src.zapt +++ b/third_party/zap/templates/call-command-handler-src.zapt @@ -9,7 +9,7 @@ #include "util.h" {{#all_user_clusters}} -{{#if (isEnable enabled)}} +{{#if (isEnabled enabled)}} EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd); {{/if}} {{/all_user_clusters}} @@ -46,7 +46,7 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd) switch (cmd->apsFrame->clusterId) { {{#all_user_clusters}} - {{#if (isEnable enabled)}} + {{#if (isEnabled enabled)}} {{#if (isClient side) }} case ZCL_{{asDelimitedMacro define}}_ID : result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd); @@ -65,7 +65,7 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd) switch (cmd->apsFrame->clusterId) { {{#all_user_clusters}} - {{#if (isEnable enabled)}} + {{#if (isEnabled enabled)}} {{#unless (isClient side) }} case ZCL_{{asDelimitedMacro define}}_ID : result = emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(cmd); @@ -85,7 +85,7 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd) // Cluster specific command parsing {{#all_user_clusters}} -{{#if (isEnable enabled)}} +{{#if (isEnabled enabled)}} EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false}}CommandParse(EmberAfClusterCommand * cmd) { bool wasHandled = false; diff --git a/third_party/zap/templates/callback-stub-src.zapt b/third_party/zap/templates/callback-stub-src.zapt index d065e3243b6497..7fd109d8188604 100644 --- a/third_party/zap/templates/callback-stub-src.zapt +++ b/third_party/zap/templates/callback-stub-src.zapt @@ -32,7 +32,7 @@ void __attribute__((weak)) emberAf{{asCamelCased name false}}ClusterInitCallback // Cluster Command callback {{#all_user_clusters}} -{{#if (isEnable enabled)}} +{{#if (isEnabled enabled)}} {{#all_user_cluster_commands}} {{#if (isStrEqual clusterName parent.name)}} {{#if (isCommandAvailable parent.side incoming outgoing commandSource)}} diff --git a/third_party/zap/templates/callback.zapt b/third_party/zap/templates/callback.zapt index 572cc9a80be6ec..ff1952d6a85d4a 100644 --- a/third_party/zap/templates/callback.zapt +++ b/third_party/zap/templates/callback.zapt @@ -27,7 +27,7 @@ void emberAf{{asCamelCased name false}}ClusterInitCallback(uint8_t endpoint); // CLuster Commands Callback {{#all_user_clusters}} -{{#if (isEnable enabled)}} +{{#if (isEnabled enabled)}} {{#all_user_cluster_commands}} {{#if (isStrEqual clusterName parent.name)}} {{#if (isCommandAvailable parent.side incoming outgoing commandSource)}} diff --git a/third_party/zap/templates/gen_config.zapt b/third_party/zap/templates/gen_config.zapt index 37a219e3e83ced..b3091ec9cd35e1 100644 --- a/third_party/zap/templates/gen_config.zapt +++ b/third_party/zap/templates/gen_config.zapt @@ -2,6 +2,7 @@ #ifndef __ZAP_GEN_CONFIG__ #define __ZAP_GEN_CONFIG__ + // User options for plugin Binding Table Library #define EMBER_BINDING_TABLE_SIZE 10 diff --git a/third_party/zap/templates/helper-chip.js b/third_party/zap/templates/helper-chip.js index 97ae38a56c8811..0a77fba2a3e574 100644 --- a/third_party/zap/templates/helper-chip.js +++ b/third_party/zap/templates/helper-chip.js @@ -62,7 +62,7 @@ function isLastElement(index, count) { return index == count - 1; } -function isEnable(enable) { +function isEnabled(enable) { return 1 == enable; } @@ -89,5 +89,5 @@ exports.isClient = isClient; exports.isServer = isServer; exports.isStrEqual = isStrEqual; exports.isLastElement = isLastElement; -exports.isEnable = isEnable; +exports.isEnabled = isEnabled; exports.isCommandAvailable = isCommandAvailable; diff --git a/third_party/zap/templates/print-cluster.zapt b/third_party/zap/templates/print-cluster.zapt index 7dba648146ba10..96430556213052 100644 --- a/third_party/zap/templates/print-cluster.zapt +++ b/third_party/zap/templates/print-cluster.zapt @@ -12,16 +12,16 @@ {{#zcl_clusters}} #if defined(ZCL_USING_{{asDelimitedMacro this.define}}_SERVER) || defined(ZCL_USING_{{asDelimitedMacro this.define}}_CLIENT) - #define SILABS_PRINTCLUSTER_{{asDelimitedMacro this.define}} {ZCL_{{asDelimitedMacro this.define}}_ID, {{this.code}}, "{{this.label}}" }, + #define CHIP_PRINTCLUSTER_{{asDelimitedMacro this.define}} {ZCL_{{asDelimitedMacro this.define}}_ID, {{this.code}}, "{{this.label}}" }, #else - #define SILABS_PRINTCLUSTER_{{asDelimitedMacro this.define}} + #define CHIP_PRINTCLUSTER_{{asDelimitedMacro this.define}} #endif {{/zcl_clusters}} #define CLUSTER_IDS_TO_NAMES \ {{#zcl_clusters}} - SILABS_PRINTCLUSTER_{{asDelimitedMacro this.define}} \ + CHIP_PRINTCLUSTER_{{asDelimitedMacro this.define}} \ {{/zcl_clusters}} #define MAX_CLUSTER_NAME_LENGTH {{zcl_cluster_largest_label_length}} From 60ea0df442e3a334dc975e4eb075d64184bf26d9 Mon Sep 17 00:00:00 2001 From: jfpenven Date: Thu, 5 Nov 2020 12:42:47 -0500 Subject: [PATCH 03/11] Moved template to src/app --- src/app/docs/README.md | 4 ++++ {third_party/zap/templates => src/app/zap}/README.md | 4 ++-- {third_party/zap/templates => src/app/zap}/af-structs.zapt | 0 {third_party/zap/templates => src/app/zap}/att-storage.zapt | 0 {third_party/zap/templates => src/app/zap}/attribute-id.zapt | 0 .../zap/templates => src/app/zap}/attribute-type.zapt | 0 .../templates => src/app/zap}/call-command-handler-src.zapt | 0 .../zap/templates => src/app/zap}/call-command-handler.zapt | 0 .../zap/templates => src/app/zap}/callback-stub-src.zapt | 0 {third_party/zap/templates => src/app/zap}/callback.zapt | 0 .../zap/templates => src/app/zap}/chip-templates.json | 0 .../zap/templates => src/app/zap}/client-command-macro.zapt | 0 {third_party/zap/templates => src/app/zap}/cluster-id.zapt | 0 {third_party/zap/templates => src/app/zap}/command-id.zapt | 0 .../zap/templates => src/app/zap}/endpoint_config.zapt | 0 {third_party/zap/templates => src/app/zap}/enums.zapt | 0 {third_party/zap/templates => src/app/zap}/gen_config.zapt | 0 {third_party/zap/templates => src/app/zap}/helper-chip.js | 0 {third_party/zap/templates => src/app/zap}/print-cluster.zapt | 0 19 files changed, 6 insertions(+), 2 deletions(-) rename {third_party/zap/templates => src/app/zap}/README.md (74%) rename {third_party/zap/templates => src/app/zap}/af-structs.zapt (100%) rename {third_party/zap/templates => src/app/zap}/att-storage.zapt (100%) rename {third_party/zap/templates => src/app/zap}/attribute-id.zapt (100%) rename {third_party/zap/templates => src/app/zap}/attribute-type.zapt (100%) rename {third_party/zap/templates => src/app/zap}/call-command-handler-src.zapt (100%) rename {third_party/zap/templates => src/app/zap}/call-command-handler.zapt (100%) rename {third_party/zap/templates => src/app/zap}/callback-stub-src.zapt (100%) rename {third_party/zap/templates => src/app/zap}/callback.zapt (100%) rename {third_party/zap/templates => src/app/zap}/chip-templates.json (100%) rename {third_party/zap/templates => src/app/zap}/client-command-macro.zapt (100%) rename {third_party/zap/templates => src/app/zap}/cluster-id.zapt (100%) rename {third_party/zap/templates => src/app/zap}/command-id.zapt (100%) rename {third_party/zap/templates => src/app/zap}/endpoint_config.zapt (100%) rename {third_party/zap/templates => src/app/zap}/enums.zapt (100%) rename {third_party/zap/templates => src/app/zap}/gen_config.zapt (100%) rename {third_party/zap/templates => src/app/zap}/helper-chip.js (100%) rename {third_party/zap/templates => src/app/zap}/print-cluster.zapt (100%) diff --git a/src/app/docs/README.md b/src/app/docs/README.md index afaca66c2370d2..234369e3d2f83b 100644 --- a/src/app/docs/README.md +++ b/src/app/docs/README.md @@ -29,6 +29,10 @@ 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> + +This directory contains all of the templates and helpers specific to CHIP for the ZAP tool. + ## Public APIs ### Attribute changes diff --git a/third_party/zap/templates/README.md b/src/app/zap/README.md similarity index 74% rename from third_party/zap/templates/README.md rename to src/app/zap/README.md index 6819e1c4ea9e8c..ca29e9cf03cce2 100644 --- a/third_party/zap/templates/README.md +++ b/src/app/zap/README.md @@ -12,14 +12,14 @@ Run ZAP with UI to configure endpoints and clusters ``` cd ./third_party/zap/repo/ -node src-script/zap-start.js --logToStdout --gen ../templates/chip-templates.json +node src-script/zap-start.js --logToStdout --gen ../../../src/app/zap/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 ../templates/chip_templates.json -i -o +node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ../../../src/app/zap/chip-templates.json -i -o ``` For more information please see the documentation under diff --git a/third_party/zap/templates/af-structs.zapt b/src/app/zap/af-structs.zapt similarity index 100% rename from third_party/zap/templates/af-structs.zapt rename to src/app/zap/af-structs.zapt diff --git a/third_party/zap/templates/att-storage.zapt b/src/app/zap/att-storage.zapt similarity index 100% rename from third_party/zap/templates/att-storage.zapt rename to src/app/zap/att-storage.zapt diff --git a/third_party/zap/templates/attribute-id.zapt b/src/app/zap/attribute-id.zapt similarity index 100% rename from third_party/zap/templates/attribute-id.zapt rename to src/app/zap/attribute-id.zapt diff --git a/third_party/zap/templates/attribute-type.zapt b/src/app/zap/attribute-type.zapt similarity index 100% rename from third_party/zap/templates/attribute-type.zapt rename to src/app/zap/attribute-type.zapt diff --git a/third_party/zap/templates/call-command-handler-src.zapt b/src/app/zap/call-command-handler-src.zapt similarity index 100% rename from third_party/zap/templates/call-command-handler-src.zapt rename to src/app/zap/call-command-handler-src.zapt diff --git a/third_party/zap/templates/call-command-handler.zapt b/src/app/zap/call-command-handler.zapt similarity index 100% rename from third_party/zap/templates/call-command-handler.zapt rename to src/app/zap/call-command-handler.zapt diff --git a/third_party/zap/templates/callback-stub-src.zapt b/src/app/zap/callback-stub-src.zapt similarity index 100% rename from third_party/zap/templates/callback-stub-src.zapt rename to src/app/zap/callback-stub-src.zapt diff --git a/third_party/zap/templates/callback.zapt b/src/app/zap/callback.zapt similarity index 100% rename from third_party/zap/templates/callback.zapt rename to src/app/zap/callback.zapt diff --git a/third_party/zap/templates/chip-templates.json b/src/app/zap/chip-templates.json similarity index 100% rename from third_party/zap/templates/chip-templates.json rename to src/app/zap/chip-templates.json diff --git a/third_party/zap/templates/client-command-macro.zapt b/src/app/zap/client-command-macro.zapt similarity index 100% rename from third_party/zap/templates/client-command-macro.zapt rename to src/app/zap/client-command-macro.zapt diff --git a/third_party/zap/templates/cluster-id.zapt b/src/app/zap/cluster-id.zapt similarity index 100% rename from third_party/zap/templates/cluster-id.zapt rename to src/app/zap/cluster-id.zapt diff --git a/third_party/zap/templates/command-id.zapt b/src/app/zap/command-id.zapt similarity index 100% rename from third_party/zap/templates/command-id.zapt rename to src/app/zap/command-id.zapt diff --git a/third_party/zap/templates/endpoint_config.zapt b/src/app/zap/endpoint_config.zapt similarity index 100% rename from third_party/zap/templates/endpoint_config.zapt rename to src/app/zap/endpoint_config.zapt diff --git a/third_party/zap/templates/enums.zapt b/src/app/zap/enums.zapt similarity index 100% rename from third_party/zap/templates/enums.zapt rename to src/app/zap/enums.zapt diff --git a/third_party/zap/templates/gen_config.zapt b/src/app/zap/gen_config.zapt similarity index 100% rename from third_party/zap/templates/gen_config.zapt rename to src/app/zap/gen_config.zapt diff --git a/third_party/zap/templates/helper-chip.js b/src/app/zap/helper-chip.js similarity index 100% rename from third_party/zap/templates/helper-chip.js rename to src/app/zap/helper-chip.js diff --git a/third_party/zap/templates/print-cluster.zapt b/src/app/zap/print-cluster.zapt similarity index 100% rename from third_party/zap/templates/print-cluster.zapt rename to src/app/zap/print-cluster.zapt From 8d104edbce8c42dd3282f964a5f4e03853fa3c9b Mon Sep 17 00:00:00 2001 From: jfpenven Date: Fri, 6 Nov 2020 00:47:14 -0500 Subject: [PATCH 04/11] Fix PR comments --- src/app/zap/af-structs.zapt | 8 ++++---- src/app/zap/att-storage.zapt | 10 +++++++--- src/app/zap/attribute-id.zapt | 8 ++++---- src/app/zap/attribute-type.zapt | 1 + src/app/zap/call-command-handler-src.zapt | 2 -- src/app/zap/call-command-handler.zapt | 8 ++++---- src/app/zap/callback-stub-src.zapt | 2 -- src/app/zap/callback.zapt | 10 +++++----- src/app/zap/chip-templates.json | 19 ++++++------------- src/app/zap/cluster-id.zapt | 1 + src/app/zap/command-id.zapt | 1 + src/app/zap/endpoint_config.zapt | 1 - src/app/zap/enums.zapt | 1 + src/app/zap/gen_config.zapt | 1 + src/app/zap/print-cluster.zapt | 7 +++---- 15 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/app/zap/af-structs.zapt b/src/app/zap/af-structs.zapt index c4c426b35e5d61..2ef2839416e1de 100644 --- a/src/app/zap/af-structs.zapt +++ b/src/app/zap/af-structs.zapt @@ -1,8 +1,8 @@ {{chip_header}} - -#ifndef SILABS_EMBER_AF_STRUCTS -#define SILABS_EMBER_AF_STRUCTS +// Enclosing macro to prevent multiple inclusion +#ifndef __ZAP_AF_STRUCTS__ +#define __ZAP_AF_STRUCTS__ #include #include "enums.h" @@ -17,4 +17,4 @@ typedef struct _{{asType label}} { } {{asUnderlyingType label}}; {{/zcl_structs}} -#endif // SILABS_EMBER_AF_STRUCTS \ No newline at end of file +#endif // __ZAP_AF_STRUCTS__ \ No newline at end of file diff --git a/src/app/zap/att-storage.zapt b/src/app/zap/att-storage.zapt index a6448d329e0f7d..f5747bfeb8829f 100644 --- a/src/app/zap/att-storage.zapt +++ b/src/app/zap/att-storage.zapt @@ -1,10 +1,11 @@ {{chip_header}} // Enclosing macro to prevent multiple inclusion -#ifndef SILABS_ATTRIBUTE_STORAGE_GEN -#define SILABS_ATTRIBUTE_STORAGE_GEN +#ifndef __ZAP_ATT_STORAGE__ +#define __ZAP_ATT_STORAGE__ // 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 @@ -21,6 +22,7 @@ #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? @@ -39,6 +41,7 @@ #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 @@ -49,4 +52,5 @@ #define COMMAND_MASK_INCOMING_SERVER (0x08) // Is this command manufacturer specific? #define COMMAND_MASK_MANUFACTURER_SPECIFIC (0x10) -#endif // SILABS_ATTRIBUTE_STORAGE_GEN \ No newline at end of file + +#endif // __ZAP_ATT_STORAGE__ \ No newline at end of file diff --git a/src/app/zap/attribute-id.zapt b/src/app/zap/attribute-id.zapt index 62dc6e94443ced..613814817d85a5 100644 --- a/src/app/zap/attribute-id.zapt +++ b/src/app/zap/attribute-id.zapt @@ -1,11 +1,11 @@ {{chip_header}} // Enclosing macro to prevent multiple inclusion -#ifndef ZAP_EMBER_ATTRIBUTE_ID -#define ZAP_EMBER_ATTRIBUTE_ID +#ifndef __ZAP_EMBER_ATTRIBUTE_ID__ +#define __ZAP_EMBER_ATTRIBUTE_ID__ {{#zcl_clusters}} -// Attribute id for cluster: {{label}} +// Attribute ids for cluster: {{label}} {{#zcl_attributes_client}} {{#first}} @@ -27,4 +27,4 @@ {{/zcl_attributes_server}} {{/zcl_clusters}} -#endif // ZAP_EMBER_ATTRIBUTE_ID \ No newline at end of file +#endif // __ZAP_EMBER_ATTRIBUTE_ID__ \ No newline at end of file diff --git a/src/app/zap/attribute-type.zapt b/src/app/zap/attribute-type.zapt index 20fdc106ec8c8c..61c0076be20f38 100644 --- a/src/app/zap/attribute-type.zapt +++ b/src/app/zap/attribute-type.zapt @@ -1,5 +1,6 @@ {{chip_header}} +// Enclosing macro to prevent multiple inclusion #ifndef __ZAP_ATTRIBUTE_TYPE__ #define __ZAP_ATTRIBUTE_TYPE__ diff --git a/src/app/zap/call-command-handler-src.zapt b/src/app/zap/call-command-handler-src.zapt index 4798b822247723..4fac1a5f31b442 100644 --- a/src/app/zap/call-command-handler-src.zapt +++ b/src/app/zap/call-command-handler-src.zapt @@ -73,7 +73,6 @@ EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd) {{/unless}} {{/if}} {{/all_user_clusters}} - default: // Unrecognized cluster ID, error status will apply. break; @@ -94,7 +93,6 @@ EmberAfStatus emberAf{{asCamelCased name false}}Cluster{{asCamelCased side false { switch (cmd->commandId) { - {{#all_user_cluster_commands}} {{#if (isStrEqual clusterName parent.name)}} {{#if (isCommandAvailable parent.side incoming outgoing commandSource name)}} diff --git a/src/app/zap/call-command-handler.zapt b/src/app/zap/call-command-handler.zapt index 0bfd72443eb511..ada3fcea672e7a 100644 --- a/src/app/zap/call-command-handler.zapt +++ b/src/app/zap/call-command-handler.zapt @@ -1,9 +1,9 @@ {{chip_header}} - -#ifndef CALL_COMMAND_HANDLER -#define CALL_COMMAND_HANDLER +// Enclosing macro to prevent multiple inclusion +#ifndef __ZAP_CALL_COMMAND_HANDLER__ +#define __ZAP_CALL_COMMAND_HANDLER__ #include "af-types.h" -#endif //CALL_COMMAND_HANDLER +#endif //__ZAP_CALL_COMMAND_HANDLER__ diff --git a/src/app/zap/callback-stub-src.zapt b/src/app/zap/callback-stub-src.zapt index 7fd109d8188604..24f843e81f7f0f 100644 --- a/src/app/zap/callback-stub-src.zapt +++ b/src/app/zap/callback-stub-src.zapt @@ -1,6 +1,5 @@ {{chip_header}} - #include "callback.h" #include "cluster-id.h" @@ -14,7 +13,6 @@ void emberAfClusterInitCallback(uint8_t endpoint, EmberAfClusterId clusterId) emberAf{{asCamelCased name false}}ClusterInitCallback(endpoint); break; {{/all_user_clusters_names}} - default: // Unrecognized cluster ID break; diff --git a/src/app/zap/callback.zapt b/src/app/zap/callback.zapt index ff1952d6a85d4a..6ab0543c5e1363 100644 --- a/src/app/zap/callback.zapt +++ b/src/app/zap/callback.zapt @@ -1,8 +1,8 @@ {{chip_header}} - -#ifndef ZCL_CALLBACK_HEADER -#define ZCL_CALLBACK_HEADER +// Enclosing macro to prevent multiple inclusion +#ifndef __ZAP_CALLBACK__ +#define __ZAP_CALLBACK__ #include "af-structs.h" #include "af-types.h" @@ -24,7 +24,7 @@ void emberAf{{asCamelCased name false}}ClusterInitCallback(uint8_t endpoint); {{/all_user_clusters_names}} -// CLuster Commands Callback +// Cluster Commands Callback {{#all_user_clusters}} {{#if (isEnabled enabled)}} @@ -53,4 +53,4 @@ bool emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}} {{/if}} {{/all_user_clusters}} -#endif //ZCL_CALLBACK_HEADER \ No newline at end of file +#endif //__ZAP_CALLBACK__ \ No newline at end of file diff --git a/src/app/zap/chip-templates.json b/src/app/zap/chip-templates.json index ac1058c788d396..010d81166f7679 100644 --- a/src/app/zap/chip-templates.json +++ b/src/app/zap/chip-templates.json @@ -1,16 +1,9 @@ { - "name": "Test templates", - "version": "test-v1", - "options": { - "testOption": { - "code1": "label1", - "code2": "label2", - "code3": "label3", - "code4": "label4", - "code5": "label5" - } - }, - "helpers": ["helper-chip.js"], + "name": "CHIP templates", + "version": "chip-v1", + "helpers": [ + "helper-chip.js" + ], "templates": [ { "path": "af-structs.zapt", @@ -78,4 +71,4 @@ "output": "print-cluster.h" } ] -} +} \ No newline at end of file diff --git a/src/app/zap/cluster-id.zapt b/src/app/zap/cluster-id.zapt index 7982e7fd03f996..cb813ba8e7af41 100644 --- a/src/app/zap/cluster-id.zapt +++ b/src/app/zap/cluster-id.zapt @@ -1,5 +1,6 @@ {{chip_header}} +// Enclosing macro to prevent multiple inclusion #ifndef __ZAP_CLUSTER_ID__ #define __ZAP_CLUSTER_ID__ diff --git a/src/app/zap/command-id.zapt b/src/app/zap/command-id.zapt index ad723a7ac5bd8f..9a078f5c8637f7 100644 --- a/src/app/zap/command-id.zapt +++ b/src/app/zap/command-id.zapt @@ -1,5 +1,6 @@ {{chip_header}} +// Enclosing macro to prevent multiple inclusion #ifndef __ZAP_GEN_ID__ #define __ZAP_GEN_ID__ diff --git a/src/app/zap/endpoint_config.zapt b/src/app/zap/endpoint_config.zapt index f0d0d6e27c76ee..c6a5ffa29d7d6c 100644 --- a/src/app/zap/endpoint_config.zapt +++ b/src/app/zap/endpoint_config.zapt @@ -1,4 +1,3 @@ {{chip_header}} - // TODO issue #3637 diff --git a/src/app/zap/enums.zapt b/src/app/zap/enums.zapt index a0df907da3a729..4caca264ee3fc8 100644 --- a/src/app/zap/enums.zapt +++ b/src/app/zap/enums.zapt @@ -1,5 +1,6 @@ {{chip_header}} +// Enclosing macro to prevent multiple inclusion #ifndef __ZAP_EMBER_ENUMS__ #define __ZAP_EMBER_ENUMS__ diff --git a/src/app/zap/gen_config.zapt b/src/app/zap/gen_config.zapt index b3091ec9cd35e1..067e4872cc6fab 100644 --- a/src/app/zap/gen_config.zapt +++ b/src/app/zap/gen_config.zapt @@ -1,5 +1,6 @@ {{chip_header}} +// Enclosing macro to prevent multiple inclusion #ifndef __ZAP_GEN_CONFIG__ #define __ZAP_GEN_CONFIG__ diff --git a/src/app/zap/print-cluster.zapt b/src/app/zap/print-cluster.zapt index 96430556213052..c6d9d507db8f6a 100644 --- a/src/app/zap/print-cluster.zapt +++ b/src/app/zap/print-cluster.zapt @@ -1,9 +1,8 @@ {{chip_header}} - // Enclosing macro to prevent multiple inclusion -#ifndef SILABS_PRINT_CLUSTER -#define SILABS_PRINT_CLUSTER +#ifndef __ZAP_PRINT_CLUSTER__ +#define __ZAP_PRINT_CLUSTER__ // This is the mapping of IDs to cluster names assuming a format according @@ -27,4 +26,4 @@ #define MAX_CLUSTER_NAME_LENGTH {{zcl_cluster_largest_label_length}} // Enclosing macro to prevent multiple inclusion -#endif // SILABS_PRINT_CLUSTER +#endif // __ZAP_PRINT_CLUSTER__ From 37778e8c5d17bce2ee9b608919da8b0cdf323e2a Mon Sep 17 00:00:00 2001 From: jfpenven Date: Fri, 6 Nov 2020 08:37:27 -0500 Subject: [PATCH 05/11] Renamed src/app/zap to src/app/zap-templates --- src/app/docs/README.md | 2 +- src/app/{zap => zap-templates}/README.md | 4 ++-- src/app/{zap => zap-templates}/af-structs.zapt | 0 src/app/{zap => zap-templates}/att-storage.zapt | 0 src/app/{zap => zap-templates}/attribute-id.zapt | 0 src/app/{zap => zap-templates}/attribute-type.zapt | 0 src/app/{zap => zap-templates}/call-command-handler-src.zapt | 0 src/app/{zap => zap-templates}/call-command-handler.zapt | 0 src/app/{zap => zap-templates}/callback-stub-src.zapt | 0 src/app/{zap => zap-templates}/callback.zapt | 0 src/app/{zap => zap-templates}/chip-templates.json | 0 src/app/{zap => zap-templates}/client-command-macro.zapt | 0 src/app/{zap => zap-templates}/cluster-id.zapt | 0 src/app/{zap => zap-templates}/command-id.zapt | 0 src/app/{zap => zap-templates}/endpoint_config.zapt | 0 src/app/{zap => zap-templates}/enums.zapt | 0 src/app/{zap => zap-templates}/gen_config.zapt | 0 src/app/{zap => zap-templates}/helper-chip.js | 0 src/app/{zap => zap-templates}/print-cluster.zapt | 0 19 files changed, 3 insertions(+), 3 deletions(-) rename src/app/{zap => zap-templates}/README.md (81%) rename src/app/{zap => zap-templates}/af-structs.zapt (100%) rename src/app/{zap => zap-templates}/att-storage.zapt (100%) rename src/app/{zap => zap-templates}/attribute-id.zapt (100%) rename src/app/{zap => zap-templates}/attribute-type.zapt (100%) rename src/app/{zap => zap-templates}/call-command-handler-src.zapt (100%) rename src/app/{zap => zap-templates}/call-command-handler.zapt (100%) rename src/app/{zap => zap-templates}/callback-stub-src.zapt (100%) rename src/app/{zap => zap-templates}/callback.zapt (100%) rename src/app/{zap => zap-templates}/chip-templates.json (100%) rename src/app/{zap => zap-templates}/client-command-macro.zapt (100%) rename src/app/{zap => zap-templates}/cluster-id.zapt (100%) rename src/app/{zap => zap-templates}/command-id.zapt (100%) rename src/app/{zap => zap-templates}/endpoint_config.zapt (100%) rename src/app/{zap => zap-templates}/enums.zapt (100%) rename src/app/{zap => zap-templates}/gen_config.zapt (100%) rename src/app/{zap => zap-templates}/helper-chip.js (100%) rename src/app/{zap => zap-templates}/print-cluster.zapt (100%) diff --git a/src/app/docs/README.md b/src/app/docs/README.md index 234369e3d2f83b..f4d4a54d24ccb0 100644 --- a/src/app/docs/README.md +++ b/src/app/docs/README.md @@ -29,7 +29,7 @@ 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> +### /src/app/zap-templates This directory contains all of the templates and helpers specific to CHIP for the ZAP tool. diff --git a/src/app/zap/README.md b/src/app/zap-templates/README.md similarity index 81% rename from src/app/zap/README.md rename to src/app/zap-templates/README.md index ca29e9cf03cce2..cd3b5601718fb4 100644 --- a/src/app/zap/README.md +++ b/src/app/zap-templates/README.md @@ -12,14 +12,14 @@ 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/chip-templates.json +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/chip-templates.json -i -o +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 diff --git a/src/app/zap/af-structs.zapt b/src/app/zap-templates/af-structs.zapt similarity index 100% rename from src/app/zap/af-structs.zapt rename to src/app/zap-templates/af-structs.zapt diff --git a/src/app/zap/att-storage.zapt b/src/app/zap-templates/att-storage.zapt similarity index 100% rename from src/app/zap/att-storage.zapt rename to src/app/zap-templates/att-storage.zapt diff --git a/src/app/zap/attribute-id.zapt b/src/app/zap-templates/attribute-id.zapt similarity index 100% rename from src/app/zap/attribute-id.zapt rename to src/app/zap-templates/attribute-id.zapt diff --git a/src/app/zap/attribute-type.zapt b/src/app/zap-templates/attribute-type.zapt similarity index 100% rename from src/app/zap/attribute-type.zapt rename to src/app/zap-templates/attribute-type.zapt diff --git a/src/app/zap/call-command-handler-src.zapt b/src/app/zap-templates/call-command-handler-src.zapt similarity index 100% rename from src/app/zap/call-command-handler-src.zapt rename to src/app/zap-templates/call-command-handler-src.zapt diff --git a/src/app/zap/call-command-handler.zapt b/src/app/zap-templates/call-command-handler.zapt similarity index 100% rename from src/app/zap/call-command-handler.zapt rename to src/app/zap-templates/call-command-handler.zapt diff --git a/src/app/zap/callback-stub-src.zapt b/src/app/zap-templates/callback-stub-src.zapt similarity index 100% rename from src/app/zap/callback-stub-src.zapt rename to src/app/zap-templates/callback-stub-src.zapt diff --git a/src/app/zap/callback.zapt b/src/app/zap-templates/callback.zapt similarity index 100% rename from src/app/zap/callback.zapt rename to src/app/zap-templates/callback.zapt diff --git a/src/app/zap/chip-templates.json b/src/app/zap-templates/chip-templates.json similarity index 100% rename from src/app/zap/chip-templates.json rename to src/app/zap-templates/chip-templates.json diff --git a/src/app/zap/client-command-macro.zapt b/src/app/zap-templates/client-command-macro.zapt similarity index 100% rename from src/app/zap/client-command-macro.zapt rename to src/app/zap-templates/client-command-macro.zapt diff --git a/src/app/zap/cluster-id.zapt b/src/app/zap-templates/cluster-id.zapt similarity index 100% rename from src/app/zap/cluster-id.zapt rename to src/app/zap-templates/cluster-id.zapt diff --git a/src/app/zap/command-id.zapt b/src/app/zap-templates/command-id.zapt similarity index 100% rename from src/app/zap/command-id.zapt rename to src/app/zap-templates/command-id.zapt diff --git a/src/app/zap/endpoint_config.zapt b/src/app/zap-templates/endpoint_config.zapt similarity index 100% rename from src/app/zap/endpoint_config.zapt rename to src/app/zap-templates/endpoint_config.zapt diff --git a/src/app/zap/enums.zapt b/src/app/zap-templates/enums.zapt similarity index 100% rename from src/app/zap/enums.zapt rename to src/app/zap-templates/enums.zapt diff --git a/src/app/zap/gen_config.zapt b/src/app/zap-templates/gen_config.zapt similarity index 100% rename from src/app/zap/gen_config.zapt rename to src/app/zap-templates/gen_config.zapt diff --git a/src/app/zap/helper-chip.js b/src/app/zap-templates/helper-chip.js similarity index 100% rename from src/app/zap/helper-chip.js rename to src/app/zap-templates/helper-chip.js diff --git a/src/app/zap/print-cluster.zapt b/src/app/zap-templates/print-cluster.zapt similarity index 100% rename from src/app/zap/print-cluster.zapt rename to src/app/zap-templates/print-cluster.zapt From 7cbb814cd6304176229758d88c0d45790c7e6e40 Mon Sep 17 00:00:00 2001 From: jfpenven Date: Fri, 6 Nov 2020 08:40:35 -0500 Subject: [PATCH 06/11] removed CLI define --- src/app/zap-templates/gen_config.zapt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/app/zap-templates/gen_config.zapt b/src/app/zap-templates/gen_config.zapt index 067e4872cc6fab..a39a4a2b0994a9 100644 --- a/src/app/zap-templates/gen_config.zapt +++ b/src/app/zap-templates/gen_config.zapt @@ -13,10 +13,6 @@ #define EMBER_APS_UNICAST_MESSAGE_COUNT 10 -/**** CLI Section ****/ -#define EMBER_AF_GENERATE_CLI - - /**** Cluster endpoint counts ****/ {{#all_user_clusters}} #define EMBER_AF_{{asDelimitedMacro define}}_{{asDelimitedMacro side}}_ENDPOINT_COUNT ({{user_endpoint_count_by_cluster id side}}) From f8668747895bd1ae674747dd9a1fbd4e7eba9d44 Mon Sep 17 00:00:00 2001 From: jfpenven Date: Mon, 9 Nov 2020 09:44:43 -0500 Subject: [PATCH 07/11] Switch to pragma once --- src/app/zap-templates/af-structs.zapt | 7 ++----- src/app/zap-templates/att-storage.zapt | 7 ++----- src/app/zap-templates/attribute-id.zapt | 7 ++----- src/app/zap-templates/attribute-type.zapt | 7 ++----- src/app/zap-templates/call-command-handler.zapt | 7 ++----- src/app/zap-templates/callback.zapt | 7 ++----- src/app/zap-templates/client-command-macro.zapt | 3 +++ src/app/zap-templates/cluster-id.zapt | 7 ++----- src/app/zap-templates/command-id.zapt | 7 ++----- src/app/zap-templates/endpoint_config.zapt | 3 +++ src/app/zap-templates/enums.zapt | 7 ++----- src/app/zap-templates/gen_config.zapt | 7 ++----- src/app/zap-templates/print-cluster.zapt | 9 ++------- 13 files changed, 28 insertions(+), 57 deletions(-) diff --git a/src/app/zap-templates/af-structs.zapt b/src/app/zap-templates/af-structs.zapt index 2ef2839416e1de..e662044f78bdf1 100644 --- a/src/app/zap-templates/af-structs.zapt +++ b/src/app/zap-templates/af-structs.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_AF_STRUCTS__ -#define __ZAP_AF_STRUCTS__ +// Prevent multiple inclusion +#pragma once #include #include "enums.h" @@ -16,5 +15,3 @@ typedef struct _{{asType label}} { {{/zcl_struct_items}} } {{asUnderlyingType label}}; {{/zcl_structs}} - -#endif // __ZAP_AF_STRUCTS__ \ No newline at end of file diff --git a/src/app/zap-templates/att-storage.zapt b/src/app/zap-templates/att-storage.zapt index f5747bfeb8829f..b0491aa268a312 100644 --- a/src/app/zap-templates/att-storage.zapt +++ b/src/app/zap-templates/att-storage.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_ATT_STORAGE__ -#define __ZAP_ATT_STORAGE__ +// Prevent multiple inclusion +#pragma once // Attribute masks modify how attributes are used by the framework // @@ -52,5 +51,3 @@ #define COMMAND_MASK_INCOMING_SERVER (0x08) // Is this command manufacturer specific? #define COMMAND_MASK_MANUFACTURER_SPECIFIC (0x10) - -#endif // __ZAP_ATT_STORAGE__ \ No newline at end of file diff --git a/src/app/zap-templates/attribute-id.zapt b/src/app/zap-templates/attribute-id.zapt index 613814817d85a5..203aa4c1a22f19 100644 --- a/src/app/zap-templates/attribute-id.zapt +++ b/src/app/zap-templates/attribute-id.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_EMBER_ATTRIBUTE_ID__ -#define __ZAP_EMBER_ATTRIBUTE_ID__ +// Prevent multiple inclusion +#pragma once {{#zcl_clusters}} // Attribute ids for cluster: {{label}} @@ -26,5 +25,3 @@ {{/last}} {{/zcl_attributes_server}} {{/zcl_clusters}} - -#endif // __ZAP_EMBER_ATTRIBUTE_ID__ \ No newline at end of file diff --git a/src/app/zap-templates/attribute-type.zapt b/src/app/zap-templates/attribute-type.zapt index 61c0076be20f38..d7319af9e1c99d 100644 --- a/src/app/zap-templates/attribute-type.zapt +++ b/src/app/zap-templates/attribute-type.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_ATTRIBUTE_TYPE__ -#define __ZAP_ATTRIBUTE_TYPE__ +// Prevent multiple inclusion +#pragma once // ZCL attribute types enum { @@ -19,5 +18,3 @@ enum { {{/if}} {{/zcl_atomics}} } - -#endif // __ZAP_ATTRIBUTE_TYPE__ \ 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 index ada3fcea672e7a..6ab97918f1a89c 100644 --- a/src/app/zap-templates/call-command-handler.zapt +++ b/src/app/zap-templates/call-command-handler.zapt @@ -1,9 +1,6 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_CALL_COMMAND_HANDLER__ -#define __ZAP_CALL_COMMAND_HANDLER__ +// Prevent multiple inclusion +#pragma once #include "af-types.h" - -#endif //__ZAP_CALL_COMMAND_HANDLER__ diff --git a/src/app/zap-templates/callback.zapt b/src/app/zap-templates/callback.zapt index 6ab0543c5e1363..5dd06a9d53fa45 100644 --- a/src/app/zap-templates/callback.zapt +++ b/src/app/zap-templates/callback.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_CALLBACK__ -#define __ZAP_CALLBACK__ +// Prevent multiple inclusion +#pragma once #include "af-structs.h" #include "af-types.h" @@ -52,5 +51,3 @@ bool emberAf{{asCamelCased parent.name false}}Cluster{{asCamelCased name false}} {{/all_user_cluster_commands}} {{/if}} {{/all_user_clusters}} - -#endif //__ZAP_CALLBACK__ \ No newline at end of file diff --git a/src/app/zap-templates/client-command-macro.zapt b/src/app/zap-templates/client-command-macro.zapt index c6a5ffa29d7d6c..fba147fa7ab0d7 100644 --- a/src/app/zap-templates/client-command-macro.zapt +++ b/src/app/zap-templates/client-command-macro.zapt @@ -1,3 +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 index cb813ba8e7af41..4331eb3b5ffe90 100644 --- a/src/app/zap-templates/cluster-id.zapt +++ b/src/app/zap-templates/cluster-id.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_CLUSTER_ID__ -#define __ZAP_CLUSTER_ID__ +// Prevent multiple inclusion +#pragma once {{#zcl_clusters}} @@ -10,5 +9,3 @@ #define ZCL_{{asDelimitedMacro define}}_ID ({{asHex code 4}}) {{/zcl_clusters}} - -#endif // __ZAP_CLUSTER_ID__ \ No newline at end of file diff --git a/src/app/zap-templates/command-id.zapt b/src/app/zap-templates/command-id.zapt index 9a078f5c8637f7..74a95c5a707fbe 100644 --- a/src/app/zap-templates/command-id.zapt +++ b/src/app/zap-templates/command-id.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_GEN_ID__ -#define __ZAP_GEN_ID__ +// Prevent multiple inclusion +#pragma once // Global, non-cluster-specific commands {{#zcl_global_commands}} @@ -18,5 +17,3 @@ #define ZCL_{{asDelimitedMacro label}}_COMMAND_ID ({{asHex code 2}}) {{/zcl_commands}} {{/zcl_clusters}} - -#endif // __ZAP_GEN_ID__ \ No newline at end of file diff --git a/src/app/zap-templates/endpoint_config.zapt b/src/app/zap-templates/endpoint_config.zapt index c6a5ffa29d7d6c..fba147fa7ab0d7 100644 --- a/src/app/zap-templates/endpoint_config.zapt +++ b/src/app/zap-templates/endpoint_config.zapt @@ -1,3 +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 index 4caca264ee3fc8..729329ae2aa38d 100644 --- a/src/app/zap-templates/enums.zapt +++ b/src/app/zap-templates/enums.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_EMBER_ENUMS__ -#define __ZAP_EMBER_ENUMS__ +// Prevent multiple inclusion +#pragma once // ZCL enums @@ -22,5 +21,3 @@ typedef enum { #define EMBER_AF_{{asDelimitedMacro parent.label}}_{{asDelimitedMacro label}}_OFFSET ({{asOffset mask}}) {{/zcl_bitmap_items}} {{/zcl_bitmaps}} - -#endif //__ZAP_EMBER_ENUMS__ \ No newline at end of file diff --git a/src/app/zap-templates/gen_config.zapt b/src/app/zap-templates/gen_config.zapt index a39a4a2b0994a9..5cc04b04c1588f 100644 --- a/src/app/zap-templates/gen_config.zapt +++ b/src/app/zap-templates/gen_config.zapt @@ -1,8 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_GEN_CONFIG__ -#define __ZAP_GEN_CONFIG__ +// Prevent multiple inclusion +#pragma once // User options for plugin Binding Table Library #define EMBER_BINDING_TABLE_SIZE 10 @@ -17,5 +16,3 @@ {{#all_user_clusters}} #define EMBER_AF_{{asDelimitedMacro define}}_{{asDelimitedMacro side}}_ENDPOINT_COUNT ({{user_endpoint_count_by_cluster id side}}) {{/all_user_clusters}} - -#endif // __ZAP_GEN_CONFIG__ \ No newline at end of file diff --git a/src/app/zap-templates/print-cluster.zapt b/src/app/zap-templates/print-cluster.zapt index c6d9d507db8f6a..7bed5cca10f338 100644 --- a/src/app/zap-templates/print-cluster.zapt +++ b/src/app/zap-templates/print-cluster.zapt @@ -1,9 +1,7 @@ {{chip_header}} -// Enclosing macro to prevent multiple inclusion -#ifndef __ZAP_PRINT_CLUSTER__ -#define __ZAP_PRINT_CLUSTER__ - +// 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. @@ -24,6 +22,3 @@ {{/zcl_clusters}} #define MAX_CLUSTER_NAME_LENGTH {{zcl_cluster_largest_label_length}} - -// Enclosing macro to prevent multiple inclusion -#endif // __ZAP_PRINT_CLUSTER__ From 36ddd1a80e6fdeaf1f058474f06327adfd1a2012 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 9 Nov 2020 19:12:03 +0000 Subject: [PATCH 08/11] Restyled by whitespace --- src/app/zap-templates/chip-templates.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/zap-templates/chip-templates.json b/src/app/zap-templates/chip-templates.json index 010d81166f7679..e3f8eaa1b50588 100644 --- a/src/app/zap-templates/chip-templates.json +++ b/src/app/zap-templates/chip-templates.json @@ -71,4 +71,4 @@ "output": "print-cluster.h" } ] -} \ No newline at end of file +} From 1267734209e1bedfa8ca3724d333d74a1f51e2c3 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 9 Nov 2020 19:12:08 +0000 Subject: [PATCH 09/11] Restyled by clang-format --- src/app/zap-templates/helper-chip.js | 70 ++++++++++++---------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/src/app/zap-templates/helper-chip.js b/src/app/zap-templates/helper-chip.js index 0a77fba2a3e574..13b78afe17232a 100644 --- a/src/app/zap-templates/helper-chip.js +++ b/src/app/zap-templates/helper-chip.js @@ -1,19 +1,19 @@ /* -* -* 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. -*/ + * + * 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} @@ -27,7 +27,7 @@ * @returns The header content */ function chip_header() { - return ` + return ` /* * * Copyright (c) 2020 Project CHIP Authors @@ -46,37 +46,27 @@ function chip_header() { */`; } -function isClient(side) { - return 0 == side.localeCompare("client"); -} +function isClient(side) { return 0 == side.localeCompare("client"); } -function isServer(side) { - return 0 == side.localeCompare("server"); -} +function isServer(side) { return 0 == side.localeCompare("server"); } -function isStrEqual(str1, str2) { - return 0 == str1.localeCompare(str2); -} +function isStrEqual(str1, str2) { return 0 == str1.localeCompare(str2); } -function isLastElement(index, count) { - return index == count - 1; -} +function isLastElement(index, count) { return index == count - 1; } -function isEnabled(enable) { - return 1 == enable; -} +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; - } + 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! From e2e0e1efca02969396be5e3354ab9ed08188398b Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 9 Nov 2020 19:12:15 +0000 Subject: [PATCH 10/11] Restyled by prettier-json --- src/app/zap-templates/chip-templates.json | 142 +++++++++++----------- 1 file changed, 70 insertions(+), 72 deletions(-) diff --git a/src/app/zap-templates/chip-templates.json b/src/app/zap-templates/chip-templates.json index e3f8eaa1b50588..3d46473c12855b 100644 --- a/src/app/zap-templates/chip-templates.json +++ b/src/app/zap-templates/chip-templates.json @@ -1,74 +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" - } - ] + "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" + } + ] } From e8018651d666c8ac84f96546d2f697399d4583d4 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 9 Nov 2020 19:12:19 +0000 Subject: [PATCH 11/11] Restyled by prettier-markdown --- src/app/docs/README.md | 3 ++- src/app/zap-templates/README.md | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/docs/README.md b/src/app/docs/README.md index f4d4a54d24ccb0..307f787ac5177d 100644 --- a/src/app/docs/README.md +++ b/src/app/docs/README.md @@ -31,7 +31,8 @@ ZCL Application Framework. ### /src/app/zap-templates -This directory contains all of the templates and helpers specific to CHIP for the ZAP tool. +This directory contains all of the templates and helpers specific to CHIP for +the ZAP tool. ## Public APIs diff --git a/src/app/zap-templates/README.md b/src/app/zap-templates/README.md index cd3b5601718fb4..0b51ba643be11c 100644 --- a/src/app/zap-templates/README.md +++ b/src/app/zap-templates/README.md @@ -22,5 +22,5 @@ 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) +For more information please see the documentation under `docs/` in +[ZAP](https://github.com/project-chip/zap)