コード例 #1
0
 def _log_level_filter_changed(self):
     """
     Takes log level enum and translates into the mapped integer.
     Integer stores the current filter value inside OutputList.
     """
     self.console_output.log_level_filter = str_to_log_level(
         self.log_level_filter)
コード例 #2
0
ファイル: console.py プロジェクト: swift-nav/piksi_tools
 def _log_level_filter_changed(self):
     """
     Takes log level enum and translates into the mapped integer.
     Integer stores the current filter value inside OutputList.
     """
     self.console_output.log_level_filter = str_to_log_level(
         self.log_level_filter)
コード例 #3
0
 def print_message_callback(self, sbp_msg, **metadata):
     try:
         encoded = sbp_msg.payload.encode('ascii', 'ignore')
         for eachline in reversed(encoded.split('\n')):
             self.console_output.write_level(
                 eachline, str_to_log_level(eachline.split(':')[0]))
     except UnicodeDecodeError:
         print("Critical Error encoding the serial stream as ascii.")
コード例 #4
0
 def print_message_callback(self, sbp_msg, **metadata):
     try:
         encoded = sbp_msg.payload.encode('ascii', 'ignore')
         for eachline in reversed(encoded.split('\n')):
             self.console_output.write_level(
                 eachline, str_to_log_level(eachline.split(':')[0]))
     except UnicodeDecodeError as e:
         print("Error encoding msg_print: {}".format(e))
コード例 #5
0
ファイル: console.py プロジェクト: longshike/piksi_tools
 def print_message_callback(self, sbp_msg, **metadata):
   try:
     encoded = sbp_msg.payload.encode('ascii', 'ignore')
     for eachline in reversed(encoded.split('\n')):
       self.console_output.write_level(eachline,
                                       str_to_log_level(eachline.split(':')[0]))
   except UnicodeDecodeError:
     print "Critical Error encoding the serial stream as ascii."
コード例 #6
0
ファイル: console.py プロジェクト: swift-nav/piksi_tools
 def print_message_callback(self, sbp_msg, **metadata):
     try:
         encoded = sbp_msg.payload.encode('ascii', 'ignore')
         for eachline in reversed(encoded.split('\n')):
             self.console_output.write_level(
                 eachline, str_to_log_level(eachline.split(':')[0]))
     except UnicodeDecodeError as e:
         print("Error encoding msg_print: {}".format(e))
コード例 #7
0
ファイル: console.py プロジェクト: asthakeshan/piksi_tools
 def __init__(self, link, update, log_level_filter, skip_settings=False, error=False):
   self.console_output = OutputList()
   self.console_output.write("Console: starting...")
   self.error = error
   sys.stdout = self.console_output
   if not error:
     sys.stderr = self.console_output
   self.log_level_filter = log_level_filter
   self.console_output.log_level_filter = str_to_log_level(log_level_filter)
   try:
     self.link = link
     self.link.add_callback(self.print_message_callback, SBP_MSG_PRINT_DEP)
     self.link.add_callback(self.log_message_callback, SBP_MSG_LOG)
     self.link.add_callback(self.ext_event_callback, SBP_MSG_EXT_EVENT)
     self.dep_handler = DeprecatedMessageHandler(link)
     settings_read_finished_functions = []
     self.tracking_view = TrackingView(self.link)
     self.solution_view = SolutionView(self.link)
     self.baseline_view = BaselineView(self.link)
     self.observation_view = ObservationView(self.link, name='Rover', relay=False)
     self.observation_view_base = ObservationView(self.link, name='Base', relay=True)
     self.system_monitor_view = SystemMonitorView(self.link)
     self.update_view = UpdateView(self.link, prompt=update)
     settings_read_finished_functions.append(self.update_view.compare_versions)
     self.networking_view = SbpRelayView(self.link)
     # Once we have received the settings, update device_serial with
     # the Piksi serial number which will be displayed in the window
     # title. This callback will also update the header route as used
     # by the networking view.
     def update_serial():
       serial_string = self.settings_view.settings['system_info']['serial_number'].value
       self.device_serial = 'PK%04d' % int(serial_string)
       if serial_string:
         self.networking_view.set_route(int(serial_string))
     settings_read_finished_functions.append(update_serial)
     self.settings_view = SettingsView(self.link,
                                       settings_read_finished_functions,
                                       False,
                                       skip=skip_settings)
     self.update_view.settings = self.settings_view.settings
     self.python_console_env = { 'send_message': self.link,
                                 'link': self.link, }
     self.python_console_env.update(self.tracking_view.python_console_cmds)
     self.python_console_env.update(self.solution_view.python_console_cmds)
     self.python_console_env.update(self.baseline_view.python_console_cmds)
     self.python_console_env.update(self.observation_view.python_console_cmds)
     self.python_console_env.update(self.networking_view.python_console_cmds)
     self.python_console_env.update(self.system_monitor_view.python_console_cmds)
     self.python_console_env.update(self.update_view.python_console_cmds)
     self.python_console_env.update(self.settings_view.python_console_cmds)
   except:
     import traceback
     traceback.print_exc()
     if self.error:
       sys.exit(1)
