From 317440962ce581a0dde38ee8db769af28d9b6d3b Mon Sep 17 00:00:00 2001 From: Artur Tynecki <77382963+ATmobica@users.noreply.github.com> Date: Wed, 27 Oct 2021 20:38:24 +0200 Subject: [PATCH] [Mbed] Add RPC support for locking and lighting examples (#11039) * Add CONFIG_CHIP_PW_RPC flag to lock and lighting apps * Add more RPC services to Mbed build Create common RPC service run function Add RPC support for lock and lighting apps Add button event handler to lock app task * Fix Locking RPC service - changed locked variable type to boolen * Add AppTask reference in Rpc.cpp Changes restyle * Fix AppTask.h include * Remove CHIPDeviceLayer include from RPC.cpp file * Increase Mbed lock-app and lighting-app build timeout in CI --- .github/workflows/examples-mbed.yaml | 4 +- config/mbed/CMakeLists.txt | 77 ++++++++-- config/mbed/chip-gn/lib/pw_rpc/BUILD.gn | 20 +++ examples/common/pigweed/mbed/Rpc.cpp | 137 ++++++++++++++++++ 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 +----- 15 files changed, 319 insertions(+), 61 deletions(-) create mode 100644 examples/common/pigweed/mbed/Rpc.cpp create mode 100644 examples/common/pigweed/mbed/Rpc.h diff --git a/.github/workflows/examples-mbed.yaml b/.github/workflows/examples-mbed.yaml index 247cd80f090548..6719d9797f0b9f 100644 --- a/.github/workflows/examples-mbed.yaml +++ b/.github/workflows/examples-mbed.yaml @@ -64,7 +64,7 @@ jobs: .environment/pigweed-venv/*.log - name: Build lock-app example - timeout-minutes: 10 + timeout-minutes: 12 run: | scripts/examples/mbed_example.sh -a=lock-app -b=$APP_TARGET -p=$APP_PROFILE .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ @@ -73,7 +73,7 @@ jobs: /tmp/bloat_reports/ - name: Build lighting-app example - timeout-minutes: 10 + timeout-minutes: 12 run: | scripts/examples/mbed_example.sh -a=lighting-app -b=$APP_TARGET -p=$APP_PROFILE .environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \ diff --git a/config/mbed/CMakeLists.txt b/config/mbed/CMakeLists.txt index 671dd67033cd30..b6bf30cfe9453b 100644 --- a/config/mbed/CMakeLists.txt +++ b/config/mbed/CMakeLists.txt @@ -225,8 +225,12 @@ if (CONFIG_CHIP_PW_RPC) list(APPEND CHIP_LIBRARIES -lPwRpc) if (${APP_TARGET} MATCHES "pigweed-app") set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "y") - else() - set(CONFIG_CHIP_PW_RPC_ECHO_PROTO "n") + 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") endif() endif(CONFIG_CHIP_PW_RPC) @@ -271,6 +275,9 @@ 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}) @@ -335,19 +342,10 @@ endif() if (CONFIG_CHIP_PW_RPC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17" PARENT_SCOPE) list(APPEND CHIP_DEFINES - CONFIG_CHIP_PW_RPC=1 + 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") @@ -355,6 +353,7 @@ 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 ) @@ -389,16 +388,64 @@ target_include_directories(${APP_TARGET} PRIVATE ${CHIP_ROOT}/third_party/nanopb/repo ${CHIP_ROOT}/examples/common - ${CHIP_ROOT}/examples//common/pigweed/mbed + ${CHIP_ROOT}/examples/common/pigweed + ${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 - ${CMAKE_CURRENT_BINARY_DIR}/protocol_buffer/gen/third_party/connectedhomeip/third_party/pigweed/repo/pw_rpc/protos.proto_library/pwpb + ) + list(APPEND CHIP_DEFINES + CHIP_PW_RPC_ECHO_PROTO=1 ) endif(CONFIG_CHIP_PW_RPC_ECHO_PROTO) -endif(CONFIG_CHIP_PW_RPC) \ No newline at end of file +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} +) diff --git a/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn b/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn index 062eea969476a7..f1a5e071e9c619 100644 --- a/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn +++ b/config/mbed/chip-gn/lib/pw_rpc/BUILD.gn @@ -18,6 +18,9 @@ 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") { @@ -37,6 +40,23 @@ 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 new file mode 100644 index 00000000000000..4f9ccde46beecc --- /dev/null +++ b/examples/common/pigweed/mbed/Rpc.cpp @@ -0,0 +1,137 @@ +/* + * + * 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 + +#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 new file mode 100644 index 00000000000000..0f30a591decad5 --- /dev/null +++ b/examples/common/pigweed/mbed/Rpc.h @@ -0,0 +1,30 @@ +/* + * + * 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 af9d577ca3473a..5a2e0d26d628d1 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) { - uint8_t locked = request.locked; + bool 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) { - uint8_t locked; + bool 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 2542a38c16f4c3..a13a8e62e17b43 100644 --- a/examples/lighting-app/mbed/config.in +++ b/examples/lighting-app/mbed/config.in @@ -2,4 +2,5 @@ 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 \ No newline at end of file +CONFIG_MBED_BSD_SOCKET_TRACE=n +CONFIG_CHIP_PW_RPC=y \ 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 b224b7f70ac1c6..21750f22a1a6e1 100644 --- a/examples/lighting-app/mbed/main/AppTask.cpp +++ b/examples/lighting-app/mbed/main/AppTask.cpp @@ -75,7 +75,6 @@ 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 1ffaf097f40375..06014ff90bf4ab 100644 --- a/examples/lighting-app/mbed/main/include/AppTask.h +++ b/examples/lighting-app/mbed/main/include/AppTask.h @@ -31,6 +31,8 @@ class AppTask void PostEvent(AppEvent * aEvent); void UpdateClusterState(void); + void ButtonEventHandler(uint32_t id, bool pushed); + private: friend AppTask & GetAppTask(void); @@ -50,7 +52,6 @@ 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 bfe4eb197bdbff..4c99ea3c8cde4e 100644 --- a/examples/lighting-app/mbed/main/main.cpp +++ b/examples/lighting-app/mbed/main/main.cpp @@ -23,6 +23,10 @@ #include "capsense.h" #endif +#ifdef CHIP_PW_RPC +#include "Rpc.h" +#endif + #include "mbedtls/platform.h" #include #include @@ -45,6 +49,16 @@ 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 2542a38c16f4c3..a13a8e62e17b43 100644 --- a/examples/lock-app/mbed/config.in +++ b/examples/lock-app/mbed/config.in @@ -2,4 +2,5 @@ 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 \ No newline at end of file +CONFIG_MBED_BSD_SOCKET_TRACE=n +CONFIG_CHIP_PW_RPC=y \ 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 d951af30e3521e..9e3a69d08f4306 100644 --- a/examples/lock-app/mbed/main/AppTask.cpp +++ b/examples/lock-app/mbed/main/AppTask.cpp @@ -78,7 +78,6 @@ static bool sHaveBLEConnections = false; static mbed::Timeout sFunctionTimer; -// TODO: change EventQueue default event size static events::EventQueue sAppEventQueue; using namespace ::chip::Credentials; @@ -258,6 +257,31 @@ 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 ad58ece17d1df6..355c6e32dc38ab 100644 --- a/examples/lock-app/mbed/main/include/AppTask.h +++ b/examples/lock-app/mbed/main/include/AppTask.h @@ -30,6 +30,8 @@ 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 a429aee1c6f613..e527adec4cfa45 100644 --- a/examples/lock-app/mbed/main/main.cpp +++ b/examples/lock-app/mbed/main/main.cpp @@ -23,6 +23,10 @@ #include "capsense.h" #endif +#ifdef CHIP_PW_RPC +#include "Rpc.h" +#endif + #include "mbedtls/platform.h" #include #include @@ -45,6 +49,16 @@ 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 a29b41a26621a5..c4a415cd63804f 100644 --- a/examples/pigweed-app/mbed/main/main.cpp +++ b/examples/pigweed-app/mbed/main/main.cpp @@ -16,47 +16,17 @@ */ #include "LEDWidget.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 "Rpc.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; @@ -65,21 +35,19 @@ int main() ChipLogProgress(NotSpecified, "Mbed pigweed-app example application start"); - pw_sys_io_Init(); - sStatusLED.Set(true); - auto error = rpcThread.start(RunRpcService); - if (error != osOK) + auto rpcThread = chip::rpc::Init(); + if (rpcThread == NULL) { - ChipLogError(NotSpecified, "Run RPC thread failed [%d]", (int) error); + ChipLogError(NotSpecified, "RPC service initialization and run failed"); 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);