Skip to content

Commit 5cc6ef7

Browse files
Bridge-app: Add actions delegate in the Bridge app
1 parent ee95bd2 commit 5cc6ef7

File tree

9 files changed

+274
-81
lines changed

9 files changed

+274
-81
lines changed

examples/bridge-app/asr/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ asr_executable("bridge_app") {
7272
output_name = "chip-asr-bridge-example.out"
7373

7474
sources = [
75+
"${chip_root}/examples/bridge-app/bridge-common/src/bridged-actions-stub.cpp",
7576
"${examples_plat_dir}/CHIPDeviceManager.cpp",
7677
"${examples_plat_dir}/init_Matter.cpp",
7778
"${examples_plat_dir}/init_asrPlatform.cpp",
@@ -104,6 +105,7 @@ asr_executable("bridge_app") {
104105
"${examples_plat_dir}",
105106
"${asr_project_dir}/include",
106107
"${chip_root}/src/lib",
108+
"${chip_root}/examples/bridge-app/bridge-common/include",
107109
]
108110

109111
defines = [ "ASR_NETWORK_LAYER_BLE=${chip_config_network_layer_ble}" ]

examples/bridge-app/asr/src/AppTask.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <app/util/attribute-storage.h>
2828
#include <app/util/endpoint-config-api.h>
2929
#include <assert.h>
30+
#include <bridged-actions-stub.h>
3031
#include <platform/ASR/NetworkCommissioningDriver.h>
3132
#include <platform/CHIPDeviceLayer.h>
3233
#include <setup_payload/OnboardingCodesUtil.h>
@@ -52,6 +53,9 @@ constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE;
5253
app::Clusters::NetworkCommissioning::Instance
5354
sWiFiNetworkCommissioningInstance(kNetworkCommissioningEndpointMain /* Endpoint Id */,
5455
&(NetworkCommissioning::ASRWiFiDriver::GetInstance()));
56+
57+
std::unique_ptr<app::Clusters::Actions::ActionsDelegateImpl> sActionsDelegateImpl;
58+
std::unique_ptr<app::Clusters::Actions::ActionsServer> sActionsServer;
5559
} // namespace
5660

5761
void NetWorkCommissioningInstInit()
@@ -62,6 +66,20 @@ void NetWorkCommissioningInstInit()
6266
emberAfEndpointEnableDisable(kNetworkCommissioningEndpointSecondary, false);
6367
}
6468

69+
void emberAfActionsClusterInitCallback(EndpointId endpoint)
70+
{
71+
VerifyOrReturn(endpoint == 1,
72+
ChipLogError(Zcl, "Actions cluster delegate is not implemented for endpoint with id %d.", endpoint));
73+
VerifyOrReturn(emberAfContainsServer(endpoint, app::Clusters::Actions::Id) == true,
74+
ChipLogError(Zcl, "Endpoint %d does not support Actions cluster.", endpoint));
75+
VerifyOrReturn(!sActionsDelegateImpl && !sActionsServer);
76+
77+
sActionsDelegateImpl = std::make_unique<app::Clusters::Actions::ActionsDelegateImpl>();
78+
sActionsServer = std::make_unique<app::Clusters::Actions::ActionsServer>(endpoint, *sActionsDelegateImpl.get());
79+
80+
sActionsServer->Init();
81+
}
82+
6583
static DeviceCallbacks EchoCallbacks;
6684

