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.
- checksums.yaml +7 -0
- data/Gemfile +18 -0
- data/Guardfile +35 -0
- data/LICENSE.txt +727 -0
- data/README.md +37 -0
- data/Rakefile +131 -0
- data/bin/cstol_converter +1178 -0
- data/bin/openc3cli +531 -0
- data/bin/rubysloc +139 -0
- data/data/config/_array_params.yaml +23 -0
- data/data/config/_id_items.yaml +24 -0
- data/data/config/_id_params.yaml +58 -0
- data/data/config/_interfaces.yaml +214 -0
- data/data/config/_interfaces.yaml.err +1017 -0
- data/data/config/_items.yaml +20 -0
- data/data/config/_params.yaml +60 -0
- data/data/config/cmd_tlm_server.yaml +136 -0
- data/data/config/command.yaml +44 -0
- data/data/config/command_modifiers.yaml +160 -0
- data/data/config/command_telemetry.yaml +3 -0
- data/data/config/interface_modifiers.yaml +104 -0
- data/data/config/item_modifiers.yaml +221 -0
- data/data/config/microservice.yaml +78 -0
- data/data/config/param_item_modifiers.yaml +52 -0
- data/data/config/parameter_modifiers.yaml +200 -0
- data/data/config/plugins.yaml +80 -0
- data/data/config/protocols.yaml +290 -0
- data/data/config/screen.yaml +147 -0
- data/data/config/table_manager.yaml +89 -0
- data/data/config/table_parameter_modifiers.yaml +9 -0
- data/data/config/target.yaml +142 -0
- data/data/config/target_config.yaml +94 -0
- data/data/config/telemetry.yaml +87 -0
- data/data/config/telemetry_modifiers.yaml +159 -0
- data/data/config/tool.yaml +63 -0
- data/data/config/unknown.yaml +3 -0
- data/data/config/widgets.yaml +1505 -0
- data/ext/mkrf_conf.rb +49 -0
- data/ext/openc3/ext/array/array.c +122 -0
- data/ext/openc3/ext/array/extconf.rb +13 -0
- data/ext/openc3/ext/buffered_file/buffered_file.c +198 -0
- data/ext/openc3/ext/buffered_file/extconf.rb +13 -0
- data/ext/openc3/ext/config_parser/config_parser.c +280 -0
- data/ext/openc3/ext/config_parser/extconf.rb +13 -0
- data/ext/openc3/ext/crc/crc.c +351 -0
- data/ext/openc3/ext/crc/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/extconf.rb +13 -0
- data/ext/openc3/ext/openc3_io/openc3_io.c +158 -0
- data/ext/openc3/ext/packet/extconf.rb +13 -0
- data/ext/openc3/ext/packet/packet.c +318 -0
- data/ext/openc3/ext/platform/extconf.rb +13 -0
- data/ext/openc3/ext/platform/platform.c +134 -0
- data/ext/openc3/ext/polynomial_conversion/extconf.rb +13 -0
- data/ext/openc3/ext/polynomial_conversion/polynomial_conversion.c +79 -0
- data/ext/openc3/ext/string/extconf.rb +13 -0
- data/ext/openc3/ext/string/string.c +63 -0
- data/ext/openc3/ext/structure/structure.c +1719 -0
- data/ext/openc3/ext/tabbed_plots_config/extconf.rb +13 -0
- data/ext/openc3/ext/tabbed_plots_config/tabbed_plots_config.c +62 -0
- data/ext/openc3/ext/telemetry/extconf.rb +13 -0
- data/ext/openc3/ext/telemetry/telemetry.c +336 -0
- data/lib/cosmos.rb +20 -0
- data/lib/cosmosc2.rb +20 -0
- data/lib/openc3/api/api.rb +39 -0
- data/lib/openc3/api/authorized_api.rb +30 -0
- data/lib/openc3/api/cmd_api.rb +451 -0
- data/lib/openc3/api/config_api.rb +58 -0
- data/lib/openc3/api/interface_api.rb +117 -0
- data/lib/openc3/api/limits_api.rb +375 -0
- data/lib/openc3/api/router_api.rb +117 -0
- data/lib/openc3/api/settings_api.rb +70 -0
- data/lib/openc3/api/target_api.rb +78 -0
- data/lib/openc3/api/tlm_api.rb +455 -0
- data/lib/openc3/bridge/bridge.rb +54 -0
- data/lib/openc3/bridge/bridge_config.rb +167 -0
- data/lib/openc3/bridge/bridge_interface_thread.rb +42 -0
- data/lib/openc3/bridge/bridge_router_thread.rb +42 -0
- data/lib/openc3/ccsds/ccsds_packet.rb +68 -0
- data/lib/openc3/ccsds/ccsds_parser.rb +148 -0
- data/lib/openc3/config/config_parser.rb +549 -0
- data/lib/openc3/config/meta_config_parser.rb +74 -0
- data/lib/openc3/conversions/conversion.rb +70 -0
- data/lib/openc3/conversions/generic_conversion.rb +83 -0
- data/lib/openc3/conversions/packet_time_formatted_conversion.rb +43 -0
- data/lib/openc3/conversions/packet_time_seconds_conversion.rb +43 -0
- data/lib/openc3/conversions/polynomial_conversion.rb +87 -0
- data/lib/openc3/conversions/processor_conversion.rb +70 -0
- data/lib/openc3/conversions/received_count_conversion.rb +38 -0
- data/lib/openc3/conversions/received_time_formatted_conversion.rb +42 -0
- data/lib/openc3/conversions/received_time_seconds_conversion.rb +42 -0
- data/lib/openc3/conversions/segmented_polynomial_conversion.rb +171 -0
- data/lib/openc3/conversions/unix_time_conversion.rb +68 -0
- data/lib/openc3/conversions/unix_time_formatted_conversion.rb +49 -0
- data/lib/openc3/conversions/unix_time_seconds_conversion.rb +49 -0
- data/lib/openc3/conversions.rb +34 -0
- data/lib/openc3/core_ext/array.rb +416 -0
- data/lib/openc3/core_ext/binding.rb +29 -0
- data/lib/openc3/core_ext/class.rb +72 -0
- data/lib/openc3/core_ext/exception.rb +61 -0
- data/lib/openc3/core_ext/file.rb +83 -0
- data/lib/openc3/core_ext/hash.rb +37 -0
- data/lib/openc3/core_ext/io.rb +134 -0
- data/lib/openc3/core_ext/kernel.rb +42 -0
- data/lib/openc3/core_ext/math.rb +128 -0
- data/lib/openc3/core_ext/matrix.rb +156 -0
- data/lib/openc3/core_ext/objectspace.rb +36 -0
- data/lib/openc3/core_ext/openc3_io.rb +57 -0
- data/lib/openc3/core_ext/range.rb +27 -0
- data/lib/openc3/core_ext/socket.rb +38 -0
- data/lib/openc3/core_ext/string.rb +389 -0
- data/lib/openc3/core_ext/stringio.rb +33 -0
- data/lib/openc3/core_ext/time.rb +508 -0
- data/lib/openc3/core_ext.rb +36 -0
- data/lib/openc3/interfaces/interface.rb +498 -0
- data/lib/openc3/interfaces/linc_interface.rb +475 -0
- data/lib/openc3/interfaces/protocols/burst_protocol.rb +192 -0
- data/lib/openc3/interfaces/protocols/crc_protocol.rb +193 -0
- data/lib/openc3/interfaces/protocols/fixed_protocol.rb +155 -0
- data/lib/openc3/interfaces/protocols/ignore_packet_protocol.rb +56 -0
- data/lib/openc3/interfaces/protocols/length_protocol.rb +165 -0
- data/lib/openc3/interfaces/protocols/override_protocol.rb +60 -0
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +206 -0
- data/lib/openc3/interfaces/protocols/protocol.rb +82 -0
- data/lib/openc3/interfaces/protocols/template_protocol.rb +261 -0
- data/lib/openc3/interfaces/protocols/terminated_protocol.rb +93 -0
- data/lib/openc3/interfaces/serial_interface.rb +94 -0
- data/lib/openc3/interfaces/simulated_target_interface.rb +168 -0
- data/lib/openc3/interfaces/stream_interface.rb +81 -0
- data/lib/openc3/interfaces/tcpip_client_interface.rb +69 -0
- data/lib/openc3/interfaces/tcpip_server_interface.rb +629 -0
- data/lib/openc3/interfaces/udp_interface.rb +169 -0
- data/lib/openc3/interfaces.rb +44 -0
- data/lib/openc3/io/buffered_file.rb +109 -0
- data/lib/openc3/io/io_multiplexer.rb +80 -0
- data/lib/openc3/io/json_api_object.rb +208 -0
- data/lib/openc3/io/json_drb.rb +335 -0
- data/lib/openc3/io/json_drb_object.rb +114 -0
- data/lib/openc3/io/json_drb_rack.rb +84 -0
- data/lib/openc3/io/json_rpc.rb +420 -0
- data/lib/openc3/io/openc3_snmp.rb +58 -0
- data/lib/openc3/io/posix_serial_driver.rb +156 -0
- data/lib/openc3/io/raw_logger.rb +167 -0
- data/lib/openc3/io/raw_logger_pair.rb +77 -0
- data/lib/openc3/io/serial_driver.rb +105 -0
- data/lib/openc3/io/stderr.rb +43 -0
- data/lib/openc3/io/stdout.rb +43 -0
- data/lib/openc3/io/udp_sockets.rb +194 -0
- data/lib/openc3/io/win32_serial_driver.rb +196 -0
- data/lib/openc3/logs/log_writer.rb +302 -0
- data/lib/openc3/logs/packet_log_constants.rb +62 -0
- data/lib/openc3/logs/packet_log_reader.rb +345 -0
- data/lib/openc3/logs/packet_log_writer.rb +299 -0
- data/lib/openc3/logs/text_log_writer.rb +68 -0
- data/lib/openc3/logs.rb +25 -0
- data/lib/openc3/microservices/cleanup_microservice.rb +68 -0
- data/lib/openc3/microservices/decom_microservice.rb +136 -0
- data/lib/openc3/microservices/interface_microservice.rb +532 -0
- data/lib/openc3/microservices/log_microservice.rb +108 -0
- data/lib/openc3/microservices/microservice.rb +204 -0
- data/lib/openc3/microservices/plugin_microservice.rb +43 -0
- data/lib/openc3/microservices/reaction_microservice.rb +541 -0
- data/lib/openc3/microservices/reducer_microservice.rb +313 -0
- data/lib/openc3/microservices/router_microservice.rb +44 -0
- data/lib/openc3/microservices/text_log_microservice.rb +84 -0
- data/lib/openc3/microservices/timeline_microservice.rb +363 -0
- data/lib/openc3/microservices/trigger_group_microservice.rb +638 -0
- data/lib/openc3/models/activity_model.rb +319 -0
- data/lib/openc3/models/auth_model.rb +65 -0
- data/lib/openc3/models/cvt_model.rb +185 -0
- data/lib/openc3/models/environment_model.rb +58 -0
- data/lib/openc3/models/gem_model.rb +137 -0
- data/lib/openc3/models/info_model.rb +31 -0
- data/lib/openc3/models/interface_model.rb +281 -0
- data/lib/openc3/models/interface_status_model.rb +117 -0
- data/lib/openc3/models/metadata_model.rb +139 -0
- data/lib/openc3/models/metric_model.rb +59 -0
- data/lib/openc3/models/microservice_model.rb +206 -0
- data/lib/openc3/models/microservice_status_model.rb +74 -0
- data/lib/openc3/models/model.rb +204 -0
- data/lib/openc3/models/note_model.rb +122 -0
- data/lib/openc3/models/notification_model.rb +40 -0
- data/lib/openc3/models/ping_model.rb +35 -0
- data/lib/openc3/models/plugin_model.rb +292 -0
- data/lib/openc3/models/process_status_model.rb +76 -0
- data/lib/openc3/models/reaction_model.rb +322 -0
- data/lib/openc3/models/reducer_model.rb +65 -0
- data/lib/openc3/models/router_model.rb +35 -0
- data/lib/openc3/models/router_status_model.rb +27 -0
- data/lib/openc3/models/scope_model.rb +153 -0
- data/lib/openc3/models/settings_model.rb +55 -0
- data/lib/openc3/models/sorted_model.rb +167 -0
- data/lib/openc3/models/target_model.rb +759 -0
- data/lib/openc3/models/timeline_model.rb +154 -0
- data/lib/openc3/models/tool_config_model.rb +38 -0
- data/lib/openc3/models/tool_model.rb +262 -0
- data/lib/openc3/models/trigger_group_model.rb +186 -0
- data/lib/openc3/models/trigger_model.rb +330 -0
- data/lib/openc3/models/widget_model.rb +138 -0
- data/lib/openc3/operators/microservice_operator.rb +128 -0
- data/lib/openc3/operators/operator.rb +277 -0
- data/lib/openc3/packets/binary_accessor.rb +1207 -0
- data/lib/openc3/packets/commands.rb +373 -0
- data/lib/openc3/packets/json_packet.rb +134 -0
- data/lib/openc3/packets/limits.rb +271 -0
- data/lib/openc3/packets/limits_response.rb +53 -0
- data/lib/openc3/packets/packet.rb +1168 -0
- data/lib/openc3/packets/packet_config.rb +625 -0
- data/lib/openc3/packets/packet_item.rb +586 -0
- data/lib/openc3/packets/packet_item_limits.rb +162 -0
- data/lib/openc3/packets/parsers/format_string_parser.rb +65 -0
- data/lib/openc3/packets/parsers/limits_parser.rb +159 -0
- data/lib/openc3/packets/parsers/limits_response_parser.rb +61 -0
- data/lib/openc3/packets/parsers/packet_item_parser.rb +272 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +134 -0
- data/lib/openc3/packets/parsers/processor_parser.rb +73 -0
- data/lib/openc3/packets/parsers/state_parser.rb +127 -0
- data/lib/openc3/packets/parsers/xtce_converter.rb +442 -0
- data/lib/openc3/packets/parsers/xtce_parser.rb +722 -0
- data/lib/openc3/packets/structure.rb +553 -0
- data/lib/openc3/packets/structure_item.rb +365 -0
- data/lib/openc3/packets/telemetry.rb +487 -0
- data/lib/openc3/processors/processor.rb +86 -0
- data/lib/openc3/processors/statistics_processor.rb +82 -0
- data/lib/openc3/processors/watermark_processor.rb +58 -0
- data/lib/openc3/processors.rb +24 -0
- data/lib/openc3/script/api_shared.rb +828 -0
- data/lib/openc3/script/calendar.rb +89 -0
- data/lib/openc3/script/commands.rb +227 -0
- data/lib/openc3/script/exceptions.rb +29 -0
- data/lib/openc3/script/extract.rb +161 -0
- data/lib/openc3/script/limits.rb +60 -0
- data/lib/openc3/script/script.rb +299 -0
- data/lib/openc3/script/script_runner.rb +238 -0
- data/lib/openc3/script/storage.rb +146 -0
- data/lib/openc3/script/suite.rb +542 -0
- data/lib/openc3/script/suite_results.rb +196 -0
- data/lib/openc3/script/suite_runner.rb +217 -0
- data/lib/openc3/script.rb +21 -0
- data/lib/openc3/streams/serial_stream.rb +167 -0
- data/lib/openc3/streams/stream.rb +63 -0
- data/lib/openc3/streams/tcpip_client_stream.rb +116 -0
- data/lib/openc3/streams/tcpip_socket_stream.rb +195 -0
- data/lib/openc3/system/system.rb +127 -0
- data/lib/openc3/system/system_config.rb +411 -0
- data/lib/openc3/system/target.rb +269 -0
- data/lib/openc3/system.rb +24 -0
- data/lib/openc3/tools/cmd_tlm_server/api.rb +20 -0
- data/lib/openc3/tools/cmd_tlm_server/cmd_tlm_server_config.rb +320 -0
- data/lib/openc3/tools/cmd_tlm_server/interface_thread.rb +294 -0
- data/lib/openc3/tools/table_manager/table.rb +77 -0
- data/lib/openc3/tools/table_manager/table_config.rb +273 -0
- data/lib/openc3/tools/table_manager/table_item.rb +90 -0
- data/lib/openc3/tools/table_manager/table_item_parser.rb +66 -0
- data/lib/openc3/tools/table_manager/table_manager_core.rb +333 -0
- data/lib/openc3/tools/table_manager/table_parser.rb +93 -0
- data/lib/openc3/tools/test_runner/test.rb +67 -0
- data/lib/openc3/top_level.rb +595 -0
- data/lib/openc3/topics/autonomic_topic.rb +52 -0
- data/lib/openc3/topics/calendar_topic.rb +44 -0
- data/lib/openc3/topics/command_decom_topic.rb +76 -0
- data/lib/openc3/topics/command_topic.rb +83 -0
- data/lib/openc3/topics/config_topic.rb +68 -0
- data/lib/openc3/topics/interface_topic.rb +73 -0
- data/lib/openc3/topics/limits_event_topic.rb +109 -0
- data/lib/openc3/topics/notifications_topic.rb +28 -0
- data/lib/openc3/topics/router_topic.rb +85 -0
- data/lib/openc3/topics/telemetry_decom_topic.rb +54 -0
- data/lib/openc3/topics/telemetry_topic.rb +36 -0
- data/lib/openc3/topics/timeline_topic.rb +45 -0
- data/lib/openc3/topics/topic.rb +53 -0
- data/lib/openc3/utilities/authentication.rb +141 -0
- data/lib/openc3/utilities/authorization.rb +51 -0
- data/lib/openc3/utilities/crc.rb +278 -0
- data/lib/openc3/utilities/csv.rb +153 -0
- data/lib/openc3/utilities/logger.rb +187 -0
- data/lib/openc3/utilities/message_log.rb +91 -0
- data/lib/openc3/utilities/metric.rb +141 -0
- data/lib/openc3/utilities/process_manager.rb +139 -0
- data/lib/openc3/utilities/quaternion.rb +257 -0
- data/lib/openc3/utilities/ruby_lex_utils.rb +568 -0
- data/lib/openc3/utilities/s3.rb +202 -0
- data/lib/openc3/utilities/s3_autoload.rb +9 -0
- data/lib/openc3/utilities/s3_file_cache.rb +274 -0
- data/lib/openc3/utilities/simulated_target.rb +117 -0
- data/lib/openc3/utilities/sleeper.rb +51 -0
- data/lib/openc3/utilities/store.rb +23 -0
- data/lib/openc3/utilities/store_autoload.rb +237 -0
- data/lib/openc3/utilities/zip.rb +21 -0
- data/lib/openc3/utilities.rb +35 -0
- data/lib/openc3/version.rb +14 -0
- data/lib/openc3/win32/excel.rb +132 -0
- data/lib/openc3/win32/win32.rb +402 -0
- data/lib/openc3/win32/win32_main.rb +333 -0
- data/lib/openc3.rb +49 -0
- data/tasks/gemfile_stats.rake +113 -0
- data/tasks/spec.rake +30 -0
- data/templates/plugin-template/README.md +15 -0
- data/templates/plugin-template/Rakefile +12 -0
- data/templates/plugin-template/plugin.gemspec +23 -0
- data/templates/plugin-template/plugin.txt +9 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/cmd.txt +8 -0
- data/templates/plugin-template/targets/TARGET/cmd_tlm/tlm.txt +8 -0
- data/templates/plugin-template/targets/TARGET/lib/target.rb +10 -0
- data/templates/plugin-template/targets/TARGET/procedures/procedure.rb +3 -0
- data/templates/plugin-template/targets/TARGET/screens/status.txt +9 -0
- data/templates/plugin-template/targets/TARGET/target.txt +5 -0
- metadata +849 -0
|
@@ -0,0 +1,828 @@
|
|
|
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
|
+
|
|
22
|
+
module OpenC3
|
|
23
|
+
module ApiShared
|
|
24
|
+
include Extract
|
|
25
|
+
|
|
26
|
+
DEFAULT_TLM_POLLING_RATE = 0.25
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
# Check the converted value of a telmetry item against a condition.
|
|
31
|
+
# Always print the value of the telemetry item to STDOUT.
|
|
32
|
+
# If the condition check fails, raise an error.
|
|
33
|
+
#
|
|
34
|
+
# Supports two signatures:
|
|
35
|
+
# check(target_name, packet_name, item_name, comparison_to_eval)
|
|
36
|
+
# check('target_name packet_name item_name > 1')
|
|
37
|
+
#
|
|
38
|
+
# @param args [String|Array<String>] See the description for calling style
|
|
39
|
+
# @param type [Symbol] Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS
|
|
40
|
+
def check(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token)
|
|
41
|
+
_check(*args, scope: scope) { |tgt, pkt, item| tlm(tgt, pkt, item, type: type, scope: scope, token: token) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @deprecated Use check with type: :RAW
|
|
45
|
+
def check_raw(*args, scope: $openc3_scope, token: $openc3_token)
|
|
46
|
+
check(*args, type: :RAW, scope: scope, token: token)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @deprecated Use check with type: :FORMATTED
|
|
50
|
+
def check_formatted(*args, scope: $openc3_scope, token: $openc3_token)
|
|
51
|
+
check(*args, type: :FORMATTED, scope: scope, token: token)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @deprecated Use check with type: :WITH_UNITS
|
|
55
|
+
def check_with_units(*args, scope: $openc3_scope, token: $openc3_token)
|
|
56
|
+
check(*args, type: :WITH_UNITS, scope: scope, token: token)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Executes the passed method and expects an exception to be raised.
|
|
60
|
+
# Raises a CheckError if an Exception is not raised.
|
|
61
|
+
# Usage:
|
|
62
|
+
# check_exception(method_name, method_params}
|
|
63
|
+
def check_exception(method_name, *args, **kwargs)
|
|
64
|
+
orig_kwargs = kwargs.clone
|
|
65
|
+
kwargs[:scope] = $openc3_scope unless kwargs[:scope]
|
|
66
|
+
kwargs[:token] = $openc3_token unless kwargs[:token]
|
|
67
|
+
send(method_name.intern, *args, **kwargs)
|
|
68
|
+
method = "#{method_name}(#{args.join(", ")}"
|
|
69
|
+
method += ", #{orig_kwargs}" unless orig_kwargs.empty?
|
|
70
|
+
method += ")"
|
|
71
|
+
rescue Exception => error
|
|
72
|
+
Logger.info "CHECK: #{method} raised #{error.class}:#{error.message}"
|
|
73
|
+
else
|
|
74
|
+
raise(CheckError, "#{method} should have raised an exception but did not.")
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Check the converted value of a telmetry item against an expected value with a tolerance.
|
|
78
|
+
# Always print the value of the telemetry item to STDOUT. If the condition check fails, raise an error.
|
|
79
|
+
#
|
|
80
|
+
# Supports two signatures:
|
|
81
|
+
# check_tolerance(target_name, packet_name, item_name, expected_value, tolerance)
|
|
82
|
+
# check_tolerance('target_name packet_name item_name', expected_value, tolerance)
|
|
83
|
+
#
|
|
84
|
+
# @param args [String|Array<String>] See the description for calling style
|
|
85
|
+
# @param type [Symbol] Telemetry type, :RAW or :CONVERTED (default)
|
|
86
|
+
def check_tolerance(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token)
|
|
87
|
+
raise "Invalid type '#{type}' for check_tolerance" unless %i(RAW CONVERTED).include?(type)
|
|
88
|
+
|
|
89
|
+
target_name, packet_name, item_name, expected_value, tolerance =
|
|
90
|
+
_check_tolerance_process_args(args, scope: scope, token: token)
|
|
91
|
+
value = tlm(target_name, packet_name, item_name, type: type, scope: scope, token: token)
|
|
92
|
+
if value.is_a?(Array)
|
|
93
|
+
expected_value, tolerance = array_tolerance_process_args(value.size, expected_value, tolerance, 'check_tolerance', scope: scope, token: token)
|
|
94
|
+
|
|
95
|
+
message = ""
|
|
96
|
+
all_checks_ok = true
|
|
97
|
+
value.size.times do |i|
|
|
98
|
+
range = (expected_value[i] - tolerance[i]..expected_value[i] + tolerance[i])
|
|
99
|
+
check_str = "CHECK: #{_upcase(target_name, packet_name, item_name)}[#{i}]"
|
|
100
|
+
range_str = "range #{range.first} to #{range.last} with value == #{value[i]}"
|
|
101
|
+
if range.include?(value[i])
|
|
102
|
+
message << "#{check_str} was within #{range_str}\n"
|
|
103
|
+
else
|
|
104
|
+
message << "#{check_str} failed to be within #{range_str}\n"
|
|
105
|
+
all_checks_ok = false
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
if all_checks_ok
|
|
110
|
+
Logger.info message
|
|
111
|
+
else
|
|
112
|
+
if $disconnect
|
|
113
|
+
Logger.error message
|
|
114
|
+
else
|
|
115
|
+
raise CheckError, message
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
else
|
|
119
|
+
range = (expected_value - tolerance)..(expected_value + tolerance)
|
|
120
|
+
check_str = "CHECK: #{_upcase(target_name, packet_name, item_name)}"
|
|
121
|
+
range_str = "range #{range.first} to #{range.last} with value == #{value}"
|
|
122
|
+
if range.include?(value)
|
|
123
|
+
Logger.info "#{check_str} was within #{range_str}"
|
|
124
|
+
else
|
|
125
|
+
message = "#{check_str} failed to be within #{range_str}"
|
|
126
|
+
if $disconnect
|
|
127
|
+
Logger.error message
|
|
128
|
+
else
|
|
129
|
+
raise CheckError, message
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# @deprecated Use check_tolerance with type: :RAW
|
|
136
|
+
def check_tolerance_raw(*args, scope: $openc3_scope, token: $openc3_token)
|
|
137
|
+
check_tolerance(*args, type: :RAW, scope: scope, token: token)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Check to see if an expression is true without waiting. If the expression
|
|
141
|
+
# is not true, the script will pause.
|
|
142
|
+
def check_expression(exp_to_eval, context = nil, scope: $openc3_scope, token: $openc3_token)
|
|
143
|
+
success = openc3_script_wait_implementation_expression(exp_to_eval, 0, DEFAULT_TLM_POLLING_RATE, context, scope: scope, token: token)
|
|
144
|
+
if success
|
|
145
|
+
Logger.info "CHECK: #{exp_to_eval} is TRUE"
|
|
146
|
+
else
|
|
147
|
+
message = "CHECK: #{exp_to_eval} is FALSE"
|
|
148
|
+
if $disconnect
|
|
149
|
+
Logger.error message
|
|
150
|
+
else
|
|
151
|
+
raise CheckError, message
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# Wait on an expression to be true. On a timeout, the script will continue.
|
|
157
|
+
#
|
|
158
|
+
# Supports multiple signatures:
|
|
159
|
+
# wait(time)
|
|
160
|
+
# wait('target_name packet_name item_name > 1', timeout, polling_rate)
|
|
161
|
+
# wait('target_name', 'packet_name', 'item_name', comparison_to_eval, timeout, polling_rate)
|
|
162
|
+
#
|
|
163
|
+
# @param args [String|Array<String>] See the description for calling style
|
|
164
|
+
# @param type [Symbol] Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS
|
|
165
|
+
def wait(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token)
|
|
166
|
+
time = nil
|
|
167
|
+
|
|
168
|
+
case args.length
|
|
169
|
+
# wait() # indefinitely until they click Go
|
|
170
|
+
when 0
|
|
171
|
+
start_time = Time.now.sys
|
|
172
|
+
openc3_script_sleep()
|
|
173
|
+
time = Time.now.sys - start_time
|
|
174
|
+
Logger.info("WAIT: Indefinite for actual time of #{time} seconds")
|
|
175
|
+
|
|
176
|
+
# wait(5) # absolute wait time
|
|
177
|
+
when 1
|
|
178
|
+
if args[0].kind_of? Numeric
|
|
179
|
+
start_time = Time.now.sys
|
|
180
|
+
openc3_script_sleep(args[0])
|
|
181
|
+
time = Time.now.sys - start_time
|
|
182
|
+
Logger.info("WAIT: #{args[0]} seconds with actual time of #{time} seconds")
|
|
183
|
+
else
|
|
184
|
+
raise "Non-numeric wait time specified"
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# wait('target_name packet_name item_name > 1', timeout, polling_rate) # polling_rate is optional
|
|
188
|
+
when 2, 3
|
|
189
|
+
target_name, packet_name, item_name, comparison_to_eval = extract_fields_from_check_text(args[0])
|
|
190
|
+
timeout = args[1]
|
|
191
|
+
if args.length == 3
|
|
192
|
+
polling_rate = args[2]
|
|
193
|
+
else
|
|
194
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE
|
|
195
|
+
end
|
|
196
|
+
_execute_wait(target_name, packet_name, item_name, type, comparison_to_eval, timeout, polling_rate, scope: scope, token: token)
|
|
197
|
+
|
|
198
|
+
# wait('target_name', 'packet_name', 'item_name', comparison_to_eval, timeout, polling_rate) # polling_rate is optional
|
|
199
|
+
when 5, 6
|
|
200
|
+
target_name = args[0]
|
|
201
|
+
packet_name = args[1]
|
|
202
|
+
item_name = args[2]
|
|
203
|
+
comparison_to_eval = args[3]
|
|
204
|
+
timeout = args[4]
|
|
205
|
+
if args.length == 6
|
|
206
|
+
polling_rate = args[5]
|
|
207
|
+
else
|
|
208
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE
|
|
209
|
+
end
|
|
210
|
+
_execute_wait(target_name, packet_name, item_name, type, comparison_to_eval, timeout, polling_rate, scope: scope, token: token)
|
|
211
|
+
|
|
212
|
+
else
|
|
213
|
+
# Invalid number of arguments
|
|
214
|
+
raise "ERROR: Invalid number of arguments (#{args.length}) passed to wait()"
|
|
215
|
+
end
|
|
216
|
+
time
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# @deprecated Use wait with type: :RAW
|
|
220
|
+
def wait_raw(*args, scope: $openc3_scope, token: $openc3_token)
|
|
221
|
+
wait(*args, type: :RAW, scope: scope, token: token)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Wait on an expression to be true. On a timeout, the script will continue.
|
|
225
|
+
#
|
|
226
|
+
# Supports two signatures:
|
|
227
|
+
# wait_tolerance('target_name packet_name item_name', expected_value, tolerance, timeout, polling_rate)
|
|
228
|
+
# wait_tolerance('target_name', 'packet_name', 'item_name', expected_value, tolerance, timeout, polling_rate)
|
|
229
|
+
#
|
|
230
|
+
# @param args [String|Array<String>] See the description for calling style
|
|
231
|
+
# @param type [Symbol] Telemetry type, :RAW or :CONVERTED (default)
|
|
232
|
+
def wait_tolerance(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token)
|
|
233
|
+
raise "Invalid type '#{type}' for wait_tolerance" unless %i(RAW CONVERTED).include?(type)
|
|
234
|
+
|
|
235
|
+
target_name, packet_name, item_name, expected_value, tolerance, timeout, polling_rate = _wait_tolerance_process_args(args, scope: scope, token: token)
|
|
236
|
+
start_time = Time.now.sys
|
|
237
|
+
value = tlm(target_name, packet_name, item_name, type: type, scope: scope, token: token)
|
|
238
|
+
if value.is_a?(Array)
|
|
239
|
+
expected_value, tolerance = array_tolerance_process_args(value.size, expected_value, tolerance, 'wait_tolerance', scope: scope, token: token)
|
|
240
|
+
|
|
241
|
+
success, value = openc3_script_wait_implementation_array_tolerance(value.size, target_name, packet_name, item_name, type, expected_value, tolerance, timeout, polling_rate, scope: scop, token: token)
|
|
242
|
+
time = Time.now.sys - start_time
|
|
243
|
+
|
|
244
|
+
message = ""
|
|
245
|
+
value.size.times do |i|
|
|
246
|
+
range = (expected_value[i] - tolerance[i]..expected_value[i] + tolerance[i])
|
|
247
|
+
wait_str = "WAIT: #{_upcase(target_name, packet_name, item_name)}[#{i}]"
|
|
248
|
+
range_str = "range #{range.first} to #{range.last} with value == #{value[i]} after waiting #{time} seconds"
|
|
249
|
+
if range.include?(value[i])
|
|
250
|
+
message << "#{wait_str} was within #{range_str}\n"
|
|
251
|
+
else
|
|
252
|
+
message << "#{wait_str} failed to be within #{range_str}\n"
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
if success
|
|
257
|
+
Logger.info message
|
|
258
|
+
else
|
|
259
|
+
Logger.warn message
|
|
260
|
+
end
|
|
261
|
+
else
|
|
262
|
+
success, value = openc3_script_wait_implementation_tolerance(target_name, packet_name, item_name, type, expected_value, tolerance, timeout, polling_rate, scope: scope, token: token)
|
|
263
|
+
time = Time.now.sys - start_time
|
|
264
|
+
range = (expected_value - tolerance)..(expected_value + tolerance)
|
|
265
|
+
wait_str = "WAIT: #{_upcase(target_name, packet_name, item_name)}"
|
|
266
|
+
range_str = "range #{range.first} to #{range.last} with value == #{value} after waiting #{time} seconds"
|
|
267
|
+
if success
|
|
268
|
+
Logger.info "#{wait_str} was within #{range_str}"
|
|
269
|
+
else
|
|
270
|
+
Logger.warn "#{wait_str} failed to be within #{range_str}"
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
time
|
|
274
|
+
end
|
|
275
|
+
|
|
276
|
+
# @deprecated Use wait_tolerance with type: :RAW
|
|
277
|
+
def wait_tolerance_raw(*args, scope: $openc3_scope, token: $openc3_token)
|
|
278
|
+
wait_tolerance(*args, type: :RAW, scope: scope, token: token)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Wait on a custom expression to be true
|
|
282
|
+
def wait_expression(exp_to_eval, timeout, polling_rate = DEFAULT_TLM_POLLING_RATE, context = nil, scope: $openc3_scope, token: $openc3_token)
|
|
283
|
+
start_time = Time.now.sys
|
|
284
|
+
success = openc3_script_wait_implementation_expression(exp_to_eval, timeout, polling_rate, context, scope: scope, token: token)
|
|
285
|
+
time = Time.now.sys - start_time
|
|
286
|
+
if success
|
|
287
|
+
Logger.info "WAIT: #{exp_to_eval} is TRUE after waiting #{time} seconds"
|
|
288
|
+
else
|
|
289
|
+
Logger.warn "WAIT: #{exp_to_eval} is FALSE after waiting #{time} seconds"
|
|
290
|
+
end
|
|
291
|
+
time
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Wait for the converted value of a telmetry item against a condition or for a timeout
|
|
295
|
+
# and then check against the condition.
|
|
296
|
+
#
|
|
297
|
+
# Supports two signatures:
|
|
298
|
+
# wait_check(target_name, packet_name, item_name, comparison_to_eval, timeout, polling_rate)
|
|
299
|
+
# wait_check('target_name packet_name item_name > 1', timeout, polling_rate)
|
|
300
|
+
#
|
|
301
|
+
# @param args [String|Array<String>] See the description for calling style
|
|
302
|
+
# @param type [Symbol] Telemetry type, :RAW, :CONVERTED (default), :FORMATTED, or :WITH_UNITS
|
|
303
|
+
def wait_check(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token, &block)
|
|
304
|
+
target_name, packet_name, item_name, comparison_to_eval, timeout, polling_rate = _wait_check_process_args(args, scope: scope, token: token)
|
|
305
|
+
start_time = Time.now.sys
|
|
306
|
+
success, value = openc3_script_wait_implementation(target_name, packet_name, item_name, type, comparison_to_eval, timeout, polling_rate, scope: scope, token: token, &block)
|
|
307
|
+
value = "'#{value}'" if value.is_a? String # Show user the check against a quoted string
|
|
308
|
+
time = Time.now.sys - start_time
|
|
309
|
+
check_str = "CHECK: #{_upcase(target_name, packet_name, item_name)} #{comparison_to_eval}"
|
|
310
|
+
with_value_str = "with value == #{value} after waiting #{time} seconds"
|
|
311
|
+
if success
|
|
312
|
+
Logger.info "#{check_str} success #{with_value_str}"
|
|
313
|
+
else
|
|
314
|
+
message = "#{check_str} failed #{with_value_str}"
|
|
315
|
+
if $disconnect
|
|
316
|
+
Logger.error message
|
|
317
|
+
else
|
|
318
|
+
raise CheckError, message
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
time
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# @deprecated use wait_check with type: :RAW
|
|
325
|
+
def wait_check_raw(*args, scope: $openc3_scope, token: $openc3_token, &block)
|
|
326
|
+
wait_check(*args, type: :RAW, scope: scope, token: token, &block)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# Wait for the value of a telmetry item to be within a tolerance of a value
|
|
330
|
+
# and then check against the condition.
|
|
331
|
+
#
|
|
332
|
+
# Supports multiple signatures:
|
|
333
|
+
# wait_tolerance('target_name packet_name item_name', expected_value, tolerance, timeout, polling_rate)
|
|
334
|
+
# wait_tolerance('target_name', 'packet_name', 'item_name', expected_value, tolerance, timeout, polling_rate)
|
|
335
|
+
#
|
|
336
|
+
# @param args [String|Array<String>] See the description for calling style
|
|
337
|
+
# @param type [Symbol] Telemetry type, :RAW or :CONVERTED (default)
|
|
338
|
+
def wait_check_tolerance(*args, type: :CONVERTED, scope: $openc3_scope, token: $openc3_token, &block)
|
|
339
|
+
raise "Invalid type '#{type}' for wait_check_tolerance" unless %i(RAW CONVERTED).include?(type)
|
|
340
|
+
|
|
341
|
+
target_name, packet_name, item_name, expected_value, tolerance, timeout, polling_rate = _wait_tolerance_process_args(args, scope: scope, token: token)
|
|
342
|
+
start_time = Time.now.sys
|
|
343
|
+
value = tlm(target_name, packet_name, item_name, type: type, scope: scope, token: token)
|
|
344
|
+
if value.is_a?(Array)
|
|
345
|
+
expected_value, tolerance = array_tolerance_process_args(value.size, expected_value, tolerance, 'wait_check_tolerance', scope: scope, token: token)
|
|
346
|
+
|
|
347
|
+
success, value = openc3_script_wait_implementation_array_tolerance(value.size, target_name, packet_name, item_name, type, expected_value, tolerance, timeout, polling_rate, scope: scope, token: token, &block)
|
|
348
|
+
time = Time.now.sys - start_time
|
|
349
|
+
|
|
350
|
+
message = ""
|
|
351
|
+
value.size.times do |i|
|
|
352
|
+
range = (expected_value[i] - tolerance[i]..expected_value[i] + tolerance[i])
|
|
353
|
+
check_str = "CHECK: #{_upcase(target_name, packet_name, item_name)}[#{i}]"
|
|
354
|
+
range_str = "range #{range.first} to #{range.last} with value == #{value[i]} after waiting #{time} seconds"
|
|
355
|
+
if range.include?(value[i])
|
|
356
|
+
message << "#{check_str} was within #{range_str}\n"
|
|
357
|
+
else
|
|
358
|
+
message << "#{check_str} failed to be within #{range_str}\n"
|
|
359
|
+
end
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
if success
|
|
363
|
+
Logger.info message
|
|
364
|
+
else
|
|
365
|
+
if $disconnect
|
|
366
|
+
Logger.error message
|
|
367
|
+
else
|
|
368
|
+
raise CheckError, message
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
else
|
|
372
|
+
success, value = openc3_script_wait_implementation_tolerance(target_name, packet_name, item_name, type, expected_value, tolerance, timeout, polling_rate, scope: scope, token: token)
|
|
373
|
+
time = Time.now.sys - start_time
|
|
374
|
+
range = (expected_value - tolerance)..(expected_value + tolerance)
|
|
375
|
+
check_str = "CHECK: #{_upcase(target_name, packet_name, item_name)}"
|
|
376
|
+
range_str = "range #{range.first} to #{range.last} with value == #{value} after waiting #{time} seconds"
|
|
377
|
+
if success
|
|
378
|
+
Logger.info "#{check_str} was within #{range_str}"
|
|
379
|
+
else
|
|
380
|
+
message = "#{check_str} failed to be within #{range_str}"
|
|
381
|
+
if $disconnect
|
|
382
|
+
Logger.error message
|
|
383
|
+
else
|
|
384
|
+
raise CheckError, message
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
end
|
|
388
|
+
time
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
# @deprecated Use wait_check_tolerance with type: :RAW
|
|
392
|
+
def wait_check_tolerance_raw(*args, scope: $openc3_scope, token: $openc3_token, &block)
|
|
393
|
+
wait_check_tolerance(*args, type: :RAW, scope: scope, token: token, &block)
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
# Wait on an expression to be true. On a timeout, the script will pause.
|
|
397
|
+
def wait_check_expression(exp_to_eval,
|
|
398
|
+
timeout,
|
|
399
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE,
|
|
400
|
+
context = nil,
|
|
401
|
+
scope: $openc3_scope, token: $openc3_token, &block)
|
|
402
|
+
start_time = Time.now.sys
|
|
403
|
+
success = openc3_script_wait_implementation_expression(exp_to_eval,
|
|
404
|
+
timeout,
|
|
405
|
+
polling_rate,
|
|
406
|
+
context, scope: scope, token: token, &block)
|
|
407
|
+
time = Time.now.sys - start_time
|
|
408
|
+
if success
|
|
409
|
+
Logger.info "CHECK: #{exp_to_eval} is TRUE after waiting #{time} seconds"
|
|
410
|
+
else
|
|
411
|
+
message = "CHECK: #{exp_to_eval} is FALSE after waiting #{time} seconds"
|
|
412
|
+
if $disconnect
|
|
413
|
+
Logger.error message
|
|
414
|
+
else
|
|
415
|
+
raise CheckError, message
|
|
416
|
+
end
|
|
417
|
+
end
|
|
418
|
+
time
|
|
419
|
+
end
|
|
420
|
+
alias wait_expression_stop_on_timeout wait_check_expression
|
|
421
|
+
|
|
422
|
+
def wait_packet(target_name,
|
|
423
|
+
packet_name,
|
|
424
|
+
num_packets,
|
|
425
|
+
timeout,
|
|
426
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE,
|
|
427
|
+
scope: $openc3_scope, token: $openc3_token)
|
|
428
|
+
_wait_packet(false, target_name, packet_name, num_packets, timeout, polling_rate, scope: scope, token: token)
|
|
429
|
+
end
|
|
430
|
+
|
|
431
|
+
# Wait for a telemetry packet to be received a certain number of times or timeout and raise an error
|
|
432
|
+
def wait_check_packet(target_name,
|
|
433
|
+
packet_name,
|
|
434
|
+
num_packets,
|
|
435
|
+
timeout,
|
|
436
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE,
|
|
437
|
+
scope: $openc3_scope, token: $openc3_token)
|
|
438
|
+
_wait_packet(true, target_name, packet_name, num_packets, timeout, polling_rate, scope: scope, token: token)
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def disable_instrumentation
|
|
442
|
+
if defined? RunningScript and RunningScript.instance
|
|
443
|
+
RunningScript.instance.use_instrumentation = false
|
|
444
|
+
begin
|
|
445
|
+
yield
|
|
446
|
+
ensure
|
|
447
|
+
RunningScript.instance.use_instrumentation = true
|
|
448
|
+
end
|
|
449
|
+
else
|
|
450
|
+
yield
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
def set_line_delay(delay)
|
|
455
|
+
if defined? RunningScript
|
|
456
|
+
RunningScript.line_delay = delay if delay >= 0.0
|
|
457
|
+
end
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
def get_line_delay
|
|
461
|
+
if defined? RunningScript
|
|
462
|
+
RunningScript.line_delay
|
|
463
|
+
end
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
###########################################################################
|
|
467
|
+
# Scripts Outside of ScriptRunner Support
|
|
468
|
+
# ScriptRunner overrides these methods to work in the OpenC3 cluster
|
|
469
|
+
# They are only here to allow for scripts to have a change to work
|
|
470
|
+
# unaltered outside of the cluster
|
|
471
|
+
###########################################################################
|
|
472
|
+
|
|
473
|
+
def start(procedure_name)
|
|
474
|
+
cached = false
|
|
475
|
+
begin
|
|
476
|
+
Kernel::load(procedure_name)
|
|
477
|
+
rescue LoadError => error
|
|
478
|
+
raise LoadError, "Error loading -- #{procedure_name}\n#{error.message}"
|
|
479
|
+
end
|
|
480
|
+
# Return whether we had to load and instrument this file, i.e. it was not cached
|
|
481
|
+
!cached
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
# Require an additional ruby file
|
|
485
|
+
def load_utility(procedure_name)
|
|
486
|
+
return start(procedure_name)
|
|
487
|
+
end
|
|
488
|
+
alias require_utility load_utility
|
|
489
|
+
|
|
490
|
+
###########################################################################
|
|
491
|
+
# Private implementation details
|
|
492
|
+
###########################################################################
|
|
493
|
+
|
|
494
|
+
# Creates a string with the parameters upcased
|
|
495
|
+
def _upcase(target_name, packet_name, item_name)
|
|
496
|
+
"#{target_name.upcase} #{packet_name.upcase} #{item_name.upcase}"
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
# Implementaton of the various check commands. It yields back to the
|
|
500
|
+
# caller to allow the return of the value through various telemetry calls.
|
|
501
|
+
# This method should not be called directly by application code.
|
|
502
|
+
def _check(*args, scope: $openc3_scope, token: $openc3_token)
|
|
503
|
+
target_name, packet_name, item_name, comparison_to_eval = _check_process_args(args, 'check', scope: scope, token: token)
|
|
504
|
+
|
|
505
|
+
value = yield(target_name, packet_name, item_name)
|
|
506
|
+
if comparison_to_eval
|
|
507
|
+
check_eval(target_name, packet_name, item_name, comparison_to_eval, value, scope: scope)
|
|
508
|
+
else
|
|
509
|
+
Logger.info "CHECK: #{_upcase(target_name, packet_name, item_name)} == #{value}"
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
|
|
513
|
+
def _check_process_args(args, function_name, scope: $openc3_scope, token: $openc3_token)
|
|
514
|
+
case args.length
|
|
515
|
+
when 1
|
|
516
|
+
target_name, packet_name, item_name, comparison_to_eval = extract_fields_from_check_text(args[0])
|
|
517
|
+
when 4
|
|
518
|
+
target_name = args[0]
|
|
519
|
+
packet_name = args[1]
|
|
520
|
+
item_name = args[2]
|
|
521
|
+
comparison_to_eval = args[3]
|
|
522
|
+
else
|
|
523
|
+
# Invalid number of arguments
|
|
524
|
+
raise "ERROR: Invalid number of arguments (#{args.length}) passed to #{function_name}()"
|
|
525
|
+
end
|
|
526
|
+
return [target_name, packet_name, item_name, comparison_to_eval]
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
def _check_tolerance_process_args(args, scope: $openc3_scope, token: $openc3_token)
|
|
530
|
+
case args.length
|
|
531
|
+
when 3
|
|
532
|
+
target_name, packet_name, item_name = extract_fields_from_tlm_text(args[0])
|
|
533
|
+
expected_value = args[1]
|
|
534
|
+
if args[2].is_a?(Array)
|
|
535
|
+
tolerance = args[2].map!(&:abs)
|
|
536
|
+
else
|
|
537
|
+
tolerance = args[2].abs
|
|
538
|
+
end
|
|
539
|
+
when 5
|
|
540
|
+
target_name = args[0]
|
|
541
|
+
packet_name = args[1]
|
|
542
|
+
item_name = args[2]
|
|
543
|
+
expected_value = args[3]
|
|
544
|
+
if args[4].is_a?(Array)
|
|
545
|
+
tolerance = args[4].map!(&:abs)
|
|
546
|
+
else
|
|
547
|
+
tolerance = args[4].abs
|
|
548
|
+
end
|
|
549
|
+
else
|
|
550
|
+
# Invalid number of arguments
|
|
551
|
+
raise "ERROR: Invalid number of arguments (#{args.length}) passed to check_tolerance()"
|
|
552
|
+
end
|
|
553
|
+
return [target_name, packet_name, item_name, expected_value, tolerance]
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
# Wait for a telemetry packet to be received a certain number of times or timeout
|
|
557
|
+
def _wait_packet(check,
|
|
558
|
+
target_name,
|
|
559
|
+
packet_name,
|
|
560
|
+
num_packets,
|
|
561
|
+
timeout,
|
|
562
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE,
|
|
563
|
+
scope: $openc3_scope, token: $openc3_token)
|
|
564
|
+
type = (check ? 'CHECK' : 'WAIT')
|
|
565
|
+
initial_count = tlm(target_name, packet_name, 'RECEIVED_COUNT', scope: scope, token: token)
|
|
566
|
+
start_time = Time.now.sys
|
|
567
|
+
success, value = openc3_script_wait_implementation(target_name,
|
|
568
|
+
packet_name,
|
|
569
|
+
'RECEIVED_COUNT',
|
|
570
|
+
:CONVERTED,
|
|
571
|
+
">= #{initial_count + num_packets}",
|
|
572
|
+
timeout,
|
|
573
|
+
polling_rate,
|
|
574
|
+
scope: scope,
|
|
575
|
+
token: token)
|
|
576
|
+
time = Time.now.sys - start_time
|
|
577
|
+
if success
|
|
578
|
+
Logger.info "#{type}: #{target_name.upcase} #{packet_name.upcase} received #{value - initial_count} times after waiting #{time} seconds"
|
|
579
|
+
else
|
|
580
|
+
message = "#{type}: #{target_name.upcase} #{packet_name.upcase} expected to be received #{num_packets} times but only received #{value - initial_count} times after waiting #{time} seconds"
|
|
581
|
+
if check
|
|
582
|
+
if $disconnect
|
|
583
|
+
Logger.error message
|
|
584
|
+
else
|
|
585
|
+
raise CheckError, message
|
|
586
|
+
end
|
|
587
|
+
else
|
|
588
|
+
Logger.warn message
|
|
589
|
+
end
|
|
590
|
+
end
|
|
591
|
+
time
|
|
592
|
+
end
|
|
593
|
+
|
|
594
|
+
def _execute_wait(target_name, packet_name, item_name, value_type, comparison_to_eval, timeout, polling_rate, scope: $openc3_scope, token: $openc3_token)
|
|
595
|
+
start_time = Time.now.sys
|
|
596
|
+
success, value = openc3_script_wait_implementation(target_name, packet_name, item_name, value_type, comparison_to_eval, timeout, polling_rate, scope: scope, token: token)
|
|
597
|
+
value = "'#{value}'" if value.is_a? String # Show user the check against a quoted string
|
|
598
|
+
time = Time.now.sys - start_time
|
|
599
|
+
wait_str = "WAIT: #{_upcase(target_name, packet_name, item_name)} #{comparison_to_eval}"
|
|
600
|
+
value_str = "with value == #{value} after waiting #{time} seconds"
|
|
601
|
+
if success
|
|
602
|
+
Logger.info "#{wait_str} success #{value_str}"
|
|
603
|
+
else
|
|
604
|
+
Logger.warn "#{wait_str} failed #{value_str}"
|
|
605
|
+
end
|
|
606
|
+
end
|
|
607
|
+
|
|
608
|
+
def _wait_tolerance_process_args(args, scope: $openc3_scope, token: $openc3_token)
|
|
609
|
+
case args.length
|
|
610
|
+
when 4, 5
|
|
611
|
+
target_name, packet_name, item_name = extract_fields_from_tlm_text(args[0])
|
|
612
|
+
expected_value = args[1]
|
|
613
|
+
if args[2].is_a?(Array)
|
|
614
|
+
tolerance = args[2].map!(&:abs)
|
|
615
|
+
else
|
|
616
|
+
tolerance = args[2].abs
|
|
617
|
+
end
|
|
618
|
+
timeout = args[3]
|
|
619
|
+
if args.length == 5
|
|
620
|
+
polling_rate = args[4]
|
|
621
|
+
else
|
|
622
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE
|
|
623
|
+
end
|
|
624
|
+
when 6, 7
|
|
625
|
+
target_name = args[0]
|
|
626
|
+
packet_name = args[1]
|
|
627
|
+
item_name = args[2]
|
|
628
|
+
expected_value = args[3]
|
|
629
|
+
if args[4].is_a?(Array)
|
|
630
|
+
tolerance = args[4].map!(&:abs)
|
|
631
|
+
else
|
|
632
|
+
tolerance = args[4].abs
|
|
633
|
+
end
|
|
634
|
+
timeout = args[5]
|
|
635
|
+
if args.length == 7
|
|
636
|
+
polling_rate = args[6]
|
|
637
|
+
else
|
|
638
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE
|
|
639
|
+
end
|
|
640
|
+
else
|
|
641
|
+
# Invalid number of arguments
|
|
642
|
+
raise "ERROR: Invalid number of arguments (#{args.length}) passed to wait_tolerance()"
|
|
643
|
+
end
|
|
644
|
+
return [target_name, packet_name, item_name, expected_value, tolerance, timeout, polling_rate]
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
# When testing an array with a tolerance, the expected value and tolerance
|
|
648
|
+
# can both be supplied as either an array or a single value. If a single
|
|
649
|
+
# value is passed in, that value will be used for all array elements.
|
|
650
|
+
def array_tolerance_process_args(array_size, expected_value, tolerance, function_name, scope: $openc3_scope, token: $openc3_token)
|
|
651
|
+
if expected_value.is_a?(Array)
|
|
652
|
+
if array_size != expected_value.size
|
|
653
|
+
raise "ERROR: Invalid array size for expected_value passed to #{function_name}()"
|
|
654
|
+
end
|
|
655
|
+
else
|
|
656
|
+
expected_value = Array.new(array_size, expected_value)
|
|
657
|
+
end
|
|
658
|
+
if tolerance.is_a?(Array)
|
|
659
|
+
if array_size != tolerance.size
|
|
660
|
+
raise "ERROR: Invalid array size for tolerance passed to #{function_name}()"
|
|
661
|
+
end
|
|
662
|
+
else
|
|
663
|
+
tolerance = Array.new(array_size, tolerance)
|
|
664
|
+
end
|
|
665
|
+
return [expected_value, tolerance]
|
|
666
|
+
end
|
|
667
|
+
|
|
668
|
+
def _wait_check_process_args(args, scope: $openc3_scope, token: $openc3_token)
|
|
669
|
+
case args.length
|
|
670
|
+
when 2, 3
|
|
671
|
+
target_name, packet_name, item_name, comparison_to_eval = extract_fields_from_check_text(args[0])
|
|
672
|
+
timeout = args[1]
|
|
673
|
+
if args.length == 3
|
|
674
|
+
polling_rate = args[2]
|
|
675
|
+
else
|
|
676
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE
|
|
677
|
+
end
|
|
678
|
+
when 5, 6
|
|
679
|
+
target_name = args[0]
|
|
680
|
+
packet_name = args[1]
|
|
681
|
+
item_name = args[2]
|
|
682
|
+
comparison_to_eval = args[3]
|
|
683
|
+
timeout = args[4]
|
|
684
|
+
if args.length == 6
|
|
685
|
+
polling_rate = args[5]
|
|
686
|
+
else
|
|
687
|
+
polling_rate = DEFAULT_TLM_POLLING_RATE
|
|
688
|
+
end
|
|
689
|
+
else
|
|
690
|
+
# Invalid number of arguments
|
|
691
|
+
raise "ERROR: Invalid number of arguments (#{args.length}) passed to wait_check()"
|
|
692
|
+
end
|
|
693
|
+
return [target_name, packet_name, item_name, comparison_to_eval, timeout, polling_rate]
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
def _openc3_script_wait_implementation(target_name, packet_name, item_name, value_type, timeout, polling_rate, exp_to_eval, scope: $openc3_scope, token: $openc3_token, &block)
|
|
697
|
+
end_time = Time.now.sys + timeout
|
|
698
|
+
|
|
699
|
+
while true
|
|
700
|
+
work_start = Time.now.sys
|
|
701
|
+
value = tlm(target_name, packet_name, item_name, type: value_type, scope: scope, token: token)
|
|
702
|
+
if not block.nil?
|
|
703
|
+
if block.call(value)
|
|
704
|
+
return true, value
|
|
705
|
+
end
|
|
706
|
+
else
|
|
707
|
+
if eval(exp_to_eval)
|
|
708
|
+
return true, value
|
|
709
|
+
end
|
|
710
|
+
end
|
|
711
|
+
break if Time.now.sys >= end_time
|
|
712
|
+
|
|
713
|
+
delta = Time.now.sys - work_start
|
|
714
|
+
sleep_time = polling_rate - delta
|
|
715
|
+
end_delta = end_time - Time.now.sys
|
|
716
|
+
sleep_time = end_delta if end_delta < sleep_time
|
|
717
|
+
sleep_time = 0 if sleep_time < 0
|
|
718
|
+
canceled = openc3_script_sleep(sleep_time)
|
|
719
|
+
|
|
720
|
+
if canceled
|
|
721
|
+
value = tlm(target_name, packet_name, item_name, type: value_type, scope: scope, token: token)
|
|
722
|
+
if eval(exp_to_eval)
|
|
723
|
+
return true, value
|
|
724
|
+
else
|
|
725
|
+
return false, value
|
|
726
|
+
end
|
|
727
|
+
end
|
|
728
|
+
end
|
|
729
|
+
|
|
730
|
+
return false, value
|
|
731
|
+
rescue NameError => error
|
|
732
|
+
if error.message =~ /uninitialized constant OpenC3::ApiShared::(\w+)/
|
|
733
|
+
new_error = NameError.new("Uninitialized constant #{$1}. Did you mean '#{$1}' as a string?")
|
|
734
|
+
new_error.set_backtrace(error.backtrace)
|
|
735
|
+
raise new_error
|
|
736
|
+
else
|
|
737
|
+
raise error
|
|
738
|
+
end
|
|
739
|
+
end
|
|
740
|
+
|
|
741
|
+
# Wait for a converted telemetry item to pass a comparison
|
|
742
|
+
def openc3_script_wait_implementation(target_name, packet_name, item_name, value_type, comparison_to_eval, timeout, polling_rate = DEFAULT_TLM_POLLING_RATE, scope: $openc3_scope, token: $openc3_token, &block)
|
|
743
|
+
if comparison_to_eval
|
|
744
|
+
exp_to_eval = "value " + comparison_to_eval
|
|
745
|
+
else
|
|
746
|
+
exp_to_eval = nil
|
|
747
|
+
end
|
|
748
|
+
_openc3_script_wait_implementation(target_name, packet_name, item_name, value_type, timeout, polling_rate, exp_to_eval, scope: scope, token: token, &block)
|
|
749
|
+
end
|
|
750
|
+
|
|
751
|
+
def openc3_script_wait_implementation_tolerance(target_name, packet_name, item_name, value_type, expected_value, tolerance, timeout, polling_rate = DEFAULT_TLM_POLLING_RATE, scope: $openc3_scope, token: $openc3_token, &block)
|
|
752
|
+
exp_to_eval = "((#{expected_value} - #{tolerance})..(#{expected_value} + #{tolerance})).include? value"
|
|
753
|
+
_openc3_script_wait_implementation(target_name, packet_name, item_name, value_type, timeout, polling_rate, exp_to_eval, scope: scope, token: token, &block)
|
|
754
|
+
end
|
|
755
|
+
|
|
756
|
+
def openc3_script_wait_implementation_array_tolerance(array_size, target_name, packet_name, item_name, value_type, expected_value, tolerance, timeout, polling_rate = DEFAULT_TLM_POLLING_RATE, scope: $openc3_scope, token: $openc3_token, &block)
|
|
757
|
+
statements = []
|
|
758
|
+
array_size.times { |i| statements << "(((#{expected_value[i]} - #{tolerance[i]})..(#{expected_value[i]} + #{tolerance[i]})).include? value[#{i}])" }
|
|
759
|
+
exp_to_eval = statements.join(" && ")
|
|
760
|
+
_openc3_script_wait_implementation(target_name, packet_name, item_name, value_type, timeout, polling_rate, exp_to_eval, scope: scope, token: token, &block)
|
|
761
|
+
end
|
|
762
|
+
|
|
763
|
+
# Wait on an expression to be true.
|
|
764
|
+
def openc3_script_wait_implementation_expression(exp_to_eval, timeout, polling_rate, context, scope: $openc3_scope, token: $openc3_token)
|
|
765
|
+
end_time = Time.now.sys + timeout
|
|
766
|
+
|
|
767
|
+
while true
|
|
768
|
+
work_start = Time.now.sys
|
|
769
|
+
if eval(exp_to_eval, context)
|
|
770
|
+
return true
|
|
771
|
+
end
|
|
772
|
+
break if Time.now.sys >= end_time
|
|
773
|
+
|
|
774
|
+
delta = Time.now.sys - work_start
|
|
775
|
+
sleep_time = polling_rate - delta
|
|
776
|
+
end_delta = end_time - Time.now.sys
|
|
777
|
+
sleep_time = end_delta if end_delta < sleep_time
|
|
778
|
+
sleep_time = 0 if sleep_time < 0
|
|
779
|
+
canceled = openc3_script_sleep(sleep_time)
|
|
780
|
+
|
|
781
|
+
if canceled
|
|
782
|
+
if eval(exp_to_eval, context)
|
|
783
|
+
return true
|
|
784
|
+
else
|
|
785
|
+
return nil
|
|
786
|
+
end
|
|
787
|
+
end
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
return nil
|
|
791
|
+
rescue NameError => error
|
|
792
|
+
if error.message =~ /uninitialized constant OpenC3::ApiShared::(\w+)/
|
|
793
|
+
new_error = NameError.new("Uninitialized constant #{$1}. Did you mean '#{$1}' as a string?")
|
|
794
|
+
new_error.set_backtrace(error.backtrace)
|
|
795
|
+
raise new_error
|
|
796
|
+
else
|
|
797
|
+
raise error
|
|
798
|
+
end
|
|
799
|
+
end
|
|
800
|
+
|
|
801
|
+
def check_eval(target_name, packet_name, item_name, comparison_to_eval, value, scope: $openc3_scope, token: $openc3_token)
|
|
802
|
+
string = "value " + comparison_to_eval
|
|
803
|
+
check_str = "CHECK: #{_upcase(target_name, packet_name, item_name)} #{comparison_to_eval}"
|
|
804
|
+
# Show user the check against a quoted string
|
|
805
|
+
# Note: We have to preserve the original 'value' variable because we're going to eval against it
|
|
806
|
+
value_str = value.is_a?(String) ? "'#{value}'" : value
|
|
807
|
+
with_value = "with value == #{value_str}"
|
|
808
|
+
if eval(string)
|
|
809
|
+
Logger.info "#{check_str} success #{with_value}"
|
|
810
|
+
else
|
|
811
|
+
message = "#{check_str} failed #{with_value}"
|
|
812
|
+
if $disconnect
|
|
813
|
+
Logger.error message
|
|
814
|
+
else
|
|
815
|
+
raise CheckError, message
|
|
816
|
+
end
|
|
817
|
+
end
|
|
818
|
+
rescue NameError => error
|
|
819
|
+
if error.message =~ /uninitialized constant OpenC3::ApiShared::(\w+)/
|
|
820
|
+
new_error = NameError.new("Uninitialized constant #{$1}. Did you mean '#{$1}' as a string?")
|
|
821
|
+
new_error.set_backtrace(error.backtrace)
|
|
822
|
+
raise new_error
|
|
823
|
+
else
|
|
824
|
+
raise error
|
|
825
|
+
end
|
|
826
|
+
end
|
|
827
|
+
end
|
|
828
|
+
end
|