summaryrefslogtreecommitdiffstats
path: root/Src/PyCatcher/src/pyCatcherModel.py
blob: 5de62346ea3c3824cbb49b2f440122e8b0c31750 (plain) (blame)
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
import datetime
import gtk
import math

class BaseStationInformation: 

    def __init__ (self):
        self.country = 'Nowhere'
        self.provider = 'Carry'
        self.arfcn = 0
        self.rxlev = 0
        self.system_info_t2 = []
        self.system_info_t2bis = []
        self.system_info_t2ter = []
        self.discovery_time = datetime.datetime.now().strftime('%T')
        self.found = False
        self.bsic = ''
        self.lac = 0
        self.cell = 0
        self.rules_report = {}
        self.evaluation = 'NYE'
               
    def get_list_model(self):
        return (self.provider, str(self.arfcn), str(self.rxlev), self.evaluation, self.discovery_time)
    
    def get_neighbour_arfcn(self):
        neighbours = self.system_info_t2[3:19]
        bin_representation = ''
        neighbour_arfcn = []
        
        for value in neighbours:
            bin_representation += str(bin(int(value, 16))[2:].zfill(8))
        
        '''
        >>> for i, bit in enumerate(reversed(a)):
...     if bit == '1':
...             print i
        '''       
        for x in xrange(1,125):
            index = 0-x
            bit = bin_representation[index]
            if bit == '1':
                neighbour_arfcn.append(abs(index))
        return neighbour_arfcn
    
    def get_neighbour_arfcn_ter(self):
        pass
        
    def get_neighbour_arfcn_bis(self):
        pass
    
    def create_lof(self):
        pass
    
class BaseStationInformationList:
    def __init__(self):
        self._base_station_list = []
        
    def add_station(self, base_station):
        for item in self._base_station_list:
            if item.arfcn == base_station.arfcn:
                item.discovery_time = datetime.datetime.now().strftime('%T')
                break
        else:
            self._base_station_list.append(base_station)
    
    def get_dot_code(self, filters=None, found_filter=None):
        preamble = r'digraph bsnetwork { '
        postamble = r'}'
        code = ''
        filtered_list = self._base_station_list
        
        if found_filter == None:
            print_neighbours = True
        else:
            print_neighbours = not found_filter.is_active
        
        if filters != None:
            for filter in filters:
                if filter.is_active:
                    filtered_list = filter.execute(filtered_list)
                    
        for station in filtered_list:
            code += str(station.arfcn) + r' [color=red]; '
            if(print_neighbours):
                for neighbour in station.get_neighbour_arfcn():
                    code += str(station.arfcn) + r' -> ' + str(neighbour) + r'; '
        #TODO: make printing the source a fixed option
        #print preamble + code + postamble
        return preamble + code + postamble
    
    def refill_store(self, store):
        store.clear()
        for item in self._base_station_list:
            store.append(item.get_list_model())