cosmos 3.9.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (438) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +23 -0
  3. data/.travis.yml +1 -0
  4. data/.yardopts +3 -0
  5. data/Gemfile +1 -1
  6. data/Manifest.txt +137 -52
  7. data/Rakefile +50 -44
  8. data/autohotkey/config/system/system.txt +0 -5
  9. data/autohotkey/config/targets/INST/cmd_tlm/inst_cmds.txt +6 -1
  10. data/autohotkey/config/targets/INST/screens/extra.txt +19 -0
  11. data/autohotkey/config/targets/INST/sequences/run_sequence.txt +1 -0
  12. data/autohotkey/config/targets/META/screens/data.txt +12 -0
  13. data/autohotkey/config/targets/SYSTEM/cmd_tlm/meta_cmd_tlm.txt +16 -0
  14. data/autohotkey/config/targets/{COSMOS/cmd_tlm/cosmos_server_cmds.txt → SYSTEM/cmd_tlm/system_cmds.txt} +8 -8
  15. data/autohotkey/config/targets/SYSTEM/cmd_tlm/system_tlm.txt +7 -0
  16. data/autohotkey/config/targets/SYSTEM/screens/limits_change.txt +14 -0
  17. data/autohotkey/config/targets/SYSTEM/screens/meta.txt +14 -0
  18. data/autohotkey/config/targets/SYSTEM/target.txt +12 -0
  19. data/autohotkey/config/tools/cmd_tlm_server/cmd_tlm_server.txt +2 -2
  20. data/autohotkey/config/tools/test_runner/test_runner2.txt +1 -1
  21. data/autohotkey/tools/CmdSequence +14 -0
  22. data/autohotkey/tools/CmdSequenceAHK +23 -0
  23. data/autohotkey/tools/CmdSequenceAHK2 +16 -0
  24. data/autohotkey/tools/cmd_extractor.ahk +2 -2
  25. data/autohotkey/tools/cmd_sender.ahk +4 -6
  26. data/autohotkey/tools/cmd_sequence.ahk +215 -0
  27. data/autohotkey/tools/cmd_sequence2.ahk +23 -0
  28. data/autohotkey/tools/data_viewer.ahk +2 -3
  29. data/autohotkey/tools/limits_monitor.ahk +9 -11
  30. data/autohotkey/tools/open_gl_builder.ahk +1 -2
  31. data/autohotkey/tools/packet_viewer.ahk +51 -35
  32. data/autohotkey/tools/replay.ahk +1 -2
  33. data/autohotkey/tools/script_runner.ahk +1 -2
  34. data/autohotkey/tools/script_runner2.ahk +1 -2
  35. data/autohotkey/tools/test_runner2.ahk +1 -5
  36. data/autohotkey/tools/test_runner3.ahk +1 -3
  37. data/autohotkey/tools/tlm_grapher.ahk +1 -3
  38. data/autohotkey/tools/tlm_grapher3.ahk +1 -2
  39. data/autohotkey/tools/tlm_viewer.ahk +8 -3
  40. data/autohotkey/tools/tlm_viewer2.ahk +2 -3
  41. data/autohotkey/tools/tlm_viewer5.ahk +1 -2
  42. data/cosmos.gemspec +26 -20
  43. data/data/cmd_sequence.png +0 -0
  44. data/data/config/_array_params.yaml +23 -0
  45. data/data/config/_id_items.yaml +24 -0
  46. data/data/config/_id_params.yaml +58 -0
  47. data/data/config/_interfaces.yaml +206 -0
  48. data/data/config/_items.yaml +20 -0
  49. data/data/config/_params.yaml +58 -0
  50. data/data/config/cmd_tlm_server.yaml +110 -0
  51. data/data/config/command.yaml +38 -0
  52. data/data/config/command_modifiers.yaml +127 -0
  53. data/data/config/command_telemetry.yaml +3 -0
  54. data/data/config/data_viewer.yaml +43 -0
  55. data/data/config/handbook_creator.yaml +23 -0
  56. data/data/config/housekeeping_params.yaml +71 -0
  57. data/data/config/interface_modifiers.yaml +44 -0
  58. data/data/config/item_modifiers.yaml +172 -0
  59. data/data/config/launcher.yaml +117 -0
  60. data/data/config/limits_monitor.yaml +53 -0
  61. data/data/config/linegraph_params.yaml +30 -0
  62. data/data/config/linegraph_plot.yaml +106 -0
  63. data/data/config/page_modifiers.yaml +128 -0
  64. data/data/config/param_item_modifiers.yaml +41 -0
  65. data/data/config/parameter_modifiers.yaml +144 -0
  66. data/data/config/protocols.yaml +257 -0
  67. data/data/config/screen.yaml +151 -0
  68. data/data/config/script_runner.yaml +15 -0
  69. data/data/config/system.yaml +153 -0
  70. data/data/config/table_manager.yaml +76 -0
  71. data/data/config/table_parameter_modifiers.yaml +9 -0
  72. data/data/config/target.yaml +71 -0
  73. data/data/config/telemetry.yaml +73 -0
  74. data/data/config/telemetry_modifiers.yaml +129 -0
  75. data/data/config/test_runner.yaml +118 -0
  76. data/data/config/tlm_extractor.yaml +109 -0
  77. data/data/config/tlm_grapher.yaml +78 -0
  78. data/data/config/tlm_viewer.yaml +107 -0
  79. data/data/config/unknown.yaml +3 -0
  80. data/data/config/widgets.yaml +1339 -0
  81. data/data/config/xy_params.yaml +50 -0
  82. data/data/config/xy_plot.yaml +12 -0
  83. data/data/config_editor.png +0 -0
  84. data/data/crc.txt +172 -161
  85. data/data/delete.png +0 -0
  86. data/demo/config/data/crc.txt +56 -36
  87. data/demo/config/data/meta_init.txt +1 -4
  88. data/demo/config/system/system.txt +15 -3
  89. data/demo/config/system/system2.txt +13 -3
  90. data/demo/config/targets/EXAMPLE/lib/example_interface.rb +2 -6
  91. data/demo/config/targets/EXAMPLE/target.txt +3 -1
  92. data/demo/config/targets/INST/cmd_tlm/inst_cmds.txt +1 -0
  93. data/demo/config/targets/INST/lib/inst_dump_component.rb +34 -0
  94. data/demo/config/targets/INST/screens/adcs.txt +39 -15
  95. data/demo/config/targets/INST/screens/commanding.txt +26 -19
  96. data/demo/config/targets/INST/screens/spacing_box.txt +44 -0
  97. data/demo/config/targets/INST/screens/spacing_grid.txt +78 -0
  98. data/demo/config/targets/INST/screens/tabs.txt +0 -2
  99. data/demo/config/targets/INST/sequences/sequence.tsv +3 -0
  100. data/demo/config/targets/INST/tables/EventAction.csv +9 -0
  101. data/demo/config/targets/INST/tables/EventAction.dat +0 -0
  102. data/demo/config/targets/INST/tables/McConfigTable.csv +20 -0
  103. data/demo/config/targets/INST/tables/McConfigTable.dat +0 -0
  104. data/demo/config/targets/INST/target.txt +4 -0
  105. data/demo/config/targets/INST/tools/data_viewer/data_viewer.txt +2 -0
  106. data/demo/config/targets/INST/tools/data_viewer/data_viewer2.txt +2 -0
  107. data/demo/config/targets/INST/tools/table_manager/EventAction_def.txt +6 -0
  108. data/demo/config/targets/INST/tools/table_manager/McConfigTable_def.txt +38 -0
  109. data/demo/config/targets/SYSTEM/cmd_tlm/limits_groups.txt +7 -3
  110. data/demo/config/targets/SYSTEM/cmd_tlm/meta_cmd_tlm.txt +16 -0
  111. data/demo/config/targets/{COSMOS/cmd_tlm/cosmos_server_cmds.txt → SYSTEM/cmd_tlm/system_cmds.txt} +8 -8
  112. data/demo/config/targets/SYSTEM/cmd_tlm/system_tlm.txt +7 -0
  113. data/demo/config/targets/{COSMOS → SYSTEM}/cmd_tlm_server.txt +2 -2
  114. data/demo/config/targets/SYSTEM/lib/limits_groups.rb +39 -0
  115. data/demo/config/targets/SYSTEM/screens/status.txt +1 -1
  116. data/demo/config/targets/SYSTEM/target.txt +12 -0
  117. data/demo/config/targets/TEMPLATED/cmd_tlm_server.txt +1 -1
  118. data/demo/config/targets/TEMPLATED/lib/templated_interface.rb +8 -5
  119. data/demo/config/targets/TEMPLATED/target.txt +2 -0
  120. data/demo/config/tools/cmd_tlm_server/cmd_tlm_server.txt +15 -6
  121. data/demo/config/tools/cmd_tlm_server/cmd_tlm_server2.txt +13 -5
  122. data/demo/config/tools/data_viewer/data_viewer.txt +9 -0
  123. data/demo/config/tools/launcher/launcher.txt +9 -6
  124. data/demo/config/tools/launcher/launcher2.txt +16 -13
  125. data/demo/config/tools/launcher/launcher_mini.txt +45 -0
  126. data/demo/config/tools/table_manager/MCConfigurationTable_fsw1_def.txt +12 -11
  127. data/demo/config/tools/table_manager/MCConfigurationTable_fsw2_def.txt +12 -11
  128. data/demo/config/tools/test_runner/test_runner.txt +1 -1
  129. data/demo/config/tools/tlm_viewer/tlm_viewer.txt +5 -5
  130. data/demo/lib/example_background_task.rb +9 -5
  131. data/demo/lib/example_target.rb +5 -15
  132. data/demo/lib/scpi_target.rb +4 -10
  133. data/demo/procedures/cosmos_api_test.rb +17 -0
  134. data/demo/tools/CmdSequence +16 -0
  135. data/demo/tools/CmdSequence.bat +9 -0
  136. data/demo/tools/ConfigEditor +16 -0
  137. data/demo/tools/ConfigEditor.bat +9 -0
  138. data/demo/tools/mac/CmdSequence.app/Contents/Info.plist +38 -0
  139. data/demo/tools/mac/CmdSequence.app/Contents/MacOS/CmdSequence.rb +16 -0
  140. data/demo/tools/mac/CmdSequence.app/Contents/MacOS/main.sh +10 -0
  141. data/demo/tools/mac/CmdSequence.app/Contents/MacOS/tool_launch.rb +38 -0
  142. data/demo/tools/mac/CmdSequence.app/Contents/Resources/appIcon.icns +0 -0
  143. data/ext/cosmos/ext/packet/packet.c +5 -5
  144. data/install/config/data/crc.txt +12 -8
  145. data/install/config/system/system.txt +13 -3
  146. data/install/config/targets/SYSTEM/cmd_tlm/meta_cmd_tlm.txt +14 -0
  147. data/install/config/targets/SYSTEM/target.txt +12 -0
  148. data/install/tools/CmdSequence +16 -0
  149. data/install/tools/CmdSequence.bat +9 -0
  150. data/install/tools/ConfigEditor +16 -0
  151. data/install/tools/ConfigEditor.bat +9 -0
  152. data/install/tools/mac/CmdSequence.app/Contents/Info.plist +38 -0
  153. data/install/tools/mac/CmdSequence.app/Contents/MacOS/CmdSequence.rb +16 -0
  154. data/install/tools/mac/CmdSequence.app/Contents/MacOS/main.sh +10 -0
  155. data/install/tools/mac/CmdSequence.app/Contents/MacOS/tool_launch.rb +38 -0
  156. data/install/tools/mac/CmdSequence.app/Contents/Resources/appIcon.icns +0 -0
  157. data/lib/cosmos.rb +1 -1
  158. data/lib/cosmos/config/config_parser.rb +147 -59
  159. data/lib/cosmos/config/meta_config_parser.rb +57 -0
  160. data/lib/cosmos/conversions/polynomial_conversion.rb +20 -4
  161. data/lib/cosmos/conversions/unix_time_conversion.rb +4 -4
  162. data/lib/cosmos/core_ext/array.rb +45 -5
  163. data/lib/cosmos/core_ext/cosmos_io.rb +31 -15
  164. data/lib/cosmos/core_ext/file.rb +2 -2
  165. data/lib/cosmos/core_ext/kernel.rb +1 -6
  166. data/lib/cosmos/core_ext/objectspace.rb +0 -2
  167. data/lib/cosmos/core_ext/string.rb +27 -4
  168. data/lib/cosmos/core_ext/time.rb +39 -10
  169. data/lib/cosmos/gui/choosers/combobox_chooser.rb +37 -26
  170. data/lib/cosmos/gui/choosers/file_chooser.rb +23 -6
  171. data/lib/cosmos/gui/choosers/float_chooser.rb +13 -11
  172. data/lib/cosmos/gui/choosers/integer_chooser.rb +13 -11
  173. data/lib/cosmos/gui/choosers/string_chooser.rb +18 -36
  174. data/lib/cosmos/gui/choosers/telemetry_chooser.rb +64 -64
  175. data/lib/cosmos/gui/choosers/value_chooser.rb +15 -15
  176. data/lib/cosmos/gui/dialogs/about_dialog.rb +18 -13
  177. data/lib/cosmos/gui/dialogs/calendar_dialog.rb +11 -3
  178. data/lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb +1 -1
  179. data/lib/cosmos/gui/dialogs/details_dialog.rb +1 -1
  180. data/lib/cosmos/gui/dialogs/exception_dialog.rb +7 -7
  181. data/lib/cosmos/gui/dialogs/find_replace_dialog.rb +20 -15
  182. data/lib/cosmos/gui/dialogs/interface_raw_dialog.rb +143 -0
  183. data/lib/cosmos/gui/dialogs/legal_dialog.rb +6 -5
  184. data/lib/cosmos/gui/dialogs/packet_log_dialog.rb +5 -2
  185. data/lib/cosmos/gui/dialogs/progress_dialog.rb +1 -1
  186. data/lib/cosmos/gui/dialogs/pry_dialog.rb +4 -4
  187. data/lib/cosmos/gui/dialogs/scroll_text_dialog.rb +3 -0
  188. data/lib/cosmos/gui/dialogs/set_tlm_dialog.rb +7 -6
  189. data/lib/cosmos/gui/dialogs/splash.rb +1 -1
  190. data/lib/cosmos/gui/dialogs/tlm_details_dialog.rb +1 -1
  191. data/lib/cosmos/gui/dialogs/tlm_graph_dialog.rb +114 -0
  192. data/lib/cosmos/gui/line_graph/line_graph.rb +9 -10
  193. data/lib/cosmos/gui/line_graph/line_graph_dialog.rb +7 -5
  194. data/lib/cosmos/gui/line_graph/line_graph_drawing.rb +3 -7
  195. data/lib/cosmos/gui/line_graph/line_graph_popups.rb +3 -8
  196. data/lib/cosmos/gui/line_graph/line_graph_scaling.rb +2 -7
  197. data/lib/cosmos/gui/line_graph/overview_graph.rb +6 -1
  198. data/lib/cosmos/gui/opengl/earth_model.rb +6 -3
  199. data/lib/cosmos/gui/opengl/gl_bounds.rb +11 -23
  200. data/lib/cosmos/gui/opengl/gl_light.rb +3 -4
  201. data/lib/cosmos/gui/opengl/gl_material.rb +3 -4
  202. data/lib/cosmos/gui/opengl/gl_scene.rb +10 -4
  203. data/lib/cosmos/gui/opengl/gl_shape.rb +6 -2
  204. data/lib/cosmos/gui/opengl/gl_viewer.rb +5 -5
  205. data/lib/cosmos/gui/opengl/gl_viewport.rb +11 -12
  206. data/lib/cosmos/gui/opengl/moon_model.rb +6 -3
  207. data/lib/cosmos/gui/opengl/stl_reader.rb +8 -9
  208. data/lib/cosmos/gui/opengl/stl_shape.rb +4 -5
  209. data/lib/cosmos/gui/opengl/texture_mapped_sphere.rb +7 -7
  210. data/lib/cosmos/gui/qt.rb +1 -1
  211. data/lib/cosmos/gui/qt_tool.rb +21 -10
  212. data/lib/cosmos/gui/text/completion.rb +23 -2
  213. data/lib/cosmos/gui/text/completion_text_edit.rb +38 -23
  214. data/lib/cosmos/gui/utilities/analyze_log.rb +1 -1
  215. data/lib/cosmos/gui/utilities/screenshot.rb +2 -2
  216. data/lib/cosmos/gui/widgets/full_text_search_line_edit.rb +11 -1
  217. data/lib/cosmos/gui/widgets/packet_log_frame.rb +19 -6
  218. data/lib/cosmos/interfaces.rb +10 -0
  219. data/lib/cosmos/interfaces/cmd_tlm_server_interface.rb +28 -47
  220. data/lib/cosmos/interfaces/interface.rb +240 -22
  221. data/lib/cosmos/interfaces/linc_interface.rb +3 -5
  222. data/lib/cosmos/interfaces/protocols/burst_protocol.rb +173 -0
  223. data/lib/cosmos/interfaces/protocols/crc_protocol.rb +141 -0
  224. data/lib/cosmos/{streams/fixed_stream_protocol.rb → interfaces/protocols/fixed_protocol.rb} +40 -37
  225. data/lib/cosmos/{streams/length_stream_protocol.rb → interfaces/protocols/length_protocol.rb} +55 -48
  226. data/lib/cosmos/interfaces/protocols/override_protocol.rb +52 -0
  227. data/lib/cosmos/interfaces/protocols/preidentified_protocol.rb +141 -0
  228. data/lib/cosmos/interfaces/protocols/protocol.rb +60 -0
  229. data/lib/cosmos/interfaces/protocols/template_protocol.rb +209 -0
  230. data/lib/cosmos/interfaces/protocols/terminated_protocol.rb +81 -0
  231. data/lib/cosmos/interfaces/serial_interface.rb +28 -23
  232. data/lib/cosmos/interfaces/simulated_target_interface.rb +27 -16
  233. data/lib/cosmos/interfaces/stream_interface.rb +36 -108
  234. data/lib/cosmos/interfaces/tcpip_client_interface.rb +21 -21
  235. data/lib/cosmos/interfaces/tcpip_server_interface.rb +555 -94
  236. data/lib/cosmos/interfaces/udp_interface.rb +51 -83
  237. data/lib/cosmos/io/buffered_file.rb +92 -2
  238. data/lib/cosmos/io/json_drb.rb +2 -2
  239. data/lib/cosmos/io/posix_serial_driver.rb +3 -1
  240. data/lib/cosmos/io/raw_logger.rb +3 -3
  241. data/lib/cosmos/io/serial_driver.rb +14 -5
  242. data/lib/cosmos/io/win32_serial_driver.rb +16 -4
  243. data/lib/cosmos/packet_logs.rb +0 -1
  244. data/lib/cosmos/packet_logs/packet_log_reader.rb +11 -1
  245. data/lib/cosmos/packet_logs/packet_log_writer.rb +31 -13
  246. data/lib/cosmos/packets/binary_accessor.rb +599 -32
  247. data/lib/cosmos/packets/commands.rb +48 -24
  248. data/lib/cosmos/packets/packet.rb +140 -54
  249. data/lib/cosmos/packets/packet_config.rb +0 -2
  250. data/lib/cosmos/packets/parsers/packet_item_parser.rb +10 -2
  251. data/lib/cosmos/packets/structure.rb +81 -33
  252. data/lib/cosmos/packets/structure_item.rb +45 -5
  253. data/lib/cosmos/packets/telemetry.rb +149 -55
  254. data/lib/cosmos/script/api_shared.rb +1000 -0
  255. data/lib/cosmos/script/commands.rb +2 -2
  256. data/lib/cosmos/script/extract.rb +19 -4
  257. data/lib/cosmos/script/limits.rb +2 -0
  258. data/lib/cosmos/script/script.rb +1 -1
  259. data/lib/cosmos/script/scripting.rb +4 -784
  260. data/lib/cosmos/script/telemetry.rb +44 -23
  261. data/lib/cosmos/script/tools.rb +15 -69
  262. data/lib/cosmos/streams/serial_stream.rb +12 -19
  263. data/lib/cosmos/streams/stream.rb +2 -11
  264. data/lib/cosmos/streams/tcpip_socket_stream.rb +3 -13
  265. data/lib/cosmos/system/system.rb +187 -31
  266. data/lib/cosmos/system/target.rb +11 -2
  267. data/lib/cosmos/tools/cmd_extractor/cmd_extractor.rb +12 -11
  268. data/lib/cosmos/tools/cmd_sender/{cmd_sender_item_delegate.rb → cmd_param_table_item_delegate.rb} +11 -10
  269. data/lib/cosmos/tools/cmd_sender/cmd_sender.rb +209 -164
  270. data/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb +652 -0
  271. data/lib/cosmos/tools/cmd_sequence/sequence_item.rb +510 -0
  272. data/lib/cosmos/tools/cmd_sequence/sequence_list.rb +194 -0
  273. data/lib/cosmos/tools/cmd_tlm_server/api.rb +179 -5
  274. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +31 -14
  275. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_config.rb +23 -16
  276. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb +92 -20
  277. data/lib/cosmos/tools/cmd_tlm_server/commanding.rb +1 -1
  278. data/lib/cosmos/tools/cmd_tlm_server/gui/interfaces_tab.rb +17 -4
  279. data/lib/cosmos/tools/cmd_tlm_server/gui/targets_tab.rb +0 -5
  280. data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +1 -2
  281. data/lib/cosmos/tools/cmd_tlm_server/interfaces.rb +4 -4
  282. data/lib/cosmos/tools/cmd_tlm_server/limits_groups_background_task.rb +121 -0
  283. data/lib/cosmos/tools/cmd_tlm_server/routers.rb +8 -4
  284. data/lib/cosmos/tools/config_editor/config_editor.rb +720 -0
  285. data/lib/cosmos/tools/config_editor/config_editor_frame.rb +675 -0
  286. data/lib/cosmos/tools/data_viewer/data_viewer.rb +44 -27
  287. data/lib/cosmos/tools/data_viewer/data_viewer_component.rb +8 -22
  288. data/lib/cosmos/tools/launcher/launcher.rb +29 -12
  289. data/lib/cosmos/tools/launcher/launcher_config.rb +1 -1
  290. data/lib/cosmos/tools/limits_monitor/limits_monitor.rb +153 -42
  291. data/lib/cosmos/tools/packet_viewer/packet_viewer.rb +44 -6
  292. data/lib/cosmos/tools/replay/replay.rb +36 -20
  293. data/lib/cosmos/tools/replay/replay_server.rb +1 -1
  294. data/lib/cosmos/tools/script_runner/script_runner_config.rb +1 -1
  295. data/lib/cosmos/tools/script_runner/script_runner_frame.rb +31 -21
  296. data/lib/cosmos/tools/table_manager/table_config.rb +9 -3
  297. data/lib/cosmos/tools/table_manager/table_manager.rb +27 -7
  298. data/lib/cosmos/tools/test_runner/results_writer.rb +6 -6
  299. data/lib/cosmos/tools/test_runner/test_runner.rb +4 -6
  300. data/lib/cosmos/tools/tlm_extractor/tlm_extractor.rb +4 -5
  301. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_config.rb +1 -1
  302. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb +1 -1
  303. data/lib/cosmos/tools/tlm_grapher/data_object_adders/housekeeping_data_object_adder.rb +23 -6
  304. data/lib/cosmos/tools/tlm_grapher/data_object_editors/housekeeping_data_object_editor.rb +44 -3
  305. data/lib/cosmos/tools/tlm_grapher/data_objects/housekeeping_data_object.rb +20 -7
  306. data/lib/cosmos/tools/tlm_grapher/tabbed_plots/overview_tabbed_plots.rb +1 -1
  307. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_config.rb +11 -4
  308. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_plot_editor.rb +2 -2
  309. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_realtime_thread.rb +1 -1
  310. data/lib/cosmos/tools/tlm_grapher/tlm_grapher.rb +16 -0
  311. data/lib/cosmos/tools/tlm_viewer/screen.rb +36 -32
  312. data/lib/cosmos/tools/tlm_viewer/tlm_viewer.rb +59 -50
  313. data/lib/cosmos/tools/tlm_viewer/tlm_viewer_config.rb +2 -2
  314. data/lib/cosmos/tools/tlm_viewer/widgets.rb +1 -0
  315. data/lib/cosmos/tools/tlm_viewer/widgets/canvasvalue_widget.rb +1 -0
  316. data/lib/cosmos/tools/tlm_viewer/widgets/labelvalue_widget.rb +22 -4
  317. data/lib/cosmos/tools/tlm_viewer/widgets/matrixbycolumns_widget.rb +9 -0
  318. data/lib/cosmos/tools/tlm_viewer/widgets/spacer_widget.rb +55 -0
  319. data/lib/cosmos/tools/tlm_viewer/widgets/vertical_widget.rb +3 -2
  320. data/lib/cosmos/tools/tlm_viewer/widgets/verticalbox_widget.rb +3 -2
  321. data/lib/cosmos/tools/tlm_viewer/widgets/widget.rb +12 -12
  322. data/lib/cosmos/top_level.rb +34 -24
  323. data/lib/cosmos/utilities/crc.rb +108 -6
  324. data/lib/cosmos/utilities/csv.rb +68 -14
  325. data/lib/cosmos/utilities/logger.rb +2 -2
  326. data/lib/cosmos/utilities/low_fragmentation_array.rb +9 -1
  327. data/lib/cosmos/version.rb +6 -6
  328. data/lib/cosmos/win32/win32_main.rb +50 -46
  329. data/run_gui_tests.bat +3 -1
  330. data/spec/conversions/unix_time_formatted_conversion_spec.rb +2 -2
  331. data/spec/conversions/unix_time_seconds_conversion_spec.rb +2 -2
  332. data/spec/core_ext/file_spec.rb +1 -1
  333. data/spec/core_ext/objectspace_spec.rb +12 -9
  334. data/spec/core_ext/string_spec.rb +6 -0
  335. data/spec/core_ext/time_spec.rb +10 -0
  336. data/spec/gui/line_graph/line_clip_spec.rb +226 -224
  337. data/spec/gui/qt_spec.rb +81 -79
  338. data/spec/install/config/system/system.txt +0 -6
  339. data/spec/install/config/targets/INST/cmd_tlm/inst_cmd_linc.txt +5 -5
  340. data/spec/install/config/targets/INST/cmd_tlm/inst_tlm_linc.txt +8 -8
  341. data/spec/install/config/targets/SYSTEM/cmd_tlm/meta_cmd_tlm.txt +16 -0
  342. data/{install/config/targets/COSMOS/cmd_tlm/cosmos_server_cmds.txt → spec/install/config/targets/SYSTEM/cmd_tlm/system_cmds.txt} +8 -8
  343. data/spec/install/config/targets/SYSTEM/cmd_tlm/system_tlm.txt +7 -0
  344. data/spec/install/config/targets/{COSMOS → SYSTEM}/cmd_tlm_server.txt +2 -2
  345. data/spec/install/config/targets/SYSTEM/screens/status.txt +12 -0
  346. data/spec/install/config/targets/SYSTEM/target.txt +12 -0
  347. data/spec/interfaces/cmd_tlm_server_interface_spec.rb +9 -13
  348. data/spec/interfaces/interface_spec.rb +402 -18
  349. data/spec/interfaces/linc_interface_spec.rb +37 -39
  350. data/spec/interfaces/protocols/burst_protocol_spec.rb +300 -0
  351. data/spec/interfaces/protocols/crc_protocol_spec.rb +709 -0
  352. data/spec/interfaces/protocols/fixed_protocol_spec.rb +119 -0
  353. data/spec/interfaces/protocols/length_protocol_spec.rb +499 -0
  354. data/spec/interfaces/protocols/override_protocol_spec.rb +158 -0
  355. data/spec/interfaces/protocols/preidentified_protocol_spec.rb +149 -0
  356. data/spec/interfaces/protocols/template_protocol_spec.rb +218 -0
  357. data/spec/interfaces/protocols/terminated_protocol_spec.rb +174 -0
  358. data/spec/interfaces/serial_interface_spec.rb +35 -34
  359. data/spec/interfaces/simulated_target_interface_spec.rb +13 -13
  360. data/spec/interfaces/tcpip_client_interface_spec.rb +21 -16
  361. data/spec/interfaces/tcpip_server_interface_spec.rb +66 -69
  362. data/spec/interfaces/udp_interface_spec.rb +120 -55
  363. data/spec/io/serial_driver_spec.rb +41 -39
  364. data/spec/io/udp_sockets_spec.rb +13 -8
  365. data/spec/io/win32_serial_driver_spec.rb +62 -59
  366. data/spec/packet_logs/packet_log_reader_spec.rb +68 -47
  367. data/spec/packet_logs/packet_log_writer_spec.rb +7 -5
  368. data/spec/packets/commands_spec.rb +5 -5
  369. data/spec/packets/packet_spec.rb +2 -14
  370. data/spec/script/extract_spec.rb +21 -7
  371. data/spec/script/scripting_spec.rb +261 -6
  372. data/spec/script/telemetry_spec.rb +17 -9
  373. data/spec/spec_helper.rb +26 -10
  374. data/spec/streams/serial_stream_spec.rb +87 -82
  375. data/spec/streams/tcpip_client_stream_spec.rb +12 -4
  376. data/spec/streams/tcpip_socket_stream_spec.rb +5 -0
  377. data/spec/system/system_spec.rb +66 -50
  378. data/spec/system/target_spec.rb +33 -11
  379. data/spec/tools/cmd_tlm_server/api_spec.rb +5 -5
  380. data/spec/tools/cmd_tlm_server/background_tasks_spec.rb +75 -15
  381. data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +125 -5
  382. data/spec/tools/cmd_tlm_server/cmd_tlm_server_spec.rb +244 -232
  383. data/spec/tools/cmd_tlm_server/commanding_spec.rb +18 -18
  384. data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +124 -29
  385. data/spec/tools/cmd_tlm_server/interfaces_spec.rb +2 -2
  386. data/spec/tools/cmd_tlm_server/limits_groups_background_task_spec.rb +145 -0
  387. data/spec/tools/cmd_tlm_server/router_thread_spec.rb +50 -10
  388. data/spec/tools/table_manager/tablemanager_core_spec.rb +0 -1
  389. data/spec/top_level/top_level_spec.rb +39 -11
  390. data/spec/utilities/csv_spec.rb +62 -20
  391. data/tasks/gemfile_stats.rake +6 -3
  392. data/test/performance/config/system/system_packets.txt +0 -1
  393. data/test/performance/config/system/system_threads.txt +0 -1
  394. metadata +177 -92
  395. data/autohotkey/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +0 -15
  396. data/autohotkey/config/targets/COSMOS/cmd_tlm_server.txt +0 -6
  397. data/autohotkey/config/targets/COSMOS/target.txt +0 -5
  398. data/autohotkey/userpath.txt +0 -1
  399. data/demo/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +0 -15
  400. data/demo/config/targets/COSMOS/screens/limits_change.txt +0 -20
  401. data/demo/config/targets/COSMOS/screens/version.txt +0 -19
  402. data/demo/config/targets/COSMOS/target.txt +0 -11
  403. data/demo/config/targets/META/cmd_tlm/meta_cmd.txt +0 -10
  404. data/demo/config/targets/META/cmd_tlm/meta_tlm.txt +0 -13
  405. data/demo/userpath.txt +0 -1
  406. data/install/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +0 -15
  407. data/install/config/targets/COSMOS/cmd_tlm_server.txt +0 -6
  408. data/install/config/targets/COSMOS/screens/limits_change.txt +0 -20
  409. data/install/config/targets/COSMOS/screens/version.txt +0 -19
  410. data/install/config/targets/COSMOS/target.txt +0 -9
  411. data/install/config/targets/SYSTEM/README.txt +0 -1
  412. data/install/userpath.txt +0 -1
  413. data/lib/cosmos/io/tcpip_server.rb +0 -571
  414. data/lib/cosmos/packet_logs/meta_packet_log_writer.rb +0 -107
  415. data/lib/cosmos/streams/burst_stream_protocol.rb +0 -25
  416. data/lib/cosmos/streams/preidentified_stream_protocol.rb +0 -118
  417. data/lib/cosmos/streams/stream_protocol.rb +0 -373
  418. data/lib/cosmos/streams/template_stream_protocol.rb +0 -140
  419. data/lib/cosmos/streams/terminated_stream_protocol.rb +0 -85
  420. data/spec/install/config/targets/COSMOS/cmd_tlm/cosmos_server_cmds.txt +0 -41
  421. data/spec/install/config/targets/COSMOS/cmd_tlm/cosmos_server_tlm.txt +0 -15
  422. data/spec/install/config/targets/COSMOS/screens/limits_change.txt +0 -20
  423. data/spec/install/config/targets/COSMOS/screens/version.txt +0 -19
  424. data/spec/install/config/targets/COSMOS/target.txt +0 -5
  425. data/spec/install/config/targets/META/cmd_tlm/meta_cmd.txt +0 -4
  426. data/spec/install/config/targets/META/cmd_tlm/meta_tlm.txt +0 -4
  427. data/spec/install/userpath.txt +0 -1
  428. data/spec/interfaces/stream_interface_spec.rb +0 -157
  429. data/spec/io/tcpip_server_spec.rb +0 -338
  430. data/spec/packet_logs/meta_packet_log_writer_spec.rb +0 -170
  431. data/spec/streams/burst_stream_protocol_spec.rb +0 -32
  432. data/spec/streams/fixed_stream_protocol_spec.rb +0 -113
  433. data/spec/streams/length_stream_protocol_spec.rb +0 -300
  434. data/spec/streams/preidentified_stream_protocol_spec.rb +0 -121
  435. data/spec/streams/stream_protocol_spec.rb +0 -346
  436. data/spec/streams/template_stream_protocol_spec.rb +0 -156
  437. data/spec/streams/terminated_stream_protocol_spec.rb +0 -127
  438. data/test/performance/userpath.txt +0 -1
