summaryrefslogtreecommitdiffstats
path: root/test/initiate-ussd
blob: 098ec87862585b229631c6207d41bed4025ee992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python

import sys
import dbus

if (len(sys.argv) < 2):
	print "Usage: %s [modem] <ussd-string>" % (sys.argv[0])
	sys.exit(1)

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object('org.ofono', '/'),
						'org.ofono.Manager')

modems = manager.GetModems()

if (len(sys.argv) == 2):
	path = modems[0][0]
	ussdstring = sys.argv[1]
else:
	path = sys.argv[1]
	ussdstring = sys.argv[2]

ussd = dbus.Interface(bus.get_object('org.ofono', path),
					'org.ofono.SupplementaryServices')

properties = ussd.GetProperties()
state = properties["State"]

print "State: %s" % (state)

if state != "idle":
	sys.exit(1);

result = ussd.Initiate(ussdstring, timeout=100)

properties = ussd.GetProperties()
state = properties["State"]

print result[0] + ": " + result[1]

if state == "idle":
	sys.exit(0)

print "State: %s" % (state)

while state == "user-response":
	response = raw_input("Enter response: ")

	result = ussd.Respond(response, timeout=100)

	properties = ussd.GetProperties()
	state = properties["State"]

	print result

	if state != "idle":
		print "State: %s" % (state)