#!/usr/bin/python3

import dbus

bus = dbus.SystemBus()

manager = dbus.Interface(bus.get_object('org.ofono', '/'), 'org.ofono.Manager')

modems = manager.GetModems()
path = modems[0][0]

monitor = dbus.Interface(bus.get_object('org.ofono', path),
						'org.ofono.NetworkMonitor')

try:
	servingcell = monitor.GetServingCellInformation()
except dbus.DBusException as e:
	print("Unable to get serving cell information")
	exit()

tech = 'Technology'
mcc = 'MobileCountryCode'
mnc = 'MobileNetworkCode'
lac = 'LocationAreaCode'
cid = 'CellId'
psc = 'PrimaryScramblingCode'
rssi = 'Strength'
ber = 'BitErrorRate'
rxlev = 'ReceivedSignalStrength'
rscp = 'ReceivedSignalCodePower'
ecn0 = 'ReceivedEnergyRatio'
rsrq = 'ReferenceSignalReceivedQuality'
rsrp = 'ReferenceSignalReceivedPower'
earfcn = 'EARFCN'
eband = 'EBand'
cqi = 'ChannelQualityIndicator'

print("Current serving cell information:")

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 rxlev in servingcell:
	print("    [ Received Signal Strength = %d]" % (servingcell[rxlev]))

if ber in servingcell:
	print("    [ Bit Error Rate = %d]" % (servingcell[ber]))

if rscp in servingcell:
	print("    [ Received Signal Code Power = %d]" % (servingcell[rscp]))

if ecn0 in servingcell:
	print("    [ Received Energy Ratio = %d]" % (servingcell[ecn0]))

if rsrq in servingcell:
	print("    [ Reference Signal Received Quality = %d]" % (servingcell[rsrq]))

if rsrp in servingcell:
	print("    [ Reference Signal Received Power = %d]" % (servingcell[rsrp]))

if earfcn in servingcell:
	print("    [ E-UTRA Absolue Radio Frequency Channel = %d ]" % (servingcell[earfcn]))

if eband in servingcell:
	print("    [ E-UTRA operating Band = %d ]" % (servingcell[eband]))

if cqi in servingcell:
	print("    [ Channel Quality Indicator = %d ]" % (servingcell[cqi]))

print('')
