| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from __future__ import absolute_import, print_function, unicode_literals |
| 5 |
|
| 6 |
import dbus |
| 7 |
|
| 8 |
bus = dbus.SystemBus() |
| 9 |
|
| 10 |
manager = dbus.Interface(bus.get_object("org.bluez", "/"), |
| 11 |
"org.freedesktop.DBus.ObjectManager") |
| 12 |
|
| 13 |
def extract_objects(object_list): |
| 14 |
list = "" |
| 15 |
for object in object_list: |
| 16 |
val = str(object) |
| 17 |
list = list + val[val.rfind("/") + 1:] + " " |
| 18 |
return list |
| 19 |
|
| 20 |
def extract_uuids(uuid_list): |
| 21 |
list = "" |
| 22 |
for uuid in uuid_list: |
| 23 |
if (uuid.endswith("-0000-1000-8000-00805f9b34fb")): |
| 24 |
if (uuid.startswith("0000")): |
| 25 |
val = "0x" + uuid[4:8] |
| 26 |
else: |
| 27 |
val = "0x" + uuid[0:8] |
| 28 |
else: |
| 29 |
val = str(uuid) |
| 30 |
list = list + val + " " |
| 31 |
return list |
| 32 |
|
| 33 |
objects = manager.GetManagedObjects() |
| 34 |
|
| 35 |
all_devices = (str(path) for path, interfaces in objects.items() if |
| 36 |
"org.bluez.Device1" in interfaces.keys()) |
| 37 |
|
| 38 |
for path, interfaces in objects.items(): |
| 39 |
if "org.bluez.Adapter1" not in interfaces.keys(): |
| 40 |
continue |
| 41 |
|
| 42 |
print("[ " + path + " ]") |
| 43 |
|
| 44 |
properties = interfaces["org.bluez.Adapter1"] |
| 45 |
for key in properties.keys(): |
| 46 |
value = properties[key] |
| 47 |
if (key == "UUIDs"): |
| 48 |
list = extract_uuids(value) |
| 49 |
print(" %s = %s" % (key, list)) |
| 50 |
else: |
| 51 |
print(" %s = %s" % (key, value)) |
| 52 |
|
| 53 |
device_list = [d for d in all_devices if d.startswith(path + "/")] |
| 54 |
|
| 55 |
for dev_path in device_list: |
| 56 |
print(" [ " + dev_path + " ]") |
| 57 |
|
| 58 |
dev = objects[dev_path] |
| 59 |
properties = dev["org.bluez.Device1"] |
| 60 |
|
| 61 |
for key in properties.keys(): |
| 62 |
value = properties[key] |
| 63 |
if (key == "UUIDs"): |
| 64 |
list = extract_uuids(value) |
| 65 |
print(" %s = %s" % (key, list)) |
| 66 |
elif (key == "Class"): |
| 67 |
print(" %s = 0x%06x" % (key, value)) |
| 68 |
elif (key == "Vendor"): |
| 69 |
print(" %s = 0x%04x" % (key, value)) |
| 70 |
elif (key == "Product"): |
| 71 |
print(" %s = 0x%04x" % (key, value)) |
| 72 |
elif (key == "Version"): |
| 73 |
print(" %s = 0x%04x" % (key, value)) |
| 74 |
else: |
| 75 |
print(" %s = %s" % (key, value)) |
| 76 |
|
| 77 |
print("") |