Skip to content

Jira 797, Central can scan with MAC address, git 376 #416

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

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions libraries/CurieBLE/src/BLEDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ void BLEDevice::scanForUuid(String uuid, bool withDuplicates)
startScan(withDuplicates);
}

void BLEDevice::scanForAddress(String macaddr, bool withDuplicates)
{
BLEDeviceManager::instance()->setAdvertiseCritical(macaddr.c_str());
startScan(withDuplicates);
}

void BLEDevice::stopScan()
{
BLEDeviceManager::instance()->stopScanning();
Expand Down
3 changes: 2 additions & 1 deletion libraries/CurieBLE/src/BLEDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,9 @@ class BLEDevice
* @note option to filter out duplicate addresses for Arduino.
* The current only support fileter duplicate mode.
*/
void scanForUuid(String uuid, bool withDuplicates);
void scanForUuid(String uuid, bool withDuplicates);

void scanForAddress(String macaddr, bool withDuplicates = true);
/**
* @brief Stop scanning for peripherals
*
Expand Down
14 changes: 14 additions & 0 deletions libraries/CurieBLE/src/internal/BLEDeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ BLEDeviceManager::BLEDeviceManager():
memset(_peer_adv_mill, 0, sizeof(_peer_adv_mill));
memset(&_adv_accept_critical, 0, sizeof(_adv_accept_critical));
memset(&_adv_critical_service_uuid, 0, sizeof(_adv_critical_service_uuid));
memset(&_adv_accept_device, 0, sizeof(_adv_accept_device));

memset(_peer_peripheral, 0, sizeof(_peer_peripheral));
memset(_peer_peripheral_adv_data, 0, sizeof(_peer_peripheral_adv_data));
Expand Down Expand Up @@ -562,6 +563,7 @@ bool BLEDeviceManager::stopScanning()
void BLEDeviceManager::clearAdvertiseCritical()
{
memset(&_adv_accept_critical, 0, sizeof(_adv_accept_critical));
memset(&_adv_accept_device, 0, sizeof(_adv_accept_device));
//memset(&_adv_critical_service_uuid, 0, sizeof(_adv_critical_service_uuid));
}

Expand Down Expand Up @@ -598,6 +600,11 @@ void BLEDeviceManager::setAdvertiseCritical(BLEService& service)
_adv_accept_critical.data = data;
}

void BLEDeviceManager::setAdvertiseCritical(const char* macaddress)
{
BLEUtils::macAddressString2BT(macaddress, _adv_accept_device);
}

bool BLEDeviceManager::hasLocalName(const BLEDevice* device) const
{
if (BLEUtils::isLocalBLE(*device) == true)
Expand Down Expand Up @@ -1248,6 +1255,13 @@ void BLEDeviceManager::handleDeviceFound(const bt_addr_le_t *addr,
if (type == BT_LE_ADV_IND || type == BT_LE_ADV_DIRECT_IND)
{
//pr_debug(LOG_MODULE_BLE, "%s-%d", __FUNCTION__, __LINE__);
// Filter address
if (BLEUtils::macAddressValid(_adv_accept_device) == true &&
(memcmp(addr->val, _adv_accept_device.val, sizeof (addr->val)) != 0))
{
return;
}

while (data_len > 1)
{
uint8_t len = data[0];
Expand Down
2 changes: 2 additions & 0 deletions libraries/CurieBLE/src/internal/BLEDeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class BLEDeviceManager
void clearAdvertiseCritical();
void setAdvertiseCritical(String name);
void setAdvertiseCritical(BLEService& service);
void setAdvertiseCritical(const char* macaddress);
bool startScanning(); // start scanning for peripherals
bool startScanningWithDuplicates(); // start scanning for peripherals, and report all duplicates
bool stopScanning(); // stop scanning for peripherals
Expand Down Expand Up @@ -378,6 +379,7 @@ class BLEDeviceManager
bt_data_t _adv_accept_critical; // The filters for central device
String _adv_critical_local_name;
bt_uuid_128_t _adv_critical_service_uuid;
bt_addr_le_t _adv_accept_device;

bt_addr_le_t _wait_for_connect_peripheral;
uint8_t _wait_for_connect_peripheral_adv_data[BLE_MAX_ADV_SIZE];
Expand Down