blob: 498ce88b96ee44c01fc8fccf343cd0f7609959db (
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
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
|
#!/usr/bin/python3
from gi.repository import GLib
import sys
import dbus
import dbus.service
import dbus.mainloop.glib
NETMON_INTERFACE = "org.ofono.NetworkMonitor"
AGENT_INTERFACE = "org.ofono.NetworkMonitorAgent"
class NetworkMonitorAgent(dbus.service.Object):
@dbus.service.method(AGENT_INTERFACE,
in_signature="", out_signature="")
def Release(self):
print("Agent Released")
mainloop.quit()
@dbus.service.method(AGENT_INTERFACE,
in_signature="a{sv}", out_signature="")
def ServingCellInformationChanged(self, servingcell):
print("ServingCellInformationChanged notification recieved")
tech = 'Technology'
mcc = 'MobileCountryCode'
mnc = 'MobileNetworkCode'
lac = 'LocationAreaCode'
cid = 'CellId'
psc = 'PrimaryScramblingCode'
rssi = 'Strength'
ber = 'BitErrorRate'
if tech in servingcell:
print(" [ Radio Access Technology = %s]" \
% (servingcell[tech]))
if mcc in servingcell:
print(" [ Mobile Country Code = %s]" \
% (servingcell[mcc]))
if mnc in servingcell:
print(" [ Mobile Network Code = %s]" \
% (servingcell[mnc]))
if lac in servingcell:
print(" [ Location Area Code = %d]" \
% (servingcell[lac]))
if cid in servingcell:
print(" [ Cell Identity = %d]" \
% (servingcell[cid]))
if psc in servingcell:
print(" [ Primary Scrambling Code = %d]" \
% (servingcell[psc]))
if rssi in servingcell:
print(" [ Signal Strength = %d]" \
% (servingcell[rssi]))
if ber in servingcell:
print(" [ Bit Error Rate = %d]" \
% (servingcell[ber]))
print('')
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
if len(sys.argv) < 2:
print("Usage: %s <update_period_in_seconds>" %\
(sys.argv[0]))
sys.exit(1)
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object("org.ofono", "/"),
"org.ofono.Manager")
modems = manager.GetModems()
path = modems[0][0]
nm = dbus.Interface(bus.get_object('org.ofono', path),
NETMON_INTERFACE)
path = "/test/netmonagent"
agent = NetworkMonitorAgent(bus, path)
try:
period = int(sys.argv[1])
except:
print("Error: Invalid argument %s" % (sys.argv[1]))
sys.exit(1)
nm.RegisterAgent(path, period)
print("Agent registered")
mainloop = GLib.MainLoop()
mainloop.run()
|