Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Im/ember array unpack (local test) #1

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -13815,6 +13815,21 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "simple_struct",
"code": 32,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
Expand Down Expand Up @@ -17335,5 +17350,6 @@
"endpointVersion": null,
"deviceIdentifier": null
}
]
}
],
"log": []
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(PRIV_INCLUDE_DIRS_LIST
set(SRC_DIRS_LIST
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/all-clusters-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
Expand Down
1 change: 1 addition & 0 deletions examples/bridge-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
SRC_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/bridge-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
Expand Down
10 changes: 9 additions & 1 deletion examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttri
ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

{{else if isStruct}}
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}StructAttributeResponse(void * context, {{chipType}} value) {
ChipLogProgress(chipTool, "On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}StructAttributeResponse: TODO: Print struct content.");
IgnoreUnusedVariable(value);
ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}
{{/if}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}
Expand Down Expand Up @@ -294,6 +300,8 @@ public:
private:
{{#if isList}}
chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback> * onSuccessCallback = new chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback>(On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse, this);
{{else if isStruct}}
chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback> * onSuccessCallback = new chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}AttributeCallback>(On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}StructAttributeResponse, this);
{{else}}
chip::Callback::Callback<{{chipCallback.name}}AttributeCallback> * onSuccessCallback = new chip::Callback::Callback<{{chipCallback.name}}AttributeCallback>(On{{chipCallback.name}}AttributeResponse, this);
{{/if}}
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ target_sources(${APP_TARGET} PRIVATE
${GEN_DIR}/lighting-app/zap-generated/IMClusterCommandHandler.cpp
${MBED_COMMON}/util/LEDWidget.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ target_sources(app PRIVATE
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ target_sources(app PRIVATE
${TELINK_COMMON}/util/src/ButtonManager.cpp
${TELINK_COMMON}/util/src/ThreadUtil.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
Expand Down
2 changes: 2 additions & 0 deletions examples/lock-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ idf_component_register(INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/../../platform/esp32"
"${CMAKE_SOURCE_DIR}/../../common/pigweed"
"${CMAKE_SOURCE_DIR}/../../common/pigweed/esp32"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lock-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
Expand Down Expand Up @@ -121,6 +122,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_CURRENT_LIST_DIR}/include"
SRC_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lock-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension"
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ target_sources(${APP_TARGET} PRIVATE
${GEN_DIR}/lock-app/zap-generated/IMClusterCommandHandler.cpp
${MBED_COMMON}/util/LEDWidget.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
${CHIP_ROOT}/src/app/reporting/reporting.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ target_sources(app PRIVATE
${GEN_DIR}/lock-app/zap-generated/IMClusterCommandHandler.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/pump-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ target_sources(app PRIVATE
${GEN_DIR}/pump-app/zap-generated/IMClusterCommandHandler.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
Expand Down
1 change: 1 addition & 0 deletions examples/pump-controller-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ target_sources(app PRIVATE
${GEN_DIR}/pump-controller-app/zap-generated/IMClusterCommandHandler.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp
${CHIP_ROOT}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp
${CHIP_ROOT}/src/app/util/DataModelHandler.cpp
${CHIP_ROOT}/src/app/reporting/reporting-default-configuration.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
SRC_DIRS
"${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/temperature-measurement-app/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util"
Expand Down
1 change: 1 addition & 0 deletions src/app/chip_data_model.gni
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ template("chip_data_model") {
"${_app_root}/util/process-cluster-message.cpp",
"${_app_root}/util/process-global-message.cpp",
"${_app_root}/util/util.cpp",
"${chip_root}/zzz_generated/app-common/app-common/zap-generated/af-structs.cpp",
"${chip_root}/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp",
]

Expand Down
15 changes: 15 additions & 0 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ EmberAfStatus writeTestListStructOctetAttribute(EndpointId endpoint)
VerifyOrReturnError(status == EMBER_ZCL_STATUS_SUCCESS, status);
return status;
}

EmberAfStatus writeTestStructAttribute(EndpointId endpoint)
{
_SimpleStruct structValue;
structValue.fieldA = 0xfedcba9876543210;
structValue.fieldB = 0x76543210;
uint8_t buf[16];
size_t len;
VerifyOrReturnError(CHIP_NO_ERROR == _SimpleStruct::ToEmberBuffer(&structValue, buf, sizeof(buf), len),
EMBER_ZCL_STATUS_FAILURE);
return writeAttribute(endpoint, ZCL_SIMPLE_STRUCT_ATTRIBUTE_ID, buf);
}
} // namespace

void emberAfPluginTestClusterServerInitCallback(void)
Expand All @@ -145,6 +157,9 @@ void emberAfPluginTestClusterServerInitCallback(void)

status = writeTestListStructOctetAttribute(endpoint);
VerifyOrReturn(status == EMBER_ZCL_STATUS_SUCCESS, ChipLogError(Zcl, kErrorStr, endpoint, "test list strut octet", status));

status = writeTestStructAttribute(endpoint);
VerifyOrReturn(status == EMBER_ZCL_STATUS_SUCCESS, ChipLogError(Zcl, kErrorStr, endpoint, "test struct", status));
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/app/common/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"version": "chip-v1",
"helpers": [
"../../zap-templates/partials/helper.js",
"../../zap-templates/common/ChipTypesHelper.js",
"../../zap-templates/common/StringHelper.js",
"../../zap-templates/common/ListHelper.js",
"../../zap-templates/common/attributes/Accessors.js",
"../../zap-templates/templates/app/helper.js",
"../../zap-templates/templates/chip/helper.js"
Expand All @@ -21,6 +23,11 @@
"name": "ZCL af-structs header",
"output": "af-structs.h"
},
{
"path": "../../zap-templates/templates/app/af-structs-src.zapt",
"name": "ZCL af-structs encoder",
"output": "af-structs.cpp"
},
{
"path": "../../zap-templates/templates/app/att-storage.zapt",
"name": "ZCL att-storage header",
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/attribute-list-byte-span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CHIP_ERROR ReadByteSpan(const uint8_t * buffer, uint16_t bufferLen, chip::ByteSp
return CHIP_NO_ERROR;
}

CHIP_ERROR WriteByteSpan(uint8_t * buffer, uint16_t bufferLen, chip::ByteSpan * span)
CHIP_ERROR WriteByteSpan(uint8_t * buffer, uint16_t bufferLen, const chip::ByteSpan * span)
{
uint16_t size = static_cast<uint16_t>(span->size());
ReturnErrorOnFailure(WriteByteSpanSize(buffer, bufferLen, size));
Expand Down
2 changes: 1 addition & 1 deletion src/app/util/attribute-list-byte-span.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ CHIP_ERROR ReadByteSpan(const uint8_t * buffer, uint16_t bufferLen, chip::ByteSp
* @param [in] span The bytespan to serialize
*
*/
CHIP_ERROR WriteByteSpan(uint8_t * buffer, uint16_t bufferLen, chip::ByteSpan * span);
CHIP_ERROR WriteByteSpan(uint8_t * buffer, uint16_t bufferLen, const chip::ByteSpan * span);

/**
* @brief Returns the byte offset of a serialized bytespan into a buffer of serialized bytespans.
Expand Down
22 changes: 14 additions & 8 deletions src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ using namespace chip;
using namespace chip::app;
using namespace chip::app::Compatibility;

CHIP_ERROR CopyStructAttributeToCHIPTLV(ClusterId clusterId, AttributeId attributeId, uint8_t * src, uint16_t len,
TLV::TLVWriter & writer, uint64_t tag);
CHIP_ERROR EmberListToCHIPTLV(ClusterId clusterId, AttributeId attributeId, uint8_t * src, uint16_t len, TLV::TLVWriter & writer,
uint64_t tag);

namespace chip {
namespace app {
namespace Compatibility {
Expand Down Expand Up @@ -324,14 +329,15 @@ CHIP_ERROR ReadSingleClusterData(ClusterInfo & aClusterInfo, TLV::TLVWriter * ap
break;
}
case ZCL_ARRAY_ATTRIBUTE_TYPE: {
TLV::TLVType containerType;
ReturnErrorOnFailure(
apWriter->StartContainer(TLV::ContextTag(AttributeDataElement::kCsTag_Data), TLV::kTLVType_List, containerType));
// TODO: Encode data in TLV, now raw buffers
ReturnErrorOnFailure(apWriter->PutBytes(
TLV::AnonymousTag, attributeData,
emberAfAttributeValueSize(aClusterInfo.mClusterId, aClusterInfo.mFieldId, attributeType, attributeData)));
ReturnErrorOnFailure(apWriter->EndContainer(containerType));
ReturnErrorOnFailure(EmberListToCHIPTLV(aClusterInfo.mClusterId, aClusterInfo.mFieldId, attributeData,
sizeof(attributeData), *apWriter,
TLV::ContextTag(AttributeDataElement::kCsTag_Data)));
break;
}
case ZCL_STRUCT_ATTRIBUTE_TYPE: {
ReturnErrorOnFailure(CopyStructAttributeToCHIPTLV(aClusterInfo.mClusterId, aClusterInfo.mFieldId, attributeData,
sizeof(attributeData), *apWriter,
TLV::ContextTag(AttributeDataElement::kCsTag_Data)));
break;
}
default:
Expand Down
16 changes: 16 additions & 0 deletions src/app/util/ember-compatibility-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@

namespace chip {
namespace app {

using TLVEncoderFunct = CHIP_ERROR (*)(const void * val, chip::TLV::TLVWriter & writer, uint64_t tag);
using TLVDecoderFunct = CHIP_ERROR (*)(void * val, const chip::TLV::TLVReader & aReader);
using EmberBufferEncodeFunct = CHIP_ERROR (*)(const void * valPtr, uint8_t * buf, size_t bufLength, size_t & len);
using EmberBufferDecodeFunct = CHIP_ERROR (*)(void * valPtr, const uint8_t * buf, size_t bufLength);

struct AttributeStructEncoderInfo
{
TLVEncoderFunct TLVEncoder = nullptr;
TLVDecoderFunct TLVDecoder = nullptr;
EmberBufferEncodeFunct EmberEncoder = nullptr;
EmberBufferDecodeFunct EmberDecoder = nullptr;
};

const AttributeStructEncoderInfo * GetAttributeStructEncoderInfo(ClusterId clusterId, AttributeId attributeId);

namespace Compatibility {

void SetupEmberAfObjects(Command * command, ClusterId clusterId, CommandId commandId, EndpointId endpointId);
Expand Down
6 changes: 6 additions & 0 deletions src/app/zap-templates/common/ChipTypesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ function asBasicType(type)
}
}

function isNoData(type)
{
return type == 'NO_DATA';
}

//
// Module exports
//
exports.asBasicType = asBasicType;
exports.isNoData = isNoData;
7 changes: 4 additions & 3 deletions src/app/zap-templates/common/ClustersHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function getEnum(enums, type)

function getStruct(structs, type)
{
return structs.find(struct => struct.label == type);
return structs.find(struct => struct.label.toLowerCase() == type.toLowerCase());
}

function handleString(item, [ atomics, enums, bitmaps, structs ])
Expand Down Expand Up @@ -278,14 +278,15 @@ function handleList(item, [ atomics, enums, bitmaps, structs ])

function handleStruct(item, [ atomics, enums, bitmaps, structs ])
{
const struct = getStruct(structs, item.type);
const struct = StructHelper.isStruct(item.type) ? getStruct(structs, item.entryType) : getStruct(structs, item.type);
if (!struct) {
return false;
}

// Add a leading `_` before the name of struct to match what is done in the af-structs.zapt template.
// For instance structs are declared as "typedef struct _{{asType label}}".
item.chipType = '_' + item.type;
item.chipType = '_' + struct.label;
item.type = 'STRUCT';
item.isStruct = true;

struct.items.map(structItem => enhancedItem(structItem, [ atomics, enums, bitmaps, structs ]));
Expand Down
Loading