Class: Cosmos::CmdSender

Inherits:
QtTool show all
Defined in:
lib/cosmos/tools/cmd_sender/cmd_sender.rb

Overview

Command Sender sends commands to the COSMOS server. Itgives the user a drop down to select the target and then command to send. It then displays all the command parameters. Once a command is sent it is added to the command history window which allows the user to resend the command or copy it for use in a script.

Constant Summary collapse

MANUALLY =
"MANUALLY ENTERED"

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ CmdSender

Returns a new instance of CmdSender.



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
102
103
104
105
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 71

def initialize(options)
  # MUST BE FIRST - All code before super is executed twice in RubyQt Based classes
  super(options)
  Cosmos.load_cosmos_icon("cmd_sender.png")

  @file_dir = System.paths['LOGS']
  @message_log = MessageLog.new('cmdsender')
  @send_raw_dir = nil
  @@send_count = 0
  @@param_widgets = []
  @@table = nil

  initialize_actions()
  initialize_menus()
  initialize_central_widget()
  complete_initialize() # defined in qt_tool

  # Bring up slash screen for long duration tasks after creation
  Splash.execute(self) do |splash|
    # Configure CosmosConfig to interact with splash screen
    ConfigParser.splash = splash

    System.commands
    Qt.execute_in_main_thread(true) do
      update_targets()
      @target_select.setCurrentText(options.packet[0]) if options.packet
      update_commands()
      @cmd_select.setCurrentText(options.packet[1]) if options.packet
      update_cmd_params()
    end

    # Unconfigure CosmosConfig to interact with splash screen
    ConfigParser.splash = nil
  end
end

Class Method Details

.param_widgetsObject



63
64
65
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 63

def self.param_widgets
  @@param_widgets
end

.run(option_parser = nil, options = nil) ⇒ Object



704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 704

def self.run (option_parser = nil, options = nil)
  Cosmos.catch_fatal_exception do
    unless option_parser && options
      option_parser, options = create_default_options()
      options.width = 600
      options.height = 425
      options.title = 'Command Sender'
      option_parser.separator "Command Sender Specific Options:"
      option_parser.on("-p", "--packet 'TARGET_NAME PACKET_NAME'", "Start with the specified command selected") do |arg|
        split = arg.split
        if split.length != 2
          puts "Packet must be specified as 'TARGET_NAME PACKET_NAME' in quotes"
          exit
        end
        options.packet = split
      end
    end

    super(option_parser, options)
  end
end

.send_countObject



55
56
57
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 55

def self.send_count
  @@send_count
end

.send_count=(val) ⇒ Object



59
60
61
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 59

def self.send_count=(val)
  @@send_count = val
end

.tableObject



67
68
69
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 67

def self.table
  @@table
end

Instance Method Details

#click_callback(item) ⇒ Object



700
701
702
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 700

def click_callback(item)
  @@table.editItem(item) if (item.flags & Qt::ItemIsEditable) != 0
end

#closeEvent(event) ⇒ Object



353
354
355
356
357
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 353

def closeEvent(event)
  shutdown_cmd_tlm()
  @message_log.stop
  super(event)
end

#cmd_changed(command) ⇒ Object



364
365
366
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 364

def cmd_changed(command)
  update_cmd_params()
end

#context_menu(point) ⇒ Object



662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 662

def context_menu(point)
  target_name = @target_select.text
  packet_name = @cmd_select.text
  item = @@table.itemAt(point)
  if item
    item_name = @@table.item(item.row, 0).text[0..-2] # Remove :
    if target_name.length > 0 and packet_name.length > 0 and item_name.length > 0
      menu = Qt::Menu.new()

      details_action = Qt::Action.new(tr("Details #{target_name} #{packet_name} #{item_name}"), self)
      details_action.statusTip = tr("Popup details about #{target_name} #{packet_name} #{item_name}")
      details_action.connect(SIGNAL('triggered()')) do
        CmdDetailsDialog.new(nil, target_name, packet_name, item_name)
      end
      menu.addAction(details_action)

      file_chooser_action = Qt::Action.new(tr("Insert Filename"), self)
      file_chooser_action.statusTip = tr("Select a file and place its name into this parameter")
      file_chooser_action.connect(SIGNAL('triggered()')) do
        filename = Qt::FileDialog::getOpenFileName(self, "Insert Filename:", @file_dir, "All Files (*)")
        if filename and not filename.empty?
          @file_dir = File.dirname(filename)
          _, value_item, state_value_item = @@param_widgets[item.row]
          if state_value_item
            state_value_item.setText(filename)
          elsif value_item
            value_item.setText(filename)
          end
        end
      end
      menu.addAction(file_chooser_action)

      menu.exec(@@table.mapToGlobal(point))
      menu.dispose
    end
  end
