forked from auracaster/bumble_mirror
Merge/rebase
This commit is contained in:
@@ -24,6 +24,10 @@ from bumble.company_ids import COMPANY_IDENTIFIERS
|
||||
from bumble.colors import color
|
||||
from bumble.core import name_or_number
|
||||
from bumble.hci import (
|
||||
HCI_READ_LOCAL_EXTENDED_FEATURES_COMMAND,
|
||||
HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND,
|
||||
HCI_Read_Local_Extended_Features_Command,
|
||||
HCI_Read_Local_Supported_Features_Command,
|
||||
map_null_terminated_utf8_string,
|
||||
HCI_SUCCESS,
|
||||
HCI_LE_SUPPORTED_FEATURES_NAMES,
|
||||
@@ -58,6 +62,36 @@ def command_succeeded(response):
|
||||
return False
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
async def get_common_info(host):
|
||||
if host.supports_command(HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND):
|
||||
response = await host.send_command(HCI_Read_Local_Supported_Features_Command())
|
||||
if response.return_parameters.status == HCI_SUCCESS:
|
||||
print()
|
||||
print(color('LMP Features:', 'yellow'))
|
||||
# TODO: support printing discrete enum values
|
||||
print(' ', response.return_parameters.lmp_features.hex())
|
||||
|
||||
if host.supports_command(HCI_READ_LOCAL_EXTENDED_FEATURES_COMMAND):
|
||||
response = await host.send_command(
|
||||
HCI_Read_Local_Extended_Features_Command(page_number=0)
|
||||
)
|
||||
if response.return_parameters.status == HCI_SUCCESS:
|
||||
if response.return_parameters.max_page_number > 0:
|
||||
print()
|
||||
print(color('Extended LMP Features:', 'yellow'))
|
||||
|
||||
for page in range(1, response.return_parameters.max_page_number + 1):
|
||||
response = await host.send_command(
|
||||
HCI_Read_Local_Extended_Features_Command(page_number=page)
|
||||
)
|
||||
|
||||
if response.return_parameters.status == HCI_SUCCESS:
|
||||
# TODO: support printing discrete enum values
|
||||
print(f' Page {page}:')
|
||||
print(' ', response.return_parameters.extended_lmp_features.hex())
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
async def get_classic_info(host):
|
||||
if host.supports_command(HCI_READ_BD_ADDR_COMMAND):
|
||||
@@ -162,6 +196,9 @@ async def async_main(transport):
|
||||
)
|
||||
print(color(' LMP Subversion:', 'green'), host.local_version.lmp_subversion)
|
||||
|
||||
# Get the common info
|
||||
await get_common_info(host)
|
||||
|
||||
# Get the Classic info
|
||||
await get_classic_info(host)
|
||||
|
||||
|
||||
@@ -17,31 +17,25 @@
|
||||
# -----------------------------------------------------------------------------
|
||||
import logging
|
||||
import asyncio
|
||||
import sys
|
||||
import os
|
||||
|
||||
from bumble.controller import Controller
|
||||
import click
|
||||
|
||||
from bumble.controller import Controller, Options
|
||||
from bumble.link import LocalLink
|
||||
from bumble.transport import open_transport_or_link
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
async def async_main():
|
||||
if len(sys.argv) != 3:
|
||||
print(
|
||||
'Usage: controllers.py <hci-transport-1> <hci-transport-2> '
|
||||
'[<hci-transport-3> ...]'
|
||||
)
|
||||
print('example: python controllers.py pty:ble1 pty:ble2')
|
||||
return
|
||||
|
||||
async def async_main(extended_advertising, transport_names):
|
||||
# Create a local link to attach the controllers to
|
||||
link = LocalLink()
|
||||
|
||||
# Create a transport and controller for all requested names
|
||||
transports = []
|
||||
controllers = []
|
||||
for index, transport_name in enumerate(sys.argv[1:]):
|
||||
options = Options(extended_advertising=extended_advertising)
|
||||
for index, transport_name in enumerate(transport_names):
|
||||
transport = await open_transport_or_link(transport_name)
|
||||
transports.append(transport)
|
||||
controller = Controller(
|
||||
@@ -49,6 +43,7 @@ async def async_main():
|
||||
host_source=transport.source,
|
||||
host_sink=transport.sink,
|
||||
link=link,
|
||||
options=options,
|
||||
)
|
||||
controllers.append(controller)
|
||||
|
||||
@@ -61,9 +56,14 @@ async def async_main():
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
def main():
|
||||
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper())
|
||||
asyncio.run(async_main())
|
||||
@click.command()
|
||||
@click.option(
|
||||
'--extended-advertising', is_flag=True, help="Enable extended advertising"
|
||||
)
|
||||
@click.argument('transports', nargs=-1, required=True)
|
||||
def main(extended_advertising, transports):
|
||||
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper())
|
||||
asyncio.run(async_main(extended_advertising, transports))
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
@@ -253,7 +253,7 @@ class Relay:
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
def main():
|
||||
async def async_main():
|
||||
# Check the Python version
|
||||
if sys.version_info < (3, 6, 1):
|
||||
print('ERROR: Python 3.6.1 or higher is required')
|
||||
@@ -280,8 +280,13 @@ def main():
|
||||
|
||||
# Start a relay
|
||||
relay = Relay(args.port)
|
||||
asyncio.get_event_loop().run_until_complete(relay.start())
|
||||
asyncio.get_event_loop().run_forever()
|
||||
async with relay.start():
|
||||
await asyncio.Future()
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
def main():
|
||||
asyncio.run(async_main())
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user