Skip to content

Commit 00ed035

Browse files
committed
wip (+7 squashed commits)
1 parent c12dee4 commit 00ed035

7 files changed

Lines changed: 745 additions & 108 deletions

File tree

apps/controller_info.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
from bumble.colors import color
2525
from bumble.core import name_or_number
2626
from bumble.hci import (
27+
HCI_READ_LOCAL_EXTENDED_FEATURES_COMMAND,
28+
HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND,
29+
HCI_Read_Local_Extended_Features_Command,
30+
HCI_Read_Local_Supported_Features_Command,
2731
map_null_terminated_utf8_string,
2832
HCI_SUCCESS,
2933
HCI_LE_SUPPORTED_FEATURES_NAMES,
@@ -56,6 +60,36 @@ def command_succeeded(response):
5660
return False
5761

5862

63+
# -----------------------------------------------------------------------------
64+
async def get_common_info(host):
65+
if host.supports_command(HCI_READ_LOCAL_SUPPORTED_FEATURES_COMMAND):
66+
response = await host.send_command(HCI_Read_Local_Supported_Features_Command())
67+
if response.return_parameters.status == HCI_SUCCESS:
68+
print()
69+
print(color('LMP Features:', 'yellow'))
70+
# TODO: support printing discrete enum values
71+
print(' ', response.return_parameters.lmp_features.hex())
72+
73+
if host.supports_command(HCI_READ_LOCAL_EXTENDED_FEATURES_COMMAND):
74+
response = await host.send_command(
75+
HCI_Read_Local_Extended_Features_Command(page_number=0)
76+
)
77+
if response.return_parameters.status == HCI_SUCCESS:
78+
if response.return_parameters.max_page_number > 0:
79+
print()
80+
print(color('Extended LMP Features:', 'yellow'))
81+
82+
for page in range(1, response.return_parameters.max_page_number + 1):
83+
response = await host.send_command(
84+
HCI_Read_Local_Extended_Features_Command(page_number=page)
85+
)
86+
87+
if response.return_parameters.status == HCI_SUCCESS:
88+
# TODO: support printing discrete enum values
89+
print(f' Page {page}:')
90+
print(' ', response.return_parameters.extended_lmp_features.hex())
91+
92+
5993
# -----------------------------------------------------------------------------
6094
async def get_classic_info(host):
6195
if host.supports_command(HCI_READ_BD_ADDR_COMMAND):
@@ -147,6 +181,9 @@ async def async_main(transport):
147181
)
148182
print(color(' LMP Subversion:', 'green'), host.local_version.lmp_subversion)
149183

184+
# Get the common info
185+
await get_common_info(host)
186+
150187
# Get the Classic info
151188
await get_classic_info(host)
152189

apps/controllers.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,33 @@
1717
# -----------------------------------------------------------------------------
1818
import logging
1919
import asyncio
20-
import sys
2120
import os
2221

23-
from bumble.controller import Controller
22+
import click
23+
24+
from bumble.controller import Controller, Options
2425
from bumble.link import LocalLink
2526
from bumble.transport import open_transport_or_link
2627

2728

2829
# -----------------------------------------------------------------------------
29-
async def async_main():
30-
if len(sys.argv) != 3:
31-
print(
32-
'Usage: controllers.py <hci-transport-1> <hci-transport-2> '
33-
'[<hci-transport-3> ...]'
34-
)
35-
print('example: python controllers.py pty:ble1 pty:ble2')
36-
return
37-
30+
async def async_main(extended_advertising, transport_names):
3831
# Create a local link to attach the controllers to
3932
link = LocalLink()
4033

4134
# Create a transport and controller for all requested names
4235
transports = []
4336
controllers = []
44-
for index, transport_name in enumerate(sys.argv[1:]):
37+
options = Options(extended_advertising=extended_advertising)
38+
for index, transport_name in enumerate(transport_names):
4539
transport = await open_transport_or_link(transport_name)
4640
transports.append(transport)
4741
controller = Controller(
4842
f'C{index}',
4943
host_source=transport.source,
5044
host_sink=transport.sink,
5145
link=link,
46+
options=options,
5247
)
5348
controllers.append(controller)
5449

@@ -61,9 +56,14 @@ async def async_main():
6156

6257

6358
# -----------------------------------------------------------------------------
64-
def main():
65-
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper())
66-
asyncio.run(async_main())
59+
@click.command()
60+
@click.option(
61+
'--extended-advertising', is_flag=True, help="Enable extended advertising"
62+
)
63+
@click.argument('transports', nargs=-1, required=True)
64+
def main(extended_advertising, transports):
65+
logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'WARNING').upper())
66+
asyncio.run(async_main(extended_advertising, transports))
6767

6868

6969
# -----------------------------------------------------------------------------

apps/link_relay/link_relay.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ async def serve(self, websocket, path):
253253

254254

255255
# ----------------------------------------------------------------------------
256-
def main():
256+
async def async_main():
257257
# Check the Python version
258258
if sys.version_info < (3, 6, 1):
259259
print('ERROR: Python 3.6.1 or higher is required')
@@ -280,8 +280,13 @@ def main():
280280

281281
# Start a relay
282282
relay = Relay(args.port)
283-
asyncio.get_event_loop().run_until_complete(relay.start())
284-
asyncio.get_event_loop().run_forever()
283+
async with relay.start():
284+
await asyncio.Future()
285+
286+
287+
# ----------------------------------------------------------------------------
288+
def main():
289+
asyncio.run(async_main())
285290

286291

287292
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)