-
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.
[Mbed] Add all-clusters-app example (#10442)
* Add Mbed OS all-clusters-app implementation Add all-clusters-app to mbed_example script, launch.json, tasks.json * Add all-cluster-app to mbed example workflow * Update app logging * mbed_app.json cleanup * Fix after rebase * Changes for Mbed OS update * Improve examples startup logging * Fix after app server refactor * Fix MBED_PATH value Example cleanup * Changes restyle * Remove TODO note * Fix mbed all-clusters-app build
- Loading branch information
Showing
13 changed files
with
542 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
config/ | ||
build-*/ |
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,144 @@ | ||
# Copyright (c) 2021 ARM Limited. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.19.0) | ||
|
||
get_filename_component(CHIP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../.. REALPATH) | ||
get_filename_component(APP_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/.. REALPATH) | ||
get_filename_component(MBED_COMMON ${CHIP_ROOT}/examples/platform/mbed REALPATH) | ||
get_filename_component(APP_UTIL ${CHIP_ROOT}/src/app/util REALPATH) | ||
get_filename_component(APP_CLUSTERS ${CHIP_ROOT}/src/app/clusters REALPATH) | ||
get_filename_component(GEN_DIR ${CHIP_ROOT}/zzz_generated/ REALPATH) | ||
|
||
configure_file( | ||
${CMAKE_CURRENT_SOURCE_DIR}/config.in | ||
${CMAKE_CURRENT_BINARY_DIR}/chip_build/config | ||
@ONLY | ||
) | ||
|
||
set(MBED_PATH $ENV{MBED_OS_PATH} CACHE INTERNAL "") | ||
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "") | ||
set(APP_TARGET chip-mbed-all-clusters-app-example) | ||
|
||
include(${MBED_PATH}/tools/cmake/app.cmake) | ||
|
||
project(${APP_TARGET}) | ||
|
||
add_subdirectory(${MBED_PATH} ./mbed_build) | ||
add_subdirectory($ENV{MBED_OS_POSIX_SOCKET_PATH} ./mbed_os_posix_socket_build) | ||
|
||
add_executable(${APP_TARGET}) | ||
|
||
add_subdirectory(${CHIP_ROOT}/config/mbed ./chip_build) | ||
|
||
mbed_configure_app_target(${APP_TARGET}) | ||
|
||
target_include_directories(${APP_TARGET} PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_SOURCE_DIR}/main/include/ | ||
${APP_ROOT}/all-clusters-common | ||
${MBED_COMMON}/util/include | ||
${CHIP_ROOT}/src/app | ||
${CHIP_ROOT}/third_party/nlio/repo/include | ||
${GEN_DIR}/all-clusters-app | ||
${GEN_DIR}/ota-provider-app | ||
${GEN_DIR}/app-common | ||
) | ||
|
||
target_sources(${APP_TARGET} PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR}/main/main.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/main/AppTask.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/main/LowPowerManager.cpp | ||
|
||
${MBED_COMMON}/util/LEDWidget.cpp | ||
|
||
${GEN_DIR}/all-clusters-app/zap-generated/attribute-size.cpp | ||
${GEN_DIR}/all-clusters-app/zap-generated/callback-stub.cpp | ||
${GEN_DIR}/all-clusters-app/zap-generated/CHIPClientCallbacks.cpp | ||
${GEN_DIR}/all-clusters-app/zap-generated/CHIPClusters.cpp | ||
${GEN_DIR}/all-clusters-app/zap-generated/IMClusterCommandHandler.cpp | ||
${GEN_DIR}/app-common/app-common/zap-generated/attributes/Accessors.cpp | ||
${GEN_DIR}/app-common/app-common/zap-generated/cluster-objects.cpp | ||
|
||
${CHIP_ROOT}/src/app/server/EchoHandler.cpp | ||
${CHIP_ROOT}/src/app/server/Dnssd.cpp | ||
${CHIP_ROOT}/src/app/server/OnboardingCodesUtil.cpp | ||
${CHIP_ROOT}/src/app/server/Server.cpp | ||
${CHIP_ROOT}/src/app/server/CommissioningWindowManager.cpp | ||
|
||
${APP_UTIL}/DataModelHandler.cpp | ||
${APP_UTIL}/af-event.cpp | ||
${APP_UTIL}/af-main-common.cpp | ||
${APP_UTIL}/attribute-storage.cpp | ||
${APP_UTIL}/attribute-table.cpp | ||
${APP_UTIL}/attribute-size-util.cpp | ||
${APP_UTIL}/attribute-list-byte-span.cpp | ||
${APP_UTIL}/binding-table.cpp | ||
${APP_UTIL}/chip-message-send.cpp | ||
${APP_UTIL}/client-api.cpp | ||
${APP_UTIL}/ember-print.cpp | ||
${APP_UTIL}/ember-compatibility-functions.cpp | ||
${APP_UTIL}/message.cpp | ||
${APP_UTIL}/process-cluster-message.cpp | ||
${APP_UTIL}/process-global-message.cpp | ||
${APP_UTIL}/util.cpp | ||
${APP_UTIL}/error-mapping.cpp | ||
|
||
${APP_CLUSTERS}/basic/basic.cpp | ||
${APP_CLUSTERS}/bindings/bindings.cpp | ||
${APP_CLUSTERS}/on-off-server/on-off-server.cpp | ||
${APP_CLUSTERS}/account-login-server/account-login-server.cpp | ||
${APP_CLUSTERS}/application-launcher-server/application-launcher-server.cpp | ||
${APP_CLUSTERS}/audio-output-server/audio-output-server.cpp | ||
${APP_CLUSTERS}/barrier-control-server/barrier-control-server.cpp | ||
${APP_CLUSTERS}/basic/basic.cpp | ||
${APP_CLUSTERS}/bindings/bindings.cpp | ||
${APP_CLUSTERS}/color-control-server/color-control-server.cpp | ||
${APP_CLUSTERS}/content-launch-server/content-launch-server.cpp | ||
${APP_CLUSTERS}/descriptor/descriptor.cpp | ||
${APP_CLUSTERS}/door-lock-server/door-lock-server-core.cpp | ||
${APP_CLUSTERS}/door-lock-server/door-lock-server-logging.cpp | ||
${APP_CLUSTERS}/door-lock-server/door-lock-server-schedule.cpp | ||
${APP_CLUSTERS}/door-lock-server/door-lock-server-user.cpp | ||
${APP_CLUSTERS}/general-commissioning-server/general-commissioning-server.cpp | ||
${APP_CLUSTERS}/groups-server/groups-server.cpp | ||
${APP_CLUSTERS}/ias-zone-server/ias-zone-server.cpp | ||
${APP_CLUSTERS}/keypad-input-server/keypad-input-server.cpp | ||
${APP_CLUSTERS}/level-control/level-control.cpp | ||
${APP_CLUSTERS}/low-power-server/low-power-server.cpp | ||
${APP_CLUSTERS}/media-input-server/media-input-server.cpp | ||
${APP_CLUSTERS}/media-playback-server/media-playback-server.cpp | ||
${APP_CLUSTERS}/network-commissioning/network-commissioning-ember.cpp | ||
${APP_CLUSTERS}/network-commissioning/network-commissioning.cpp | ||
${APP_CLUSTERS}/on-off-server/on-off-server.cpp | ||
${APP_CLUSTERS}/ota-provider/ota-provider.cpp | ||
${APP_CLUSTERS}/scenes/scenes.cpp | ||
${APP_CLUSTERS}/target-navigator-server/target-navigator-server.cpp | ||
${APP_CLUSTERS}/tv-channel-server/tv-channel-server.cpp | ||
${APP_CLUSTERS}/operational-credentials-server/operational-credentials-server.cpp | ||
${APP_CLUSTERS}/test-cluster-server/test-cluster-server.cpp | ||
${APP_CLUSTERS}/occupancy-sensor-server/occupancy-sensor-server.cpp | ||
${APP_CLUSTERS}/diagnostic-logs-server/diagnostic-logs-server.cpp | ||
${APP_CLUSTERS}/ethernet_network_diagnostics_server/ethernet_network_diagnostics_server.cpp | ||
${APP_CLUSTERS}/software_diagnostics_server/software_diagnostics_server.cpp | ||
${APP_CLUSTERS}/thread_network_diagnostics_server/thread_network_diagnostics_server.cpp | ||
${APP_CLUSTERS}/wifi_network_diagnostics_server/wifi_network_diagnostics_server.cpp | ||
${APP_CLUSTERS}/pump-configuration-and-control-server/pump-configuration-and-control-server.cpp | ||
${APP_CLUSTERS}/administrator-commissioning-server/administrator-commissioning-server.cpp | ||
${APP_CLUSTERS}/identify-server/identify-server.cpp | ||
${APP_CLUSTERS}/window-covering-server/window-covering-server.cpp | ||
${APP_CLUSTERS}/general_diagnostics_server/general_diagnostics_server.cpp | ||
) | ||
|
||
target_link_libraries(${APP_TARGET} mbed-os-posix-socket mbed-os mbed-ble mbed-events mbed-netsocket mbed-storage mbed-storage-kv-global-api mbed-mbedtls mbed-emac chip) | ||
|
||
if(MBED_TARGET STREQUAL "CY8CPROTO_062_4343W") | ||
target_link_libraries(${APP_TARGET} mbed-cy-psoc6-common-network) | ||
endif() | ||
|
||
mbed_set_post_build(${APP_TARGET}) | ||
|
||
option(VERBOSE_BUILD "Have a verbose build process") | ||
if(VERBOSE_BUILD) | ||
set(CMAKE_VERBOSE_MAKEFILE ON) | ||
endif() |
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,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 |
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,143 @@ | ||
/* | ||
* | ||
* 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 "AppTask.h" | ||
#include "LEDWidget.h" | ||
#include <app/server/OnboardingCodesUtil.h> | ||
|
||
#include <app/server/Dnssd.h> | ||
#include <app/server/Server.h> | ||
#include <credentials/DeviceAttestationCredsProvider.h> | ||
#include <credentials/examples/DeviceAttestationCredsExample.h> | ||
|
||
#include <support/logging/CHIPLogging.h> | ||
|
||
static LEDWidget sStatusLED(MBED_CONF_APP_SYSTEM_STATE_LED); | ||
|
||
static bool sIsWiFiStationProvisioned = false; | ||
static bool sIsWiFiStationEnabled = false; | ||
static bool sIsWiFiStationConnected = false; | ||
static bool sIsPairedToAccount = false; | ||
static bool sHaveBLEConnections = false; | ||
|
||
static events::EventQueue sAppEventQueue; | ||
|
||
using namespace ::chip::DeviceLayer; | ||
using namespace ::chip::Credentials; | ||
|
||
AppTask AppTask::sAppTask; | ||
|
||
int AppTask::Init() | ||
{ | ||
// Register the callback to init the MDNS server when connectivity is available | ||
PlatformMgr().AddEventHandler( | ||
[](const ChipDeviceEvent * event, intptr_t arg) { | ||
// Restart the server whenever an ip address is renewed | ||
if (event->Type == DeviceEventType::kInternetConnectivityChange) | ||
{ | ||
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established || | ||
event->InternetConnectivityChange.IPv6 == kConnectivity_Established) | ||
{ | ||
chip::app::DnssdServer::Instance().StartServer(); | ||
} | ||
} | ||
}, | ||
0); | ||
|
||
// Start BLE advertising if needed | ||
if (!CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART) | ||
{ | ||
ChipLogProgress(NotSpecified, "Enabling BLE advertising."); | ||
ConnectivityMgr().SetBLEAdvertisingEnabled(true); | ||
} | ||
|
||
chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement(); | ||
|
||
// Init ZCL Data Model and start server | ||
chip::Server::GetInstance().Init(); | ||
|
||
// Initialize device attestation config | ||
SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); | ||
ConfigurationMgr().LogDeviceConfig(); | ||
// QR code will be used with CHIP Tool | ||
PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); | ||
|
||
return 0; | ||
} | ||
|
||
int AppTask::StartApp() | ||
{ | ||
int ret = Init(); | ||
if (ret) | ||
{ | ||
ChipLogError(NotSpecified, "AppTask.Init() failed"); | ||
return ret; | ||
} | ||
|
||
ChipLogProgress(NotSpecified, "Mbed all-clusters-app example application run"); | ||
|
||
while (true) | ||
{ | ||
sAppEventQueue.dispatch(100); | ||
|
||
// Collect connectivity and configuration state from the CHIP stack. Because the | ||
// CHIP event loop is being run in a separate task, the stack must be locked | ||
// while these values are queried. However we use a non-blocking lock request | ||
// (TryLockChipStack()) to avoid blocking other UI activities when the CHIP | ||
// task is busy (e.g. with a long crypto operation). | ||
|
||
if (PlatformMgr().TryLockChipStack()) | ||
{ | ||
sIsWiFiStationProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); | ||
sIsWiFiStationEnabled = ConnectivityMgr().IsWiFiStationEnabled(); | ||
sIsWiFiStationConnected = ConnectivityMgr().IsWiFiStationConnected(); | ||
sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); | ||
PlatformMgr().UnlockChipStack(); | ||
} | ||
|
||
// Update the status LED | ||
// | ||
// If system is connected to Wi-Fi station, keep the LED On constantly. | ||
// | ||
// If Wi-Fi is provisioned, but not connected to Wi-Fi station yet | ||
// THEN blink the LED Off for a short period of time. | ||
// | ||
// If the system has ble connection(s) uptill the stage above, THEN blink the LEDs at an even | ||
// rate of 100ms. | ||
// | ||
// Otherwise, blink the LED ON for a very short time. | ||
if (sIsWiFiStationConnected) | ||
{ | ||
sStatusLED.Set(true); | ||
} | ||
else if (sIsWiFiStationProvisioned && sIsWiFiStationEnabled && sIsPairedToAccount && !sIsWiFiStationConnected) | ||
{ | ||
sStatusLED.Blink(950, 50); | ||
} | ||
else if (sHaveBLEConnections) | ||
{ | ||
sStatusLED.Blink(100, 100); | ||
} | ||
else | ||
{ | ||
sStatusLED.Blink(50, 950); | ||
} | ||
|
||
sStatusLED.Animate(); | ||
} | ||
} |
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,22 @@ | ||
/* | ||
* | ||
* 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. | ||
*/ | ||
|
||
bool lowPowerClusterSleep() | ||
{ | ||
return true; | ||
} |
Oops, something went wrong.