/usr/share/ofono/scripts/test-cbs is in ofono-scripts 1.12.bzr6858+14.04.20140318-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | #!/usr/bin/python
import dbus
import dbus.mainloop.glib
import sys
from gi.repository import GLib
import os
def print_menu():
print("Select test case")
print("----------------------------------------------------------------")
print("[0] Activate cbs")
print("[1] Deactivate cbs")
print("[2] Get cbs properties")
print("[3] Set/Register topics")
print(" If several - give topics separated with comma. \
\n E.g. 20,50-51,60")
print("[4] Clear/Unregister topics")
print("[5] NetReg Base Station - Get current serving cell")
print("[x] Exit")
print("----------------------------------------------------------------")
def property_changed(property, value):
if value == "" and property == "Topics":
print("User selected Topics have been cleared. \
\nRegistered for emergency topics only.")
else:
print("Cell Broadcast property %s is changed to %s" % (property, value))
print("\nPress ENTER to continue")
def incoming_broadcast(text, topic):
print("Broadcast msg: %s \n Topic channel: %s" % (text, topic))
print("\nPress ENTER to continue")
def emergency_broadcast(text, properties):
emergType = properties["EmergencyType"]
emergAlert = properties["EmergencyAlert"]
print("Broadcast msg: %s \n\t Type: %s \n\t Alert: %s \n\t Popup: %s" \
% (text, emergType, emergAlert, popup))
if properties["Popup"] == True:
print("Popup required.")
print("\nPress ENTER to continue")
def set_cbs_state(cbs, state):
if state == True:
print("Activating cell broadcast...")
cbs.SetProperty("Powered", dbus.Boolean(1))
else:
print("Deactivating cell broadcast...")
cbs.SetProperty("Powered", dbus.Boolean(0))
print("-----------------------------------------------------------")
def print_cbs_properties(cbs):
properties = cbs.GetProperties()
print("---------------------PROPERTIES----------------------------")
for p in properties:
if len(properties[p].__str__()) > 0:
if p == "Powered":
if properties[p] == True:
print("Cell Broadcast is Activated.")
else:
print("Cell Broadcast is Deactivated.")
elif p == "Topics":
print("Currently set CBS %s are: %s" \
% (p, properties[p]))
topics_available = True
else:
print("Cell Broadcast %s value empty" % (p))
print("-----------------------------------------------------------")
def set_topics(cbs):
print_cbs_properties(cbs)
topicTemp = ""
invalidData = False;
index = 0
topics = input('Enter the topic ID(s) you want to register to: ')
while index < len(topics):
if topics[index] == ',' or topics[index] == '-':
topicTemp = ""
elif topics[index] >= '0' and topics[index] <= '9':
topicTemp = topicTemp + topics[index]
else:
print("Invalid char. \"%s\" entered. Topic not set." \
% (topics[index]))
invalidData = True
break
if topicTemp:
if int(topicTemp) > 999:
invalidData = True
print("Invalid Topic ID %s (range 0-999). \
\nCould not register." % topicTemp)
index = index + 1
if invalidData == False:
try:
print("Setting Cell Broadcast topics...")
cbs.SetProperty("Topics", topics);
except dbus.DBusException as e:
print("Unable to set topic: %s" % e)
print("-----------------------------------------------------------")
def get_serving_cell_name(netReg):
wasFound = False;
properties = netReg.GetProperties()
for p in properties:
if p == "BaseStation":
if len(properties[p].__str__()) > 0:
print("Current serving cell name: %s" \
% (properties["BaseStation"]))
wasFound = True;
else:
print("Current Serving cell name empty. \
Base Station CBS not available.")
if wasFound == False:
print("Base Station parameter not found. \
\nBase Station CBS not available.")
print("-----------------------------------------------------------")
def stdin_handler(channel, condition, cbs, netReg):
in_key = os.read(channel.unix_get_fd(), 160).rstrip().decode('UTF-8')
if in_key == '0':
set_cbs_state(cbs, True)
elif in_key == '1':
set_cbs_state(cbs, False)
elif in_key == '2':
print_cbs_properties(cbs)
elif in_key == '3':
set_topics(cbs)
elif in_key == '4':
cbs.SetProperty("Topics", "")
elif in_key == '5':
get_serving_cell_name(netReg)
elif in_key == 'x':
sys.exit(1)
print('\n' * 2)
print_menu()
return True
if __name__ == "__main__":
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()
path = modems[0][0]
cbs = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.CellBroadcast')
netReg = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.NetworkRegistration')
cbs.connect_to_signal("PropertyChanged", property_changed)
cbs.connect_to_signal("IncomingBroadcast", incoming_broadcast)
cbs.connect_to_signal("EmergencyBroadcast", emergency_broadcast)
print('\n' * 2)
print_menu()
GLib.io_add_watch(GLib.IOChannel(filedes=sys.stdin.fileno()),
GLib.PRIORITY_DEFAULT, GLib.IO_IN, stdin_handler, cbs, \
netReg)
mainloop = GLib.MainLoop()
mainloop.run()
|