Class: Cosmos::CmdTlmServerGui
- Defined in:
- lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb
Overview
Implements the GUI functions of the Command and Telemetry Server. All the QT calls are implemented here. The non-GUI functionality is contained in the CmdTlmServer class.
Constant Summary collapse
- STOPPED =
0
- RUNNING =
1
- ERROR =
2
- CMD =
"Command"
- TLM =
"Telemetry"
Class Method Summary collapse
Instance Method Summary collapse
- #closeEvent(event) ⇒ Object
- #create_log_layout(form_layout, log_writer, label_prefix) ⇒ Object
-
#edit_clear_counters ⇒ Object
Edit->Clear Counters.
- #get_cmd_tlm_def(name) ⇒ Object
- #graceful_kill ⇒ Object
- #handle_interfaces_tab(name) ⇒ Object
- #handle_logging_tab ⇒ Object
- #handle_packets_tab(name) ⇒ Object
- #handle_status_tab ⇒ Object
- #handle_string_output ⇒ Object
- #handle_tab_change(index) ⇒ Object
- #handle_targets_tab ⇒ Object
-
#initialize(options) ⇒ CmdTlmServerGui
constructor
A new instance of CmdTlmServerGui.
- #initialize_actions ⇒ Object
- #initialize_central_widget ⇒ Object
- #initialize_menus ⇒ Object
- #kill_tab_thread ⇒ Object
- #meta_callback(meta_target_name, meta_packet_name) ⇒ Object
- #populate_interfaces(name) ⇒ Object
- #populate_log_file_info(layout) ⇒ Object
- #populate_logging ⇒ Object
- #populate_logging_actions(layout) ⇒ Object
- #populate_packets(name) ⇒ Object
- #populate_status ⇒ Object
- #populate_targets ⇒ Object
- #process_server_messages(options) ⇒ Object
- #stop_callback ⇒ Object
- #update_filename_and_logging_state ⇒ 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) ⇒ CmdTlmServerGui
Returns a new instance of CmdTlmServerGui.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 50 def initialize() super() # MUST BE FIRST - All code before super is executed twice in RubyQt Based classes Cosmos.load_cosmos_icon("cts.png") @production = .production @no_prompt = .no_prompt @message_log = nil @output_sleeper = Sleeper.new statusBar.showMessage(tr("")) # Show blank message to initialize status bar initialize_actions() () () complete_initialize() Splash.execute(self) do |splash| ConfigParser.splash = splash splash. = "Initializing #{CMD} and #{TLM} Server" # Start the thread that will process server messages and add them to the output text () CmdTlmServer. = method(:meta_callback) cts = CmdTlmServer.new(.config_file, @production) cts.stop_callback = method(:stop_callback) @message_log = CmdTlmServer. # Now that we've started the server (CmdTlmServer.new) we can populate all the tabs splash. = "Populating Tabs" Qt.execute_in_main_thread(true) do # Override the default title if one was given in the config file self.window_title = CmdTlmServer.title if CmdTlmServer.title splash.progress = 0 populate_interfaces('Interfaces') splash.progress = 100/7 * 1 populate_targets() splash.progress = 100/7 * 2 populate_packets(CMD) splash.progress = 100/7 * 3 populate_packets(TLM) splash.progress = 100/7 * 4 populate_interfaces('Routers') splash.progress = 100/7 * 5 populate_logging() splash.progress = 100/7 * 6 populate_status() splash.progress = 100 end ConfigParser.splash = nil end end |
Class Method Details
.run(option_parser = nil, options = nil) ⇒ Object
960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 960 def self.run(option_parser = nil, = nil) Cosmos.catch_fatal_exception do unless option_parser and option_parser, = () .width = 800 .height = 500 # Set the default title which can be overridden in the config file .title = "#{CMD} and #{TLM} Server" .auto_size = false .config_file = CmdTlmServer::DEFAULT_CONFIG_FILE .production = false .no_prompt = false option_parser.separator "CTS Specific Options:" option_parser.on("-c", "--config FILE", "Use the specified configuration file") do |arg| .config_file = arg end option_parser.on("-p", "--production", "Run the server in production mode which disables the ability to stop logging.") do |arg| .production = true end option_parser.on("-n", "--no-prompt", "Don't prompt with Are You Sure dialog on close.") do |arg| .no_prompt = true end end super(option_parser, ) end end |
Instance Method Details
#closeEvent(event) ⇒ Object
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 935 def closeEvent(event) # Create are you sure dialog if @no_prompt continue = true else msg = Qt::MessageBox.new(self) msg.setIcon(Qt::MessageBox::Question) msg.setText("Are you sure? All tools connected to this CmdTlmServer will lose connections and cease to function if the CmdTlmServer is closed.") msg.setWindowTitle('Confirm Close') msg.setStandardButtons(Qt::MessageBox::Yes | Qt::MessageBox::No) continue = false continue = true if msg.exec() == Qt::MessageBox::Yes msg.dispose end if continue kill_tab_thread() CmdTlmServer.instance.stop_logging('ALL') CmdTlmServer.instance.stop super(event) else event.ignore() end end |
#create_log_layout(form_layout, log_writer, label_prefix) ⇒ Object
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 598 def create_log_layout(form_layout, log_writer, label_prefix) label = Qt::Label.new(tr(log_writer.logging_enabled.to_s)) label.setTextInteractionFlags(Qt::TextSelectableByMouse) form_layout.addRow("#{label_prefix} Logging:", label) label = Qt::Label.new(tr(log_writer.queue.size.to_s)) label.setTextInteractionFlags(Qt::TextSelectableByMouse) form_layout.addRow("#{label_prefix} Queue Size:", label) label = Qt::Label.new(tr(log_writer.filename)) label.setTextInteractionFlags(Qt::TextSelectableByMouse) form_layout.addRow("#{label_prefix} Filename:", label) file_size = 0 begin file_size = File.size(log_writer.filename) if log_writer.filename rescue Exception # Do nothing on error end label = Qt::Label.new(tr(file_size.to_s)) label.setTextInteractionFlags(Qt::TextSelectableByMouse) form_layout.addRow("#{label_prefix} File Size:", label) end |
#edit_clear_counters ⇒ Object
Edit->Clear Counters
133 134 135 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 133 def edit_clear_counters CmdTlmServer.clear_counters end |
#get_cmd_tlm_def(name) ⇒ Object
441 442 443 444 445 446 447 448 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 441 def get_cmd_tlm_def(name) case name when CMD return System.commands when TLM return System.telemetry end end |
#graceful_kill ⇒ Object
1028 1029 1030 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 1028 def graceful_kill # Just to avoid warning end |
#handle_interfaces_tab(name) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 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 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 316 def handle_interfaces_tab(name) @tab_thread = Thread.new do if @interfaces_table[name] begin while true Qt.execute_in_main_thread(true) do row = 0 if name == 'Routers' interfaces = CmdTlmServer.routers else interfaces = CmdTlmServer.interfaces end interfaces.all.each do |interface_name, interface| = @interfaces_table[name].cellWidget(row,1) state = @interfaces_table[name].item(row,2) if interface.connected? .setText('Disconnect') .setDisabled(true) if interface.disable_disconnect state.setText('true') state.textColor = Cosmos::GREEN elsif interface.thread .text = 'Cancel Connect' .setDisabled(false) state.text = 'attempting' state.textColor = Cosmos::RED else .setText('Connect') .setDisabled(false) state.setText('false') state.textColor = Cosmos::BLACK end @interfaces_table[name].item(row,3).setText(interface.num_clients.to_s) @interfaces_table[name].item(row,4).setText(interface.write_queue_size.to_s) @interfaces_table[name].item(row,5).setText(interface.read_queue_size.to_s) @interfaces_table[name].item(row,6).setText(interface.bytes_written.to_s) @interfaces_table[name].item(row,7).setText(interface.bytes_read.to_s) if name == 'Routers' @interfaces_table[name].item(row,8).setText(interface.read_count.to_s) @interfaces_table[name].item(row,9).setText(interface.write_count.to_s) else @interfaces_table[name].item(row,8).setText(interface.write_count.to_s) @interfaces_table[name].item(row,9).setText(interface.read_count.to_s) end row += 1 end end break if @tab_sleeper.sleep(1) end rescue Exception => error Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(self, error, "COSMOS CTS : #{name} Tab Thread")} end end end end |
#handle_logging_tab ⇒ Object
714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 714 def handle_logging_tab @tab_thread = Thread.new do begin while true Qt.execute_in_main_thread(true) do update_filename_and_logging_state() end break if @tab_sleeper.sleep(1) end rescue Exception => error Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(self, error, "COSMOS CTS : Logging Tab Thread")} end end end |
#handle_packets_tab(name) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 538 def handle_packets_tab(name) cmd_tlm = get_cmd_tlm_def(name) @tab_thread = Thread.new do begin unless cmd_tlm.target_names.empty? while true Qt.execute_in_main_thread(true) do row = 0 cmd_tlm.target_names.sort.each do |target_name| packets = cmd_tlm.packets(target_name) packets.sort.each do |packet_name, packet| next if packet.hidden @packets_table[name].item(row, 2).setText(packet.received_count.to_s) row += 1 end end end break if @tab_sleeper.sleep(1) end end rescue Exception => error Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(self, error, "COSMOS CTS : #{name} Packets Tab Thread")} end end end |
#handle_status_tab ⇒ Object
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 857 def handle_status_tab @tab_thread = Thread.new do begin if CmdTlmServer.json_drb previous_request_count = CmdTlmServer.json_drb.request_count else previous_request_count = 0 end while true start_time = Time.now Qt.execute_in_main_thread(true) do # Update limits set current_limits_set = System.limits_set.to_s if @limits_set_combo.currentText != current_limits_set known_limits_sets = System.limits.sets known_limits_sets = known_limits_sets.map {|x| x.to_s}.sort current_index = known_limits_sets.index(current_limits_set.to_s) @limits_set_combo.clear known_limits_sets.sort.each do |limits_set| @limits_set_combo.addItem(limits_set.to_s) end @limits_set_combo.setCurrentIndex(current_index) end # Update API status if CmdTlmServer.json_drb @api_table.item(0,1).setText(CmdTlmServer.json_drb.num_clients.to_s) @api_table.item(0,2).setText(CmdTlmServer.json_drb.request_count.to_s) request_count = CmdTlmServer.json_drb.request_count requests_per_second = request_count - previous_request_count @api_table.item(0,3).setText(requests_per_second.to_s) previous_request_count = request_count average_request_time = CmdTlmServer.json_drb.average_request_time @api_table.item(0,4).setText(sprintf("%0.6f s", average_request_time)) estimated_utilization = requests_per_second * average_request_time * 100.0 @api_table.item(0,5).setText(sprintf("%0.2f %", estimated_utilization)) end # Update system status @system_table.item(0,0).setText(Thread.list.length.to_s) objs = ObjectSpace.count_objects @system_table.item(0,1).setText(objs[:TOTAL].to_s) @system_table.item(0,2).setText(objs[:FREE].to_s) total = 0 objs.each do |key, val| next if key == :TOTAL || key == :FREE total += val end @system_table.item(0,3).setText(total.to_s) # Update background task status background_tasks = CmdTlmServer.background_tasks.all if background_tasks.length > 0 row = 0 background_tasks.each_with_index do |background_task, index| if background_task.thread status = background_task.thread.status status = 'complete' if status == false @background_tasks_table.item(row, 1).setText(status.to_s) else @background_tasks_table.item(row, 1).setText('no thread') end @background_tasks_table.item(row, 2).setText(background_task.status.to_s) row += 1 end end end total_time = Time.now - start_time if total_time > 0.0 and total_time < 1.0 break if @tab_sleeper.sleep(1.0 - total_time) end end rescue Exception => error Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(self, error, "COSMOS CTS : Settings Tab Thread")} end end end |
#handle_string_output ⇒ Object
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 1007 def handle_string_output if @string_output.string[-1..-1] == "\n" Qt.execute_in_main_thread(true) do lines_to_write = '' string = @string_output.string.clone @string_output.string = @string_output.string[string.length..-1] string.each_line {|out_line| @output.add_formatted_text(out_line); lines_to_write += out_line } @output.flush @message_log.write(lines_to_write) end end end |
#handle_tab_change(index) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 171 def handle_tab_change(index) kill_tab_thread() @tab_sleeper = Sleeper.new case index when 0 handle_interfaces_tab('Interfaces') when 1 handle_targets_tab() when 2 handle_packets_tab(CMD) when 3 handle_packets_tab(TLM) when 4 handle_interfaces_tab('Routers') when 5 handle_logging_tab() when 6 handle_status_tab() end end |
#handle_targets_tab ⇒ Object
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 420 def handle_targets_tab @tab_thread = Thread.new do begin while true Qt.execute_in_main_thread(true) do row = 0 System.targets.sort.each do |target_name, target| next if target_name == 'SYSTEM' @targets_table.item(row,2).setText(target.cmd_cnt.to_s) @targets_table.item(row,3).setText(target.tlm_cnt.to_s) row += 1 end end break if @tab_sleeper.sleep(1) end rescue Exception => error Qt.execute_in_main_thread(true) {|| ExceptionDialog.new(self, error, "COSMOS CTS : Targets Tab Thread")} end end end |
#initialize_actions ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 103 def initialize_actions super() # Edit actions @edit_clear_counters = Qt::Action.new(tr('&Clear Counters'), self) @edit_clear_counters.statusTip = tr('Clear counters for all interfaces and targets') @edit_clear_counters.connect(SIGNAL('triggered()')) { edit_clear_counters() } end |
#initialize_central_widget ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 137 def # Create the central widget @splitter = Qt::Splitter.new(Qt::Vertical, ) setCentralWidget(@splitter) @tabbook = Qt::TabWidget.new connect(@tabbook, SIGNAL('currentChanged(int)'), self, SLOT('handle_tab_change(int)')) @splitter.addWidget(@tabbook) # Add the message output @output = Qt::PlainTextEdit.new @output.setReadOnly(true) @output.setMaximumBlockCount(10000) # 10000 lines of history will be displayed @splitter.addWidget(@output) # Set the stretch factor to give priority to the tabbook (index 0) instead of the output (index 1) @splitter.setStretchFactor(0, 1) # (index, stretch) # Override stdout to the message window # All code attempting to print into the GUI must use $stdout rather than STDOUT @string_output = StringIO.new("", "r+") $stdout = @string_output Logger.level = Logger::INFO @tab_thread = nil end |
#initialize_menus ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 112 def @file_menu = .addMenu(tr('&File')) @file_menu.addAction(@exit_action) # Do not allow clear counters in production mode unless @production @edit_menu = .addMenu(tr('&Edit')) @edit_menu.addAction(@edit_clear_counters) end @about_string = "#{CMD} and #{TLM} Server is the heart of the COSMOS system. " @about_string << "It connects to the target and processes command and telemetry requests from other tools." () end |
#kill_tab_thread ⇒ Object
164 165 166 167 168 169 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 164 def kill_tab_thread @tab_sleeper ||= nil @tab_sleeper.cancel if @tab_sleeper Cosmos.kill_thread(self, @tab_thread) @tab_thread = nil end |
#meta_callback(meta_target_name, meta_packet_name) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 43 def (, ) Qt.execute_in_main_thread(true) do result = SetTlmDialog.execute(self, 'Enter Metadata', 'Set Metadata', 'Cancel', , ) exit(1) unless result end end |
#populate_interfaces(name) ⇒ Object
192 193 194 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 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 312 313 314 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 192 def populate_interfaces(name) @interfaces_table ||= {} if name == 'Routers' interfaces = CmdTlmServer.routers else interfaces = CmdTlmServer.interfaces end num_interfaces = interfaces.names.length if interfaces.names.length > 0 scroll = Qt::ScrollArea.new scroll.setMinimumSize(800, 150) = Qt::Widget.new layout = Qt::VBoxLayout.new() # Since the layout will be inside a scroll area make sure it respects the sizes we set layout.setSizeConstraint(Qt::Layout::SetMinAndMaxSize) interfaces_table = Qt::TableWidget.new() interfaces_table.verticalHeader.hide() interfaces_table.setRowCount(num_interfaces) interfaces_table.setColumnCount(10) if name == 'Routers' interfaces_table.setHorizontalHeaderLabels(["Router", "Connect/Disconnect", "Connected?", "Clients", "Tx Q Size", "Rx Q Size", " Bytes Tx ", " Bytes Rx ", " Cmd Pkts ", " Tlm Pkts "]) else interfaces_table.setHorizontalHeaderLabels(["Interface", "Connect/Disconnect", "Connected?", "Clients", "Tx Q Size", "Rx Q Size", " Bytes Tx ", " Bytes Rx ", " Cmd Pkts ", " Tlm Pkts "]) end row = 0 interfaces.all.each do |interface_name, interface| item = Qt::TableWidgetItem.new(tr(interface_name)) item.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 0, item) if interface.connected? = 'Disconnect' elsif interface.thread.nil? = 'Connect' else = 'Cancel Connect' end = Qt::PushButton.new() if name == 'Routers' .connect(SIGNAL('clicked()')) do if interface.thread Logger.info "User disconnecting router #{interface_name}" CmdTlmServer.instance.disconnect_router(interface_name) else Logger.info "User connecting router #{interface_name}" CmdTlmServer.instance.connect_router(interface_name) end end else .connect(SIGNAL('clicked()')) do if interface.thread Logger.info "User disconnecting interface #{interface_name}" CmdTlmServer.instance.disconnect_interface(interface_name) else Logger.info "User connecting interface #{interface_name}" CmdTlmServer.instance.connect_interface(interface_name) end end end .setDisabled(true) if interface.disable_disconnect interfaces_table.setCellWidget(row, 1, ) state = Qt::TableWidgetItem.new if interface.connected? state.setText('true') state.textColor = Cosmos::GREEN elsif interface.thread state.setText('attempting') state.textColor = Cosmos::YELLOW else state.setText('false') state.textColor = Cosmos::BLACK end state.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 2, state) num_clients = Qt::TableWidgetItem.new(tr(interface.num_clients.to_s)) num_clients.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 3, num_clients) write_queue_size = Qt::TableWidgetItem.new(tr(interface.write_queue_size.to_s)) write_queue_size.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 4, write_queue_size) read_queue_size = Qt::TableWidgetItem.new(tr(interface.read_queue_size.to_s)) read_queue_size.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 5, read_queue_size) bytes_written = Qt::TableWidgetItem.new(tr(interface.bytes_written.to_s)) bytes_written.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 6, bytes_written) bytes_read = Qt::TableWidgetItem.new(tr(interface.bytes_read.to_s)) bytes_read.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 7, bytes_read) write_count = Qt::TableWidgetItem.new(tr(interface.write_count.to_s)) write_count.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 8, write_count) read_count = Qt::TableWidgetItem.new(tr(interface.read_count.to_s)) read_count.setTextAlignment(Qt::AlignCenter) interfaces_table.setItem(row, 9, read_count) row += 1 end interfaces_table.displayFullSize layout.addWidget(interfaces_table) scroll.setWidget() if name == 'Routers' @tabbook.addTab(scroll, "Routers") @interfaces_table['Routers'] = interfaces_table else @tabbook.addTab(scroll, "Interfaces") @interfaces_table['Interfaces'] = interfaces_table end end end |
#populate_log_file_info(layout) ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 619 def populate_log_file_info(layout) CmdTlmServer.packet_logging.all.sort.each do |packet_log_writer_pair_name, packet_log_writer_pair| log = Qt::GroupBox.new("#{packet_log_writer_pair_name} Packet Log Writer") log_layout = Qt::VBoxLayout.new(log) interfaces = [] CmdTlmServer.interfaces.all.each do |interface_name, interface| if interface.packet_log_writer_pairs.include?(packet_log_writer_pair) interfaces << interface.name end end form_layout = Qt::FormLayout.new @logging_layouts[packet_log_writer_pair_name] = form_layout label = Qt::Label.new(tr(interfaces.join(", "))) label.setTextInteractionFlags(Qt::TextSelectableByMouse) form_layout.addRow("Interfaces:", label) create_log_layout(form_layout, packet_log_writer_pair.cmd_log_writer, 'Cmd') create_log_layout(form_layout, packet_log_writer_pair.tlm_log_writer, 'Tlm') = Qt::HBoxLayout.new = Qt::PushButton.new(tr('Start Cmd Logging')) .addWidget() .connect(SIGNAL('clicked()')) do CmdTlmServer.instance.start_cmd_log(packet_log_writer_pair_name) end = Qt::PushButton.new(tr('Start Tlm Logging')) .addWidget() .connect(SIGNAL('clicked()')) do CmdTlmServer.instance.start_tlm_log(packet_log_writer_pair_name) end if @production == false = Qt::PushButton.new(tr('Stop Cmd Logging')) .addWidget() .connect(SIGNAL('clicked()')) do CmdTlmServer.instance.stop_cmd_log(packet_log_writer_pair_name) end = Qt::PushButton.new(tr('Stop Tlm Logging')) .addWidget() .connect(SIGNAL('clicked()')) do CmdTlmServer.instance.stop_tlm_log(packet_log_writer_pair_name) end end form_layout.addRow("Actions:", ) log_layout.addLayout(form_layout) layout.addWidget(log) end layout.addWidget(Qt::Label.new(tr("Note: Buffered IO operations cause file size to not reflect total logged data size until the log file is closed."))) end |
#populate_logging ⇒ Object
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 668 def populate_logging scroll = Qt::ScrollArea.new = Qt::Widget.new layout = Qt::VBoxLayout.new() # Since the layout will be inside a scroll area # make sure it respects the sizes we set layout.setSizeConstraint(Qt::Layout::SetMinAndMaxSize) populate_logging_actions(layout) # Create the hash which will hold the logging layouts @logging_layouts = {} # Add the cmd/tlm log files information populate_log_file_info(layout) # Set the scroll area widget last now that all the items have been layed out scroll.setWidget() @tabbook.addTab(scroll, "Logging") end |
#populate_logging_actions(layout) ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 565 def populate_logging_actions(layout) # Add all the action buttons actions = Qt::GroupBox.new(tr("Actions")) actions_layout = Qt::VBoxLayout.new(actions) = Qt::GridLayout.new = [ ["Start Logging on All", [0,0], :start_logging], ["Stop Logging on All", [0,1], :stop_logging], ["Start #{TLM} Logging on All", [1,0], :start_tlm_log], ["Stop #{TLM} Logging on All", [1,1], :stop_tlm_log], ["Start #{CMD} Logging on All", [2,0], :start_cmd_log], ["Stop #{CMD} Logging on All", [2,1], :stop_cmd_log] ] .each do |text, location, method| next if text =~ /Stop/ and @production = Qt::PushButton.new(tr(text)) .addWidget(, location[0], location[1]) .connect(SIGNAL('clicked()')) do begin CmdTlmServer.instance.send(method, 'ALL') rescue Exception => error statusBar.showMessage(tr(error.)) end end end actions_layout.addLayout() layout.addWidget(actions) end |
#populate_packets(name) ⇒ Object
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 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 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 450 def populate_packets(name) cmd_tlm = get_cmd_tlm_def(name) unless cmd_tlm.target_names.empty? count = 0 cmd_tlm.target_names.sort.each do |target_name| packets = cmd_tlm.packets(target_name) packets.each do |packet_name, packet| count += 1 unless packet.hidden end end scroll = Qt::ScrollArea.new = Qt::Widget.new layout = Qt::VBoxLayout.new() # Since the layout will be inside a scroll area # make sure it respects the sizes we set layout.setSizeConstraint(Qt::Layout::SetMinAndMaxSize) table = Qt::TableWidget.new() table.verticalHeader.hide() table.setRowCount(count) column_cnt = 4 column_cnt += 1 if name == TLM table.setColumnCount(column_cnt) # Force the last section to fill all available space in the frame #~ table.horizontalHeader.setStretchLastSection(true) headers = ["Target Name", "Packet Name", "Packet Count", "View Raw"] headers << "View in Packet Viewer" if name == TLM table.setHorizontalHeaderLabels(headers) row = 0 cmd_tlm.target_names.sort.each do |target_name| packets = cmd_tlm.packets(target_name) packets.sort.each do |packet_name, packet| packet.received_count ||= 0 next if packet.hidden = Qt::TableWidgetItem.new(tr(target_name)) .setTextAlignment(Qt::AlignRight | Qt::AlignVCenter) table.setItem(row, 0, ) table.setItem(row, 1, Qt::TableWidgetItem.new(tr(packet_name))) packet_count = Qt::TableWidgetItem.new(tr(packet.received_count.to_s)) packet_count.setTextAlignment(Qt::AlignCenter) table.setItem(row, 2, packet_count) view_raw = Qt::PushButton.new("View Raw") view_raw.connect(SIGNAL('clicked()')) do @raw_dialogs ||= [] @raw_dialogs << CmdRawDialog.new(self, target_name, packet_name) if name == CMD @raw_dialogs << TlmRawDialog.new(self, target_name, packet_name) if name == TLM end table.setCellWidget(row, 3, view_raw) if name == TLM if target_name != 'UNKNOWN' and packet_name != 'UNKNOWN' view_pv = Qt::PushButton.new("View in Packet Viewer") view_pv.connect(SIGNAL('clicked()')) do if Kernel.is_windows? Cosmos.run_process("rubyw tools/PacketViewer -p \"#{target_name} #{packet_name}\" --system #{File.basename(System.initial_filename)}") elsif Kernel.is_mac? and File.exist?("tools/mac/PacketViewer.app") Cosmos.run_process("open tools/mac/PacketViewer.app --args -p \"#{target_name} #{packet_name}\" --system #{File.basename(System.initial_filename)}") else Cosmos.run_process("ruby tools/PacketViewer -p \"#{target_name} #{packet_name}\" --system #{File.basename(System.initial_filename)}") end end table.setCellWidget(row, 4, view_pv) else = Qt::TableWidgetItem.new(tr('N/A')) .setTextAlignment(Qt::AlignCenter) table.setItem(row, 4, ) end end row += 1 end end table.displayFullSize layout.addWidget(table) scroll.setWidget() tab_name = "Cmd Packets" if name == CMD tab_name = "Tlm Packets" if name == TLM @tabbook.addTab(scroll, tab_name) @packets_table ||= {} @packets_table[name] = table end end |
#populate_status ⇒ Object
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 729 def populate_status scroll = Qt::ScrollArea.new = Qt::Widget.new layout = Qt::VBoxLayout.new() limits = Qt::GroupBox.new(tr("Limits Status")) limits_layout = Qt::FormLayout.new(limits) current_limits_set = System.limits_set.to_s known_limits_sets = System.limits.sets known_limits_sets = known_limits_sets.map {|x| x.to_s}.sort current_index = known_limits_sets.index(current_limits_set.to_s) @limits_set_combo = Qt::ComboBox.new limits_layout.addRow("Limits Set:", @limits_set_combo) layout.addWidget(limits) known_limits_sets.sort.each do |limits_set| @limits_set_combo.addItem(limits_set.to_s) end @limits_set_combo.setMaxVisibleItems(6) @limits_set_combo.setCurrentIndex(current_index) # Only connect to the signal that is sent when the user chooses an item. # If the limits set is changed programatically the code in # handle_status_tab will pick up the change. @limits_set_combo.connect(SIGNAL('activated(int)')) do selected_limits_set = @limits_set_combo.currentText if selected_limits_set System.limits_set = selected_limits_set.intern if System.limits_set != selected_limits_set.intern end end api = Qt::GroupBox.new(tr("API Status")) api_layout = Qt::VBoxLayout.new(api) @api_table = Qt::TableWidget.new() @api_table.verticalHeader.hide() @api_table.setRowCount(1) @api_table.setColumnCount(6) @api_table.setHorizontalHeaderLabels(["Port", "Num Clients", "Requests", "Requests/Sec", "Avg Request Time", "Estimated Utilization"]) @api_table.setItem(0, 0, Qt::TableWidgetItem.new(tr(System.ports['CTS_API'].to_s))) item0 = Qt::TableWidgetItem.new(tr(CmdTlmServer.json_drb.num_clients.to_s)) item0.setTextAlignment(Qt::AlignCenter) @api_table.setItem(0, 1, item0) item = Qt::TableWidgetItem.new(tr(CmdTlmServer.json_drb.request_count.to_s)) item.setTextAlignment(Qt::AlignCenter) @api_table.setItem(0, 2, item) item2 = Qt::TableWidgetItem.new("0.0") item2.setTextAlignment(Qt::AlignCenter) @api_table.setItem(0, 3, item2) item3 = Qt::TableWidgetItem.new("0.0") item3.setTextAlignment(Qt::AlignCenter) @api_table.setItem(0, 4, item3) item4 = Qt::TableWidgetItem.new("0.0") item4.setTextAlignment(Qt::AlignCenter) @api_table.setItem(0, 5, item4) @api_table.displayFullSize api_layout.addWidget(@api_table) layout.addWidget(api) system = Qt::GroupBox.new(tr("System Status")) system_layout = Qt::VBoxLayout.new(system) @system_table = Qt::TableWidget.new() @system_table.verticalHeader.hide() @system_table.setRowCount(1) @system_table.setColumnCount(4) @system_table.setHorizontalHeaderLabels(["Threads", "Total Objs", "Free Objs", "Allocated Objs"]) item0 = Qt::TableWidgetItem.new("0") item0.setTextAlignment(Qt::AlignCenter) @system_table.setItem(0, 0, item0) item1 = Qt::TableWidgetItem.new("0.0") item1.setTextAlignment(Qt::AlignCenter) @system_table.setItem(0, 1, item1) item2 = Qt::TableWidgetItem.new("0.0") item2.setTextAlignment(Qt::AlignCenter) @system_table.setItem(0, 2, item2) item3 = Qt::TableWidgetItem.new("0.0") item3.setTextAlignment(Qt::AlignCenter) @system_table.setItem(0, 3, item3) @system_table.displayFullSize system_layout.addWidget(@system_table) layout.addWidget(system) background_tasks_groupbox = Qt::GroupBox.new(tr("Background Tasks")) background_tasks_layout = Qt::VBoxLayout.new(background_tasks_groupbox) @background_tasks_table = Qt::TableWidget.new() @background_tasks_table.verticalHeader.hide() @background_tasks_table.setRowCount(CmdTlmServer.background_tasks.all.length) @background_tasks_table.setColumnCount(3) @background_tasks_table.setHorizontalHeaderLabels(["Name", "State", "Status"]) background_tasks = CmdTlmServer.background_tasks.all if background_tasks.length > 0 row = 0 background_tasks.each_with_index do |background_task, index| background_task_name = background_task.name background_task_name = "Background Task ##{index + 1}" unless background_task_name = Qt::TableWidgetItem.new(background_task_name) .setTextAlignment(Qt::AlignCenter) @background_tasks_table.setItem(row, 0, ) if background_task.thread status = background_task.thread.status status = 'complete' if status == false = Qt::TableWidgetItem.new(status.to_s) else = Qt::TableWidgetItem.new('no thread') end .setTextAlignment(Qt::AlignCenter) .setSizeHint(Qt::Size.new(80, 30)) @background_tasks_table.setItem(row, 1, ) = Qt::TableWidgetItem.new(background_task.status.to_s) .setTextAlignment(Qt::AlignCenter) .setSizeHint(Qt::Size.new(500, 30)) @background_tasks_table.setItem(row, 2, ) row += 1 end end @background_tasks_table.displayFullSize background_tasks_layout.addWidget(@background_tasks_table) layout.addWidget(background_tasks_groupbox) # Set the scroll area widget last now that all the items have been layed out scroll.setWidget() @tabbook.addTab(scroll, "Status") end |
#populate_targets ⇒ Object
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 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 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 371 def populate_targets num_targets = System.targets.length if num_targets > 0 return if num_targets == 1 and System.targets['SYSTEM'] num_targets -= 1 if System.targets['SYSTEM'] scroll = Qt::ScrollArea.new = Qt::Widget.new layout = Qt::VBoxLayout.new() # Since the layout will be inside a scroll area make sure it respects the sizes we set layout.setSizeConstraint(Qt::Layout::SetMinAndMaxSize) @targets_table = Qt::TableWidget.new() @targets_table.verticalHeader.hide() @targets_table.setRowCount(num_targets) @targets_table.setColumnCount(4) @targets_table.setHorizontalHeaderLabels(["Target Name", "Interface", "#{CMD} Count", "#{TLM} Count"]) row = 0 System.targets.sort.each do |target_name, target| next if target_name == 'SYSTEM' = Qt::TableWidgetItem.new(tr(target_name)) .setTextAlignment(Qt::AlignCenter) @targets_table.setItem(row, 0, ) if target.interface = Qt::TableWidgetItem.new(tr(target.interface.name.to_s)) else = Qt::TableWidgetItem.new(tr('')) end .setTextAlignment(Qt::AlignCenter) @targets_table.setItem(row, 1, ) cmd_cnt = Qt::TableWidgetItem.new(tr(target.cmd_cnt.to_s)) cmd_cnt.setTextAlignment(Qt::AlignCenter) @targets_table.setItem(row, 2, cmd_cnt) tlm_cnt = Qt::TableWidgetItem.new(tr(target.tlm_cnt.to_s)) tlm_cnt.setTextAlignment(Qt::AlignCenter) @targets_table.setItem(row, 3, tlm_cnt) row += 1 end @targets_table.displayFullSize layout.addWidget(@targets_table) scroll.setWidget() @tabbook.addTab(scroll, "Targets") end end |
#process_server_messages(options) ⇒ Object
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 988 def () # Start thread to read server messages @output_thread = Thread.new do begin while !@message_log sleep(1) end while true handle_string_output() break if @output_sleeper.sleep(1) end rescue Exception => error Qt.execute_in_main_thread(true) do ExceptionDialog.new(self, error, "#{.title}: Messages Thread") end end end end |
#stop_callback ⇒ Object
1020 1021 1022 1023 1024 1025 1026 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 1020 def stop_callback handle_string_output() @output_sleeper.cancel Qt::CoreApplication.processEvents() Cosmos.kill_thread(self, @output_thread) handle_string_output() end |
#update_filename_and_logging_state ⇒ Object
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb', line 689 def update_filename_and_logging_state CmdTlmServer.packet_logging.all.each do |packet_log_writer_pair_name, packet_log_writer_pair| @logging_layouts[packet_log_writer_pair_name].itemAt(1, Qt::FormLayout::FieldRole)..setText(packet_log_writer_pair.cmd_log_writer.logging_enabled.to_s) @logging_layouts[packet_log_writer_pair_name].itemAt(2, Qt::FormLayout::FieldRole)..setText(packet_log_writer_pair.cmd_log_writer.queue.size.to_s) @logging_layouts[packet_log_writer_pair_name].itemAt(3, Qt::FormLayout::FieldRole)..setText(packet_log_writer_pair.cmd_log_writer.filename) file_size = 0 begin file_size = File.size(packet_log_writer_pair.cmd_log_writer.filename) if packet_log_writer_pair.cmd_log_writer.filename rescue Exception # Do nothing on error end @logging_layouts[packet_log_writer_pair_name].itemAt(4, Qt::FormLayout::FieldRole)..setText(file_size.to_s) @logging_layouts[packet_log_writer_pair_name].itemAt(5, Qt::FormLayout::FieldRole)..setText(packet_log_writer_pair.tlm_log_writer.logging_enabled.to_s) @logging_layouts[packet_log_writer_pair_name].itemAt(6, Qt::FormLayout::FieldRole)..setText(packet_log_writer_pair.tlm_log_writer.queue.size.to_s) @logging_layouts[packet_log_writer_pair_name].itemAt(7, Qt::FormLayout::FieldRole)..setText(packet_log_writer_pair.tlm_log_writer.filename) file_size = 0 begin file_size = File.size(packet_log_writer_pair.tlm_log_writer.filename) if packet_log_writer_pair.tlm_log_writer.filename rescue Exception # Do nothing on error end @logging_layouts[packet_log_writer_pair_name].itemAt(8, Qt::FormLayout::FieldRole)..setText(file_size.to_s) end end |