6785
CHIP_ERROR AppTask::StartAppTask()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
#pragma once
18+
#include <app-common/zap-generated/cluster-objects.h>
19+
#include <app-common/zap-generated/ids/Attributes.h>
20+
#include <app-common/zap-generated/ids/Clusters.h>
21+
#include <app/AttributeAccessInterface.h>
22+
#include <app/AttributeAccessInterfaceRegistry.h>
23+
#include <app/clusters/actions-server/actions-server.h>
24+
#include <app/util/attribute-storage.h>
25+
#include <lib/support/CodeUtils.h>
26+
#include <lib/support/logging/CHIPLogging.h>
27+
#include <vector>
28+
29+
namespace chip {
30+
namespace app {
31+
namespace Clusters {
32+
namespace Actions {
33+
class ActionsDelegateImpl : public Delegate
34+
{
35+
private:
36+
std::vector<ActionStructStorage> kActionList = {
37+
ActionStructStorage(0, CharSpan::fromCharString("TurnOnLight"), ActionTypeEnum::kScene, 0, 0, ActionStateEnum::kInactive),
38+
ActionStructStorage(1, CharSpan::fromCharString("TurnOffLight"), ActionTypeEnum::kScene, 1, 0, ActionStateEnum::kInactive),
39+
ActionStructStorage(2, CharSpan::fromCharString("ToggleLight"), ActionTypeEnum::kScene, 2, 0, ActionStateEnum::kInactive)
40+
};
41+
42+
std::vector<EndpointId> firstEpList = { 0 };
43+
std::vector<EndpointId> secondEpList = { 0, 1 };
44+
std::vector<EndpointId> thirdEpList = { 1, 2, 3 };
45+
46+
std::vector<EndpointListStorage> kEndpointList = {
47+
EndpointListStorage(0, CharSpan::fromCharString("On"), EndpointListTypeEnum::kOther,
48+
DataModel::List<const EndpointId>(firstEpList.data(), firstEpList.size())),
49+
EndpointListStorage(1, CharSpan::fromCharString("Off"), EndpointListTypeEnum::kOther,
50+
DataModel::List<const EndpointId>(secondEpList.data(), secondEpList.size())),
51+
EndpointListStorage(2, CharSpan::fromCharString("Toggle"), EndpointListTypeEnum::kOther,
52+
DataModel::List<const EndpointId>(thirdEpList.data(), thirdEpList.size()))
53+
};
54+
55+
CHIP_ERROR ReadActionAtIndex(uint16_t index, ActionStructStorage & action) override;
56+
CHIP_ERROR ReadEndpointListAtIndex(uint16_t index, EndpointListStorage & epList) override;
57+
bool HaveActionWithId(uint16_t actionId, uint16_t & actionIndex) override;
58+
59+
Protocols::InteractionModel::Status HandleInstantAction(uint16_t actionId, Optional<uint32_t> invokeId) override;
60+
Protocols::InteractionModel::Status HandleInstantActionWithTransition(uint16_t actionId, uint16_t transitionTime,
61+
Optional<uint32_t> invokeId) override;
62+
Protocols::InteractionModel::Status HandleStartAction(uint16_t actionId, Optional<uint32_t> invokeId) override;
63+
Protocols::InteractionModel::Status HandleStartActionWithDuration(uint16_t actionId, uint32_t duration,
64+
Optional<uint32_t> invokeId) override;
65+
Protocols::InteractionModel::Status HandleStopAction(uint16_t actionId, Optional<uint32_t> invokeId) override;
66+
Protocols::InteractionModel::Status HandlePauseAction(uint16_t actionId, Optional<uint32_t> invokeId) override;
67+
Protocols::InteractionModel::Status HandlePauseActionWithDuration(uint16_t actionId, uint32_t duration,
68+
Optional<uint32_t> invokeId) override;
69+
Protocols::InteractionModel::Status HandleResumeAction(uint16_t actionId, Optional<uint32_t> invokeId) override;
70+
Protocols::InteractionModel::Status HandleEnableAction(uint16_t actionId, Optional<uint32_t> invokeId) override;
71+
Protocols::InteractionModel::Status HandleEnableActionWithDuration(uint16_t actionId, uint32_t duration,
72+
Optional<uint32_t> invokeId) override;
73+
Protocols::InteractionModel::Status HandleDisableAction(uint16_t actionId, Optional<uint32_t> invokeId) override;
74+
Protocols::InteractionModel::Status HandleDisableActionWithDuration(uint16_t actionId, uint32_t duration,
75+
Optional<uint32_t> invokeId) override;
76+
};
77+
} // namespace Actions
78+
} // namespace Clusters
79+
} // namespace app
80+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
#include <bridged-actions-stub.h>
19+
20+
using namespace chip;
21+
using namespace chip::app;
22+
using namespace chip::app::Clusters;
23+
using namespace chip::app::Clusters::Actions;
24+
using namespace chip::app::Clusters::Actions::Attributes;
25+
using namespace chip::Protocols::InteractionModel;
26+
27+
CHIP_ERROR ActionsDelegateImpl::ReadActionAtIndex(uint16_t index, ActionStructStorage & action)
28+
{
29+
if (index >= kActionList.size())
30+
{
31+
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
32+
}
33+
action = kActionList[index];
34+
return CHIP_NO_ERROR;
35+
}
36+
37+
CHIP_ERROR ActionsDelegateImpl::ReadEndpointListAtIndex(uint16_t index, EndpointListStorage & epList)
38+
{
39+
if (index >= kEndpointList.size())
40+
{
41+
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
42+
}
43+
epList = kEndpointList[index];
44+
return CHIP_NO_ERROR;
45+
}
46+
47+
bool ActionsDelegateImpl::HaveActionWithId(uint16_t actionId, uint16_t & actionIndex)
48+
{
49+
for (size_t i = 0; i < kEndpointList.size(); i++)
50+
{
51+
if (kActionList[i].actionID == actionId)
52+
{
53+
actionIndex = (uint16_t) i;
54+
return true;
55+
}
56+
}
57+
return false;
58+
}
59+
60+
Status ActionsDelegateImpl::HandleInstantAction(uint16_t actionId, Optional<uint32_t> invokeId)
61+
{
62+
// Not implemented
63+
return Status::NotFound;
64+
}
65+
66+
Status ActionsDelegateImpl::HandleInstantActionWithTransition(uint16_t actionId, uint16_t transitionTime,
67+
Optional<uint32_t> invokeId)
68+
{
69+
// Not implemented
70+
return Status::NotFound;
71+
}
72+
73+
Status ActionsDelegateImpl::HandleStartAction(uint16_t actionId, Optional<uint32_t> invokeId)
74+
{
75+
// Not implemented
76+
return Status::NotFound;
77+
}
78+
79+
Status ActionsDelegateImpl::HandleStartActionWithDuration(uint16_t actionId, uint32_t duration, Optional<uint32_t> invokeId)
80+
{
81+
// Not implemented
82+
return Status::NotFound;
83+
}
84+
85+
Status ActionsDelegateImpl::HandleStopAction(uint16_t actionId, Optional<uint32_t> invokeId)
86+
{
87+
// Not implemented
88+
return Status::NotFound;
89+
}
90+
91+
Status ActionsDelegateImpl::HandlePauseAction(uint16_t actionId, Optional<uint32_t> invokeId)
92+
{
93+
// Not implemented
94+
return Status::NotFound;
95+
}
96+
97+
Status ActionsDelegateImpl::HandlePauseActionWithDuration(uint16_t actionId, uint32_t duration, Optional<uint32_t> invokeId)
98+
{
99+
// Not implemented
100+
return Status::NotFound;
101+
}
102+
103+
Status ActionsDelegateImpl::HandleResumeAction(uint16_t actionId, Optional<uint32_t> invokeId)
104+
{
105+
// Not implemented
106+
return Status::NotFound;
107+
}
108+
109+
Status ActionsDelegateImpl::HandleEnableAction(uint16_t actionId, Optional<uint32_t> invokeId)
110+
{
111+
// Not implemented
112+
return Status::NotFound;
113+
}
114+
115+
Status ActionsDelegateImpl::HandleEnableActionWithDuration(uint16_t actionId, uint32_t duration, Optional<uint32_t> invokeId)
116+
{
117+
// Not implemented
118+
return Status::NotFound;
119+
}
120+
121+
Status ActionsDelegateImpl::HandleDisableAction(uint16_t actionId, Optional<uint32_t> invokeId)
122+
{
123+
// Not implemented
124+
return Status::NotFound;
125+
}
126+
127+
Status ActionsDelegateImpl::HandleDisableActionWithDuration(uint16_t actionId, uint32_t duration, Optional<uint32_t> invokeId)
128+
{
129+
// Not implemented
130+
return Status::NotFound;
131+
}

examples/bridge-app/esp32/main/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ get_filename_component(APP_COMMON_GEN_DIR ${CHIP_ROOT}/zzz_generated/app-common/
2020
idf_component_register(PRIV_INCLUDE_DIRS
2121
"${CMAKE_CURRENT_LIST_DIR}/include"
2222
"${CHIP_ROOT}/examples/providers"
23+
"${CHIP_ROOT}/examples/bridge-app/bridge-common/include"
2324
SRC_DIRS
2425
"${CMAKE_CURRENT_LIST_DIR}"
2526
"${APP_COMMON_GEN_DIR}/attributes"
2627
"${APP_COMMON_GEN_DIR}"
2728
"${CHIP_ROOT}/examples/platform/esp32/common"
28-
"${CHIP_ROOT}/examples/providers")
29+
"${CHIP_ROOT}/examples/providers"
30+
"${CHIP_ROOT}/examples/bridge-app/bridge-common/src")
2931

3032
include(${CHIP_ROOT}/src/app/chip_data_model.cmake)
3133
chip_configure_data_model(${COMPONENT_LIB}

examples/bridge-app/esp32/main/DeviceCallbacks.cpp

-78
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include <app-common/zap-generated/cluster-objects.h>
20-
#include <app-common/zap-generated/ids/Attributes.h>
21-
#include <app-common/zap-generated/ids/Clusters.h>
22-
#include <app/AttributeAccessInterface.h>
23-
#include <app/AttributeAccessInterfaceRegistry.h>
24-
#include <app/util/attribute-storage.h>
2519
#include <lib/support/CodeUtils.h>
2620
#include <lib/support/logging/CHIPLogging.h>
2721

@@ -43,75 +37,3 @@ void AppDeviceCallbacks::PostAttributeChangeCallback(EndpointId endpointId, Clus
4337
clusterId, endpointId, attributeId);
4438
ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
4539
}
46-
47-
namespace {
48-
49-
class ActionsAttrAccess : public AttributeAccessInterface
50-
{
51-
public:
52-
// Register for the Actions cluster on all endpoints.
53-
ActionsAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), Actions::Id) {}
54-
55-
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
56-
57-
private:
58-
static constexpr uint16_t ClusterRevision = 1;
59-
60-
CHIP_ERROR ReadActionListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder);
61-
CHIP_ERROR ReadEndpointListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder);
62-
CHIP_ERROR ReadSetupUrlAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder);
63-
CHIP_ERROR ReadClusterRevision(EndpointId endpoint, AttributeValueEncoder & aEncoder);
64-
};
65-
66-
constexpr uint16_t ActionsAttrAccess::ClusterRevision;
67-
68-
CHIP_ERROR ActionsAttrAccess::ReadActionListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
69-
{
70-
// Just return an empty list
71-
return aEncoder.EncodeEmptyList();
72-
}
73-
74-
CHIP_ERROR ActionsAttrAccess::ReadEndpointListAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
75-
{
76-
// Just return an empty list
77-
return aEncoder.EncodeEmptyList();
78-
}
79-
80-
CHIP_ERROR ActionsAttrAccess::ReadSetupUrlAttribute(EndpointId endpoint, AttributeValueEncoder & aEncoder)
81-
{
82-
static const char SetupUrl[] = "https://example.com";
83-
return aEncoder.Encode(chip::CharSpan::fromCharString(SetupUrl));
84-
}
85-
86-
CHIP_ERROR ActionsAttrAccess::ReadClusterRevision(EndpointId endpoint, AttributeValueEncoder & aEncoder)
87-
{
88-
return aEncoder.Encode(ClusterRevision);
89-
}
90-
91-
ActionsAttrAccess gAttrAccess;
92-
93-
CHIP_ERROR ActionsAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
94-
{
95-
VerifyOrDie(aPath.mClusterId == Actions::Id);
96-
97-
switch (aPath.mAttributeId)
98-
{
99-
case ActionList::Id:
100-
return ReadActionListAttribute(aPath.mEndpointId, aEncoder);
101-
case EndpointLists::Id:
102-
return ReadEndpointListAttribute(aPath.mEndpointId, aEncoder);
103-
case SetupURL::Id:
104-
return ReadSetupUrlAttribute(aPath.mEndpointId, aEncoder);
105-
case ClusterRevision::Id:
106-
return ReadClusterRevision(aPath.mEndpointId, aEncoder);
107-
default:
108-
break;
109-
}
110-
return CHIP_NO_ERROR;
111-
}
112-
} // anonymous namespace
113-
114-
void MatterActionsPluginServerInitCallback(void)
115-
{
116-
AttributeAccessInterfaceRegistry::Instance().Register(&gAttrAccess);
117-
}

0 commit comments

Comments
 (0)