ble.py - added guessing subroutine for ble adapter
This commit is contained in:
1 parent
080efd9ddc
commit
63b2f85eb3
1 file changed
+26
-3
+26
-3
@@ -337,11 +337,33 @@ def test(test_count = 0, bt_usb_id = None) -> None:
|
||||
test_list = mac_list_new
|
||||
log.warning(f" Re-do list - {test_list}")
|
||||
|
||||
def usb_id_guess():
|
||||
log.warning("USB ID Not found, I'll try and guess...")
|
||||
result = ''
|
||||
guess_command = "lsusb | grep -i blue | awk '{print $6'}"
|
||||
try:
|
||||
# Run the command in a shell because of the pipe
|
||||
output = subprocess.run(
|
||||
guess_command,
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=True,
|
||||
).stdout.strip()
|
||||
result = output
|
||||
log.info(f"USB Best guess - {result}")
|
||||
except subprocess.CalledProcessError as exc:
|
||||
log.error(f"USB-ID guess failed: {exc}")
|
||||
|
||||
return result
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# If run as a script, execute the legacy test
|
||||
# Since I intend to run this service for months at a time,
|
||||
# I need to do some robust long term tests on the driver
|
||||
# --------------------------------------------------------------------------- #
|
||||
if __name__ == "__main__":
|
||||
# if running a test, make a log file in temp
|
||||
import json
|
||||
from datetime import datetime
|
||||
logfile_path = f"/tmp/ble-test-{datetime.now().strftime('%y%m%d-%H%M%S')}.log"
|
||||
@@ -350,13 +372,12 @@ if __name__ == "__main__":
|
||||
_file_handler.setFormatter(_stdout_handler.formatter) # reuse formatter
|
||||
_logger.addHandler(_file_handler)
|
||||
log.info(f"Logfile initialized at {logfile_path}")
|
||||
# 1. Grab the argument (string)
|
||||
# Make sure the test count is passed
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python3 test.py <count>")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
count = int(sys.argv[1]) # convert to integer
|
||||
count = int(sys.argv[1])
|
||||
except ValueError:
|
||||
print("The count must be an integer.")
|
||||
sys.exit(1)
|
||||
@@ -378,6 +399,8 @@ if __name__ == "__main__":
|
||||
for usb_id in present_usb_id_output:
|
||||
if usb_id in bt_usb_ids:
|
||||
current_usb_id = usb_id
|
||||
if len(current_usb_id) == 0:
|
||||
current_usb_id = usb_id_guess()
|
||||
log.info(f"BLE USB ID Detected: {current_usb_id} - Resetting")
|
||||
reset_adapter()
|
||||
test_count = 0
|
||||
|
||||
Reference in new issue
Block a user