openc3 5.0.6

Sign up to get free protection for your applications and to get access to all the features.
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,89 @@
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/script/extract'
21
+ require 'time'
22
+
23
+ module OpenC3
24
+ module Script
25
+ include Extract
26
+
27
+ private
28
+
29
+ # Gets the current metadata
30
+ #
31
+ # @return The result of the method call.
32
+ def get_metadata(scope: $openc3_scope)
33
+ response = $api_server.request('get', "/openc3-api/metadata/latest", scope: scope)
34
+ # Non-existant just returns nil
35
+ return nil if response.nil? || response.code != 200
36
+ return JSON.parse(response.body, :allow_nan => true, :create_additions => true)
37
+ end
38
+
39
+ # Sets the metadata
40
+ #
41
+ # @param metadata [Hash<Symbol, Variable>] A hash of metadata
42
+ # @param color [String] Events color to show on Calendar tool, if nil will be blue
43
+ # @param start [Time] Metadata time value, if nil will be current time
44
+ # @return The result of the method call.
45
+ def set_metadata(metadata, color: nil, start: nil, scope: $openc3_scope)
46
+ unless metadata.is_a?(Hash)
47
+ raise "metadata must be a Hash: #{metadata} is a #{metadata.class}"
48
+ end
49
+ color = color.nil? ? '#003784' : color
50
+ data = { color: color, metadata: metadata }
51
+ data[:start] = start.iso8601 unless start.nil?
52
+ response = $api_server.request('post', '/openc3-api/metadata', data: data, json: true, scope: scope)
53
+ if response.nil? || response.code != 201
54
+ raise "Failed to set_metadata"
55
+ end
56
+ return JSON.parse(response.body, :allow_nan => true, :create_additions => true)
57
+ end
58
+
59
+ # Updates the metadata
60
+ #
61
+ # @param metadata [Hash<Symbol, Variable>] A hash of metadata
62
+ # @param color [String] Events color to show on Calendar tool, if nil will be blue
63
+ # @param start [Integer] Metadata time value as integer seconds from epoch
64
+ # @return The result of the method call.
65
+ def update_metadata(metadata, color: nil, start: nil, scope: $openc3_scope)
66
+ unless metadata.is_a?(Hash)
67
+ raise "metadata must be a Hash: #{metadata} is a #{metadata.class}"
68
+ end
69
+ color = color.nil? ? '#003784' : color
70
+ if start == nil
71
+ existing = get_metadata()
72
+ start = existing['start']
73
+ metadata = existing['metadata'].merge(metadata)
74
+ end
75
+ data = { :color => color, :metadata => metadata }
76
+ data[:start] = Time.at(start).iso8601
77
+ response = $api_server.request('put', "/openc3-api/metadata/#{start}", data: data, json: true, scope: scope)
78
+ if response.nil? || response.code != 200
79
+ raise "Failed to update_metadata"
80
+ end
81
+ return JSON.parse(response.body, :allow_nan => true, :create_additions => true)
82
+ end
83
+
84
+ # Requests the metadata from the user for a target
85
+ def input_metadata(*args, **kwargs)
86
+ raise StandardError "can only be used in Script Runner"
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,227 @@
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'
21
+ require 'openc3/script/extract'
22
+
23
+ module OpenC3
24
+ module Script
25
+ include Extract
26
+
27
+ private
28
+
29
+ # Format the command like it appears in a script
30
+ # TODO: Make this output alternative syntax if any binary data
31
+ def _cmd_string(target_name, cmd_name, cmd_params, raw, scope: $openc3_scope)
32
+ output_string = $disconnect ? 'DISCONNECT: ' : ''
33
+ if raw
34
+ output_string += 'cmd_raw("'
35
+ else
36
+ output_string += 'cmd("'
37
+ end
38
+ output_string += target_name + ' ' + cmd_name
39
+ if cmd_params.nil? or cmd_params.empty?
40
+ output_string << '")'
41
+ else
42
+ params = []
43
+ cmd_params.each do |key, value|
44
+ next if Packet::RESERVED_ITEM_NAMES.include?(key)
45
+
46
+ if value.is_a?(String)
47
+ value = value.convert_to_value.to_s
48
+ if value.length > 256
49
+ value = value[0..255] + "...'"
50
+ end
51
+ if !value.is_printable?
52
+ value = "BINARY"
53
+ end
54
+ value.tr!('"', "'")
55
+ elsif value.is_a?(Array)
56
+ value = "[#{value.join(", ")}]"
57
+ end
58
+ params << "#{key} #{value}"
59
+ end
60
+ params = params.join(", ")
61
+ output_string += ' with ' + params + '")'
62
+ end
63
+ output_string
64
+ end
65
+
66
+ # Log any warnings about disabling checks and log the command itself
67
+ # NOTE: This is a helper method and should not be called directly
68
+ def _log_cmd(target_name, cmd_name, cmd_params, raw, no_range, no_hazardous, scope: $openc3_scope)
69
+ if no_range
70
+ Logger.warn "Command #{target_name} #{cmd_name} being sent ignoring range checks"
71
+ end
72
+ if no_hazardous
73
+ Logger.warn "Command #{target_name} #{cmd_name} being sent ignoring hazardous warnings"
74
+ end
75
+ Logger.info _cmd_string(target_name, cmd_name, cmd_params, raw)
76
+ end
77
+
78
+ def _cmd_disconnect(cmd, raw, no_range, no_hazardous, *args, scope: $openc3_scope)
79
+ case args.length
80
+ when 1
81
+ target_name, cmd_name, cmd_params = extract_fields_from_cmd_text(args[0])
82
+ when 2, 3
83
+ target_name = args[0]
84
+ cmd_name = args[1]
85
+ if args.length == 2
86
+ cmd_params = {}
87
+ else
88
+ cmd_params = args[2]
89
+ end
90
+ else
91
+ # Invalid number of arguments
92
+ raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{cmd}()"
93
+ end
94
+ # Get the command and validate the parameters
95
+ command = $api_server.get_command(target_name, cmd_name, scope: scope)
96
+ cmd_params.each do |param_name, param_value|
97
+ param = command['items'].find { |item| item['name'] == param_name }
98
+ unless param
99
+ raise "Packet item '#{target_name} #{cmd_name} #{param_name}' does not exist"
100
+ end
101
+ end
102
+ _log_cmd(target_name, cmd_name, cmd_params, raw, no_range, no_hazardous)
103
+ end
104
+
105
+ # Send the command and log the results
106
+ # NOTE: This is a helper method and should not be called directly
107
+ def _cmd(cmd, cmd_no_hazardous, *args, **kw_args)
108
+ if kw_args[:scope]
109
+ scope = kw_args[:scope]
110
+ kw_args.delete(:scope)
111
+ else
112
+ scope = $openc3_scope
113
+ end
114
+ args << kw_args if kw_args.length > 0
115
+
116
+ raw = cmd.include?('raw')
117
+ no_range = cmd.include?('no_range') || cmd.include?('no_checks')
118
+ no_hazardous = cmd.include?('no_hazardous') || cmd.include?('no_checks')
119
+
120
+ if $disconnect
121
+ _cmd_disconnect(cmd, raw, no_range, no_hazardous, *args, scope: scope)
122
+ else
123
+ begin
124
+ target_name, cmd_name, cmd_params = $api_server.method_missing(cmd, *args, scope: scope)
125
+ _log_cmd(target_name, cmd_name, cmd_params, raw, no_range, no_hazardous, scope: scope)
126
+ rescue HazardousError => e
127
+ # This opens a prompt at which point they can cancel and stop the script
128
+ # or say Yes and send the command. Thus we don't care about the return value.
129
+ prompt_for_hazardous(e.target_name, e.cmd_name, e.hazardous_description)
130
+ target_name, cmd_name, cmd_params = $api_server.method_missing(cmd_no_hazardous, *args, scope: scope)
131
+ _log_cmd(target_name, cmd_name, cmd_params, raw, no_range, no_hazardous, scope: scope)
132
+ end
133
+ end
134
+ end
135
+
136
+ # Send a command to the specified target
137
+ # Usage:
138
+ # cmd(target_name, cmd_name, cmd_params = {})
139
+ # or
140
+ # cmd('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
141
+ def cmd(*args, **kw_args)
142
+ _cmd('cmd', 'cmd_no_hazardous_check', *args, **kw_args)
143
+ end
144
+
145
+ # Send a command to the specified target without range checking parameters
146
+ # Usage:
147
+ # cmd_no_range_check(target_name, cmd_name, cmd_params = {})
148
+ # or
149
+ # cmd_no_range_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
150
+ def cmd_no_range_check(*args, **kw_args)
151
+ _cmd('cmd_no_range_check', 'cmd_no_checks', *args, **kw_args)
152
+ end
153
+
154
+ # Send a command to the specified target without hazardous checks
155
+ # Usage:
156
+ # cmd_no_hazardous_check(target_name, cmd_name, cmd_params = {})
157
+ # or
158
+ # cmd_no_hazardous_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
159
+ def cmd_no_hazardous_check(*args, **kw_args)
160
+ _cmd('cmd_no_hazardous_check', nil, *args, **kw_args)
161
+ end
162
+
163
+ # Send a command to the specified target without range checking or hazardous checks
164
+ # Usage:
165
+ # cmd_no_checks(target_name, cmd_name, cmd_params = {})
166
+ # or
167
+ # cmd_no_checks('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
168
+ def cmd_no_checks(*args, **kw_args)
169
+ _cmd('cmd_no_checks', nil, *args, **kw_args)
170
+ end
171
+
172
+ # Send a command to the specified target without running conversions
173
+ # Usage:
174
+ # cmd_raw(target_name, cmd_name, cmd_params = {})
175
+ # or
176
+ # cmd_raw('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
177
+ def cmd_raw(*args, **kw_args)
178
+ _cmd('cmd_raw', 'cmd_raw_no_hazardous_check', *args, **kw_args)
179
+ end
180
+
181
+ # Send a command to the specified target without range checking parameters or running conversions
182
+ # Usage:
183
+ # cmd_raw_no_range_check(target_name, cmd_name, cmd_params = {})
184
+ # or
185
+ # cmd_raw_no_range_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
186
+ def cmd_raw_no_range_check(*args, **kw_args)
187
+ _cmd('cmd_raw_no_range_check', 'cmd_raw_no_checks', *args, **kw_args)
188
+ end
189
+
190
+ # Send a command to the specified target without hazardous checks or running conversions
191
+ # Usage:
192
+ # cmd_raw_no_hazardous_check(target_name, cmd_name, cmd_params = {})
193
+ # or
194
+ # cmd_raw_no_hazardous_check('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
195
+ def cmd_raw_no_hazardous_check(*args, **kw_args)
196
+ _cmd('cmd_raw_no_hazardous_check', nil, *args, **kw_args)
197
+ end
198
+
199
+ # Send a command to the specified target without range checking or hazardous checks or running conversions
200
+ # Usage:
201
+ # cmd_raw_no_checks(target_name, cmd_name, cmd_params = {})
202
+ # or
203
+ # cmd_raw_no_checks('target_name cmd_name with cmd_param1 value1, cmd_param2 value2')
204
+ def cmd_raw_no_checks(*args, **kw_args)
205
+ _cmd('cmd_raw_no_checks', nil, *args, **kw_args)
206
+ end
207
+
208
+ # Sends raw data through an interface from a file
209
+ def send_raw_file(interface_name, filename, scope: $openc3_scope)
210
+ data = nil
211
+ File.open(filename, 'rb') { |file| data = file.read }
212
+ $api_server.send_raw(interface_name, data, scope: scope)
213
+ end
214
+
215
+ # Returns the time the most recent command was sent
216
+ def get_cmd_time(target_name = nil, command_name = nil, scope: $openc3_scope)
217
+ results = $api_server.get_cmd_time(target_name, command_name, scope: scope)
218
+ if Array === results
219
+ if results[2] and results[3]
220
+ results[2] = Time.at(results[2], results[3]).sys
221
+ end
222
+ results.delete_at(3)
223
+ end
224
+ results
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,29 @@
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
+ module OpenC3
21
+ # Error raised by the API when a check fails
22
+ class CheckError < StandardError; end
23
+
24
+ # Error raised by the API when a script should be stopped
25
+ class StopScript < StandardError; end
26
+
27
+ # Error raised by the API when a case should be skipped
28
+ class SkipScript < StandardError; end
29
+ end
@@ -0,0 +1,161 @@
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/utilities/store'
21
+
22
+ module OpenC3
23
+ module Extract
24
+ SCANNING_REGULAR_EXPRESSION = %r{ (?:"(?:[^\\"]|\\.)*") | (?:'(?:[^\\']|\\.)*') | (?:\[(?:[^\\\[\]]|\\.)*\]) | \S+ }x # "
25
+
26
+ private
27
+
28
+ def add_cmd_parameter(keyword, value, packet, cmd_params)
29
+ quotes_removed = value.remove_quotes
30
+ if value == quotes_removed
31
+ type = nil
32
+ if packet['items']
33
+ packet['items'].each do |parameter|
34
+ if parameter['name'] == keyword
35
+ type = parameter['data_type']
36
+ break
37
+ end
38
+ end
39
+ end
40
+ if (type == 'STRING' or type == 'BLOCK') and value.upcase.start_with?("0X")
41
+ cmd_params[keyword] = value.hex_to_byte_string
42
+ else
43
+ cmd_params[keyword] = value.convert_to_value
44
+ end
45
+ else
46
+ cmd_params[keyword] = quotes_removed
47
+ end
48
+ end
49
+
50
+ def extract_fields_from_cmd_text(text, scope: $openc3_scope)
51
+ split_string = text.split(/\s+with\s+/i, 2)
52
+ raise "ERROR: text must not be empty" if split_string.length == 0
53
+ raise "ERROR: 'with' must be followed by parameters : #{text}" if (split_string.length == 1 and text =~ /\s*with\s*/i) or (split_string.length == 2 and split_string[1].empty?)
54
+
55
+ # Extract target_name and cmd_name
56
+ first_half = split_string[0].split
57
+ raise "ERROR: Both Target Name and Command Name must be given : #{text}" if first_half.length < 2
58
+ raise "ERROR: Only Target Name and Command Name must be given before 'with' : #{text}" if first_half.length > 2
59
+
60
+ target_name = first_half[0]
61
+ cmd_name = first_half[1]
62
+ cmd_params = {}
63
+
64
+ begin
65
+ # Returns the packet JSON representation
66
+ packet = TargetModel.packet(target_name, cmd_name, type: :CMD, scope: scope)
67
+ rescue
68
+ packet = {}
69
+ end
70
+
71
+ if split_string.length == 2
72
+ # Extract Command Parameters
73
+ second_half = split_string[1].scan(SCANNING_REGULAR_EXPRESSION)
74
+ keyword = nil
75
+ value = nil
76
+ comma = nil
77
+ second_half.each do |item|
78
+ unless keyword
79
+ keyword = item
80
+ next
81
+ end
82
+ unless value
83
+ if item[-1..-1] == ','
84
+ value = item[0..-2]
85
+ comma = true
86
+ else
87
+ value = item
88
+ next
89
+ end
90
+ end
91
+ unless comma
92
+ raise "Missing comma in command parameters: #{text}" if item != ','
93
+ end
94
+ add_cmd_parameter(keyword, value, packet, cmd_params)
95
+ keyword = nil
96
+ value = nil
97
+ comma = nil
98
+ end
99
+ if keyword
100
+ if value
101
+ add_cmd_parameter(keyword, value, packet, cmd_params)
102
+ else
103
+ raise "Missing value for last command parameter: #{text}"
104
+ end
105
+ end
106
+ end
107
+
108
+ return [target_name, cmd_name, cmd_params]
109
+ end
110
+
111
+ def extract_fields_from_tlm_text(text)
112
+ split_string = text.split
113
+ raise "ERROR: Telemetry Item must be specified as 'TargetName PacketName ItemName' : #{text}" if split_string.length != 3
114
+
115
+ target_name = split_string[0]
116
+ packet_name = split_string[1]
117
+ item_name = split_string[2]
118
+ return [target_name, packet_name, item_name]
119
+ end
120
+
121
+ def extract_fields_from_set_tlm_text(text)
122
+ error_msg = "ERROR: Set Telemetry Item must be specified as 'TargetName PacketName ItemName = Value' : #{text}"
123
+ # We have to handle these cases:
124
+ # set_tlm("TGT PKT ITEM='new item'")
125
+ # set_tlm("TGT PKT ITEM = 'new item'")
126
+ # set_tlm("TGT PKT ITEM= 'new item'")
127
+ # set_tlm("TGT PKT ITEM ='new item'")
128
+ split_string = text.split('=')
129
+ raise error_msg if split_string.length < 2 || split_string[1].strip.empty?
130
+
131
+ split_string = split_string[0].strip.split << split_string[1..-1].join('=').strip
132
+ raise error_msg if split_string.length != 4 # Ensure tgt,pkt,item,value
133
+
134
+ target_name = split_string[0]
135
+ packet_name = split_string[1]
136
+ item_name = split_string[2]
137
+ value = split_string[3].strip.convert_to_value
138
+ value = value.remove_quotes if String === value
139
+ return [target_name, packet_name, item_name, value]
140
+ end
141
+
142
+ def extract_fields_from_check_text(text)
143
+ split_string = text.split
144
+ raise "ERROR: Check improperly specified: #{text}" if split_string.length < 3
145
+
146
+ target_name = split_string[0]
147
+ packet_name = split_string[1]
148
+ item_name = split_string[2]
149
+ comparison_to_eval = nil
150
+ return [target_name, packet_name, item_name, comparison_to_eval] if split_string.length == 3
151
+ raise "ERROR: Check improperly specified: #{text}" if split_string.length < 4
152
+
153
+ split_string = text.split(/ /) # Split on regex spaces to preserve spaces in comparison
154
+ index = split_string.rindex(item_name)
155
+ comparison_to_eval = split_string[(index + 1)..(split_string.length - 1)].join(" ")
156
+ raise "ERROR: Use '==' instead of '=': #{text}" if split_string[3] == '='
157
+
158
+ return [target_name, packet_name, item_name, comparison_to_eval]
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,60 @@
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
+ module OpenC3
21
+ module Script
22
+ private
23
+
24
+ # Define all the modification methods such that we can disconnect them
25
+ %i(enable_limits disable_limits set_limits enable_limits_group disable_limits_group set_limits_set).each do |method_name|
26
+ define_method(method_name) do |*args, **kw_args, &block|
27
+ kw_args[:scope] = $openc3_scope unless kw_args[:scope]
28
+ if $disconnect
29
+ Logger.info "DISCONNECT: #{method_name}(#{args}) ignored"
30
+ else
31
+ $api_server.public_send(method_name, *args, **kw_args, &block)
32
+ end
33
+ end
34
+ end
35
+
36
+ def get_limits_events(offset = nil, count: 100, scope: $openc3_scope)
37
+ result = $api_server.get_limits_events(offset, count: count, scope: scope)
38
+ if result
39
+ result[0] = result[0].to_s.intern
40
+ if result[0] == :LIMITS_CHANGE
41
+ result[1][3] = result[1][3].to_s.intern if result[1][3]
42
+ result[1][4] = result[1][4].to_s.intern if result[1][4]
43
+ if result[1][5] and result[1][6]
44
+ result[1][5] = Time.at(result[1][5], result[1][6]).sys
45
+ result[1].delete_at(6)
46
+ end
47
+ elsif result[0] == :LIMITS_SETTINGS
48
+ result[1][3] = result[1][3].to_s.intern if result[1][3]
49
+ elsif result[0] == :STALE_PACKET
50
+ # Nothing extra to do
51
+ elsif result[0] == :STALE_PACKET_RCVD
52
+ # Nothing extra to do
53
+ else
54
+ result[1] = result[1].to_s.intern
55
+ end
56
+ end
57
+ result
58
+ end
59
+ end
60
+ end