From e130bec6a06deafaf666a7fe96a54a23aa04eea3 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Sat, 24 Nov 2018 22:09:46 +0000 Subject: [PATCH] BLE: rework ScanParameters::phy_configuration_t --- features/FEATURE_BLE/ble/gap/ScanParameters.h | 40 ++++++++++++++++++- .../FEATURE_BLE/source/generic/GenericGap.cpp | 18 ++++----- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/features/FEATURE_BLE/ble/gap/ScanParameters.h b/features/FEATURE_BLE/ble/gap/ScanParameters.h index a456ab2c5c..5d1e2a1f4a 100644 --- a/features/FEATURE_BLE/ble/gap/ScanParameters.h +++ b/features/FEATURE_BLE/ble/gap/ScanParameters.h @@ -32,10 +32,21 @@ namespace ble { class ScanParameters { public: + + /** + * Scan configuration of a physical channel. + */ struct phy_configuration_t { + /** + * Construct a phy_configuration_t. + * @param scan_interval The scan interval. + * @param scan_window The scan window + * @param active_scanning True if scan request should be sent and false + * otherwise. + */ phy_configuration_t( - scan_window_t scan_interval = scan_interval_t::min(), - scan_interval_t scan_window = scan_window_t::min(), + scan_interval_t scan_interval = scan_interval_t::min(), + scan_window_t scan_window = scan_window_t::min(), bool active_scanning = false ) : interval(scan_interval), @@ -47,6 +58,31 @@ public: } } + /** + * Get the scan interval. + */ + const scan_window_t &getInterval() const + { + return interval; + } + + /** + * Get the scan window. + */ + const scan_interval_t &getWindow() const + { + return window; + } + + /** + * Return if active scanning is set. + */ + bool isActiveScanningSet() const + { + return active_scanning; + } + + private: scan_window_t interval; scan_interval_t window; bool active_scanning; diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index c6d708da17..5aa9fb2bc1 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -2570,18 +2570,18 @@ ble_error_t GenericGap::setScanParameters(const ScanParameters ¶ms) if (is_extended_advertising_available()) { bool active_scanning[] = { - params.get1mPhyConfiguration().active_scanning, - params.getCodedPhyConfiguration().active_scanning + params.get1mPhyConfiguration().isActiveScanningSet(), + params.getCodedPhyConfiguration().isActiveScanningSet() }; uint16_t scan_interval[] = { - params.get1mPhyConfiguration().interval.value(), - params.getCodedPhyConfiguration().interval.value() + params.get1mPhyConfiguration().getInterval().value(), + params.getCodedPhyConfiguration().getInterval().value() }; uint16_t scan_window[] = { - params.get1mPhyConfiguration().window.value(), - params.getCodedPhyConfiguration().window.value() + params.get1mPhyConfiguration().getWindow().value(), + params.getCodedPhyConfiguration().getWindow().value() }; return _pal_gap.set_extended_scan_parameters( @@ -2601,9 +2601,9 @@ ble_error_t GenericGap::setScanParameters(const ScanParameters ¶ms) params.get1mPhyConfiguration(); return _pal_gap.set_scan_parameters( - legacy_configuration.active_scanning, - legacy_configuration.interval.value(), - legacy_configuration.window.value(), + legacy_configuration.isActiveScanningSet(), + legacy_configuration.getInterval().value(), + legacy_configuration.getWindow().value(), params.getOwnAddressType(), params.getFilter() );