test-ussd becomes send-ussd
PATCH 1/2 test-ussd becomes send-ussd
--- test/send-ussd | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test-ussd | 75 -------------------------------------------------------- 2 files changed, 75 insertions(+), 75 deletions(-) create mode 100755 test/send-ussd delete mode 100755 test/test-ussd
test/send-ussd new file +75 -0
@@ -0,0 +1,75 @@ +#!/usr/bin/python + +import sys +import gobject +import os + +import dbus +import dbus.mainloop.glib + +state = None + +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 + if name != "State": + return + print("USSD session state is " + value) + state = str(value) + +def stdin_handler(fd, condition): + s = os.read(fd.fileno(), 160).rstrip() + if not s: + ss.Cancel() + elif state == "user-response": + print ss.Respond(s, timeout = 100) + elif state == "idle": + 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() + + manager = dbus.Interface(bus.get_object('org.ofono', '/'), + 'org.ofono.Manager') + + modems = manager.GetModems() + modem = modems[0][0] + + if (len(sys.argv) == 2): + ussd = sys.argv[1] + else: + 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) + + gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler) + + mainloop = gobject.MainLoop() + mainloop.run()
test/test-ussd deleted +0 -75
75 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 2/2 test-ussd: new script more generic
This script can be used to handle network initiated USSD without preliminary USSD request.
--- test/test-ussd | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 test/test-ussd
test/test-ussd new file +97 -0
@@ -0,0 +1,97 @@ +#!/usr/bin/python + +import sys +import gobject +import os + +import dbus +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 "\n\nEnter response (c for cancel - x for exit):" + elif state == "idle": + print "\n\nEnter USSD request (x for exit):" + +def ussd_notification_received(content): + clear_screen() + print("Network sent a Notification: " + content) + print_menu() + +def ussd_request_received(content): + clear_screen() + print("Network sent a Request: " + content) + +def ussd_property_changed(name, value): + global state + if name != "State": + return + print("USSD session state is " + value) + state = str(value) + + print_menu() + +def stdin_handler(fd, condition): + s = os.read(fd.fileno(), 182).rstrip() + + if s == 'c': + if state == "user-response" or state == 'active': + ss.Cancel() + elif s == 'x': + sys.exit() + elif state == "user-response": + print ss.Respond(s, timeout = 100) + elif state == "idle": + print ss.Initiate(s, timeout = 100) + else: + print "Invalid state", state + return True + +if __name__ == "__main__": + if (len(sys.argv) >2 or (len(sys.argv) == 2 and + sys.argv[1] in ("-h", "--help"))): + print "Usage: %s [-h] [modem]" % (sys.argv[0]) + sys.exit(1) + + dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) + + bus = dbus.SystemBus() + + manager = dbus.Interface(bus.get_object('org.ofono', '/'), + 'org.ofono.Manager') + + modems = manager.GetModems() + + if (len(sys.argv) == 2): + modem = sys.argv[1] + else: + modem = modems[0][0] + + 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) + + gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler) + + mainloop = gobject.MainLoop() + mainloop.run()
Signature · 1 line
1.7.9.5
Hi Philippe,
Quoted 7 lines · Philippe Nunes
--- test/send-ussd | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test-ussd | 75 -------------------------------------------------------- 2 files changed, 75 insertions(+), 75 deletions(-)create mode 100755 test/send-ussd
delete mode 100755 test/test-ussd
Why don't we just get rid of test-ussd and create a new send-ussd script that doesn't do any stdin handling. Something along the lines of:
ss.GetProperties()
if state == 'idle'
rsp = ss.Initiate()
elif state == 'user-response'
rsp = ss.Respond()
print response
And perhaps another ussd related script that just cancels the request. Would this satisfy your requirements?
Regards,
-Denis
Hi Denis,
Quoted 18 lines
Quoted 7 lines
--- test/send-ussd | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test-ussd | 75 -------------------------------------------------------- 2 files changed, 75 insertions(+), 75 deletions(-)create mode 100755 test/send-ussd
delete mode 100755 test/test-ussdWhy don't we just get rid of test-ussd and create a new send-ussd script that doesn't do any stdin handling. Something along the lines of:
ss.GetProperties()if state == 'idle'
rsp =ss.Initiate()
elif state == 'user-response'
rsp =ss.Respond()
Quoted 4 lines
print response
And perhaps another ussd related script that just cancels the request. Would this satisfy your requirements?
are the existing test/initiate-ussd and test/cancel-ussd not good enough?
Regards
Marcel
Hi Marcel,
Quoted 20 lines · Marcel Holtmann
Hi Denis,
Quoted 18 lines
Quoted 7 lines
--- test/send-ussd | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test-ussd | 75 -------------------------------------------------------- 2 files changed, 75 insertions(+), 75 deletions(-)create mode 100755 test/send-ussd
delete mode 100755 test/test-ussdWhy don't we just get rid of test-ussd and create a new send-ussd script that doesn't do any stdin handling. Something along the lines of:
ss.GetProperties()if state == 'idle'
rsp =ss.Initiate()
elif state == 'user-response'
rsp =ss.Respond()
Quoted 8 lines
Quoted 4 lines
print response
And perhaps another ussd related script that just cancels the request. Would this satisfy your requirements?
are the existing test/initiate-ussd and test/cancel-ussd not good enough?
initiate-ussd is close but not quite, it doesn't handle network initiated USSDs.
Anyway, the point here is that we need to get rid of test-ussd, it really serves no purpose.
Regards,
-Denis