cosmos 4.4.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +5 -5
  2. data/.dockerignore +2 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +6 -6
  5. data/Dockerfile +70 -0
  6. data/Manifest.txt +37 -2
  7. data/README.md +9 -0
  8. data/Rakefile +55 -5
  9. data/appveyor.yml +18 -8
  10. data/autohotkey/config/tools/cmd_sequence/cmd_sequence.txt +2 -0
  11. data/autohotkey/lib/cmd_sequence_exporter.rb +52 -0
  12. data/autohotkey/procedures/collect.rb +2 -2
  13. data/autohotkey/procedures/collect_util.rb +1 -1
  14. data/autohotkey/procedures/script_test.rb +1 -1
  15. data/autohotkey/tools/CmdSenderAHK2 +18 -0
  16. data/autohotkey/tools/cmd_extractor.ahk +11 -9
  17. data/autohotkey/tools/cmd_sender.ahk +35 -7
  18. data/autohotkey/tools/cmd_sender2.ahk +4 -0
  19. data/autohotkey/tools/cmd_sequence.ahk +22 -9
  20. data/autohotkey/tools/config_editor.ahk +4 -4
  21. data/autohotkey/tools/data_viewer.ahk +1 -1
  22. data/autohotkey/tools/limits_monitor.ahk +1 -1
  23. data/autohotkey/tools/packet_viewer.ahk +1 -1
  24. data/autohotkey/tools/script_runner.ahk +1 -1
  25. data/autohotkey/tools/test_runner2.ahk +1 -1
  26. data/autohotkey/tools/tlm_grapher.ahk +1 -1
  27. data/autohotkey/tools/tlm_grapher3.ahk +1 -1
  28. data/autohotkey/tools/tlm_viewer.ahk +1 -1
  29. data/autohotkey/tools/tlm_viewer2.ahk +1 -1
  30. data/autohotkey/tools/tlm_viewer5.ahk +1 -1
  31. data/bin/cstol_converter +1 -1
  32. data/bin/rubysloc +73 -28
  33. data/bin/xtce_converter +1 -1
  34. data/cosmos.gemspec +2 -2
  35. data/data/config/command_modifiers.yaml +16 -1
  36. data/data/config/interface_modifiers.yaml +3 -2
  37. data/data/config/param_item_modifiers.yaml +5 -0
  38. data/data/config/system.yaml +110 -23
  39. data/data/config/telemetry_modifiers.yaml +16 -1
  40. data/data/crc.txt +416 -411
  41. data/demo/Rakefile +4 -4
  42. data/demo/config/dart/Gemfile +1 -6
  43. data/demo/config/data/crc.txt +233 -232
  44. data/demo/config/system/system.txt +17 -6
  45. data/demo/config/system/system2.txt +17 -6
  46. data/demo/config/system/system_alt_ports.txt +17 -6
  47. data/demo/config/targets/INST/cmd_tlm/inst_cmds.txt +4 -4
  48. data/demo/config/targets/INST/cmd_tlm/inst_tlm.txt +4 -0
  49. data/demo/config/targets/INST/cmd_tlm/inst_tlm_override.txt +12 -0
  50. data/demo/config/targets/INST/lib/sim_inst.rb +2 -2
  51. data/demo/config/targets/INST/target.txt +1 -0
  52. data/demo/config/tools/handbook_creator/default_toc.xsl +59 -59
  53. data/demo/procedures/cosmos_api_test.rb +8 -8
  54. data/ext/cosmos/ext/buffered_file/buffered_file.c +2 -2
  55. data/ext/cosmos/ext/config_parser/config_parser.c +1 -2
  56. data/ext/cosmos/ext/line_graph/line_graph.c +53 -94
  57. data/ext/cosmos/ext/platform/platform.c +56 -21
  58. data/ext/cosmos/ext/polynomial_conversion/polynomial_conversion.c +4 -8
  59. data/ext/cosmos/ext/structure/structure.c +12 -0
  60. data/extensions/vscode/.gitignore +4 -0
  61. data/extensions/vscode/.vscode/launch.json +32 -0
  62. data/extensions/vscode/.vscode/settings.json +13 -0
  63. data/extensions/vscode/.vscode/tasks.json +79 -0
  64. data/extensions/vscode/License.txt +879 -0
  65. data/extensions/vscode/README.md +9 -0
  66. data/extensions/vscode/client/License.txt +879 -0
  67. data/extensions/vscode/client/README.md +39 -0
  68. data/extensions/vscode/client/cosmos.configuration.json +23 -0
  69. data/extensions/vscode/client/images/icon.png +0 -0
  70. data/extensions/vscode/client/package-lock.json +414 -0
  71. data/extensions/vscode/client/package.json +105 -0
  72. data/extensions/vscode/client/src/extension.ts +132 -0
  73. data/extensions/vscode/client/src/screen_preview.rb +25 -0
  74. data/extensions/vscode/client/syntaxes/cosmos.tmLanguage.json +219 -0
  75. data/extensions/vscode/client/tsconfig.json +17 -0
  76. data/extensions/vscode/package-lock.json +26 -0
  77. data/extensions/vscode/package.json +35 -0
  78. data/extensions/vscode/server/License.txt +879 -0
  79. data/extensions/vscode/server/package-lock.json +236 -0
  80. data/extensions/vscode/server/package.json +29 -0
  81. data/extensions/vscode/server/src/server.ts +59 -0
  82. data/extensions/vscode/server/tsconfig.json +16 -0
  83. data/install/Rakefile +4 -4
  84. data/install/config/dart/Gemfile +2 -7
  85. data/install/config/data/crc.txt +137 -137
  86. data/install/config/system/system.txt +17 -6
  87. data/install/config/tools/handbook_creator/default_toc.xsl +59 -59
  88. data/lib/cosmos/config/config_parser.rb +2 -10
  89. data/lib/cosmos/core_ext/class.rb +10 -0
  90. data/lib/cosmos/core_ext/time.rb +5 -3
  91. data/lib/cosmos/dart/config/boot.rb +1 -1
  92. data/lib/cosmos/dart/config/database.yml +2 -0
  93. data/lib/cosmos/dart/examples/dart_decom_client.rb +1 -1
  94. data/lib/cosmos/dart/lib/dart_common.rb +12 -5
  95. data/lib/cosmos/dart/lib/dart_constants.rb +15 -0
  96. data/lib/cosmos/dart/lib/dart_decom_query.rb +5 -6
  97. data/lib/cosmos/dart/lib/dart_decommutator.rb +64 -54
  98. data/lib/cosmos/dart/lib/dart_master_query.rb +71 -0
  99. data/lib/cosmos/dart/lib/dart_reducer_worker_thread.rb +165 -134
  100. data/lib/cosmos/dart/processes/dart.rb +4 -2
  101. data/lib/cosmos/dart/processes/dart_decom_server.rb +3 -3
  102. data/lib/cosmos/dart/processes/dart_ingester.rb +38 -1
  103. data/lib/cosmos/dart/processes/dart_master.rb +44 -0
  104. data/lib/cosmos/dart/processes/dart_util.rb +115 -0
  105. data/lib/cosmos/dart/spec/dart/dart_database_cleaner_spec.rb +2 -2
  106. data/lib/cosmos/gui/qt.rb +10 -10
  107. data/lib/cosmos/gui/qt_tool.rb +17 -12
  108. data/lib/cosmos/gui/text/completion_text_edit.rb +2 -0
  109. data/lib/cosmos/gui/widgets/dart_meta_frame.rb +22 -3
  110. data/lib/cosmos/interfaces/dart_status_interface.rb +1 -1
  111. data/lib/cosmos/interfaces/linc_interface.rb +3 -3
  112. data/lib/cosmos/interfaces/protocols/burst_protocol.rb +1 -1
  113. data/lib/cosmos/interfaces/protocols/crc_protocol.rb +1 -1
  114. data/lib/cosmos/interfaces/protocols/length_protocol.rb +5 -0
  115. data/lib/cosmos/interfaces/protocols/template_protocol.rb +3 -3
  116. data/lib/cosmos/interfaces/serial_interface.rb +7 -1
  117. data/lib/cosmos/interfaces/stream_interface.rb +1 -1
  118. data/lib/cosmos/interfaces/tcpip_server_interface.rb +16 -16
  119. data/lib/cosmos/io/io_multiplexer.rb +6 -2
  120. data/lib/cosmos/io/json_drb.rb +5 -5
  121. data/lib/cosmos/io/json_drb_object.rb +7 -2
  122. data/lib/cosmos/io/json_drb_rack.rb +25 -5
  123. data/lib/cosmos/io/json_rpc.rb +1 -1
  124. data/lib/cosmos/io/posix_serial_driver.rb +60 -22
  125. data/lib/cosmos/io/serial_driver.rb +11 -8
  126. data/lib/cosmos/io/win32_serial_driver.rb +31 -3
  127. data/lib/cosmos/packet_logs/packet_log_reader.rb +2 -2
  128. data/lib/cosmos/packets/packet.rb +9 -9
  129. data/lib/cosmos/packets/packet_config.rb +27 -9
  130. data/lib/cosmos/packets/parsers/xtce_converter.rb +10 -10
  131. data/lib/cosmos/packets/parsers/xtce_parser.rb +3 -0
  132. data/lib/cosmos/packets/structure.rb +35 -5
  133. data/lib/cosmos/packets/structure_item.rb +5 -1
  134. data/lib/cosmos/packets/telemetry.rb +7 -1
  135. data/lib/cosmos/script/api_shared.rb +18 -1
  136. data/lib/cosmos/script/extract.rb +1 -1
  137. data/lib/cosmos/script/script.rb +4 -11
  138. data/lib/cosmos/streams/serial_stream.rb +11 -6
  139. data/lib/cosmos/system/system.rb +155 -57
  140. data/lib/cosmos/tools/cmd_sender/cmd_param_table_item_delegate.rb +15 -0
  141. data/lib/cosmos/tools/cmd_sender/cmd_params.rb +382 -0
  142. data/lib/cosmos/tools/cmd_sender/cmd_sender.rb +29 -318
  143. data/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb +14 -17
  144. data/lib/cosmos/tools/cmd_sequence/sequence_item.rb +38 -331
  145. data/lib/cosmos/tools/cmd_sequence/sequence_list.rb +16 -11
  146. data/lib/cosmos/tools/cmd_tlm_server/api.rb +10 -8
  147. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +2 -2
  148. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb +1 -0
  149. data/lib/cosmos/tools/cmd_tlm_server/gui/logging_tab.rb +1 -1
  150. data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +29 -26
  151. data/lib/cosmos/tools/cmd_tlm_server/limits_groups_background_task.rb +1 -1
  152. data/lib/cosmos/tools/cmd_tlm_server/router_thread.rb +5 -0
  153. data/lib/cosmos/tools/config_editor/config_editor.rb +34 -3
  154. data/lib/cosmos/tools/config_editor/config_editor_frame.rb +8 -9
  155. data/lib/cosmos/tools/config_editor/system_config_dialog.rb +158 -0
  156. data/lib/cosmos/tools/handbook_creator/handbook_creator.rb +1 -1
  157. data/lib/cosmos/tools/handbook_creator/handbook_creator_config.rb +1 -1
  158. data/lib/cosmos/tools/script_runner/script_runner_frame.rb +7 -4
  159. data/lib/cosmos/tools/test_runner/test.rb +6 -3
  160. data/lib/cosmos/tools/test_runner/test_runner.rb +6 -6
  161. data/lib/cosmos/tools/tlm_extractor/tlm_extractor.rb +3 -3
  162. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_config.rb +1 -4
  163. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb +20 -16
  164. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_dart_thread.rb +21 -17
  165. data/lib/cosmos/tools/tlm_grapher/tlm_grapher.rb +18 -11
  166. data/lib/cosmos/tools/tlm_viewer/tlm_viewer.rb +17 -6
  167. data/lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb +2 -0
  168. data/lib/cosmos/top_level.rb +1 -1
  169. data/lib/cosmos/utilities/ruby_lex_utils.rb +34 -30
  170. data/lib/cosmos/utilities/simulated_target.rb +1 -1
  171. data/lib/cosmos/version.rb +5 -5
  172. data/lib/cosmos/win32/excel.rb +23 -17
  173. data/run_gui_tests.bat +1 -0
  174. data/spec/core_ext/class_spec.rb +54 -0
  175. data/spec/core_ext/socket_spec.rb +1 -1
  176. data/spec/core_ext/time_spec.rb +4 -0
  177. data/spec/install/yaml_docs_spec.rb +26 -6
  178. data/spec/interfaces/linc_interface_spec.rb +1 -1
  179. data/spec/interfaces/protocols/length_protocol_spec.rb +39 -0
  180. data/spec/interfaces/serial_interface_spec.rb +1 -5
  181. data/spec/io/json_drb_rack_spec.rb +166 -0
  182. data/spec/io/json_drb_spec.rb +14 -0
  183. data/spec/io/json_rpc_spec.rb +4 -5
  184. data/spec/io/posix_serial_driver_spec.rb +81 -0
  185. data/spec/io/win32_serial_driver_spec.rb +33 -3
  186. data/spec/packet_logs/packet_log_reader_spec.rb +36 -37
  187. data/spec/packets/structure_spec.rb +52 -2
  188. data/spec/packets/telemetry_spec.rb +29 -1
  189. data/spec/script/extract_spec.rb +4 -1
  190. data/spec/system/system_spec.rb +111 -3
  191. data/spec/tools/cmd_tlm_server/api_spec.rb +12 -12
  192. data/spec/tools/cmd_tlm_server/background_tasks_spec.rb +2 -2
  193. data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +4 -3
  194. data/spec/tools/cmd_tlm_server/router_thread_spec.rb +2 -3
  195. data/spec/utilities/logger_spec.rb +3 -3
  196. data/spec/utilities/message_log_spec.rb +6 -3
  197. data/tasks/gemfile_stats.rake +22 -13
  198. data/test/performance/Rakefile +4 -4
  199. data/test/performance/config/data/crc.txt +67 -48
  200. metadata +52 -11
  201. data/demo/outputs/dart/logs/README.txt +0 -1
  202. data/lib/cosmos/dart/Gemfile +0 -69
