Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from advertisement duration units to ms moved from Gap to … #63

Merged
merged 2 commits into from
Aug 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions ble/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,10 @@ class Gap {
};

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);
Expand Down Expand Up @@ -470,7 +464,7 @@ class Gap {
} else if (interval < getMinAdvertisingInterval()) {
interval = getMinAdvertisingInterval();
}
_advParams.setInterval(MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval));
_advParams.setInterval(GapAdvertisingParams::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(interval));
}

/**
Expand Down
10 changes: 9 additions & 1 deletion ble/GapAdvertisingParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,16 @@ class GapAdvertisingParams {
}
}

static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */
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 getInterval(void) const {return ADVERTISEMENT_DURATION_UNITS_TO_MS(_interval);}
uint16_t getTimeout(void) const {return _timeout; }

void setAdvertisingType(AdvertisingType_t newAdvType) {_advType = newAdvType; }
Expand Down
5 changes: 5 additions & 0 deletions ble/GapScanningParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class GapScanningParams {
uint16_t timeout = 0,
bool activeScanning = false);

static const uint16_t UNIT_0_625_MS = 625; /**< Number of microseconds in 0.625 milliseconds. */
static uint16_t MSEC_TO_SCAN_DURATION_UNITS(uint32_t durationInMillis) {
return (durationInMillis * 1000) / UNIT_0_625_MS;
}

ble_error_t setInterval(uint16_t newIntervalInMS);

ble_error_t setWindow(uint16_t newWindowInMS);
Expand Down
2 changes: 1 addition & 1 deletion ble/services/URIBeaconConfigService.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class URIBeaconConfigService {
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. */
Expand Down
8 changes: 4 additions & 4 deletions source/GapScanningParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(MSEC_TO_SCAN_DURATION_UNITS(interval)),
_window(MSEC_TO_SCAN_DURATION_UNITS(window)),
_timeout(timeout),
_activeScanning(activeScanning) {
/* stay within limits */
Expand All @@ -40,7 +40,7 @@ GapScanningParams::GapScanningParams(uint16_t interval, uint16_t window, uint16_
ble_error_t
GapScanningParams::setInterval(uint16_t newIntervalInMS)
{
uint16_t newInterval = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newIntervalInMS);
uint16_t newInterval = MSEC_TO_SCAN_DURATION_UNITS(newIntervalInMS);
if ((newInterval >= SCAN_INTERVAL_MIN) && (newInterval < SCAN_INTERVAL_MAX)) {
_interval = newInterval;
return BLE_ERROR_NONE;
Expand All @@ -52,7 +52,7 @@ GapScanningParams::setInterval(uint16_t newIntervalInMS)
ble_error_t
GapScanningParams::setWindow(uint16_t newWindowInMS)
{
uint16_t newWindow = Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(newWindowInMS);
uint16_t newWindow = MSEC_TO_SCAN_DURATION_UNITS(newWindowInMS);
if ((newWindow >= SCAN_WINDOW_MIN) && (newWindow < SCAN_WINDOW_MAX)) {
_window = newWindow;
return BLE_ERROR_NONE;
Expand Down