end

#file_send_rawObject



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 294

def file_send_raw
  begin
    dialog = Qt::Dialog.new(self, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
    dialog.setWindowTitle("Send Raw Data From File")
    layout = Qt::GridLayout.new
    interfaces = Qt::ComboBox.new
    interfaces.addItems(get_interface_names())
    interfaces.setMaxVisibleItems(30)
    layout.addWidget(interfaces, 0, 1)
    int_label = Qt::Label.new(tr("&Interface:"))
    int_label.setBuddy(interfaces)
    layout.addWidget(int_label, 0, 0)

    file_line = Qt::LineEdit.new(@send_raw_dir)
    file_line.setMinimumSize(250, 0)
    file_label = Qt::Label.new(tr("&Filename:"))
    file_label.setBuddy(file_line)
    get_file = Qt::PushButton.new("Select")
    file_layout = Qt::BoxLayout.new(Qt::Horizontal)
    file_layout.addWidget(get_file)
    file_layout.addWidget(file_line)
    get_file.connect(SIGNAL('clicked()')) do
      Cosmos.set_working_dir do
        file_line.text = Qt::FileDialog::getOpenFileName(self, "Select File", @send_raw_dir, tr("Binary Files (*.bin);;All Files (*)"))
      end
    end

    layout.addWidget(file_label, 1, 0)
    layout.addLayout(file_layout, 1, 1)

    button_layout = Qt::BoxLayout.new(Qt::Horizontal)
    ok = Qt::PushButton.new("Ok")
    connect(ok, SIGNAL('clicked()'), dialog, SLOT('accept()'))
    button_layout.addWidget(ok)
    cancel = Qt::PushButton.new("Cancel")
    connect(cancel, SIGNAL('clicked()'), dialog, SLOT('reject()'))
    button_layout.addWidget(cancel)
    layout.addLayout(button_layout, 2, 0, 1 ,2)

    dialog.setLayout(layout)
    if dialog.exec == Qt::Dialog::Accepted
      @send_raw_dir = file_line.text
      Cosmos.set_working_dir do
        send_raw_file(interfaces.text, file_line.text)
      end
      statusBar.showMessage(tr("File #{file_line.text} sent to interface #{interfaces.text}"))
    end
    dialog.dispose
  rescue Exception => err
    message = "Error sending raw file due to #{err}"
    @message_log.write(Time.now.formatted + '  ' + message + "\n")
    statusBar.showMessage(message)
  rescue DRb::DRbConnError
    message = "Error Connecting to Command and Telemetry Server"
    @message_log.write(Time.now.formatted + '  ' + message + "\n")
    statusBar.showMessage(message)
  end
end

#initialize_actionsObject



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
132
133
134
135
136
137
138
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 107

def initialize_actions
  super()

  @send_raw_action = Qt::Action.new(Cosmos.get_icon('send_file.png'),
                                    tr('&Send Raw'),
                                    self)
  @send_raw_action.shortcut  = Qt::KeySequence.new(tr('Ctrl+S'))
  @send_raw_action.statusTip = tr('Send raw data from a file')
  connect(@send_raw_action, SIGNAL('triggered()'), self, SLOT('file_send_raw()'))

  @ignore_range = Qt::Action.new(tr('&Ignore Range Checks'), self)
  @ignore_range.statusTip = tr('Ignore range checks when processing command')
  @ignore_range.setCheckable(true)
  @ignore_range.setChecked(false)

  @states_in_hex = Qt::Action.new(tr('&Display State Values in Hex'), self)
  @states_in_hex.statusTip = tr('Display states values in hex instead of decimal')
  @states_in_hex.setCheckable(true)
  @states_in_hex.setChecked(false)
  connect(@states_in_hex, SIGNAL('toggled(bool)'), self, SLOT('menu_states_in_hex(bool)'))

  @show_ignored = Qt::Action.new(tr('&Show Ignored Parameters'), self)
  @show_ignored.statusTip = tr('Show ignored parameters which are normally hidden')
  @show_ignored.setCheckable(true)
  @show_ignored.setChecked(false)
  connect(@show_ignored, SIGNAL('toggled(bool)'), self, SLOT('update_cmd_params(bool)'))

  @cmd_raw = Qt::Action.new(tr('Disable &Parameter Conversions'), self)
  @cmd_raw.statusTip = tr('Send the command without running write or state conversions')
  @cmd_raw.setCheckable(true)
  @cmd_raw.setChecked(false)
end

#initialize_central_widgetObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
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
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 159

def initialize_central_widget
  # Create the central widget
  central_widget = Qt::Widget.new
  setCentralWidget(central_widget)

  # Create the top half of the splitter window
  sender = Qt::Widget.new

  # Create the top level vertical layout
  top_layout = Qt::VBoxLayout.new(sender)
  # Set the size constraint to always respect the minimum sizes of the child widgets
  # If this is not set then when we refresh the command parameters they'll all be squished
  top_layout.setSizeConstraint(Qt::Layout::SetMinimumSize)

  # Set the target combobox selection
  @target_select = Qt::ComboBox.new
  @target_select.setMaxVisibleItems(6)
  connect(@target_select, SIGNAL('activated(const QString&)'), self, SLOT('target_changed(const QString&)'))
  target_label = Qt::Label.new(tr("&Target:"))
  target_label.setBuddy(@target_select)

  # Set the comamnd combobox selection
  @cmd_select = Qt::ComboBox.new
  @cmd_select.setMaxVisibleItems(20)
  connect(@cmd_select, SIGNAL('activated(const QString&)'), self, SLOT('cmd_changed(const QString&)'))
  cmd_label = Qt::Label.new(tr("&Command:"))
  cmd_label.setBuddy(@cmd_select)

  # Button to send command
  send = Qt::PushButton.new("Send")
  connect(send, SIGNAL('clicked()'), self, SLOT('send_button()'))

  # Layout the top level selection
  select_layout = Qt::HBoxLayout.new
  select_layout.addWidget(target_label)
  select_layout.addWidget(@target_select, 1)
  select_layout.addWidget(cmd_label)
  select_layout.addWidget(@cmd_select, 1)
  select_layout.addWidget(send)
  top_layout.addLayout(select_layout)

  # Separator Between Command Selection and Command Description
  sep1 = Qt::Frame.new(sender)
  sep1.setFrameStyle(Qt::Frame::HLine | Qt::Frame::Sunken)
  top_layout.addWidget(sep1)

  # Command Description Label
  dec_label = Qt::Label.new(tr("Description:"))
  @description = Qt::Label.new('')
  @description.setWordWrap(true)
  desc_layout = Qt::HBoxLayout.new
  desc_layout.addWidget(dec_label)
  desc_layout.addWidget(@description, 1)
  top_layout.addLayout(desc_layout)

  # Separator Between Command Selection and Description
  sep2 = Qt::Frame.new(sender)
  sep2.setFrameStyle(Qt::Frame::HLine | Qt::Frame::Sunken)
  top_layout.addWidget(sep2)

  # Parameters Label
  param_label = Qt::Label.new(tr("Parameters:"))
  top_layout.addWidget(param_label)

  # Grid Layout for Parameters
  @table_layout = Qt::VBoxLayout.new
  top_layout.addLayout(@table_layout, 500)

  # Add stretch to force everything to fit against the top of the window
  # otherwise the selection window, description, and parameters all try
  # to get equal space.
  top_layout.addStretch(1)

  # Create the text edit where previously issued commands go and where
  # commands can be manually typed in and re-executed
  @input = CmdSenderTextEdit.new(statusBar)
  @input.setFocus()

  layout = Qt::VBoxLayout.new
  layout.setSpacing(1)
  layout.setContentsMargins(1, 1, 1, 1)
  layout.setSizeConstraint(Qt::Layout::SetMaximumSize)
  layout.addWidget(Qt::Label.new("Command History: (Pressing Enter on the line re-executes the command)"))
  layout.addWidget(@input)
  history = Qt::Widget.new
  history.layout = layout

  # Create the scroll area
  scroll = Qt::ScrollArea.new
  scroll.setMinimumSize(500, 150)
  scroll.setWidgetResizable(true)
  scroll.setWidget(sender)

  splitter = Qt::Splitter.new(central_widget)
  splitter.setOrientation(Qt::Vertical)
  splitter.addWidget(scroll)
  splitter.addWidget(history)
  splitter.setStretchFactor(0,10)
  splitter.setStretchFactor(1,1)

  layout = Qt::VBoxLayout.new
  layout.setSpacing(1)
  layout.setContentsMargins(1, 1, 1, 1)
  layout.setSizeConstraint(Qt::Layout::SetMaximumSize)
  layout.addWidget(splitter)
  central_widget.layout = layout

  # Mark this window as the window for popups
  set_cmd_tlm_gui_window(self)
end

#initialize_menusObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 140

def initialize_menus
  # File Menu
  file_menu = menuBar.addMenu(tr('&File'))
  file_menu.addAction(@send_raw_action)
  file_menu.addAction(@exit_action)
  file_menu.insertSeparator(@exit_action)

  # Mode Menu
  mode_menu = menuBar.addMenu(tr('&Mode'))
  mode_menu.addAction(@ignore_range)
  mode_menu.addAction(@states_in_hex)
  mode_menu.addAction(@show_ignored)
  mode_menu.addAction(@cmd_raw)

  # Help Menu
  @about_string = "Command Sender allows the user to send any command defined in the system."
  initialize_help_menu()
end


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 270

def menu_states_in_hex(checked)
  @@param_widgets.each do |packet_item, value_item, state_value_item|
    if state_value_item
      text = state_value_item.text
      quotes_removed = text.remove_quotes
      if text == quotes_removed
        if checked
          if text.is_int?
            @@table.blockSignals(true)
            state_value_item.text = sprintf("0x%X", text.to_i)
            @@table.blockSignals(false)
          end
        else
          if text.is_hex?
            @@table.blockSignals(true)
            state_value_item.text = Integer(text).to_s
            @@table.blockSignals(false)
          end
        end
      end
    end
  end
end

#send_buttonObject



368
369
370
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
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 368

def send_button
  begin
    target_name = @target_select.text
    packet_name = @cmd_select.text
    if target_name and packet_name
      output_string, params = view_as_script()
      @message_log.write(Time.now.formatted + '  ' + output_string + "\n")
      if @cmd_raw.checked?
        if @ignore_range.checked?
          cmd_raw_no_range_check(target_name, packet_name, params)
        else
          cmd_raw(target_name, packet_name, params)
        end
      else
        if @ignore_range.checked?
          cmd_no_range_check(target_name, packet_name, params)
        else
          cmd(target_name, packet_name, params)
        end
      end

      if statusBar.currentMessage != 'Hazardous command not sent'
        @@send_count += 1
        statusBar.showMessage("#{output_string} sent. (#{@@send_count})")
        @input.append(output_string)
        @input.moveCursor(Qt::TextCursor::End)
        @input.ensureCursorVisible()
      end
    end
  rescue DRb::DRbConnError
    message = "Error Connecting to Command and Telemetry Server"
    @message_log.write(Time.now.formatted + '  ' + message + "\n")
    statusBar.showMessage(message)
    Qt::MessageBox.critical(self, 'Error', message)
  rescue Exception => err
    message = "Error sending #{target_name} #{packet_name} due to #{err}"
    @message_log.write(Time.now.formatted + '  ' + message + "\n")
    statusBar.showMessage(message)
    Qt::MessageBox.critical(self, 'Error', message)
  end
end

#target_changed(target) ⇒ Object



359
360
361
362
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 359

def target_changed(target)
  update_commands()
  update_cmd_params()
end

#update_cmd_params(ignored_toggle = nil) ⇒ Object



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
537
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
564
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
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
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 485

def update_cmd_params(ignored_toggle = nil)
  old_params = {}
  if ignored_toggle.nil?
    ignored_toggle = false
  else
    ignored_toggle = true
    # Save parameter values
    @@param_widgets.each do |packet_item, value_item, state_value_item|
      text = value_item.text
      if state_value_item
        old_params[packet_item.name] = [text, state_value_item.text]
      else
        old_params[packet_item.name] = text
      end
    end
  end

  # Clear Status Bar
  statusBar.showMessage(tr(""))

  target_name = @target_select.text
  target = System.targets[target_name]
  packet_name = @cmd_select.text
  if target_name and packet_name
    packet = System.commands.packet(target_name, packet_name)
    packet_items = packet.sorted_items
    shown_packet_items = []
    packet_items.each do |packet_item|
      next if target and target.ignored_parameters.include?(packet_item.name) && !@show_ignored.checked?
      shown_packet_items << packet_item
    end

    # Update Command Description
    @description.text = packet.description.to_s

    # Destroy the old table widget
    @@table.dispose if @@table
    @@table = nil

    # Update Parameters
    @@param_widgets = []
    drawn_header = false

    row = 0
    shown_packet_items.each do |packet_item|
      next if target and target.ignored_parameters.include?(packet_item.name) && !@show_ignored.checked?
      value_item = nil
      state_value_item = nil

      unless drawn_header
        @@table = Qt::TableWidget.new()
        @@table.setSizePolicy(Qt::SizePolicy::Expanding, Qt::SizePolicy::Expanding)
        @@table.setWordWrap(true)
        @@table.setRowCount(shown_packet_items.length)
        @@table.setColumnCount(5)
        @@table.setHorizontalHeaderLabels(['Name', '         Value or State         ', '         ', 'Units', 'Description'])
        @@table.horizontalHeader.setStretchLastSection(true)
        @@table.verticalHeader.setVisible(false)
        @@table.setItemDelegate(CmdSenderItemDelegate.new(@@table))
        @@table.setContextMenuPolicy(Qt::CustomContextMenu)
        @@table.verticalHeader.setResizeMode(Qt::HeaderView::ResizeToContents)
        @@table.setEditTriggers(Qt::AbstractItemView::AllEditTriggers)
        @@table.setSelectionMode(Qt::AbstractItemView::NoSelection)
        connect(@@table, SIGNAL('customContextMenuRequested(const QPoint&)'), self, SLOT('context_menu(const QPoint&)'))
        connect(@@table, SIGNAL('itemClicked(QTableWidgetItem*)'), self, SLOT('click_callback(QTableWidgetItem*)'))
        drawn_header = true
      end

      # Parameter Name
      item = Qt::TableWidgetItem.new("#{packet_item.name}:")
      item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
      item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
      @@table.setItem(row, 0, item)

      if packet_item.states
        default_state = packet_item.states.key(packet_item.default)
        if old_params[packet_item.name]
          value_item = Qt::TableWidgetItem.new(old_params[packet_item.name][0])
        else
          if default_state
            value_item = Qt::TableWidgetItem.new(default_state.to_s)
          else
            value_item = Qt::TableWidgetItem.new(MANUALLY)
          end
        end
        value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
        value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
        @@table.setItem(row, 1, value_item)

        if old_params[packet_item.name]
          state_value_item = Qt::TableWidgetItem.new(old_params[packet_item.name][1])
        else
          if @states_in_hex.checked? && packet_item.default.kind_of?(Integer)
            state_value_item = Qt::TableWidgetItem.new(sprintf("0x%X", packet_item.default))
          else
            state_value_item = Qt::TableWidgetItem.new(packet_item.default.to_s)
          end
        end
        state_value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
        state_value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
        @@table.setItem(row, 2, state_value_item)

        # If the parameter is required set the combobox to MANUAL and
        # clear the value field so they have to choose something
        if packet_item.required and !old_params[packet_item.name]
          value_item.setText(MANUALLY)
          state_value_item.setText('')
        end
      else
        # Parameter Value
        if old_params[packet_item.name]
          value_item = Qt::TableWidgetItem.new(old_params[packet_item.name])
        else
          if packet_item.required
            value_item = Qt::TableWidgetItem.new('')
          else
            if packet_item.format_string
              begin
                value_item = Qt::TableWidgetItem.new(sprintf(packet_item.format_string, packet_item.default))
              rescue
                # Oh well - Don't use the format string
                value_item = Qt::TableWidgetItem.new(packet_item.default.to_s)
              end
            else
              value_item = Qt::TableWidgetItem.new(packet_item.default.to_s)
            end
          end
        end
        value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
        value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
        @@table.setItem(row, 1, value_item)
        @@table.setSpan(row, 1, 1, 2)
      end

      # Units
      item = Qt::TableWidgetItem.new(packet_item.units.to_s)
      item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
      item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
      @@table.setItem(row, 3, item)

      # Description
      item = Qt::TableWidgetItem.new(packet_item.description.to_s)
      item.setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter)
      item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
      @@table.setItem(row, 4, item)

      @@param_widgets << [packet_item, value_item, state_value_item]
      row += 1
    end

    if @@table
      @@table.connect(SIGNAL('itemChanged(QTableWidgetItem*)')) do |item|
        packet_item, value_item, state_value_item = @@param_widgets[item.row]
        if item.column == 1
          if packet_item.states
            value = packet_item.states[value_item.text]
            @@table.blockSignals(true)
            if @states_in_hex.checked? && value.kind_of?(Integer)
              state_value_item.setText(sprintf("0x%X", value))
            else
              state_value_item.setText(value.to_s)
            end
            @@table.blockSignals(false)
          end
        elsif item.column == 2
          @@table.blockSignals(true)
          @@table.item(item.row, 1).setText(MANUALLY)
          @@table.blockSignals(false)
        end
      end
      @table_layout.addWidget(@@table, 500)
      @@table.resizeColumnsToContents()
      @@table.resizeRowsToContents()
    end
  end # if target_name and packet_name
