-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[app] add binding cluster support #12981
Merged
+671
−45
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2e4ced3
[app] add binding cluster support
gjc13 596c3bd
fix review comments & add docs
gjc13 811f8c9
decouple client from server attributes
gjc13 04396c2
Use interaction engine to send On/Off commands
gjc13 b2b5427
add group to the callback signature
gjc13 fae9f45
fix review comments
gjc13 3c7fd9d
add docs for binding callback arguments
gjc13 eb6607a
fix unbind
gjc13 3a752b8
modify callback signature
gjc13 9ad1478
make BindingManager instance optional
gjc13 88864ff
Modify struct layout to save RAM
gjc13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
examples/all-clusters-app/all-clusters-common/include/binding-handler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "lib/core/CHIPError.h" | ||
|
||
CHIP_ERROR InitBindingHandlers(); |
112 changes: 112 additions & 0 deletions
112
examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* | ||
* Copyright (c) 2021 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "binding-handler.h" | ||
|
||
#include "app-common/zap-generated/ids/Clusters.h" | ||
#include "app-common/zap-generated/ids/Commands.h" | ||
#include "app/CommandSender.h" | ||
#include "app/clusters/bindings/BindingManager.h" | ||
#include "app/server/Server.h" | ||
#include "controller/InvokeInteraction.h" | ||
#include "lib/core/CHIPError.h" | ||
|
||
#if defined(ENABLE_CHIP_SHELL) | ||
#include "lib/shell/Engine.h" | ||
|
||
using chip::Shell::Engine; | ||
using chip::Shell::shell_command_t; | ||
using chip::Shell::streamer_get; | ||
using chip::Shell::streamer_printf; | ||
#endif // defined(ENABLE_CHIP_SHELL) | ||
|
||
static bool sSwitchOnOffState = false; | ||
#if defined(ENABLE_CHIP_SHELL) | ||
static void ToggleSwitchOnOff(bool newState) | ||
{ | ||
sSwitchOnOffState = newState; | ||
chip::BindingManager::GetInstance().NotifyBoundClusterChanged(1, chip::app::Clusters::OnOff::Id, nullptr); | ||
} | ||
|
||
static CHIP_ERROR SwitchCommandHandler(int argc, char ** argv) | ||
{ | ||
if (argc == 1 && strcmp(argv[0], "on") == 0) | ||
{ | ||
ToggleSwitchOnOff(true); | ||
return CHIP_NO_ERROR; | ||
} | ||
if (argc == 1 && strcmp(argv[0], "off") == 0) | ||
{ | ||
ToggleSwitchOnOff(false); | ||
return CHIP_NO_ERROR; | ||
} | ||
streamer_printf(streamer_get(), "Usage: switch [on|off]"); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
static void RegisterSwitchCommands() | ||
{ | ||
static const shell_command_t sSwitchCommand = { SwitchCommandHandler, "switch", "Switch commands. Usage: switch [on|off]" }; | ||
Engine::Root().RegisterCommands(&sSwitchCommand, 1); | ||
return; | ||
} | ||
#endif // defined(ENABLE_CHIP_SHELL) | ||
|
||
static void BoundDeviceChangedHandler(const EmberBindingTableEntry * binding, chip::DeviceProxy * peer_device, void * context) | ||
{ | ||
using namespace chip; | ||
using namespace chip::app; | ||
|
||
if (binding->type == EMBER_MULTICAST_BINDING) | ||
{ | ||
ChipLogError(NotSpecified, "Group binding is not supported now"); | ||
return; | ||
} | ||
|
||
if (binding->type == EMBER_UNICAST_BINDING && binding->local == 1 && binding->clusterId == Clusters::OnOff::Id) | ||
{ | ||
auto onSuccess = [](const ConcreteCommandPath & commandPath, const StatusIB & status, const auto & dataResponse) { | ||
ChipLogProgress(NotSpecified, "OnOff command succeeds"); | ||
}; | ||
auto onFailure = [](const StatusIB & status, CHIP_ERROR error) { | ||
ChipLogError(NotSpecified, "OnOff command failed: %" CHIP_ERROR_FORMAT, error.Format()); | ||
}; | ||
|
||
if (sSwitchOnOffState) | ||
{ | ||
Clusters::OnOff::Commands::On::Type onCommand; | ||
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), | ||
binding->remote, onCommand, onSuccess, onFailure); | ||
} | ||
else | ||
{ | ||
Clusters::OnOff::Commands::Off::Type offCommand; | ||
Controller::InvokeCommandRequest(peer_device->GetExchangeManager(), peer_device->GetSecureSession().Value(), | ||
binding->remote, offCommand, onSuccess, onFailure); | ||
} | ||
} | ||
} | ||
|
||
CHIP_ERROR InitBindingHandlers() | ||
{ | ||
chip::BindingManager::GetInstance().SetAppServer(&chip::Server::GetInstance()); | ||
chip::BindingManager::GetInstance().RegisterBoundDeviceChangedHandler(BoundDeviceChangedHandler); | ||
#if defined(ENABLE_CHIP_SHELL) | ||
RegisterSwitchCommands(); | ||
#endif | ||
return CHIP_NO_ERROR; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the switch is toggled quickly 'N' times in succession, and before
BoundDeviceChangedHandler
can be called? Does it result in N calls being made toBoundDeviceChangedHandler
from the Binding manager?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need to connect to the unicast binding first, we'll check for duplication when pushing to the pending nofication queue. Only one call will be made under such circumstance.
If the binding is ready, we'll directly call the handler. It will be up to the application to do anti-jittering.