Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f9ba3b3

Browse files
committed
[WIP] Implement and test multiple concurrent connections
1 parent 95ce2e1 commit f9ba3b3

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
lines changed

‎src/local/BLELocalDevice.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,41 @@ BLEDevice BLELocalDevice::central()
265265
return ATT.central();
266266
}
267267

268+
BLEDevice BLELocalDevice::central(int index)
269+
{
270+
HCI.poll();
271+
272+
return ATT.central(index);
273+
}
274+
275+
int BLELocalDevice::centralCount()
276+
{
277+
HCI.poll();
278+
279+
return ATT.centralCount();
280+
}
281+
282+
BLEDevice BLELocalDevice::peripheral()
283+
{
284+
HCI.poll();
285+
286+
return ATT.peripheral();
287+
}
288+
289+
BLEDevice BLELocalDevice::peripheral(int index)
290+
{
291+
HCI.poll();
292+
293+
return ATT.peripheral(index);
294+
}
295+
296+
int BLELocalDevice::peripheralCount()
297+
{
298+
HCI.poll();
299+
300+
return ATT.peripheralCount();
301+
}
302+
268303
BLEDevice BLELocalDevice::available()
269304
{
270305
HCI.poll();

‎src/local/BLELocalDevice.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class BLELocalDevice {
6262
void stopScan();
6363

6464
BLEDevice central();
65+
BLEDevice central(int index);
66+
int centralCount();
67+
BLEDevice peripheral();
68+
BLEDevice peripheral(int index);
69+
int peripheralCount();
6570
BLEDevice available();
6671

6772
void setEventHandler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler);

‎src/utility/ATT.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,19 +497,78 @@ bool ATTClass::disconnect()
497497
return (numDisconnects > 0);
498498
}
499499

500-
BLEDevice ATTClass::central()
500+
BLEDevice ATTClass::central()
501501
{
502+
return central(0);
503+
}
504+
505+
BLEDevice ATTClass::central(int index)
506+
{
507+
int currentIndex = 0;
502508
for (int i = 0; i < ATT_MAX_PEERS; i++) {
503509
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x01) {
504510
continue;
505511
}
506512

507-
return BLEDevice(_peers[i].addressType, _peers[i].address);
513+
if (currentIndex == index) {
514+
return BLEDevice(_peers[i].addressType, _peers[i].address);
515+
}
516+
currentIndex++;
508517
}
509518

510519
return BLEDevice();
511520
}
512521

522+
int ATTClass::centralCount()
523+
{
524+
int count = 0;
525+
for (int i = 0; i < ATT_MAX_PEERS; i++) {
526+
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x01) {
527+
continue;
528+
}
529+
530+
count++;
531+
}
532+
533+
return count;
534+
}
535+
536+
BLEDevice ATTClass::peripheral()
537+
{
538+
return peripheral(0);
539+
}
540+
541+
BLEDevice ATTClass::peripheral(int index)
542+
{
543+
int currentIndex = 0;
544+
for (int i = 0; i < ATT_MAX_PEERS; i++) {
545+
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x00) {
546+
continue;
547+
}
548+
549+
if (currentIndex == index) {
550+
return BLEDevice(_peers[i].addressType, _peers[i].address);
551+
}
552+
currentIndex++;
553+
}
554+
555+
return BLEDevice();
556+
}
557+
558+
int ATTClass::peripheralCount()
559+
{
560+
int count = 0;
561+
for (int i = 0; i < ATT_MAX_PEERS; i++) {
562+
if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x00) {
563+
continue;
564+
}
565+
566+
count++;
567+
}
568+
569+
return count;
570+
}
571+
513572
bool ATTClass::handleNotify(uint16_t handle, const uint8_t* value, int length)
514573
{
515574
int numNotifications = 0;

‎src/utility/ATT.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class ATTClass {
6767
bool disconnect();
6868

6969
BLEDevice central();
70+
BLEDevice central(int index);
71+
int centralCount();
72+
BLEDevice peripheral();
73+
BLEDevice peripheral(int index);
74+
int peripheralCount();
7075

7176
bool handleNotify(uint16_t handle, const uint8_t* value, int length);
7277
bool handleInd(uint16_t handle, const uint8_t* value, int length);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /