Skip to content

Commit

Permalink
Update emberAf*AttributeChange callbacks (#10315)
Browse files Browse the repository at this point in the history
* Add chip::app::ConcreteAttributePath

* Update emberAf[Pre/Post]AttributeChangeCallback signature to Matter[Pre/Post]AttributeChangeCallback

* Update emberAf{{asUpperCamelCase label}}ClusterAttributeChangeCallback signature to Matter{{asUpperCamelCase label}}AttributeChangeCallback

* Update usage of emberAf{{asUpperCamelCase label}}ClusterAttributeChangeCallback across the tree

* Update usage of emberAfPostAttributeChangeCallback across the tree

* Update generated content
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 18, 2021
1 parent 047619a commit 2a3cb0b
Show file tree
Hide file tree
Showing 54 changed files with 2,213 additions and 5,760 deletions.
25 changes: 0 additions & 25 deletions examples/all-clusters-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,11 @@
* limitations under the License.
*/

#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/Command.h>
#include <app/chip-zcl-zpro-codec.h>
#include <app/server/Mdns.h>
#include <app/util/af-types.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <app/util/util.h>
#include <lib/core/CHIPError.h>
#include <lib/support/CHIPMem.h>
#include <lib/support/RandUtils.h>

#include "AppMain.h"

#include <cassert>
#include <iostream>

using namespace chip;
using namespace chip::Inet;
using namespace chip::Transport;
using namespace chip::DeviceLayer;

void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
{}

bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::Command * commandObj)
{
emberAfSendDefaultResponse(emberAfCurrentCommand(), EMBER_ZCL_STATUS_SUCCESS);
Expand Down
22 changes: 9 additions & 13 deletions examples/lighting-app/efr32/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@
*/

#include "AppConfig.h"
#include <lib/support/logging/CHIPLogging.h>

#include "LightingManager.h"

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/util/af-types.h>
#include <app/ConcreteAttributePath.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace ::chip;
using namespace ::chip::app::Clusters;

void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type,
uint16_t size, uint8_t * value)
{
if (clusterId == OnOff::Id)
{
if (attributeId != OnOff::Attributes::OnOff::Id)
{
ChipLogError(Zcl, "ON OFF attribute ID: " ChipLogFormatMEI " Type: %" PRIu8 " Value: %" PRIu16 ", length %" PRIu16,
ChipLogValueMEI(attributeId), type, *value, size);
return;
}
ClusterId clusterId = attributePath.mClusterId;
AttributeId attributeId = attributePath.mAttributeId;
ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId));

if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id)
{
LightMgr().InitiateAction(AppEvent::kEventType_Light, *value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION);
}
else if (clusterId == LevelControl::Id)
Expand Down
43 changes: 8 additions & 35 deletions examples/lighting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,27 @@
* limitations under the License.
*/

#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>
#include "LightingManager.h"
#include <AppMain.h>

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/chip-zcl-zpro-codec.h>
#include <app/util/af-types.h>
#include <app/util/af.h>
#include <app/util/attribute-storage.h>
#include <app/util/util.h>

#include "LightingManager.h"

#include <AppMain.h>
#include <app/ConcreteAttributePath.h>
#include <lib/support/logging/CHIPLogging.h>

#if defined(PW_RPC_ENABLED)
#include "Rpc.h"
#endif // PW_RPC_ENABLED

#include <cassert>
#include <iostream>

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

void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type,
uint16_t size, uint8_t * value)
{
if (clusterId != OnOff::Id)
{
ChipLogProgress(Zcl, "Unknown cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(clusterId));
return;
}

if (attributeId != OnOff::Attributes::OnOff::Id)
{
ChipLogProgress(Zcl, "Unknown attribute ID: " ChipLogFormatMEI, ChipLogValueMEI(attributeId));
return;
}

if (*value)
{
LightingMgr().InitiateAction(LightingManager::ON_ACTION);
}
else
if (attributePath.mClusterId == OnOff::Id && attributePath.mAttributeId == OnOff::Attributes::OnOff::Id)
{
LightingMgr().InitiateAction(LightingManager::OFF_ACTION);
LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION);
}
}