@@ -17,6 +17,7 @@ Cosmos.catch_fatal_exception do
17
17
  require 'cosmos/gui/dialogs/cmd_details_dialog'
18
18
  require 'cosmos/gui/widgets/full_text_search_line_edit'
19
19
  require 'cosmos/tools/cmd_sender/cmd_sender_text_edit'
20
+ require 'cosmos/tools/cmd_sender/cmd_params'
20
21
  require 'cosmos/tools/cmd_sender/cmd_param_table_item_delegate'
21
22
  require 'cosmos/config/config_parser'
22
23
  require 'cosmos/script'
@@ -41,15 +42,6 @@ module Cosmos
41
42
  # command is sent it is added to the command history window which allows the
42
43
  # user to resend the command or copy it for use in a script.
43
44
  class CmdSender < QtTool
44
- slots 'file_send_raw()'
45
- slots 'update_cmd_params(bool)'
46
- slots 'menu_states_in_hex(bool)'
47
- slots 'target_changed(const QString&)'
48
- slots 'cmd_changed(const QString&)'
49
- slots 'send_button()'
50
- slots 'context_menu(const QPoint&)'
51
- slots 'click_callback(QTableWidgetItem*)'
52
-
53
45
  MANUALLY = CmdParamTableItemDelegate::MANUALLY