コード例 #8
0
 def __init__(self, link, update, log_level_filter, skip_settings=False, error=False):
   self.console_output = OutputList()
   self.console_output.write("Console: starting...")
   self.error = error
   sys.stdout = self.console_output
   if not error:
     sys.stderr = self.console_output
   self.log_level_filter = log_level_filter
   self.console_output.log_level_filter = str_to_log_level(log_level_filter)
   try:
     self.link = link
     self.link.add_callback(self.print_message_callback, SBP_MSG_PRINT_DEP)
     self.link.add_callback(self.log_message_callback, SBP_MSG_LOG)
     self.link.add_callback(self.ext_event_callback, SBP_MSG_EXT_EVENT)
     self.dep_handler = DeprecatedMessageHandler(link)
     settings_read_finished_functions = []
     self.tracking_view = TrackingView(self.link)
     self.solution_view = SolutionView(self.link)
     self.baseline_view = BaselineView(self.link)
     self.observation_view = ObservationView(self.link, name='Rover', relay=False)
     self.observation_view_base = ObservationView(self.link, name='Base', relay=True)
     self.system_monitor_view = SystemMonitorView(self.link)
     self.update_view = UpdateView(self.link, prompt=update)
     settings_read_finished_functions.append(self.update_view.compare_versions)
     self.networking_view = SbpRelayView(self.link)
     # Once we have received the settings, update device_serial with
     # the Piksi serial number which will be displayed in the window
     # title. This callback will also update the header route as used
     # by the networking view.
     def update_serial():
       serial_string = self.settings_view.settings['system_info']['serial_number'].value
       self.device_serial = 'PK%04d' % int(serial_string)
       if serial_string:
         self.networking_view.set_route(int(serial_string))
     settings_read_finished_functions.append(update_serial)
     self.settings_view = SettingsView(self.link,
                                       settings_read_finished_functions,
                                       skip=skip_settings)
     self.update_view.settings = self.settings_view.settings
     self.python_console_env = { 'send_message': self.link,
                                 'link': self.link, }
     self.python_console_env.update(self.tracking_view.python_console_cmds)
     self.python_console_env.update(self.solution_view.python_console_cmds)
     self.python_console_env.update(self.baseline_view.python_console_cmds)
     self.python_console_env.update(self.observation_view.python_console_cmds)
     self.python_console_env.update(self.networking_view.python_console_cmds)
     self.python_console_env.update(self.system_monitor_view.python_console_cmds)
     self.python_console_env.update(self.update_view.python_console_cmds)
     self.python_console_env.update(self.settings_view.python_console_cmds)
   except:
     import traceback
     traceback.print_exc()
     if self.error:
       sys.exit(1)