@@ -0,0 +1,510 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2014 Ball Aerospace & Technologies Corp.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+
11
+ require 'time'
12
+ require 'cosmos'
13
+ Cosmos.catch_fatal_exception do
14
+ require 'cosmos/script'
15
+ require 'cosmos/gui/dialogs/calendar_dialog'
16
+ require 'cosmos/gui/dialogs/cmd_details_dialog'
17
+ require 'cosmos/tools/cmd_sender/cmd_param_table_item_delegate'
18
+ end
19
+
20
+ module Cosmos
21
+ # Widget that represents an individual command that is sent as part of a
22
+ # sequence. Items can have absolute execution times or a relative delay from
23
+ # the previous item.
24
+ class SequenceItem < Qt::Frame # Inherit from Frame so we can use setFrameStyle
25
+ # Emit the modified signal to allow changes to propagate upwards
26
+ signals 'modified()'
27
+ MANUALLY = "MANUALLY ENTERED"
28
+
29
+ # Parse a time and command string into a SequenceItem which is returned
30
+ # @param time [String] Time (absolute or relative delay). Supports a single
31
+ # float value (relative delay) or a absolute time specified as
32
+ # "YYYY/MM/DD HH:MM:SS.MS"
33
+ # @param command [String] Command String which should not be
34
+ # quoted and is everything inside the quotes of a command.
35
+ # For example: TGT PKT with STRING 'HI', VALUE 12. Parse errors are
36
+ # raised as execptions which must be handled by higher level code.
37
+ # @return [SequenceItem] SequenceItem which the line represents
38
+ def self.parse(time, command)
39
+ tgt_name, pkt_name, cmd_params = extract_fields_from_cmd_text(command)
40
+ packet = System.commands.packet(tgt_name, pkt_name).dup
41
+ packet.restore_defaults
42
+ cmd_params.each do |param_name, param_value|
43
+ packet.write(param_name, param_value)
44
+ end
45
+ SequenceItem.new(packet, time)
46
+ end
47
+
48
+ # Create a new SequenceItem based on the given command with the given delay
49
+ # @param command [Packet] Command packet
50
+ # @param time [String] Absolute time in YYYY/MM/DD HH:MM:SS format or a
51
+ # single float value representing the delta delay time
52
+ def initialize(command, time = nil)
53
+ super()
54
+ @command = command
55
+ @table = nil
56
+ @param_widgets = []
57
+ @show_ignored = false
58
+ @states_in_hex = false
59
+ @expanded = false
60
+ @file_dir = System.paths['LOGS']
61
+
62
+ setAutoFillBackground(true)
63
+ setPalette(Cosmos.getPalette("black", "white"))
64
+ setFrameStyle(Qt::Frame::Box)
65
+
66
+ top_layout = Qt::VBoxLayout.new
67
+ top_layout.setContentsMargins(2, 0, 0, 0)
68
+ setLayout(top_layout)
69
+ top_layout.addLayout(create_cmd_layout(command, time))
70
+ top_layout.addWidget(create_parameters())
71
+ update_cmd_params()
72
+ set_cmd_name_info()
73
+ end
74
+
75
+ # Set or clear read only status on the item
76
+ # @param bool [Boolean] Whether to make the item read only
77
+ def read_only(bool)
78
+ @time.setReadOnly(bool)
79
+ end
80
+
81
+ # Show or hide ignored parameters
82
+ # @param bool [Boolean] Whether to show ignored command items
83
+ def show_ignored(bool)
84
+ @show_ignored = bool
85
+ update_cmd_params(bool)
86
+ end
87
+
88
+ # Display state values in hex (or decimal)
89
+ # @param bool [Boolean] Whether to display state values in hex
90
+ def states_in_hex(bool)
91
+ @states_in_hex = bool
92
+ @param_widgets.each do |_, _, state_value_item|
93
+ next unless state_value_item
94
+ text = state_value_item.text
95
+ quotes_removed = text.remove_quotes
96
+ if text == quotes_removed
97
+ if bool
98
+ if text.is_int?
99
+ @table.blockSignals(true)
100
+ state_value_item.text = sprintf("0x%X", text.to_i)
101
+ @table.blockSignals(false)
102
+ end
103
+ else
104
+ if text.is_hex?
105
+ @table.blockSignals(true)
106
+ state_value_item.text = Integer(text).to_s
107
+ @table.blockSignals(false)
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ # Show the command parameters part of the GUI
116
+ def expand
117
+ @expanded = true
118
+ @parameters.show
119
+ end
120
+
121
+ # Hide the command parameters part of the GUI
122
+ def collapse
123
+ @expanded = false
124
+ @parameters.hide
125
+ end
126
+
127
+ # @return [Hash] All the parameter item values keyed by their name
128
+ def command_params
129
+ params = {}
130
+ @param_widgets.each do |packet_item, value_item, state_value_item|
131
+ text = ''
132
+ Qt.execute_in_main_thread do
133
+ text = value_item.text
134
+ text = state_value_item.text if state_value_item && (text == MANUALLY)
135
+ end
136
+ quotes_removed = text.remove_quotes
137
+ if text == quotes_removed
138
+ if (packet_item.data_type == :STRING or packet_item.data_type == :BLOCK) and text.upcase.start_with?("0X")
139
+ params[packet_item.name] = text.hex_to_byte_string
140
+ else
141
+ params[packet_item.name] = text.convert_to_value
142
+ end
143
+ else
144
+ params[packet_item.name] = quotes_removed
145
+ end
146
+ raise "#{packet_item.name} is required" if quotes_removed == '' && packet_item.required
147
+ end
148
+ params
149
+ end
150
+
151
+ # @return [String] Command to be executed with no quotes or other decorations
152
+ def command_string
153
+ output_string = System.commands.build_cmd_output_string(@command.target_name, @command.packet_name, command_params(), false)
154
+ if output_string =~ /[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F-\xFF]/
155
+ output_string = output_string.inspect.remove_quotes
156
+ end
157
+ output_string[5..-3]
158
+ end
159
+
160
+ # @return [String] Absolute or relative time
161
+ def time
162
+ time = ''
163
+ Qt.execute_in_main_thread { time = @time.text }
164
+ time
165
+ end
166
+
167
+ # @return [String] Time and command string
168
+ def save
169
+ "COMMAND \"#{time}\" \"#{command_string}\""
170
+ end
171
+
172
+ # Handles showing and hiding the command parameters. Must be part of the
173
+ # public API.
174
+ def mouseReleaseEvent(event)
175
+ super(event)
176
+ if event.button == Qt::LeftButton
177
+ @expanded = !@expanded
178
+ if @expanded
179
+ @parameters.show
180
+ else
181
+ @parameters.hide
182
+ end
183
+ end
184
+ end
185
+
186
+ protected
187
+
188
+ # Create the command layout which holds the command name, information,
189
+ # and the delete button to remove the sequence item.
190
+ # @param command [Packet] Command packet
191
+ # @param time [String] Execution delay in absolute or relative time
192
+ def create_cmd_layout(command, time)
193
+ cmd_layout = Qt::HBoxLayout.new
194
+ cmd_layout.setContentsMargins(0, 0, 0, 0)
195
+ cmd_layout.addWidget(create_time_edit(time))
196
+
197
+ @cmd_name = Qt::Label.new("#{command.target_name} #{command.packet_name}")
198
+ cmd_layout.addWidget(@cmd_name)
199
+ @cmd_info = Qt::Label.new("") # Label for the hazardous designation
200
+ cmd_layout.addWidget(@cmd_info)
201
+ cmd_layout.addStretch()
202
+
203
+ delete = Qt::PushButton.new
204
+ delete.setFixedSize(25, 25)
205
+ delete_icon = Cosmos.get_icon('delete.png')
206
+ delete.setIcon(delete_icon)
207
+ delete.connect(SIGNAL('clicked()')) do
208
+ emit modified() # Tell the higher level that we're gone
209
+ self.dispose
210
+ end
211
+ cmd_layout.addWidget(delete)
212
+ cmd_layout
213
+ end
214
+
215
+ # Creates the time edit widget which holds the time delay. The widget is
216
+ # a normal LineEdit which is edited as usual to enter a relative delay.
217
+ # If the widget is right clicked it launches a CalendarDialog to allow the
218
+ # user to select and absolute time to execute the sequence item.
219
+ # @param time [String] The initial value for the time delay
220
+ def create_time_edit(time)
221
+ @time = Qt::LineEdit.new(Time.now.sys.formatted)
222
+ fm = @time.fontMetrics
223
+ # Set the width to support an absolute time
224
+ @time.setFixedWidth(fm.boundingRect(Time.now.sys.formatted).width + 10)
225
+ @time.text = time ? time : "0.00"
226
+ # Setting the absolute time is via a Right-Click custom context menu
227
+ @time.setContextMenuPolicy(Qt::CustomContextMenu)
228
+ @time.connect(SIGNAL('customContextMenuRequested(const QPoint&)')) do
229
+ dialog = CalendarDialog.new(@time, "Select Absolute Execution Time:", Time.now.sys, true)
230
+ case dialog.exec
231
+ when Qt::Dialog::Accepted
232
+ @time.text = dialog.time.formatted
233
+ end
234
+ end
235
+ @time.connect(SIGNAL('textChanged(const QString&)')) { emit modified }
236
+ @time
237
+ end
238
+
239
+ # Create the parameters widget which holds the command description and
240
+ # the table which contains all the command parameters
241
+ def create_parameters
242
+ @parameters = Qt::Widget.new
243
+ parameters_layout = Qt::VBoxLayout.new
244
+ # Command Description Label
245
+ dec_label = Qt::Label.new(tr("Description:"))
246
+ description = Qt::Label.new(@command.description)
247
+ description.setWordWrap(true)
248
+ desc_layout = Qt::HBoxLayout.new
249
+ desc_layout.addWidget(dec_label)
250
+ desc_layout.addWidget(description, 1)
251
+ parameters_layout.addLayout(desc_layout)
252
+
253
+ param_label = Qt::Label.new(tr("Parameters:"))
254
+ parameters_layout.addWidget(param_label)
255
+ @table_layout = Qt::VBoxLayout.new
256
+ parameters_layout.addLayout(@table_layout, 500)
257
+ @parameters.setLayout(parameters_layout)
258
+ @parameters.hide
259
+ @parameters
260
+ end
261
+
262
+ # Update the command parameters table for the given command
263
+ # @param ignored_toggle [Boolean] Whether to display the ignored
264
+ # parameters. Pass nil (the default) to keep the existing setting.
265
+ def update_cmd_params(ignored_toggle = nil)
266
+ old_params = {}
267
+ if !ignored_toggle.nil?
268
+ # Save parameter values
269
+ @param_widgets.each do |packet_item, value_item, state_value_item|
270
+ text = value_item.text
271
+ if state_value_item
272
+ old_params[packet_item.name] = [text, state_value_item.text]
273
+ else
274
+ old_params[packet_item.name] = text
275
+ end
276
+ end
277
+ end
278
+
279
+ target = System.targets[@command.target_name]
280
+ packet_items = @command.sorted_items
281
+ shown_packet_items = []
282
+ packet_items.each do |packet_item|
283
+ if target && target.ignored_parameters.include?(packet_item.name) && !@show_ignored
284
+ if @param_widgets.empty? # First time rendering the parameters
285
+ if packet_item.states
286
+ # Skip this if the default matches the saved value
287
+ next if @command.read_item(packet_item, :RAW) == packet_item.default
288
+ else
289
+ # Skip this if the default matches the saved value
290
+ next if @command.read_item(packet_item) == packet_item.default
291
+ end
292
+ else # Check the current values
293
+ result = @param_widgets.select {|item,_,_| item == packet_item }
294
+ next if result.empty?
295
+ _, value_item, state_value_item = result[0]
296
+ value = state_value_item ? state_value_item.text : value_item.text
297
+ # Skip this if the default matches the current value
298
+ next if packet_item.default.to_s == value
299
+ end
300
+ end
301
+ shown_packet_items << packet_item
302
+ end
303
+
304
+ @table.dispose if @table
305
+ @table = nil
306
+
307
+ # Update Parameters
308
+ @param_widgets = []
309
+ drawn_header = false
310
+
311
+ row = 0
312
+ shown_packet_items.each do |packet_item|
313
+ value_item = nil
314
+ state_value_item = nil
315
+
316
+ unless drawn_header
317
+ @table = Qt::TableWidget.new()
318
+ @table.setSizePolicy(Qt::SizePolicy::Expanding, Qt::SizePolicy::Expanding)
319
+ @table.setWordWrap(true)
320
+ @table.setRowCount(shown_packet_items.length)
321
+ @table.setColumnCount(5)
322
+ @table.setHorizontalHeaderLabels(['Name', ' Value or State ', ' ', 'Units', 'Description'])
323
+ @table.verticalHeader.setVisible(false)
324
+ @table.setItemDelegate(CmdParamTableItemDelegate.new(@table, @param_widgets))
325
+ @table.setEditTriggers(Qt::AbstractItemView::DoubleClicked | Qt::AbstractItemView::SelectedClicked | Qt::AbstractItemView::AnyKeyPressed)
326
+ @table.setSelectionMode(Qt::AbstractItemView::NoSelection)
327
+ @table.setContextMenuPolicy(Qt::CustomContextMenu)
328
+ @table.connect(SIGNAL('customContextMenuRequested(const QPoint&)')) do |point|
329
+ context_menu(point)
330
+ end
331
+ drawn_header = true
332
+ end
333
+
334
+ # Parameter Name
335
+ item = Qt::TableWidgetItem.new("#{packet_item.name}:")
336
+ item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
337
+ item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
338
+ @table.setItem(row, 0, item)
339
+
340
+ if packet_item.states
341
+ default = @command.read_item(packet_item, :RAW)
342
+ default_state = packet_item.states.key(default)
343
+ if old_params[packet_item.name]
344
+ value_item = Qt::TableWidgetItem.new(old_params[packet_item.name][0])
345
+ else
346
+ if default_state
347
+ value_item = Qt::TableWidgetItem.new(default_state.to_s)
348
+ else
349
+ value_item = Qt::TableWidgetItem.new(MANUALLY)
350
+ end
351
+ end
352
+ value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
353
+ value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
354
+ @table.setItem(row, 1, value_item)
355
+
356
+ if old_params[packet_item.name]
357
+ state_value_item = Qt::TableWidgetItem.new(old_params[packet_item.name][1])
358
+ else
359
+ if @states_in_hex && packet_item.default.kind_of?(Integer)
360
+ state_value_item = Qt::TableWidgetItem.new(sprintf("0x%X", default))
361
+ else
362
+ default_str = default.to_s
363
+ if default_str.is_printable?
364
+ state_value_item = Qt::TableWidgetItem.new(default_str)
365
+ else
366
+ state_value_item = Qt::TableWidgetItem.new("0x" + default_str.simple_formatted)
367
+ end
368
+ end
369
+ end
370
+ state_value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
371
+ state_value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
372
+ @table.setItem(row, 2, state_value_item)
373
+ else # Parameter Value
374
+ if old_params[packet_item.name]
375
+ value_item = Qt::TableWidgetItem.new(old_params[packet_item.name])
376
+ else
377
+ default = @command.read_item(packet_item)
378
+ if packet_item.format_string
379
+ begin
380
+ value_text = sprintf(packet_item.format_string, default)
381
+ rescue
382
+ # Oh well - Don't use the format string
383
+ value_text = default.to_s
384
+ end
385
+ else
386
+ value_text = default.to_s
387
+ end
388
+ if !value_text.is_printable?
389
+ value_text = "0x" + value_text.simple_formatted
390
+ end
391
+ value_item = Qt::TableWidgetItem.new(value_text)
392
+ end
393
+ value_item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
394
+ value_item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable)
395
+ @table.setItem(row, 1, value_item)
396
+ @table.setSpan(row, 1, 1, 2)
397
+ end
398
+
399
+ # Units
400
+ item = Qt::TableWidgetItem.new(packet_item.units.to_s)
401
+ item.setTextAlignment(Qt::AlignRight | Qt::AlignVCenter)
402
+ item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
403
+ @table.setItem(row, 3, item)
404
+
405
+ # Description
406
+ item = Qt::TableWidgetItem.new(packet_item.description.to_s)
407
+ item.setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter)
408
+ item.setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled)
409
+ @table.setItem(row, 4, item)
410
+
411
+ @param_widgets << [packet_item, value_item, state_value_item]
412
+ row += 1
413
+ end
414
+
415
+ if @table
416
+ connect_table_item_changed()
417
+ @table.setSizePolicy(Qt::SizePolicy.Minimum, Qt::SizePolicy.Minimum)
418
+ @table.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff)
419
+ @table.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff)
420
+ @table.resizeColumnsToContents()
421
+ @table.resizeRowsToContents()
422
+ @table.setFixedSize(@table.horizontalHeader.length + @table.verticalHeader.width,
423
+ 2 + @table.verticalHeader.length + @table.horizontalHeader.height)
424
+ @table_layout.addWidget(@table)
425
+ end
426
+ end
427
+
428
+ # Sets the @cmd_name label to the command that will be sent. Also udpates
429
+ # the @cmd_info with whether this command is hazardous or not.
430
+ def set_cmd_name_info
431
+ @cmd_name.text = command_string
432
+ hazardous, _ = System.commands.cmd_hazardous?(@command.target_name, @command.packet_name, command_params())
433
+ if hazardous
434
+ @cmd_info.text = "(Hazarous)"
435
+ else
436
+ @cmd_info.text = ""
437
+ end
438
+ rescue => error
439
+ @cmd_info.text = "(Error)"
440
+ Qt::MessageBox.warning(self, 'Error', error.message)
441
+ end
442
+
443
+ # If the user right clicks over a table item, this method displays a context
444
+ # menu with various options.
445
+ # @param point [Qt::Point] Point to display the context menu
446
+ def context_menu(point)
447
+ target_name = @command.target_name
448
+ packet_name = @command.packet_name
449
+ item = @table.itemAt(point)
450
+ if item
451
+ item_name = @table.item(item.row, 0).text[0..-2] # Remove :
452
+ if target_name.length > 0 && packet_name.length > 0 && item_name.length > 0
453
+ menu = Qt::Menu.new()
454
+
455
+ details_action = Qt::Action.new(tr("Details #{target_name} #{packet_name} #{item_name}"), self)
456
+ details_action.statusTip = tr("Popup details about #{target_name} #{packet_name} #{item_name}")
457
+ details_action.connect(SIGNAL('triggered()')) do
458
+ CmdDetailsDialog.new(nil, target_name, packet_name, item_name)
459
+ end
460
+ menu.addAction(details_action)
461
+
462
+ file_chooser_action = Qt::Action.new(tr("Insert Filename"), self)
463
+ file_chooser_action.statusTip = tr("Select a file and place its name into this parameter")
464
+ file_chooser_action.connect(SIGNAL('triggered()')) do
465
+ filename = Qt::FileDialog::getOpenFileName(self, "Insert Filename:", @file_dir, "All Files (*)")
466
+ if filename && !filename.empty?
467
+ @file_dir = File.dirname(filename)
468
+ _, value_item, state_value_item = @param_widgets[item.row]
469
+ if state_value_item
470
+ state_value_item.setText(filename)
471
+ elsif value_item
472
+ value_item.setText(filename)
473
+ end
474
+ end
475
+ end
476
+ menu.addAction(file_chooser_action)
477
+
478
+ menu.exec(@table.mapToGlobal(point))
479
+ menu.dispose
480
+ end
481
+ end # if item
482
+ end
483
+
484
+ # Connect the itemChanged signal to the table so we can handle user edits
485
+ # of the table parameters. This method emits the modified signal.
486
+ def connect_table_item_changed
487
+ @table.connect(SIGNAL('itemChanged(QTableWidgetItem*)')) do |item|
488
+ packet_item, value_item, state_value_item = @param_widgets[item.row]
489
+ if item.column == 1
490
+ if packet_item.states
491
+ value = packet_item.states[value_item.text]
492
+ @table.blockSignals(true)
493
+ if @states_in_hex && value.kind_of?(Integer)
494
+ state_value_item.setText(sprintf("0x%X", value))
495
+ else
496
+ state_value_item.setText(value.to_s)
497
+ end
498
+ @table.blockSignals(false)
499
+ end
500
+ elsif item.column == 2
501
+ @table.blockSignals(true)
502
+ @table.item(item.row, 1).setText(MANUALLY)
503
+ @table.blockSignals(false)
504
+ end
505
+ set_cmd_name_info()
506
+ emit modified # Tell the higher level that something changed
507
+ end
508
+ end
509
+ end
510
+ end