Skip to content

Commit fb902b5

Browse files
Add a silabs internal api to sync/link Zigbee attributes to matter attributes
1 parent 3b164b3 commit fb902b5

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*****************************************************************************
2+
* @file sl-matter-attribute-storage.cpp
3+
* @brief Link zigbee datamodel attribute changes to Matter attribute storage.
4+
*******************************************************************************
5+
* # License
6+
* <b>Copyright 2024 Silicon Laboratories Inc.
7+
*www.silabs.com</b>
8+
*******************************************************************************
9+
*
10+
* The licensor of this software is Silicon
11+
*Laboratories Inc. Your use of this software is
12+
*governed by the terms of Silicon Labs Master
13+
*Software License Agreement (MSLA) available at
14+
* www.silabs.com/about-us/legal/master-software-license-agreement.
15+
*This software is distributed to you in Source Code
16+
*format and is governed by the sections of the MSLA
17+
*applicable to Source Code.
18+
*
19+
******************************************************************************/
20+
21+
#include <app/util/attribute-metadata.h>
22+
#include <app/util/attribute-table.h>
23+
#include <lib/support/TypeTraits.h>
24+
#include <lib/support/logging/CHIPLogging.h>
25+
#include <protocols/interaction_model/StatusCode.h>
26+
#include <sl-matter-attribute-storage.h>
27+
#include <sl_component_catalog.h>
28+
29+
namespace {
30+
// This is called from simplicity_sdk/protocol/zigbee/app/framework/util/attribute-storage.c on ZB attribute write
31+
// when GENERATED_MULTI_PROTOCOL_ATTRIBUTE_MAPPING and SL_CATALOG_MULTIPROTOCOL_ZIGBEE_MATTER_COMMON_PRESENT are defined.
32+
extern "C" sl_status_t sli_matter_af_write_attribute(uint16_t endpointId, uint32_t clusterId, uint32_t attributeId,
33+
uint8_t * attributeValue, uint8_t type)
34+
{
35+
// All type shall be directly applicable. We expect compilation error if type changes.
36+
chip::EndpointId matterEndpointId = endpointId;
37+
chip::ClusterId matterClusterId = clusterId;
38+
chip::AttributeId matterAttributeId = attributeId;
39+
EmberAfAttributeType matterDataType = type;
40+
41+
chip::Protocols::InteractionModel::Status imStatus =
42+
emberAfWriteAttribute(matterEndpointId, matterClusterId, matterAttributeId, attributeValue, matterDataType);
43+
44+
// For sl internal use so we return a known status type to our stack
45+
sl_status_t slStatus = SL_STATUS_OK;
46+
if (imStatus != chip::Protocols::InteractionModel::Status::Success)
47+
{
48+
ChipLogError(Zcl, "Failed to write Matter attribute from multiprotocol update. Err:0x%02x", chip::to_underlying(imStatus));
49+
slStatus = SL_STATUS_FAIL;
50+
}
51+
52+
return slStatus;
53+
}
54+
} // namespace
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************************
2+
* @file sl-matter-attribute-storage.h
3+
* @brief Link zigbee datamodel attribute changes to Matter attribute storage.
4+
*******************************************************************************
5+
* # License
6+
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
7+
*******************************************************************************
8+
*
9+
* The licensor of this software is Silicon Laboratories Inc. Your use of this
10+
* software is governed by the terms of Silicon Labs Master Software License
11+
* Agreement (MSLA) available at
12+
* www.silabs.com/about-us/legal/master-software-license-agreement. This
13+
* software is distributed to you in Source Code format and is governed by the
14+
* sections of the MSLA applicable to Source Code.
15+
*
16+
******************************************************************************/
17+
18+
#ifndef SL_MATTER_ATTRIBUTE_STORAGE
19+
#define SL_MATTER_ATTRIBUTE_STORAGE
20+
21+
#include <sl_status.h>
22+
#include <stdint.h>
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/**
29+
* @brief Writes an attribute value to the Matter attribute storage.
30+
*
31+
* *** This is a Silabs internal api. ***
32+
*
33+
* It exposes the Matter API that writes to the Matter attribute storage to our zigbee datamodel stack,
34+
* implemented in C, for multiprotocol usecases, without exposing matter datamodel elements
35+
*
36+
* This function expect that either the used Zigbee cluster/attributes maps 1 to 1 to the matter counter part
37+
* or that the caller translated the Zigbee attribute parameters to Matter attribute parameters.
38+
*
39+
* The function ultimaly uses those fields in the Matter API to perform the attribute write operation.
40+
*
41+
* @param endpointId Linked ZB/Matter endpoint identifier.
42+
* @param clusterId Linked ZB/Matter cluster identifier.
43+
* @param attributeId Linked ZB/Matter attribute identifier.
44+
* @param attributeValue Pointer to the attribute value to be written.
45+
* @param type The data type of the attribute. Shall match Matters' EmberAfAttributeType
46+
* @return sl_status_t Status of the write operation, SL_STATUS_OK if successful, otherwise SL_STATUS_FAIL.
47+
*/
48+
sl_status_t sli_matter_af_write_attribute(uint16_t endpointId, uint32_t clusterId, uint32_t attributeId, uint8_t * attributeValue,
49+
uint8_t type);
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif // SL_MATTER_ATTRIBUTE_STORAGE

0 commit comments

Comments
 (0)