コード例 #9
0
    def __init__(self,
                 link,
                 update,
                 log_level_filter,
                 skip_settings=False,
                 error=False,
                 cnx_desc=None,
                 json_logging=False,
                 log_dirname=None,
                 override_filename=None,
                 log_console=False,
                 networking=None,
                 serial_upgrade=False):
        self.error = error
        self.cnx_desc = cnx_desc
        self.dev_id = cnx_desc
        self.num_sats = 0
        self.mode = ''
        self.forwarder = None
        self.latency = '--'
        # if we have passed a logfile, we set our directory to it
        override_filename = override_filename
        home = expanduser("~")
        swift_path = os.path.normpath(os.path.join(home, 'SwiftNav'))

        if log_dirname:
            self.directory_name = log_dirname
            if override_filename:
                override_filename = os.path.join(log_dirname,
                                                 override_filename)
        else:
            self.directory_name = swift_path

        # Start swallowing sys.stdout and sys.stderr
        self.console_output = OutputList(tfile=log_console,
                                         outdir=self.directory_name)
        sys.stdout = self.console_output
        self.console_output.write("Console: " + CONSOLE_VERSION +
                                  " starting...")
        if not error:
            sys.stderr = self.console_output

        self.log_level_filter = log_level_filter
        self.console_output.log_level_filter = str_to_log_level(
            log_level_filter)
        try:
            self.link = link
            self.link.add_callback(self.print_message_callback,
                                   SBP_MSG_PRINT_DEP)
            self.link.add_callback(self.log_message_callback, SBP_MSG_LOG)
            self.link.add_callback(self.ext_event_callback, SBP_MSG_EXT_EVENT)
            self.link.add_callback(self.cmd_resp_callback,
                                   SBP_MSG_COMMAND_RESP)
            self.link.add_callback(self.update_on_heartbeat, SBP_MSG_HEARTBEAT)
            self.dep_handler = DeprecatedMessageHandler(link)
            settings_read_finished_functions = []
            self.tracking_view = TrackingView(self.link)
            self.solution_view = SolutionView(self.link,
                                              dirname=self.directory_name)
            self.baseline_view = BaselineView(self.link,
                                              dirname=self.directory_name)
            self.observation_view = ObservationView(
                self.link,
                name='Local',
                relay=False,
                dirname=self.directory_name)
            self.observation_view_base = ObservationView(
                self.link,
                name='Remote',
                relay=True,
                dirname=self.directory_name)
            self.system_monitor_view = SystemMonitorView(self.link)
            self.update_view = UpdateView(self.link,
                                          download_dir=swift_path,
                                          prompt=update,
                                          serial_upgrade=serial_upgrade)
            self.imu_view = IMUView(self.link)
            self.spectrum_analyzer_view = SpectrumAnalyzerView(self.link)
            settings_read_finished_functions.append(
                self.update_view.compare_versions)
            if networking:
                import yaml
                try:
                    networking_dict = yaml.load(networking)
                    networking_dict.update({'show_networking': True})
                except yaml.YAMLError:
                    print(
                        "Unable to interpret networking cmdline argument.  It will be ignored."
                    )
                    import traceback
                    print(traceback.format_exc())
                    networking_dict = {'show_networking': True}
            else:
                networking_dict = {}
            networking_dict.update(
                {'whitelist': [SBP_MSG_POS_LLH, SBP_MSG_HEARTBEAT]})
            self.networking_view = SbpRelayView(self.link, **networking_dict)
            self.json_logging = json_logging
            self.csv_logging = False
            self.first_json_press = True
            if json_logging:
                self._start_json_logging(override_filename)
                self.json_logging = True
            # we set timer interval to 1200 milliseconds because we expect a heartbeat each second
            self.timer_cancel = call_repeatedly(1.2, self.check_heartbeat)

            # Once we have received the settings, update device_serial with
            # the Swift serial number which will be displayed in the window
            # title. This callback will also update the header route as used
            # by the networking view.

            def update_serial():
                uuid = None
                mfg_id = None
                try:
                    uuid = self.settings_view.settings['system_info'][
                        'uuid'].value
                    mfg_id = self.settings_view.settings['system_info'][
                        'serial_number'].value
                except KeyError:
                    pass
                if mfg_id:
                    self.device_serial = 'PK' + str(mfg_id)[-6:]
                self.networking_view.set_route(uuid=uuid, serial_id=mfg_id)
                if self.networking_view.connect_when_uuid_received:
                    self.networking_view._connect_rover_fired()

            settings_read_finished_functions.append(update_serial)
            self.settings_view = SettingsView(self.link,
                                              settings_read_finished_functions,
                                              skip=skip_settings)
            self.update_view.settings = self.settings_view.settings
            self.python_console_env = {
                'send_message': self.link,
                'link': self.link,
            }
            self.python_console_env.update(
                self.tracking_view.python_console_cmds)
            self.python_console_env.update(
                self.solution_view.python_console_cmds)
            self.python_console_env.update(
                self.baseline_view.python_console_cmds)
            self.python_console_env.update(
                self.observation_view.python_console_cmds)
            self.python_console_env.update(
                self.networking_view.python_console_cmds)
            self.python_console_env.update(
                self.system_monitor_view.python_console_cmds)
            self.python_console_env.update(
                self.update_view.python_console_cmds)
            self.python_console_env.update(self.imu_view.python_console_cmds)
            self.python_console_env.update(
                self.settings_view.python_console_cmds)
            self.python_console_env.update(
                self.spectrum_analyzer_view.python_console_cmds)

        except:
            import traceback
            traceback.print_exc()
            if self.error:
                sys.exit(1)
