Skip to content

Commit

Permalink
Regenerating ZAP
Browse files Browse the repository at this point in the history
  • Loading branch information
woody-apple committed Oct 27, 2021
2 parents 2996f40 + 9b8410f commit 65dbbf9
Show file tree
Hide file tree
Showing 99 changed files with 17,540 additions and 15,291 deletions.
16 changes: 16 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -14890,6 +14890,14 @@
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestNullableOptionalRequest",
"code": 15,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
}
],
"attributes": [
Expand Down Expand Up @@ -14949,6 +14957,14 @@
"source": "server",
"incoming": 0,
"outgoing": 1
},
{
"name": "TestNullableOptionalResponse",
"code": 6,
"mfgCode": null,
"source": "server",
"incoming": 0,
"outgoing": 1
}
],
"attributes": [
Expand Down
30 changes: 30 additions & 0 deletions examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#pragma once

#include "controller/ExampleOperationalCredentialsIssuer.h"
#include <app/data-model/Nullable.h>
#include <controller/CHIPDeviceController.h>
#include <inet/InetInterface.h>
#include <lib/core/Optional.h>
#include <lib/support/Span.h>
#include <lib/support/logging/CHIPLogging.h>

Expand Down Expand Up @@ -151,6 +153,34 @@ class Command
return AddArgument(name, min, max, reinterpret_cast<std::underlying_type_t<T> *>(out));
}

template <typename T>
size_t AddArgument(const char * name, chip::Optional<T> * value)
{
// We always require our args to be provided for the moment.
return AddArgument(name, &value->Emplace());
}

template <typename T>
size_t AddArgument(const char * name, int64_t min, uint64_t max, chip::Optional<T> * value)
{
// We always require our args to be provided for the moment.
return AddArgument(name, min, max, &value->Emplace());
}

template <typename T>
size_t AddArgument(const char * name, chip::app::DataModel::Nullable<T> * value)
{
// We always require our args to be provided for the moment.
return AddArgument(name, &value->SetNonNull());
}

template <typename T>
size_t AddArgument(const char * name, int64_t min, uint64_t max, chip::app::DataModel::Nullable<T> * value)
{
// We always require our args to be provided for the moment.
return AddArgument(name, min, max, &value->SetNonNull());
}

virtual CHIP_ERROR Run() = 0;

private:
Expand Down
12 changes: 12 additions & 0 deletions examples/chip-tool/commands/tests/TestCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ class TestCommand : public CHIPCommand

bool CheckValueAsString(const char * itemName, chip::CharSpan current, const char * expected);

template <typename T>
bool CheckValuePresent(const char * itemName, const chip::Optional<T> & value)
{
if (value.HasValue())
{
return true;
}

Exit(std::string(itemName) + " expected to have value but doesn't");
return false;
}

chip::Callback::Callback<chip::Controller::OnDeviceConnected> mOnDeviceConnectedCallback;
chip::Callback::Callback<chip::Controller::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;

