Skip to content

Commit

Permalink
Support write events as string through RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinpan1 committed Apr 15, 2024
1 parent 3252a78 commit 8480b14
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/common/pigweed/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pw_proto_library("button_service") {

pw_proto_library("event_service") {
sources = [ "protos/event_service.proto" ]
inputs = [ "protos/event_service.options" ]
deps = [ "$dir_pw_protobuf:common_protos" ]
strip_prefix = "protos"
prefix = "event_service"
Expand Down
1 change: 1 addition & 0 deletions examples/common/pigweed/protos/event_service.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chip.rpc.EventSetRequest.event_payload max_size:2048 // max event size
7 changes: 3 additions & 4 deletions examples/common/pigweed/protos/event_service.proto
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
syntax = "proto3";

import 'pw_protobuf_protos/common.proto';

package chip.rpc;

import 'pw_protobuf_protos/common.proto';

message EventSetRequest {
uint32 endpoint_id = 1;
uint32 cluster_id = 2;
uint32 event_id = 3;
std::string event_payload = 4;
string event_payload = 3; //
}

message EventSetResponse {
Expand Down
11 changes: 5 additions & 6 deletions examples/common/pigweed/rpc_services/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ namespace rpc {
class Event final : public pw_rpc::nanopb::Event::Service<Event>
{
public:
virtual ~Event() = default;

virtual pw::Status Set(const chip_rpc_EventSetRequest & request, chip_rpc_EventSetResponse & response)
::pw::Status Set( const ::chip_rpc_EventSetRequest& request, ::chip_rpc_EventSetResponse& response)
{
EndpointId endpointId = request.endpoint_id;
uint8_t newPosition = 1 ; // to be parsed from request.event_payload

printf("\033[41m %s, %d, request.event_playload=%s \033[0m \n", __func__, __LINE__, request.event_payload);
EventNumber eventNumber;
{
DeviceLayer::StackLock lock;
Expand All @@ -53,18 +52,18 @@ class Event final : public pw_rpc::nanopb::Event::Service<Event>
return pw::OkStatus();
}

virtual pw::Status Get(const chip_rpc_EventGetRequest & request, chip_rpc_EventGetResponse & response)
::pw::Status Get( const ::chip_rpc_EventGetRequest& request, ::chip_rpc_EventGetResponse& response)
{
EndpointId endpointId = request.endpoint_id;
uint32 event_id = 1; // TBD
// uint32_t event_id = 1; // TBD

{
DeviceLayer::StackLock lock;
// TBD: Get latest event number
// RETURN_STATUS_IF_NOT_OK(app::Clusters::Switch::Attributes::StateValue::Get(endpointId, &state_value));
}

response.state.event_id = event_id;
response.event_id = endpointId;
return pw::OkStatus();
}
};
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/linux/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Device device_service;
#endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE

#if defined(PW_RPC_EVENT_SERVICE) && PW_RPC_EVENT_SERVICE
BooleanState event_service;
Event event_service;
#endif // defined(PW_RPC_EVENT_SERVICE) && PW_RPC_EVENT_SERVICE

#if defined(PW_RPC_LIGHTING_SERVICE) && PW_RPC_LIGHTING_SERVICE
Expand Down

0 comments on commit 8480b14

Please sign in to comment.