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