Beispiel #1
0
 def mode_init(self):
     log("mode_init ", 9)
     # Set run Trigger
     self.th_run = True
     # Switch servo to on
     self.ardu.toggle_servos(True)
     # Bring servo slowly to scan start pos
     try:
         self.ardu.set_servo(_val=1000,
                             _speed=self.init_speed,
                             wait_servo_confirm=True)
         # Scan slowly both Net Modes
         while self.run_trigger and self.th_run and not self.cell_hdg_list:
             try:
                 self.scan.scan_one_cycle(_resolution=self.scan_resolution,
                                          _lte_duration=self.scan_duration,
                                          _speed=self.init_speed)
                 # go slowly to strongest visible cell
                 self.go_strongest_cell(_speed=self.init_speed)
                 self.c5 = time.time()
                 self.data2web()
             except ConnectionError:
                 self.close(
                     "main.mode_init() scan.scan_one_cycle - ConnectionError"
                 )
     except ConnectionError:
         self.close("main.mode_init() ardu.set_servo - ConnectionError")
Beispiel #2
0
 def pasv_scan(self):
     log("pasv_scan ", 9)
     self.scan.get_lte_signals_avg(self.ardu.servo_val,
                                   self.scan_resolution, self.scan_duration)
     self.scan.get_cells(self.lte.net_mode)
     self.chk_sig_in_threshold()
     # TODO Temporary
     self.call_web2data = True
Beispiel #3
0
 def cell_scan(self):
     log("cell_scan ", 9)
     try:
         self.scan.scan_hdg_range(self.cell_hdg_list, self.lte.net_mode,
                                  self.cell_speed, self.scan_resolution,
                                  self.scan_duration)
         self.go_strongest_cell(_speed=self.cell_speed)
         self.call_web2data = True
     except ConnectionError:
         self.close("main.cell_scan() scan_hdg_range ConnectionError")
Beispiel #4
0
 def get_not_scanned_vis_hdg(self, _net_mode):
     # Returns a array of hdg that are visible an not scanned
     _scan_res = self.get_scanres_dict(_net_mode)
     _vis_range = self.get_visible_hdg()
     _res = []
     if len(_scan_res) >= self.N:
         log("No more hidden cells !!", 9)
         return _res, _net_mode
     for _i in _vis_range:
         if overflow_value(_i, self.N) not in _scan_res:
             _res.append(_i)
     return _res, _net_mode
Beispiel #5
0
 def reboot(self):
     try:        # for E 3372
         self.client.device.reboot()
     except ResponseErrorException:
         log('Rebooting LTE-Modem ...', 9)
         time.sleep(30)
         self.run_trigger = True
         return True
     except Exception as e:
         self.run_trigger = False
         raise e
     return False
Beispiel #6
0
    def chk_no_scanned_array(self):
        _t = False
        for _n in range(2):
            _le = len(self.scan.get_scanres_dict(self.lte.net_mode))
            if _le < self.scan.N:
                _le = int(
                    (self.scan.N - _le) / 2
                )  # FIXME _le get smaller and smaller. Also servo gets nervous
                _vis_hdg_not_scan = self.scan.get_not_scanned_vis_hdg(
                    self.lte.net_mode)[0]
                if len(
                        _vis_hdg_not_scan
                ) >= _le:  # if more than 1/3 of not scanned array is visible, scan it
                    log("chk_no_scanned_array > " + str(_n), 9)
                    # if _n:
                    #     _vis_hdg_not_scan = _vis_hdg_not_scan[::-1]
                    try:
                        self.scan.scan_hdg_range(_vis_hdg_not_scan,
                                                 self.lte.net_mode,
                                                 self.cell_speed,
                                                 self.scan_resolution,
                                                 self.scan_duration)
                        if not _n:
                            try:
                                self.lte.switch_net_mode()
                            except Exception as e:
                                # TODO Reboot LTE Stick
                                self.close(
                                    "main.chk_no_scanned_array()  switch_net_mode - "
                                    + str(e))
                                break
                        _t = True
                    except Exception as e:
                        self.close(
                            "main.chk_no_scanned_array() scan_hdg_range - " +
                            str(e))
                        break

            if _t and _n:
                self.go_strongest_cell(_speed=self.cell_speed)
                self.call_web2data = True
