Home | History | Annotate | Download | only in test
      1 #!/usr/bin/python
      2 
      3 import sys
      4 import dbus
      5 from optparse import OptionParser, make_option
      6 
      7 bus = dbus.SystemBus()
      8 
      9 manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
     10 
     11 option_list = [
     12 		make_option("-i", "--device", action="store",
     13 				type="string", dest="dev_id"),
     14 		]
     15 parser = OptionParser(option_list=option_list)
     16 
     17 (options, args) = parser.parse_args()
     18 
     19 if options.dev_id:
     20 	adapter_path = manager.FindAdapter(options.dev_id)
     21 else:
     22 	adapter_path = manager.DefaultAdapter()
     23 
     24 adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
     25 							"org.bluez.Adapter")
     26 
     27 test = dbus.Interface(bus.get_object("org.bluez", "/org/bluez/test"),
     28 			"org.bluez.TelephonyTest")
     29 
     30 if len(args) < 1:
     31 	print """Usage: %s <command>
     32 
     33 	connect <bdaddr>
     34 	disconnect <bdaddr>
     35 	outgoing <number>
     36 	incoming <number>
     37 	cancel
     38 	signal <level>
     39 	battery <level>
     40 	roaming <yes|no>
     41 	registration <status>
     42 	subscriber <number>
     43 	speakergain <bdaddr> [level]
     44 	microphonegain <bdaddr> [level]
     45 	play <bdaddr>
     46 	stop <bdaddr>
     47 	""" % sys.argv[0]
     48 	sys.exit(1)
     49 
     50 if args[0] == "connect":
     51 	if len(args) < 2:
     52 		print "Need device address parameter"
     53 		sys.exit(1)
     54 	device = adapter.FindDevice(args[1])
     55 	headset = dbus.Interface(bus.get_object("org.bluez", device),
     56 					"org.bluez.Headset")
     57 	headset.Connect()
     58 	sys.exit(0)
     59 
     60 if args[0] == "disconnect":
     61 	if len(args) < 2:
     62 		print "Need device address parameter"
     63 		sys.exit(1)
     64 	device = adapter.FindDevice(args[1])
     65 	headset = dbus.Interface(bus.get_object("org.bluez", device),
     66 					"org.bluez.Headset")
     67 	headset.Disconnect()
     68 	sys.exit(0)
     69 
     70 if args[0] == "speakergain":
     71 	if len(args) < 2:
     72 		print "Need device address parameter"
     73 		sys.exit(1)
     74 	device = adapter.FindDevice(args[1])
     75 	headset = dbus.Interface(bus.get_object("org.bluez", device),
     76 					"org.bluez.Headset")
     77 	if len(args) > 2:
     78 		headset.SetProperty('SpeakerGain', dbus.UInt16(args[2]))
     79 	else:
     80 		props = headset.GetProperties()
     81 		print props['SpeakerGain']
     82 
     83 	sys.exit(0)
     84 
     85 if args[0] == "microphonegain":
     86 	if len(args) < 2:
     87 		print "Need device address parameter"
     88 		sys.exit(1)
     89 	device = adapter.FindDevice(args[1])
     90 	headset = dbus.Interface(bus.get_object("org.bluez", device),
     91 					"org.bluez.Headset")
     92 	if len(args) > 2:
     93 		headset.SetProperty('MicrophoneGain', dbus.UInt16(args[2]))
     94 	else:
     95 		props = headset.GetProperties()
     96 		print props['MicrophoneGain']
     97 
     98 	sys.exit(0)
     99 
    100 if args[0] == "play":
    101 	if len(args) < 2:
    102 		print "Need device address parameter"
    103 		sys.exit(1)
    104 	device = adapter.FindDevice(args[1])
    105 	headset = dbus.Interface(bus.get_object("org.bluez", device),
    106 					"org.bluez.Headset")
    107 	headset.Play()
    108 
    109 	sys.exit(0)
    110 
    111 if args[0] == "stop":
    112 	if len(args) < 2:
    113 		print "Need device address parameter"
    114 		sys.exit(1)
    115 	device = adapter.FindDevice(args[1])
    116 	headset = dbus.Interface(bus.get_object("org.bluez", device),
    117 					"org.bluez.Headset")
    118 	headset.Stop()
    119 
    120 	sys.exit(0)
    121 
    122 if args[0] == "outgoing":
    123 	if len(args) > 1:
    124 		test.OutgoingCall(args[1])
    125 	else:
    126 		print "Need number parameter"
    127 	sys.exit(0)
    128 
    129 if args[0] == "incoming":
    130 	if len(args) > 1:
    131 		test.IncomingCall(args[1])
    132 	else:
    133 		print "Need number parameter"
    134 	sys.exit(0)
    135 
    136 if args[0] == "cancel":
    137 	test.CancelCall()
    138 	sys.exit(0)
    139 
    140 if args[0] == "signal":
    141 	if len(args) > 1:
    142 		test.SignalStrength(args[1])
    143 	else:
    144 		print "Need signal strength parameter"
    145 	sys.exit(0)
    146 
    147 if args[0] == "battery":
    148 	if len(args) > 1:
    149 		test.BatteryLevel(args[1])
    150 	else:
    151 		print "Need battery level parameter"
    152 	sys.exit(0)
    153 
    154 if args[0] == "roaming":
    155 	if len(args) > 1:
    156 		test.RoamingStatus(args[1] == "yes" or False)
    157 	else:
    158 		print "Need yes/no parameter"
    159 	sys.exit(0)
    160 
    161 if args[0] == "registration":
    162 	if len(args) > 1:
    163 		test.RegistrationStatus(args[1] == "yes" or False)
    164 	else:
    165 		print "Need yes/no parameter"
    166 	sys.exit(0)
    167 
    168 if args[0] == "subscriber":
    169 	if len(args) > 1:
    170 		test.SetSubscriberNumber(args[1])
    171 	else:
    172 		print "Need number parameter"
    173 	sys.exit(0)
    174 
    175 print "Unknown command"
    176 sys.exit(1)
    177