コード例 #10
0
    def __init__(self,
                 link,
                 driver,
                 update,
                 log_level_filter,
                 error=False,
                 cnx_desc=None,
                 json_logging=False,
                 log_dirname=None,
                 override_filename=None,
                 log_console=False,
                 connection_info=None,
                 expand_json=False
                 ):
        self.error = error
        self.cnx_desc = cnx_desc
        self.connection_info = connection_info
        self.dev_id = cnx_desc
        self.num_sats_str = EMPTY_STR
        self.mode = ''
        self.ins_status_string = "None"
        self.forwarder = None
        self.age_of_corrections = '--'
        self.expand_json = expand_json
        # if we have passed a logfile, we set our directory to it
        override_filename = override_filename
        self.last_status_update_time = 0
        self.last_driver_bytes_read = 0
        self.driver = driver

        if log_dirname:
            self.directory_name = log_dirname
            if override_filename:
                override_filename = os.path.join(log_dirname,
                                                 override_filename)
        else:
            self.directory_name = swift_path

        # Start swallowing sys.stdout and sys.stderr
        self.console_output = OutputList(
            tfile=log_console, outdir=self.directory_name)
        sys.stdout = self.console_output
        self.console_output.write("Console: " + CONSOLE_VERSION +
                                  " starting...")
        if not error:
            sys.stderr = self.console_output

        self.log_level_filter = log_level_filter
        self.console_output.log_level_filter = str_to_log_level(
            log_level_filter)
        try:
            self.link = link
            self.link.add_callback(self.print_message_callback,
                                   SBP_MSG_PRINT_DEP)
            self.link.add_callback(self.log_message_callback, SBP_MSG_LOG)
            self.link.add_callback(self.ext_event_callback, SBP_MSG_EXT_EVENT)
            self.link.add_callback(self.cmd_resp_callback,
                                   SBP_MSG_COMMAND_RESP)
            self.link.add_callback(self.update_on_heartbeat, SBP_MSG_HEARTBEAT)
            self.dep_handler = DeprecatedMessageHandler(link)
            settings_read_finished_functions = []
            self.tracking_view = TrackingView(self.link)
            self.solution_view = SolutionView(
                self.link, dirname=self.directory_name)
            self.baseline_view = BaselineView(
                self.link, dirname=self.directory_name)
            self.skyplot_view = SkyplotView(self.link, self.tracking_view)
            self.observation_view = ObservationView(
                self.link,
                name='Local',
                relay=False,
                dirname=self.directory_name,
                tracking_view=self.tracking_view)
            self.observation_view_base = ObservationView(
                self.link,
                name='Remote',
                relay=True,
                dirname=self.directory_name)
            self.system_monitor_view = SystemMonitorView(self.link)
            self.update_view = UpdateView(
                self.link,
                download_dir=swift_path,
                prompt=update,
                connection_info=self.connection_info)
            self.imu_view = IMUView(self.link)
            self.mag_view = MagView(self.link)
            self.spectrum_analyzer_view = SpectrumAnalyzerView(self.link)
            settings_read_finished_functions.append(
                self.update_view.compare_versions)
            self.networking_view = SbpRelayView(self.link)
            self.json_logging = json_logging
            self.csv_logging = False
            self.first_json_press = True
            if json_logging:
                self._start_json_logging(override_filename)
                self.json_logging = True
            # we set timer interval to 1200 milliseconds because we expect a heartbeat each second
            self.timer_cancel = call_repeatedly(1.2, self.check_heartbeat)

            # Once we have received the settings, update device_serial with
            # the Swift serial number which will be displayed in the window
            # title. This callback will also update the header route as used
            # by the networking view.

            def update_serial():
                mfg_id = None
                try:
                    self.uuid = self.settings_view.settings['system_info'][
                        'uuid'].value
                    mfg_id = self.settings_view.settings['system_info'][
                        'serial_number'].value
                except KeyError:
                    pass
                if mfg_id:
                    self.device_serial = 'PK' + str(mfg_id)

            skip_settings_read = False
            if 'mode' in self.connection_info:
                if self.connection_info['mode'] == 'file':
                    skip_settings_read = True

            settings_read_finished_functions.append(update_serial)
            self.settings_view = SettingsView(
                self.link,
                settings_read_finished_functions,
                skip_read=skip_settings_read)
            self.update_view.settings = self.settings_view.settings
            self.python_console_env = {
                'send_message': self.link,
                'link': self.link,
            }
            self.python_console_env.update(
                self.tracking_view.python_console_cmds)
            self.python_console_env.update(
                self.solution_view.python_console_cmds)
            self.python_console_env.update(
                self.baseline_view.python_console_cmds)
            self.python_console_env.update(
                self.skyplot_view.python_console_cmds)
            self.python_console_env.update(
                self.observation_view.python_console_cmds)
            self.python_console_env.update(
                self.networking_view.python_console_cmds)
            self.python_console_env.update(
                self.system_monitor_view.python_console_cmds)
            self.python_console_env.update(
                self.update_view.python_console_cmds)
            self.python_console_env.update(self.imu_view.python_console_cmds)
            self.python_console_env.update(self.mag_view.python_console_cmds)
            self.python_console_env.update(
                self.settings_view.python_console_cmds)
            self.python_console_env.update(
                self.spectrum_analyzer_view.python_console_cmds)

        except:  # noqa
            import traceback
            traceback.print_exc()
            if self.error:
                os._exit(1)
