cosmos 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (336) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.travis.yml +2 -0
  4. data/.yardopts +1 -0
  5. data/Gemfile +1 -0
  6. data/Manifest.txt +130 -0
  7. data/autohotkey/tools/ConfigEditorAHK +19 -0
  8. data/autohotkey/tools/cmd_extractor.ahk +4 -4
  9. data/autohotkey/tools/cmd_sequence.ahk +9 -5
  10. data/autohotkey/tools/config_editor.ahk +197 -0
  11. data/autohotkey/tools/packet_viewer.ahk +12 -6
  12. data/autohotkey/tools/replay.ahk +29 -29
  13. data/autohotkey/tools/script_runner.ahk +10 -2
  14. data/autohotkey/tools/tlm_extractor.ahk +7 -8
  15. data/autohotkey/tools/tlm_grapher.ahk +21 -9
  16. data/bin/dart_import +2 -0
  17. data/cosmos.gemspec +18 -16
  18. data/data/config/cmd_tlm_server.yaml +9 -0
  19. data/data/config/interface_modifiers.yaml +17 -0
  20. data/data/config/item_modifiers.yaml +3 -3
  21. data/data/crc.txt +184 -90
  22. data/data/dart.png +0 -0
  23. data/demo/Gemfile +1 -0
  24. data/demo/Rakefile +4 -0
  25. data/demo/config/dart/Gemfile +54 -0
  26. data/demo/config/data/crc.txt +28 -21
  27. data/demo/config/system/system.txt +3 -0
  28. data/demo/config/system/system2.txt +3 -0
  29. data/demo/config/targets/INST/cmd_tlm/inst_cmds.txt +3 -3
  30. data/demo/config/targets/INST/cmd_tlm/inst_tlm.txt +1 -1
  31. data/demo/config/targets/INST/lib/sim_inst.rb +1 -1
  32. data/demo/config/targets/INST/screens/adcs.txt +2 -1
  33. data/demo/config/targets/INST/screens/array.txt +1 -1
  34. data/demo/config/targets/INST/screens/block.txt +1 -1
  35. data/demo/config/targets/INST/screens/commanding.txt +7 -2
  36. data/demo/config/targets/INST/screens/graphs.txt +1 -1
  37. data/demo/config/targets/INST/screens/ground.txt +1 -1
  38. data/demo/config/targets/INST/screens/hs.txt +2 -1
  39. data/demo/config/targets/INST/screens/latest.txt +1 -1
  40. data/demo/config/targets/INST/screens/limits.txt +1 -1
  41. data/demo/config/targets/INST/screens/other.txt +1 -1
  42. data/demo/config/targets/INST/screens/tabs.txt +1 -1
  43. data/demo/config/tools/cmd_tlm_server/cmd_tlm_server.txt +2 -2
  44. data/demo/config/tools/cmd_tlm_server/cmd_tlm_server2.txt +3 -1
  45. data/demo/config/tools/launcher/launcher.txt +3 -2
  46. data/demo/tools/Dart +16 -0
  47. data/demo/tools/Dart.bat +9 -0
  48. data/demo/tools/mac/CmdSequence.app/Contents/MacOS/main.sh +0 -0
  49. data/demo/tools/mac/ConfigEditor.app/Contents/MacOS/main.sh +0 -0
  50. data/install/Gemfile +1 -0
  51. data/install/Rakefile +4 -0
  52. data/install/config/dart/Gemfile +54 -0
  53. data/install/config/data/crc.txt +6 -3
  54. data/install/config/system/system.txt +3 -0
  55. data/install/config/tools/launcher/launcher.txt +3 -2
  56. data/install/tools/Dart +16 -0
  57. data/install/tools/Dart.bat +9 -0
  58. data/install/tools/mac/CmdSequence.app/Contents/MacOS/main.sh +0 -0
  59. data/install/tools/mac/ConfigEditor.app/Contents/MacOS/main.sh +0 -0
  60. data/lib/cosmos/core_ext/time.rb +8 -8
  61. data/lib/cosmos/dart/.rspec +1 -0
  62. data/lib/cosmos/dart/Gemfile +69 -0
  63. data/lib/cosmos/dart/Rakefile +7 -0
  64. data/lib/cosmos/dart/app/assets/config/manifest.js +4 -0
  65. data/lib/cosmos/dart/app/assets/images/.keep +0 -0
  66. data/lib/cosmos/dart/app/assets/javascripts/application.js +13 -0
  67. data/lib/cosmos/dart/app/assets/javascripts/cable.js +13 -0
  68. data/lib/cosmos/dart/app/assets/stylesheets/application.css.scss +15 -0
  69. data/lib/cosmos/dart/app/channels/application_cable/channel.rb +4 -0
  70. data/lib/cosmos/dart/app/channels/application_cable/connection.rb +4 -0
  71. data/lib/cosmos/dart/app/controllers/application_controller.rb +3 -0
  72. data/lib/cosmos/dart/app/helpers/application_helper.rb +2 -0
  73. data/lib/cosmos/dart/app/jobs/application_job.rb +2 -0
  74. data/lib/cosmos/dart/app/mailers/application_mailer.rb +4 -0
  75. data/lib/cosmos/dart/app/models/application_record.rb +3 -0
  76. data/lib/cosmos/dart/app/models/item.rb +6 -0
  77. data/lib/cosmos/dart/app/models/item_to_decom_table_mapping.rb +9 -0
  78. data/lib/cosmos/dart/app/models/packet.rb +4 -0
  79. data/lib/cosmos/dart/app/models/packet_config.rb +7 -0
  80. data/lib/cosmos/dart/app/models/packet_log.rb +3 -0
  81. data/lib/cosmos/dart/app/models/packet_log_entry.rb +41 -0
  82. data/lib/cosmos/dart/app/models/system_config.rb +2 -0
  83. data/lib/cosmos/dart/app/models/target.rb +4 -0
  84. data/lib/cosmos/dart/app/views/layouts/application.html.erb +14 -0
  85. data/lib/cosmos/dart/app/views/layouts/mailer.html.erb +13 -0
  86. data/lib/cosmos/dart/app/views/layouts/mailer.text.erb +1 -0
  87. data/lib/cosmos/dart/bin/bundle +3 -0
  88. data/lib/cosmos/dart/bin/rails +4 -0
  89. data/lib/cosmos/dart/bin/rake +4 -0
  90. data/lib/cosmos/dart/bin/setup +34 -0
  91. data/lib/cosmos/dart/bin/update +29 -0
  92. data/lib/cosmos/dart/config.ru +5 -0
  93. data/lib/cosmos/dart/config/application.rb +29 -0
  94. data/lib/cosmos/dart/config/boot.rb +3 -0
  95. data/lib/cosmos/dart/config/cable.yml +9 -0
  96. data/lib/cosmos/dart/config/database.yml +23 -0
  97. data/lib/cosmos/dart/config/environment.rb +5 -0
  98. data/lib/cosmos/dart/config/environments/development.rb +62 -0
  99. data/lib/cosmos/dart/config/environments/production.rb +84 -0
  100. data/lib/cosmos/dart/config/environments/test.rb +42 -0
  101. data/lib/cosmos/dart/config/initializers/application_controller_renderer.rb +6 -0
  102. data/lib/cosmos/dart/config/initializers/assets.rb +12 -0
  103. data/lib/cosmos/dart/config/initializers/backtrace_silencers.rb +7 -0
  104. data/lib/cosmos/dart/config/initializers/cookies_serializer.rb +5 -0
  105. data/lib/cosmos/dart/config/initializers/filter_parameter_logging.rb +4 -0
  106. data/lib/cosmos/dart/config/initializers/inflections.rb +16 -0
  107. data/lib/cosmos/dart/config/initializers/mime_types.rb +4 -0
  108. data/lib/cosmos/dart/config/initializers/new_framework_defaults.rb +25 -0
  109. data/lib/cosmos/dart/config/initializers/session_store.rb +3 -0
  110. data/lib/cosmos/dart/config/initializers/wrap_parameters.rb +14 -0
  111. data/lib/cosmos/dart/config/locales/en.yml +23 -0
  112. data/lib/cosmos/dart/config/puma.rb +47 -0
  113. data/lib/cosmos/dart/config/routes.rb +3 -0
  114. data/lib/cosmos/dart/config/secrets.yml +22 -0
  115. data/lib/cosmos/dart/db/migrate/20170406172907_create_targets.rb +8 -0
  116. data/lib/cosmos/dart/db/migrate/20170406172927_create_packets.rb +10 -0
  117. data/lib/cosmos/dart/db/migrate/20170406172937_create_packet_logs.rb +9 -0
  118. data/lib/cosmos/dart/db/migrate/20170406172943_create_packet_log_entries.rb +16 -0
  119. data/lib/cosmos/dart/db/migrate/20170406183500_change_packet_log_entries_primary_key.rb +5 -0
  120. data/lib/cosmos/dart/db/migrate/20170407153618_add_unique_requirements.rb +7 -0
  121. data/lib/cosmos/dart/db/migrate/20170511155447_add_meta_id_to_packet_log_entries.rb +6 -0
  122. data/lib/cosmos/dart/db/migrate/20170523185056_rename_received_time_and_add_is_tlm_to_packet_log_entries.rb +7 -0
  123. data/lib/cosmos/dart/db/migrate/20170525201157_create_items.rb +10 -0
  124. data/lib/cosmos/dart/db/migrate/20170525201315_create_system_configs.rb +9 -0
  125. data/lib/cosmos/dart/db/migrate/20170525201624_create_packet_configs.rb +11 -0
  126. data/lib/cosmos/dart/db/migrate/20170525201745_create_item_to_decom_table_mappings.rb +12 -0
  127. data/lib/cosmos/dart/db/migrate/20170525201939_create_decom_tables.rb +12 -0
  128. data/lib/cosmos/dart/db/migrate/20170525202051_add_decom_state_to_packet_log_entry.rb +5 -0
  129. data/lib/cosmos/dart/db/migrate/20170913160409_update_items.rb +6 -0
  130. data/lib/cosmos/dart/db/migrate/20170913160558_update_item_to_decom_table_mapping.rb +11 -0
  131. data/lib/cosmos/dart/db/migrate/20170913160916_udpate_decom_table.rb +6 -0
  132. data/lib/cosmos/dart/db/migrate/20170913212026_add_ready_to_packet_configs.rb +5 -0
  133. data/lib/cosmos/dart/db/migrate/20170913223556_modify_tables.rb +9 -0
  134. data/lib/cosmos/dart/db/migrate/20170914215744_modify_mapping_table.rb +6 -0
  135. data/lib/cosmos/dart/db/migrate/20170919201433_add_system_config_id_to_packet_config.rb +11 -0
  136. data/lib/cosmos/dart/db/migrate/20170919210307_add_max_table_index_to_packet_configs.rb +5 -0
  137. data/lib/cosmos/dart/db/migrate/20171215225546_add_ready_to_packet_log_entries.rb +5 -0
  138. data/lib/cosmos/dart/db/migrate/20180116214338_add_index_for_ple_ready_to_packet_log_entries.rb +5 -0
  139. data/lib/cosmos/dart/db/schema.rb +103 -0
  140. data/lib/cosmos/dart/db/seeds.rb +7 -0
  141. data/lib/cosmos/dart/examples/dart_decom_client.rb +45 -0
  142. data/lib/cosmos/dart/examples/dart_stream_client.rb +93 -0
  143. data/lib/cosmos/dart/lib/dart_common.rb +749 -0
  144. data/lib/cosmos/dart/lib/dart_database_cleaner.rb +172 -0
  145. data/lib/cosmos/dart/lib/dart_decom_query.rb +184 -0
  146. data/lib/cosmos/dart/lib/dart_decommutator.rb +235 -0
  147. data/lib/cosmos/dart/lib/dart_importer.rb +154 -0
  148. data/lib/cosmos/dart/lib/dart_logging.rb +50 -0
  149. data/lib/cosmos/dart/lib/dart_packet_log_writer.rb +139 -0
  150. data/lib/cosmos/dart/lib/dart_reducer_manager.rb +85 -0
  151. data/lib/cosmos/dart/lib/dart_reducer_worker_thread.rb +263 -0
  152. data/lib/cosmos/dart/lib/dart_tcpip_server_interface.rb +142 -0
  153. data/lib/cosmos/dart/processes/dart.rb +145 -0
  154. data/lib/cosmos/dart/processes/dart_decom_server.rb +39 -0
  155. data/lib/cosmos/dart/processes/dart_import.rb +63 -0
  156. data/lib/cosmos/dart/processes/dart_ingester.rb +92 -0
  157. data/lib/cosmos/dart/processes/dart_reducer.rb +27 -0
  158. data/lib/cosmos/dart/processes/dart_stream_server.rb +31 -0
  159. data/lib/cosmos/dart/processes/dart_worker.rb +37 -0
  160. data/lib/cosmos/dart/spec/dart/dart_common_spec.rb +333 -0
  161. data/lib/cosmos/dart/spec/dart/dart_database_cleaner_spec.rb +455 -0
  162. data/lib/cosmos/dart/spec/dart/dart_decom_query_spec.rb +153 -0
  163. data/lib/cosmos/dart/spec/dart/dart_decommutator_spec.rb +336 -0
  164. data/lib/cosmos/dart/spec/dart/dart_importer_spec.rb +83 -0
  165. data/lib/cosmos/dart/spec/dart/dart_logging_spec.rb +30 -0
  166. data/lib/cosmos/dart/spec/dart/dart_packet_log_writer_spec.rb +149 -0
  167. data/lib/cosmos/dart/spec/dart/dart_reducer_manager_spec.rb +289 -0
  168. data/lib/cosmos/dart/spec/dart/dart_tcpip_server_interface_spec.rb +241 -0
  169. data/lib/cosmos/dart/spec/rails_helper.rb +60 -0
  170. data/lib/cosmos/dart/spec/spec_helper.rb +139 -0
  171. data/lib/cosmos/gui/dialogs/about_dialog.rb +1 -1
  172. data/lib/cosmos/gui/dialogs/dart_dialog.rb +60 -0
  173. data/lib/cosmos/gui/dialogs/legal_dialog.rb +1 -0
  174. data/lib/cosmos/gui/dialogs/scroll_text_dialog.rb +0 -3
  175. data/lib/cosmos/gui/qt.rb +10 -1
  176. data/lib/cosmos/gui/text/completion.rb +10 -9
  177. data/lib/cosmos/gui/text/completion_text_edit.rb +16 -14
  178. data/lib/cosmos/gui/text/ruby_editor.rb +2 -2
  179. data/lib/cosmos/gui/widgets/dart_frame.rb +142 -0
  180. data/lib/cosmos/gui/widgets/dart_meta_frame.rb +119 -0
  181. data/lib/cosmos/gui/widgets/packet_log_frame.rb +42 -12
  182. data/lib/cosmos/interfaces/interface.rb +1 -2
  183. data/lib/cosmos/interfaces/protocols/crc_protocol.rb +26 -8
  184. data/lib/cosmos/interfaces/protocols/fixed_protocol.rb +8 -2
  185. data/lib/cosmos/interfaces/protocols/protocol.rb +2 -1
  186. data/lib/cosmos/interfaces/protocols/template_protocol.rb +1 -1
  187. data/lib/cosmos/interfaces/stream_interface.rb +1 -0
  188. data/lib/cosmos/interfaces/tcpip_server_interface.rb +2 -3
  189. data/lib/cosmos/io/json_drb_object.rb +1 -1
  190. data/lib/cosmos/io/json_rpc.rb +2 -1
  191. data/lib/cosmos/io/win32_serial_driver.rb +2 -9
  192. data/lib/cosmos/packet_logs/packet_log_writer.rb +1 -1
  193. data/lib/cosmos/packets/packet.rb +22 -12
  194. data/lib/cosmos/packets/packet_config.rb +2 -1
  195. data/lib/cosmos/packets/packet_item.rb +26 -24
  196. data/lib/cosmos/packets/parsers/macro_parser.rb +5 -2
  197. data/lib/cosmos/packets/parsers/packet_item_parser.rb +35 -17
  198. data/lib/cosmos/packets/parsers/packet_parser.rb +3 -10
  199. data/lib/cosmos/packets/parsers/xtce_converter.rb +21 -35
  200. data/lib/cosmos/packets/parsers/xtce_parser.rb +54 -46
  201. data/lib/cosmos/packets/structure.rb +10 -2
  202. data/lib/cosmos/packets/structure_item.rb +22 -8
  203. data/lib/cosmos/processors/statistics_processor.rb +2 -0
  204. data/lib/cosmos/script/api_shared.rb +13 -12
  205. data/lib/cosmos/script/cmd_tlm_server.rb +4 -0
  206. data/lib/cosmos/script/commands.rb +3 -15
  207. data/lib/cosmos/script/script.rb +69 -23
  208. data/lib/cosmos/streams/tcpip_client_stream.rb +2 -2
  209. data/lib/cosmos/system/system.rb +42 -25
  210. data/lib/cosmos/system/target.rb +6 -2
  211. data/lib/cosmos/tools/cmd_extractor/cmd_extractor.rb +177 -36
  212. data/lib/cosmos/tools/cmd_sender/cmd_param_table_item_delegate.rb +3 -2
  213. data/lib/cosmos/tools/cmd_sender/cmd_sender.rb +34 -8
  214. data/lib/cosmos/tools/cmd_sequence/cmd_sequence.rb +80 -25
  215. data/lib/cosmos/tools/cmd_tlm_server/api.rb +19 -4
  216. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +15 -14
  217. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_gui.rb +15 -9
  218. data/lib/cosmos/tools/cmd_tlm_server/gui/interfaces_tab.rb +1 -9
  219. data/lib/cosmos/tools/cmd_tlm_server/gui/logging_tab.rb +1 -6
  220. data/lib/cosmos/tools/cmd_tlm_server/gui/packets_tab.rb +1 -3
  221. data/lib/cosmos/tools/cmd_tlm_server/gui/replay_tab.rb +84 -7
  222. data/lib/cosmos/tools/cmd_tlm_server/gui/status_tab.rb +0 -1
  223. data/lib/cosmos/tools/cmd_tlm_server/gui/targets_tab.rb +1 -5
  224. data/lib/cosmos/tools/cmd_tlm_server/limits_groups_background_task.rb +3 -2
  225. data/lib/cosmos/tools/cmd_tlm_server/replay_backend.rb +159 -27
  226. data/lib/cosmos/tools/cmd_tlm_server/routers.rb +1 -1
  227. data/lib/cosmos/tools/config_editor/config_editor.rb +17 -52
  228. data/lib/cosmos/tools/config_editor/config_editor_frame.rb +0 -5
  229. data/lib/cosmos/tools/data_viewer/data_viewer.rb +111 -0
  230. data/lib/cosmos/tools/limits_monitor/limits_monitor.rb +31 -18
  231. data/lib/cosmos/tools/packet_viewer/packet_viewer.rb +12 -3
  232. data/lib/cosmos/tools/script_runner/script_runner.rb +27 -14
  233. data/lib/cosmos/tools/script_runner/script_runner_frame.rb +104 -37
  234. data/lib/cosmos/tools/table_manager/table_config.rb +1 -1
  235. data/lib/cosmos/tools/table_manager/table_item_parser.rb +4 -2
  236. data/lib/cosmos/tools/table_manager/table_manager.rb +0 -5
  237. data/lib/cosmos/tools/table_manager/table_manager_core.rb +0 -1
  238. data/lib/cosmos/tools/test_runner/test.rb +1 -3
  239. data/lib/cosmos/tools/test_runner/test_runner.rb +26 -15
  240. data/lib/cosmos/tools/tlm_extractor/tlm_extractor.rb +290 -137
  241. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_config.rb +122 -25
  242. data/lib/cosmos/tools/tlm_extractor/tlm_extractor_processor.rb +67 -0
  243. data/lib/cosmos/tools/tlm_grapher/data_object_editors/housekeeping_data_object_editor.rb +28 -0
  244. data/lib/cosmos/tools/tlm_grapher/data_object_editors/xy_data_object_editor.rb +36 -0
  245. data/lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb +42 -3
  246. data/lib/cosmos/tools/tlm_grapher/data_objects/housekeeping_data_object.rb +88 -14
  247. data/lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb +2 -5
  248. data/lib/cosmos/tools/tlm_grapher/data_objects/singlexy_data_object.rb +2 -6
  249. data/lib/cosmos/tools/tlm_grapher/data_objects/xy_data_object.rb +74 -18
  250. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_config.rb +3 -7
  251. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_dart_thread.rb +159 -0
  252. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_tool.rb +49 -2
  253. data/lib/cosmos/tools/tlm_viewer/screen.rb +3 -0
  254. data/lib/cosmos/tools/tlm_viewer/tlm_viewer_config.rb +0 -2
  255. data/lib/cosmos/tools/tlm_viewer/widgets.rb +1 -0
  256. data/lib/cosmos/tools/tlm_viewer/widgets/backgroundbutton_widget.rb +54 -0
  257. data/lib/cosmos/tools/tlm_viewer/widgets/button_widget.rb +5 -5
  258. data/lib/cosmos/top_level.rb +1 -0
  259. data/lib/cosmos/utilities/crc.rb +3 -0
  260. data/lib/cosmos/utilities/csv.rb +1 -0
  261. data/lib/cosmos/utilities/message_log.rb +2 -1
  262. data/lib/cosmos/utilities/simulated_target.rb +8 -8
  263. data/lib/cosmos/version.rb +5 -5
  264. data/lib/cosmos/win32/win32.rb +4 -10
  265. data/run_gui_tests.bat +2 -1
  266. data/spec/config/config_parser_spec.rb +4 -4
  267. data/spec/core_ext/array_spec.rb +1 -1
  268. data/spec/core_ext/exception_spec.rb +12 -12
  269. data/spec/core_ext/file_spec.rb +6 -6
  270. data/spec/core_ext/hash_spec.rb +1 -1
  271. data/spec/core_ext/socket_spec.rb +2 -2
  272. data/spec/core_ext/string_spec.rb +13 -13
  273. data/spec/core_ext/time_spec.rb +0 -2
  274. data/spec/gui/utilities/script_module_gui_spec.rb +3 -3
  275. data/spec/install/config/targets/INST/cmd_tlm/inst_tlm.txt +6 -6
  276. data/spec/install/config/tools/cmd_tlm_server/cmd_tlm_server.txt +4 -0
  277. data/spec/interfaces/cmd_tlm_server_interface_spec.rb +6 -2
  278. data/spec/interfaces/interface_spec.rb +0 -1
  279. data/spec/interfaces/linc_interface_spec.rb +0 -5
  280. data/spec/interfaces/protocols/crc_protocol_spec.rb +201 -85
  281. data/spec/interfaces/protocols/fixed_protocol_spec.rb +33 -9
  282. data/spec/interfaces/protocols/length_protocol_spec.rb +1 -1
  283. data/spec/interfaces/protocols/override_protocol_spec.rb +6 -2
  284. data/spec/interfaces/protocols/preidentified_protocol_spec.rb +1 -5
  285. data/spec/interfaces/protocols/template_protocol_spec.rb +0 -1
  286. data/spec/interfaces/simulated_target_interface_spec.rb +5 -5
  287. data/spec/interfaces/udp_interface_spec.rb +2 -4
  288. data/spec/io/buffered_file_spec.rb +8 -12
  289. data/spec/io/json_drb_spec.rb +9 -9
  290. data/spec/io/json_rpc_spec.rb +4 -4
  291. data/spec/io/raw_logger_spec.rb +4 -3
  292. data/spec/packet_logs/packet_log_reader_spec.rb +3 -6
  293. data/spec/packet_logs/packet_log_writer_spec.rb +4 -4
  294. data/spec/packets/binary_accessor_spec.rb +5 -8
  295. data/spec/packets/commands_spec.rb +2 -2
  296. data/spec/packets/limits_spec.rb +2 -2
  297. data/spec/packets/packet_config_spec.rb +12 -0
  298. data/spec/packets/packet_item_limits_spec.rb +1 -1
  299. data/spec/packets/packet_item_spec.rb +9 -9
  300. data/spec/packets/packet_spec.rb +15 -5
  301. data/spec/packets/parsers/packet_item_parser_spec.rb +27 -0
  302. data/spec/packets/parsers/xtce_parser_spec.rb +27 -30
  303. data/spec/packets/structure_spec.rb +2 -1
  304. data/spec/packets/telemetry_spec.rb +3 -5
  305. data/spec/processors/statistics_processor_spec.rb +35 -0
  306. data/spec/script/cmd_tlm_server_spec.rb +4 -21
  307. data/spec/script/commands_disconnect_spec.rb +46 -58
  308. data/spec/script/commands_spec.rb +40 -61
  309. data/spec/script/limits_spec.rb +1 -21
  310. data/spec/script/script_spec.rb +32 -41
  311. data/spec/script/scripting_spec.rb +166 -185
  312. data/spec/script/telemetry_spec.rb +10 -5
  313. data/spec/script/tools_spec.rb +2 -24
  314. data/spec/spec_helper.rb +11 -5
  315. data/spec/system/system_spec.rb +17 -12
  316. data/spec/tools/cmd_tlm_server/api_spec.rb +21 -10
  317. data/spec/tools/cmd_tlm_server/background_tasks_spec.rb +15 -16
  318. data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +0 -1
  319. data/spec/tools/cmd_tlm_server/cmd_tlm_server_spec.rb +16 -27
  320. data/spec/tools/cmd_tlm_server/commanding_spec.rb +2 -6
  321. data/spec/tools/cmd_tlm_server/connections_spec.rb +0 -4
  322. data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +13 -13
  323. data/spec/tools/cmd_tlm_server/interfaces_spec.rb +5 -9
  324. data/spec/tools/cmd_tlm_server/limits_groups_background_task_spec.rb +11 -3
  325. data/spec/tools/cmd_tlm_server/packet_logging_spec.rb +0 -4
  326. data/spec/tools/cmd_tlm_server/router_thread_spec.rb +5 -5
  327. data/spec/tools/cmd_tlm_server/routers_spec.rb +5 -9
  328. data/spec/tools/table_manager/table_config_spec.rb +0 -1
  329. data/spec/tools/table_manager/tablemanager_core_spec.rb +23 -23
  330. data/spec/tools/tlm_viewer/tlm_viewer_config_spec.rb +6 -4
  331. data/spec/top_level/top_level_spec.rb +9 -9
  332. data/spec/utilities/csv_spec.rb +2 -12
  333. data/spec/utilities/logger_spec.rb +6 -6
  334. data/spec/utilities/message_log_spec.rb +3 -11
  335. data/tasks/gemfile_stats.rake +2 -2
  336. metadata +198 -63
