@@ -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+
513572bool ATTClass::handleNotify (uint16_t handle, const uint8_t * value, int length)
514573{
515574 int numNotifications = 0 ;
0 commit comments