コード例 #11
0
    def __init__(self,
                 link,
                 update,
                 log_level_filter,
                 skip_settings=False,
                 error=False,
                 port=None,
                 json_logging=False,
                 log_dirname=None):
        self.console_output = OutputList()
        self.console_output.write("Console: starting...")
        self.error = error
        sys.stdout = self.console_output
        self.port = port
        self.num_sats = 0
        self.mode = ''
        self.forwarder = None
        # if we have passed a logfile, we set our directory to it
        override_filename = None
        swift_path = None
        home = expanduser("~")
        swift_path = os.path.normpath(os.path.join(home, 'SwiftNav'))
        try:
            os.makedirs(swift_path)
        except OSError:
            if not os.path.isdir(swift_path):
                raise

        if log_dirname:
            self.directory_name = log_dirname
        else:
            self.directory_name = swift_path

        if not error:
            sys.stderr = self.console_output
        self.log_level_filter = log_level_filter
        self.console_output.log_level_filter = str_to_log_level(
            log_level_filter)
        try:
            self.link = link
            self.link.add_callback(self.print_message_callback,
                                   SBP_MSG_PRINT_DEP)
            self.link.add_callback(self.log_message_callback, SBP_MSG_LOG)
            self.link.add_callback(self.ext_event_callback, SBP_MSG_EXT_EVENT)
            self.link.add_callback(self.update_on_heartbeat, SBP_MSG_HEARTBEAT)
            self.dep_handler = DeprecatedMessageHandler(link)
            settings_read_finished_functions = []
            self.tracking_view = TrackingView(self.link)
            self.solution_view = SolutionView(self.link,
                                              dirname=self.directory_name)
            self.baseline_view = BaselineView(self.link,
                                              dirname=self.directory_name)
            self.observation_view = ObservationView(
                self.link,
                name='Local',
                relay=False,
                dirname=self.directory_name)
            self.observation_view_base = ObservationView(
                self.link,
                name='Remote',
                relay=True,
                dirname=self.directory_name)
            self.system_monitor_view = SystemMonitorView(self.link)
            self.update_view = UpdateView(self.link, prompt=update)
            settings_read_finished_functions.append(
                self.update_view.compare_versions)
            self.networking_view = SbpRelayView(self.link)
            self.json_logging = json_logging
            self.csv_logging = False
            self.first_json_press = True
            if json_logging:
                self._start_json_logging(override_filename)
                self.json_logging = True

            # Once we have received the settings, update device_serial with
            # the Piksi serial number which will be displayed in the window
            # title. This callback will also update the header route as used
            # by the networking view.
            def update_serial():
                serial_string = self.settings_view.settings['system_info'][
                    'serial_number'].value
                self.device_serial = 'PK%04d' % int(serial_string)
                if serial_string:
                    self.networking_view.set_route(int(serial_string))

            settings_read_finished_functions.append(update_serial)
            self.settings_view = SettingsView(self.link,
                                              settings_read_finished_functions,
                                              skip=skip_settings)
            self.update_view.settings = self.settings_view.settings
            self.python_console_env = {
                'send_message': self.link,
                'link': self.link,
            }
            self.python_console_env.update(
                self.tracking_view.python_console_cmds)
            self.python_console_env.update(
                self.solution_view.python_console_cmds)
            self.python_console_env.update(
                self.baseline_view.python_console_cmds)
            self.python_console_env.update(
                self.observation_view.python_console_cmds)
            self.python_console_env.update(
                self.networking_view.python_console_cmds)
            self.python_console_env.update(
                self.system_monitor_view.python_console_cmds)
            self.python_console_env.update(
                self.update_view.python_console_cmds)
            self.python_console_env.update(
                self.settings_view.python_console_cmds)

        except:
            import traceback
            traceback.print_exc()
            if self.error:
                sys.exit(1)
