Skip to content

Commit 2675b00

Browse files
[Chef] Fix AirQualitySensor to support RPC write (project-chip#30822)
* Fix AirQualitySensor to support RPC write 1. Support Write Attributes through RPC 2. Support Multiple Endpoints for AirQuality / Concentration Measurement Clusters 3. Fix comformance issues caught by TC_DeviceConformance.py * Restyled by whitespace * Restyled by clang-format * Update ZAP version and fix compilation issues * Restyled by clang-format --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent 5bd7c37 commit 2675b00

7 files changed

+517
-135
lines changed

examples/chef/common/chef-air-quality.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <app-common/zap-generated/ids/Clusters.h>
2020
#include <app/util/config.h>
2121
#include <lib/core/DataModelTypes.h>
22+
#include <map>
2223

2324
using namespace chip;
2425
using namespace chip::app;
@@ -30,10 +31,57 @@ using namespace chip::app::Clusters::AirQuality;
3031

3132
static chip::BitMask<Feature, uint32_t> airQualityFeatures(Feature::kFair, Feature::kModerate, Feature::kVeryPoor,
3233
Feature::kExtremelyPoor);
33-
static Instance gAirQualityClusterInstance = Instance(1, airQualityFeatures);
34+
static std::map<int, Instance *> gAirQualityClusterInstance{};
3435

3536
void emberAfAirQualityClusterInitCallback(chip::EndpointId endpointId)
3637
{
37-
gAirQualityClusterInstance.Init();
38+
Instance * clusterInstance = new Instance(1, airQualityFeatures);
39+
clusterInstance->Init();
40+
gAirQualityClusterInstance[1] = clusterInstance;
41+
}
42+
43+
EmberAfStatus chefAirQualityWriteCallback(EndpointId endpoint, ClusterId clusterId,
44+
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer)
45+
{
46+
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;
47+
48+
if (gAirQualityClusterInstance.find(endpoint) == gAirQualityClusterInstance.end())
49+
{
50+
ChipLogError(DeviceLayer, "Invalid Endpoind ID: %d", endpoint);
51+
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
52+
}
53+
54+
Instance * clusterInstance = gAirQualityClusterInstance[endpoint];
55+
AttributeId attributeId = attributeMetadata->attributeId;
56+
57+
switch (attributeId)
58+
{
59+
case chip::app::Clusters::AirQuality::Attributes::AirQuality::Id: {
60+
AirQualityEnum m = static_cast<AirQualityEnum>(buffer[0]);
61+
Protocols::InteractionModel::Status status = clusterInstance->UpdateAirQuality(m);
62+
if (Protocols::InteractionModel::Status::Success == status)
63+
{
64+
break;
65+
}
66+
ret = EMBER_ZCL_STATUS_UNSUPPORTED_WRITE;
67+
ChipLogError(DeviceLayer, "Invalid Attribute Update status: %d", static_cast<int>(status));
68+
}
69+
break;
70+
default:
71+
ret = EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
72+
ChipLogError(DeviceLayer, "Unsupported Attribute ID: %d", static_cast<int>(attributeId));
73+
break;
74+
}
75+
76+
return ret;
77+
}
78+
79+
EmberAfStatus chefAirQualityReadCallback(EndpointId endpoint, ClusterId clusterId,
80+
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
81+
uint16_t maxReadLength)
82+
{
83+
EmberAfStatus ret = EMBER_ZCL_STATUS_SUCCESS;
84+
85+
return ret;
3886
}
3987
#endif
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include <app-common/zap-generated/callback.h>
18+
#include <app-common/zap-generated/ids/Attributes.h>
19+
#include <app-common/zap-generated/ids/Clusters.h>
20+
#include <app/util/af-types.h>
21+
#include <app/util/config.h>
22+
#include <lib/core/DataModelTypes.h>
23+
24+
#ifdef EMBER_AF_PLUGIN_AIR_QUALITY_SERVER
25+
EmberAfStatus chefAirQualityWriteCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
26+
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer);
27+
EmberAfStatus chefAirQualityReadCallback(chip::EndpointId endpoint, chip::ClusterId clusterId,
28+
const EmberAfAttributeMetadata * attributeMetadata, uint8_t * buffer,
29+
uint16_t maxReadLength);
30+
#endif

0 commit comments

Comments
 (0)