Skip to content

Commit aadb8aa

Browse files
authored
Merge branch 'master' into icd_provisional_attributes
2 parents 8324603 + 533df0c commit aadb8aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6019
-102
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+5-5
Original file line numberDiff line numberDiff line change
@@ -3876,7 +3876,7 @@ cluster ValveConfigurationAndControl = 129 {
38763876
}
38773877

38783878
/** This cluster provides a mechanism for querying data about electrical power as measured by the server. */
3879-
provisional cluster ElectricalPowerMeasurement = 144 {
3879+
cluster ElectricalPowerMeasurement = 144 {
38803880
revision 1;
38813881

38823882
enum MeasurementTypeEnum : enum16 {
@@ -3981,7 +3981,7 @@ provisional cluster ElectricalPowerMeasurement = 144 {
39813981
}
39823982

39833983
/** This cluster provides a mechanism for querying data about the electrical energy imported or provided by the server. */
3984-
provisional cluster ElectricalEnergyMeasurement = 145 {
3984+
cluster ElectricalEnergyMeasurement = 145 {
39853985
revision 1;
39863986

39873987
enum MeasurementTypeEnum : enum16 {
@@ -4278,7 +4278,7 @@ provisional cluster DeviceEnergyManagement = 152 {
42784278
}
42794279

42804280
/** Electric Vehicle Supply Equipment (EVSE) is equipment used to charge an Electric Vehicle (EV) or Plug-In Hybrid Electric Vehicle. This cluster provides an interface to the functionality of Electric Vehicle Supply Equipment (EVSE) management. */
4281-
provisional cluster EnergyEvse = 153 {
4281+
cluster EnergyEvse = 153 {
42824282
revision 2;
42834283

42844284
enum EnergyTransferStoppedReasonEnum : enum8 {
@@ -4490,7 +4490,7 @@ provisional cluster EnergyPreference = 155 {
44904490
}
44914491

44924492
/** The Power Topology Cluster provides a mechanism for expressing how power is flowing between endpoints. */
4493-
provisional cluster PowerTopology = 156 {
4493+
cluster PowerTopology = 156 {
44944494
revision 1;
44954495

44964496
bitmap Feature : bitmap32 {
@@ -4511,7 +4511,7 @@ provisional cluster PowerTopology = 156 {
45114511
}
45124512

45134513
/** Attributes and commands for selecting a mode from a list of supported options. */
4514-
provisional cluster EnergyEvseMode = 157 {
4514+
cluster EnergyEvseMode = 157 {
45154515
revision 1;
45164516

45174517
enum ModeTag : enum16 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 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+
18+
#pragma once
19+
20+
// Please refer to https://github.com/CHIP-Specifications/connectedhomeip-spec/blob/master/src/namespaces
21+
constexpr const uint8_t kNamespaceCommonLevel = 5;
22+
// Common Number Namespace: 5, tag 0 (Low)
23+
constexpr const uint8_t kTagCommonLow = 0;
24+
// Common Number Namespace: 5, tag 1 (Medium)
25+
constexpr const uint8_t kTagCommonMedium = 1;
26+
// Common Number Namespace: 5, tag 2 (High)
27+
constexpr const uint8_t kTagCommonHigh = 2;
28+
29+
constexpr const uint8_t kNamespaceCommonNumber = 7;
30+
// Common Number Namespace: 7, tag 0 (Zero)
31+
constexpr const uint8_t kTagCommonZero = 0;
32+
// Common Number Namespace: 7, tag 1 (One)
33+
constexpr const uint8_t kTagCommonOne = 1;
34+
// Common Number Namespace: 7, tag 2 (Two)
35+
constexpr const uint8_t kTagCommonTwo = 2;
36+
37+
constexpr const uint8_t kNamespacePosition = 8;
38+
// Common Position Namespace: 8, tag: 0 (Left)
39+
constexpr const uint8_t kTagPositionLeft = 0;
40+
// Common Position Namespace: 8, tag: 1 (Right)
41+
constexpr const uint8_t kTagPositionRight = 1;
42+
// Common Position Namespace: 8, tag: 2 (Top)
43+
constexpr const uint8_t kTagPositionTop = 2;
44+
// Common Position Namespace: 8, tag: 3 (Bottom)
45+
constexpr const uint8_t kTagPositionBottom = 3;
46+
// Common Position Namespace: 8, tag: 4 (Middle)
47+
constexpr const uint8_t kTagPositionMiddle = 4;
48+
// Common Position Namespace: 8, tag: 5 (Row)
49+
constexpr const uint8_t kTagPositionRow = 5;
50+
// Common Position Namespace: 8, tag: 6 (Column)
51+
constexpr const uint8_t kTagPositionColumn = 6;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include "chef-rpc-actions-worker.h"
20+
#include <app-common/zap-generated/attributes/Accessors.h>
21+
#include <app-common/zap-generated/callback.h>
22+
#include <app/data-model/Nullable.h>
23+
#include <app/util/config.h>
24+
#include <lib/core/DataModelTypes.h>
25+
#include <map>
26+
#include <platform/CHIPDeviceLayer.h>
27+
28+
using chip::app::DataModel::Nullable;
29+
30+
using namespace chip;
31+
using namespace chip::app;
32+
using namespace chip::app::Clusters;
33+
using namespace chip::rpc;
34+
35+
static std::map<ClusterId, ActionsDelegate *> gActionsDelegateMap{};
36+
37+
ActionsDelegate * RpcFindActionsDelegate(ClusterId clusterId)
38+
{
39+
if (gActionsDelegateMap.find(clusterId) != gActionsDelegateMap.end())
40+
{
41+
return gActionsDelegateMap[clusterId];
42+
}
43+
44+
return nullptr;
45+
}
46+
47+
static void RpcActionsTaskCallback(System::Layer * systemLayer, void * data)
48+
{
49+
ChefRpcActionsWorker * worker = (ChefRpcActionsWorker *) data;
50+
51+
worker->ProcessActionQueue();
52+
}
53+
54+
bool ChefRpcActionsCallback(EndpointId endpointId, ClusterId clusterId, uint8_t type, uint32_t delayMs, uint32_t actionId,
55+
std::vector<uint32_t> args)
56+
{
57+
ActionTask task(endpointId, clusterId, static_cast<ActionType>(type), delayMs, actionId, args);
58+
59+
return ChefRpcActionsWorker::Instance().EnqueueAction(task);
60+
}
61+
62+
bool ChefRpcActionsWorker::EnqueueAction(ActionTask task)
63+
{
64+
bool kickTimer = false;
65+
66+
if (queue.empty())
67+
{
68+
kickTimer = true; // kick timer when the first task is adding to the queue
69+
}
70+
71+
queue.push(task);
72+
73+
if (kickTimer)
74+
{
75+
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(task.delayMs), RpcActionsTaskCallback, this);
76+
}
77+
return true;
78+
}
79+
80+
void ChefRpcActionsWorker::ProcessActionQueue()
81+
{
82+
// Dequeue the first item
83+
ActionTask task = queue.front();
84+
queue.pop();
85+
86+
ActionsDelegate * delegate = RpcFindActionsDelegate(task.clusterId);
87+
if (nullptr == delegate)
88+
{
89+
ChipLogError(NotSpecified,
90+
"Cannot run action due to not finding delegate: endpointId=%d, clusterId=%04lx, attributeId=%04lx",
91+
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId));
92+
return;
93+
}
94+
95+
ActionType type = static_cast<ActionType>(task.type);
96+
97+
switch (type)
98+
{
99+
case ActionType::WRITE_ATTRIBUTE: {
100+
ChipLogProgress(NotSpecified, "Writing Attribute: endpointId=%d, clusterId=%04lx, attributeId=%04lx, args.size=%lu",
101+
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
102+
static_cast<unsigned long>(task.args.size()));
103+
delegate->AttributeWriteHandler(task.endpointId, static_cast<chip::AttributeId>(task.actionId), task.args);
104+
}
105+
break;
106+
case ActionType::RUN_COMMAND: {
107+
ChipLogProgress(NotSpecified, "Running Command: endpointId=%d, clusterId=%04lx, commandId=%04lx, args.size=%lu",
108+
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
109+
static_cast<unsigned long>(task.args.size()));
110+
delegate->CommandHandler(task.endpointId, static_cast<chip::CommandId>(task.actionId), task.args);
111+
}
112+
break;
113+
case ActionType::EMIT_EVENT: {
114+
ChipLogProgress(NotSpecified, "Emitting Event: endpointId=%d, clusterId=%04lx, eventIdId=%04lx, args.size=%lu",
115+
task.endpointId, static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
116+
static_cast<unsigned long>(task.args.size()));
117+
delegate->EventHandler(task.endpointId, static_cast<chip::EventId>(task.actionId), task.args);
118+
}
119+
break;
120+
default:
121+
break;
122+
}
123+
124+
if (queue.empty())
125+
{
126+
// Return due to no more actions in queue
127+
return;
128+
}
129+
130+
// Run next action
131+
task = queue.front();
132+
ChipLogProgress(NotSpecified, "StartTimer: endpointId=%d, clusterId=%04lx, eventIdId=%04lx, task.delyMs=%lu", task.endpointId,
133+
static_cast<unsigned long>(task.clusterId), static_cast<unsigned long>(task.actionId),
134+
static_cast<unsigned long>(task.delayMs));
135+
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(task.delayMs), RpcActionsTaskCallback, this);
136+
}
137+
138+
void ChefRpcActionsWorker::RegisterRpcActionsDelegate(ClusterId clusterId, ActionsDelegate * delegate)
139+
{
140+
// Register by cluster
141+
if (nullptr == RpcFindActionsDelegate(clusterId))
142+
{
143+
gActionsDelegateMap[clusterId] = delegate;
144+
return;
145+
}
146+
}
147+
148+
ChefRpcActionsWorker::ChefRpcActionsWorker()
149+
{
150+
chip::rpc::SubscribeActions(ChefRpcActionsCallback);
151+
}
152+
153+
static ChefRpcActionsWorker instance;
154+
155+
ChefRpcActionsWorker & ChefRpcActionsWorker::Instance()
156+
{
157+
return instance;
158+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/clusters/mode-base-server/mode-base-server.h>
22+
#include <app/util/config.h>
23+
#include <cstring>
24+
#include <queue>
25+
#include <utility>
26+
#include <vector>
27+
28+
#include "Rpc.h"
29+
30+
namespace chip {
31+
namespace app {
32+
33+
class ActionsDelegate
34+
{
35+
public:
36+
ActionsDelegate(ClusterId clusterId) : mClusterId(clusterId){};
37+
38+
virtual ~ActionsDelegate() = default;
39+
40+
virtual void AttributeWriteHandler(chip::EndpointId endpointId, chip::AttributeId attributeId, std::vector<uint32_t> args) = 0;
41+
virtual void CommandHandler(chip::EndpointId endpointId, chip::CommandId commandId, std::vector<uint32_t> args) = 0;
42+
virtual void EventHandler(chip::EndpointId endpointId, chip::EventId eventId, std::vector<uint32_t> args) = 0;
43+
44+
protected:
45+
ClusterId mClusterId;
46+
};
47+
48+
struct ActionTask
49+
{
50+
chip::EndpointId endpointId;
51+
chip::ClusterId clusterId;
52+
chip::rpc::ActionType type; // Aligned with Storage buf
53+
uint32_t delayMs;
54+
uint32_t actionId;
55+
std::vector<uint32_t> args;
56+
ActionTask(chip::EndpointId endpoint, chip::ClusterId cluster, chip::rpc::ActionType actionType, uint32_t delay, uint32_t id,
57+
std::vector<uint32_t> arg) :
58+
endpointId(endpoint),
59+
clusterId(cluster), type(actionType), delayMs(delay), actionId(id), args(arg){};
60+
~ActionTask(){};
61+
};
62+
63+
class ChefRpcActionsWorker
64+
{
65+
public:
66+
static ChefRpcActionsWorker & Instance();
67+
68+
ChefRpcActionsWorker();
69+
70+
bool EnqueueAction(ActionTask task);
71+
void ProcessActionQueue();
72+
void RegisterRpcActionsDelegate(ClusterId clusterId, ActionsDelegate * delegate);
73+
74+
private:
75+
std::queue<ActionTask> queue;
76+
};
77+
78+
} // namespace app
79+
} // namespace chip

0 commit comments

Comments
 (0)