Skip to content

Commit

Permalink
Update smartrowreader.py
Browse files Browse the repository at this point in the history
  • Loading branch information
TbsJah authored Jun 26, 2024
1 parent e4f1643 commit 31a8167
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/adapters/smartrow/smartrowreader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import gatt
import logging
import subprocess
import threading
from time import time
from time import sleep

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -111,8 +112,12 @@ def device_discovered(self, device):
self.discovered=True


def connecttosmartrow():
manager = SmartRowManager(adapter_name='hci0')
def connecttosmartrow(passthru = False):
if not passthru:
manager = SmartRowManager(adapter_name='hci0')
else:
manager = SmartRowManager(adapter_name=get_sr_preferred_adapter())

logger.info("starting discovery")
manager.start_discovery() # from the DeviceManager class call the methode start_discorvery
manager.run()
Expand All @@ -122,10 +127,27 @@ def connecttosmartrow():
macaddresssmartrower = manager.smartrowmac
return macaddresssmartrower

# Find the built-in Bluetooth adapter. It has a Bus type of UART.
def get_sr_preferred_adapter():
hci_info = subprocess.run(['hciconfig', 'hci0'], stdout=subprocess.PIPE).stdout.decode('utf-8')
if 'UART' in hci_info:
logger.info('Preferred SmartRow adapter is hci0')
return 'hci0'

hci_info = subprocess.run(['hciconfig', 'hci1'], stdout=subprocess.PIPE).stdout.decode('utf-8')
if 'UART' in hci_info:
logger.info('Preferred SmartRow adapter is hci1')
return 'hci1'

hci_info = subprocess.run(['hciconfig', 'hci2'], stdout=subprocess.PIPE).stdout.decode('utf-8')
if 'UART' in hci_info:
logger.info('Preferred SmartRow adapter is hci2')
return 'hci2'


if __name__ == '__main__':

manager = gatt.DeviceManager(adapter_name='hci1')
manager = gatt.DeviceManager(adapter_name='hci0')
device = SmartRow(mac_address="", manager=manager)
device.connect()

Expand Down

0 comments on commit 31a8167

Please sign in to comment.