Skip to content

Commit

Permalink
Zap add accessors helpers for attributes (#7183)
Browse files Browse the repository at this point in the history
* Add Attributes Accessors into src/app/common/gen

* Update some ZCL definition types to use the types from the spec

* Update gen/ folders
  • Loading branch information
vivien-apple authored and pull[bot] committed Sep 2, 2021
1 parent c2b9b9c commit 311035a
Show file tree
Hide file tree
Showing 15 changed files with 10,748 additions and 144 deletions.
8,221 changes: 8,221 additions & 0 deletions src/app/common/gen/attributes/Accessors.cpp

Large diffs are not rendered by default.

2,197 changes: 2,197 additions & 0 deletions src/app/common/gen/attributes/Accessors.h

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/app/common/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -15824,7 +15824,7 @@ bool emberAfDiagnosticLogsClusterRetrieveLogsRequestCallback(chip::app::Command
*/
bool emberAfDiagnosticLogsClusterRetrieveLogsResponseCallback(chip::app::Command * commandObj, uint8_t status,
chip::ByteSpan content,
/* TYPE WARNING: unknown defaults to */ uint8_t * timeStamp,
/* TYPE WARNING: utc defaults to */ uint8_t * timeStamp,
uint32_t timeSinceBoot);

/**
Expand Down Expand Up @@ -16854,7 +16854,7 @@ bool emberAfTestClusterClusterTestUnknownCommandCallback(chip::app::Command * co
* @brief Cluster DisplayMessage Command callback
*/
bool emberAfMessagingClusterDisplayMessageCallback(chip::app::Command * commandObj, uint32_t messageId, uint8_t messageControl,
/* TYPE WARNING: unknown defaults to */ uint8_t * startTime,
/* TYPE WARNING: utc defaults to */ uint8_t * startTime,
uint16_t durationInMinutes, uint8_t * message,
uint8_t optionalExtendedMessageControl);

Expand All @@ -16872,29 +16872,29 @@ bool emberAfMessagingClusterCancelMessageCallback(chip::app::Command * commandOb
* @brief Cluster MessageConfirmation Command callback
*/
bool emberAfMessagingClusterMessageConfirmationCallback(chip::app::Command * commandObj, uint32_t messageId,
/* TYPE WARNING: unknown defaults to */ uint8_t * confirmationTime,
/* TYPE WARNING: utc defaults to */ uint8_t * confirmationTime,
uint8_t messageConfirmationControl, chip::ByteSpan messageResponse);

/**
* @brief Cluster DisplayProtectedMessage Command callback
*/
bool emberAfMessagingClusterDisplayProtectedMessageCallback(chip::app::Command * commandObj, uint32_t messageId,
uint8_t messageControl,
/* TYPE WARNING: unknown defaults to */ uint8_t * startTime,
/* TYPE WARNING: utc defaults to */ uint8_t * startTime,
uint16_t durationInMinutes, uint8_t * message,
uint8_t optionalExtendedMessageControl);

/**
* @brief Cluster GetMessageCancellation Command callback
*/
bool emberAfMessagingClusterGetMessageCancellationCallback(
chip::app::Command * commandObj, /* TYPE WARNING: unknown defaults to */ uint8_t * earliestImplementationTime);
chip::app::Command * commandObj, /* TYPE WARNING: utc defaults to */ uint8_t * earliestImplementationTime);

/**
* @brief Cluster CancelAllMessages Command callback
*/
bool emberAfMessagingClusterCancelAllMessagesCallback(chip::app::Command * commandObj,
/* TYPE WARNING: unknown defaults to */ uint8_t * implementationDateTime);
/* TYPE WARNING: utc defaults to */ uint8_t * implementationDateTime);

/**
* @brief Cluster GetAlerts Command callback
Expand Down
12 changes: 6 additions & 6 deletions src/app/common/gen/client-command-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@
* Command: RetrieveLogsResponse
* @param status LogsStatus
* @param content OCTET_STRING
* @param timeStamp UTC_TIME
* @param timeStamp UTC
* @param timeSinceBoot INT32U
*/
#define emberAfFillCommandDiagnostic \
Expand Down Expand Up @@ -4675,7 +4675,7 @@
* Command: DisplayMessage
* @param messageId INT32U
* @param messageControl MessagingControlMask
* @param startTime UTC_TIME
* @param startTime UTC
* @param durationInMinutes INT16U
* @param message CHAR_STRING
* @param optionalExtendedMessageControl MessagingExtendedControlMask
Expand Down Expand Up @@ -4720,7 +4720,7 @@
/** @brief Command description for MessageConfirmation
*
* Command: MessageConfirmation
* @param confirmationTime UTC_TIME
* @param confirmationTime UTC
* @param messageConfirmationControl BITMAP8
* @param messageResponse OCTET_STRING
*/
Expand All @@ -4743,7 +4743,7 @@
/** @brief Command description for GetMessageCancellation
*
* Command: GetMessageCancellation
* @param earliestImplementationTime UTC_TIME
* @param earliestImplementationTime UTC
*/
#define emberAfFillCommandMessagingClusterGetMessageCancellation(earliestImplementationTime) \
emberAfFillExternalBuffer(mask, \
Expand All @@ -4754,7 +4754,7 @@
*
* Command: DisplayProtectedMessage
* @param messageControl MessagingControlMask
* @param startTime UTC_TIME
* @param startTime UTC
* @param durationInMinutes INT16U
* @param message CHAR_STRING
* @param optionalExtendedMessageControl MessagingExtendedControlMask
Expand All @@ -4769,7 +4769,7 @@
/** @brief Command description for CancelAllMessages
*
* Command: CancelAllMessages
* @param implementationDateTime UTC_TIME
* @param implementationDateTime UTC
*/
#define emberAfFillCommandMessagingClusterCancelAllMessages(implementationDateTime) \
emberAfFillExternalBuffer(mask, \
Expand Down
11 changes: 11 additions & 0 deletions src/app/common/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"helpers": [
"../../zap-templates/partials/helper.js",
"../../zap-templates/common/StringHelper.js",
"../../zap-templates/common/attributes/Accessors.js",
"../../zap-templates/templates/app/helper.js",
"../../zap-templates/templates/chip/helper.js"
],
Expand Down Expand Up @@ -70,6 +71,16 @@
"name": "ZCL print-cluster header",
"output": "src/app/common/gen/print-cluster.h"
},
{
"path": "../../zap-templates/templates/app/attributes/Accessors.zapt",
"name": "Attributes Accessors header",
"output": "src/app/common/gen/attributes/Accessors.h"
},
{
"path": "../../zap-templates/templates/app/attributes/Accessors-src.zapt",
"name": "Attributes Accessors",
"output": "src/app/common/gen/attributes/Accessors.cpp"
},
{
"path": "../../zap-templates/templates/app/ids/Attributes.zapt",
"name": "Attributes Ids header",
Expand Down
28 changes: 28 additions & 0 deletions src/app/zap-templates/common/StructHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
*
* Copyright (c) 2021 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.
*/

const kType = 'STRUCT';

function isStruct(type)
{
return type.toUpperCase() == kType;
}

//
// Module exports
//
exports.isStruct = isStruct;
56 changes: 56 additions & 0 deletions src/app/zap-templates/common/attributes/Accessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
*
* Copyright (c) 2021 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.
*/

const ListHelper = require('../../common/ListHelper.js');
const StringHelper = require('../../common/StringHelper.js');
const StructHelper = require('../../common/StructHelper.js');

// Issue #8202
// The specification allow non-standard signed and unsigned integer with a width of 24, 40, 48 or 56, but those types does not have
// proper support yet into the codebase and the resulting generated code can not be built with them.
// Once they are supported, the following method could be removed.
const unsupportedTypes = [ 'INT24S', 'INT40S', 'INT48S', 'INT56S', 'INT24U', 'INT40U', 'INT48U', 'INT56U' ];
function isUnsupportedType(type)
{
return unsupportedTypes.includes(type.toUpperCase());
}

function canHaveSimpleAccessors(type)
{
if (StringHelper.isString(type)) {
return false;
}

if (ListHelper.isList(type)) {
return false;
}

if (StructHelper.isStruct(type)) {
return false;
}

if (isUnsupportedType(type)) {
return false;
}

return true;
}

//
// Module exports
//
exports.canHaveSimpleAccessors = canHaveSimpleAccessors;
2 changes: 2 additions & 0 deletions src/app/zap-templates/common/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ function atomicType(arg)
case 'octet_string':
case 'long_octet_string':
return 'chip::ByteSpan';
case 'eui64':
return 'chip::node_id';
default:
throw 'not overriding';
}
Expand Down
50 changes: 50 additions & 0 deletions src/app/zap-templates/templates/app/attributes/Accessors-src.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{>header}}

/**
* @file
* This file contains definitions for accessors around clusters attributes.
*/

#pragma once

#include <app/common/gen/attributes/Accessors.h>

#include <app/common/gen/ids/Attributes.h>
#include <app/common/gen/ids/Clusters.h>

namespace chip {
namespace app {
namespace Clusters {

{{#zcl_clusters}}
{{#zcl_attributes_server}}
{{#if (hasSpecificAttributes)}}
{{#first}}
namespace {{asUpperCamelCase parent.label}} {
namespace Attributes {
{{/first}}
{{#if clusterRef}}
{{#if (canHaveSimpleAccessors type)}}
EmberAfStatus Get{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} * {{asLowerCamelCase label}})
{
return emberAfReadServerAttribute(endpoint, {{asUpperCamelCase parent.label}}::Id, Ids::{{asUpperCamelCase label}}, (uint8_t *) {{asLowerCamelCase label}}, sizeof(*{{asLowerCamelCase label}}));

}
EmberAfStatus Set{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} {{asLowerCamelCase label}})
{
return emberAfWriteServerAttribute(endpoint, {{asUpperCamelCase parent.label}}::Id, Ids::{{asUpperCamelCase label}}, (uint8_t *) &{{asLowerCamelCase label}}, ZCL_{{asDelimitedMacro type}}_ATTRIBUTE_TYPE);
}
{{/if}}
{{/if}}
{{#last}}
} // namespace Attributes
} // {{asUpperCamelCase parent.label}}

{{/last}}
{{/if}}
{{/zcl_attributes_server}}
{{/zcl_clusters}}

} // Clusters
} // app
} // chip
41 changes: 41 additions & 0 deletions src/app/zap-templates/templates/app/attributes/Accessors.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{>header}}

/**
* @file
* This file contains declarations for accessors around clusters attributes.
*/

#pragma once

#include <app/util/af-types.h>
#include <lib/support/Span.h>

namespace chip {
namespace app {
namespace Clusters {

{{#zcl_clusters}}
{{#zcl_attributes_server}}
{{#if (hasSpecificAttributes)}}
{{#first}}
namespace {{asUpperCamelCase parent.label}} {
namespace Attributes {
{{/first}}
{{#if clusterRef}}
{{#if (canHaveSimpleAccessors type)}}
EmberAfStatus Get{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} * {{asLowerCamelCase label}}); // {{type}} {{isArray}}
EmberAfStatus Set{{asUpperCamelCase label}}(chip::EndpointId endpoint, {{asUnderlyingZclType type}} {{asLowerCamelCase label}});
{{/if}}
{{/if}}
{{#last}}
} // namespace Attributes
} // {{asUpperCamelCase parent.label}}

{{/last}}
{{/if}}
{{/zcl_attributes_server}}
{{/zcl_clusters}}

} // Clusters
} // app
} // chip
6 changes: 2 additions & 4 deletions src/app/zap-templates/templates/app/ids/Attributes.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ namespace Clusters {
namespace Globals {
namespace Attributes {
namespace Ids {
{{#zcl_attributes}}
{{#if (isServer side)}}
{{#zcl_attributes_server}}
{{#unless clusterRef}}
static constexpr AttributeId {{asUpperCamelCase label}} = {{asHex code 4}};
{{/unless}}
{{/if}}
{{/zcl_attributes}}
{{/zcl_attributes_server}}
} // namespace Ids
} // namespace Attributes
} // namespace Globals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ limitations under the License.
<description>Response to the RetrieveLogsRequest</description>
<arg name="status" type="LogsStatus"/>
<arg name="content" type="OCTET_STRING"/>
<arg name="timeStamp" type="UTC_TIME"/>
<arg name="timeStamp" type="UTC"/>
<arg name="timeSinceBoot" type="INT32U"/>
</command>
</cluster>
Expand Down
10 changes: 5 additions & 5 deletions src/app/zap-templates/zcl/data-model/silabs/ami.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ limitations under the License.
</description>
<arg name="messageId" type="INT32U"/>
<arg name="messageControl" type="MessagingControlMask"/>
<arg name="startTime" type="UTC_TIME"/>
<arg name="startTime" type="UTC"/>
<arg name="durationInMinutes" type="INT16U"/>
<arg name="message" type="CHAR_STRING"/>
<arg name="optionalExtendedMessageControl" type="MessagingExtendedControlMask" introducedIn="se-1.2a-07-5356-19" default="0x00"/>
Expand All @@ -95,7 +95,7 @@ limitations under the License.
</description>
<arg name="messageId" type="INT32U"/>
<arg name="messageControl" type="MessagingControlMask"/>
<arg name="startTime" type="UTC_TIME"/>
<arg name="startTime" type="UTC"/>
<arg name="durationInMinutes" type="INT16U"/>
<arg name="message" type="CHAR_STRING"/>
<arg name="optionalExtendedMessageControl" type="MessagingExtendedControlMask"/>
Expand All @@ -104,7 +104,7 @@ limitations under the License.
<description>
The CancelAllMessages command indicates to a client device that it should cancel all display messages currently held by it.
</description>
<arg name="implementationDateTime" type="UTC_TIME"/>
<arg name="implementationDateTime" type="UTC"/>
</command>
<!-- Messaging Cluster Client - Commands -->
<command source="client" code="0x00" name="GetLastMessage" optional="false" cli="zcl msg get">
Expand All @@ -117,15 +117,15 @@ limitations under the License.
The Message Confirmation command provides an indication that a Utility Customer has acknowledged and/or accepted the contents of a previously sent message. Enhanced Message Confirmation commands shall contain an answer of 'NO', 'YES' and/or a message confirmation string.
</description>
<arg name="messageId" type="INT32U"/>
<arg name="confirmationTime" type="UTC_TIME"/>
<arg name="confirmationTime" type="UTC"/>
<arg name="messageConfirmationControl" type="BITMAP8" introducedIn="se-1.2a-07-5356-19"/>
<arg name="messageResponse" type="OCTET_STRING" introducedIn="se-1.2a-07-5356-19"/>
</command>
<command source="client" code="0x02" name="GetMessageCancellation" optional="true" introducedIn="se-1.2a-07-5356-19" cli="zcl msg get-msg-x">
<description>
This command initiates the return of the first (and maybe only) Cancel All Messages command held on the associated server, and which has an implementation time equal to or later than the value indicated in the payload.
</description>
<arg name="earliestImplementationTime" type="UTC_TIME"/>
<arg name="earliestImplementationTime" type="UTC"/>
</command>
</cluster>
<!-- SE extension to the Alarms cluster. -->
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap-templates/zcl/data-model/silabs/general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ limitations under the License.
<attribute side="server" code="0x0003" define="SCENE_VALID" type="BOOLEAN" min="0x00" max="0x01" writable="false" default="0x00" optional="false">scene valid</attribute>
<attribute side="server" code="0x0004" define="SCENE_NAME_SUPPORT" type="BITMAP8" min="0x00" max="0x80" writable="false" optional="false">name support</attribute>
<!-- NAME_SUPPORT -->
<attribute side="server" code="0x0005" define="LAST_CONFIGURED_BY" type="IEEE_ADDRESS" writable="false" optional="true">last configured by</attribute>
<attribute side="server" code="0x0005" define="LAST_CONFIGURED_BY" type="EUI64" writable="false" optional="true">last configured by</attribute>
<command source="client" code="0x00" name="AddScene" optional="false" cli="zcl scenes add">
<description>
Add a scene to the scene table. Extension field sets are supported, and are inputed as arrays of the form [[cluster ID] [length] [value0...n] ...]
Expand Down
Loading

0 comments on commit 311035a

Please sign in to comment.