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,193 @@
|
|
|
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/config/config_parser'
|
|
21
|
+
require 'openc3/interfaces/protocols/protocol'
|
|
22
|
+
require 'openc3/utilities/crc'
|
|
23
|
+
require 'thread'
|
|
24
|
+
|
|
25
|
+
module OpenC3
|
|
26
|
+
# Creates a CRC on write and verifies a CRC on read
|
|
27
|
+
class CrcProtocol < Protocol
|
|
28
|
+
ERROR = "ERROR" # on CRC mismatch
|
|
29
|
+
DISCONNECT = "DISCONNECT" # on CRC mismatch
|
|
30
|
+
|
|
31
|
+
# @param write_item_name [String/nil] Item to fill with calculated CRC value for outgoing packets (nil = don't fill)
|
|
32
|
+
# @param strip_crc [Boolean] Whether or not to remove the CRC from incoming packets
|
|
33
|
+
# @param bad_strategy [ERROR/DISCONNECT] How to handle CRC errors on incoming packets. ERROR = Just log the error, DISCONNECT = Disconnect interface
|
|
34
|
+
# @param bit_offset [Integer] Bit offset of the CRC in the data. Can be negative to indicate distance from end of packet
|
|
35
|
+
# @param bit_size [Integer] Bit size of the CRC - Must be 16, 32, or 64
|
|
36
|
+
# @param endianness [BIG_ENDIAN/LITTLE_ENDIAN] Endianness of the CRC
|
|
37
|
+
# @param poly [Integer] Polynomial to use when calculating the CRC
|
|
38
|
+
# @param seed [Integer] Seed value to start the calculation
|
|
39
|
+
# @param xor [Boolean] Whether to XOR the CRC result with 0xFFFF
|
|
40
|
+
# @param reflect [Boolean] Whether to bit reverse each byte of data before calculating the CRC
|
|
41
|
+
# @param allow_empty_data [true/false/nil] See Protocol#initialize
|
|
42
|
+
def initialize(
|
|
43
|
+
write_item_name = nil,
|
|
44
|
+
strip_crc = false,
|
|
45
|
+
bad_strategy = "ERROR",
|
|
46
|
+
bit_offset = -32,
|
|
47
|
+
bit_size = 32,
|
|
48
|
+
endianness = 'BIG_ENDIAN',
|
|
49
|
+
poly = nil,
|
|
50
|
+
seed = nil,
|
|
51
|
+
xor = nil,
|
|
52
|
+
reflect = nil,
|
|
53
|
+
allow_empty_data = nil
|
|
54
|
+
)
|
|
55
|
+
super(allow_empty_data)
|
|
56
|
+
@write_item_name = ConfigParser.handle_nil(write_item_name)
|
|
57
|
+
@strip_crc = ConfigParser.handle_true_false(strip_crc)
|
|
58
|
+
raise "Invalid strip CRC of '#{strip_crc}'. Must be TRUE or FALSE." unless !!@strip_crc == @strip_crc
|
|
59
|
+
|
|
60
|
+
case bad_strategy
|
|
61
|
+
when ERROR, DISCONNECT
|
|
62
|
+
@bad_strategy = bad_strategy
|
|
63
|
+
else
|
|
64
|
+
raise "Invalid bad CRC strategy of #{bad_strategy}. Must be ERROR or DISCONNECT."
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
case endianness.to_s.upcase
|
|
68
|
+
when 'BIG_ENDIAN'
|
|
69
|
+
@endianness = :BIG_ENDIAN # Convert to symbol for use in BinaryAccessor.write
|
|
70
|
+
when 'LITTLE_ENDIAN'
|
|
71
|
+
@endianness = :LITTLE_ENDIAN # Convert to symbol for use in BinaryAccessor.write
|
|
72
|
+
else
|
|
73
|
+
raise "Invalid endianness '#{endianness}'. Must be BIG_ENDIAN or LITTLE_ENDIAN."
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
begin
|
|
77
|
+
@bit_offset = Integer(bit_offset)
|
|
78
|
+
rescue
|
|
79
|
+
raise "Invalid bit offset of #{bit_offset}. Must be a number."
|
|
80
|
+
end
|
|
81
|
+
raise "Invalid bit offset of #{bit_offset}. Must be divisible by 8." if @bit_offset % 8 != 0
|
|
82
|
+
|
|
83
|
+
poly = ConfigParser.handle_nil(poly)
|
|
84
|
+
begin
|
|
85
|
+
poly = Integer(poly) if poly
|
|
86
|
+
rescue
|
|
87
|
+
raise "Invalid polynomial of #{poly}. Must be a number."
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
seed = ConfigParser.handle_nil(seed)
|
|
91
|
+
begin
|
|
92
|
+
seed = Integer(seed) if seed
|
|
93
|
+
rescue
|
|
94
|
+
raise "Invalid seed of #{seed}. Must be a number."
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
xor = ConfigParser.handle_true_false_nil(xor)
|
|
98
|
+
raise "Invalid XOR value of '#{xor}'. Must be TRUE or FALSE." if xor && !!xor != xor
|
|
99
|
+
|
|
100
|
+
reflect = ConfigParser.handle_true_false_nil(reflect) if reflect
|
|
101
|
+
raise "Invalid reflect value of '#{reflect}'. Must be TRUE or FALSE." if reflect && !!reflect != reflect
|
|
102
|
+
|
|
103
|
+
# Built the CRC arguments array. All subsequent arguments are dependent
|
|
104
|
+
# on the previous ones so we build it up incrementally.
|
|
105
|
+
args = []
|
|
106
|
+
if poly
|
|
107
|
+
args << poly
|
|
108
|
+
if seed
|
|
109
|
+
args << seed
|
|
110
|
+
unless xor.nil? # Can't check raw variable because it could be false
|
|
111
|
+
args << xor
|
|
112
|
+
unless reflect.nil? # Can't check raw variable because it could be false
|
|
113
|
+
args << reflect
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
@bit_size = bit_size.to_i
|
|
120
|
+
case @bit_size
|
|
121
|
+
when 16
|
|
122
|
+
@pack = (@endianness == :BIG_ENDIAN) ? 'n' : 'v'
|
|
123
|
+
if args.empty?
|
|
124
|
+
@crc = Crc16.new
|
|
125
|
+
else
|
|
126
|
+
@crc = Crc16.new(*args)
|
|
127
|
+
end
|
|
128
|
+
when 32
|
|
129
|
+
@pack = (@endianness == :BIG_ENDIAN) ? 'N' : 'V'
|
|
130
|
+
if args.empty?
|
|
131
|
+
@crc = Crc32.new
|
|
132
|
+
else
|
|
133
|
+
@crc = Crc32.new(*args)
|
|
134
|
+
end
|
|
135
|
+
when 64
|
|
136
|
+
@pack = (@endianness == :BIG_ENDIAN) ? 'N' : 'V'
|
|
137
|
+
if args.empty?
|
|
138
|
+
@crc = Crc64.new
|
|
139
|
+
else
|
|
140
|
+
@crc = Crc64.new(*args)
|
|
141
|
+
end
|
|
142
|
+
else
|
|
143
|
+
raise "Invalid bit size of #{bit_size}. Must be 16, 32, or 64."
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def read_data(data)
|
|
148
|
+
return super(data) if data.length <= 0
|
|
149
|
+
|
|
150
|
+
crc = BinaryAccessor.read(@bit_offset, @bit_size, :UINT, data, @endianness)
|
|
151
|
+
calculated_crc = @crc.calc(data[0...(@bit_offset / 8)])
|
|
152
|
+
if calculated_crc != crc
|
|
153
|
+
Logger.error "#{@interface ? @interface.name : ""}: Invalid CRC detected! Calculated 0x#{calculated_crc.to_s(16).upcase} vs found 0x#{crc.to_s(16).upcase}."
|
|
154
|
+
if @bad_strategy == DISCONNECT
|
|
155
|
+
return :DISCONNECT
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
if @strip_crc
|
|
159
|
+
new_data = data.dup
|
|
160
|
+
new_data = new_data[0...(@bit_offset / 8)]
|
|
161
|
+
end_range = (@bit_offset + @bit_size) / 8
|
|
162
|
+
new_data << data[end_range..-1] if end_range != 0
|
|
163
|
+
return new_data
|
|
164
|
+
end
|
|
165
|
+
return data
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def write_packet(packet)
|
|
169
|
+
if @write_item_name
|
|
170
|
+
end_range = packet.get_item(@write_item_name).bit_offset / 8
|
|
171
|
+
crc = @crc.calc(packet.buffer(false)[0...end_range])
|
|
172
|
+
packet.write(@write_item_name, crc)
|
|
173
|
+
end
|
|
174
|
+
packet
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def write_data(data)
|
|
178
|
+
unless @write_item_name
|
|
179
|
+
if @bit_size == 64
|
|
180
|
+
crc = @crc.calc(data)
|
|
181
|
+
data << ("\x00" * 8)
|
|
182
|
+
BinaryAccessor.write((crc >> 32), -64, 32, :UINT, data, @endianness, :ERROR)
|
|
183
|
+
BinaryAccessor.write((crc & 0xFFFFFFFF), -32, 32, :UINT, data, @endianness, :ERROR)
|
|
184
|
+
else
|
|
185
|
+
crc = @crc.calc(data)
|
|
186
|
+
data << ("\x00" * (@bit_size / 8))
|
|
187
|
+
BinaryAccessor.write(crc, -@bit_size, @bit_size, :UINT, data, @endianness, :ERROR)
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
data
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
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/config/config_parser'
|
|
21
|
+
require 'openc3/interfaces/protocols/burst_protocol'
|
|
22
|
+
|
|
23
|
+
module OpenC3
|
|
24
|
+
# Delineates packets by identifying them and then
|
|
25
|
+
# reading out their entire fixed length. Packets lengths can vary but
|
|
26
|
+
# they must all be fixed.
|
|
27
|
+
class FixedProtocol < BurstProtocol
|
|
28
|
+
# @param min_id_size [Integer] The minimum amount of data needed to
|
|
29
|
+
# identify a packet.
|
|
30
|
+
# @param discard_leading_bytes (see BurstProtocol#initialize)
|
|
31
|
+
# @param sync_pattern (see BurstProtocol#initialize)
|
|
32
|
+
# @param telemetry [Boolean] Whether the interface is returning
|
|
33
|
+
# telemetry (true) or commands (false)
|
|
34
|
+
# @param fill_fields (see BurstProtocol#initialize)
|
|
35
|
+
# @param unknown_raise Whether to raise an exception on an unknown packet
|
|
36
|
+
# @param allow_empty_data [true/false/nil] See Protocol#initialize
|
|
37
|
+
def initialize(
|
|
38
|
+
min_id_size,
|
|
39
|
+
discard_leading_bytes = 0,
|
|
40
|
+
sync_pattern = nil,
|
|
41
|
+
telemetry = true,
|
|
42
|
+
fill_fields = false,
|
|
43
|
+
unknown_raise = false,
|
|
44
|
+
allow_empty_data = nil
|
|
45
|
+
)
|
|
46
|
+
super(discard_leading_bytes, sync_pattern, fill_fields, allow_empty_data)
|
|
47
|
+
@min_id_size = Integer(min_id_size)
|
|
48
|
+
@telemetry = telemetry
|
|
49
|
+
@unknown_raise = ConfigParser.handle_true_false(unknown_raise)
|
|
50
|
+
@received_time = nil
|
|
51
|
+
@target_name = nil
|
|
52
|
+
@packet_name = nil
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Set the received_time, target_name and packet_name which we recorded when
|
|
56
|
+
# we identified this packet. The server will also do this but since we know
|
|
57
|
+
# the information here, we perform this optimization.
|
|
58
|
+
def read_packet(packet)
|
|
59
|
+
packet.received_time = @received_time
|
|
60
|
+
packet.target_name = @target_name
|
|
61
|
+
packet.packet_name = @packet_name
|
|
62
|
+
return packet
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
protected
|
|
66
|
+
|
|
67
|
+
# Identifies an unknown buffer of data as a Packet. The raw data is
|
|
68
|
+
# returned but the packet that matched is recorded so it can be set in the
|
|
69
|
+
# read_packet callback.
|
|
70
|
+
#
|
|
71
|
+
# @return [String|Symbol] The identified packet data or :STOP if more data
|
|
72
|
+
# is required to build a packet
|
|
73
|
+
def identify_and_finish_packet
|
|
74
|
+
packet_data = nil
|
|
75
|
+
identified_packet = nil
|
|
76
|
+
|
|
77
|
+
@interface.target_names.each do |target_name|
|
|
78
|
+
target_packets = nil
|
|
79
|
+
unique_id_mode = false
|
|
80
|
+
begin
|
|
81
|
+
if @telemetry
|
|
82
|
+
target_packets = System.telemetry.packets(target_name)
|
|
83
|
+
target = System.targets[target_name]
|
|
84
|
+
unique_id_mode = target.tlm_unique_id_mode if target
|
|
85
|
+
else
|
|
86
|
+
target_packets = System.commands.packets(target_name)
|
|
87
|
+
target = System.targets[target_name]
|
|
88
|
+
unique_id_mode = target.cmd_unique_id_mode if target
|
|
89
|
+
end
|
|
90
|
+
rescue RuntimeError
|
|
91
|
+
# No commands/telemetry for this target
|
|
92
|
+
next
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
if unique_id_mode
|
|
96
|
+
target_packets.each do |packet_name, packet|
|
|
97
|
+
if packet.identify?(@data[@discard_leading_bytes..-1])
|
|
98
|
+
identified_packet = packet
|
|
99
|
+
break
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
else
|
|
103
|
+
# Do a hash lookup to quickly identify the packet
|
|
104
|
+
if target_packets.length > 0
|
|
105
|
+
packet = target_packets.first[1]
|
|
106
|
+
key = packet.read_id_values(@data[@discard_leading_bytes..-1])
|
|
107
|
+
if @telemetry
|
|
108
|
+
hash = System.telemetry.config.tlm_id_value_hash[target_name]
|
|
109
|
+
else
|
|
110
|
+
hash = System.commands.config.cmd_id_value_hash[target_name]
|
|
111
|
+
end
|
|
112
|
+
identified_packet = hash[key]
|
|
113
|
+
identified_packet = hash['CATCHALL'.freeze] unless identified_packet
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
if identified_packet
|
|
118
|
+
if identified_packet.defined_length + @discard_leading_bytes > @data.length
|
|
119
|
+
# Check if need more data to finish packet
|
|
120
|
+
return :STOP
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Set some variables so we can update the packet in
|
|
124
|
+
# read_packet
|
|
125
|
+
@received_time = Time.now.sys
|
|
126
|
+
@target_name = identified_packet.target_name
|
|
127
|
+
@packet_name = identified_packet.packet_name
|
|
128
|
+
|
|
129
|
+
# Get the data from this packet
|
|
130
|
+
packet_data = @data.slice!(0, identified_packet.defined_length + @discard_leading_bytes)
|
|
131
|
+
break
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
unless identified_packet
|
|
136
|
+
raise "Unknown data received by FixedProtocol" if @unknown_raise
|
|
137
|
+
|
|
138
|
+
# Unknown packet? Just return all the current data
|
|
139
|
+
@received_time = nil
|
|
140
|
+
@target_name = nil
|
|
141
|
+
@packet_name = nil
|
|
142
|
+
packet_data = @data.clone
|
|
143
|
+
@data.replace('')
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
return packet_data
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def reduce_to_single_packet
|
|
150
|
+
return :STOP if @data.length < @min_id_size
|
|
151
|
+
|
|
152
|
+
identify_and_finish_packet()
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
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/config/config_parser'
|
|
21
|
+
require 'openc3/interfaces/protocols/protocol'
|
|
22
|
+
require 'openc3/utilities/crc'
|
|
23
|
+
require 'thread'
|
|
24
|
+
|
|
25
|
+
module OpenC3
|
|
26
|
+
# Ignore a specific packet by not letting it through the protocol
|
|
27
|
+
class IgnorePacketProtocol < Protocol
|
|
28
|
+
# @param target_name [String] Target name
|
|
29
|
+
# @param packet_name [String] Packet name
|
|
30
|
+
def initialize(target_name, packet_name, allow_empty_data = nil)
|
|
31
|
+
super(allow_empty_data)
|
|
32
|
+
System.telemetry.packet(target_name, packet_name)
|
|
33
|
+
@target_name = target_name
|
|
34
|
+
@packet_name = packet_name
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def read_packet(packet)
|
|
38
|
+
# Need to make sure packet is identified and defined
|
|
39
|
+
target_names = nil
|
|
40
|
+
target_names = @interface.target_names if @interface
|
|
41
|
+
identified_packet = System.telemetry.identify_and_define_packet(packet, target_names)
|
|
42
|
+
if identified_packet
|
|
43
|
+
if identified_packet.target_name == @target_name && identified_packet.packet_name == @packet_name
|
|
44
|
+
return :STOP
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
return super(packet)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def write_packet(packet)
|
|
51
|
+
return :STOP if packet.target_name == @target_name && packet.packet_name == @packet_name
|
|
52
|
+
|
|
53
|
+
return super(packet)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# encoding: ascii-8bit
|
|
2
|
+
|
|
3
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
|
7
|
+
# under the terms of the GNU Affero General Public License
|
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU Affero General Public License for more details.
|
|
15
|
+
|
|
16
|
+
# Modified by OpenC3, Inc.
|
|
17
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
18
|
+
# All Rights Reserved
|
|
19
|
+
|
|
20
|
+
require 'openc3/packets/binary_accessor'
|
|
21
|
+
require 'openc3/interfaces/protocols/burst_protocol'
|
|
22
|
+
require 'openc3/config/config_parser'
|
|
23
|
+
|
|
24
|
+
module OpenC3
|
|
25
|
+
# Protocol which delineates packets using a length field at a fixed
|
|
26
|
+
# location in each packet.
|
|
27
|
+
class LengthProtocol < BurstProtocol
|
|
28
|
+
# @param length_bit_offset [Integer] The bit offset of the length field
|
|
29
|
+
# @param length_bit_size [Integer] The size in bits of the length field
|
|
30
|
+
# @param length_value_offset [Integer] The offset to apply to the length
|
|
31
|
+
# value once it has been read from the packet. The value in the length
|
|
32
|
+
# field itself plus the length value offset MUST equal the total bytes
|
|
33
|
+
# including any discarded bytes.
|
|
34
|
+
# For example: if your length field really means "length - 1" this value should be 1.
|
|
35
|
+
# @param length_bytes_per_count [Integer] The number of bytes per each
|
|
36
|
+
# length field 'count'. This is used if the units of the length field is
|
|
37
|
+
# something other than bytes, for example words.
|
|
38
|
+
# @param length_endianness [String] The endianness of the length field.
|
|
39
|
+
# Must be either BIG_ENDIAN or LITTLE_ENDIAN.
|
|
40
|
+
# @param discard_leading_bytes (see BurstProtocol#initialize)
|
|
41
|
+
# @param sync_pattern (see BurstProtocol#initialize)
|
|
42
|
+
# @param max_length [Integer] The maximum allowed value of the length field
|
|
43
|
+
# @param fill_length_and_sync_pattern [Boolean] Fill the length field and sync
|
|
44
|
+
# pattern when writing packets
|
|
45
|
+
# @param allow_empty_data [true/false/nil] See Protocol#initialize
|
|
46
|
+
def initialize(
|
|
47
|
+
length_bit_offset = 0,
|
|
48
|
+
length_bit_size = 16,
|
|
49
|
+
length_value_offset = 0,
|
|
50
|
+
length_bytes_per_count = 1,
|
|
51
|
+
length_endianness = 'BIG_ENDIAN',
|
|
52
|
+
discard_leading_bytes = 0,
|
|
53
|
+
sync_pattern = nil,
|
|
54
|
+
max_length = nil,
|
|
55
|
+
fill_length_and_sync_pattern = false,
|
|
56
|
+
allow_empty_data = nil
|
|
57
|
+
)
|
|
58
|
+
super(discard_leading_bytes, sync_pattern, fill_length_and_sync_pattern, allow_empty_data)
|
|
59
|
+
|
|
60
|
+
# Save length field attributes
|
|
61
|
+
@length_bit_offset = Integer(length_bit_offset)
|
|
62
|
+
@length_bit_size = Integer(length_bit_size)
|
|
63
|
+
@length_value_offset = Integer(length_value_offset)
|
|
64
|
+
@length_bytes_per_count = Integer(length_bytes_per_count)
|
|
65
|
+
|
|
66
|
+
# Save endianness
|
|
67
|
+
if length_endianness.to_s.upcase == 'LITTLE_ENDIAN'
|
|
68
|
+
@length_endianness = :LITTLE_ENDIAN
|
|
69
|
+
else
|
|
70
|
+
@length_endianness = :BIG_ENDIAN
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Derive number of bytes required to contain entire length field
|
|
74
|
+
if @length_endianness == :BIG_ENDIAN or ((@length_bit_offset % 8) == 0)
|
|
75
|
+
length_bits_needed = @length_bit_offset + @length_bit_size
|
|
76
|
+
length_bits_needed += 8 if (length_bits_needed % 8) != 0
|
|
77
|
+
@length_bytes_needed = ((length_bits_needed - 1) / 8) + 1
|
|
78
|
+
else
|
|
79
|
+
@length_bytes_needed = (length_bit_offset / 8) + 1
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Save max length setting
|
|
83
|
+
@max_length = ConfigParser.handle_nil(max_length)
|
|
84
|
+
@max_length = Integer(@max_length) if @max_length
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Called to perform modifications on a command packet before it is send
|
|
88
|
+
#
|
|
89
|
+
# @param packet [Packet] Original packet
|
|
90
|
+
# @return [Packet] Potentially modified packet
|
|
91
|
+
def write_packet(packet)
|
|
92
|
+
if @fill_fields
|
|
93
|
+
# If the start of the length field is past what we discard, then the
|
|
94
|
+
# length field is inside the packet
|
|
95
|
+
if @length_bit_offset >= (@discard_leading_bytes * 8)
|
|
96
|
+
length = calculate_length(packet.buffer.length + @discard_leading_bytes)
|
|
97
|
+
# Subtract off the discarded bytes since they haven't been added yet
|
|
98
|
+
# Adding bytes happens in the write_data method
|
|
99
|
+
offset = @length_bit_offset - (@discard_leading_bytes * 8)
|
|
100
|
+
# Directly write the packet buffer and fill in the length
|
|
101
|
+
BinaryAccessor.write(length, offset, @length_bit_size, :UINT,
|
|
102
|
+
packet.buffer(false), @length_endianness, :ERROR)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
return super(packet) # Allow burst_protocol to set the sync if needed
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Called to perform modifications on write data before making it into a packet
|
|
109
|
+
#
|
|
110
|
+
# @param data [String] Raw packet data
|
|
111
|
+
# @return [String] Potentially modified packet data
|
|
112
|
+
def write_data(data)
|
|
113
|
+
data = super(data)
|
|
114
|
+
if @fill_fields
|
|
115
|
+
# If the start of the length field is before what we discard, then the
|
|
116
|
+
# length field is outside the packet
|
|
117
|
+
if @length_bit_offset < (@discard_leading_bytes * 8)
|
|
118
|
+
BinaryAccessor.write(calculate_length(data.length), @length_bit_offset, @length_bit_size, :UINT,
|
|
119
|
+
data, @length_endianness, :ERROR)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
return data
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
protected
|
|
126
|
+
|
|
127
|
+
def calculate_length(buffer_length)
|
|
128
|
+
length = (buffer_length / @length_bytes_per_count) - @length_value_offset
|
|
129
|
+
if @max_length && length > @max_length
|
|
130
|
+
raise "Calculated length #{length} larger than max_length #{@max_length}"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
length
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def reduce_to_single_packet
|
|
137
|
+
# Make sure we have at least enough data to reach the length field
|
|
138
|
+
return :STOP if @data.length < @length_bytes_needed
|
|
139
|
+
|
|
140
|
+
# Determine the packet's length
|
|
141
|
+
length = BinaryAccessor.read(@length_bit_offset,
|
|
142
|
+
@length_bit_size,
|
|
143
|
+
:UINT,
|
|
144
|
+
@data,
|
|
145
|
+
@length_endianness)
|
|
146
|
+
raise "Length value received larger than max_length: #{length} > #{@max_length}" if @max_length and length > @max_length
|
|
147
|
+
|
|
148
|
+
packet_length = (length * @length_bytes_per_count) + @length_value_offset
|
|
149
|
+
# Ensure the calculated packet length is long enough to support the location of the length field
|
|
150
|
+
# without overlap into the next packet
|
|
151
|
+
if (packet_length * 8) < (@length_bit_offset + @length_bit_size)
|
|
152
|
+
raise "Calculated packet length of #{packet_length * 8} bits < (offset:#{@length_bit_offset} + size:#{@length_bit_size})"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Make sure we have enough data for the packet
|
|
156
|
+
return :STOP if @data.length < packet_length
|
|
157
|
+
|
|
158
|
+
# Reduce to packet data and setup current_data for next packet
|
|
159
|
+
packet_data = @data[0..(packet_length - 1)]
|
|
160
|
+
@data.replace(@data[packet_length..-1])
|
|
161
|
+
|
|
162
|
+
return packet_data
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# encoding: ascii-8bit
|
|
2
|
+
|
|
3
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
|
7
|
+
# under the terms of the GNU Affero General Public License
|
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU Affero General Public License for more details.
|
|
15
|
+
|
|
16
|
+
# Modified by OpenC3, Inc.
|
|
17
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
18
|
+
# All Rights Reserved
|
|
19
|
+
|
|
20
|
+
require 'openc3/interfaces/protocols/protocol'
|
|
21
|
+
|
|
22
|
+
module OpenC3
|
|
23
|
+
# Protocol which permanently overrides an item value such that reading the
|
|
24
|
+
# item returns the overriden value. Methods are prefixed with underscores
|
|
25
|
+
# so the API can include the original name which calls out to these
|
|
26
|
+
# methods. Clearing the override requires calling normalize_tlm.
|
|
27
|
+
class OverrideProtocol < Protocol
|
|
28
|
+
# @param allow_empty_data [true/false/nil] See Protocol#initialize
|
|
29
|
+
def initialize(allow_empty_data = nil)
|
|
30
|
+
super(allow_empty_data)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Called to perform modifications on a read packet before it is given to the user
|
|
34
|
+
#
|
|
35
|
+
# @param packet [Packet] Original packet
|
|
36
|
+
# @return [Packet] Potentially modified packet
|
|
37
|
+
def read_packet(packet)
|
|
38
|
+
if @interface.override_tlm && !@interface.override_tlm.empty?
|
|
39
|
+
# Need to make sure packet is identified and defined
|
|
40
|
+
target_names = nil
|
|
41
|
+
target_names = @interface.target_names if @interface
|
|
42
|
+
identified_packet = System.telemetry.identify_and_define_packet(packet, target_names)
|
|
43
|
+
if identified_packet
|
|
44
|
+
packet = identified_packet
|
|
45
|
+
packets = @interface.override_tlm[packet.target_name]
|
|
46
|
+
if packets
|
|
47
|
+
items = packets[packet.packet_name]
|
|
48
|
+
if items
|
|
49
|
+
items.each do |item_name, value|
|
|
50
|
+
# This should be safe because we check at the API level it exists
|
|
51
|
+
packet.write(item_name, value[0], value[1])
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
return packet
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|