Expand Down
43 changes: 13 additions & 30 deletions examples/lighting-app/mbed/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,31 @@
* limitations under the License.
*/

#include <lib/support/logging/CHIPLogging.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/command-id.h>
#include <app/util/af-types.h>
#include <app/util/af.h>

#include "AppTask.h"
#include "LightingManager.h"

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;
using namespace ::chip::app::Clusters;

void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type,
uint16_t size, uint8_t * value)
{
ChipLogProgress(Zcl, "Cluster callback: %" PRIx32, clusterId);
ClusterId clusterId = attributePath.mClusterId;
AttributeId attributeId = attributePath.mAttributeId;
ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId));

if (clusterId == ZCL_ON_OFF_CLUSTER_ID)
if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id)
{
if (attributeId != ZCL_ON_OFF_ATTRIBUTE_ID)
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
return;
}

LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION,
AppEvent::kEventType_Lighting, size, value);
}
else if (clusterId == ZCL_LEVEL_CONTROL_CLUSTER_ID)
else if (clusterId == LevelControl::Id && attributeId == LevelControl::Attributes::CurrentLevel::Id)
{
if (attributeId != ZCL_CURRENT_LEVEL_ATTRIBUTE_ID)
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
return;
}

ChipLogProgress(Zcl, "Value: %u, length %u", *value, size);
if (size == 1)
{
Expand All @@ -63,11 +51,6 @@ void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId
ChipLogError(Zcl, "wrong length for level: %d", size);
}
}
else
{
ChipLogProgress(Zcl, "Unknown cluster ID: %" PRIx32, clusterId);
return;
}
}

/** @brief OnOff Cluster Init
Expand Down
18 changes: 9 additions & 9 deletions examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@
* limitations under the License.
*/

#include <lib/support/logging/CHIPLogging.h>
#include "AppTask.h"
#include "LightingManager.h"

#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app-common/zap-generated/ids/Commands.h>
#include <app/util/af-types.h>
#include <app/util/af.h>

#include "AppTask.h"
#include "LightingManager.h"
#include <app/ConcreteAttributePath.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace chip;
using namespace chip::app::Clusters;

void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type,
uint16_t size, uint8_t * value)
{
ClusterId clusterId = attributePath.mClusterId;
AttributeId attributeId = attributePath.mAttributeId;

if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id)
{
ChipLogProgress(Zcl, "Cluster OnOff: attribute OnOff set to %" PRIu8, *value);
Expand Down
61 changes: 25 additions & 36 deletions examples/lighting-app/qpg/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,29 @@
#include "AppTask.h"
#include "LightingManager.h"

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/command-id.h>
#include <app/chip-zcl-zpro-codec.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/ConcreteAttributePath.h>
#include <app/util/af-types.h>
#include <app/util/attribute-storage.h>
#include <app/util/util.h>
#include <lib/support/logging/CHIPLogging.h>

using namespace ::chip;
using namespace chip::app::Clusters;

void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId, AttributeId attributeId, uint8_t mask,
uint16_t manufacturerCode, uint8_t type, uint16_t size, uint8_t * value)
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t mask, uint8_t type,
uint16_t size, uint8_t * value)
{
if (clusterId == ZCL_ON_OFF_CLUSTER_ID)
{
if (attributeId != ZCL_ON_OFF_ATTRIBUTE_ID)
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
return;
}
EndpointId endpoint = attributePath.mEndpointId;
ClusterId clusterId = attributePath.mClusterId;
AttributeId attributeId = attributePath.mAttributeId;

if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id)
{
LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION, 0, size, value);
}
else if (clusterId == ZCL_LEVEL_CONTROL_CLUSTER_ID)
else if (clusterId == LevelControl::Id && attributeId == LevelControl::Attributes::CurrentLevel::Id)
{
if (attributeId != ZCL_CURRENT_LEVEL_ATTRIBUTE_ID)
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
return;
}

