Skip to content

Commit

Permalink
Align auto-advertising behavior to spec (#6573)
Browse files Browse the repository at this point in the history
* Modify BLE advertising to start on button press for lock-app

* Align define

* Restyled by whitespace

* restyler - whitespace removal

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Timothy Maes <[email protected]>
  • Loading branch information
3 people authored and pull[bot] committed May 20, 2021
1 parent 3772b77 commit 1107841
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
4 changes: 4 additions & 0 deletions examples/lighting-app/qpg6100/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lock-app/qpg6100/APPLICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions examples/lock-app/qpg6100/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 15 additions & 8 deletions examples/lock-app/qpg6100/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/platform/qpg6100/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1107841

Please sign in to comment.