From 1107841373c40b0cd511fedd674316adea9d4993 Mon Sep 17 00:00:00 2001 From: lucicop Date: Mon, 10 May 2021 17:01:56 +0300 Subject: [PATCH] Align auto-advertising behavior to spec (#6573) * Modify BLE advertising to start on button press for lock-app * Align define * Restyled by whitespace * restyler - whitespace removal Co-authored-by: Restyled.io Co-authored-by: Timothy Maes --- examples/lighting-app/qpg6100/src/AppTask.cpp | 4 ++++ examples/lock-app/qpg6100/APPLICATION.md | 2 +- examples/lock-app/qpg6100/include/AppTask.h | 7 +++--- examples/lock-app/qpg6100/src/AppTask.cpp | 23 ++++++++++++------- .../qpg6100/CHIPDevicePlatformConfig.h | 5 ++++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/examples/lighting-app/qpg6100/src/AppTask.cpp b/examples/lighting-app/qpg6100/src/AppTask.cpp index 58e0ef504c230b..07ccd0f3bd708a 100644 --- a/examples/lighting-app/qpg6100/src/AppTask.cpp +++ b/examples/lighting-app/qpg6100/src/AppTask.cpp @@ -104,6 +104,10 @@ int AppTask::Init() ConfigurationMgr().LogDeviceConfig(); PrintOnboardingCodes(chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)); + // Enable BLE advertisements + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); + return err; } diff --git a/examples/lock-app/qpg6100/APPLICATION.md b/examples/lock-app/qpg6100/APPLICATION.md index 6c164caa1037d6..0f86eb6066abd8 100644 --- a/examples/lock-app/qpg6100/APPLICATION.md +++ b/examples/lock-app/qpg6100/APPLICATION.md @@ -13,7 +13,7 @@ This application uses following buttons of the DK board: - SW2: Used to perform a HW reset for the full board - SW4: Used to toggle the Unlock/Lock the simulated lock - SW5: Used to perform, depending on the time the button is kept pressed, - - Software update - not yet supported (released before 3s) + - Start BLE advertising (released before 3s) - Trigger Thread joining (release after 3s) - Factory reset (released after 6s) diff --git a/examples/lock-app/qpg6100/include/AppTask.h b/examples/lock-app/qpg6100/include/AppTask.h index c661c956974069..7dc789c0cbdb3f 100644 --- a/examples/lock-app/qpg6100/include/AppTask.h +++ b/examples/lock-app/qpg6100/include/AppTask.h @@ -66,9 +66,10 @@ class AppTask enum Function_t { kFunction_NoneSelected = 0, - kFunction_SoftwareUpdate = 0, - kFunction_Joiner = 1, - kFunction_FactoryReset = 2, + kFunction_SoftwareUpdate = 1, + kFunction_Joiner = 2, + kFunction_FactoryReset = 3, + kFunction_StartBleAdv = 4, kFunction_Invalid } Function; diff --git a/examples/lock-app/qpg6100/src/AppTask.cpp b/examples/lock-app/qpg6100/src/AppTask.cpp index 3c562830b6692f..9947b61b37da48 100644 --- a/examples/lock-app/qpg6100/src/AppTask.cpp +++ b/examples/lock-app/qpg6100/src/AppTask.cpp @@ -276,7 +276,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) // If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT, // initiate factory reset - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) { #if CHIP_ENABLE_OPENTHREAD ChipLogProgress(NotSpecified, "Release button now to Start Thread Joiner"); @@ -319,7 +319,7 @@ void AppTask::FunctionHandler(AppEvent * aEvent) return; } - // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (< + // To trigger BLE advertising: press the APP_FUNCTION_BUTTON button briefly (< // FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the // APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT + // FACTORY_RESET_CANCEL_WINDOW_TIMEOUT All LEDs start blinking after @@ -336,20 +336,27 @@ void AppTask::FunctionHandler(AppEvent * aEvent) sAppTask.StartTimer(FACTORY_RESET_TRIGGER_TIMEOUT); #endif - sAppTask.mFunction = kFunction_SoftwareUpdate; + sAppTask.mFunction = kFunction_StartBleAdv; } } else { - // If the button was released before factory reset got initiated, trigger a - // software update. - if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_SoftwareUpdate) + // If the button was released before factory reset got initiated, trigger BLE advertising. + if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_StartBleAdv) { sAppTask.CancelTimer(); - sAppTask.mFunction = kFunction_NoneSelected; - ChipLogError(NotSpecified, "Software Update currently not supported."); + if (!ConnectivityMgr().IsThreadProvisioned()) + { + // Enable BLE advertisements + ConnectivityMgr().SetBLEAdvertisingEnabled(true); + ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); + } + else + { + ChipLogError(NotSpecified, "Network is already provisioned, BLE advertisement not enabled"); + } } #if CHIP_ENABLE_OPENTHREAD else if (sAppTask.mFunctionTimerActive && sAppTask.mFunction == kFunction_Joiner) diff --git a/src/platform/qpg6100/CHIPDevicePlatformConfig.h b/src/platform/qpg6100/CHIPDevicePlatformConfig.h index 18b51d96cbd4eb..adfceaaa77df49 100644 --- a/src/platform/qpg6100/CHIPDevicePlatformConfig.h +++ b/src/platform/qpg6100/CHIPDevicePlatformConfig.h @@ -63,5 +63,10 @@ #define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL 0 #define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 0 +// Per 5.2.5.2. Commencement Section of CHIP spec, BLE advertisement is +// disabled for Locks and Barrier Access Devices. +#define CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART 0 +#define CHIP_DEVICE_CONFIG_ENABLE_PAIRING_AUTOSTART 0 + // ========== Platform-specific Cluster Overrides ========= #define CHIP_CLUSTER_NETWORK_COMMISSIONING_MAX_NETWORKS 1