コード例 #12
0
ファイル: console.py プロジェクト: swift-nav/piksi_tools
    def __init__(self,
                 link,
                 update,
                 log_level_filter,
                 error=False,
                 cnx_desc=None,
                 json_logging=False,
                 log_dirname=None,
                 override_filename=None,
                 log_console=False,
                 connection_info=None,
                 expand_json=False
                 ):
        self.error = error
        self.cnx_desc = cnx_desc
        self.connection_info = connection_info
        self.dev_id = cnx_desc
        self.num_sats = 0
        self.mode = ''
        self.forwarder = None
        self.age_of_corrections = '--'
        self.expand_json = expand_json
        # if we have passed a logfile, we set our directory to it
        override_filename = override_filename
        self.last_status_update_time = 0

        if log_dirname:
            self.directory_name = log_dirname
            if override_filename:
                override_filename = os.path.join(log_dirname,
                                                 override_filename)
        else:
            self.directory_name = swift_path

        # Start swallowing sys.stdout and sys.stderr
        self.console_output = OutputList(
            tfile=log_console, outdir=self.directory_name)
        sys.stdout = self.console_output
        self.console_output.write("Console: " + CONSOLE_VERSION +
                                  " starting...")
        if not error:
            sys.stderr = self.console_output

        self.log_level_filter = log_level_filter
        self.console_output.log_level_filter = str_to_log_level(
            log_level_filter)
        try:
            self.link = link
            self.link.add_callback(self.print_message_callback,
                                   SBP_MSG_PRINT_DEP)
            self.link.add_callback(self.log_message_callback, SBP_MSG_LOG)
            self.link.add_callback(self.ext_event_callback, SBP_MSG_EXT_EVENT)
            self.link.add_callback(self.cmd_resp_callback,
                                   SBP_MSG_COMMAND_RESP)
            self.link.add_callback(self.update_on_heartbeat, SBP_MSG_HEARTBEAT)
            self.dep_handler = DeprecatedMessageHandler(link)
            settings_read_finished_functions = []
            self.tracking_view = TrackingView(self.link)
            self.solution_view = SolutionView(
                self.link, dirname=self.directory_name)
            self.baseline_view = BaselineView(
                self.link, dirname=self.directory_name)
            self.observation_view = ObservationView(
                self.link,
                name='Local',
                relay=False,
                dirname=self.directory_name)
            self.observation_view_base = ObservationView(
                self.link,
                name='Remote',
                relay=True,
                dirname=self.directory_name)
            self.system_monitor_view = SystemMonitorView(self.link)
            self.update_view = UpdateView(
                self.link,
                download_dir=swift_path,
                prompt=update,
                connection_info=self.connection_info)
            self.imu_view = IMUView(self.link)
            self.mag_view = MagView(self.link)
            self.spectrum_analyzer_view = SpectrumAnalyzerView(self.link)
            settings_read_finished_functions.append(
                self.update_view.compare_versions)
            self.networking_view = SbpRelayView(self.link)
            self.json_logging = json_logging
            self.csv_logging = False
            self.first_json_press = True
            if json_logging:
                self._start_json_logging(override_filename)
                self.json_logging = True
            # we set timer interval to 1200 milliseconds because we expect a heartbeat each second
            self.timer_cancel = call_repeatedly(1.2, self.check_heartbeat)

            # Once we have received the settings, update device_serial with
            # the Swift serial number which will be displayed in the window
            # title. This callback will also update the header route as used
            # by the networking view.

            def update_serial():
                mfg_id = None
                try:
                    self.uuid = self.settings_view.settings['system_info'][
                        'uuid'].value
                    mfg_id = self.settings_view.settings['system_info'][
                        'serial_number'].value
                except KeyError:
                    pass
                if mfg_id:
                    self.device_serial = 'PK' + str(mfg_id)

            skip_settings_read = False
            if 'mode' in self.connection_info:
                if self.connection_info['mode'] == 'file':
                    skip_settings_read = True

            settings_read_finished_functions.append(update_serial)
            self.settings_view = SettingsView(
                self.link,
                settings_read_finished_functions,
                skip_read=skip_settings_read)
            self.update_view.settings = self.settings_view.settings
            self.python_console_env = {
                'send_message': self.link,
                'link': self.link,
            }
            self.python_console_env.update(
                self.tracking_view.python_console_cmds)
            self.python_console_env.update(
                self.solution_view.python_console_cmds)
            self.python_console_env.update(
                self.baseline_view.python_console_cmds)
            self.python_console_env.update(
                self.observation_view.python_console_cmds)
            self.python_console_env.update(
                self.networking_view.python_console_cmds)
            self.python_console_env.update(
                self.system_monitor_view.python_console_cmds)
            self.python_console_env.update(
                self.update_view.python_console_cmds)
            self.python_console_env.update(self.imu_view.python_console_cmds)
            self.python_console_env.update(self.mag_view.python_console_cmds)
            self.python_console_env.update(
                self.settings_view.python_console_cmds)
            self.python_console_env.update(
                self.spectrum_analyzer_view.python_console_cmds)

        except:  # noqa
            import traceback
            traceback.print_exc()
            if self.error:
                os._exit(1)
