From b77cb320405dcb99c30d301a575cb87196dbf91c Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Wed, 27 Oct 2021 00:06:56 -0700 Subject: [PATCH] Revert "[Mbed] Add RPC support for locking and lighting examples (#10960)" This reverts commit 2149dae4c24add7ad40c8ac89cabb8ce990d78be. --- config/mbed/CMakeLists.txt | 77 ++-------- config/mbed/chip-gn/lib/pw_rpc/BUILD.gn | 20 --- examples/common/pigweed/mbed/Rpc.cpp | 138 ------------------ examples/common/pigweed/mbed/Rpc.h | 30 ---- .../common/pigweed/rpc_services/Locking.h | 4 +- examples/lighting-app/mbed/config.in | 3 +- examples/lighting-app/mbed/main/AppTask.cpp | 1 + .../lighting-app/mbed/main/include/AppTask.h | 3 +- examples/lighting-app/mbed/main/main.cpp | 14 -- examples/lock-app/mbed/config.in | 3 +- examples/lock-app/mbed/main/AppTask.cpp | 26 +--- examples/lock-app/mbed/main/include/AppTask.h | 2 - examples/lock-app/mbed/main/main.cpp | 14 -- examples/pigweed-app/mbed/main/main.cpp | 42 +++++- 14 files changed, 59 insertions(+), 318 deletions(-) delete mode 100644 examples/common/pigweed/mbed/Rpc.cpp delete mode 100644 examples/common/pigweed/mbed/Rpc.h diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index b6bf30cfe9453b..671dd67033cd30 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -225,12 +225,8 @@ if (CONFIG_CHIP_PW_RPC) list(APPEND CHIP_LIBRARIES -lPwRpc) if (${APP_TARGET} MATCHES "pigweed-app") set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "y") - elseif (${APP_TARGET} MATCHES "lighting-app") - set(CONFIG_CHIP_PW_RPC_COMMON_PROTO "y") - set(CONFIG_CHIP_PW_RPC_LIGHTING_PROTO "y") - elseif (${APP_TARGET} MATCHES "lock-app") - set(CONFIG_CHIP_PW_RPC_COMMON_PROTO "y") - set(CONFIG_CHIP_PW_RPC_LOCKING_PROTO "y") + else() + set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "n") endif() endif(CONFIG_CHIP_PW_RPC) @@ -275,9 +271,6 @@ chip_gn_arg_bool ("chip_bypass_rendezvous" CONFIG_CHIP_BYPASS_REN chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC) if (CONFIG_CHIP_PW_RPC) chip_gn_arg_bool ("chip_build_pw_rpc_echo_proto" CONFIG_CHIP_PW_RPC_ECHO_PROTO) - chip_gn_arg_bool ("chip_build_pw_rpc_common_proto" CONFIG_CHIP_PW_RPC_COMMON_PROTO) - chip_gn_arg_bool ("chip_build_pw_rpc_lighting_proto" CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) - chip_gn_arg_bool ("chip_build_pw_rpc_locking_proto" CONFIG_CHIP_PW_RPC_LOCKING_PROTO) endif(CONFIG_CHIP_PW_RPC) file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/args.gn CONTENT ${CHIP_GN_ARGS}) @@ -342,10 +335,19 @@ endif() if (CONFIG_CHIP_PW_RPC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" PARENT_SCOPE) list(APPEND CHIP_DEFINES - CHIP_PW_RPC=1 + CONFIG_CHIP_PW_RPC=1 ) endif() +target_include_directories(${APP_TARGET} PRIVATE + ${CHIP_INCLUDES} +) + +target_compile_definitions(${APP_TARGET} PRIVATE + ${CHIP_DEFINES} +) + + if (CONFIG_CHIP_PW_RPC) set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo") @@ -353,7 +355,6 @@ set(PIGWEED_ROOT "${CHIP_ROOT}/third_party/pigweed/repo") target_sources(${APP_TARGET} PRIVATE ${CHIP_ROOT}/examples/common/pigweed/RpcService.cpp ${CHIP_ROOT}/examples/common/pigweed/mbed/PigweedLoggerMutex.cpp - ${CHIP_ROOT}/examples/common/pigweed/mbed/Rpc.cpp ${MBED_COMMON}/util/PigweedLogger.cpp ) @@ -388,64 +389,16 @@ target_include_directories(${APP_TARGET} PRIVATE ${CHIP_ROOT}/third_party/nanopb/repo ${CHIP_ROOT}/examples/common - ${CHIP_ROOT}/examples/common/pigweed - ${CHIP_ROOT}/examples/common/pigweed/mbed + ${CHIP_ROOT}/examples//common/pigweed/mbed ${MBED_COMMON}/pw_sys_io/public - - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/pwpb - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_protobuf/common_protos.proto_library/nanopb ) if (CONFIG_CHIP_PW_RPC_ECHO_PROTO) target_include_directories(${APP_TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb_rpc ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/nanopb - ) - list(APPEND CHIP_DEFINES - CHIP_PW_RPC_ECHO_PROTO=1 + ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/pwpb ) endif(CONFIG_CHIP_PW_RPC_ECHO_PROTO) -if (CONFIG_CHIP_PW_RPC_COMMON_PROTO) - target_include_directories(${APP_TARGET} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/button_service.proto_library/nanopb - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/button_service.proto_library/nanopb_rpc - - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/device_service.proto_library/nanopb - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/device_service.proto_library/nanopb_rpc - ) - list(APPEND CHIP_DEFINES - CHIP_PW_RPC_COMMON_PROTO=1 - ) -endif(CONFIG_CHIP_PW_RPC_COMMON_PROTO) - -if (CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) - target_include_directories(${APP_TARGET} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/lighting_service.proto_library/nanopb - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/lighting_service.proto_library/nanopb_rpc - ) - list(APPEND CHIP_DEFINES - CHIP_PW_RPC_LIGHTING_PROTO=1 - ) -endif(CONFIG_CHIP_PW_RPC_LIGHTING_PROTO) - -if (CONFIG_CHIP_PW_RPC_LOCKING_PROTO) - target_include_directories(${APP_TARGET} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/locking_service.proto_library/nanopb - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/examples/common/pigweed/locking_service.proto_library/nanopb_rpc - ) - list(APPEND CHIP_DEFINES - CHIP_PW_RPC_LOCKING_PROTO=1 - ) -endif(CONFIG_CHIP_PW_RPC_LOCKING_PROTO) - -endif(CONFIG_CHIP_PW_RPC) - - -target_include_directories(${APP_TARGET} PRIVATE - ${CHIP_INCLUDES} -) - -target_compile_definitions(${APP_TARGET} PRIVATE - ${CHIP_DEFINES} -) +endif(CONFIG_CHIP_PW_RPC) \ No newline at end of file diff --git a/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn b/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn index f1a5e071e9c619..062eea969476a7 100644 --- a/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn +++ b/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn @@ -18,9 +18,6 @@ import("$dir_pw_build/target_types.gni") declare_args() { chip_build_pw_rpc_echo_proto = false - chip_build_pw_rpc_common_proto = false - chip_build_pw_rpc_lighting_proto = false - chip_build_pw_rpc_locking_proto = false } static_library("pw_rpc") { @@ -40,23 +37,6 @@ static_library("pw_rpc") { deps += [ "$dir_pw_rpc/nanopb:echo_service" ] } - if (chip_build_pw_rpc_common_proto) { - deps += [ - "${chip_root}/examples/common/pigweed:button_service.nanopb_rpc", - "${chip_root}/examples/common/pigweed:device_service.nanopb_rpc", - ] - } - - if (chip_build_pw_rpc_lighting_proto) { - deps += - [ "${chip_root}/examples/common/pigweed:lighting_service.nanopb_rpc" ] - } - - if (chip_build_pw_rpc_locking_proto) { - deps += - [ "${chip_root}/examples/common/pigweed:locking_service.nanopb_rpc" ] - } - deps += pw_build_LINK_DEPS output_dir = "${root_out_dir}/lib" diff --git a/examples/common/pigweed/mbed/Rpc.cpp b/examples/common/pigweed/mbed/Rpc.cpp deleted file mode 100644 index cd22e6e2182d5a..00000000000000 --- a/examples/common/pigweed/mbed/Rpc.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * - * Copyright (c) 2021 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. - */ - -#include "Rpc.h" -#include "PigweedLogger.h" -#include "PigweedLoggerMutex.h" -#include "pigweed/RpcService.h" - -#include "pw_hdlc/rpc_channel.h" -#include "pw_hdlc/rpc_packets.h" -#include "pw_rpc/server.h" -#include "pw_stream/sys_io_stream.h" -#include "pw_sys_io/sys_io.h" -#include "pw_sys_io_mbed/init.h" - -#include -#include - -#ifdef CHIP_PW_RPC_ECHO_PROTO -#include "pw_rpc/echo_service_nanopb.h" -#endif - -#ifdef CHIP_PW_RPC_COMMON_PROTO -#include "AppTask.h" -#include "rpc_services/Button.h" -#include "rpc_services/Device.h" -#endif - -#ifdef CHIP_PW_RPC_LIGHTING_PROTO -#include "rpc_services/Lighting.h" -#endif - -#ifdef CHIP_PW_RPC_LOCKING_PROTO -#include "rpc_services/Locking.h" -#endif - -using namespace ::chip::DeviceLayer; -using namespace ::rtos; - -namespace chip { -namespace rpc { - -#ifdef CHIP_PW_RPC_COMMON_PROTO -class MbedButton final : public Button -{ -public: - pw::Status Event(ServerContext &, const chip_rpc_ButtonEvent & request, pw_protobuf_Empty & response) - { - GetAppTask().ButtonEventHandler(request.idx, request.pushed); - return pw::OkStatus(); - } -}; -#endif - -namespace { - -#define RPC_THREAD_NAME "RPC" -#define RPC_STACK_SIZE (4 * 1024) - -rtos::Thread rpcThread{ osPriorityNormal, RPC_STACK_SIZE, /* memory provided */ nullptr, RPC_THREAD_NAME }; - -#ifdef CHIP_PW_RPC_ECHO_PROTO -pw::rpc::EchoService echo_service; -#endif - -#ifdef CHIP_PW_RPC_COMMON_PROTO -chip::rpc::MbedButton button_service; -chip::rpc::Device device_service; -#endif - -#ifdef CHIP_PW_RPC_LIGHTING_PROTO -chip::rpc::Lighting lighting_service; -#endif - -#ifdef CHIP_PW_RPC_LOCKING_PROTO -chip::rpc::Locking locking_service; -#endif - -void RegisterServices(pw::rpc::Server & server) -{ -#ifdef CHIP_PW_RPC_ECHO_PROTO - server.RegisterService(echo_service); -#endif - -#ifdef CHIP_PW_RPC_COMMON_PROTO - server.RegisterService(button_service); - server.RegisterService(device_service); -#endif - -#ifdef CHIP_PW_RPC_LIGHTING_PROTO - server.RegisterService(lighting_service); -#endif - -#ifdef CHIP_PW_RPC_LOCKING_PROTO - server.RegisterService(locking_service); -#endif -} - -} // namespace - -void RunRpcService() -{ - Start(RegisterServices, &logger_mutex); -} - -Thread * Init() -{ - pw_sys_io_Init(); - - ChipLogProgress(NotSpecified, "RPC service starting...\r\n"); - - auto error = rpcThread.start(RunRpcService); - if (error != osOK) - { - ChipLogError(NotSpecified, "Run RPC service failed[%d]", error); - return NULL; - } - - return &rpcThread; -} - -} // namespace rpc -} // namespace chip diff --git a/examples/common/pigweed/mbed/Rpc.h b/examples/common/pigweed/mbed/Rpc.h deleted file mode 100644 index 0f30a591decad5..00000000000000 --- a/examples/common/pigweed/mbed/Rpc.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * 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 "rtos/Thread.h" - -namespace chip { -namespace rpc { - -void RunRpcService(); - -rtos::Thread * Init(); - -} // namespace rpc -} // namespace chip diff --git a/examples/common/pigweed/rpc_services/Locking.h b/examples/common/pigweed/rpc_services/Locking.h index 5a2e0d26d628d1..af9d577ca3473a 100644 --- a/examples/common/pigweed/rpc_services/Locking.h +++ b/examples/common/pigweed/rpc_services/Locking.h @@ -34,14 +34,14 @@ class Locking final : public generated::Locking virtual pw::Status Set(ServerContext &, const chip_rpc_LockingState & request, pw_protobuf_Empty & response) { - bool locked = request.locked; + uint8_t locked = request.locked; RETURN_STATUS_IF_NOT_OK(app::Clusters::OnOff::Attributes::OnOff::Set(kEndpoint, locked)); return pw::OkStatus(); } virtual pw::Status Get(ServerContext &, const pw_protobuf_Empty & request, chip_rpc_LockingState & response) { - bool locked; + uint8_t locked; RETURN_STATUS_IF_NOT_OK(app::Clusters::OnOff::Attributes::OnOff::Get(kEndpoint, &locked)); response.locked = locked; return pw::OkStatus(); diff --git a/examples/lighting-app/mbed/config.in b/examples/lighting-app/mbed/config.in index a13a8e62e17b43..2542a38c16f4c3 100644 --- a/examples/lighting-app/mbed/config.in +++ b/examples/lighting-app/mbed/config.in @@ -2,5 +2,4 @@ CONFIG_CHIP_BUILD_TESTS=n CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS=y CONFIG_CHIP_PROJECT_CONFIG=main/include/CHIPProjectConfig.h CONFIG_CHIP_BYPASS_RENDEZVOUS=n -CONFIG_MBED_BSD_SOCKET_TRACE=n -CONFIG_CHIP_PW_RPC=y \ No newline at end of file +CONFIG_MBED_BSD_SOCKET_TRACE=n \ No newline at end of file diff --git a/examples/lighting-app/mbed/main/AppTask.cpp b/examples/lighting-app/mbed/main/AppTask.cpp index 21750f22a1a6e1..b224b7f70ac1c6 100644 --- a/examples/lighting-app/mbed/main/AppTask.cpp +++ b/examples/lighting-app/mbed/main/AppTask.cpp @@ -75,6 +75,7 @@ static bool sHaveBLEConnections = false; static mbed::Timeout sFunctionTimer; +// TODO: change EventQueue default event size static events::EventQueue sAppEventQueue; using namespace ::chip::Credentials; diff --git a/examples/lighting-app/mbed/main/include/AppTask.h b/examples/lighting-app/mbed/main/include/AppTask.h index 06014ff90bf4ab..1ffaf097f40375 100644 --- a/examples/lighting-app/mbed/main/include/AppTask.h +++ b/examples/lighting-app/mbed/main/include/AppTask.h @@ -31,8 +31,6 @@ class AppTask void PostEvent(AppEvent * aEvent); void UpdateClusterState(void); - void ButtonEventHandler(uint32_t id, bool pushed); - private: friend AppTask & GetAppTask(void); @@ -52,6 +50,7 @@ class AppTask void LightingButtonPressEventHandler(void); void FunctionButtonPressEventHandler(void); void FunctionButtonReleaseEventHandler(void); + void ButtonEventHandler(uint32_t id, bool pushed); void SliderEventHandler(int slider_pos); void TimerEventHandler(void); diff --git a/examples/lighting-app/mbed/main/main.cpp b/examples/lighting-app/mbed/main/main.cpp index 4c99ea3c8cde4e..bfe4eb197bdbff 100644 --- a/examples/lighting-app/mbed/main/main.cpp +++ b/examples/lighting-app/mbed/main/main.cpp @@ -23,10 +23,6 @@ #include "capsense.h" #endif -#ifdef CHIP_PW_RPC -#include "Rpc.h" -#endif - #include "mbedtls/platform.h" #include #include @@ -49,16 +45,6 @@ int main() Capsense::getInstance().init(); #endif -#if CHIP_PW_RPC - auto rpcThread = chip::rpc::Init(); - if (rpcThread == NULL) - { - ChipLogError(NotSpecified, "RPC service initialization and run failed"); - ret = EXIT_FAILURE; - goto exit; - } -#endif - ChipLogProgress(NotSpecified, "Mbed lighting-app example application start"); ret = mbedtls_platform_setup(NULL); diff --git a/examples/lock-app/mbed/config.in b/examples/lock-app/mbed/config.in index a13a8e62e17b43..2542a38c16f4c3 100644 --- a/examples/lock-app/mbed/config.in +++ b/examples/lock-app/mbed/config.in @@ -2,5 +2,4 @@ CONFIG_CHIP_BUILD_TESTS=n CONFIG_CHIP_WITH_EXTERNAL_MBEDTLS=y CONFIG_CHIP_PROJECT_CONFIG=main/include/CHIPProjectConfig.h CONFIG_CHIP_BYPASS_RENDEZVOUS=n -CONFIG_MBED_BSD_SOCKET_TRACE=n -CONFIG_CHIP_PW_RPC=y \ No newline at end of file +CONFIG_MBED_BSD_SOCKET_TRACE=n \ No newline at end of file diff --git a/examples/lock-app/mbed/main/AppTask.cpp b/examples/lock-app/mbed/main/AppTask.cpp index 9e3a69d08f4306..d951af30e3521e 100644 --- a/examples/lock-app/mbed/main/AppTask.cpp +++ b/examples/lock-app/mbed/main/AppTask.cpp @@ -78,6 +78,7 @@ static bool sHaveBLEConnections = false; static mbed::Timeout sFunctionTimer; +// TODO: change EventQueue default event size static events::EventQueue sAppEventQueue; using namespace ::chip::Credentials; @@ -257,31 +258,6 @@ void AppTask::FunctionButtonReleaseEventHandler() sAppTask.PostEvent(&button_event); } -void AppTask::ButtonEventHandler(uint32_t id, bool pushed) -{ - if (id > 1) - { - ChipLogError(NotSpecified, "Wrong button ID"); - return; - } - - AppEvent button_event; - button_event.Type = AppEvent::kEventType_Button; - button_event.ButtonEvent.Pin = id == 0 ? LOCK_BUTTON : FUNCTION_BUTTON; - button_event.ButtonEvent.Action = pushed ? BUTTON_PUSH_EVENT : BUTTON_RELEASE_EVENT; - - if (id == 0) - { - button_event.Handler = LockActionEventHandler; - } - else - { - button_event.Handler = FunctionHandler; - } - - sAppTask.PostEvent(&button_event); -} - void AppTask::ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor) { // If the action has been initiated by the lock, update the bolt lock trait diff --git a/examples/lock-app/mbed/main/include/AppTask.h b/examples/lock-app/mbed/main/include/AppTask.h index 355c6e32dc38ab..ad58ece17d1df6 100644 --- a/examples/lock-app/mbed/main/include/AppTask.h +++ b/examples/lock-app/mbed/main/include/AppTask.h @@ -30,8 +30,6 @@ class AppTask void PostEvent(AppEvent * aEvent); void UpdateClusterState(void); - void ButtonEventHandler(uint32_t id, bool pushed); - private: friend AppTask & GetAppTask(void); diff --git a/examples/lock-app/mbed/main/main.cpp b/examples/lock-app/mbed/main/main.cpp index e527adec4cfa45..a429aee1c6f613 100644 --- a/examples/lock-app/mbed/main/main.cpp +++ b/examples/lock-app/mbed/main/main.cpp @@ -23,10 +23,6 @@ #include "capsense.h" #endif -#ifdef CHIP_PW_RPC -#include "Rpc.h" -#endif - #include "mbedtls/platform.h" #include #include @@ -49,16 +45,6 @@ int main() Capsense::getInstance().init(); #endif -#if CHIP_PW_RPC - auto rpcThread = chip::rpc::Init(); - if (rpcThread == NULL) - { - ChipLogError(NotSpecified, "RPC service initialization and run failed"); - ret = EXIT_FAILURE; - goto exit; - } -#endif - ChipLogProgress(NotSpecified, "Mbed lock-app example application start"); ret = mbedtls_platform_setup(NULL); diff --git a/examples/pigweed-app/mbed/main/main.cpp b/examples/pigweed-app/mbed/main/main.cpp index c4a415cd63804f..a29b41a26621a5 100644 --- a/examples/pigweed-app/mbed/main/main.cpp +++ b/examples/pigweed-app/mbed/main/main.cpp @@ -16,17 +16,47 @@ */ #include "LEDWidget.h" -#include "Rpc.h" +#include "PigweedLoggerMutex.h" +#include "pigweed/RpcService.h" + +#include "pw_rpc/echo_service_nanopb.h" +#include "pw_rpc/server.h" +#include "pw_sys_io/sys_io.h" +#include "pw_sys_io_mbed/init.h" #include #include +#include "rtos/Mutex.h" +#include "rtos/Thread.h" + using namespace ::chip::rpc; using namespace ::chip::DeviceLayer; using namespace ::chip::Logging::Platform; static LEDWidget sStatusLED(MBED_CONF_APP_SYSTEM_STATE_LED); +namespace { + +#define RPC_THREAD_NAME "RPC" +#define RPC_STACK_SIZE (4 * 1024) + +rtos::Thread rpcThread{ osPriorityNormal, RPC_STACK_SIZE, /* memory provided */ nullptr, RPC_THREAD_NAME }; + +pw::rpc::EchoService echo_service; + +void RegisterServices(pw::rpc::Server & server) +{ + server.RegisterService(echo_service); +} + +void RunRpcService() +{ + Start(RegisterServices, &logger_mutex); +} + +} // namespace + int main() { int ret = 0; @@ -35,19 +65,21 @@ int main() ChipLogProgress(NotSpecified, "Mbed pigweed-app example application start"); + pw_sys_io_Init(); + sStatusLED.Set(true); - auto rpcThread = chip::rpc::Init(); - if (rpcThread == NULL) + auto error = rpcThread.start(RunRpcService); + if (error != osOK) { - ChipLogError(NotSpecified, "RPC service initialization and run failed"); + ChipLogError(NotSpecified, "Run RPC thread failed [%d]", (int) error); ret = EXIT_FAILURE; goto exit; } ChipLogProgress(NotSpecified, "Mbed pigweed-app example application run"); - rpcThread->join(); + rpcThread.join(); exit: ChipLogProgress(NotSpecified, "Exited with code %d", ret);