Expand Down
2 changes: 2 additions & 0 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}Success(v
{{~#*inline "field"}}data.{{asLowerCamelCase label}}{{/inline~}}
{{#if isArray}}
ChipLogProgress(Zcl, " {{label}}: Array printing is not implemented yet.");
{{else if isOptional}}
ChipLogProgress(Zcl, " {{label}}: Optional printing is not implemented yet.");
{{else if (isOctetString type)}}
ChipLogProgress(Zcl, " {{label}}: %zu", {{>field}}.size());
{{else if (isCharString type)}}
Expand Down
10 changes: 9 additions & 1 deletion examples/chip-tool/templates/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ class {{filename}}: public TestCommand
VerifyOrReturn(mReceivedReport_{{waitForReport.index}}, Exit("Initial report not received!"));
{{/if}}
{{#chip_tests_item_response_parameters}}
{{~#*inline "item"}}{{asLowerCamelCase name}}{{/inline}}
{{~#*inline "item"}}{{asLowerCamelCase name}}{{#if isOptional}}.Value(){{/if}}{{/inline}}
{{#if hasExpectedValue}}
{{#if isOptional}}
{{~#*inline "item"}}{{asLowerCamelCase name}}{{/inline}}
VerifyOrReturn(CheckValuePresent("{{> item}}", {{> item}}));
{{/if}}
VerifyOrReturn(CheckValue
{{~#if isList}}AsListLength("{{>item}}", {{>item}}, {{expectedValue.length}})
{{else if isArray}}AsList("{{>item}}", {{>item}}, {{expectedValue}})
Expand All @@ -182,6 +186,10 @@ class {{filename}}: public TestCommand
);
{{/if}}
{{#if hasExpectedConstraints}}
{{#if isOptional}}
{{~#*inline "item"}}{{asLowerCamelCase name}}{{/inline}}
VerifyOrReturn(CheckValuePresent("{{> item}}", {{> item}}));
{{/if}}
{{#if expectedConstraints.type}}VerifyOrReturn(CheckConstraintType("{{>item}}", "", "{{expectedConstraints.type}}"));{{/if}}
{{~#if expectedConstraints.format}}VerifyOrReturn(CheckConstraintFormat("{{>item}}", "", "{{expectedConstraints.format}}"));{{/if}}
{{~#if expectedConstraints.minLength}}VerifyOrReturn(CheckConstraintMinLength("{{>item}}", {{>item}}.size(), {{expectedConstraints.minLength}}));{{/if}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
{{#if isArray}}
{{#if isOptional}}
{{#if ignore}}
{{>commandValue ns=ns container=(concat container ".Emplace()") definedValue=definedValue type=type isOptional=false ignore=true}}
{{else}}
{{>commandValue ns=ns container=(concat container "." label ".Emplace()") definedValue=definedValue type=type isOptional=false ignore=true}}
{{/if}}
{{else if isNullable}}
{{#if ignore}}
{{>commandValue ns=ns container=(concat container ".SetNonNull()") definedValue=definedValue type=type isNullable=false ignore=true}}
{{else}}
{{>commandValue ns=ns container=(concat container "." label ".SetNonNull()") definedValue=definedValue type=type isNullable=false ignore=true}}
{{/if}}
{{else if isArray}}

{{! forceNotList=true because we really want the type of a single item here }}
{{zapTypeToEncodableClusterObjectType type ns=ns forceNotList=true}} {{asLowerCamelCase label}}List[{{definedValue.length}}];
{{! forceNotList=true because we really want the type of a single item here.
Similarly, forceNotOptional=true and forceNotNullable=true because we
have accounted for those already. }}
{{zapTypeToEncodableClusterObjectType type ns=ns forceNotList=true forceNotNullable=true forceNotOptional=true}} {{asLowerCamelCase label}}List[{{definedValue.length}}];
{{#each definedValue}}
{{>commandValue ns=../ns container=(concat (asLowerCamelCase ../label) "List[" @index "]") definedValue=. type=../type ignore=true}}
{{/each}}
Expand Down
28 changes: 28 additions & 0 deletions scripts/helpers/pull_upstream_and_regenerate_zap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
set -x

git pull upstream master
git submodule update --init --recursive third_party/zap/

git status

cd third_party/zap/repo/
npm ci
npm run version-stamp
npm rebuild canvas --update-binary
npm run build-spa

cd ../../../

scripts/tools/zap_regen_all.py

git status

git add zzz_generated/*
git add src/darwin/Framework/*
git add src/controller/python/chip/clusters/*
git add src/controller/java/zap-generated/*

git status

git commit -m "Regenerating ZAP"
99 changes: 0 additions & 99 deletions scripts/helpers/rebase_and_regenerate_zap.sh

This file was deleted.

75 changes: 35 additions & 40 deletions src/app/clusters/basic/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,81 +18,76 @@

#include "basic.h"

#include <app-common/zap-generated/attributes/Accessors.h>
#include <platform/CHIPDeviceLayer.h>

#include <app-common/zap-generated/att-storage.h>
#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <lib/support/ZclString.h>
#include <protocols/interaction_model/Constants.h>

#include <cstring>

using namespace chip;
using namespace chip::app::Clusters::Basic;
using namespace chip::DeviceLayer;

void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint)
{
uint16_t vendorId;
uint16_t productId;
uint16_t productRevision;
uint32_t firmwareRevision;
char cString[65];
uint8_t bufferMemory[65];
MutableByteSpan zclString(bufferMemory);
EmberAfStatus status;

if (ConfigurationMgr().GetVendorName(cString, sizeof(cString)) == CHIP_NO_ERROR)
char vendorName[33];
if (ConfigurationMgr().GetVendorName(vendorName, sizeof(vendorName)) == CHIP_NO_ERROR)
{
MakeZclCharString(zclString, cString);
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_VENDOR_NAME_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, zclString.data(),
ZCL_CHAR_STRING_ATTRIBUTE_TYPE);
status = Attributes::VendorName::Set(endpoint, chip::CharSpan(vendorName, strlen(vendorName)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Vendor Name: 0x%02x", status));
}

uint16_t vendorId;
if (ConfigurationMgr().GetVendorId(vendorId) == CHIP_NO_ERROR)
{
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_VENDOR_ID_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
reinterpret_cast<uint8_t *>(&vendorId), ZCL_INT16U_ATTRIBUTE_TYPE);
status = Attributes::VendorID::Set(endpoint, vendorId);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Vendor Id: 0x%02x", status));
}

if (ConfigurationMgr().GetProductName(cString, sizeof(cString)) == CHIP_NO_ERROR)
char productName[33];
if (ConfigurationMgr().GetProductName(productName, sizeof(productName)) == CHIP_NO_ERROR)
{
MakeZclCharString(zclString, cString);
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_PRODUCT_NAME_ATTRIBUTE_ID, CLUSTER_MASK_SERVER, zclString.data(),
ZCL_CHAR_STRING_ATTRIBUTE_TYPE);
status = Attributes::ProductName::Set(endpoint, chip::CharSpan(productName, strlen(productName)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product Name: 0x%02x", status));
}

uint16_t productId;
if (ConfigurationMgr().GetProductId(productId) == CHIP_NO_ERROR)
{
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_PRODUCT_ID_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
reinterpret_cast<uint8_t *>(&productId), ZCL_INT16U_ATTRIBUTE_TYPE);
status = Attributes::ProductID::Set(endpoint, productId);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product Id: 0x%02x", status));
}

if (ConfigurationMgr().GetProductRevisionString(cString, sizeof(cString)) == CHIP_NO_ERROR)
char productRevisionString[65];
if (ConfigurationMgr().GetProductRevisionString(productRevisionString, sizeof(productRevisionString)) == CHIP_NO_ERROR)
{
MakeZclCharString(zclString, cString);
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_HARDWARE_VERSION_STRING_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE);
status =
Attributes::HardwareVersionString::Set(endpoint, chip::CharSpan(productRevisionString, strlen(productRevisionString)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status,
ChipLogError(Zcl, "Error setting Hardware Version String: 0x%02x", status));
}

uint16_t productRevision;
if (ConfigurationMgr().GetProductRevision(productRevision) == CHIP_NO_ERROR)
{
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_HARDWARE_VERSION_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
reinterpret_cast<uint8_t *>(&productRevision), ZCL_INT16U_ATTRIBUTE_TYPE);
status = Attributes::HardwareVersion::Set(endpoint, productRevision);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Hardware Version: 0x%02x", status));
}

if (ConfigurationMgr().GetFirmwareRevisionString(cString, sizeof(cString)) == CHIP_NO_ERROR)
char firmwareRevisionString[65];
if (ConfigurationMgr().GetFirmwareRevisionString(firmwareRevisionString, sizeof(firmwareRevisionString)) == CHIP_NO_ERROR)
{
MakeZclCharString(zclString, cString);
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_SOFTWARE_VERSION_STRING_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
zclString.data(), ZCL_CHAR_STRING_ATTRIBUTE_TYPE);
status = Attributes::SoftwareVersionString::Set(endpoint,
chip::CharSpan(firmwareRevisionString, strlen(firmwareRevisionString)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status,
ChipLogError(Zcl, "Error setting Software Version String: 0x%02x", status));
}

uint16_t firmwareRevision;
if (ConfigurationMgr().GetFirmwareRevision(firmwareRevision) == CHIP_NO_ERROR)
{
emberAfWriteAttribute(endpoint, ZCL_BASIC_CLUSTER_ID, ZCL_SOFTWARE_VERSION_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
reinterpret_cast<uint8_t *>(&firmwareRevision), ZCL_INT32U_ATTRIBUTE_TYPE);
status = Attributes::HardwareVersion::Set(endpoint, firmwareRevision);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Software Version: 0x%02x", status));
}
}
Loading

0 comments on commit 65dbbf9

Please sign in to comment.