my version with changed conversion between duration units
Fork of BLE_API by
Revision 758:85c13328a10a, committed 2015-08-05
- Comitter:
- jslater8
- Date:
- Wed Aug 05 14:20:04 2015 +0000
- Parent:
- 757:4cd3b18607ec
- Commit message:
- Conversion from Interval duration units to milliseconds now in GapAdvertisingParams.h and changed getInterval to properly convert back to milliseconds
Changed in this revision
diff -r 4cd3b18607ec -r 85c13328a10a ble/Gap.h --- a/ble/Gap.h Tue Jul 21 13:25:40 2015 +0100 +++ b/ble/Gap.h Wed Aug 05 14:20:04 2015 +0000 @@ -128,15 +128,6 @@ static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */ static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */ - static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) { - return (durationInMillis * 1000) / UNIT_1_25_MS; - } - static uint16_t MSEC_TO_ADVERTISEMENT_DURATION_UNITS(uint32_t durationInMillis) { - return (durationInMillis * 1000) / UNIT_0_625_MS; - } - static uint16_t ADVERTISEMENT_DURATION_UNITS_TO_MS(uint16_t gapUnits) { - return (gapUnits * UNIT_0_625_MS) / 1000; - } typedef void (*TimeoutEventCallback_t)(TimeoutSource_t source); typedef void (*ConnectionEventCallback_t)(const ConnectionCallbackParams_t *params); @@ -470,7 +461,7 @@ } else if (interval < getMinAdvertisingInterval()) { interval = getMinAdvertisingInterval(); } - _advParams.setInterval(MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)); + _advParams.setInterval(GapAdvertisingParams::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)); } /**
diff -r 4cd3b18607ec -r 85c13328a10a ble/GapAdvertisingParams.h --- a/ble/GapAdvertisingParams.h Tue Jul 21 13:25:40 2015 +0100 +++ b/ble/GapAdvertisingParams.h Wed Aug 05 14:20:04 2015 +0000 @@ -17,6 +17,7 @@ #ifndef __GAP_ADVERTISING_PARAMS_H__ #define __GAP_ADVERTISING_PARAMS_H__ + /**************************************************************************/ /*! \brief @@ -85,13 +86,25 @@ } } } + + static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */ + static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */ + static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) { + return (durationInMillis * 1000) / UNIT_1_25_MS; + } + static uint16_t MSEC_TO_ADVERTISEMENT_DURATION_UNITS(uint32_t durationInMillis) { + return (durationInMillis * 1000) / UNIT_0_625_MS; + } + static uint16_t ADVERTISEMENT_DURATION_UNITS_TO_MS(uint16_t gapUnits) { + return (gapUnits * UNIT_0_625_MS) / 1000; + } AdvertisingType_t getAdvertisingType(void) const {return _advType; } uint16_t getInterval(void) const {return _interval;} uint16_t getTimeout(void) const {return _timeout; } void setAdvertisingType(AdvertisingType_t newAdvType) {_advType = newAdvType; } - void setInterval(uint16_t newInterval) {_interval = newInterval;} + void setInterval(uint16_t newInterval) {_interval = ADVERTISEMENT_DURATION_UNITS_TO_MS(newInterval);} void setTimeout(uint16_t newTimeout) {_timeout = newTimeout; } private:
diff -r 4cd3b18607ec -r 85c13328a10a ble/services/URIBeaconConfigService.h --- a/ble/services/URIBeaconConfigService.h Tue Jul 21 13:25:40 2015 +0100 +++ b/ble/services/URIBeaconConfigService.h Wed Aug 05 14:20:04 2015 +0000 @@ -178,7 +178,7 @@ ble.gap().setTxPower(params.advPowerLevels[params.txPowerMode]); ble.gap().setDeviceName(reinterpret_cast<const uint8_t *>(&DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); - ble.gap().setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADVERTISING_INTERVAL_MSEC)); + ble.gap().setAdvertisingInterval(GapAdvertisingParams::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(ADVERTISING_INTERVAL_MSEC)); } /* Helper function to switch to the non-connectible normal mode for URIBeacon. This gets called after a timeout. */
diff -r 4cd3b18607ec -r 85c13328a10a source/GapScanningParams.cpp --- a/source/GapScanningParams.cpp Tue Jul 21 13:25:40 2015 +0100 +++ b/source/GapScanningParams.cpp Wed Aug 05 14:20:04 2015 +0000 @@ -18,8 +18,8 @@ #include "ble/GapScanningParams.h" GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_t timeout, bool activeScanning) : - _interval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)), - _window(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)), + _interval(GapAdvertisingParams::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval)), + _window(GapAdvertisingParams::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(window)), _timeout(timeout), _activeScanning(activeScanning) { /* stay within limits */ @@ -40,7 +40,7 @@ ble_error_t GapScanningParams::setInterval(uint16_t newIntervalInMS) { - uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS); + uint16_t newInterval = GapAdvertisingParams::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS); if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) { _interval = newInterval; return BLE_ERROR_NONE; @@ -52,7 +52,7 @@ ble_error_t GapScanningParams::setWindow(uint16_t newWindowInMS) { - uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS); + uint16_t newWindow = GapAdvertisingParams::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS); if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) { _window = newWindow; return BLE_ERROR_NONE;