54
46
 
55
47
  # @return [Integer] Number of commands sent
@@ -62,20 +54,6 @@ module Cosmos
62
54
  @@send_count = val
63
55
  end
64
56
 
65
- # @return [Array<PacketItem, Qt::TableWidgetItem, Qt::TableWidgetItem>]
66
- # Array of the packet item, the table widget item representing the value,
67
- # and the table widget item representing states if the packet item has
68
- # states.
69
- def self.param_widgets
70
- @@param_widgets
71
- end
72
-
73
- # @return [Qt::TableWidget] Table holding the command parameters. Each
74
- # parameter is a separate row in the table.
75
- def self.table
76
- @@table
77
- end
78
-
79
57
  # Create the application by building the GUI and loading an initial target
80
58
  # and command packet. This can be passed on the command line or the first
81
59
  # target and packet will be loaded.
@@ -85,13 +63,11 @@ module Cosmos
85
63
  super(options)
86
64
  Cosmos.load_cosmos_icon("cmd_sender.png")
87
65
 
88
- @file_dir = System.paths['LOGS']
89
66
  @message_log = MessageLog.new('cmdsender')
90
67
  @production = options.production
91
68
  @send_raw_dir = nil
92
69
  @@send_count = 0
93
- @@param_widgets = []
94
- @@table = nil
70
+ @cmd_params = CmdParams.new
95
71
 