if (size == 1)
{
ChipLogProgress(Zcl, "New level: %u", *value);
Expand All @@ -64,36 +54,35 @@ void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId
ChipLogError(Zcl, "wrong length for level: %d", size);
}
}
else if (clusterId == ZCL_COLOR_CONTROL_CLUSTER_ID)
else if (clusterId == ColorControl::Id)
{
/* ignore several attributes that are currently not processed */
if ((attributeId == ZCL_COLOR_CONTROL_REMAINING_TIME_ATTRIBUTE_ID) ||
(attributeId == ZCL_COLOR_CONTROL_ENHANCED_COLOR_MODE_ATTRIBUTE_ID) ||
(attributeId == ZCL_COLOR_CONTROL_COLOR_MODE_ATTRIBUTE_ID))
if ((attributeId == ColorControl::Attributes::RemainingTime::Id) ||
(attributeId == ColorControl::Attributes::EnhancedColorMode::Id) ||
(attributeId == ColorControl::Attributes::ColorMode::Id))
{
return;
}

if ((attributeId != ZCL_COLOR_CONTROL_CURRENT_X_ATTRIBUTE_ID) &&
(attributeId != ZCL_COLOR_CONTROL_CURRENT_Y_ATTRIBUTE_ID) &&
(attributeId != ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID) &&
(attributeId != ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID))
if ((attributeId != ColorControl::Attributes::CurrentX::Id) && (attributeId != ColorControl::Attributes::CurrentY::Id) &&
(attributeId != ColorControl::Attributes::CurrentHue::Id) &&
(attributeId != ColorControl::Attributes::CurrentSaturation::Id))
{
ChipLogProgress(Zcl, "Unknown attribute ID: %" PRIx32, attributeId);
ChipLogProgress(Zcl, "Unknown attribute ID: " ChipLogFormatMEI, ChipLogValueMEI(attributeId));
return;
}

if (size == sizeof(uint16_t))
{
XyColor_t xy;
if (attributeId == ZCL_COLOR_CONTROL_CURRENT_X_ATTRIBUTE_ID)
if (attributeId == ColorControl::Attributes::CurrentX::Id)
{
xy.x = *reinterpret_cast<uint16_t *>(value);
// get Y from cluster value storage
EmberAfStatus status = ColorControl::Attributes::CurrentY::Get(endpoint, &xy.y);
assert(status == EMBER_ZCL_STATUS_SUCCESS);
}
if (attributeId == ZCL_COLOR_CONTROL_CURRENT_Y_ATTRIBUTE_ID)
if (attributeId == ColorControl::Attributes::CurrentY::Id)
{
xy.y = *reinterpret_cast<uint16_t *>(value);
// get X from cluster value storage
Expand All @@ -106,14 +95,14 @@ void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId
else if (size == sizeof(uint8_t))
{
HsvColor_t hsv;
if (attributeId == ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID)
if (attributeId == ColorControl::Attributes::CurrentHue::Id)
{
hsv.h = *value;
// get saturation from cluster value storage
EmberAfStatus status = ColorControl::Attributes::CurrentSaturation::Get(endpoint, &hsv.s);
assert(status == EMBER_ZCL_STATUS_SUCCESS);
}
if (attributeId == ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID)
if (attributeId == ColorControl::Attributes::CurrentSaturation::Id)
{
hsv.s = *value;
// get hue from cluster value storage
Expand All @@ -130,7 +119,7 @@ void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId
}
else
{
ChipLogProgress(Zcl, "Unknown cluster ID: %" PRIx32, clusterId);
ChipLogProgress(Zcl, "Unknown cluster ID: " ChipLogFormatMEI, ChipLogValueMEI(clusterId));
return;
}
}
Expand Down
Loading

0 comments on commit 2a3cb0b

Please sign in to comment.