Skip to contentSkip to conversation

test-ussd: USSD request is optional to monitor SS interface

PATCH In review Philippe Nunes 2 participants 2 messages Jun 24, 2012 – Jun 27, 2012

lore
Share & tools
lore
#1 lore raw
In reply to Philippe Nunes

Hi Philippe,

Quoted 62 lines · Philippe Nunes
---
  test/test-ussd |   60 ++++++++++++++++++++++++++++++++++++++------------------
  1 file changed, 41 insertions(+), 19 deletions(-)
test/test-ussd +29 -4
index c21f5e3..c8099b0 100755
@@ -9,12 +9,28 @@ import dbus.mainloop.glib
 
  state = None
 
+def clear_screen(numlines=100):
+	import os
+	if os.name == "posix":
+		os.system('clear')
+
+	elif os.name in ("nt", "dos", "ce"):
+		os.system('CLS')
+
+	else:
+		print '\n' * numlines
+
+def print_menu():
+	if state == "user-response":
+		print "Enter response (c for cancel - x for exit):"
+	elif state == "idle":
+		print "Enter USSD request (x for exit):"
+
  def ussd_notification_received(content):
  	print("Network sent a Notification: " + content)
 
  def ussd_request_received(content):
  	print("Network sent a Request: " + content)
-	ss.Cancel()
 
  def ussd_property_changed(name, value):
  	global state
@@ -23,23 +39,27 @@ def ussd_property_changed(name, value):
  	print("USSD session state is " + value)
  	state = str(value)
 
+	print_menu()
+
  def stdin_handler(fd, condition):
-	s = os.read(fd.fileno(), 160).rstrip()
-	if not s:
-		ss.Cancel()
+	s = os.read(fd.fileno(), 182).rstrip()
+
+	if s == 'c':
+		if state == "user-response" or state == 'active':
+			clear_screen
+			ss.Cancel()
+	elif s == 'x':
+		sys.exit(1)
  	elif state == "user-response":
+		clear_screen()
  		print ss.Respond(s, timeout = 100)
  	elif state == "idle":
+		clear_screen()
  		print ss.Initiate(s, timeout = 100)

test/test-ussd def ussd_property_changed(name, value): · line 42

Quoted 10 lines
test/test-ussd +1 -6
-	else:
-		print "Invalid state", state
+
  	return True
 
  if __name__ == "__main__":
-	if (len(sys.argv)<  2):
-		print "Usage: %s [modem]<ussd-string>" % (sys.argv[0])
-		sys.exit(1)
-

Why are you removing this? The script should still be printing a basic usage help script even if you are adding new semantics to it.

Quoted 26 lines
test/test-ussd +1 -9
  	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
  	bus = dbus.SystemBus()
@@ -50,24 +70,26 @@ if __name__ == "__main__":
  	modems = manager.GetModems()
  	modem = modems[0][0]
 
-	if (len(sys.argv) == 2):
-		ussd = sys.argv[1]
-	else:
+	if (len(sys.argv) == 3):
  		modem = sys.argv[1]
-		ussd = sys.argv[2]
 
  	ss = dbus.Interface(bus.get_object('org.ofono', modem),
  					'org.ofono.SupplementaryServices')
 
-	props = ss.GetProperties()
-	for p in props:
-		ussd_property_changed(p, props[p])
-
  	ss.connect_to_signal("NotificationReceived", ussd_notification_received)
  	ss.connect_to_signal("RequestReceived", ussd_request_received)
  	ss.connect_to_signal("PropertyChanged", ussd_property_changed)
 
-	print ss.Initiate(ussd, timeout=100)

test/test-ussd if __name__ == "__main__": · line 92

Quoted 10 lines
test/test-ussd +10 -0
+	if (len(sys.argv)>  1):
+		if (len(sys.argv) == 2):
+			ussd = sys.argv[1]
+		elif (len(sys.argv) == 3):
+			ussd = sys.argv[2]
+		print ss.Initiate(ussd, timeout=100)
+	else:
+		props = ss.GetProperties()
+		for p in props:
+			ussd_property_changed(p, props[p])