96
72
  initialize_actions()
97
73
  initialize_menus()
@@ -146,7 +122,7 @@ module Cosmos
146
122
  @send_raw_action.setEnabled(false)
147
123
  end
148
124
  @send_raw_action.statusTip = tip
149
- connect(@send_raw_action, SIGNAL('triggered()'), self, SLOT('file_send_raw()'))
125
+ @send_raw_action.connect(SIGNAL('triggered()')) { file_send_raw }
150
126
 
151
127
  # Mode menu actions
152
128
  @ignore_range = Qt::Action.new('&Ignore Range Checks', self)
@@ -162,14 +138,18 @@ module Cosmos
162
138
  @states_in_hex = Qt::Action.new('&Display State Values in Hex', self)
163
139
  @states_in_hex.statusTip = 'Display states values in hex instead of decimal'
164
140
  @states_in_hex.setCheckable(true)
165
- @states_in_hex.setChecked(false)
166
- connect(@states_in_hex, SIGNAL('toggled(bool)'), self, SLOT('menu_states_in_hex(bool)'))
141
+ @states_in_hex.setChecked(CmdParams.states_in_hex)
142
+ @states_in_hex.connect(SIGNAL('toggled(bool)')) do |checked|
143
+ @cmd_params.states_in_hex(checked)
144
+ end
167
145
 
168
146
  @show_ignored = Qt::Action.new('&Show Ignored Parameters', self)
169
147
  @show_ignored.statusTip = 'Show ignored parameters which are normally hidden'
170
148
  @show_ignored.setCheckable(true)
171
- @show_ignored.setChecked(false)
172
- connect(@show_ignored, SIGNAL('toggled(bool)'), self, SLOT('update_cmd_params(bool)'))
149
+ @show_ignored.setChecked(CmdParams.show_ignored)
150
+ @show_ignored.connect(SIGNAL('toggled(bool)')) do |checked|
151
+ update_cmd_params(checked)
152
+ end
173
153
 
174
154
  @cmd_raw = Qt::Action.new('Disable &Parameter Conversions', self)
175
155
  tip = 'Send the command without running write or state conversions'
@@ -243,20 +223,23 @@ module Cosmos
243
223
  # Set the target combobox selection
244
224
  @target_select = Qt::ComboBox.new
245
225
  @target_select.setMaxVisibleItems(6)
