@@ -109,8 +109,9 @@ ATTClass::~ATTClass()
109109
110110bool ATTClass::connect (uint8_t peerBdaddrType, uint8_t peerBdaddr[6 ])
111111{
112+ // original supervision timeout "0x00c8" seems to be too short for Nano 33 BLE (2 seconds)
112113 if (HCI.leCreateConn (0x0060 , 0x0030 , 0x00 , peerBdaddrType, peerBdaddr, 0x00 ,
113- 0x0006 , 0x000c , 0x0000 , 0x00c8 , 0x0004 , 0x0006 ) != 0 ) {
114+ 0x001c , 0x0020 , 0x0000 , 1000 , 0x0004 , 0x0006 ) != 0 ) {
114115 return false ;
115116 }
116117
@@ -503,19 +504,78 @@ bool ATTClass::disconnect()
503504 return (numDisconnects > 0 );
504505}
505506
506- BLEDevice ATTClass::central ()
507+ BLEDevice ATTClass::central ()
507508{
509+ return central (0 );
510+ }
511+
512+ BLEDevice ATTClass::central (int index)
513+ {
514+ int currentIndex = 0 ;
508515 for (int i = 0 ; i < ATT_MAX_PEERS; i++) {
509516 if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x01 ) {
510517 continue ;
511518 }
512519
513- return BLEDevice (_peers[i].addressType , _peers[i].address );
520+ if (currentIndex == index) {
521+ return BLEDevice (_peers[i].addressType , _peers[i].address );
522+ }
523+ currentIndex++;
514524 }
515525
516526 return BLEDevice ();
517527}
518528
529+ int ATTClass::centralCount ()
530+ {
531+ int count = 0 ;
532+ for (int i = 0 ; i < ATT_MAX_PEERS; i++) {
533+ if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x01 ) {
534+ continue ;
535+ }
536+
537+ count++;
538+ }
539+
540+ return count;
541+ }
542+
543+ BLEDevice ATTClass::peripheral ()
544+ {
545+ return peripheral (0 );
546+ }
547+
548+ BLEDevice ATTClass::peripheral (int index)
549+ {
550+ int currentIndex = 0 ;
551+ for (int i = 0 ; i < ATT_MAX_PEERS; i++) {
552+ if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x00 ) {
553+ continue ;
554+ }
555+
556+ if (currentIndex == index) {
557+ return BLEDevice (_peers[i].addressType , _peers[i].address );
558+ }
559+ currentIndex++;
560+ }
561+
562+ return BLEDevice ();
563+ }
564+
565+ int ATTClass::peripheralCount ()
566+ {
567+ int count = 0 ;
568+ for (int i = 0 ; i < ATT_MAX_PEERS; i++) {
569+ if (_peers[i].connectionHandle == 0xffff || _peers[i].role != 0x00 ) {
570+ continue ;
571+ }
572+
573+ count++;
574+ }
575+
576+ return count;
577+ }
578+
519579bool ATTClass::handleNotify (uint16_t handle, const uint8_t * value, int length)
520580{
521581 int numNotifications = 0 ;
0 commit comments