@@ -0,0 +1,27 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2018 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 File.expand_path('../../config/environment', __FILE__)
12
+ require 'dart_reducer_manager'
13
+ require 'dart_logging'
14
+
15
+ # Start the DartReducer
16
+ Cosmos.catch_fatal_exception do
17
+ DartCommon.handle_argv
18
+
19
+ Cosmos::Logger.level = Cosmos::Logger::INFO
20
+ dart_logging = DartLogging.new('dart_reducer')
21
+ num_threads = ENV['DART_NUM_REDUCERS']
22
+ num_threads ||= 5
23
+ num_threads = num_threads.to_i
24
+ drm = DartReducerManager.new(num_threads)
25
+ drm.run
26
+ dart_logging.stop
27
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2018 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 File.expand_path('../../config/environment', __FILE__)
12
+ require 'dart_tcpip_server_interface'
13
+ require 'dart_logging'
14
+
15
+ Cosmos.catch_fatal_exception do
16
+ DartCommon.handle_argv
17
+
18
+ Cosmos::Logger.level = Cosmos::Logger::INFO
19
+ dart_logging = DartLogging.new('dart_stream_server')
20
+
21
+ dts = DartTcpipServerInterface.new
22
+ dts.connect
23
+ Cosmos::Logger.info("Dart Stream Server Started...")
24
+ begin
25
+ sleep(1) while true
26
+ rescue Interrupt
27
+ Cosmos::Logger.info("Dart Stream Server Closing...")
28
+ dart_logging.stop
29
+ exit(0)
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2018 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 File.expand_path('../../config/environment', __FILE__)
12
+ require 'dart_common'
13
+ require 'dart_logging'
14
+ require 'dart_decommutator'
15
+
16
+ Cosmos.catch_fatal_exception do
17
+ DartCommon.handle_argv
18
+
19
+ # 0-based worker ID
20
+ worker_id = ARGV[0]
21
+ worker_id ||= 0
22
+ worker_id = worker_id.to_i
23
+ # Total number of workers
24
+ num_workers = ARGV[1]
25
+ num_workers ||= 1
26
+ num_workers = num_workers.to_i
27
+
28
+ Cosmos::Logger.level = Cosmos::Logger::INFO
29
+ dart_logging = DartLogging.new("dart_worker_#{worker_id}")
30
+ Cosmos::Logger.info("Dart Worker Starting...")
31
+ raise "Worker count #{num_workers} invalid" if num_workers < 1
32
+ raise "Worker id #{worker_id} too high for worker count of #{num_workers}" if worker_id >= num_workers
33
+ decom = DartDecommutator.new(worker_id, num_workers)
34
+ decom.run # Blocks forever
35
+ shutdown_cmd_tlm()
36
+ dart_logging.stop
37
+ end
@@ -0,0 +1,333 @@
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 'rails_helper'
12
+ require 'dart_common'
13
+ require 'database_cleaner'
14
+ require 'cosmos/tools/cmd_tlm_server/cmd_tlm_server'
15
+ require 'cosmos/tools/cmd_tlm_server/api'
16
+
17
+ describe DartCommon do
18
+ let(:common) { Object.new.extend(DartCommon) }
19
+
20
+ describe "sync_targets_and_packets" do
21
+ it "configures the database" do
22
+ targets = Cosmos::System.telemetry.all.keys.sort
23
+ expect(targets).to eql Cosmos::System.commands.all.keys.sort
24
+
25
+ # Put all the known targets and packets into the DB
26
+ common.sync_targets_and_packets
27
+
28
+ # Verify the targets
29
+ Target.all.order(:name).each_with_index do |target, i|
30
+ expect(target.name).to eq targets[i]
31
+ end
32
+ # Verify the telemetry packets
33
+ Cosmos::System.telemetry.all.each do |target_name, packets|
34
+ target = Target.find_by_name(target_name)
35
+ expect(target.name).to eq target_name
36
+ packets.each do |name, packet|
37
+ pkt = Packet.where({target: target, name: name, is_tlm: true}).first
38
+ expect(pkt.name).to eq name
39
+ expect(pkt.is_tlm).to eq true
40
+ expect(pkt.target.name).to eq target_name
41
+ end
42
+ end
43
+ # Verify the command packets
44
+ Cosmos::System.commands.all.each do |target_name, packets|
45
+ target = Target.find_by_name(target_name)
46
+ expect(target.name).to eq target_name
47
+ packets.each do |name, packet|
48
+ pkt = Packet.where({target: target, name: name, is_tlm: false}).first
49
+ expect(pkt.name).to eq name
50
+ expect(pkt.is_tlm).to eq false
51
+ expect(pkt.target.name).to eq target_name
52
+ end
53
+ end
54
+
55
+ num_tgts = Target.all.length
56
+ tgt_created_at = Target.first.created_at
57
+ num_pkts = Packet.all.length
58
+ pkt_created_at = Packet.first.created_at
59
+ #num_items = Item.all.length
60
+ #item_created_at = Item.first.created_at
61
+
62
+ # Try to add the known targets and packets into the DB again
63
+ common.sync_targets_and_packets
64
+ # Verify nothing was added
65
+ expect(Target.all.length).to eq num_tgts
66
+ expect(Packet.all.length).to eq num_pkts
67
+ #expect(Item.all.length).to eq num_items
68
+ expect(Target.first.created_at).to eq tgt_created_at
69
+ expect(Packet.first.created_at).to eq pkt_created_at
70
+ #expect(Item.first.created_at).to eq item_created_at
71
+ end
72
+ end
73
+
74
+ describe "setup_packet_config" do
75
+ it "builds the packet configuration in the DB" do
76
+ common.sync_targets_and_packets
77
+ target_id, packet_id = common.lookup_target_and_packet_id("INST", "HEALTH_STATUS", true)
78
+ packet_log = PacketLog.create(:filename => "filename", :is_tlm => true)
79
+ ple = PacketLogEntry.new
80
+ ple.target_id = target_id
81
+ ple.packet_id = packet_id
82
+ ple.time = Time.now
83
+ ple.packet_log_id = packet_log.id
84
+ ple.data_offset = 0
85
+ ple.meta_id = 0
86
+ ple.is_tlm = true
87
+ ple.ready = true
88
+ ple.save!
89
+
90
+ packet = Cosmos::System.telemetry.packet("INST", "HEALTH_STATUS")
91
+ packet_config = PacketConfig.create(:packet_id => packet_id, :name => packet.config_name, :first_system_config_id => 0)
92
+ common.setup_packet_config(packet, packet_id, packet_config)
93
+
94
+ model = common.get_decom_table_model(packet_config.id, 0)
95
+ expect(model.column_names).to include("i0")
96
+ model = common.get_decom_table_model(packet_config.id, 0, '_m')
97
+ expect(model.column_names).to include("i0min")
98
+ expect(model.column_names).to include("i0max")
99
+ expect(model.column_names).to include("i0avg")
100
+ expect(model.column_names).to include("i0stddev")
101
+ model = common.get_decom_table_model(packet_config.id, 0, '_h')
102
+ expect(model.column_names).to include("i0min")
103
+ expect(model.column_names).to include("i0max")
104
+ expect(model.column_names).to include("i0avg")
105
+ expect(model.column_names).to include("i0stddev")
106
+ model = common.get_decom_table_model(packet_config.id, 0, '_d')
107
+ expect(model.column_names).to include("i0min")
108
+ expect(model.column_names).to include("i0max")
109
+ expect(model.column_names).to include("i0avg")
110
+ expect(model.column_names).to include("i0stddev")
111
+
112
+ # Useful debugging to pring out all the mapping items
113
+ # ItemToDecomTableMapping.all.each do |map|
114
+ # item = Item.find(map.item_id)
115
+ # puts "item name:#{item.name} id:#{item.id} val:#{map.value_type} reduced:#{map.reduced} config:#{map.packet_config_id} table_i:#{map.table_index} item_i:#{map.item_index}"
116
+ # end
117
+
118
+ ###################################
119
+ # Spot check some interesting items
120
+ ###################################
121
+
122
+ item = Item.find_by_name("RECEIVED_TIMESECONDS")
123
+ mapping = ItemToDecomTableMapping.where("item_id = ?", item.id)
124
+ # RECEIVED_TIMESECONDS is derived so it has a single mapping
125
+ expect(mapping.length).to eq 1
126
+ map = mapping.first
127
+ expect(map.value_type).to eq ItemToDecomTableMapping::RAW_CON
128
+ expect(map.reduced).to eq true # Seconds is an integer so it can be reduced
129
+ expect(map.packet_config_id).to eq packet_config.id
130
+ expect(map.table_index).to eq 0 # Not enough values to span multiple tables
131
+
132
+ item = Item.find_by_name("RECEIVED_TIMEFORMATTED")
133
+ mapping = ItemToDecomTableMapping.where("item_id = ?", item.id)
134
+ # RECEIVED_TIMEFORMATTED is derived so it has a single mapping
135
+ expect(mapping.length).to eq 1
136
+ map = mapping.first
137
+ expect(map.value_type).to eq ItemToDecomTableMapping::RAW_CON
138
+ expect(map.reduced).to eq false # Formatted is a string so it can't be reduced
139
+ expect(map.packet_config_id).to eq packet_config.id
140
+ expect(map.table_index).to eq 0 # Not enough values to span multiple tables
141
+
142
+ item = Item.find_by_name("TEMP1")
143
+ mapping = ItemToDecomTableMapping.where("item_id = ?", item.id)
144
+ # TEMP1 creates a separate RAW and CONVERTED table since it has a conversion
145
+ expect(mapping.length).to eq 2
146
+ map = mapping.where("value_type = ?", ItemToDecomTableMapping::RAW).first
147
+ expect(map.value_type).to eq ItemToDecomTableMapping::RAW
148
+ expect(map.reduced).to eq true # UINT32 can be reduced
149
+ expect(map.packet_config_id).to eq packet_config.id
150
+ expect(map.table_index).to eq 0 # Not enough values to span multiple tables
151
+ map = mapping.where("value_type = ?", ItemToDecomTableMapping::CONVERTED).first
152
+ expect(map.value_type).to eq ItemToDecomTableMapping::CONVERTED
153
+ expect(map.reduced).to eq true # UINT32 can be reduced
154
+ expect(map.packet_config_id).to eq packet_config.id
155
+ expect(map.table_index).to eq 0 # Not enough values to span multiple tables
156
+
157
+ item = Item.find_by_name("GROUND1STATUS")
158
+ mapping = ItemToDecomTableMapping.where("item_id = ?", item.id)
159
+ # GROUND1STATUS creates a separate RAW and CONVERTED table since it has states
160
+ expect(mapping.length).to eq 2
161
+ map = mapping.where("value_type = ?", ItemToDecomTableMapping::RAW).first
162
+ expect(map.value_type).to eq ItemToDecomTableMapping::RAW
163
+ expect(map.reduced).to eq true # Raw value can be reduced
164
+ expect(map.packet_config_id).to eq packet_config.id
165
+ expect(map.table_index).to eq 0 # Not enough values to span multiple tables
166
+ map = mapping.where("value_type = ?", ItemToDecomTableMapping::CONVERTED).first
167
+ expect(map.value_type).to eq ItemToDecomTableMapping::CONVERTED
168
+ expect(map.reduced).to eq false # Converted is a string and can't be reduced
169
+ expect(map.packet_config_id).to eq packet_config.id
170
+ expect(map.table_index).to eq 0 # Not enough values to span multiple tables
171
+ end
172
+
173
+ it "spans multiple DB tables with big packets" do
174
+ # Create a new packet with a bunch of items
175
+ packet = Cosmos::Packet.new('INST', 'BIGGIE', :BIG_ENDIAN)
176
+ num_items = DartCommon::MAX_COLUMNS_PER_TABLE + 1
177
+ num_items.times do |index|
178
+ packet.append_item("ITEM#{index}", 8, :INT)
179
+ end
180
+ # Push the new packet into the PacketConfig telemetry hash
181
+ Cosmos::System.telemetry.config.telemetry['INST']['BIGGIE'] = packet
182
+ common.sync_targets_and_packets
183
+ target_id, packet_id = common.lookup_target_and_packet_id("INST", "BIGGIE", true)
184
+ packet_log = PacketLog.create(:filename => "filename", :is_tlm => true)
185
+ ple = PacketLogEntry.new
186
+ ple.target_id = target_id
187
+ ple.packet_id = packet_id
188
+ ple.time = Time.now
189
+ ple.packet_log_id = packet_log.id
190
+ ple.data_offset = 0
191
+ ple.meta_id = 0
192
+ ple.is_tlm = true
193
+ ple.ready = true
194
+ ple.save!
195
+
196
+ packet = Cosmos::System.telemetry.packet("INST", "BIGGIE")
197
+ packet_config = PacketConfig.create(:packet_id => packet_id, :name => packet.config_name, :first_system_config_id => 0)
198
+ common.setup_packet_config(packet, packet_id, packet_config)
199
+
200
+ # Verify the decommutation and reduction tables were created
201
+ (0..1).each do |table_index|
202
+ model = common.get_decom_table_model(packet_config.id, table_index)
203
+ if table_index == 0
204
+ expect(model.column_names).to include("i0")
205
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE - 1}")
206
+ # The base decommutation table doesn't average
207
+ expect(model.column_names).to_not include("i0avg")
208
+ expect(model.column_names).to_not include("i0stddev")
209
+ else
210
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE}")
211
+ expect(model.column_names).to_not include("i#{DartCommon::MAX_COLUMNS_PER_TABLE + 1}")
212
+ end
213
+
214
+ %w(m h d).each do |suffix|
215
+ model = common.get_decom_table_model(packet_config.id, table_index, "_#{suffix}")
216
+ if table_index == 0
217
+ # The decommutation tables have min max avg only
218
+ expect(model.column_names).to_not include("i0")
219
+ expect(model.column_names).to include("i0min")
220
+ expect(model.column_names).to include("i0max")
221
+ expect(model.column_names).to include("i0avg")
222
+ expect(model.column_names).to include("i0stddev")
223
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE - 1}min")
224
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE - 1}max")
225
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE - 1}avg")
226
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE - 1}stddev")
227
+ else
228
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE}min")
229
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE}max")
230
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE}avg")
231
+ expect(model.column_names).to include("i#{DartCommon::MAX_COLUMNS_PER_TABLE}stddev")
232
+ end
233
+ end
234
+ end
235
+
236
+ num_items.times do |index|
237
+ item = Item.where("name = ? AND packet_id = ?", "ITEM#{index}", packet_id).first
238
+ map = ItemToDecomTableMapping.where("item_id = ?", item.id).first
239
+ if index < DartCommon::MAX_COLUMNS_PER_TABLE
240
+ expect(map.table_index).to eq 0
241
+ else
242
+ expect(map.table_index).to eq 1 # Mapping spans another table
243
+ end
244
+ end
245
+ end
246
+ end
247
+
248
+ describe "switch_and_get_system_config" do
249
+ before(:each) do
250
+ allow_any_instance_of(Cosmos::Interface).to receive(:connected?)
251
+ allow_any_instance_of(Cosmos::Interface).to receive(:connect)
252
+ allow_any_instance_of(Cosmos::Interface).to receive(:disconnect)
253
+ allow_any_instance_of(Cosmos::Interface).to receive(:write_raw)
254
+ allow_any_instance_of(Cosmos::Interface).to receive(:read)
255
+ allow_any_instance_of(Cosmos::Interface).to receive(:write)
256
+ @tlm_file = File.join(Cosmos::USERPATH,'config','targets','SYSTEM','cmd_tlm','test1_tlm.txt')
257
+ FileUtils.rm @tlm_file if File.exist? @tlm_file
258
+ end
259
+
260
+ it "raises an error if the configuration can't be found" do
261
+ api = Cosmos::CmdTlmServer.new
262
+ expect { common.switch_and_get_system_config("abcd") }.to raise_error(/No saved config/)
263
+ api.stop
264
+ end
265
+
266
+ it "does nothing if loading the current config" do
267
+ api = Cosmos::CmdTlmServer.new
268
+ current = Cosmos::System.configuration_name
269
+ common.switch_and_get_system_config(current)
270
+ expect(Cosmos::System.configuration_name).to eq current
271
+ api.stop
272
+ end
273
+
274
+ it "loads new configuration" do
275
+ api = Cosmos::CmdTlmServer.new
276
+ initial_config = Cosmos::System.configuration_name
277
+
278
+ # Create a new configuration by writing another telemetry file
279
+ File.open(@tlm_file, 'w') do |file|
280
+ file.puts "TELEMETRY SYSTEM TEST1 BIG_ENDIAN"
281
+ file.puts " APPEND_ITEM DATA 240 STRING"
282
+ end
283
+ # Reset the instance variable so it will create the new configuration
284
+ Cosmos::System.class_eval('@@instance = nil')
285
+ Cosmos::System.telemetry # Create the new config
286
+ new_config = Cosmos::System.configuration_name
287
+ expect(new_config).to_not eq initial_config
288
+
289
+ # Stub find_configuration to first return nil (not found) and then work
290
+ # This allows the switch_and_get_system_config to act like the local copy
291
+ # could not be found and then properly finds it
292
+ allow(Cosmos::System.instance).to receive(:find_configuration).and_return(nil, Cosmos::System.instance.find_configuration(initial_config))
293
+ messages = []
294
+ allow(Cosmos::Logger).to receive(:info) { |msg| messages << msg }
295
+
296
+ common.switch_and_get_system_config(initial_config)
297
+ expect(Cosmos::System.configuration_name).to eq initial_config
298
+ messages.each do |msg|
299
+ if msg =~ /Configuration retrieved/
300
+ expect(msg).to match(/#{initial_config}/)
301
+ end
302
+ end
303
+
304
+ api.stop
305
+ FileUtils.rm @tlm_file
306
+ end
307
+ end
308
+
309
+ describe "read_packet_from_ple" do
310
+ # NOTE: most of read_packet_from_ple is tested in the dart_packet_log_writer_spec
311
+ it "raises an error if the packet can't be found" do
312
+ common.sync_targets_and_packets
313
+ target_id, packet_id = common.lookup_target_and_packet_id("INST", "HEALTH_STATUS", true)
314
+ packet_log = PacketLog.create(:filename => "filename", :is_tlm => true)
315
+ ple = PacketLogEntry.new
316
+ ple.target_id = target_id
317
+ ple.packet_id = packet_id
318
+ ple.time = Time.now
319
+ ple.packet_log_id = packet_log.id
320
+ ple.data_offset = 999
321
+ ple.meta_id = 999
322
+ ple.is_tlm = true
323
+ ple.ready = true
324
+ ple.save!
325
+
326
+ expect(Cosmos::Logger).to receive(:error) do |msg|
327
+ expect(msg).to match(/Error Reading Packet/)
328
+ end
329
+ packet = common.read_packet_from_ple(ple)
330
+ expect(packet).to be_nil
331
+ end
332
+ end
333
+ end
@@ -0,0 +1,455 @@
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 'rails_helper'
12
+ require 'dart_database_cleaner'
13
+ require 'dart_packet_log_writer'
14
+ require 'dart_decommutator'
15
+
16
+ describe DartDatabaseCleaner do
17
+ before(:each) do
18
+ DatabaseCleaner.strategy = :truncation
19
+ DatabaseCleaner.clean
20
+ @cleaner = DartDatabaseCleaner.new
21
+ end
22
+
23
+ describe "clean" do
24
+ it "calls the cleaning methods" do
25
+ messages = []
26
+ allow(Cosmos::Logger).to receive(:info) { |msg| messages << msg }
27
+ DartDatabaseCleaner.clean(false)
28
+ expect(messages.select{|m| m =~ /Cleaning up SystemConfig/}.length).to eq 1
29
+ expect(messages.select{|m| m =~ /Cleaning up PacketLog\./}.length).to eq 1
30
+ expect(messages.select{|m| m =~ /Cleaning up PacketConfig/}.length).to eq 1
31
+ expect(messages.select{|m| m =~ /Cleaning up PacketLogEntry/}.length).to eq 1
32
+ expect(messages.select{|m| m =~ /Cleaning up Decommutation/}.length).to eq 1
33
+ expect(messages.select{|m| m =~ /Database cleanup complete/}.length).to eq 1
34
+ end
35
+ end
36
+
37
+ describe "clean_system_configs" do
38
+ it "ensures all system configs are local" do
39
+ # Create a bogus SystemConfig to cause an error
40
+ SystemConfig.create(:name => "test")
41
+
42
+ expect(Cosmos::Logger).to receive(:error) do |msg|
43
+ expect(msg).to match(/Could not load system_config: test/)
44
+ end
45
+ config, error = @cleaner.clean_system_configs
46
+ # Ensure the configuration is loaded
47
+ expect(config).to eq Cosmos::System.configuration_name
48
+ end
49
+ end
50
+
51
+ describe "clean_packet_logs" do
52
+ before(:each) do
53
+ @target = Target.create(:name => "test")
54
+ @packet = Packet.create(:target_id => @target.id, :name => "test", :is_tlm => true)
55
+ end
56
+
57
+ it "ensures all packet logs exist" do
58
+ # Create a good file which exists where we expect
59
+ filename = File.join(Cosmos::System.paths['DART_DATA'], 'test_file.bin')
60
+ File.open(filename, 'w') { |file| file.puts "This is test data" }
61
+ packet_log = PacketLog.create(:filename => filename, :is_tlm => true)
62
+
63
+ ple = PacketLogEntry.new
64
+ ple.target_id = @target.id
65
+ ple.packet_id = @packet.id
66
+ ple.time = Time.now
67
+ ple.packet_log_id = packet_log.id
68
+ ple.data_offset = 0
69
+ ple.meta_id = 0
70
+ ple.is_tlm = true
71
+ ple.ready = true
72
+ ple.save!
73
+
74
+ @cleaner.clean_packet_logs(false)
75
+ # Ensure nothing changed
76
+ log = PacketLog.find(1)
77
+ expect(log.filename).to eq filename
78
+ entry = PacketLogEntry.find(1)
79
+ expect(entry.packet_log.filename).to eq filename
80
+ end
81
+
82
+ it "checks for files moved to DART_DATA and updates the path" do
83
+ # Create a good file which exists where we expect
84
+ filename = File.join(Cosmos::System.paths['DART_DATA'], 'test_file.bin')
85
+ File.open(filename, 'w') { |file| file.puts "This is test data" }
86
+ # Create a PacketLog with a bad path
87
+ bad_path = File.join("C:/somewhere/that/does/not/exist", File.basename(filename))
88
+ packet_log = PacketLog.create(:filename => bad_path, :is_tlm => true)
89
+
90
+ ple = PacketLogEntry.new
91
+ ple.target_id = @target.id
92
+ ple.packet_id = @packet.id
93
+ ple.time = Time.now
94
+ ple.packet_log_id = packet_log.id
95
+ ple.data_offset = 0
96
+ ple.meta_id = 0
97
+ ple.is_tlm = true
98
+ ple.ready = true
99
+ ple.save!
100
+
101
+ @cleaner.clean_packet_logs(false)
102
+ # Ensure the path is updated
103
+ log = PacketLog.find(1)
104
+ expect(log.filename).to eq filename
105
+ entry = PacketLogEntry.find(1)
106
+ expect(entry.packet_log.filename).to eq filename
107
+ end
108
+
109
+ it "exits if a file is missing and force == false" do
110
+ # Create a PacketLog with a non-existant file
111
+ packet_log = PacketLog.create(:filename => "C:/no/file/here/test.bin", :is_tlm => true)
112
+ expect { @cleaner.clean_packet_logs(false) }.to raise_error(SystemExit)
113
+ end
114
+
115
+ it "deletes if a file is missing and force == true" do
116
+ # Create a PacketLog with a non-existant file
117
+ packet_log = PacketLog.create(:filename => "C:/no/file/here/test.bin", :is_tlm => true)
118
+ 10.times do
119
+ ple = PacketLogEntry.new
120
+ ple.target_id = @target.id
121
+ ple.packet_id = @packet.id
122
+ ple.time = Time.now
123
+ ple.packet_log_id = packet_log.id
124
+ ple.data_offset = 0
125
+ ple.meta_id = 0
126
+ ple.is_tlm = true
127
+ ple.ready = true
128
+ ple.save!
129
+ end
130
+
131
+ @cleaner.clean_packet_logs(true)
132
+ expect { PacketLog.find(1) }.to raise_error(ActiveRecord::RecordNotFound)
133
+ # Also any PacketLogEntries linked to that PacketLog are deleted
134
+ expect(PacketLogEntry.all.count).to eq 0
135
+ end
136
+ end
137
+
138
+ describe "clean_packet_configs" do
139
+ it "raises if the SystemConfig can't be found" do
140
+ target = Target.create(:name => "test")
141
+ packet = Packet.create(:target_id => target.id, :name => "test", :is_tlm => true)
142
+ PacketConfig.create(:packet_id => packet.id, :name => "test", :first_system_config_id => 1)
143
+ expect { @cleaner.clean_packet_configs }.to raise_error(/Cleanup failure/)
144
+ end
145
+
146
+ it "complains about bad SystemConfigs" do
147
+ @cleaner.sync_targets_and_packets
148
+ target_id, packet_id = @cleaner.lookup_target_and_packet_id("INST", "HEALTH_STATUS", true)
149
+ packet = Cosmos::System.telemetry.packet("INST", "HEALTH_STATUS")
150
+ sys_config = SystemConfig.create(:name => "test")
151
+ PacketConfig.create(:packet_id => packet_id, :name => packet.config_name, :first_system_config_id => sys_config.id)
152
+
153
+ expect(Cosmos::Logger).to receive(:error) do |msg|
154
+ expect(msg).to match(/Could not switch to system config: test/)
155
+ end
156
+ @cleaner.clean_packet_configs
157
+ end
158
+
159
+ it "recreates the PacketConfig if it is not 'ready'" do
160
+ @cleaner.sync_targets_and_packets
161
+ target_id, packet_id = @cleaner.lookup_target_and_packet_id("INST", "HEALTH_STATUS", true)
162
+ packet = Cosmos::System.telemetry.packet("INST", "HEALTH_STATUS")
163
+ meta_packet = Cosmos::System.telemetry.packet("SYSTEM", "META")
164
+ sys_config = SystemConfig.create(:name => meta_packet.read("CONFIG"))
165
+ PacketConfig.create(:packet_id => packet_id, :name => packet.config_name, :first_system_config_id => sys_config.id)
166
+
167
+ # By default new PacketConfig items should not be marked ready
168
+ packet_config = PacketConfig.where(:packet_id => packet_id, :name => packet.config_name, :first_system_config_id => sys_config.id).first
169
+ expect(packet_config.ready).to be false
170
+
171
+ item = Item.create(:packet_id => packet_id, :name => "TEST_ITEM")
172
+ # Create an item to decom table mapping to ensure it gets cleaned up
173
+ ItemToDecomTableMapping.create(
174
+ :item_id => item.id,
175
+ :value_type => ItemToDecomTableMapping::RAW,
176
+ :reduced => true,
177
+ :packet_config_id => packet_config.id,
178
+ :table_index => 0,
179
+ :item_index => 999999) # Bogus value we can check
180
+ expect(ItemToDecomTableMapping.find_by_item_index(999999)).to_not be_nil
181
+ # Create a decommutation table to ensure it gets cleaned up
182
+ table_name = "t#{packet_config.id}_0"
183
+ table = ActiveRecord::Base.connection.create_table(table_name) do |table|
184
+ table.integer :delete_me # Bogus column
185
+ end
186
+ # Need to create model
187
+ model = Class.new(ActiveRecord::Base) do
188
+ self.table_name = table_name.dup
189
+ end
190
+ model.reset_column_information
191
+ model_name = table_name.upcase
192
+ Cosmos.send(:remove_const, model_name) if Cosmos.const_defined?(model_name)
193
+ Cosmos.const_set(model_name, model)
194
+
195
+ expect(model.column_names).to include("delete_me")
196
+ # Create reduction tables to ensure they are cleaned up
197
+ %w(_h _m _d).each do |id|
198
+ table_name = "t#{packet_config.id}_0#{id}"
199
+ table = ActiveRecord::Base.connection.create_table(table_name) do |table|
200
+ table.integer :delete_me # Bogus column
201
+ end
202
+ # Need to create model
203
+ model = Class.new(ActiveRecord::Base) do
204
+ self.table_name = table_name.dup
205
+ end
206
+ model.reset_column_information
207
+ model_name = table_name.upcase
208
+ Cosmos.send(:remove_const, model_name) if Cosmos.const_defined?(model_name)
209
+ Cosmos.const_set(model_name, model)
210
+
211
+ expect(model.column_names).to include("delete_me")
212
+ end
213
+ messages = [] # Store all Logger.info messages
214
+ allow(Cosmos::Logger).to receive(:info) { |msg| messages << msg }
215
+
216
+ @cleaner.clean_packet_configs # <--- PERFORM THE TEST
217
+
218
+ # Check messages for success
219
+ expect(messages.select {|msg| msg =~ /Successfully cleaned/ }[0]).to match(/packet_config: 1/)
220
+ packet_config = PacketConfig.where(:packet_id => packet_id, :name => packet.config_name, :first_system_config_id => sys_config.id).first
221
+ expect(packet_config.ready).to be true # ready is not true
222
+ # The item should still be there
223
+ expect(Item.find(1).name).to eq "TEST_ITEM"
224
+ # The old ItemToDecomTableMapping should be removed
225
+ expect(ItemToDecomTableMapping.find_by_item_index(999999)).to be_nil
226
+ # All new items should have the PacketConfig ID set
227
+ ItemToDecomTableMapping.all.each do |item|
228
+ expect(item.packet_config_id).to eq packet_config.id
229
+ end
230
+ # The decom table should have been recreated
231
+ model = @cleaner.get_decom_table_model(packet_config.id, 0)
232
+ expect(model.column_names).to_not include("delete_me")
233
+ expect(model.column_names).to include("i0") # as well as i1, i2, etc
234
+ # The reduction table should have been recreated
235
+ %w(_h _m _d).each do |id|
236
+ model = @cleaner.get_decom_table_model(packet_config.id, 0, id)
237
+ expect(model.column_names).to_not include("delete_me")
238
+ expect(model.column_names).to include("i0min")
239
+ expect(model.column_names).to include("i0max")
240
+ expect(model.column_names).to include("i0avg")
241
+ expect(model.column_names).to include("i0stddev")
242
+ end
243
+ end
244
+ end
245
+
246
+ describe "clean_packet_log_entries" do
247
+ it "removes PacketLogEntry rows where ready == false" do
248
+ target = Target.create(:name => "test")
249
+ packet = Packet.create(:target_id => target.id, :name => "test", :is_tlm => true)
250
+ packet_log = PacketLog.create(:filename => "filename", :is_tlm => true)
251
+ ple = PacketLogEntry.new
252
+ ple.target_id = target.id
253
+ ple.packet_id = packet.id
254
+ ple.time = Time.now
255
+ ple.packet_log_id = packet_log.id
256
+ ple.data_offset = 1
257
+ ple.meta_id = 1
258
+ ple.is_tlm = true
259
+ ple.ready = false
260
+ ple.save!
261
+ expect(PacketLogEntry.all.length).to eq 1
262
+ @cleaner.clean_packet_log_entries
263
+ expect(PacketLogEntry.all.length).to eq 0
264
+ end
265
+ end
266
+
267
+ describe "clean_decommutation_tables" do
268
+ it "removes decommutation rows which are in progress" do
269
+ writer = DartPacketLogWriter.new(
270
+ :TLM, # Log telemetry
271
+ 'clean_decom_', # File name suffix
272
+ true, # Enable logging
273
+ nil, # Don't cycle on time
274
+ 2_000_000_000, # Cycle the log at 2GB
275
+ Cosmos::System.paths['DART_DATA']) # Log into the DART_DATA dir
276
+
277
+ hs_packet = Cosmos::System.telemetry.packet("INST", "HEALTH_STATUS")
278
+ # Write three packets. The first packet is always SYSTEM META.
279
+ 3.times do
280
+ hs_packet.received_time = Time.now
281
+ writer.write(hs_packet)
282
+ sleep 0.01
283
+ end
284
+ writer.shutdown
285
+ sleep 0.1
286
+
287
+ # Create a valid SystemConfig in order to create a valid PacketConfig
288
+ meta = Cosmos::System.telemetry.packet("SYSTEM", "META")
289
+ system_config = SystemConfig.create(:name => meta.read("CONFIG"))
290
+ target_id, packet_id = writer.lookup_target_and_packet_id("INST", "HEALTH_STATUS", true)
291
+ packet_config = PacketConfig.create(:packet_id => packet_id, :name => hs_packet.config_name, :first_system_config_id => system_config.id)
292
+ writer.setup_packet_config(hs_packet, packet_id, packet_config)
293
+
294
+ decom = writer.get_decom_table_model(packet_config.id, 0)
295
+ PacketLogEntry.all.each do |ple|
296
+ # By default all PacketLogEntries should be marked NOT_STARTED
297
+ expect(ple.decom_state).to eq PacketLogEntry::NOT_STARTED
298
+ case ple.target.name
299
+ when 'SYSTEM'
300
+ ple.decom_state = PacketLogEntry::COMPLETE
301
+ when 'INST'
302
+ ple.decom_state = PacketLogEntry::IN_PROGRESS
303
+ row = decom.new
304
+ row.time = Time.now
305
+ row.reduced_state = DartDecommutator::INITIALIZING
306
+ row.ple_id = ple.id
307
+ row.save!
308
+ end
309
+ ple.save!
310
+ end
311
+ expect(decom.all.count).to eq 3
312
+
313
+ @cleaner.clean_decommutation_tables # <--- PERFORM THE TEST
314
+
315
+ PacketLogEntry.all.each do |ple|
316
+ case ple.target.name
317
+ when 'SYSTEM'
318
+ expect(ple.decom_state).to eq PacketLogEntry::COMPLETE
319
+ when 'INST'
320
+ # All INST should be now marked NOT_STARTED
321
+ expect(ple.decom_state).to eq PacketLogEntry::NOT_STARTED
322
+ end
323
+ end
324
+ # The decommutation table has been cleaned
325
+ decom = writer.get_decom_table_model(packet_config.id, 0)
326
+ expect(decom.all.count).to eq 0
327
+ end
328
+ end
329
+
330
+ describe "clean_decommutation_tables" do
331
+ it "removes decommutation rows which are in progress" do
332
+ writer = DartPacketLogWriter.new(
333
+ :TLM, # Log telemetry
334
+ 'clean_decom_', # File name suffix
335
+ true, # Enable logging
336
+ nil, # Don't cycle on time
337
+ 2_000_000_000, # Cycle the log at 2GB
338
+ Cosmos::System.paths['DART_DATA']) # Log into the DART_DATA dir
339
+
340
+ hs_packet = Cosmos::System.telemetry.packet("INST", "HEALTH_STATUS")
341
+ # Write three packets. The first packet is always SYSTEM META.
342
+ 3.times do
343
+ hs_packet.received_time = Time.now
344
+ writer.write(hs_packet)
345
+ sleep 0.01
346
+ end
347
+ writer.shutdown
348
+ sleep 0.1
349
+
350
+ # Create a valid SystemConfig in order to create a valid PacketConfig
351
+ meta = Cosmos::System.telemetry.packet("SYSTEM", "META")
352
+ system_config = SystemConfig.create(:name => meta.read("CONFIG"))
353
+ target_id, packet_id = writer.lookup_target_and_packet_id("INST", "HEALTH_STATUS", true)
354
+ packet_config = PacketConfig.create(:packet_id => packet_id, :name => hs_packet.config_name, :first_system_config_id => system_config.id)
355
+ writer.setup_packet_config(hs_packet, packet_id, packet_config)
356
+
357
+ decom = writer.get_decom_table_model(packet_config.id, 0)
358
+ PacketLogEntry.all.each do |ple|
359
+ # By default all PacketLogEntries should be marked NOT_STARTED
360
+ expect(ple.decom_state).to eq PacketLogEntry::NOT_STARTED
361
+ case ple.target.name
362
+ when 'SYSTEM'
363
+ ple.decom_state = PacketLogEntry::COMPLETE
364
+ when 'INST'
365
+ ple.decom_state = PacketLogEntry::IN_PROGRESS
366
+ row = decom.new
367
+ row.time = Time.now
368
+ row.reduced_state = DartDecommutator::INITIALIZING
369
+ row.ple_id = ple.id
370
+ row.save!
371
+ end
372
+ ple.save!
373
+ end
374
+ expect(decom.all.count).to eq 3
375
+
376
+ @cleaner.clean_decommutation_tables # <--- PERFORM THE TEST
377
+
378
+ PacketLogEntry.all.each do |ple|
379
+ case ple.target.name
380
+ when 'SYSTEM'
381
+ expect(ple.decom_state).to eq PacketLogEntry::COMPLETE
382
+ when 'INST'
383
+ # All INST should be now marked NOT_STARTED
384
+ expect(ple.decom_state).to eq PacketLogEntry::NOT_STARTED
385
+ end
386
+ end
387
+ # The decommutation table has been cleaned
388
+ decom = writer.get_decom_table_model(packet_config.id, 0)
389
+ expect(decom.all.count).to eq 0
390
+ end
391
+ end
392
+
393
+ describe "clean_reductions" do
394
+ it "removes decommutation rows which are in progress" do
395
+ writer = DartPacketLogWriter.new(
396
+ :TLM, # Log telemetry
397
+ 'clean_reduction_', # File name suffix
398
+ true, # Enable logging
399
+ nil, # Don't cycle on time
400
+ 2_000_000_000, # Cycle the log at 2GB
401
+ Cosmos::System.paths['DART_DATA']) # Log into the DART_DATA dir
402
+
403
+ hs_packet = Cosmos::System.telemetry.packet("INST", "HEALTH_STATUS")
404
+ # Write three packets. The first packet is always SYSTEM META.
405
+ 3.times do
406
+ hs_packet.received_time = Time.now
407
+ writer.write(hs_packet)
408
+ sleep 0.01
409
+ end
410
+ writer.shutdown
411
+ sleep 0.1
412
+
413
+ # Create a valid SystemConfig in order to create a valid PacketConfig
414
+ meta = Cosmos::System.telemetry.packet("SYSTEM", "META")
415
+ system_config = SystemConfig.create(:name => meta.read("CONFIG"))
416
+ target_id, packet_id = writer.lookup_target_and_packet_id("INST", "HEALTH_STATUS", true)
417
+ packet_config = PacketConfig.create(:packet_id => packet_id, :name => hs_packet.config_name, :first_system_config_id => system_config.id)
418
+ writer.setup_packet_config(hs_packet, packet_id, packet_config)
419
+
420
+ decom = writer.get_decom_table_model(packet_config.id, 0)
421
+ PacketLogEntry.all.each do |ple|
422
+ # By default all PacketLogEntries should be marked NOT_STARTED
423
+ expect(ple.decom_state).to eq PacketLogEntry::NOT_STARTED
424
+ case ple.target.name
425
+ when 'SYSTEM'
426
+ ple.decom_state = PacketLogEntry::COMPLETE
427
+ when 'INST'
428
+ ple.decom_state = PacketLogEntry::IN_PROGRESS
429
+ row = decom.new
430
+ row.time = Time.now
431
+ row.reduced_state = DartDecommutator::INITIALIZING
432
+ row.ple_id = ple.id
433
+ row.save!
434
+ end
435
+ ple.save!
436
+ end
437
+ expect(decom.all.count).to eq 3
438
+
439
+ @cleaner.clean_decommutation_tables # <--- PERFORM THE TEST
440
+
441
+ PacketLogEntry.all.each do |ple|
442
+ case ple.target.name
443
+ when 'SYSTEM'
444
+ expect(ple.decom_state).to eq PacketLogEntry::COMPLETE
445
+ when 'INST'
446
+ # All INST should be now marked NOT_STARTED
447
+ expect(ple.decom_state).to eq PacketLogEntry::NOT_STARTED
448
+ end
449
+ end
450
+ # The decommutation table has been cleaned
451
+ decom = writer.get_decom_table_model(packet_config.id, 0)
452
+ expect(decom.all.count).to eq 0
453
+ end
454
+ end
455
+ end