246
- connect(@target_select, SIGNAL('activated(const QString&)'), self, SLOT('target_changed(const QString&)'))
226
+ @target_select.connect(SIGNAL('activated(const QString&)')) do |target|
227
+ update_commands()
228
+ update_cmd_params()
229
+ end
247
230
  target_label = Qt::Label.new("&Target:")
248
231
  target_label.setBuddy(@target_select)
249
232
 
250
233
  # Set the comamnd combobox selection
251
234
  @cmd_select = Qt::ComboBox.new
252
235
  @cmd_select.setMaxVisibleItems(20)
253
- connect(@cmd_select, SIGNAL('activated(const QString&)'), self, SLOT('cmd_changed(const QString&)'))
236
+ @cmd_select.connect(SIGNAL('activated(const QString&)')) {|command| update_cmd_params }
254
237
  cmd_label = Qt::Label.new("&Command:")
255
238
  cmd_label.setBuddy(@cmd_select)
256
239
 
257
240
  # Button to send command
258
241
  send = Qt::PushButton.new("Send")
259
- connect(send, SIGNAL('clicked()'), self, SLOT('send_button()'))
242
+ send.connect(SIGNAL('clicked()')) { send_button }
260
243
 
261
244
  # Layout the top level selection
262
245
  select_layout = Qt::HBoxLayout.new
@@ -326,32 +309,6 @@ module Cosmos
326
309
  history
327
310
  end
328
311
 
329
- # Changes the display of items with states to hex if checked is true.
330
- # Otherwise state values are displayed as decimal.
331
- # @param checked [Boolean] Whether to display state values in hex
332
- def menu_states_in_hex(checked)
333
- @@param_widgets.each do |_, _, state_value_item|
334
- next unless state_value_item
335
- text = state_value_item.text
336
- quotes_removed = text.remove_quotes
337
- if text == quotes_removed
338
- if checked
339
- if text.is_int?
340
- @@table.blockSignals(true)
341
- state_value_item.text = sprintf("0x%X", text.to_i)
342
- @@table.blockSignals(false)
343
- end
344
- else
345
- if text.is_hex?
346
- @@table.blockSignals(true)
347
- state_value_item.text = Integer(text).to_s
348
- @@table.blockSignals(false)
349
- end
350
- end
351
- end
352
- end
353
- end
354
-
355
312
  # Opens a dialog which allows the user to select a file to read and send
356
313
  # directly over the interface.
357
314
  def file_send_raw
@@ -417,17 +374,6 @@ module Cosmos
417
374
  super(event)
418
375
  end
419
376
 
420
- # Updates the commands combobox and command parameters table
421
- def target_changed(_)
422
- update_commands()
423
- update_cmd_params()
424
- end
425
-
426
- # Updates the command parameters table
427
- def cmd_changed(_)
428
- update_cmd_params()
429
- end
430
-
431
377
  # Sends the current command and parameters to the target
432
378
  def send_button
433
379
  target_name = @target_select.text
@@ -470,26 +416,8 @@ module Cosmos
470
416
 
471
417
  # @return [String, Hash] Command as it would appear in a ScriptRunner script
472
418
  def view_as_script
473
- params = {}
474
-
475
- @@param_widgets.each do |packet_item, value_item, state_value_item|
476
- text = value_item.text
477
-
478
- text = state_value_item.text if state_value_item && (text == MANUALLY or @cmd_raw.checked?)
479
- quotes_removed = text.remove_quotes
480
- if text == quotes_removed
481
- if (packet_item.data_type == :STRING or packet_item.data_type == :BLOCK) and text.upcase.start_with?("0X")
482
- params[packet_item.name] = text.hex_to_byte_string
483
- else
484
- params[packet_item.name] = text.convert_to_value
485
- end
486
- else
487
- params[packet_item.name] = quotes_removed
488
- end
489
- raise "#{packet_item.name} is required." if quotes_removed == '' && packet_item.required
490
- end
491
419
  statusBar.clearMessage()
492
-
420
+ params = @cmd_params.params_text(@cmd_raw.checked?)
493
421
  output_string = System.commands.build_cmd_output_string(@target_select.text, @cmd_select.text, params, @cmd_raw.checked?)
494
422
  if output_string =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/
495
423
  output_string = output_string.inspect.remove_quotes
@@ -552,22 +480,9 @@ module Cosmos
552
480
 
553
481
  # Updates the command parameters table based on the selected target and
554
482
  # packet comboboxes
555
- # @param ignored_toggle [Boolean] Whether to display the ignored
556
- # parameters. Pass nil (the default) to keep the existing setting.
557
- def update_cmd_params(ignored_toggle = nil)
558
- old_params = {}
559
- if !ignored_toggle.nil?
560
- # Save parameter values
561
- @@param_widgets.each do |packet_item, value_item, state_value_item|
562
- text = value_item.text
563
- if state_value_item
564
- old_params[packet_item.name] = [text, state_value_item.text]
565
- else
566
- old_params[packet_item.name] = text
567
- end
568
- end
569
- end
570
-
483
+ # @param checked [Boolean] Whether the show ignored parameters option
484
+ # is checked. Pass nil (the default) to keep the existing setting.
485
+ def update_cmd_params(checked = nil)
571
486
  # Clear Status Bar
