Class: Cosmos::DataViewer
- Defined in:
- lib/cosmos/tools/data_viewer/data_viewer.rb
Class Method Summary collapse
-
.run(option_parser = nil, options = nil) ⇒ Object
Class methods.
Instance Method Summary collapse
- #cancel_callback(progress_dialog = nil) ⇒ Object
- #closeEvent(event) ⇒ Object
- #context_menu(point) ⇒ Object
- #current_component ⇒ Object
- #delete_component(index) ⇒ Object
- #enable_disable_component_packet(index, target_name, packet_name, enabled) ⇒ Object
- #graceful_kill ⇒ Object
- #handle_open_log_file ⇒ Object
- #handle_pause ⇒ Object
- #handle_reset ⇒ Object
- #handle_start ⇒ Object
- #handle_stop ⇒ Object
- #handle_tab_change(index) ⇒ Object
-
#initialize(options) ⇒ DataViewer
constructor
A new instance of DataViewer.
- #initialize_actions ⇒ Object
- #initialize_central_widget ⇒ Object
- #initialize_menus ⇒ Object
- #kill_subscription_thread ⇒ Object
-
#on_tab_delete ⇒ Object
Handles deleting the current tab.
- #process_config ⇒ Object
-
#search_text ⇒ Object
Called by the FindReplaceDialog to get the text to search.
- #start_subscription_thread ⇒ Object
- #update_gui ⇒ Object
Methods inherited from QtTool
#about, #complete_initialize, create_default_options, graceful_kill, #initialize_help_menu, post_options_parsed_hook, pre_window_new_hook, redirect_io, restore_io
Constructor Details
#initialize(options) ⇒ DataViewer
Returns a new instance of DataViewer.
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 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 32 def initialize() super() # MUST BE FIRST - All code before super is executed twice in RubyQt Based classes Cosmos.load_cosmos_icon("data_viewer.png") initialize_actions() () () complete_initialize() # Initialize instance variables @auto_start = false @pause = false @log_file_directory = System.paths['LOGS'] @tlm_log_system = nil @subscription_thread = nil @subscription_id = nil @packet_log_reader = System.default_packet_log_reader.new @time_start = nil @time_end = nil @log_filenames = [] @cancel_thread = false @sleeper = Sleeper.new # Process config file and create a tab for each data viewer component @component_mutex = Mutex.new @components = [] @packets = [] @packet_to_components_mapping = {} @config_filename = File.join(Cosmos::USERPATH, 'config', 'tools', 'data_viewer', .config_file) process_config() # Load System Definition and Event Data Splash.execute(self) do |splash| Qt.execute_in_main_thread(true) do ConfigParser.splash = splash System.telemetry @components.each do |component| # Create tab for each component component.initialize_gui @tab_book.addTab(component, component.tab_name) end if @auto_start handle_start() end ConfigParser.splash = nil end end # Add GUI Update Timeout @timer = Qt::Timer.new(self) @timer.connect(SIGNAL('timeout()')) { update_gui() } @timer.method_missing(:start, 100) end |
Class Method Details
.run(option_parser = nil, options = nil) ⇒ Object
Class methods
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 596 def self.run(option_parser = nil, = nil) Cosmos.catch_fatal_exception do unless option_parser and option_parser, = () .width = 550 .height = 500 .title = "Data Viewer" .config_file = 'data_viewer.txt' option_parser.separator "Data Viewer Specific Options:" option_parser.on("-c", "--config FILE", "Use the specified configuration file") do |arg| .config_file = arg end end super(option_parser, ) end end |
Instance Method Details
#cancel_callback(progress_dialog = nil) ⇒ Object
457 458 459 460 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 457 def cancel_callback(progress_dialog = nil) @cancel_progress = true return true, false end |
#closeEvent(event) ⇒ Object
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 477 def closeEvent(event) # Stop GUI update timeout @pause = true # Stop Processing Packets handle_stop() # Shutdown each component @component_mutex.synchronize do @components.each {|component| component.shutdown} end # Give things time to complete sleep(0.1) # Standard COSMOS Shutdown shutdown_cmd_tlm() # Accept closure super(event) end |
#context_menu(point) ⇒ Object
225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 225 def (point) index = 0 (0..@tab_book.tabBar.count).each do |i| index = i if @tab_book.tabBar.tabRect(i).contains(point) end return if (index == @tab_book.tabBar.count) # Bring the right clicked tab to the front @tab_book.setCurrentIndex(index) @tab_menu.exec(@tab_book.mapToGlobal(point)) end |
#current_component ⇒ Object
182 183 184 185 186 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 182 def current_component @component_mutex.synchronize do yield @components[@tab_book.currentIndex()] end end |
#delete_component(index) ⇒ Object
542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 542 def delete_component(index) @component_mutex.synchronize do # Get the component to be deleted component = @components[index] # Delete from the components array @components.delete_at(index) # Delete from mapping @packet_to_components_mapping.each do |key, components| components.delete(component) end end end |
#enable_disable_component_packet(index, target_name, packet_name, enabled) ⇒ Object
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 557 def enable_disable_component_packet(index, target_name, packet_name, enabled) @component_mutex.synchronize do # Get the component to be deleted component = @components[index] key = target_name + ' ' + packet_name if enabled # Add to mapping components = @packet_to_components_mapping[key] components << component unless components.include?(component) else # Delete from mapping components = @packet_to_components_mapping[key] components.delete(component) end end end |
#graceful_kill ⇒ Object
318 319 320 321 322 323 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 318 def graceful_kill @cancel_thread = true @sleeper.cancel script_disconnect() # This will break out of get_packet_data Qt::CoreApplication.processEvents end |
#handle_open_log_file ⇒ Object
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 390 def handle_open_log_file # Prompt user for filename packet_log_dialog = PacketLogDialog.new(self, 'Open Log File(s):', @log_file_directory, @packet_log_reader, [], nil, false, true, true, Cosmos::TLM_FILE_PATTERN) begin packet_log_dialog.time_start = @time_start packet_log_dialog.time_end = @time_end case packet_log_dialog.exec when Qt::Dialog::Accepted @packet_log_reader = packet_log_dialog.packet_log_reader @log_filenames = packet_log_dialog.filenames.sort @time_start = packet_log_dialog.time_start @time_end = packet_log_dialog.time_end @log_file_directory = File.dirname(@log_filenames[0]) @log_file_directory << '/' unless @log_file_directory[-1..-1] == '\\' # Stop realtime collection handle_stop() # Reset components handle_reset() @cancel_progress = false ProgressDialog.execute(self, 'Processing Log File', 500, 200, @log_filenames.length > 1, true, true, true, true) do |dialog| dialog.cancel_callback = method(:cancel_callback) dialog. @log_filenames.each_with_index do |filename, file_index| break if @cancel_progress Qt.execute_in_main_thread(true) do self.setWindowTitle("Data Viewer : #{filename}") end file_size = File.size(filename).to_f dialog.append_text("Processing: #{filename}") Cosmos.check_log_configuration(@packet_log_reader, filename) @packet_log_reader.each(filename, true, @time_start, @time_end) do |packet| break if @cancel_progress progress = @packet_log_reader.bytes_read.to_f / file_size dialog.set_step_progress(progress) # Route packet to its component(s) index = packet.target_name + ' ' + packet.packet_name components = @packet_to_components_mapping[index] if components @component_mutex.synchronize do components.each do |component| component.process_packet(packet) end end end end dialog.set_overall_progress((file_index + 1).to_f / @log_filenames.length) if @log_filenames.length > 1 end dialog.append_text("Done!") dialog.set_step_progress(1.0) dialog.set_overall_progress(1.0) if @log_filenames.length > 1 dialog.complete end end ensure packet_log_dialog.dispose if packet_log_dialog end end |
#handle_pause ⇒ Object
361 362 363 364 365 366 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 361 def handle_pause @pause = true if @subscription_thread @realtime_button_bar.state = 'Paused' end end |
#handle_reset ⇒ Object
325 326 327 328 329 330 331 332 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 325 def handle_reset @component_mutex.synchronize do @components.each do |component| component.reset end end System.telemetry.reset end |
#handle_start ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 334 def handle_start if windowTitle() != 'Data Viewer' # Clear Title setWindowTitle('Data Viewer') # Return to default configuration # Show splash during possible reconfiguration Splash.execute(self) do |splash| ConfigParser.splash = splash System.load_configuration ConfigParser.splash = nil end # Reset Components handle_reset() end # Restart GUI Updates if necessary if @pause @pause = false @timer.method_missing(:start, 100) end # Restart Subscription Thread if necessary start_subscription_thread() end |
#handle_stop ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 368 def handle_stop # Shutdown packet subscription thread kill_subscription_thread() # Unsubscribe from subscription if @subscription_id begin unsubscribe_packet_data(@subscription_id) rescue DRb::DRbConnError # Do Nothing end end # Restart GUI Updates if necessary if @pause @pause = false @timer.method_missing(:start, 100) end @realtime_button_bar.state = 'Stopped' end |
#handle_tab_change(index) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 195 def handle_tab_change(index) # Remove existing actions @tab_menu_actions.each do |action| @tab_menu.removeAction(action) action.dispose end @tab_menu_actions = [] # Add new actions unless @components.empty? @component_mutex.synchronize do component = @components[index] component.packets.each do |target_name, packet_name| action = Qt::Action.new("#{target_name} #{packet_name}", @tab_menu) action.setCheckable(true) key = target_name + ' ' + packet_name components = @packet_to_components_mapping[key] if components.include?(component) action.setChecked(true) else action.setChecked(false) end action.connect(SIGNAL('triggered()')) { enable_disable_component_packet(index, target_name, packet_name, action.checked?) } @tab_menu.addAction(action) @tab_menu_actions << action end end end end |
#initialize_actions ⇒ Object
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 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 86 def initialize_actions super() # File Menu Actions @open_log = Qt::Action.new(tr('&Open Log File'), self) @open_log_keyseq = Qt::KeySequence.new(tr('Ctrl+O')) @open_log.shortcut = @open_log_keyseq @open_log.statusTip = tr('Open telemetry log file for processing') @open_log.connect(SIGNAL('triggered()')) { handle_open_log_file() } @handle_reset = Qt::Action.new(tr('&Reset'), self) @handle_reset_keyseq = Qt::KeySequence.new(tr('Ctrl+R')) @handle_reset.shortcut = @handle_reset_keyseq @handle_reset.statusTip = tr('Reset Components') @handle_reset.connect(SIGNAL('triggered()')) { handle_reset() } # Search Actions @search_find = Qt::Action.new(Cosmos.get_icon('search.png'), tr('&Find'), self) @search_find_keyseq = Qt::KeySequence.new(tr('Ctrl+F')) @search_find.shortcut = @search_find_keyseq @search_find.statusTip = tr('Find text') @search_find.connect(SIGNAL('triggered()')) do FindReplaceDialog.show_find(self) end @search_find_next = Qt::Action.new(tr('Find &Next'), self) @search_find_next_keyseq = Qt::KeySequence.new(tr('F3')) @search_find_next.shortcut = @search_find_next_keyseq @search_find_next.statusTip = tr('Find next instance') @search_find_next.connect(SIGNAL('triggered()')) do FindReplaceDialog.find_next(self) end @search_find_previous = Qt::Action.new(tr('Find &Previous'), self) @search_find_previous_keyseq = Qt::KeySequence.new(tr('Shift+F3')) @search_find_previous.shortcut = @search_find_previous_keyseq @search_find_previous.statusTip = tr('Find previous instance') @search_find_previous.connect(SIGNAL('triggered()')) do FindReplaceDialog.find_previous(self) end # Tab Menu Actions @delete_tab = Qt::Action.new(Cosmos.get_icon('delete_tab.png'), tr('&Delete Tab'), self) @delete_tab.statusTip = tr('Delete active tab') @delete_tab.connect(SIGNAL('triggered()')) { on_tab_delete() } end |
#initialize_central_widget ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 158 def # Create the central widget @central_widget = Qt::Widget.new setCentralWidget(@central_widget) # Create the top level vertical layout @top_layout = Qt::VBoxLayout.new(@central_widget) # Realtime Button Bar @realtime_button_bar = RealtimeButtonBar.new(self) @realtime_button_bar.start_callback = method(:handle_start) @realtime_button_bar.pause_callback = method(:handle_pause) @realtime_button_bar.stop_callback = method(:handle_stop) @realtime_button_bar.state = 'Stopped' @top_layout.addWidget(@realtime_button_bar) # Create tab book @tab_book = Qt::TabWidget.new @tab_book.setContextMenuPolicy(Qt::CustomContextMenu) connect(@tab_book, SIGNAL('currentChanged(int)'), self, SLOT('handle_tab_change(int)')) connect(@tab_book, SIGNAL('customContextMenuRequested(const QPoint&)'), self, SLOT('context_menu(const QPoint&)')) @top_layout.addWidget(@tab_book) end |
#initialize_menus ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 133 def # File Menu = .addMenu(tr('&File')) .addAction(@open_log) .addAction(@handle_reset) .addSeparator() .addAction(@exit_action) # Tab Menu @tab_menu = .addMenu(tr('&Tab')) @tab_menu.addAction(@delete_tab) @tab_menu.addSeparator() @tab_menu_actions = [] # Search Menu = .addMenu(tr('&Search')) .addAction(@search_find) .addAction(@search_find_next) .addAction(@search_find_previous) # Help Menu @about_string = "Data Viewer is designed to allow users view data that is not easily displayed on telemetry screens." () end |
#kill_subscription_thread ⇒ Object
313 314 315 316 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 313 def kill_subscription_thread Cosmos.kill_thread(self, @subscription_thread) @subscription_thread = nil end |
#on_tab_delete ⇒ Object
Handles deleting the current tab
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 576 def on_tab_delete if @tab_book.currentIndex() and @tab_book.currentIndex() >= 0 case Qt::MessageBox.warning(self, 'Warning!', "Are you sure you want to delete the active tab?", Qt::MessageBox::Yes | Qt::MessageBox::No, Qt::MessageBox::No) when Qt::MessageBox::Yes # Remove component tab_index = @tab_book.currentIndex() delete_component(tab_index) @tab_book.removeTab(tab_index) statusBar.showMessage(tr("Tab Deleted")) end else Qt::MessageBox.information(self, 'Info', "No tabs exist") end end |
#process_config ⇒ Object
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 499 def process_config # ensure the file exists unless test ?f, @config_filename raise "Configuration File Does not Exist: #{@config_filename}" end parser = ConfigParser.new parser.parse_file(@config_filename) do |keyword, params| case keyword when 'AUTO_START' usage = "#{keyword}" parser.verify_num_parameters(0, 0, usage) @auto_start = true when 'COMPONENT' usage = "#{keyword} <tab name> <component class filename> <component specific options...>" parser.verify_num_parameters(2, nil, usage) component_class = Cosmos.require_class(params[1]) if params.length >= 3 @components << component_class.new(self, params[0], *params[2..-1]) else @components << component_class.new(self, params[0]) end when 'PACKET' usage = "#{keyword} <target_name> <packet_name>" parser.verify_num_parameters(2, 2, usage) target_name = params[0].upcase packet_name = params[1].upcase @packets << [target_name, packet_name] @components[-1].add_packet(target_name, packet_name) index = target_name + ' ' + packet_name @packet_to_components_mapping[index] ||= [] @packet_to_components_mapping[index] << @components[-1] # Unknown keyword else raise "Unhandled keyword: #{keyword}" if keyword end end end |
#search_text ⇒ Object
Called by the FindReplaceDialog to get the text to search
189 190 191 192 193 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 189 def search_text current_component do |component| component.text end end |
#start_subscription_thread ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 238 def start_subscription_thread unless @subscription_thread # Start Thread to Gather Events @subscription_thread = Thread.new do @cancel_thread = false @sleeper = Sleeper.new if !@packets.empty? begin while true break if @cancel_thread begin @subscription_id = subscribe_packet_data(@packets, 10000) break if @cancel_thread if @pause Qt.execute_in_main_thread(true) { @realtime_button_bar.state = 'Paused' } else Qt.execute_in_main_thread(true) { @realtime_button_bar.state = 'Running' } end Qt.execute_in_main_thread(true) { statusBar.showMessage("Connected to Command and Telemetry Server: #{Time.now.formatted}") } rescue DRb::DRbConnError break if @cancel_thread Qt.execute_in_main_thread(true) do @realtime_button_bar.state = 'Connecting' statusBar.showMessage(tr("Error Connecting to Command and Telemetry Server")) end break if @sleeper.sleep(1) break if @cancel_thread retry end while true break if @cancel_thread begin # Get a subscribed to packet packet_data, target_name, packet_name, received_time, received_count = get_packet_data(@subscription_id) # Put packet data into its packet packet = System.telemetry.packet(target_name, packet_name) packet.buffer = packet_data packet.received_time = received_time packet.received_count = received_count # Route packet to its component(s) index = packet.target_name + ' ' + packet.packet_name @component_mutex.synchronize do components = @packet_to_components_mapping[index] if components components.each do |component| component.process_packet(packet) end end end rescue DRb::DRbConnError break if @cancel_thread Qt.execute_in_main_thread(true) { statusBar.showMessage(tr("Error Connecting to Command and Telemetry Server")) } break # Let outer loop resubscribe rescue RuntimeError => error raise error unless error. =~ /queue/ break if @cancel_thread Qt.execute_in_main_thread(true) { statusBar.showMessage(tr("Connection Dropped by Command and Telemetry Server: #{Time.now.formatted}")) } break # Let outer loop resubscribe end end end rescue Exception => error break if @cancel_thread Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(self, error, "Data Viewer : Subscription Thread")} end end # if [email protected] end else Qt.execute_in_main_thread(true) { @realtime_button_bar.state = 'Running' } end end |
#update_gui ⇒ Object
462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/cosmos/tools/data_viewer/data_viewer.rb', line 462 def update_gui if @pause @timer.method_missing(:stop) else Qt.execute_in_main_thread(true) do @component_mutex.synchronize do @components.each do |component| break if @pause component.update_gui end end end end end |