• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021-2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# -----------------------------------------------------------------------------
16# Imports
17# -----------------------------------------------------------------------------
18import logging
19import asyncio
20import sys
21import os
22
23from bumble.controller import Controller
24from bumble.link import LocalLink
25from bumble.transport import open_transport_or_link
26
27
28# -----------------------------------------------------------------------------
29async 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
38    # Create a local link to attach the controllers to
39    link = LocalLink()
40
41    # Create a transport and controller for all requested names
42    transports = []
43    controllers = []
44    for index, transport_name in enumerate(sys.argv[1:]):
45        transport = await open_transport_or_link(transport_name)
46        transports.append(transport)
47        controller = Controller(
48            f'C{index}',
49            host_source=transport.source,
50            host_sink=transport.sink,
51            link=link,
52        )
53        controllers.append(controller)
54
55    # Wait until the user interrupts
56    await asyncio.get_running_loop().create_future()
57
58    # Cleanup
59    for transport in transports:
60        transport.close()
61
62
63# -----------------------------------------------------------------------------
64def main():
65    logging.basicConfig(level=os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper())
66    asyncio.run(async_main())
67
68
69# -----------------------------------------------------------------------------
70if __name__ == '__main__':
71    main()
72