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,167 @@
|
|
|
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 'thread'
|
|
21
|
+
require 'socket' # For gethostname
|
|
22
|
+
require 'openc3/config/config_parser'
|
|
23
|
+
|
|
24
|
+
module OpenC3
|
|
25
|
+
# Creates a log file of raw data for either reads or writes. Can automatically
|
|
26
|
+
# cycle the log based on when the log file reaches a predefined size.
|
|
27
|
+
class RawLogger
|
|
28
|
+
# @return [String] The filename of the log
|
|
29
|
+
attr_reader :filename
|
|
30
|
+
|
|
31
|
+
# @return [Queue] Queue for asynchronous logging
|
|
32
|
+
attr_reader :queue
|
|
33
|
+
|
|
34
|
+
# @return [Boolean] Is logging enabled?
|
|
35
|
+
attr_reader :logging_enabled
|
|
36
|
+
|
|
37
|
+
# @return [String] Original name passed to raw logger
|
|
38
|
+
attr_reader :orig_name
|
|
39
|
+
|
|
40
|
+
# The allowable log types
|
|
41
|
+
LOG_TYPES = [:READ, :WRITE]
|
|
42
|
+
|
|
43
|
+
# The cycle time interval. Cycle times are only checked at this level of
|
|
44
|
+
# granularity.
|
|
45
|
+
CYCLE_TIME_INTERVAL = 60
|
|
46
|
+
|
|
47
|
+
# @param log_name [String] The name of the raw logger. Typically matches the
|
|
48
|
+
# name of the corresponding interface
|
|
49
|
+
# @param log_type [Symbol] The type of log to create. Must be :READ
|
|
50
|
+
# or :WRITE.
|
|
51
|
+
# @param log_directory [String] The directory to store the log files.
|
|
52
|
+
# @param logging_enabled [Boolean] Whether to enable raw logging
|
|
53
|
+
# @param cycle_size [Integer] The size in bytes before creating a new log file.
|
|
54
|
+
def initialize(
|
|
55
|
+
log_name,
|
|
56
|
+
log_type,
|
|
57
|
+
log_directory,
|
|
58
|
+
logging_enabled = false,
|
|
59
|
+
cycle_size = 2000000000
|
|
60
|
+
)
|
|
61
|
+
raise "log_type must be :READ or :WRITE" unless LOG_TYPES.include? log_type
|
|
62
|
+
|
|
63
|
+
@log_type = log_type
|
|
64
|
+
@orig_name = log_name
|
|
65
|
+
@log_name = (log_name.to_s.downcase + '_raw_' + @log_type.to_s.downcase + '_' + self.object_id.to_s).freeze
|
|
66
|
+
@log_directory = log_directory
|
|
67
|
+
@cycle_size = ConfigParser.handle_nil(cycle_size)
|
|
68
|
+
@cycle_size = Integer(@cycle_size) if @cycle_size
|
|
69
|
+
@mutex = Mutex.new
|
|
70
|
+
@file = nil
|
|
71
|
+
@filename = nil
|
|
72
|
+
@start_time = Time.now.sys
|
|
73
|
+
@logging_enabled = ConfigParser.handle_true_false(logging_enabled)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Set the raw logger name
|
|
77
|
+
# @param log_name [String] new name
|
|
78
|
+
def name=(log_name)
|
|
79
|
+
@orig_name = log_name
|
|
80
|
+
@log_name = (log_name.to_s.downcase + '_raw_' + @log_type.to_s.downcase + '_' + self.object_id.to_s).freeze
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Write data to the log file.
|
|
84
|
+
#
|
|
85
|
+
# If no log file currently exists in the filesystem, a new file will be
|
|
86
|
+
# created.
|
|
87
|
+
#
|
|
88
|
+
# Writing a log file is a critical operation so the entire method is
|
|
89
|
+
# wrapped with a rescue and handled with handle_critical_exception
|
|
90
|
+
#
|
|
91
|
+
# @param data [String] The data to write to the log file
|
|
92
|
+
def write(data)
|
|
93
|
+
if @logging_enabled
|
|
94
|
+
return if !data or data.length <= 0
|
|
95
|
+
|
|
96
|
+
need_new_file = false
|
|
97
|
+
@mutex.synchronize do
|
|
98
|
+
if !@file or (@cycle_size and (@file.stat.size + data.length) > @cycle_size)
|
|
99
|
+
need_new_file = true
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
start_new_file() if need_new_file
|
|
103
|
+
@mutex.synchronize { @file.write(data) if @file }
|
|
104
|
+
end
|
|
105
|
+
rescue => err
|
|
106
|
+
Logger.instance.error "Error writing #{@filename} : #{err.formatted}"
|
|
107
|
+
OpenC3.handle_critical_exception(err)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Starts a new log file by closing the existing log file. New log files are
|
|
111
|
+
# not created until data is written by {#write} so this does not
|
|
112
|
+
# immediately create a log file on the filesystem.
|
|
113
|
+
def start
|
|
114
|
+
close_file() unless (Time.now.sys - @start_time) < 1.0 # Prevent close/open too fast
|
|
115
|
+
@mutex.synchronize { @logging_enabled = true }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Stops all logging and closes the current log file.
|
|
119
|
+
def stop
|
|
120
|
+
@mutex.synchronize { @logging_enabled = false }
|
|
121
|
+
close_file()
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Create a clone of this object with a new name
|
|
125
|
+
def clone
|
|
126
|
+
raw_logger = super()
|
|
127
|
+
raw_logger.name = raw_logger.orig_name
|
|
128
|
+
raw_logger
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
protected
|
|
132
|
+
|
|
133
|
+
# Starting a new log file is a critical operation so the entire method is
|
|
134
|
+
# wrapped with a rescue and handled with handle_critical_exception
|
|
135
|
+
def start_new_file
|
|
136
|
+
close_file()
|
|
137
|
+
@mutex.synchronize do
|
|
138
|
+
@filename = File.join(@log_directory, File.build_timestamped_filename([@log_name], '.bin'))
|
|
139
|
+
@file = File.new(@filename, 'wb')
|
|
140
|
+
@start_time = Time.now.sys
|
|
141
|
+
Logger.instance.info "Raw Log File Opened : #{@filename}"
|
|
142
|
+
end
|
|
143
|
+
rescue => err
|
|
144
|
+
Logger.instance.error "Error opening #{@filename} : #{err.formatted}"
|
|
145
|
+
@logging_enabled = false
|
|
146
|
+
OpenC3.handle_critical_exception(err)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# Closing a log file isn't critical so we just log an error
|
|
150
|
+
def close_file
|
|
151
|
+
@mutex.synchronize do
|
|
152
|
+
if @file
|
|
153
|
+
begin
|
|
154
|
+
@file.close unless @file.closed?
|
|
155
|
+
File.chmod(0444, @file.path) # Make file read only
|
|
156
|
+
Logger.instance.info "Raw Log File Closed : #{@filename}"
|
|
157
|
+
rescue => err
|
|
158
|
+
Logger.instance.error "Error closing #{@filename} : #{err.formatted}"
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
@file = nil
|
|
162
|
+
@filename = nil
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
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/io/raw_logger'
|
|
21
|
+
|
|
22
|
+
module OpenC3
|
|
23
|
+
# Holds a read/write pair of raw loggers
|
|
24
|
+
class RawLoggerPair
|
|
25
|
+
# @return [RawLogger] The read logger
|
|
26
|
+
attr_accessor :read_logger
|
|
27
|
+
# @return [RawLogger] The write logger
|
|
28
|
+
attr_accessor :write_logger
|
|
29
|
+
|
|
30
|
+
# @param name [String] name to be added to log filenames
|
|
31
|
+
# @param log_directory [String] The directory to store the log files
|
|
32
|
+
# @param params [Array] raw log writer parameters or empty array
|
|
33
|
+
def initialize(name, log_directory, params = [])
|
|
34
|
+
if params.empty?
|
|
35
|
+
raw_logger_class = RawLogger
|
|
36
|
+
else
|
|
37
|
+
raw_logger_class = OpenC3.require_class(params[0])
|
|
38
|
+
end
|
|
39
|
+
if params[1]
|
|
40
|
+
@read_logger = raw_logger_class.new(name, :READ, log_directory, *params[1..-1])
|
|
41
|
+
@write_logger = raw_logger_class.new(name, :WRITE, log_directory, *params[1..-1])
|
|
42
|
+
else
|
|
43
|
+
@read_logger = raw_logger_class.new(name, :READ, log_directory)
|
|
44
|
+
@write_logger = raw_logger_class.new(name, :WRITE, log_directory)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Change the raw logger name
|
|
49
|
+
# @param name [String] new name
|
|
50
|
+
def name=(name)
|
|
51
|
+
@read_logger.name = name
|
|
52
|
+
@write_logger.name = name
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Start raw logging
|
|
56
|
+
def start
|
|
57
|
+
@read_logger.start
|
|
58
|
+
@write_logger.start
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Close any open raw data log files
|
|
62
|
+
def stop
|
|
63
|
+
@read_logger.stop
|
|
64
|
+
@write_logger.stop
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Clone the raw logger pair
|
|
68
|
+
def clone
|
|
69
|
+
raw_logger_pair = super()
|
|
70
|
+
raw_logger_pair.read_logger = @read_logger.clone
|
|
71
|
+
raw_logger_pair.write_logger = @write_logger.clone
|
|
72
|
+
raw_logger_pair.read_logger.start if @read_logger.logging_enabled
|
|
73
|
+
raw_logger_pair.write_logger.start if @write_logger.logging_enabled
|
|
74
|
+
raw_logger_pair
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
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/core_ext/kernel'
|
|
21
|
+
if Kernel.is_windows?
|
|
22
|
+
require 'openc3/io/win32_serial_driver'
|
|
23
|
+
elsif RUBY_ENGINE == 'ruby'
|
|
24
|
+
require 'openc3/io/posix_serial_driver'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
module OpenC3
|
|
28
|
+
# A platform independent serial driver
|
|
29
|
+
class SerialDriver
|
|
30
|
+
EVEN = :EVEN
|
|
31
|
+
ODD = :ODD
|
|
32
|
+
NONE = :NONE
|
|
33
|
+
VALID_PARITY = [EVEN, ODD, NONE]
|
|
34
|
+
|
|
35
|
+
# @param port_name [String] Name of the serial port
|
|
36
|
+
# @param baud_rate [Integer] Serial port baud rate
|
|
37
|
+
# @param parity [Symbol] Must be one of :EVEN, :ODD or :NONE
|
|
38
|
+
# @param stop_bits [Integer] Number of stop bits
|
|
39
|
+
# @param write_timeout [Float|nil] Number of seconds to wait for the write to
|
|
40
|
+
# complete or nil to block
|
|
41
|
+
# @param read_timeout [Float|nil] Number of seconds to wait for the read to
|
|
42
|
+
# complete or nil to block
|
|
43
|
+
# @param flow_control [Symbol] Currently supported :NONE and :RTSCTS (default :NONE)
|
|
44
|
+
# @param data_bits [Integer] Number of data bits (default 8)
|
|
45
|
+
def initialize(port_name,
|
|
46
|
+
baud_rate,
|
|
47
|
+
parity = :NONE,
|
|
48
|
+
stop_bits = 1,
|
|
49
|
+
write_timeout = 10.0,
|
|
50
|
+
read_timeout = nil,
|
|
51
|
+
flow_control = :NONE,
|
|
52
|
+
data_bits = 8)
|
|
53
|
+
raise(ArgumentError, "Invalid parity: #{parity}") unless VALID_PARITY.include? parity
|
|
54
|
+
|
|
55
|
+
if Kernel.is_windows?
|
|
56
|
+
@driver = Win32SerialDriver.new(port_name,
|
|
57
|
+
baud_rate,
|
|
58
|
+
parity,
|
|
59
|
+
stop_bits,
|
|
60
|
+
write_timeout,
|
|
61
|
+
read_timeout,
|
|
62
|
+
0.01,
|
|
63
|
+
1000,
|
|
64
|
+
flow_control,
|
|
65
|
+
data_bits)
|
|
66
|
+
elsif RUBY_ENGINE == 'ruby'
|
|
67
|
+
@driver = PosixSerialDriver.new(port_name,
|
|
68
|
+
baud_rate,
|
|
69
|
+
parity,
|
|
70
|
+
stop_bits,
|
|
71
|
+
write_timeout,
|
|
72
|
+
read_timeout,
|
|
73
|
+
flow_control,
|
|
74
|
+
data_bits)
|
|
75
|
+
else
|
|
76
|
+
@driver = nil # JRuby Serial on Linux not currently supported
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Disconnects the driver from the comm port
|
|
81
|
+
def close
|
|
82
|
+
@driver.close
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @return [Boolean] Whether the serial port has been closed
|
|
86
|
+
def closed?
|
|
87
|
+
@driver.closed?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# @param data [String] Binary data to write to the serial port
|
|
91
|
+
def write(data)
|
|
92
|
+
@driver.write(data)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# @return [String] Binary data read from the serial port
|
|
96
|
+
def read
|
|
97
|
+
@driver.read
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# @return [String] Binary data read from the serial port
|
|
101
|
+
def read_nonblock
|
|
102
|
+
@driver.read_nonblock
|
|
103
|
+
end
|
|
104
|
+
end # class SerialDriver
|
|
105
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
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/io/io_multiplexer'
|
|
21
|
+
|
|
22
|
+
module OpenC3
|
|
23
|
+
# Adds STDERR to the multiplexed streams
|
|
24
|
+
class Stderr < IoMultiplexer
|
|
25
|
+
@@instance = nil
|
|
26
|
+
|
|
27
|
+
def initialize
|
|
28
|
+
super()
|
|
29
|
+
@streams << STDERR
|
|
30
|
+
@@instance = self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [Stderr] Returns a single instance of Stderr
|
|
34
|
+
def self.instance
|
|
35
|
+
self.new unless @@instance
|
|
36
|
+
@@instance
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def tty?
|
|
40
|
+
false
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
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/io/io_multiplexer'
|
|
21
|
+
|
|
22
|
+
module OpenC3
|
|
23
|
+
# Adds STDOUT to the multiplexed streams
|
|
24
|
+
class Stdout < IoMultiplexer
|
|
25
|
+
@@instance = nil
|
|
26
|
+
|
|
27
|
+
def initialize
|
|
28
|
+
super()
|
|
29
|
+
@streams << STDOUT
|
|
30
|
+
@@instance = self
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [Stdout] Returns a single instance of Stdout
|
|
34
|
+
def self.instance
|
|
35
|
+
self.new unless @@instance
|
|
36
|
+
@@instance
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def tty?
|
|
40
|
+
false
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,194 @@
|
|
|
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 'socket'
|
|
21
|
+
require 'ipaddr'
|
|
22
|
+
require 'timeout' # for Timeout::Error
|
|
23
|
+
|
|
24
|
+
# Define needed constants for Windows
|
|
25
|
+
Socket::IP_MULTICAST_IF = 9 unless Socket.const_defined?('IP_MULTICAST_IF')
|
|
26
|
+
Socket::IP_MULTICAST_TTL = 10 unless Socket.const_defined?('IP_MULTICAST_TTL')
|
|
27
|
+
|
|
28
|
+
module OpenC3
|
|
29
|
+
class UdpReadWriteSocket
|
|
30
|
+
# @param bind_port [Integer[ Port to write data out from and receive data on (0 = randomly assigned)
|
|
31
|
+
# @param bind_address [String] Local address to bind to (0.0.0.0 = All local addresses)
|
|
32
|
+
# @param external_port [Integer] External port to write to
|
|
33
|
+
# @param external_address [String] External host to send data to
|
|
34
|
+
# @param multicast_interface_address [String] Local outgoing interface to send multicast packets from
|
|
35
|
+
# @param ttl [Integer] Time To Live for outgoing multicast packets
|
|
36
|
+
# @param read_multicast [Boolean] Whether or not to try to read from the external address as multicast
|
|
37
|
+
# @param write_multicast [Boolean] Whether or not to write to the external address as multicast
|
|
38
|
+
def initialize(
|
|
39
|
+
bind_port = 0,
|
|
40
|
+
bind_address = "0.0.0.0",
|
|
41
|
+
external_port = nil,
|
|
42
|
+
external_address = nil,
|
|
43
|
+
multicast_interface_address = nil,
|
|
44
|
+
ttl = 1,
|
|
45
|
+
read_multicast = true,
|
|
46
|
+
write_multicast = true
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
@socket = UDPSocket.new
|
|
50
|
+
|
|
51
|
+
# Basic setup to reuse address
|
|
52
|
+
@socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1)
|
|
53
|
+
|
|
54
|
+
# Bind to local address and port - This sets recv port, write_src port, recv_address, and write_src_address
|
|
55
|
+
@socket.bind(bind_address, bind_port) if bind_address and bind_port
|
|
56
|
+
|
|
57
|
+
# Default send to the specified address and port
|
|
58
|
+
@socket.connect(external_address, external_port) if external_address and external_port
|
|
59
|
+
|
|
60
|
+
# Handle multicast
|
|
61
|
+
if UdpReadWriteSocket.multicast?(external_address, external_port)
|
|
62
|
+
if write_multicast
|
|
63
|
+
# Basic setup set time to live
|
|
64
|
+
@socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_MULTICAST_TTL, ttl.to_i)
|
|
65
|
+
|
|
66
|
+
# Set outgoing interface
|
|
67
|
+
@socket.setsockopt(
|
|
68
|
+
Socket::IPPROTO_IP,
|
|
69
|
+
Socket::IP_MULTICAST_IF,
|
|
70
|
+
IPAddr.new(multicast_interface_address).hton
|
|
71
|
+
) if multicast_interface_address
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Receive messages sent to the multicast address
|
|
75
|
+
if read_multicast
|
|
76
|
+
multicast_interface_address = "0.0.0.0" unless multicast_interface_address
|
|
77
|
+
membership = IPAddr.new(external_address).hton + IPAddr.new(multicast_interface_address).hton
|
|
78
|
+
@socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, membership)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @param data [String] Binary data to send
|
|
84
|
+
# @param write_timeout [Float] Time in seconds to wait for the data to send
|
|
85
|
+
def write(data, write_timeout = 10.0)
|
|
86
|
+
num_bytes_to_send = data.length
|
|
87
|
+
total_bytes_sent = 0
|
|
88
|
+
bytes_sent = 0
|
|
89
|
+
data_to_send = data
|
|
90
|
+
|
|
91
|
+
loop do
|
|
92
|
+
begin
|
|
93
|
+
bytes_sent = @socket.write_nonblock(data_to_send)
|
|
94
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
|
95
|
+
result = IO.fast_select(nil, [@socket], nil, write_timeout)
|
|
96
|
+
if result
|
|
97
|
+
retry
|
|
98
|
+
else
|
|
99
|
+
raise Timeout::Error, "Write Timeout"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
total_bytes_sent += bytes_sent
|
|
103
|
+
break if total_bytes_sent >= num_bytes_to_send
|
|
104
|
+
|
|
105
|
+
data_to_send = data[total_bytes_sent..-1]
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# @param read_timeout [Float] Time in seconds to wait for the read to
|
|
110
|
+
# complete
|
|
111
|
+
def read(read_timeout = nil)
|
|
112
|
+
data = nil
|
|
113
|
+
begin
|
|
114
|
+
data, _ = @socket.recvfrom_nonblock(65536)
|
|
115
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
|
116
|
+
result = IO.fast_select([@socket], nil, nil, read_timeout)
|
|
117
|
+
if result
|
|
118
|
+
retry
|
|
119
|
+
else
|
|
120
|
+
raise Timeout::Error, "Read Timeout"
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
data
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Defer all methods to the UDPSocket
|
|
127
|
+
def method_missing(method, *args, &block)
|
|
128
|
+
@socket.__send__(method, *args, &block)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# @param host [String] Machine name or IP address
|
|
132
|
+
# @param port [String] Port
|
|
133
|
+
# @return [Boolean] Whether the hostname is multicast
|
|
134
|
+
def self.multicast?(host, port)
|
|
135
|
+
return false if host.nil? || port.nil?
|
|
136
|
+
|
|
137
|
+
Addrinfo.udp(host, port).ipv4_multicast?
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Creates a UDPSocket and implements a non-blocking write.
|
|
142
|
+
class UdpWriteSocket < UdpReadWriteSocket
|
|
143
|
+
# @param dest_address [String] Host to send data to
|
|
144
|
+
# @param dest_port [Integer] Port to send data to
|
|
145
|
+
# @param src_port [Integer[ Port to send data out from
|
|
146
|
+
# @param multicast_interface_address [String] Local outgoing interface to send multicast packets from
|
|
147
|
+
# @param ttl [Integer] Time To Live for outgoing packets
|
|
148
|
+
# @param bind_address [String] Local address to bind to (0.0.0.0 = All local addresses)
|
|
149
|
+
def initialize(
|
|
150
|
+
dest_address,
|
|
151
|
+
dest_port,
|
|
152
|
+
src_port = nil,
|
|
153
|
+
multicast_interface_address = nil,
|
|
154
|
+
ttl = 1,
|
|
155
|
+
bind_address = "0.0.0.0"
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
super(
|
|
159
|
+
src_port,
|
|
160
|
+
bind_address,
|
|
161
|
+
dest_port,
|
|
162
|
+
dest_address,
|
|
163
|
+
multicast_interface_address,
|
|
164
|
+
ttl,
|
|
165
|
+
false,
|
|
166
|
+
true)
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# Creates a UDPSocket and implements a non-blocking read.
|
|
171
|
+
class UdpReadSocket < UdpReadWriteSocket
|
|
172
|
+
# @param recv_port [Integer] Port to receive data on
|
|
173
|
+
# @param multicast_address [String] Address to add multicast
|
|
174
|
+
# @param multicast_interface_address [String] Local incoming interface to receive multicast packets on
|
|
175
|
+
# @param bind_address [String] Local address to bind to (0.0.0.0 = All local addresses)
|
|
176
|
+
def initialize(
|
|
177
|
+
recv_port = 0,
|
|
178
|
+
multicast_address = nil,
|
|
179
|
+
multicast_interface_address = nil,
|
|
180
|
+
bind_address = "0.0.0.0"
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
super(
|
|
184
|
+
recv_port,
|
|
185
|
+
bind_address,
|
|
186
|
+
nil,
|
|
187
|
+
multicast_address,
|
|
188
|
+
multicast_interface_address,
|
|
189
|
+
1,
|
|
190
|
+
true,
|
|
191
|
+
false)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
end
|