572
487
  statusBar.showMessage("")
573
488
 
@@ -576,222 +491,18 @@ module Cosmos
576
491
  packet_name = @cmd_select.text
577
492
  if target_name && packet_name
578
493
  packet = System.commands.packet(target_name, packet_name)
579
- packet_items = packet.sorted_items
580
- shown_packet_items = []
581
- packet_items.each do |packet_item|
582
- next if target && target.ignored_parameters.include?(packet_item.name) && !@show_ignored.checked?
583
- shown_packet_items << packet_item
584
- end
585
-
586
- # Update Command Description
587
- @description.text = packet.description.to_s
588
-
589
- # Destroy the old table widget
590
- @@table.dispose if @@table
591
- @@table = nil
592
-
593
- # Update Parameters
594
- @@param_widgets = []
595
- drawn_header = false
596
-
597
- row = 0
598
- shown_packet_items.each do |packet_item|
599
- next if target && target.ignored_parameters.include?(packet_item.name) && !@show_ignored.checked?
600
- value_item = nil
601
- state_value_item = nil
602
-
603
- unless drawn_header
604
- @@table = Qt::TableWidget.new()
605
- @@table.setSizePolicy(Qt::SizePolicy::Expanding, Qt::SizePolicy::Expanding)
606
- @@table.setWordWrap(true)
607
- @@table.setRowCount(shown_packet_items.length)
608
- @@table.setColumnCount(5)
609
- @@table.setHorizontalHeaderLabels(['Name', ' Value or State ', ' ', 'Units', 'Description'])
610
- @@table.horizontalHeader.setStretchLastSection(true)
611
- @@table.verticalHeader.setVisible(false)
612
- @@table.setItemDelegate(CmdParamTableItemDelegate.new(@@table, @@param_widgets, @production))
613
- @@table.setContextMenuPolicy(Qt::CustomContextMenu)
614
- @@table.verticalHeader.setResizeMode(Qt::HeaderView::ResizeToContents)
615
- @@table.setEditTriggers(Qt::AbstractItemView::DoubleClicked | Qt::AbstractItemView::SelectedClicked | Qt::AbstractItemView::AnyKeyPressed)
616
- @@table.setSelectionMode(Qt::AbstractItemView::NoSelection)
617
- connect(@@table, SIGNAL('customContextMenuRequested(const QPoint&)'), self, SLOT('context_menu(const QPoint&)'))
618
- connect(@@table, SIGNAL('itemClicked(QTableWidgetItem*)'), self, SLOT('click_callback(QTableWidgetItem*)'))
619
- drawn_header = true
620
- end
621
-
622
- # Parameter Name
623
- item = Qt::TableWidgetItem.new("#{packet_item.name}:")
624
- item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
625
- item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
626
- @@table.setItem(row, 0, item)
627
-
628
- if packet_item.states
629
- default_state = packet_item.states.key(packet_item.default)
630
- if old_params[packet_item.name]
631
- value_item = Qt::TableWidgetItem.new(old_params[packet_item.name][0])
632
- else
633
- if default_state
634
- value_item = Qt::TableWidgetItem.new(default_state.to_s)
635
- elsif @production
636
- value_item = Qt::TableWidgetItem.new(packet_item.states.keys[0])
637
- else
638
- value_item = Qt::TableWidgetItem.new(MANUALLY)
639
- end
640
- end
641
- value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
642
- value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
643
- @@table.setItem(row, 1, value_item)
644
-
645
- if old_params[packet_item.name]
646
- state_value_item = Qt::TableWidgetItem.new(old_params[packet_item.name][1])
647
- else
648
- if @states_in_hex.checked? && packet_item.default.kind_of?(Integer)
649
- state_value_item = Qt::TableWidgetItem.new(sprintf("0x%X", packet_item.default))
650
- else
651
- default_str = packet_item.default.to_s
652
- if default_str.is_printable?
653
- state_value_item = Qt::TableWidgetItem.new(default_str)
654
- else
655
- state_value_item = Qt::TableWidgetItem.new("0x" + default_str.simple_formatted)
656
- end
657
- end
658
- end
659
- state_value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
660
- if @production
661
- state_value_item.setFlags(Qt::NoItemFlags)
662
- else
663
- state_value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
664
- end
665
- @@table.setItem(row, 2, state_value_item)
666
-
667
- # If the parameter is required clear the combobox and
668
- # clear the value field so they have to choose something
669
- if packet_item.required && !old_params[packet_item.name]
670
- value_item.setText('')
671
- state_value_item.setText('')
672
- end
673
- else
674
- # Parameter Value
675
- if old_params[packet_item.name]
676
- value_item = Qt::TableWidgetItem.new(old_params[packet_item.name])
677
- else
678
- if packet_item.required
679
- value_text = ''
680
- else
681
- if packet_item.format_string
682
- begin
683
- value_text = sprintf(packet_item.format_string, packet_item.default)
684
- rescue
685
- # Oh well - Don't use the format string
686
- value_text = packet_item.default.to_s
687
- end
688
- else
689
- value_text = packet_item.default.to_s
690
- end
691
- if !value_text.is_printable?
692
- value_text = "0x" + value_text.simple_formatted
693
- # Add quotes around STRING or BLOCK defaults so CmdSender interprets them correctly
694
- elsif (packet_item.data_type == :STRING or packet_item.data_type == :BLOCK)
695
- value_text = "'#{packet_item.default}'"
696
- end
697
- end
698
- value_item = Qt::TableWidgetItem.new(value_text)
699
- end
700
- value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
701
- value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
702
- @@table.setItem(row, 1, value_item)
703
- @@table.setSpan(row, 1, 1, 2)
704
- end
705
-
706
- # Units
707
- item = Qt::TableWidgetItem.new(packet_item.units.to_s)
708
- item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
709
- item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
710
- @@table.setItem(row, 3, item)
711
-
712
- # Description
713
- item = Qt::TableWidgetItem.new(packet_item.description.to_s)
714
- item.setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter)
715
- item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
716
- @@table.setItem(row, 4, item)
717
-
718
- @@param_widgets << [packet_item, value_item, state_value_item]
719
- row += 1
720
- end
721
-
722
- if @@table
723
- @@table.connect(SIGNAL('itemChanged(QTableWidgetItem*)')) do |item|
724
- packet_item, value_item, state_value_item = @@param_widgets[item.row]
725
- if item.column == 1
726
- if packet_item.states
727
- value = packet_item.states[value_item.text]
728
- @@table.blockSignals(true)
729
- if @states_in_hex.checked? && value.kind_of?(Integer)
730
- state_value_item.setText(sprintf("0x%X", value))
731
- else
732
- state_value_item.setText(value.to_s)
733
- end
734
- @@table.blockSignals(false)
735
- end
736
- elsif item.column == 2
737
- @@table.blockSignals(true)
738
- @@table.item(item.row, 1).setText(MANUALLY)
739
- @@table.blockSignals(false)
740
- end
741
- end
742
- @table_layout.addWidget(@@table, 500)
743
- @@table.resizeColumnsToContents()
744
- @@table.resizeRowsToContents()
745
- end
746
- end # if target_name && packet_name
747
- end
748
-
749
- # If the user right clicks over a table item, this method displays a context
750
- # menu with various options.
751
- # @param point [Qt::Point] Point to display the context menu
752
- def context_menu(point)
753
- target_name = @target_select.text
754
- packet_name = @cmd_select.text
755
- item = @@table.itemAt(point)
756
- if item
757
- item_name = @@table.item(item.row, 0).text[0..-2] # Remove :
758
- if target_name.length > 0 && packet_name.length > 0 && item_name.length > 0
759
- menu = Qt::Menu.new()
760
-
761
- details_action = Qt::Action.new("Details #{target_name} #{packet_name} #{item_name}", self)
762
- details_action.statusTip = "Popup details about #{target_name} #{packet_name} #{item_name}"
763
- details_action.connect(SIGNAL('triggered()')) do
764
- CmdDetailsDialog.new(nil, target_name, packet_name, item_name)
765
- end
766
- menu.addAction(details_action)
767
-
768
- file_chooser_action = Qt::Action.new("Insert Filename", self)
769
- file_chooser_action.statusTip = "Select a file and place its name into this parameter"
770
- file_chooser_action.connect(SIGNAL('triggered()')) do
771
- filename = Qt::FileDialog::getOpenFileName(self, "Insert Filename:", @file_dir, "All Files (*)")
772
- if filename && !filename.empty?
773
- @file_dir = File.dirname(filename)
774
- _, value_item, state_value_item = @@param_widgets[item.row]
775
- if state_value_item
776
- state_value_item.setText(filename)
777
- elsif value_item
778
- value_item.setText(filename)
779
- end
780
- end
781
- end
782
- menu.addAction(file_chooser_action)
783
-
784
- menu.exec(@@table.mapToGlobal(point))
785
- menu.dispose
494
+ # Directly update packet description ... safe because always in GUI thread
495
+ hazardous, _ = System.commands.cmd_hazardous?(target_name, packet_name)
496
+ if hazardous
497
+ @description.text = "(Hazardous) #{packet.description}"
498
+ else
499
+ @description.text = packet.description
786
500
  end
