/usr/lib/python2.7/dist-packages/framework/subsystems/ogsmd/gsm/celldb.py is in fso-frameworkd 0.10.1-3.
This file is owned by root:root, with mode 0o644.
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 | from sys import stdin, stdout, stderr, argv
from math import sqrt
from struct import calcsize, pack, unpack
CELL_DB = '/etc/freesmartphone/ogsmd/cell.db'
LA_DB = '/etc/freesmartphone/ogsmd/la.db'
class SimpleCenter(object):
# FIXME port pyproj to the neo and use it
def __init__(self):
self.points = []
def addPoint(self, point):
self.points.append(point)
def calc(self):
if not self.points:
return None
x_min = min([point[0] for point in self.points])
x_max = max([point[0] for point in self.points])
x_mid = (x_min+x_max)/2
x_size = x_max-x_min
y_min = min([point[1] for point in self.points])
y_max = max([point[1] for point in self.points])
y_mid = (y_min+y_max)/2
y_size = y_max-y_min
z_min = min([point[2] for point in self.points])
z_max = max([point[2] for point in self.points])
z_mid = (z_min+z_max)/2
z_size = z_max-z_min
size = sqrt(x_size**2 + y_size**2 + z_size**2)
return (x_mid, y_mid, z_mid, size, len(self.points))
class ProjCenter(object):
def __init__(self):
from pyproj import Proj, transform
self.pwgs84 = Proj(proj='lonlat',datum='WGS84')
self.pecef = Proj(proj='geocent', datum='WGS84')
self.points = []
def addPoint(self, point):
self.points.append(point)
def calc(self):
if not self.points:
return None
ecefs = []
for lat, long, alt in self.points:
ecefs.append(transform(self.pwgs84, self.pecef, long, lat, alt))
x_min = min([ecef[0] for ecef in ecefs])
x_max = max([ecef[0] for ecef in ecefs])
x_mid = (x_min+x_max)/2
x_size = x_max-x_min
y_min = min([ecef[1] for ecef in ecefs])
y_max = max([ecef[1] for ecef in ecefs])
y_mid = (y_min+y_max)/2
y_size = y_max-y_min
z_min = min([ecef[2] for ecef in ecefs])
z_max = max([ecef[2] for ecef in ecefs])
z_mid = (z_min+z_max)/2
z_size = z_max-z_min
size = sqrt(x_size**2 + y_size**2 + z_size**2)
long, lat, alt = transform(self.pecef, self.pwgs84, x_mid, y_mid, z_mid)
return (lat, long, alt, size, len(ecefs))
Center = SimpleCenter
def find(f, format, pattern_format, pattern_data):
format_size = calcsize(format)
pattern_size = calcsize(pattern_format)
pattern = pack(pattern_format, *pattern_data)
l = 0
f.seek(0, 2)
r = f.tell()/format_size
while l < r:
m = (r+l)/2
f.seek(m*format_size)
data = f.read(format_size)
if pattern == data[:pattern_size]:
return unpack(format, data)
elif pattern<data[:pattern_size]:
r = m
elif data[:pattern_size]<pattern:
l = m
if l+1==r:
return None
def get_cell(mcc, mnc, lac, cid):
cell_db = file(CELL_DB, 'rb')
result = find(cell_db, '!HHHHffff', '!HHHH', (mcc, mnc, lac, cid))
cell_db.close()
if result:
return result[4:]
else:
return None
def get_center(mcc, mnc, cells):
center = Center()
cell_db = file(CELL_DB, 'rb')
for lac, cid in cells:
cell = find(cell_db, '!HHHHffff', '!HHHH', (mcc, mnc, lac, cid))
if cell:
center.addPoint(cell[4:7])
cell_db.close()
return center.calc()
def get_la(mcc, mnc, lac):
la_db = file(LA_DB, 'rb')
result = find(la_db, '!HHHffff', '!HHH', (mcc, mnc, lac))
la_db.close()
if result:
return result[3:]
else:
return None
if __name__=="__main__":
cell_count = (len(argv)-3)/2
mcc, mnc = map(eval, argv[1:3])
laccids = map(eval, argv[3:3+cell_count*2])
cells = []
for i in range(cell_count):
cells.append(laccids[i*2:i*2+2])
for lac, cid in cells:
print 'Cell 0x%04x 0x%04x:' % (lac, cid), get_cell(mcc, mnc, lac, cid)
print 'Center:', get_center(mcc, mnc, cells)
print 'LA 0x%04x:' % lac, get_la(mcc, mnc, lac)
|