4 import dbus.mainloop.glib
10 print "Select test case"
11 print "----------------------------------------------------------------"
12 print "[0] Activate cbs"
13 print "[1] Deactivate cbs"
14 print "[2] Get cbs properties"
15 print "[3] Set/Register topics"
16 print " If several - give topics separated with comma. \
18 print "[4] Clear/Unregister topics"
19 print "[5] NetReg Base Station - Get current serving cell"
21 print "----------------------------------------------------------------"
23 def property_changed(property, value):
24 if value == "" and property == "Topics":
25 print "User selected Topics have been cleared. \
26 \nRegistered for emergency topics only."
28 print "Cell Broadcast property %s is changed to %s" % (property, value)
29 print "\nPress ENTER to continue"
31 def incoming_broadcast(text, topic):
32 print "Broadcast msg: %s \n Topic channel: %s" % (text, topic)
33 print "\nPress ENTER to continue"
35 def emergency_broadcast(text, properties):
36 emergType = properties["EmergencyType"]
37 emergAlert = properties["EmergencyAlert"]
39 print "Broadcast msg: %s \n\t Type: %s \n\t Alert: %s \n\t Popup: %s" \
40 % (text, emergType, emergAlert, popup)
42 if properties["Popup"] == True:
43 print "Popup required."
45 print "\nPress ENTER to continue"
47 def set_cbs_state(cbs, state):
49 print "Activating cell broadcast..."
50 cbs.SetProperty("Powered", dbus.Boolean(1))
52 print "Deactivating cell broadcast..."
53 cbs.SetProperty("Powered", dbus.Boolean(0))
54 print "-----------------------------------------------------------"
56 def print_cbs_properties(cbs):
57 properties = cbs.GetProperties()
58 print "---------------------PROPERTIES----------------------------"
60 if len(properties[p].__str__()) > 0:
62 if properties[p] == True:
63 print "Cell Broadcast is Activated."
65 print "Cell Broadcast is Deactivated."
67 print "Currently set CBS %s are: %s" \
69 topics_available = True
71 print "Cell Broadcast %s value empty" % (p)
72 print "-----------------------------------------------------------"
75 print_cbs_properties(cbs)
81 topics = raw_input('Enter the topic ID(s) you want to register to: ')
83 while index < len(topics):
84 if topics[index] == ',' or topics[index] == '-':
86 elif topics[index] >= '0' and topics[index] <= '9':
87 topicTemp = topicTemp + topics[index]
89 print "Invalid char. \"%s\" entered. Topic not set." \
95 if int(topicTemp) > 999:
97 print "Invalid Topic ID %s (range 0-999). \
98 \nCould not register." % topicTemp
102 if invalidData == False:
104 print "Setting Cell Broadcast topics..."
105 cbs.SetProperty("Topics", topics);
106 except dbus.DBusException, e:
107 print "Unable to set topic: ", e
109 print "-----------------------------------------------------------"
111 def get_serving_cell_name(netReg):
113 properties = netReg.GetProperties()
116 if p == "BaseStation":
117 if len(properties[p].__str__()) > 0:
118 print "Current serving cell name: %s" \
119 % (properties["BaseStation"])
122 print "Current Serving cell name empty. \
123 Base Station CBS not available."
125 if wasFound == False:
126 print "Base Station parameter not found. \
127 \nBase Station CBS not available."
128 print "-----------------------------------------------------------"
130 def stdin_handler(fd, condition, cbs, netReg):
131 in_key = os.read(fd.fileno(), 160).rstrip()
134 set_cbs_state(cbs, True)
137 set_cbs_state(cbs, False)
140 print_cbs_properties(cbs)
146 cbs.SetProperty("Topics", "")
149 get_serving_cell_name(netReg)
159 if __name__ == "__main__":
161 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
162 bus = dbus.SystemBus()
164 manager = dbus.Interface(bus.get_object('org.ofono', '/'),
167 modems = manager.GetModems()
170 cbs = dbus.Interface(bus.get_object('org.ofono', path),
171 'org.ofono.CellBroadcast')
173 netReg = dbus.Interface(bus.get_object('org.ofono', path),
174 'org.ofono.NetworkRegistration')
176 cbs.connect_to_signal("PropertyChanged", property_changed)
177 cbs.connect_to_signal("IncomingBroadcast", incoming_broadcast)
178 cbs.connect_to_signal("EmergencyBroadcast", emergency_broadcast)
184 gobject.io_add_watch(sys.stdin, gobject.IO_IN, stdin_handler, cbs, \
187 mainloop = gobject.MainLoop()