openc3 5.0.6

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 (307) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +18 -0
  3. data/Guardfile +35 -0
  4. data/LICENSE.txt +727 -0
  5. data/README.md +37 -0
  6. data/Rakefile +131 -0
  7. data/bin/cstol_converter +1178 -0
  8. data/bin/openc3cli +531 -0
  9. data/bin/rubysloc +139 -0
  10. data/data/config/_array_params.yaml +23 -0
  11. data/data/config/_id_items.yaml +24 -0
  12. data/data/config/_id_params.yaml +58 -0
  13. data/data/config/_interfaces.yaml +214 -0
  14. data/data/config/_interfaces.yaml.err +1017 -0
  15. data/data/config/_items.yaml +20 -0
  16. data/data/config/_params.yaml +60 -0
  17. data/data/config/cmd_tlm_server.yaml +136 -0
  18. data/data/config/command.yaml +44 -0
  19. data/data/config/command_modifiers.yaml +160 -0
  20. data/data/config/command_telemetry.yaml +3 -0
  21. data/data/config/interface_modifiers.yaml +104 -0
  22. data/data/config/item_modifiers.yaml +221 -0
  23. data/data/config/microservice.yaml +78 -0
  24. data/data/config/param_item_modifiers.yaml +52 -0
  25. data/data/config/parameter_modifiers.yaml +200 -0
  26. data/data/config/plugins.yaml +80 -0
  27. data/data/config/protocols.yaml +290 -0
  28. data/data/config/screen.yaml +147 -0
  29. data/data/config/table_manager.yaml +89 -0
  30. data/data/config/table_parameter_modifiers.yaml +9 -0
  31. data/data/config/target.yaml +142 -0
  32. data/data/config/target_config.yaml +94 -0
  33. data/data/config/telemetry.yaml +87 -0
  34. data/data/config/telemetry_modifiers.yaml +159 -0
  35. data/data/config/tool.yaml +63 -0
  36. data/data/config/unknown.yaml +3 -0
  37. data/data/config/widgets.yaml +1505 -0
  38. data/ext/mkrf_conf.rb +49 -0
  39. data/ext/openc3/ext/array/array.c +122 -0
  40. data/ext/openc3/ext/array/extconf.rb +13 -0
  41. data/ext/openc3/ext/buffered_file/buffered_file.c +198 -0
  42. data/ext/openc3/ext/buffered_file/extconf.rb +13 -0
  43. data/ext/openc3/ext/config_parser/config_parser.c +280 -0
  44. data/ext/openc3/ext/config_parser/extconf.rb +13 -0
  45. data/ext/openc3/ext/crc/crc.c +351 -0
  46. data/ext/openc3/ext/crc/extconf.rb +13 -0
  47. data/ext/openc3/ext/openc3_io/extconf.rb +13 -0
  48. data/ext/openc3/ext/openc3_io/openc3_io.c +158 -0
  49. data/ext/openc3/ext/packet/extconf.rb +13 -0
  50. data/ext/openc3/ext/packet/packet.c +318 -0
  51. data/ext/openc3/ext/platform/extconf.rb +13 -0
  52. data/ext/openc3/ext/platform/platform.c +134 -0
  53. data/ext/openc3/ext/polynomial_conversion/extconf.rb +13 -0
  54. data/ext/openc3/ext/polynomial_conversion/polynomial_conversion.c +79 -0
  55. data/ext/openc3/ext/string/extconf.rb +13 -0
  56. data/ext/openc3/ext/string/string.c +63 -0
  57. data/ext/openc3/ext/structure/structure.c +1719 -0
  58. data/ext/openc3/ext/tabbed_plots_config/extconf.rb +13 -0
  59. data/ext/openc3/ext/tabbed_plots_config/tabbed_plots_config.c +62 -0
  60. data/ext/openc3/ext/telemetry/extconf.rb +13 -0
  61. data/ext/openc3/ext/telemetry/telemetry.c +336 -0
  62. data/lib/cosmos.rb +20 -0
  63. data/lib/cosmosc2.rb +20 -0
  64. data/lib/openc3/api/api.rb +39 -0
  65. data/lib/openc3/api/authorized_api.rb +30 -0
  66. data/lib/openc3/api/cmd_api.rb +451 -0
  67. data/lib/openc3/api/config_api.rb +58 -0
  68. data/lib/openc3/api/interface_api.rb +117 -0
  69. data/lib/openc3/api/limits_api.rb +375 -0
  70. data/lib/openc3/api/router_api.rb +117 -0
  71. data/lib/openc3/api/settings_api.rb +70 -0
  72. data/lib/openc3/api/target_api.rb +78 -0
  73. data/lib/openc3/api/tlm_api.rb +455 -0
  74. data/lib/openc3/bridge/bridge.rb +54 -0
  75. data/lib/openc3/bridge/bridge_config.rb +167 -0
  76. data/lib/openc3/bridge/bridge_interface_thread.rb +42 -0
  77. data/lib/openc3/bridge/bridge_router_thread.rb +42 -0
  78. data/lib/openc3/ccsds/ccsds_packet.rb +68 -0
  79. data/lib/openc3/ccsds/ccsds_parser.rb +148 -0
  80. data/lib/openc3/config/config_parser.rb +549 -0
  81. data/lib/openc3/config/meta_config_parser.rb +74 -0
  82. data/lib/openc3/conversions/conversion.rb +70 -0
  83. data/lib/openc3/conversions/generic_conversion.rb +83 -0
  84. data/lib/openc3/conversions/packet_time_formatted_conversion.rb +43 -0
  85. data/lib/openc3/conversions/packet_time_seconds_conversion.rb +43 -0
  86. data/lib/openc3/conversions/polynomial_conversion.rb +87 -0
  87. data/lib/openc3/conversions/processor_conversion.rb +70 -0
  88. data/lib/openc3/conversions/received_count_conversion.rb +38 -0
  89. data/lib/openc3/conversions/received_time_formatted_conversion.rb +42 -0
  90. data/lib/openc3/conversions/received_time_seconds_conversion.rb +42 -0
  91. data/lib/openc3/conversions/segmented_polynomial_conversion.rb +171 -0
  92. data/lib/openc3/conversions/unix_time_conversion.rb +68 -0
  93. data/lib/openc3/conversions/unix_time_formatted_conversion.rb +49 -0
  94. data/lib/openc3/conversions/unix_time_seconds_conversion.rb +49 -0
  95. data/lib/openc3/conversions.rb +34 -0
  96. data/lib/openc3/core_ext/array.rb +416 -0
  97. data/lib/openc3/core_ext/binding.rb +29 -0
  98. data/lib/openc3/core_ext/class.rb +72 -0
  99. data/lib/openc3/core_ext/exception.rb +61 -0
  100. data/lib/openc3/core_ext/file.rb +83 -0
  101. data/lib/openc3/core_ext/hash.rb +37 -0
  102. data/lib/openc3/core_ext/io.rb +134 -0
  103. data/lib/openc3/core_ext/kernel.rb +42 -0
  104. data/lib/openc3/core_ext/math.rb +128 -0
  105. data/lib/openc3/core_ext/matrix.rb +156 -0
  106. data/lib/openc3/core_ext/objectspace.rb +36 -0
  107. data/lib/openc3/core_ext/openc3_io.rb +57 -0
  108. data/lib/openc3/core_ext/range.rb +27 -0
  109. data/lib/openc3/core_ext/socket.rb +38 -0
  110. data/lib/openc3/core_ext/string.rb +389 -0
  111. data/lib/openc3/core_ext/stringio.rb +33 -0
  112. data/lib/openc3/core_ext/time.rb +508 -0
  113. data/lib/openc3/core_ext.rb +36 -0
  114. data/lib/openc3/interfaces/interface.rb +498 -0
  115. data/lib/openc3/interfaces/linc_interface.rb +475 -0
  116. data/lib/openc3/interfaces/protocols/burst_protocol.rb +192 -0
  117. data/lib/openc3/interfaces/protocols/crc_protocol.rb +193 -0
  118. data/lib/openc3/interfaces/protocols/fixed_protocol.rb +155 -0
  119. data/lib/openc3/interfaces/protocols/ignore_packet_protocol.rb +56 -0
  120. data/lib/openc3/interfaces/protocols/length_protocol.rb +165 -0
  121. data/lib/openc3/interfaces/protocols/override_protocol.rb +60 -0
  122. data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +206 -0
  123. data/lib/openc3/interfaces/protocols/protocol.rb +82 -0
  124. data/lib/openc3/interfaces/protocols/template_protocol.rb +261 -0
  125. data/lib/openc3/interfaces/protocols/terminated_protocol.rb +93 -0
  126. data/lib/openc3/interfaces/serial_interface.rb +94 -0
  127. data/lib/openc3/interfaces/simulated_target_interface.rb +168 -0
  128. data/lib/openc3/interfaces/stream_interface.rb +81 -0
  129. data/lib/openc3/interfaces/tcpip_client_interface.rb +69 -0
  130. data/lib/openc3/interfaces/tcpip_server_interface.rb +629 -0
  131. data/lib/openc3/interfaces/udp_interface.rb +169 -0
  132. data/lib/openc3/interfaces.rb +44 -0
  133. data/lib/openc3/io/buffered_file.rb +109 -0
  134. data/lib/openc3/io/io_multiplexer.rb +80 -0
  135. data/lib/openc3/io/json_api_object.rb +208 -0
  136. data/lib/openc3/io/json_drb.rb +335 -0
  137. data/lib/openc3/io/json_drb_object.rb +114 -0
  138. data/lib/openc3/io/json_drb_rack.rb +84 -0
  139. data/lib/openc3/io/json_rpc.rb +420 -0
  140. data/lib/openc3/io/openc3_snmp.rb +58 -0
  141. data/lib/openc3/io/posix_serial_driver.rb +156 -0
  142. data/lib/openc3/io/raw_logger.rb +167 -0
  143. data/lib/openc3/io/raw_logger_pair.rb +77 -0
  144. data/lib/openc3/io/serial_driver.rb +105 -0
  145. data/lib/openc3/io/stderr.rb +43 -0
  146. data/lib/openc3/io/stdout.rb +43 -0
  147. data/lib/openc3/io/udp_sockets.rb +194 -0
  148. data/lib/openc3/io/win32_serial_driver.rb +196 -0
  149. data/lib/openc3/logs/log_writer.rb +302 -0
  150. data/lib/openc3/logs/packet_log_constants.rb +62 -0
  151. data/lib/openc3/logs/packet_log_reader.rb +345 -0
  152. data/lib/openc3/logs/packet_log_writer.rb +299 -0
  153. data/lib/openc3/logs/text_log_writer.rb +68 -0
  154. data/lib/openc3/logs.rb +25 -0
  155. data/lib/openc3/microservices/cleanup_microservice.rb +68 -0
  156. data/lib/openc3/microservices/decom_microservice.rb +136 -0
  157. data/lib/openc3/microservices/interface_microservice.rb +532 -0
  158. data/lib/openc3/microservices/log_microservice.rb +108 -0
  159. data/lib/openc3/microservices/microservice.rb +204 -0
  160. data/lib/openc3/microservices/plugin_microservice.rb +43 -0
  161. data/lib/openc3/microservices/reaction_microservice.rb +541 -0
  162. data/lib/openc3/microservices/reducer_microservice.rb +313 -0
  163. data/lib/openc3/microservices/router_microservice.rb +44 -0
  164. data/lib/openc3/microservices/text_log_microservice.rb +84 -0
  165. data/lib/openc3/microservices/timeline_microservice.rb +363 -0
  166. data/lib/openc3/microservices/trigger_group_microservice.rb +638 -0
  167. data/lib/openc3/models/activity_model.rb +319 -0
  168. data/lib/openc3/models/auth_model.rb +65 -0
  169. data/lib/openc3/models/cvt_model.rb +185 -0
  170. data/lib/openc3/models/environment_model.rb +58 -0
  171. data/lib/openc3/models/gem_model.rb +137 -0
  172. data/lib/openc3/models/info_model.rb +31 -0
  173. data/lib/openc3/models/interface_model.rb +281 -0
  174. data/lib/openc3/models/interface_status_model.rb +117 -0
  175. data/lib/openc3/models/metadata_model.rb +139 -0
  176. data/lib/openc3/models/metric_model.rb +59 -0
  177. data/lib/openc3/models/microservice_model.rb +206 -0
  178. data/lib/openc3/models/microservice_status_model.rb +74 -0
  179. data/lib/openc3/models/model.rb +204 -0
  180. data/lib/openc3/models/note_model.rb +122 -0
  181. data/lib/openc3/models/notification_model.rb +40 -0
  182. data/lib/openc3/models/ping_model.rb +35 -0
  183. data/lib/openc3/models/plugin_model.rb +292 -0
  184. data/lib/openc3/models/process_status_model.rb +76 -0
  185. data/lib/openc3/models/reaction_model.rb +322 -0
  186. data/lib/openc3/models/reducer_model.rb +65 -0
  187. data/lib/openc3/models/router_model.rb +35 -0
  188. data/lib/openc3/models/router_status_model.rb +27 -0
  189. data/lib/openc3/models/scope_model.rb +153 -0
  190. data/lib/openc3/models/settings_model.rb +55 -0
  191. data/lib/openc3/models/sorted_model.rb +167 -0
  192. data/lib/openc3/models/target_model.rb +759 -0
  193. data/lib/openc3/models/timeline_model.rb +154 -0
  194. data/lib/openc3/models/tool_config_model.rb +38 -0
  195. data/lib/openc3/models/tool_model.rb +262 -0
  196. data/lib/openc3/models/trigger_group_model.rb +186 -0
  197. data/lib/openc3/models/trigger_model.rb +330 -0
  198. data/lib/openc3/models/widget_model.rb +138 -0
  199. data/lib/openc3/operators/microservice_operator.rb +128 -0
  200. data/lib/openc3/operators/operator.rb +277 -0
  201. data/lib/openc3/packets/binary_accessor.rb +1207 -0
  202. data/lib/openc3/packets/commands.rb +373 -0
  203. data/lib/openc3/packets/json_packet.rb +134 -0
  204. data/lib/openc3/packets/limits.rb +271 -0
  205. data/lib/openc3/packets/limits_response.rb +53 -0
  206. data/lib/openc3/packets/packet.rb +1168 -0
  207. data/lib/openc3/packets/packet_config.rb +625 -0
  208. data/lib/openc3/packets/packet_item.rb +586 -0
  209. data/lib/openc3/packets/packet_item_limits.rb +162 -0
  210. data/lib/openc3/packets/parsers/format_string_parser.rb +65 -0
  211. data/lib/openc3/packets/parsers/limits_parser.rb +159 -0
  212. data/lib/openc3/packets/parsers/limits_response_parser.rb +61 -0
  213. data/lib/openc3/packets/parsers/packet_item_parser.rb +272 -0
  214. data/lib/openc3/packets/parsers/packet_parser.rb +134 -0
  215. data/lib/openc3/packets/parsers/processor_parser.rb +73 -0
  216. data/lib/openc3/packets/parsers/state_parser.rb +127 -0
  217. data/lib/openc3/packets/parsers/xtce_converter.rb +442 -0
  218. data/lib/openc3/packets/parsers/xtce_parser.rb +722 -0
  219. data/lib/openc3/packets/structure.rb +553 -0
  220. data/lib/openc3/packets/structure_item.rb +365 -0
  221. data/lib/openc3/packets/telemetry.rb +487 -0
  222. data/lib/openc3/processors/processor.rb +86 -0
  223. data/lib/openc3/processors/statistics_processor.rb +82 -0
  224. data/lib/openc3/processors/watermark_processor.rb +58 -0
  225. data/lib/openc3/processors.rb +24 -0
  226. data/lib/openc3/script/api_shared.rb +828 -0
  227. data/lib/openc3/script/calendar.rb +89 -0
  228. data/lib/openc3/script/commands.rb +227 -0
  229. data/lib/openc3/script/exceptions.rb +29 -0
  230. data/lib/openc3/script/extract.rb +161 -0
  231. data/lib/openc3/script/limits.rb +60 -0
  232. data/lib/openc3/script/script.rb +299 -0
  233. data/lib/openc3/script/script_runner.rb +238 -0
  234. data/lib/openc3/script/storage.rb +146 -0
  235. data/lib/openc3/script/suite.rb +542 -0
  236. data/lib/openc3/script/suite_results.rb +196 -0
  237. data/lib/openc3/script/suite_runner.rb +217 -0
  238. data/lib/openc3/script.rb +21 -0
  239. data/lib/openc3/streams/serial_stream.rb +167 -0
  240. data/lib/openc3/streams/stream.rb +63 -0
  241. data/lib/openc3/streams/tcpip_client_stream.rb +116 -0
  242. data/lib/openc3/streams/tcpip_socket_stream.rb +195 -0
  243. data/lib/openc3/system/system.rb +127 -0
  244. data/lib/openc3/system/system_config.rb +411 -0
  245. data/lib/openc3/system/target.rb +269 -0
  246. data/lib/openc3/system.rb +24 -0
  247. data/lib/openc3/tools/cmd_tlm_server/api.rb +20 -0
  248. data/lib/openc3/tools/cmd_tlm_server/cmd_tlm_server_config.rb +320 -0
  249. data/lib/openc3/tools/cmd_tlm_server/interface_thread.rb +294 -0
  250. data/lib/openc3/tools/table_manager/table.rb +77 -0
  251. data/lib/openc3/tools/table_manager/table_config.rb +273 -0
  252. data/lib/openc3/tools/table_manager/table_item.rb +90 -0
  253. data/lib/openc3/tools/table_manager/table_item_parser.rb +66 -0
  254. data/lib/openc3/tools/table_manager/table_manager_core.rb +333 -0
  255. data/lib/openc3/tools/table_manager/table_parser.rb +93 -0
  256. data/lib/openc3/tools/test_runner/test.rb +67 -0
  257. data/lib/openc3/top_level.rb +595 -0
  258. data/lib/openc3/topics/autonomic_topic.rb +52 -0
  259. data/lib/openc3/topics/calendar_topic.rb +44 -0
  260. data/lib/openc3/topics/command_decom_topic.rb +76 -0
  261. data/lib/openc3/topics/command_topic.rb +83 -0
  262. data/lib/openc3/topics/config_topic.rb +68 -0
  263. data/lib/openc3/topics/interface_topic.rb +73 -0
  264. data/lib/openc3/topics/limits_event_topic.rb +109 -0
  265. data/lib/openc3/topics/notifications_topic.rb +28 -0
  266. data/lib/openc3/topics/router_topic.rb +85 -0
  267. data/lib/openc3/topics/telemetry_decom_topic.rb +54 -0
  268. data/lib/openc3/topics/telemetry_topic.rb +36 -0
  269. data/lib/openc3/topics/timeline_topic.rb +45 -0
  270. data/lib/openc3/topics/topic.rb +53 -0
  271. data/lib/openc3/utilities/authentication.rb +141 -0
  272. data/lib/openc3/utilities/authorization.rb +51 -0
  273. data/lib/openc3/utilities/crc.rb +278 -0
  274. data/lib/openc3/utilities/csv.rb +153 -0
  275. data/lib/openc3/utilities/logger.rb +187 -0
  276. data/lib/openc3/utilities/message_log.rb +91 -0
  277. data/lib/openc3/utilities/metric.rb +141 -0
  278. data/lib/openc3/utilities/process_manager.rb +139 -0
  279. data/lib/openc3/utilities/quaternion.rb +257 -0
  280. data/lib/openc3/utilities/ruby_lex_utils.rb +568 -0
  281. data/lib/openc3/utilities/s3.rb +202 -0
  282. data/lib/openc3/utilities/s3_autoload.rb +9 -0
  283. data/lib/openc3/utilities/s3_file_cache.rb +274 -0
  284. data/lib/openc3/utilities/simulated_target.rb +117 -0
  285. data/lib/openc3/utilities/sleeper.rb +51 -0
  286. data/lib/openc3/utilities/store.rb +23 -0
  287. data/lib/openc3/utilities/store_autoload.rb +237 -0
  288. data/lib/openc3/utilities/zip.rb +21 -0
  289. data/lib/openc3/utilities.rb +35 -0
  290. data/lib/openc3/version.rb +14 -0
  291. data/lib/openc3/win32/excel.rb +132 -0
  292. data/lib/openc3/win32/win32.rb +402 -0
  293. data/lib/openc3/win32/win32_main.rb +333 -0
  294. data/lib/openc3.rb +49 -0
  295. data/tasks/gemfile_stats.rake +113 -0
  296. data/tasks/spec.rake +30 -0
  297. data/templates/plugin-template/README.md +15 -0
  298. data/templates/plugin-template/Rakefile +12 -0
  299. data/templates/plugin-template/plugin.gemspec +23 -0
  300. data/templates/plugin-template/plugin.txt +9 -0
  301. data/templates/plugin-template/targets/TARGET/cmd_tlm/cmd.txt +8 -0
  302. data/templates/plugin-template/targets/TARGET/cmd_tlm/tlm.txt +8 -0
  303. data/templates/plugin-template/targets/TARGET/lib/target.rb +10 -0
  304. data/templates/plugin-template/targets/TARGET/procedures/procedure.rb +3 -0
  305. data/templates/plugin-template/targets/TARGET/screens/status.txt +9 -0
  306. data/templates/plugin-template/targets/TARGET/target.txt +5 -0
  307. metadata +849 -0
