Home | History | Annotate | Download | only in test
      1 #!/usr/bin/python
      2 # -*- coding: utf-8 -*-
      3 
      4 import dbus
      5 import dbus.service
      6 import gobject
      7 from dbus.mainloop.glib import DBusGMainLoop
      8 import sys
      9 
     10 DBusGMainLoop(set_as_default=True)
     11 loop = gobject.MainLoop()
     12 
     13 bus = dbus.SystemBus()
     14 
     15 hdp_manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
     16 						"org.bluez.HealthManager")
     17 app_path = hdp_manager.CreateApplication({"DataType": dbus.types.UInt16(4103),
     18 					"Role": "sink"})
     19 
     20 print app_path
     21 
     22 manager = dbus.Interface(bus.get_object("org.bluez", "/"),
     23 						"org.bluez.Manager")
     24 
     25 adapters = manager.ListAdapters()
     26 
     27 i = 1
     28 for ad in adapters:
     29 	print "%d. %s" % (i, ad)
     30 	i = i + 1
     31 
     32 print "Select an adapter: ",
     33 select = None
     34 while select == None:
     35 	try:
     36 		pos = int(sys.stdin.readline()) - 1
     37 		if pos < 0:
     38 			raise TypeError
     39 		select = adapters[pos]
     40 	except (TypeError, IndexError, ValueError):
     41 		print "Wrong selection, try again: ",
     42 	except KeyboardInterrupt:
     43 		sys.exit()
     44 
     45 adapter =  dbus.Interface(bus.get_object("org.bluez", select),
     46 						"org.bluez.Adapter")
     47 
     48 devices = adapter.ListDevices()
     49 
     50 if len(devices) == 0:
     51 	print "No devices available"
     52 	sys.exit()
     53 
     54 i = 1
     55 for dev in devices:
     56 	print "%d. %s" % (i, dev)
     57 	i = i + 1
     58 
     59 print "Select a device: ",
     60 select = None
     61 while select == None:
     62 	try:
     63 		pos = int(sys.stdin.readline()) - 1
     64 		if pos < 0:
     65 			raise TypeError
     66 		select = devices[pos]
     67 	except (TypeError, IndexError, ValueError):
     68 		print "Wrong selection, try again: ",
     69 	except KeyboardInterrupt:
     70 		sys.exit()
     71 
     72 print "Connecting to %s" % (select)
     73 device = dbus.Interface(bus.get_object("org.bluez", select),
     74 					"org.bluez.HealthDevice")
     75 
     76 chan = device.CreateChannel(app_path, "Any")
     77 
     78 print chan
     79 
     80 print "Push Enter for finishing"
     81 sys.stdin.readline()
     82 
     83 hdp_manager.DestroyApplication(app_path)
     84