What exactly are you getting out of the else clause that isn't already handled by list-modems and monitor-ofono scripts?

test/test-ussd if __name__ == "__main__": · line 95

Quoted 3 lines
test/test-ussd +0 -0
  	gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler)
 

Regards,
-Denis

#0 lore raw

PATCH 1/1 test-ussd: USSD request is optional to monitor SS interface

---
 test/test-ussd |   60 ++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 19 deletions(-)
test/test-ussd +41 -19
index c21f5e3..c8099b0 100755
@@ -9,12 +9,28 @@ import dbus.mainloop.glib
 
 state = None
 
+def clear_screen(numlines=100):
+	import os
+	if os.name == "posix":
+		os.system('clear')
+
+	elif os.name in ("nt", "dos", "ce"):
+		os.system('CLS')
+
+	else:
+		print '\n' * numlines
+
+def print_menu():
+	if state == "user-response":
+		print "Enter response (c for cancel - x for exit):"
+	elif state == "idle":
+		print "Enter USSD request (x for exit):"
+
 def ussd_notification_received(content):
 	print("Network sent a Notification: " + content)
 
 def ussd_request_received(content):
 	print("Network sent a Request: " + content)
-	ss.Cancel()
 
 def ussd_property_changed(name, value):
 	global state
@@ -23,23 +39,27 @@ def ussd_property_changed(name, value):
 	print("USSD session state is " + value)
 	state = str(value)
 
+	print_menu()
+
 def stdin_handler(fd, condition):
-	s = os.read(fd.fileno(), 160).rstrip()
-	if not s:
-		ss.Cancel()
+	s = os.read(fd.fileno(), 182).rstrip()
+
+	if s == 'c':
+		if state == "user-response" or state == 'active':
+			clear_screen
+			ss.Cancel()
+	elif s == 'x':
+		sys.exit(1)
 	elif state == "user-response":
+		clear_screen()
 		print ss.Respond(s, timeout = 100)
 	elif state == "idle":
+		clear_screen()
 		print ss.Initiate(s, timeout = 100)
-	else:
-		print "Invalid state", state
+
 	return True
 
 if __name__ == "__main__":
-	if (len(sys.argv) < 2):
-		print "Usage: %s [modem] <ussd-string>" % (sys.argv[0])
-		sys.exit(1)
-
 	dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
 	bus = dbus.SystemBus()
@@ -50,24 +70,26 @@ if __name__ == "__main__":
 	modems = manager.GetModems()
 	modem = modems[0][0]
 
-	if (len(sys.argv) == 2):
-		ussd = sys.argv[1]
-	else:
+	if (len(sys.argv) == 3):
 		modem = sys.argv[1]
-		ussd = sys.argv[2]
 
 	ss = dbus.Interface(bus.get_object('org.ofono', modem),
 					'org.ofono.SupplementaryServices')
 
-	props = ss.GetProperties()
-	for p in props:
-		ussd_property_changed(p, props[p])
-
 	ss.connect_to_signal("NotificationReceived", ussd_notification_received)
 	ss.connect_to_signal("RequestReceived", ussd_request_received)
 	ss.connect_to_signal("PropertyChanged", ussd_property_changed)
 
-	print ss.Initiate(ussd, timeout=100)
+	if (len(sys.argv) > 1):
+		if (len(sys.argv) == 2):
+			ussd = sys.argv[1]
+		elif (len(sys.argv) == 3):
+			ussd = sys.argv[2]
+		print ss.Initiate(ussd, timeout=100)
+	else:
+		props = ss.GetProperties()
+		for p in props:
+			ussd_property_changed(p, props[p])
 
 	gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler)
 
Signature · 1 line
1.7.9.5