Skip to content

Commit

Permalink
[WIP] Implement and test multiple concurrent connections
Browse files Browse the repository at this point in the history
  • Loading branch information
polldo committed Aug 11, 2020
1 parent 95ce2e1 commit f9ba3b3
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/local/BLELocalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,41 @@ BLEDevice BLELocalDevice::central()
return ATT.central();
}

BLEDevice BLELocalDevice::central(int index)
{
HCI.poll();

return ATT.central(index);
}

int BLELocalDevice::centralCount()
{
HCI.poll();

return ATT.centralCount();
}

BLEDevice BLELocalDevice::peripheral()
{
HCI.poll();

return ATT.peripheral();
}

BLEDevice BLELocalDevice::peripheral(int index)
{
HCI.poll();

return ATT.peripheral(index);
}

int BLELocalDevice::peripheralCount()
{
HCI.poll();

return ATT.peripheralCount();
}

BLEDevice BLELocalDevice::available()
{
HCI.poll();
Expand Down
5 changes: 5 additions & 0 deletions src/local/BLELocalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class BLELocalDevice {
void stopScan();

BLEDevice central();
BLEDevice central(int index);
int centralCount();
BLEDevice peripheral();
BLEDevice peripheral(int index);
int peripheralCount();
BLEDevice available();

void setEventHandler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler);
Expand Down
63 changes: 61 additions & 2 deletions src/utility/ATT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,78 @@ bool ATTClass::disconnect()
return (numDisconnects > 0);
}

BLEDevice ATTClass::central()
BLEDevice ATTClass::central()
{
return central(0);
}

BLEDevice ATTClass::central(int index)
{
int currentIndex = 0;
for (int i = 0; i < ATT_MAX_PEERS; i++) {
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x01) {
continue;
}

return BLEDevice(_peers[i].addressType, _peers[i].address);
if (currentIndex == index) {
return BLEDevice(_peers[i].addressType, _peers[i].address);
}
currentIndex++;
}

return BLEDevice();
}

int ATTClass::centralCount()
{
int count = 0;
for (int i = 0; i < ATT_MAX_PEERS; i++) {
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x01) {
continue;
}

count++;
}

return count;
}

BLEDevice ATTClass::peripheral()
{
return peripheral(0);
}

BLEDevice ATTClass::peripheral(int index)
{
int currentIndex = 0;
for (int i = 0; i < ATT_MAX_PEERS; i++) {
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x00) {
continue;
}

if (currentIndex == index) {
return BLEDevice(_peers[i].addressType, _peers[i].address);
}
currentIndex++;
}

return BLEDevice();
}

int ATTClass::peripheralCount()
{
int count = 0;
for (int i = 0; i < ATT_MAX_PEERS; i++) {
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x00) {
continue;
}

count++;
}

return count;
}

bool ATTClass::handleNotify(uint16_t handle, const uint8_t* value, int length)
{
int numNotifications = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/utility/ATT.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class ATTClass {
bool disconnect();

BLEDevice central();
BLEDevice central(int index);
int centralCount();
BLEDevice peripheral();
BLEDevice peripheral(int index);
int peripheralCount();

bool handleNotify(uint16_t handle, const uint8_t* value, int length);
bool handleInd(uint16_t handle, const uint8_t* value, int length);
Expand Down

0 comments on commit f9ba3b3

Please sign in to comment.