Upgrade ofono to 1.11 and merge to 2.0alpha
[profile/ivi/ofono.git] / test / send-ussd
1 #!/usr/bin/python
2
3 import sys
4 import dbus
5
6 if (len(sys.argv) < 2):
7         print "Usage: %s [modem] <ussd-string>" % (sys.argv[0])
8         sys.exit(1)
9
10 bus = dbus.SystemBus()
11
12 manager = dbus.Interface(bus.get_object('org.ofono', '/'),
13                                                 'org.ofono.Manager')
14
15 modems = manager.GetModems()
16
17 if (len(sys.argv) == 2):
18         path = modems[0][0]
19         ussdstring = sys.argv[1]
20 else:
21         path = sys.argv[1]
22         ussdstring = sys.argv[2]
23
24 ussd = dbus.Interface(bus.get_object('org.ofono', path),
25                                         'org.ofono.SupplementaryServices')
26
27 properties = ussd.GetProperties()
28 state = properties["State"]
29
30 print "State: %s" % (state)
31
32 if state == "idle":
33         result = ussd.Initiate(ussdstring, timeout=100)
34         print result[0] + ": " + result[1]
35 elif state == "user-response":
36         print ussd.Respond(ussdstring, timeout=100)
37 else:
38         sys.exit(1);
39
40 properties = ussd.GetProperties()
41 state = properties["State"]
42
43 if state == "idle":
44         sys.exit(0)
45
46 print "State: %s" % (state)
47
48 while state == "user-response":
49         response = raw_input("Enter response: ")
50
51         print ussd.Respond(response, timeout=100)
52
53         properties = ussd.GetProperties()
54         state = properties["State"]
55
56         if state != "idle":
57                 print "State: %s" % (state)