Beispiel #7
0
    def set_net_mode(self, _net_mode=4):
        # net_mode
        # 0 = auto
        # 1 = 2G
        # 2 = 3G
        # 3 = 4G
        # 4 = best available mode
        if self.net_mode == _net_mode:
            return _net_mode
        mode_list = self.get_net_mode_list()
        available_modes = mode_list['AccessList']['Access']
        if '02' in available_modes or '03' in available_modes or _net_mode == 0:
            lte_band = mode_list['LTEBandList']['LTEBand'][0]['Value']
            net_band = mode_list['LTEBandList']['LTEBand'][1]['Value']
            if _net_mode == 4:
                _net_mode = available_modes[-1:]

            _net_mode = '0' + str(_net_mode)
            try:    # E 3372
                self.client.net.set_net_mode(networkmode=_net_mode, networkband=net_band, lteband=lte_band)
            except ResponseErrorException:
                e_c = 0
                while self.client.device.signal()['mode'] is None:
                    if e_c > 10:
                        log("Error.. None Net Mode after changing Net Mode .. No NET !!", 9)
                        self.net_mode = int(_net_mode)
                        return _net_mode
                    time.sleep(1)
                    e_c += 1

                # print("New Net-Mode set: " + str(net_mode))
                self.net_mode = int(_net_mode)
                time.sleep(3)
                return _net_mode
            except Exception as e:
                log("Error.. while trying to set Net Mode ..", 1)
                self.run_trigger = False
                raise e
            return False
        else:
            return False
Beispiel #8
0
 def chk_sig_in_threshold(self):
     _sig = self.scan.get_scanres_dict(self.lte.net_mode)
     _sig = _sig[self.ardu.servo_val][0]
     if _sig < self.scan.get_threshold(self.lte.net_mode):
         self.call_web2data = True
         log("chk_sig_in_threshold -- Trigger ", 9)
         log(
             "chk_sig_in_threshold old cell hdg list  " +
             str(self.cell_hdg_list), 9)
         self.go_strongest_cell(_speed=self.cell_speed)
         log(
             "chk_sig_in_threshold new cell hdg list  " +
             str(self.cell_hdg_list), 9)
Beispiel #9
0
 def chk_act_cell_vis(self):
     if not self.scan.check_if_in_vis_hdg(self.ardu.servo_val):
         log("chk_act_cell_vis ", 9)
         self.go_strongest_cell(_speed=self.cell_speed)
Beispiel #10
0
    def plot_signal_arrays(
            self, _net_mode):  # Plot signal array in a separately Plot
        # FIXME
        # plot axis get added and not separate axis ..
        # _radii_array = self.radii_array every irritation but doesnt wor .. hmpf
        # solution: Plot in bars not filled
        # FIXME END
        _sig_array_dict = self.load_cells(_net_mode)

        def _get_mode_config(_n_mo):
            return {
                2: (20., '3g_array-800x800'),
                3: (20., '4g_array-800x800')
            }[_n_mo]

        def _get_sig_array_color(_val):
            return {
                7: 'lawngreen',
                6: 'green',
                5: 'mediumspringgreen',
                4: 'yellowgreen',
                3: 'yellow',
                2: 'orange',
                1: 'red',
                0: 'black'
            }[int(round(_val / 3))]  # TODO better colors for the signal values

        if len(_sig_array_dict.keys()
               ):  # Plot signal arrays if get data in ( sig_array not None )
            _plot_config = _get_mode_config(_net_mode)
            e_max = 0
            _fig = plt.figure(figsize=(8, 8))

            for _key in sorted(_sig_array_dict.keys()):
                _ax = _fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar')
                # for _label in _ax.get_yticklabels():
                #     _ax.figure.texts.append(_label)
                _radii_array = []
                log("", 9)
                log("self.radii_array : " + str(self.radii_array), 9)
                _radii_array = self.radii_array

                log("Radi1 key:" + str(_key) + ' - Radi1' + str(_radii_array),
                    9)
                _cor_hdg_key = 0
                for _hdg_key in _sig_array_dict[_key]:
                    _cor_hdg_key = overflow_value((self.center + _hdg_key),
                                                  self.N)
                    _radii_array[_cor_hdg_key] = _plot_config[0] + _key
                _radii_array[_cor_hdg_key] = 0

                _ax.grid(True)
                _ax.xaxis.set_visible(False)
                _col = _get_sig_array_color(_plot_config[0] + _key)  # FIXME
                if (_plot_config[0] + _key) > e_max:  # FIXME
                    e_max = (_plot_config[0] + _key)  # FIXME
                _ax.set_alpha(0.8)
                _ax.fill_between(self.theta,
                                 _radii_array,
                                 color=_col,
                                 alpha=0.8)
                _ax.set_rmin(0)
                _ax.set_rmax(e_max)
                log("", 9)
                log("Radi2 key:" + str(_key) + ' - Radi2' + str(_radii_array),
                    9)
                time.sleep(0.1)

            # ax.grid(True)

            # plt.savefig(self.html_images + plot_config[1] + '.png')   # TODO add space in website and change filename
            plt.savefig(config.html_root + 'test_' + str(_net_mode) + '.png')
            # shutil.copy(self.html_images + o_name + '.png',
            #             self.html_images + o_name + '-800x800' + '.png')

            plt.cla()
            plt.clf()
            plt.close(_fig)
            time.sleep(1)