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,420 @@
|
|
|
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 'json'
|
|
21
|
+
require 'date'
|
|
22
|
+
|
|
23
|
+
class Object
|
|
24
|
+
def as_json(options = nil) #:nodoc:
|
|
25
|
+
if respond_to?(:to_hash)
|
|
26
|
+
to_hash
|
|
27
|
+
else
|
|
28
|
+
instance_variables
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Struct #:nodoc:
|
|
34
|
+
def as_json(options = nil)
|
|
35
|
+
pairs = []
|
|
36
|
+
self.each_pair { |k, v| pairs << k.to_s; pairs << v.as_json(options) }
|
|
37
|
+
Hash[*pairs]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class TrueClass
|
|
42
|
+
def as_json(options = nil) self end #:nodoc:
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class FalseClass
|
|
46
|
+
def as_json(options = nil) self end #:nodoc:
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class NilClass
|
|
50
|
+
def as_json(options = nil) self end #:nodoc:
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class String
|
|
54
|
+
NON_ASCII_PRINTABLE = /[^\x21-\x7e\s]/
|
|
55
|
+
|
|
56
|
+
def as_json(options = nil)
|
|
57
|
+
if NON_ASCII_PRINTABLE.match?(self)
|
|
58
|
+
self.to_json_raw_object
|
|
59
|
+
else
|
|
60
|
+
self
|
|
61
|
+
end
|
|
62
|
+
end #:nodoc:
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class Symbol
|
|
66
|
+
def as_json(options = nil) to_s end #:nodoc:
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class Numeric
|
|
70
|
+
def as_json(options = nil) self end #:nodoc:
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
class Float
|
|
74
|
+
def self.json_create(object)
|
|
75
|
+
case object['raw']
|
|
76
|
+
when "Infinity" then Float::INFINITY
|
|
77
|
+
when "-Infinity" then -Float::INFINITY
|
|
78
|
+
when "NaN" then Float::NAN
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def as_json(options = nil)
|
|
83
|
+
return { "json_class" => Float, "raw" => "Infinity" } if self.infinite? == 1
|
|
84
|
+
return { "json_class" => Float, "raw" => "-Infinity" } if self.infinite? == -1
|
|
85
|
+
return { "json_class" => Float, "raw" => "NaN" } if self.nan?
|
|
86
|
+
|
|
87
|
+
return self
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class Regexp
|
|
92
|
+
def as_json(options = nil) to_s end #:nodoc:
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
module Enumerable
|
|
96
|
+
def as_json(options = nil) #:nodoc:
|
|
97
|
+
to_a.as_json(options)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
class Array
|
|
102
|
+
def as_json(options = nil) #:nodoc:
|
|
103
|
+
map { |v| v.as_json(options) }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
class Hash
|
|
108
|
+
def as_json(options = nil) #:nodoc:
|
|
109
|
+
pairs = []
|
|
110
|
+
self.each { |k, v| pairs << k.to_s; pairs << v.as_json(options) }
|
|
111
|
+
Hash[*pairs]
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
class Time
|
|
116
|
+
def as_json(options = nil) #:nodoc:
|
|
117
|
+
to_json(options).remove_quotes
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
class Date
|
|
122
|
+
def as_json(options = nil) #:nodoc:
|
|
123
|
+
to_json(options).remove_quotes
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
class DateTime
|
|
128
|
+
def as_json(options = nil) #:nodoc:
|
|
129
|
+
to_json(options).remove_quotes
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class Exception
|
|
134
|
+
def as_json(*a)
|
|
135
|
+
hash = {}
|
|
136
|
+
hash['class'] = self.class.name
|
|
137
|
+
hash['message'] = self.message
|
|
138
|
+
hash['backtrace'] = self.backtrace
|
|
139
|
+
instance_vars = {}
|
|
140
|
+
self.instance_variables.each do |instance_var_name|
|
|
141
|
+
instance_vars[instance_var_name.to_s] = self.instance_variable_get(instance_var_name.to_s.intern)
|
|
142
|
+
end
|
|
143
|
+
hash['instance_variables'] = instance_vars
|
|
144
|
+
hash.as_json(*a)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def to_json(*a)
|
|
148
|
+
as_json(*a).to_json(*a)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def self.from_hash(hash)
|
|
152
|
+
begin
|
|
153
|
+
# Get Error class handling namespaced constants
|
|
154
|
+
split_error_class_name = hash['class'].split("::")
|
|
155
|
+
error_class = Object
|
|
156
|
+
split_error_class_name.each do |name|
|
|
157
|
+
error_class = error_class.const_get(name)
|
|
158
|
+
end
|
|
159
|
+
rescue
|
|
160
|
+
error = OpenC3::JsonDRbUnknownError.new(hash['message'])
|
|
161
|
+
error.set_backtrace(hash['backtrace'].concat(caller()))
|
|
162
|
+
raise error
|
|
163
|
+
end
|
|
164
|
+
error = error_class.new(hash['message'])
|
|
165
|
+
error.set_backtrace(hash['backtrace'].concat(caller())) if hash['backtrace']
|
|
166
|
+
hash['instance_variables'].each do |name, value|
|
|
167
|
+
error.instance_variable_set(name.intern, value)
|
|
168
|
+
end
|
|
169
|
+
error
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
module OpenC3
|
|
174
|
+
# An unknown JSON DRb error which can be re-raised by Exception
|
|
175
|
+
class JsonDRbUnknownError < StandardError; end
|
|
176
|
+
|
|
177
|
+
# Base class for all JSON Remote Procedure Calls. Provides basic
|
|
178
|
+
# comparison and Hash to JSON conversions.
|
|
179
|
+
class JsonRpc
|
|
180
|
+
include Comparable
|
|
181
|
+
|
|
182
|
+
def initialize
|
|
183
|
+
@hash = {}
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# @param other [JsonRpc] Another JsonRpc to compare hash values with
|
|
187
|
+
def <=>(other)
|
|
188
|
+
return nil unless other.respond_to?(:as_json)
|
|
189
|
+
|
|
190
|
+
self.as_json(:allow_nan => true) <=> other.as_json(:allow_nan => true)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# @param a [Array] Array of options
|
|
194
|
+
# @return [Hash] Hash representing the object
|
|
195
|
+
def as_json(*a)
|
|
196
|
+
@hash.as_json(*a)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# @param a [Array] Array of options
|
|
200
|
+
# @return [String] The JSON encoded String
|
|
201
|
+
def to_json(*a)
|
|
202
|
+
as_json(*a).to_json(*a)
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
# Represents a JSON Remote Procedure Call Request
|
|
207
|
+
class JsonRpcRequest < JsonRpc
|
|
208
|
+
DANGEROUS_METHODS = ['__send__', 'send', 'instance_eval', 'instance_exec']
|
|
209
|
+
|
|
210
|
+
# @param method_name [String] The name of the method to call
|
|
211
|
+
# @param method_params [Array<String>] Array of strings which represent the
|
|
212
|
+
# parameters to send to the method
|
|
213
|
+
# @param keyword_params [Hash<String, Variable>] Hash of key value keyword params
|
|
214
|
+
# @param id [Integer] The identifier which will be matched to the response
|
|
215
|
+
def initialize(method_name, method_params, keyword_params, id)
|
|
216
|
+
super()
|
|
217
|
+
@hash['jsonrpc'.freeze] = '2.0'.freeze
|
|
218
|
+
@hash['method'.freeze] = method_name.to_s
|
|
219
|
+
if method_params and method_params.length != 0
|
|
220
|
+
@hash['params'.freeze] = method_params
|
|
221
|
+
end
|
|
222
|
+
if keyword_params and keyword_params.length != 0
|
|
223
|
+
symbolized = {}
|
|
224
|
+
keyword_params.each do |key, value|
|
|
225
|
+
symbolized[key.intern] = value
|
|
226
|
+
end
|
|
227
|
+
@hash['keyword_params'.freeze] = symbolized
|
|
228
|
+
end
|
|
229
|
+
@hash['id'.freeze] = id.to_i
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# @return [String] The method to call
|
|
233
|
+
def method
|
|
234
|
+
@hash['method'.freeze]
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# @return [Array<String>] Array of strings which represent the
|
|
238
|
+
# parameters to send to the method
|
|
239
|
+
def params
|
|
240
|
+
@hash['params'.freeze] || []
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# @return [Hash<String, Variable>] Hash which represents the
|
|
244
|
+
# keyword parameters to send to the method
|
|
245
|
+
def keyword_params
|
|
246
|
+
@hash['keyword_params'.freeze]
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# @return [Integer] The request identifier
|
|
250
|
+
def id
|
|
251
|
+
@hash['id'.freeze]
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# Creates a JsonRpcRequest object from a JSON encoded String. The version
|
|
255
|
+
# must be 2.0 and the JSON must include the method and id members.
|
|
256
|
+
#
|
|
257
|
+
# @param request_data [String] JSON encoded string representing the request
|
|
258
|
+
# @param request_headers [Hash] Request Header to include the auth token
|
|
259
|
+
# @return [JsonRpcRequest]
|
|
260
|
+
def self.from_json(request_data, request_headers)
|
|
261
|
+
hash = JSON.parse(request_data, :allow_nan => true, :create_additions => true)
|
|
262
|
+
hash['keyword_params']['token'] = request_headers['HTTP_AUTHORIZATION'] if request_headers['HTTP_AUTHORIZATION']
|
|
263
|
+
# Verify the jsonrpc version is correct and there is a method and id
|
|
264
|
+
raise unless hash['jsonrpc'.freeze] == "2.0".freeze && hash['method'.freeze] && hash['id'.freeze]
|
|
265
|
+
|
|
266
|
+
self.from_hash(hash)
|
|
267
|
+
rescue
|
|
268
|
+
raise "Invalid JSON-RPC 2.0 Request\n#{request_data.inspect}\n"
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Creates a JsonRpcRequest object from a Hash
|
|
272
|
+
#
|
|
273
|
+
# @param hash [Hash] Hash containing the following keys: method, params,
|
|
274
|
+
# and id
|
|
275
|
+
# @return [JsonRpcRequest]
|
|
276
|
+
def self.from_hash(hash)
|
|
277
|
+
self.new(hash['method'.freeze], hash['params'.freeze], hash['keyword_params'.freeze], hash['id'.freeze])
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Represents a JSON Remote Procedure Call Response
|
|
282
|
+
class JsonRpcResponse < JsonRpc
|
|
283
|
+
# @param id [Integer] The identifier which will be matched to the request
|
|
284
|
+
def initialize(id)
|
|
285
|
+
super()
|
|
286
|
+
@hash['jsonrpc'.freeze] = "2.0".freeze
|
|
287
|
+
@hash['id'.freeze] = id
|
|
288
|
+
end
|
|
289
|
+
|
|
290
|
+
# Creates a JsonRpcResponse object from a JSON encoded String. The version
|
|
291
|
+
# must be 2.0 and the JSON must include the id members. It must also
|
|
292
|
+
# include either result for success or error for failure but never both.
|
|
293
|
+
#
|
|
294
|
+
# @param response_data [String] JSON encoded string representing the response
|
|
295
|
+
# @return [JsonRpcResponse]
|
|
296
|
+
def self.from_json(response_data)
|
|
297
|
+
msg = "Invalid JSON-RPC 2.0 Response#{response_data.inspect}\n"
|
|
298
|
+
begin
|
|
299
|
+
hash = JSON.parse(response_data, :allow_nan => true, :create_additions => true)
|
|
300
|
+
rescue
|
|
301
|
+
raise $!, msg, $!.backtrace
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
# Verify the jsonrpc version is correct and there is an ID
|
|
305
|
+
raise msg unless hash['jsonrpc'.freeze] == "2.0".freeze and hash.key?('id'.freeze)
|
|
306
|
+
|
|
307
|
+
# If there is a result this is probably a good response
|
|
308
|
+
if hash.key?('result'.freeze)
|
|
309
|
+
# Can't have an error key in a good response
|
|
310
|
+
raise msg if hash.key?('error'.freeze)
|
|
311
|
+
|
|
312
|
+
JsonRpcSuccessResponse.from_hash(hash)
|
|
313
|
+
elsif hash.key?('error'.freeze)
|
|
314
|
+
# There was an error key so create an error response
|
|
315
|
+
JsonRpcErrorResponse.from_hash(hash)
|
|
316
|
+
else
|
|
317
|
+
# Neither a result or error key so raise exception
|
|
318
|
+
raise msg
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
# Represents a JSON Remote Procedure Call Success Response
|
|
324
|
+
class JsonRpcSuccessResponse < JsonRpcResponse
|
|
325
|
+
# @param id [Integer] The identifier which will be matched to the request
|
|
326
|
+
def initialize(result, id)
|
|
327
|
+
super(id)
|
|
328
|
+
@hash['result'.freeze] = result
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
# @return [Object] The result of the method request
|
|
332
|
+
def result
|
|
333
|
+
@hash['result'.freeze]
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
# Creates a JsonRpcSuccessResponse object from a Hash
|
|
337
|
+
#
|
|
338
|
+
# @param hash [Hash] Hash containing the following keys: result and id
|
|
339
|
+
# @return [JsonRpcSuccessResponse]
|
|
340
|
+
def self.from_hash(hash)
|
|
341
|
+
self.new(hash['result'.freeze], hash['id'.freeze])
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# Represents a JSON Remote Procedure Call Error Response
|
|
346
|
+
class JsonRpcErrorResponse < JsonRpcResponse
|
|
347
|
+
# @param error [JsonRpcError] The error object
|
|
348
|
+
# @param id [Integer] The identifier which will be matched to the request
|
|
349
|
+
def initialize(error, id)
|
|
350
|
+
super(id)
|
|
351
|
+
@hash['error'.freeze] = error
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# @return [JsonRpcError] The error object
|
|
355
|
+
def error
|
|
356
|
+
@hash['error'.freeze]
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# Creates a JsonRpcErrorResponse object from a Hash
|
|
360
|
+
#
|
|
361
|
+
# @param hash [Hash] Hash containing the following keys: error and id
|
|
362
|
+
# @return [JsonRpcErrorResponse]
|
|
363
|
+
def self.from_hash(hash)
|
|
364
|
+
self.new(JsonRpcError.from_hash(hash['error'.freeze]), hash['id'.freeze])
|
|
365
|
+
end
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
# Represents a JSON Remote Procedure Call Error
|
|
369
|
+
class JsonRpcError < JsonRpc
|
|
370
|
+
# Enumeration of JSON RPC error codes
|
|
371
|
+
class ErrorCode
|
|
372
|
+
PARSE_ERROR = -32700
|
|
373
|
+
INVALID_REQUEST = -32600
|
|
374
|
+
METHOD_NOT_FOUND = -32601
|
|
375
|
+
INVALID_PARAMS = -32602
|
|
376
|
+
INTERNAL_ERROR = -32603
|
|
377
|
+
AUTH_ERROR = -32500
|
|
378
|
+
FORBIDDEN_ERROR = -32501
|
|
379
|
+
OTHER_ERROR = -1
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
# @param code [Integer] The error type that occurred
|
|
383
|
+
# @param message [String] A short description of the error
|
|
384
|
+
# @param data [Hash] Additional information about the error
|
|
385
|
+
def initialize(code, message, data = nil)
|
|
386
|
+
super()
|
|
387
|
+
@hash['code'] = code
|
|
388
|
+
@hash['message'] = message
|
|
389
|
+
@hash['data'] = data
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
# @return [Integer] The error type that occurred
|
|
393
|
+
def code
|
|
394
|
+
@hash['code']
|
|
395
|
+
end
|
|
396
|
+
|
|
397
|
+
# @return [String] A short description of the error
|
|
398
|
+
def message
|
|
399
|
+
@hash['message']
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
# @return [Hash] Additional information about the error
|
|
403
|
+
def data
|
|
404
|
+
@hash['data']
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# Creates a JsonRpcError object from a Hash
|
|
408
|
+
#
|
|
409
|
+
# @param hash [Hash] Hash containing the following keys: code, message, and
|
|
410
|
+
# optionally data
|
|
411
|
+
# @return [JsonRpcError]
|
|
412
|
+
def self.from_hash(hash)
|
|
413
|
+
if hash['code'] and (hash['code'].to_i == hash['code']) and hash['message']
|
|
414
|
+
self.new(hash['code'], hash['message'], hash['data'])
|
|
415
|
+
else
|
|
416
|
+
raise "Invalid JSON-RPC 2.0 Error\n#{hash.inspect}\n"
|
|
417
|
+
end
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
# This file updates the Ruby SNMP gem for non-blocking sockets
|
|
21
|
+
# to work around potential process lockups.
|
|
22
|
+
#
|
|
23
|
+
# Known to work with SNMP Version 1.0.2
|
|
24
|
+
|
|
25
|
+
# Note requires SNMP Ruby Gem - gem install snmp
|
|
26
|
+
require 'snmp'
|
|
27
|
+
|
|
28
|
+
old_verbose = $VERBOSE; $VERBOSE = nil
|
|
29
|
+
module SNMP
|
|
30
|
+
class UDPTransport
|
|
31
|
+
def recv(max_bytes)
|
|
32
|
+
# Implement blocking using recvfrom_nonblock to prevent potential
|
|
33
|
+
# ruby thread deadlock
|
|
34
|
+
|
|
35
|
+
data, host_info = @socket.recvfrom_nonblock(max_bytes)
|
|
36
|
+
return data
|
|
37
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
|
38
|
+
IO.fast_select([@socket])
|
|
39
|
+
retry
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class UDPServerTransport
|
|
44
|
+
def recvfrom(max_bytes)
|
|
45
|
+
# Implement blocking using recvfrom_nonblock to prevent potential
|
|
46
|
+
# ruby thread deadlock
|
|
47
|
+
begin
|
|
48
|
+
data, host_info = @socket.recvfrom_nonblock(max_bytes)
|
|
49
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
|
50
|
+
IO.fast_select([@socket])
|
|
51
|
+
retry
|
|
52
|
+
end
|
|
53
|
+
flags, host_port, host_name, host_ip = host_info
|
|
54
|
+
return data, host_ip, host_port
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
$VERBOSE = old_verbose
|
|
@@ -0,0 +1,156 @@
|
|
|
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 'fcntl'
|
|
21
|
+
require 'termios' # Requires ruby-termios gem
|
|
22
|
+
require 'timeout' # For Timeout::Error
|
|
23
|
+
|
|
24
|
+
module OpenC3
|
|
25
|
+
# Serial driver for use on Posix serial ports found on UNIX based systems
|
|
26
|
+
class PosixSerialDriver
|
|
27
|
+
# (see SerialDriver#initialize)
|
|
28
|
+
def initialize(port_name = '/dev/ttyS0',
|
|
29
|
+
baud_rate = 9600,
|
|
30
|
+
parity = :NONE,
|
|
31
|
+
stop_bits = 1,
|
|
32
|
+
write_timeout = 10.0,
|
|
33
|
+
read_timeout = nil,
|
|
34
|
+
flow_control = :NONE,
|
|
35
|
+
data_bits = 8)
|
|
36
|
+
|
|
37
|
+
# Convert Baud Rate into Termios constant
|
|
38
|
+
begin
|
|
39
|
+
baud_rate = Object.const_get("Termios::B#{baud_rate}")
|
|
40
|
+
rescue NameError
|
|
41
|
+
raise(ArgumentError, "Invalid Baud Rate, Not Defined by Termios: #{baud_rate}")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Verify Parameters
|
|
45
|
+
raise(ArgumentError, "Invalid Data Bits: #{data_bits}") unless [5, 6, 7, 8].include?(data_bits)
|
|
46
|
+
raise(ArgumentError, "Invalid parity: #{parity}") if parity and !SerialDriver::VALID_PARITY.include?(parity)
|
|
47
|
+
raise(ArgumentError, "Invalid Stop Bits: #{stop_bits}") unless [1, 2].include?(stop_bits)
|
|
48
|
+
|
|
49
|
+
@write_timeout = write_timeout
|
|
50
|
+
@read_timeout = read_timeout
|
|
51
|
+
|
|
52
|
+
parity = nil if parity == :NONE
|
|
53
|
+
|
|
54
|
+
# Open the serial Port
|
|
55
|
+
@handle = Kernel.open(port_name, File::RDWR | File::NONBLOCK)
|
|
56
|
+
flags = @handle.fcntl(Fcntl::F_GETFL, 0)
|
|
57
|
+
@handle.fcntl(Fcntl::F_SETFL, flags & ~File::NONBLOCK)
|
|
58
|
+
@handle.extend Termios
|
|
59
|
+
|
|
60
|
+
# Configure the serial Port
|
|
61
|
+
tio = Termios.new_termios()
|
|
62
|
+
iflags = 0
|
|
63
|
+
iflags |= Termios::IGNPAR unless parity
|
|
64
|
+
cflags = 0
|
|
65
|
+
cflags |= Termios::CREAD # Enable receiver
|
|
66
|
+
cflags |= Termios.const_get("CS#{data_bits}") # data bits
|
|
67
|
+
cflags |= Termios::CLOCAL # Ignore Modem Control Lines
|
|
68
|
+
cflags |= Termios::CSTOPB if stop_bits == 2
|
|
69
|
+
cflags |= Termios::PARENB if parity
|
|
70
|
+
cflags |= Termios::PARODD if parity == :ODD
|
|
71
|
+
cflags |= Termios::CRTSCTS if flow_control == :RTSCTS
|
|
72
|
+
tio.iflag = iflags
|
|
73
|
+
tio.oflag = 0
|
|
74
|
+
tio.cflag = cflags
|
|
75
|
+
tio.lflag = 0
|
|
76
|
+
tio.cc[Termios::VTIME] = 0
|
|
77
|
+
tio.cc[Termios::VMIN] = 1
|
|
78
|
+
tio.ispeed = baud_rate
|
|
79
|
+
tio.ospeed = baud_rate
|
|
80
|
+
@handle.tcflush(Termios::TCIOFLUSH)
|
|
81
|
+
@handle.tcsetattr(Termios::TCSANOW, tio)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# (see SerialDriver#close)
|
|
85
|
+
def close
|
|
86
|
+
if @handle
|
|
87
|
+
# Close the serial Port
|
|
88
|
+
@handle.close
|
|
89
|
+
@handle = nil
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# (see SerialDriver#closed?)
|
|
94
|
+
def closed?
|
|
95
|
+
if @handle
|
|
96
|
+
false
|
|
97
|
+
else
|
|
98
|
+
true
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# (see SerialDriver#write)
|
|
103
|
+
def write(data)
|
|
104
|
+
num_bytes_to_send = data.length
|
|
105
|
+
total_bytes_sent = 0
|
|
106
|
+
bytes_sent = 0
|
|
107
|
+
data_to_send = data
|
|
108
|
+
|
|
109
|
+
loop do
|
|
110
|
+
begin
|
|
111
|
+
bytes_sent = @handle.write_nonblock(data_to_send)
|
|
112
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
|
113
|
+
result = IO.fast_select(nil, [@handle], nil, @write_timeout)
|
|
114
|
+
if result
|
|
115
|
+
retry
|
|
116
|
+
else
|
|
117
|
+
raise Timeout::Error, "Write Timeout"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
total_bytes_sent += bytes_sent
|
|
121
|
+
break if total_bytes_sent >= num_bytes_to_send
|
|
122
|
+
|
|
123
|
+
data_to_send = data[total_bytes_sent..-1]
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# (see SerialDriver#read)
|
|
128
|
+
def read
|
|
129
|
+
begin
|
|
130
|
+
data = @handle.read_nonblock(65535)
|
|
131
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
|
132
|
+
result = IO.fast_select([@handle], nil, nil, @read_timeout)
|
|
133
|
+
if result
|
|
134
|
+
retry
|
|
135
|
+
else
|
|
136
|
+
raise Timeout::Error, "Read Timeout"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
data
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# (see SerialDriver#read_nonblock)
|
|
144
|
+
def read_nonblock
|
|
145
|
+
data = ''
|
|
146
|
+
|
|
147
|
+
begin
|
|
148
|
+
data = @handle.read_nonblock(65535)
|
|
149
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
|
150
|
+
# Do Nothing
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
data
|
|
154
|
+
end
|
|
155
|
+
end # class PosixSerialDriver
|
|
156
|
+
end
|