def __init__(self, link, update, log_level_filter): self.console_output = OutputList() self.console_output.write("Console: starting...") sys.stdout = self.console_output 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) 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.sbp_relay_view = SbpRelayView(self.link) 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) # Once we have received the settings, update device_serial with the Piksi # serial number which will be displayed in the window title def update_serial(): serial_string = self.settings_view.settings['system_info']['serial_number'].value self.device_serial = 'PK%04d' % int(serial_string) settings_read_finished_functions.append(update_serial) self.settings_view = \ SettingsView(self.link, settings_read_finished_functions, hide_expert = not args.expert) 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.sbp_relay_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()
def __init__(self, link, update, log_level_filter): self.console_output = OutputList() self.console_output.write("Console: starting...") sys.stdout = self.console_output 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) 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.sbp_relay_view = SbpRelayView(self.link) 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) # Once we have received the settings, update device_serial with the Piksi # serial number which will be displayed in the window title def update_serial(): serial_string = self.settings_view.settings['system_info'][ 'serial_number'].value self.device_serial = 'PK%04d' % int(serial_string) settings_read_finished_functions.append(update_serial) self.settings_view = \ SettingsView(self.link, settings_read_finished_functions, hide_expert = not args.expert) 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.sbp_relay_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()
class SwiftConsole(HasTraits): link = Instance(sbp.client.Handler) console_output = Instance(OutputList()) python_console_env = Dict device_serial = Str('') a = Int b = Int tracking_view = Instance(TrackingView) solution_view = Instance(SolutionView) baseline_view = Instance(BaselineView) observation_view = Instance(ObservationView) sbp_relay_view = Instance(SbpRelayView) observation_view_base = Instance(ObservationView) system_monitor_view = Instance(SystemMonitorView) settings_view = Instance(SettingsView) update_view = Instance(UpdateView) log_level_filter = Enum(list(SYSLOG_LEVELS.itervalues())) paused_button = SVGButton( label='', tooltip='Pause console update', toggle_tooltip='Resume console update', toggle=True, filename=os.path.join(os.path.dirname(__file__), 'images', 'iconic', 'pause.svg'), toggle_filename=os.path.join(os.path.dirname(__file__), 'images', 'iconic', 'play.svg'), width=8, height=8) clear_button = SVGButton(label='', tooltip='Clear console buffer', filename=os.path.join(os.path.dirname(__file__), 'images', 'iconic', 'x.svg'), width=8, height=8) view = View(VSplit( Tabbed(Item('tracking_view', style='custom', label='Tracking'), Item('solution_view', style='custom', label='Solution'), Item('baseline_view', style='custom', label='Baseline'), VSplit( Item('observation_view', style='custom', show_label=False), Item('observation_view_base', style='custom', show_label=False), label='Observations', ), Item('settings_view', style='custom', label='Settings'), Item('update_view', style='custom', label='Firmware Update'), Tabbed(Item('system_monitor_view', style='custom', label='System Monitor'), Item('sbp_relay_view', label='SBP Relay', style='custom', show_label=False), Item('python_console_env', style='custom', label='Python Console', editor=ShellEditor()), label='Advanced', show_labels=False), show_labels=False), VGroup( HGroup( Spring(width=4, springy=False), Item('paused_button', show_label=False, width=8, height=8), Item('clear_button', show_label=False, width=8, height=8), Item('', label='Console Log', emphasized=True), Spring(), UItem( 'log_level_filter', style='simple', padding=0, height=8, show_label=True, tooltip= 'Show log levels up to and including the selected level of severity.\nThe CONSOLE log level is always visible.' ), ), Item( 'console_output', style='custom', editor=InstanceEditor(), height=0.3, show_label=False, ), )), icon=icon, resizable=True, width=1000, height=600, handler=ConsoleHandler(), title=CONSOLE_TITLE) 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." def log_message_callback(self, sbp_msg, **metadata): try: encoded = sbp_msg.text.encode('ascii', 'ignore') for eachline in reversed(encoded.split('\n')): self.console_output.write_level(eachline, sbp_msg.level) except UnicodeDecodeError: print "Critical Error encoding the serial stream as ascii." def ext_event_callback(self, sbp_msg, **metadata): e = MsgExtEvent(sbp_msg) print 'External event: %s edge on pin %d at wn=%d, tow=%d, time qual=%s' % ( "Rising" if (e.flags & (1 << 0)) else "Falling", e.pin, e.wn, e.tow, "good" if (e.flags & (1 << 1)) else "unknown") def _paused_button_fired(self): self.console_output.paused = not self.console_output.paused 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) def _clear_button_fired(self): self.console_output.clear() def __init__(self, link, update, log_level_filter): self.console_output = OutputList() self.console_output.write("Console: starting...") sys.stdout = self.console_output 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) 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.sbp_relay_view = SbpRelayView(self.link) 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) # Once we have received the settings, update device_serial with the Piksi # serial number which will be displayed in the window title def update_serial(): serial_string = self.settings_view.settings['system_info'][ 'serial_number'].value self.device_serial = 'PK%04d' % int(serial_string) settings_read_finished_functions.append(update_serial) self.settings_view = \ SettingsView(self.link, settings_read_finished_functions, hide_expert = not args.expert) 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.sbp_relay_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()
class SwiftConsole(HasTraits): """Traits-defined Swift Console. link : object Serial driver update : bool Update the firmware log_level_filter : str Syslog string, one of "ERROR", "WARNING", "INFO", "DEBUG". skip_settings : bool Don't read the device settings. Set to False when the console is reading from a network connection only. """ link = Instance(sbpc.Handler) console_output = Instance(OutputList()) python_console_env = Dict device_serial = Str("") a = Int b = Int tracking_view = Instance(TrackingView) solution_view = Instance(SolutionView) baseline_view = Instance(BaselineView) observation_view = Instance(ObservationView) sbp_relay_view = Instance(SbpRelayView) observation_view_base = Instance(ObservationView) system_monitor_view = Instance(SystemMonitorView) settings_view = Instance(SettingsView) update_view = Instance(UpdateView) log_level_filter = Enum(list(SYSLOG_LEVELS.itervalues())) paused_button = SVGButton( label="", tooltip="Pause console update", toggle_tooltip="Resume console update", toggle=True, filename=os.path.join(os.path.dirname(__file__), "images", "iconic", "pause.svg"), toggle_filename=os.path.join(os.path.dirname(__file__), "images", "iconic", "play.svg"), width=8, height=8, ) clear_button = SVGButton( label="", tooltip="Clear console buffer", filename=os.path.join(os.path.dirname(__file__), "images", "iconic", "x.svg"), width=8, height=8, ) view = View( VSplit( Tabbed( Item("tracking_view", style="custom", label="Tracking"), Item("solution_view", style="custom", label="Solution"), Item("baseline_view", style="custom", label="Baseline"), VSplit( Item("observation_view", style="custom", show_label=False), Item("observation_view_base", style="custom", show_label=False), label="Observations", ), Item("settings_view", style="custom", label="Settings"), Item("update_view", style="custom", label="Firmware Update"), Tabbed( Item("system_monitor_view", style="custom", label="System Monitor"), Item("sbp_relay_view", label="SBP Relay", style="custom", show_label=False), Item("python_console_env", style="custom", label="Python Console", editor=ShellEditor()), label="Advanced", show_labels=False, ), show_labels=False, ), VGroup( HGroup( Spring(width=4, springy=False), Item("paused_button", show_label=False, width=8, height=8), Item("clear_button", show_label=False, width=8, height=8), Item("", label="Console Log", emphasized=True), Spring(), UItem( "log_level_filter", style="simple", padding=0, height=8, show_label=True, tooltip="Show log levels up to and including the selected level of severity.\nThe CONSOLE log level is always visible.", ), ), Item("console_output", style="custom", editor=InstanceEditor(), height=0.3, show_label=False), ), ), icon=icon, resizable=True, width=1000, height=600, handler=ConsoleHandler(), title=CONSOLE_TITLE, ) 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." def log_message_callback(self, sbp_msg, **metadata): try: encoded = sbp_msg.text.encode("ascii", "ignore") for eachline in reversed(encoded.split("\n")): self.console_output.write_level(eachline, sbp_msg.level) except UnicodeDecodeError: print "Critical Error encoding the serial stream as ascii." def ext_event_callback(self, sbp_msg, **metadata): e = MsgExtEvent(sbp_msg) print "External event: %s edge on pin %d at wn=%d, tow=%d, time qual=%s" % ( "Rising" if (e.flags & (1 << 0)) else "Falling", e.pin, e.wn, e.tow, "good" if (e.flags & (1 << 1)) else "unknown", ) def _paused_button_fired(self): self.console_output.paused = not self.console_output.paused 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) def _clear_button_fired(self): self.console_output.clear() def __init__(self, link, update, log_level_filter, skip_settings=False): self.console_output = OutputList() self.console_output.write("Console: starting...") sys.stdout = self.console_output 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) 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.sbp_relay_view = SbpRelayView(self.link) 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) # Once we have received the settings, update device_serial with the Piksi # serial number which will be displayed in the window title def update_serial(): serial_string = self.settings_view.settings["system_info"]["serial_number"].value self.device_serial = "PK%04d" % int(serial_string) settings_read_finished_functions.append(update_serial) self.settings_view = SettingsView( self.link, settings_read_finished_functions, hide_expert=not args.expert, 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.sbp_relay_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()
class SwiftConsole(HasTraits): link = Instance(sbp.client.Handler) console_output = Instance(OutputList()) python_console_env = Dict device_serial = Str('') a = Int b = Int tracking_view = Instance(TrackingView) solution_view = Instance(SolutionView) baseline_view = Instance(BaselineView) observation_view = Instance(ObservationView) sbp_relay_view = Instance(SbpRelayView) observation_view_base = Instance(ObservationView) system_monitor_view = Instance(SystemMonitorView) settings_view = Instance(SettingsView) update_view = Instance(UpdateView) log_level_filter = Enum(list(SYSLOG_LEVELS.itervalues())) paused_button = SVGButton( label='', tooltip='Pause console update', toggle_tooltip='Resume console update', toggle=True, filename=os.path.join(os.path.dirname(__file__), 'images', 'iconic', 'pause.svg'), toggle_filename=os.path.join(os.path.dirname(__file__), 'images', 'iconic', 'play.svg'), width=8, height=8 ) clear_button = SVGButton( label='', tooltip='Clear console buffer', filename=os.path.join(os.path.dirname(__file__), 'images', 'iconic', 'x.svg'), width=8, height=8 ) view = View( VSplit( Tabbed( Item('tracking_view', style='custom', label='Tracking'), Item('solution_view', style='custom', label='Solution'), Item('baseline_view', style='custom', label='Baseline'), VSplit( Item('observation_view', style='custom', show_label=False), Item('observation_view_base', style='custom', show_label=False), label='Observations', ), Item('settings_view', style='custom', label='Settings'), Item('update_view', style='custom', label='Firmware Update'), Tabbed( Item('system_monitor_view', style='custom', label='System Monitor'), Item('sbp_relay_view', label='SBP Relay', style='custom', show_label=False), Item( 'python_console_env', style='custom', label='Python Console', editor=ShellEditor()), label='Advanced', show_labels=False ), show_labels=False ), VGroup( HGroup( Spring(width=4, springy=False), Item('paused_button', show_label=False, width=8, height=8), Item('clear_button', show_label=False, width=8, height=8), Item('', label='Console Log', emphasized=True), Spring(), UItem('log_level_filter', style='simple', padding=0, height=8, show_label=True, tooltip='Show log levels up to and including the selected level of severity.\nThe CONSOLE log level is always visible.'), ), Item( 'console_output', style='custom', editor=InstanceEditor(), height=0.3, show_label=False, ), ) ), icon = icon, resizable = True, width = 1000, height = 600, handler = ConsoleHandler(), title = CONSOLE_TITLE ) 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." def log_message_callback(self, sbp_msg, **metadata): try: encoded = sbp_msg.text.encode('ascii', 'ignore') for eachline in reversed(encoded.split('\n')): self.console_output.write_level(eachline, sbp_msg.level) except UnicodeDecodeError: print "Critical Error encoding the serial stream as ascii." def ext_event_callback(self, sbp_msg, **metadata): e = MsgExtEvent(sbp_msg) print 'External event: %s edge on pin %d at wn=%d, tow=%d, time qual=%s' % ( "Rising" if (e.flags & (1<<0)) else "Falling", e.pin, e.wn, e.tow, "good" if (e.flags & (1<<1)) else "unknown") def _paused_button_fired(self): self.console_output.paused = not self.console_output.paused 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) def _clear_button_fired(self): self.console_output.clear() def __init__(self, link, update, log_level_filter): self.console_output = OutputList() self.console_output.write("Console: starting...") sys.stdout = self.console_output 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) 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.sbp_relay_view = SbpRelayView(self.link) 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) # Once we have received the settings, update device_serial with the Piksi # serial number which will be displayed in the window title def update_serial(): serial_string = self.settings_view.settings['system_info']['serial_number'].value self.device_serial = 'PK%04d' % int(serial_string) settings_read_finished_functions.append(update_serial) self.settings_view = \ SettingsView(self.link, settings_read_finished_functions, hide_expert = not args.expert) 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.sbp_relay_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()