501
+ table = @cmd_params.update_cmd_params(packet, show_ignored: checked)
502
+ @table_layout.addWidget(table, 500) if table
787
503
  end
788
504
  end
789
505
 
790
- # @param item [Qt::TableWidgetItem] Item which was left clicked
791
- def click_callback(item)
792
- @@table.editItem(item) if (item.flags & Qt::ItemIsEditable) != 0
793
- end
794
-
795
506
  # (see QtTool.run)
796
507
  def self.run(option_parser = nil, options = nil)
797
508
  Cosmos.catch_fatal_exception do
@@ -135,17 +135,21 @@ module Cosmos
135
135
  @show_ignored = Qt::Action.new('&Show Ignored Parameters', self)
136
136
  @show_ignored.statusTip = 'Show ignored parameters which are normally hidden'
137
137
  @show_ignored.setCheckable(true)
138
- @show_ignored.setChecked(false)
139
- @show_ignored.connect(SIGNAL('toggled(bool)')) do |bool|
140
- @sequence_list.map {|item| item.show_ignored(bool) }
138
+ @show_ignored.setChecked(CmdParams.show_ignored)
139
+ @show_ignored.connect(SIGNAL('toggled(bool)')) do |checked|
140
+ # In case there aren't any sequences open, make sure to store the current value
141
+ CmdParams.show_ignored = checked
142
+ @sequence_list.map {|item| item.show_ignored(checked) }
141
143
  end
