• 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('Usage: controllers.py <hci-transport-1> <hci-transport-2> [<hci-transport-3> ...]')
32        print('example: python controllers.py pty:ble1 pty:ble2')
33        return
34
35    # Create a loccal link to attach the controllers to
36    link = LocalLink()
37
38    # Create a transport and controller for all requested names
39    transports = []
40    controllers = []
41    for index, transport_name in enumerate(sys.argv[1:]):
42        transport = await open_transport_or_link(transport_name)
43        transports.append(transport)
44        controller = Controller(f'C{index}', host_source = transport.source, host_sink = transport.sink, link = link)
45        controllers.append(controller)
46
47    # Wait until the user interrupts
48    await asyncio.get_running_loop().create_future()
49
50    # Cleanup
51    for transport in transports:
52        transport.close()
53
54
55# -----------------------------------------------------------------------------
56def main():
57    logging.basicConfig(level = os.environ.get('BUMBLE_LOGLEVEL', 'INFO').upper())
58    asyncio.run(async_main())
59
60
61# -----------------------------------------------------------------------------
62if __name__ == '__main__':
63    main()
64