@@ -0,0 +1,373 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2022 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 Affero 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
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+
16
+ # Modified by OpenC3, Inc.
17
+ # All changes Copyright 2022, OpenC3, Inc.
18
+ # All Rights Reserved
19
+
20
+ require 'openc3/packets/packet_config'
21
+
22
+ module OpenC3
23
+ # Commands uses PacketConfig to parse the command and telemetry
24
+ # configuration files. It contains all the knowledge of which command packets
25
+ # exist in the system and how to access them. This class is the API layer
26
+ # which other classes use to access commands.
27
+ #
28
+ # This should not be confused with the Api module which implements the JSON
29
+ # API that is used by tools when accessing the Server. The Api module always
30
+ # provides Ruby primatives where the PacketConfig class can return actual
31
+ # Packet or PacketItem objects. While there are some overlapping methods between
32
+ # the two, these are separate interfaces into the system.
33
+ class Commands
34
+ attr_accessor :config
35
+
36
+ LATEST_PACKET_NAME = 'LATEST'.freeze
37
+
38
+ # @param config [PacketConfig] Packet configuration to use to access the
39
+ # commands
40
+ def initialize(config)
41
+ @config = config
42
+ end
43
+
44
+ # (see PacketConfig#warnings)
45
+ def warnings
46
+ return @config.warnings
47
+ end
48
+
49
+ # @return [Array<String>] The command target names (excluding UNKNOWN)
50
+ def target_names
51
+ result = @config.commands.keys.sort
52
+ result.delete('UNKNOWN'.freeze)
53
+ return result
54
+ end
55
+
56
+ # @param target_name [String] The target name
57
+ # @return [Hash<packet_name=>Packet>] Hash of the command packets for the given
58
+ # target name keyed by the packet name
59
+ def packets(target_name)
60
+ target_packets = @config.commands[target_name.to_s.upcase]
61
+ raise "Command target '#{target_name.to_s.upcase}' does not exist" unless target_packets
62
+
63
+ target_packets
64
+ end
65
+
66
+ # @param target_name [String] The target name
67
+ # @param packet_name [String] The packet name. Must be a defined packet name
68
+ # and not 'LATEST'.
69
+ # @return [Packet] The command packet for the given target and packet name
70
+ def packet(target_name, packet_name)
71
+ target_packets = packets(target_name)
72
+ packet = target_packets[packet_name.to_s.upcase]
73
+ raise "Command packet '#{target_name.to_s.upcase} #{packet_name.to_s.upcase}' does not exist" unless packet
74
+
75
+ packet
76
+ end
77
+
78
+ # @param target_name (see #packet)
79
+ # @param packet_name (see #packet)
80
+ # @return [Array<PacketItem>] The command parameters for the given target and packet name
81
+ def params(target_name, packet_name)
82
+ return packet(target_name, packet_name).sorted_items
83
+ end
84
+
85
+ # Identifies an unknown buffer of data as a defined command and sets the
86
+ # commands's data to the given buffer. Identifying a command uses the fields
87
+ # marked as ID_PARAMETER to identify if the buffer passed represents the
88
+ # command defined. Incorrectly sized buffers are still processed but an
89
+ # error is logged.
90
+ #
91
+ # Note: Subsequent requests for the command (using packet) will return
92
+ # an uninitialized copy of the command. Thus you must use the return value
93
+ # of this method.
94
+ #
95
+ # @param (see #identify_tlm!)
96
+ # @return (see #identify_tlm!)
97
+ def identify(packet_data, target_names = nil)
98
+ identified_packet = nil
99
+
100
+ target_names = target_names() unless target_names
101
+
102
+ target_names.each do |target_name|
103
+ target_name = target_name.to_s.upcase
104
+ target_packets = nil
105
+ begin
106
+ target_packets = packets(target_name)
107
+ rescue RuntimeError
108
+ # No commands for this target
109
+ next
110
+ end
111
+
112
+ target = System.targets[target_name]
113
+ if target and target.cmd_unique_id_mode
114
+ # Iterate through the packets and see if any represent the buffer
115
+ target_packets.each do |packet_name, packet|
116
+ if packet.identify?(packet_data)
117
+ identified_packet = packet
118
+ break
119
+ end
120
+ end
121
+ else
122
+ # Do a hash lookup to quickly identify the packet
123
+ if target_packets.length > 0
124
+ packet = target_packets.first[1]
125
+ key = packet.read_id_values(packet_data)
126
+ hash = @config.cmd_id_value_hash[target_name]
127
+ identified_packet = hash[key]
128
+ identified_packet = hash['CATCHALL'.freeze] unless identified_packet
129
+ end
130
+ end
131
+
132
+ if identified_packet
133
+ identified_packet.received_count += 1
134
+ identified_packet = identified_packet.clone
135
+ identified_packet.received_time = nil
136
+ identified_packet.stored = false
137
+ identified_packet.extra = nil
138
+ identified_packet.buffer = packet_data
139
+ break
140
+ end
141
+ end
142
+
143
+ return identified_packet
144
+ end
145
+
146
+ # Returns a copy of the specified command packet with the parameters
147
+ # initialzed to the given params values.
148
+ #
149
+ # @param target_name (see #packet)
150
+ # @param packet_name (see #packet)
151
+ # @param params [Hash<param_name=>param_value>] Parameter items to override
152
+ # in the given command.
153
+ # @param range_checking [Boolean] Whether to perform range checking on the
154
+ # passed in parameters.
155
+ # @param raw [Boolean] Indicates whether or not to run conversions on command parameters
156
+ # @param check_required_params [Boolean] Indicates whether or not to check
157
+ # that the required command parameters are present
158
+ def build_cmd(target_name, packet_name, params = {}, range_checking = true, raw = false, check_required_params = true)
159
+ target_upcase = target_name.to_s.upcase
160
+ packet_upcase = packet_name.to_s.upcase
161
+
162
+ # Lookup the command and create a light weight copy
163
+ pkt = packet(target_upcase, packet_upcase)
164
+ pkt.received_count += 1
165
+ command = pkt.clone
166
+
167
+ # Restore the command's buffer to a zeroed string of defined length
168
+ # This will undo any side effects from earlier commands that may have altered the size
169
+ # of the buffer
170
+ command.buffer = "\x00" * command.defined_length
171
+
172
+ # Set time, parameters, and restore defaults
173
+ command.received_time = Time.now.sys
174
+ command.stored = false
175
+ command.extra = nil
176
+ command.given_values = params
177
+ command.restore_defaults(command.buffer(false), params.keys)
178
+ command.raw = raw
179
+
180
+ given_item_names = set_parameters(command, params, range_checking)
181
+ check_required_params(command, given_item_names) if check_required_params
182
+
183
+ return command
184
+ end
185
+
186
+ # Formatted version of a command
187
+ def format(packet, ignored_parameters = [])
188
+ if packet.raw
189
+ items = packet.read_all(:RAW)
190
+ raw = true
191
+ else
192
+ items = packet.read_all(:FORMATTED)
193
+ raw = false
194
+ end
195
+ items.delete_if { |item_name, item_value| ignored_parameters.include?(item_name) }
196
+ return build_cmd_output_string(packet.target_name, packet.packet_name, items, raw)
197
+ end
198
+
199
+ def build_cmd_output_string(target_name, cmd_name, cmd_params, raw = false)
200
+ if raw
201
+ output_string = 'cmd_raw("'
202
+ else
203
+ output_string = 'cmd("'
204
+ end
205
+ output_string << target_name + ' ' + cmd_name
206
+ if cmd_params.nil? or cmd_params.empty?
207
+ output_string << '")'
208
+ else
209
+ begin
210
+ command_items = packet(target_name, cmd_name).items
211
+ rescue
212
+ end
213
+
214
+ params = []
215
+ cmd_params.each do |key, value|
216
+ next if Packet::RESERVED_ITEM_NAMES.include?(key)
217
+
218
+ begin
219
+ item_type = command_items[key].data_type
220
+ rescue
221
+ item_type = nil
222
+ end
223
+
224
+ if value.is_a?(String)
225
+ value = value.dup
226
+ if item_type == :BLOCK or item_type == :STRING
227
+ if !value.is_printable?
228
+ value = "0x" + value.simple_formatted
229
+ else
230
+ value = value.inspect
231
+ end
232
+ else
233
+ value = value.convert_to_value.to_s
234
+ end
235
+ if value.length > 256
236
+ value = value[0..255] + "...'"
237
+ end
238
+ value.tr!('"', "'")
239
+ elsif value.is_a?(Array)
240
+ value = "[#{value.join(", ")}]"
241
+ end
242
+ params << "#{key} #{value}"
243
+ end
244
+ params = params.join(", ")
245
+ output_string << ' with ' + params + '")'
246
+ end
247
+ return output_string
248
+ end
249
+
250
+ # Returns whether the given command is hazardous. Commands are hazardous
251
+ # if they are marked hazardous overall or if any of their hardardous states
252
+ # are set. Thus any given parameter values are first applied to the command
253
+ # and then checked for hazardous states.
254
+ #
255
+ # @param command [Packet] The command to check for hazardous
256
+ def cmd_pkt_hazardous?(command)
257
+ return [true, command.hazardous_description] if command.hazardous
258
+
259
+ # Check each item for hazardous states
260
+ item_defs = command.items
261
+ item_defs.each do |item_name, item_def|
262
+ if item_def.hazardous
263
+ state_name = command.read(item_name)
264
+ # Nominally the command.read will return a valid state_name
265
+ # If it doesn't, the if check will fail and we'll fall through to
266
+ # the bottom where we return [false, nil] which means this
267
+ # command is not hazardous.
268
+ return [true, item_def.hazardous[state_name]] if item_def.hazardous[state_name]
269
+ end
270
+ end
271
+
272
+ return [false, nil]
273
+ end
274
+
275
+ # Returns whether the given command is hazardous. Commands are hazardous
276
+ # if they are marked hazardous overall or if any of their hardardous states
277
+ # are set. Thus any given parameter values are first applied to the command
278
+ # and then checked for hazardous states.
279
+ #
280
+ # @param target_name (see #packet)
281
+ # @param packet_name (see #packet)
282
+ # @param params (see #build_cmd)
283
+ def cmd_hazardous?(target_name, packet_name, params = {})
284
+ # Build a command without range checking, perform conversions, and don't
285
+ # check required parameters since we're not actually using the command.
286
+ cmd_pkt_hazardous?(build_cmd(target_name, packet_name, params, false, false, false))
287
+ end
288
+
289
+ def clear_counters
290
+ @config.commands.each do |target_name, target_packets|
291
+ target_packets.each do |packet_name, packet|
292
+ packet.received_count = 0
293
+ end
294
+ end
295
+ end
296
+
297
+ # Returns an array with a "TARGET_NAME PACKET_NAME" string for every command in the system (PACKET_NAME == command name)
298
+ def all_packet_strings(include_hidden = false, splash = nil)
299
+ strings = []
300
+ tnames = target_names()
301
+ total = tnames.length.to_f
302
+ tnames.each_with_index do |target_name, index|
303
+ if splash
304
+ splash.message = "Processing #{target_name} command"
305
+ splash.progress = index / total
306
+ end
307
+
308
+ # TODO: This wasn't being used ... should it be
309
+ # ignored_items = System.targets[target_name].ignored_items
310
+
311
+ packets(target_name).each do |command_name, packet|
312
+ # We don't audit against hidden or disabled packets/commands
313
+ next if !include_hidden and (packet.hidden || packet.disabled)
314
+
315
+ strings << "#{target_name} #{command_name}"
316
+ end
317
+ end
318
+ strings
319
+ end
320
+
321
+ def all
322
+ @config.commands
323
+ end
324
+
325
+ protected
326
+
327
+ def set_parameters(command, params, range_checking)
328
+ given_item_names = []
329
+ params.each do |item_name, value|
330
+ item_upcase = item_name.to_s.upcase
331
+ item = command.get_item(item_upcase)
332
+ range_check_value = value
333
+
334
+ # Convert from state to value if possible
335
+ if item.states and item.states[value.to_s.upcase]
336
+ range_check_value = item.states[value.to_s.upcase]
337
+ end
338
+
339
+ if range_checking
340
+ range = item.range
341
+ if range
342
+ # Perform Range Check on command parameter
343
+ if not range.include?(range_check_value)
344
+ range_check_value = "'#{range_check_value}'" if String === range_check_value
345
+ raise "Command parameter '#{command.target_name} #{command.packet_name} #{item_upcase}' = #{range_check_value} not in valid range of #{range.first} to #{range.last}"
346
+ end
347
+ end
348
+ end
349
+
350
+ # Update parameter in command
351
+ if command.raw
352
+ command.write(item_upcase, value, :RAW)
353
+ else
354
+ command.write(item_upcase, value, :CONVERTED)
355
+ end
356
+
357
+ given_item_names << item_upcase
358
+ end
359
+ given_item_names
360
+ end
361
+
362
+ def check_required_params(command, given_item_names)
363
+ # Script Runner could call this command with only some parameters
364
+ # so make sure any required parameters were actually passed in.
365
+ item_defs = command.items
366
+ item_defs.each do |item_name, item_def|
367
+ if item_def.required and not given_item_names.include? item_name
368
+ raise "Required command parameter '#{command.target_name} #{command.packet_name} #{item_name}' not given"
369
+ end
370
+ end
371
+ end
372
+ end # class Commands
373
+ end
@@ -0,0 +1,134 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2022 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 Affero 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
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+
16
+ # Modified by OpenC3, Inc.
17
+ # All changes Copyright 2022, OpenC3, Inc.
18
+ # All Rights Reserved
19
+
20
+ require 'openc3'
21
+ require 'json'
22
+ require 'openc3/config/config_parser'
23
+
24
+ module OpenC3
25
+ class JsonPacket
26
+ attr_accessor :cmd_or_tlm
27
+ attr_accessor :target_name
28
+ attr_accessor :packet_name
29
+ attr_accessor :packet_time
30
+ attr_accessor :stored
31
+ attr_accessor :json_hash
32
+
33
+ def initialize(cmd_or_tlm, target_name, packet_name, time_nsec_from_epoch, stored, json_data)
34
+ @cmd_or_tlm = cmd_or_tlm.intern
35
+ @target_name = target_name
36
+ @packet_name = packet_name
37
+ @packet_time = ::Time.from_nsec_from_epoch(time_nsec_from_epoch)
38
+ @stored = ConfigParser.handle_true_false(stored)
39
+ @json_hash = JSON.parse(json_data, :allow_nan => true, :create_additions => true)
40
+ end
41
+
42
+ # Read an item in the packet by name
43
+ #
44
+ # @param name [String] Name of the item to read - Should already by upcase
45
+ # @param value_type (see #read_item)
46
+ def read(name, value_type = :CONVERTED)
47
+ if value_type == :WITH_UNITS
48
+ value = @json_hash["#{name}__U"]
49
+ return value if value
50
+ end
51
+ if value_type == :WITH_UNITS or value_type == :FORMATTED
52
+ value = @json_hash["#{name}__F"]
53
+ return value if value
54
+
55
+ value = @json_hash["#{name}__C"]
56
+ return value.to_s if value
57
+
58
+ value = @json_hash[name]
59
+ return value.to_s if value
60
+
61
+ return nil
62
+ end
63
+ if value_type == :CONVERTED
64
+ value = @json_hash["#{name}__C"]
65
+ return value if value
66
+ end
67
+ value = @json_hash[name]
68
+ return value if value
69
+ end
70
+
71
+ def read_with_limits_state(name, value_type = :CONVERTED)
72
+ value = read(name, value_type)
73
+ limits_state = @json_hash["#{name}__L"]
74
+ limits_state.intern if limits_state
75
+ return [value, limits_state]
76
+ end
77
+
78
+ # Read all items in the packet into an array of arrays
79
+ # [[item name, item value], ...]
80
+ #
81
+ # @param value_type (see #read_item)
82
+ def read_all(value_type = :CONVERTED, names = nil)
83
+ result = {}
84
+ names = read_all_names() unless names
85
+ names.each do |name|
86
+ result[name] = read(name, value_type)
87
+ end
88
+ return result
89
+ end
90
+
91
+ # Read all items in the packet into an array of arrays
92
+ # [[item name, item value], [item limits state], ...]
93
+ #
94
+ # @param value_type (see #read_all)
95
+ def read_all_with_limits_states(value_type = :CONVERTED, names = nil)
96
+ result = {}
97
+ names = read_all_names() unless names
98
+ names.each do |name|
99
+ result[name] = read_with_limits_state(name, value_type)
100
+ end
101
+ return result
102
+ end
103
+
104
+ # Read all the names of items in the packet
105
+ # Note: This is not very efficient, ideally only call once for discovery purposes
106
+ def read_all_names
107
+ result = {}
108
+ @json_hash.each do |key, value|
109
+ result[key.split("__")[0]] = true
110
+ end
111
+ return result.keys
112
+ end
113
+
114
+ # Create a string that shows the name and value of each item in the packet
115
+ #
116
+ # @param value_type (see #read_item)
117
+ # @param indent (see Structure#formatted)
118
+ def formatted(value_type = :CONVERTED, names = nil, indent = 0)
119
+ names = read_all_names() unless names
120
+ indent_string = ' ' * indent
121
+ string = ''
122
+ names.each do |name|
123
+ value = read(name, value_type)
124
+ if String === value and value =~ File::NON_ASCII_PRINTABLE
125
+ string << "#{indent_string}#{name}:\n"
126
+ string << value.formatted(1, 16, ' ', indent + 2)
127
+ else
128
+ string << "#{indent_string}#{name}: #{value}\n"
129
+ end
130
+ end
131
+ return string
132
+ end
133
+ end
134
+ end