-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Adding boolean state sensor control to Chef
- Add new RPCs to set/read BooleanState cluster - Update nRF, ESP32 and Linux chef examples to include - Update some docs that were stale - Allow StatusUtils for RPC to deal with CHIP_ERROR Issue #25225 Fixes #31725
- Loading branch information
1 parent
09324e7
commit 393662c
Showing
11 changed files
with
207 additions
and
5 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
examples/common/pigweed/protos/boolean_state_service.proto
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,37 @@ | ||
syntax = "proto3"; | ||
|
||
import 'pw_protobuf_protos/common.proto'; | ||
|
||
package chip.rpc; | ||
|
||
// This may eventually contain more attributes. | ||
message BooleanStateState { | ||
bool state_value = 1; | ||
} | ||
|
||
message BooleanStateSetRequest { | ||
uint32 endpoint_id = 1; | ||
bool state_value = 2; | ||
} | ||
|
||
message BooleanStateSetResponse { | ||
uint64 event_number = 1; | ||
} | ||
|
||
message BooleanStateGetRequest { | ||
uint32 endpoint_id = 1; | ||
} | ||
|
||
message BooleanStateGetResponse { | ||
BooleanStateState state = 1; | ||
} | ||
|
||
service BooleanState { | ||
// Set will return generated event number (caused by change) if all supported fields are successfully applied, any | ||
// unsupported fields will be ignored. | ||
rpc Set(BooleanStateSetRequest) returns (BooleanStateSetResponse){} | ||
|
||
// Get will populate all of the supported boolean state cluster state fields | ||
// with the current values. | ||
rpc Get(BooleanStateGetRequest) returns (BooleanStateGetResponse){} | ||
} |
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,72 @@ | ||
/* | ||
* | ||
* Copyright (c) 2024 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* 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 "app/util/attribute-storage.h" | ||
#include "boolean_state_service/boolean_state_service.rpc.pb.h" | ||
#include "pigweed/rpc_services/internal/StatusUtils.h" | ||
#include <app-common/zap-generated/attributes/Accessors.h> | ||
#include <app/EventLogging.h> | ||
#include <platform/PlatformManager.h> | ||
|
||
namespace chip { | ||
namespace rpc { | ||
|
||
class BooleanState final : public pw_rpc::nanopb::BooleanState::Service<BooleanState> | ||
{ | ||
public: | ||
virtual ~BooleanState() = default; | ||
|
||
virtual pw::Status Set(const chip_rpc_BooleanStateSetRequest & request, chip_rpc_BooleanStateSetResponse & response) | ||
{ | ||
EndpointId endpointId = request.endpoint_id; | ||
bool newState = request.state_value; | ||
|
||
EventNumber eventNumber; | ||
{ | ||
DeviceLayer::StackLock lock; | ||
|
||
// Update attribute first, then emit StateChange event only on success. | ||
RETURN_STATUS_IF_NOT_OK(app::Clusters::BooleanState::Attributes::StateValue::Set(endpointId, newState)); | ||
|
||
chip::app::Clusters::BooleanState::Events::StateChange::Type event{ newState }; | ||
RETURN_STATUS_IF_NOT_OK(app::LogEvent(event, endpointId, eventNumber)); | ||
} | ||
|
||
response.event_number = static_cast<uint64_t>(eventNumber); | ||
return pw::OkStatus(); | ||
} | ||
|
||
virtual pw::Status Get(const chip_rpc_BooleanStateGetRequest & request, chip_rpc_BooleanStateGetResponse & response) | ||
{ | ||
EndpointId endpointId = request.endpoint_id; | ||
bool state_value = false; | ||
|
||
{ | ||
DeviceLayer::StackLock lock; | ||
RETURN_STATUS_IF_NOT_OK(app::Clusters::BooleanState::Attributes::StateValue::Get(endpointId, &state_value)); | ||
} | ||
|
||
response.state.state_value = state_value; | ||
return pw::OkStatus(); | ||
} | ||
}; | ||
|
||
} // namespace rpc | ||
} // namespace chip |
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