3 * Copyright (c) 2020 Project CHIP Authors
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include "PigweedLogger.h"
22 #include "PigweedLoggerMutex.h"
23 #include "pigweed/RpcService.h"
25 #include "main/pigweed_lighting.rpc.pb.h"
26 #include "pw_hdlc/rpc_channel.h"
27 #include "pw_hdlc/rpc_packets.h"
28 #include "pw_rpc/server.h"
29 #include "pw_stream/sys_io_stream.h"
30 #include "pw_sys_io/sys_io.h"
31 #include "pw_sys_io_nrfconnect/init.h"
35 #include <logging/log.h>
37 LOG_MODULE_DECLARE(app);
42 class LightingService final : public generated::LightingService<LightingService>
45 pw::Status ButtonEvent(ServerContext & ctx, const chip_rpc_Button & request, chip_rpc_Empty & response)
47 GetAppTask().ButtonEventHandler(request.action << request.idx /* button_state */, 1 << request.idx /* has_changed */);
48 return pw::OkStatus();
56 constexpr size_t kRpcTaskSize = 4096;
57 constexpr int kRpcPriority = 5;
59 K_THREAD_STACK_DEFINE(rpc_stack_area, kRpcTaskSize);
60 struct k_thread rpc_thread_data;
62 chip::rpc::LightingService lighting_service;
64 void RegisterServices(pw::rpc::Server & server)
66 server.RegisterService(lighting_service);
74 k_tid_t tid = k_thread_create(&rpc_thread_data, rpc_stack_area, K_THREAD_STACK_SIZEOF(rpc_stack_area), RunRpcService, NULL,
75 NULL, NULL, kRpcPriority, 0, K_NO_WAIT);
79 void RunRpcService(void *, void *, void *)
81 Start(RegisterServices, &logger_mutex);