142
144
 
143
145
  @states_in_hex = Qt::Action.new('&Display State Values in Hex', self)
144
146
  @states_in_hex.statusTip = 'Display states values in hex instead of decimal'
145
147
  @states_in_hex.setCheckable(true)
146
- @states_in_hex.setChecked(false)
147
- @states_in_hex.connect(SIGNAL('toggled(bool)')) do |bool|
148
- @sequence_list.map {|item| item.states_in_hex(bool) }
148
+ @states_in_hex.setChecked(CmdParams.states_in_hex)
149
+ @states_in_hex.connect(SIGNAL('toggled(bool)')) do |checked|
150
+ # In case there aren't any sequences open, make sure to store the current value
151
+ CmdParams.states_in_hex = checked
152
+ @sequence_list.map {|item| item.states_in_hex(checked) }
149
153
  end
150
154
 
151
155
  @expand_action = Qt::Action.new('&Expand All', self)
@@ -226,9 +230,7 @@ module Cosmos
226
230
 
227
231
  @target_select = Qt::ComboBox.new
228
232
  @target_select.setMaxVisibleItems(6)
229
- @target_select.connect(SIGNAL('activated(const QString&)')) do |target|
230
- target_changed()
231
- end
233
+ @target_select.connect(SIGNAL('activated(const QString&)')) {|target| target_changed() }
232
234
  target_label = Qt::Label.new("&Target:")
233
235
  target_label.setBuddy(@target_select)
234
236
 
@@ -253,7 +255,7 @@ module Cosmos
253
255
  splitter = Qt::Splitter.new(Qt::Vertical, self)
254
256
  central_layout.addWidget(splitter)
255
257
 
256
- @sequence_list = SequenceList.new
258
+ @sequence_list = SequenceList.new(self)
257
259
  @sequence_list.connect(SIGNAL("modified()")) { update_title }
258
260
 
259
261
  @scroll = Qt::ScrollArea.new()
@@ -278,11 +280,7 @@ module Cosmos
278
280
  end
279
281
 
280
282
  def add_command
281
- command = System.commands.packet(@target_select.text, @cmd_select.text).dup
282
- command.restore_defaults
283
- item = @sequence_list.add(command)
284
- item.show_ignored(@show_ignored.isChecked())
285
- item.states_in_hex(@states_in_hex.isChecked())
283
+ item = @sequence_list.add(@target_select.text.strip, @cmd_select.text.strip)
286
284
  end
287
285
 
288
286
  # Export the sequence list into a custom binary format
@@ -300,6 +298,7 @@ module Cosmos
300
298
  return unless prompt_for_save_if_needed()
301
299
  @sequence_list.clear
302
300
  @filename = "Untitled"
301
+ update_title()
303
302
  end
304
303
 
305
304
  # Opens a sequence list file and populates the GUI
@@ -314,8 +313,6 @@ module Cosmos
314
313
  if !filename.nil? && File.exist?(filename) && !File.directory?(filename)
315
314
  # Try to open and load the file. Errors are handled here.
316
315
  @sequence_list.open(filename)
317
- @sequence_list.map {|item| item.show_ignored(@show_ignored.isChecked()) }
318
- @sequence_list.map {|item| item.states_in_hex(@states_in_hex.isChecked()) }
319
316
  @filename = filename
320
317
  @sequence_dir = File.dirname(filename)
321
318
  @sequence_dir << '/' if @sequence_dir[-1..-1] != '/' and @sequence_dir[-1..-1] != '\\'