mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-17 01:04:40 +08:00
Update string type handling
This commit is contained in:
parent
ab3715031f
commit
b72732982d
@ -4,50 +4,49 @@ import dbus
|
||||
|
||||
bus = dbus.SystemBus()
|
||||
|
||||
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
|
||||
"org.bluez.Manager")
|
||||
|
||||
def extract_uuids(uuid_list):
|
||||
list = ''
|
||||
list = ""
|
||||
for uuid in uuid_list:
|
||||
if (uuid.endswith('-0000-1000-8000-00805f9b34fb')):
|
||||
if (uuid.startswith('0000')):
|
||||
val = '0x' + uuid[4:8]
|
||||
if (uuid.endswith("-0000-1000-8000-00805f9b34fb")):
|
||||
if (uuid.startswith("0000")):
|
||||
val = "0x" + uuid[4:8]
|
||||
else:
|
||||
val = '0x' + uuid[0:8]
|
||||
val = "0x" + uuid[0:8]
|
||||
else:
|
||||
val = str(uuid)
|
||||
list = list + val + ' '
|
||||
list = list + val + " "
|
||||
return list
|
||||
|
||||
|
||||
manager = dbus.Interface(bus.get_object('org.bluez', '/'), 'org.bluez.Manager')
|
||||
|
||||
adapter_list = manager.ListAdapters()
|
||||
|
||||
for i in adapter_list:
|
||||
adapter = dbus.Interface(bus.get_object('org.bluez', i),
|
||||
'org.bluez.Adapter')
|
||||
print '[ ' + i + ' ]'
|
||||
adapter = dbus.Interface(bus.get_object("org.bluez", i),
|
||||
"org.bluez.Adapter")
|
||||
print "[ " + i + " ]"
|
||||
|
||||
properties = adapter.GetProperties()
|
||||
for key in properties.keys():
|
||||
print ' %s = %s' % (key, properties[key])
|
||||
print " %s = %s" % (key, properties[key])
|
||||
|
||||
device_list = adapter.ListDevices()
|
||||
|
||||
for n in device_list:
|
||||
device = dbus.Interface(bus.get_object('org.bluez', n),
|
||||
'org.bluez.Device')
|
||||
print ' [ ' + n + ' ]'
|
||||
device = dbus.Interface(bus.get_object("org.bluez", n),
|
||||
"org.bluez.Device")
|
||||
print " [ " + n + " ]"
|
||||
|
||||
properties = device.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = properties[key]
|
||||
if (key == 'UUID' or key == 'UUIDs'):
|
||||
if (key == "UUIDs"):
|
||||
list = extract_uuids(value)
|
||||
print ' %s = %s' % (key, list)
|
||||
print " %s = %s" % (key, list)
|
||||
elif (key == "Class"):
|
||||
print ' %s = 0x%06x' % (key, value)
|
||||
print " %s = 0x%06x" % (key, value)
|
||||
else:
|
||||
print ' %s = %s' % (key, value)
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
print
|
||||
|
@ -8,47 +8,48 @@ import dbus.mainloop.glib
|
||||
|
||||
class Agent(dbus.service.Object):
|
||||
@dbus.service.method("org.bluez.Agent",
|
||||
in_signature='', out_signature='')
|
||||
in_signature="", out_signature="")
|
||||
def Release(self):
|
||||
print 'Release'
|
||||
print "Release"
|
||||
mainloop.quit()
|
||||
|
||||
@dbus.service.method("org.bluez.Agent",
|
||||
in_signature='o', out_signature='s')
|
||||
in_signature="o", out_signature="s")
|
||||
def RequestPasskey(self, device):
|
||||
print 'RequestPasskey (' + device + ')'
|
||||
return '1234'
|
||||
print "RequestPasskey (" + device + ")"
|
||||
return "1234"
|
||||
|
||||
@dbus.service.method("org.bluez.Agent",
|
||||
in_signature='s', out_signature='')
|
||||
in_signature="s", out_signature="")
|
||||
def ConfirmModeChange(self, mode):
|
||||
print 'ConfirmModeChange (' + mode + ')'
|
||||
print "ConfirmModeChange (" + mode + ")"
|
||||
return
|
||||
|
||||
@dbus.service.method("org.bluez.Agent",
|
||||
in_signature='', out_signature='')
|
||||
in_signature="", out_signature="")
|
||||
def Cancel(self):
|
||||
print 'Cancel'
|
||||
print "Cancel"
|
||||
return
|
||||
|
||||
if __name__ == '__main__':
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
|
||||
bus = dbus.SystemBus()
|
||||
manager = dbus.Interface(bus.get_object('org.bluez', '/'),
|
||||
'org.bluez.Manager')
|
||||
path = manager.DefaultAdapter()
|
||||
adapter = dbus.Interface(bus.get_object('org.bluez', path),
|
||||
'org.bluez.Adapter')
|
||||
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
|
||||
"org.bluez.Manager")
|
||||
|
||||
path = '/test/agent'
|
||||
path = manager.DefaultAdapter()
|
||||
adapter = dbus.Interface(bus.get_object("org.bluez", path),
|
||||
"org.bluez.Adapter")
|
||||
|
||||
path = "/test/agent"
|
||||
object = Agent(bus, path)
|
||||
|
||||
adapter.RegisterAgent(path)
|
||||
print 'Agent registered'
|
||||
print "Agent registered"
|
||||
|
||||
mainloop = gobject.MainLoop()
|
||||
mainloop.run()
|
||||
|
||||
#adapter.UnregisterAgent(path)
|
||||
#print 'Agent unregistered'
|
||||
#print "Agent unregistered"
|
||||
|
@ -6,14 +6,14 @@ import dbus
|
||||
import dbus.mainloop.glib
|
||||
|
||||
def device_found(address, properties):
|
||||
print '[ ' + address + ' ]'
|
||||
print "[ " + address + " ]"
|
||||
|
||||
for key in properties.keys():
|
||||
value = properties[key]
|
||||
if (key == "Class"):
|
||||
print ' %s = 0x%06x' % (key, value)
|
||||
print " %s = 0x%06x" % (key, value)
|
||||
else:
|
||||
print ' %s = %s' % (key, value)
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
def discovery_completed():
|
||||
mainloop.quit()
|
||||
@ -22,19 +22,20 @@ if __name__ == '__main__':
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
|
||||
bus = dbus.SystemBus()
|
||||
manager = dbus.Interface(bus.get_object('org.bluez', '/'),
|
||||
'org.bluez.Manager')
|
||||
manager = dbus.Interface(bus.get_object("org.bluez", "/"),
|
||||
"org.bluez.Manager")
|
||||
|
||||
path = manager.DefaultAdapter()
|
||||
adapter = dbus.Interface(bus.get_object('org.bluez', path),
|
||||
'org.bluez.Adapter')
|
||||
adapter = dbus.Interface(bus.get_object("org.bluez", path),
|
||||
"org.bluez.Adapter")
|
||||
|
||||
bus.add_signal_receiver(device_found,
|
||||
dbus_interface = 'org.bluez.Adapter',
|
||||
signal_name = 'DeviceFound')
|
||||
dbus_interface = "org.bluez.Adapter",
|
||||
signal_name = "DeviceFound")
|
||||
|
||||
bus.add_signal_receiver(discovery_completed,
|
||||
dbus_interface = 'org.bluez.Adapter',
|
||||
signal_name = 'DiscoveryCompleted')
|
||||
dbus_interface = "org.bluez.Adapter",
|
||||
signal_name = "DiscoveryCompleted")
|
||||
|
||||
adapter.DiscoverDevices()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user