end

#update_commandsObject



469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 469

def update_commands
  @cmd_select.clearItems()
  target_name = @target_select.text
  if target_name
    commands = System.commands.packets(@target_select.text)
    command_names = []
    commands.each do |command_name, command|
      command_names << command_name unless command.hidden
    end
    command_names.sort!
    command_names.each do |command_name|
      @cmd_select.addItem(command_name)
    end
  end
end

#update_targetsObject



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 445

def update_targets
  @target_select.clearItems()
  target_names = System.commands.target_names
  target_names_to_delete = []
  target_names.each do |target_name|
    found_non_hidden = false
    begin
      packets = System.commands.packets(target_name)
      packets.each do |packet_name, packet|
        found_non_hidden = true unless packet.hidden
      end
    rescue
      # Don't do anything
    end
    target_names_to_delete << target_name unless found_non_hidden
  end
  target_names_to_delete.each do |target_name|
    target_names.delete(target_name)
  end
  target_names.each do |target_name|
    @target_select.addItem(target_name)
  end
end

#view_as_scriptObject



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
# File 'lib/cosmos/tools/cmd_sender/cmd_sender.rb', line 410

def view_as_script
  params = {}

  @@param_widgets.each do |packet_item, value_item, state_value_item|
    text = value_item.text

    text = state_value_item.text if state_value_item and (text == MANUALLY or @cmd_raw.checked?)
    quotes_removed = text.remove_quotes
    if text == quotes_removed
      params[packet_item.name] = text.convert_to_value
    else
      params[packet_item.name] = quotes_removed
    end
    raise "#{packet_item.name} is required." if quotes_removed == '' and packet_item.required
  end
  statusBar.clearMessage()

  output_string = build_cmd_output_string(@target_select.text, @cmd_select.text, params, @cmd_raw.checked?)
  if output_string =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/
    output_string = output_string.inspect.remove_quotes
  end

  if @cmd_raw.checked?
    if @ignore_range.checked?
      output_string.insert(7, '_no_range_check')
    end
  else
    if @ignore_range.checked?
      output_string.insert(3, '_no_range_check')
    end
  end

  return output_string, params
end