Skip to content

Commit

Permalink
[python] Add flag to disable BLE for controller (#7179)
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored and pull[bot] committed Jun 11, 2021
1 parent 6a6bb91 commit 3456569
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/controller/python/chip-device-ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import time
import string
import re
import traceback
from cmd import Cmd
from chip.ChipBleUtility import FAKE_CONN_OBJ_VALUE
from chip.setup_payload import SetupPayload
Expand Down Expand Up @@ -151,8 +152,13 @@ def __init__(self, rendezvousAddr=None, controllerNodeId=0, bluetoothAdapter=Non

# If we are on Linux and user selects non-default bluetooth adapter.
if sys.platform.startswith("linux") and (bluetoothAdapter is not None):
self.bleMgr = BleManager(self.devCtrl)
self.bleMgr.ble_adapter_select("hci{}".format(bluetoothAdapter))
try:
self.bleMgr = BleManager(self.devCtrl)
self.bleMgr.ble_adapter_select("hci{}".format(bluetoothAdapter))
except Exception as ex:
traceback.print_exc()
print("Failed to initialize BLE, if you don't have BLE, run chip-device-ctrl with --no-ble")
raise ex

self.historyFileName = os.path.expanduser(
"~/.chip-device-ctrl-history")
Expand Down Expand Up @@ -743,9 +749,15 @@ def main():
dest="bluetoothAdapter",
default="hci0",
type="str",
help="Controller bluetooth adapter ID",
help="Controller bluetooth adapter ID, use --no-ble to disable bluetooth functions.",
metavar="<bluetooth-adapter>",
)
optParser.add_option(
"--no-ble",
action="store_true",
dest="disableBluetooth",
help="Disable bluetooth, calling BLE related feature with this flag results in undefined behavior.",
)
(options, remainingArgs) = optParser.parse_args(sys.argv[1:])

if len(remainingArgs) != 0:
Expand All @@ -754,7 +766,9 @@ def main():

adapterId = None
if sys.platform.startswith("linux"):
if not options.bluetoothAdapter.startswith("hci"):
if options.disableBluetooth:
adapterId = None
elif not options.bluetoothAdapter.startswith("hci"):
print(
"Invalid bluetooth adapter: {}, adapter name looks like hci0, hci1 etc.")
sys.exit(-1)
Expand All @@ -766,8 +780,14 @@ def main():
"Invalid bluetooth adapter: {}, adapter name looks like hci0, hci1 etc.")
sys.exit(-1)

devMgrCmd = DeviceMgrCmd(rendezvousAddr=options.rendezvousAddr,
controllerNodeId=options.controllerNodeId, bluetoothAdapter=adapterId)
try:
devMgrCmd = DeviceMgrCmd(rendezvousAddr=options.rendezvousAddr,
controllerNodeId=options.controllerNodeId, bluetoothAdapter=adapterId)
except Exception as ex:
print(ex)
print("Failed to bringup CHIPDeviceController CLI")
sys.exit(1)

print("Chip Device Controller Shell")
if options.rendezvousAddr:
print("Rendezvous address set to %s" % options.rendezvousAddr)
Expand Down

0 comments on commit 3456569

Please sign in to comment.