コード例 #13
0
ファイル: console.py プロジェクト: jkretzmer/piksi_tools
    def __init__(self,
                 link,
                 update,
                 log_level_filter,
                 skip_settings=False,
                 error=False,
                 cnx_desc=None,
                 json_logging=False,
                 log_dirname=None,
                 override_filename=None,
                 log_console=False,
                 networking=None,
                 serial_upgrade=False):
        self.error = error
        self.cnx_desc = cnx_desc
        self.dev_id = cnx_desc
        self.num_sats = 0
        self.mode = ''
        self.forwarder = None
        self.latency = '--'
        # if we have passed a logfile, we set our directory to it
        override_filename = override_filename
        home = expanduser("~")
        swift_path = os.path.normpath(os.path.join(home, 'SwiftNav'))

        if log_dirname:
            self.directory_name = log_dirname
            if override_filename:
                override_filename = os.path.join(log_dirname,
                                                 override_filename)
        else:
            self.directory_name = swift_path

        # Start swallowing sys.stdout and sys.stderr
        self.console_output = OutputList(
            tfile=log_console, outdir=self.directory_name)
        sys.stdout = self.console_output
        self.console_output.write("Console: " + CONSOLE_VERSION +
                                  " starting...")
        if not error:
            sys.stderr = self.console_output

        self.log_level_filter = log_level_filter
        self.console_output.log_level_filter = str_to_log_level(
            log_level_filter)
        try:
            self.link = link
            self.link.add_callback(self.print_message_callback,
                                   SBP_MSG_PRINT_DEP)
            self.link.add_callback(self.log_message_callback, SBP_MSG_LOG)
            self.link.add_callback(self.ext_event_callback, SBP_MSG_EXT_EVENT)
            self.link.add_callback(self.cmd_resp_callback,
                                   SBP_MSG_COMMAND_RESP)
            self.link.add_callback(self.update_on_heartbeat, SBP_MSG_HEARTBEAT)
            self.dep_handler = DeprecatedMessageHandler(link)
            settings_read_finished_functions = []
            self.tracking_view = TrackingView(self.link)
            self.solution_view = SolutionView(
                self.link, dirname=self.directory_name)
            self.baseline_view = BaselineView(
                self.link, dirname=self.directory_name)
            self.observation_view = ObservationView(
                self.link,
                name='Local',
                relay=False,
                dirname=self.directory_name)
            self.observation_view_base = ObservationView(
                self.link,
                name='Remote',
                relay=True,
                dirname=self.directory_name)
            self.system_monitor_view = SystemMonitorView(self.link)
            self.update_view = UpdateView(
                self.link,
                download_dir=swift_path,
                prompt=update,
                serial_upgrade=serial_upgrade)
            self.imu_view = IMUView(self.link)
            self.spectrum_analyzer_view = SpectrumAnalyzerView(self.link)
            settings_read_finished_functions.append(
                self.update_view.compare_versions)
            if networking:
                from ruamel.yaml import YAML
                yaml = YAML(typ='safe')
                try:
                    networking_dict = yaml.load(networking)
                    networking_dict.update({'show_networking': True})
                except yaml.YAMLError:
                    print(
                        "Unable to interpret networking cmdline argument.  It will be ignored."
                    )
                    import traceback
                    print(traceback.format_exc())
                    networking_dict = {'show_networking': True}
            else:
                networking_dict = {}
            networking_dict.update({
                'whitelist': [SBP_MSG_POS_LLH, SBP_MSG_HEARTBEAT]
            })
            self.networking_view = SbpRelayView(self.link, **networking_dict)
            self.json_logging = json_logging
            self.csv_logging = False
            self.first_json_press = True
            if json_logging:
                self._start_json_logging(override_filename)
                self.json_logging = True
            # we set timer interval to 1200 milliseconds because we expect a heartbeat each second
            self.timer_cancel = call_repeatedly(1.2, self.check_heartbeat)

            # Once we have received the settings, update device_serial with
            # the Swift serial number which will be displayed in the window
            # title. This callback will also update the header route as used
            # by the networking view.

            def update_serial():
                uuid = None
                mfg_id = None
                try:
                    uuid = self.settings_view.settings['system_info'][
                        'uuid'].value
                    mfg_id = self.settings_view.settings['system_info'][
                        'serial_number'].value
                except KeyError:
                    pass
                if mfg_id:
                    self.device_serial = 'PK' + str(mfg_id)[-6:]
                self.networking_view.set_route(uuid=uuid, serial_id=mfg_id)
                if self.networking_view.connect_when_uuid_received:
                    self.networking_view._connect_rover_fired()

            settings_read_finished_functions.append(update_serial)
            self.settings_view = SettingsView(
                self.link,
                settings_read_finished_functions,
                skip=skip_settings)
            self.update_view.settings = self.settings_view.settings
            self.python_console_env = {
                'send_message': self.link,
                'link': self.link,
            }
            self.python_console_env.update(
                self.tracking_view.python_console_cmds)
            self.python_console_env.update(
                self.solution_view.python_console_cmds)
            self.python_console_env.update(
                self.baseline_view.python_console_cmds)
            self.python_console_env.update(
                self.observation_view.python_console_cmds)
            self.python_console_env.update(
                self.networking_view.python_console_cmds)
            self.python_console_env.update(
                self.system_monitor_view.python_console_cmds)
            self.python_console_env.update(
                self.update_view.python_console_cmds)
            self.python_console_env.update(self.imu_view.python_console_cmds)
            self.python_console_env.update(
                self.settings_view.python_console_cmds)
            self.python_console_env.update(
                self.spectrum_analyzer_view.python_console_cmds)

        except:
            import traceback
            traceback.print_exc()
            if self.error:
                sys.exit(1)