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,351 @@
|
|
|
1
|
+
/*
|
|
2
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
3
|
+
# All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can modify and/or redistribute it
|
|
6
|
+
# under the terms of the GNU Affero General Public License
|
|
7
|
+
# as published by the Free Software Foundation; version 3 with
|
|
8
|
+
# attribution addendums as found in the LICENSE.txt
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Affero General Public License for more details.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
# Modified by OpenC3, Inc.
|
|
18
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
19
|
+
# All Rights Reserved
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "ruby.h"
|
|
23
|
+
#include "stdio.h"
|
|
24
|
+
|
|
25
|
+
VALUE mOpenC3;
|
|
26
|
+
VALUE cCrc;
|
|
27
|
+
VALUE cCrc16;
|
|
28
|
+
VALUE cCrc32;
|
|
29
|
+
VALUE cCrc64;
|
|
30
|
+
|
|
31
|
+
static ID id_ivar_seed = 0;
|
|
32
|
+
static ID id_ivar_xor = 0;
|
|
33
|
+
static ID id_ivar_reflect = 0;
|
|
34
|
+
static ID id_ivar_table = 0;
|
|
35
|
+
|
|
36
|
+
static const unsigned char BIT_REVERSE_TABLE[] =
|
|
37
|
+
{
|
|
38
|
+
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
|
39
|
+
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
|
40
|
+
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
|
41
|
+
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
|
42
|
+
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
|
43
|
+
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
|
44
|
+
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
|
45
|
+
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
|
46
|
+
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
|
47
|
+
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
|
48
|
+
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
|
49
|
+
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
|
50
|
+
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
|
51
|
+
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
|
52
|
+
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
|
53
|
+
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF};
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Bit Reverse an unsigned char
|
|
57
|
+
*/
|
|
58
|
+
static unsigned char bit_reverse_8(unsigned char value)
|
|
59
|
+
{
|
|
60
|
+
return BIT_REVERSE_TABLE[value];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
* Bit Reverse an unsigned short
|
|
65
|
+
*/
|
|
66
|
+
static unsigned short bit_reverse_16(unsigned short value)
|
|
67
|
+
{
|
|
68
|
+
return (BIT_REVERSE_TABLE[value & 0xff] << 8) |
|
|
69
|
+
(BIT_REVERSE_TABLE[(value >> 8) & 0xff]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/*
|
|
73
|
+
* Bit Reverse an unsigned int
|
|
74
|
+
*/
|
|
75
|
+
static unsigned int bit_reverse_32(unsigned int value)
|
|
76
|
+
{
|
|
77
|
+
return (BIT_REVERSE_TABLE[value & 0xff] << 24) |
|
|
78
|
+
(BIT_REVERSE_TABLE[(value >> 8) & 0xff] << 16) |
|
|
79
|
+
(BIT_REVERSE_TABLE[(value >> 16) & 0xff] << 8) |
|
|
80
|
+
(BIT_REVERSE_TABLE[(value >> 24) & 0xff]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/*
|
|
84
|
+
* Bit Reverse an unsigned long long
|
|
85
|
+
*/
|
|
86
|
+
static unsigned long long bit_reverse_64(unsigned long long value)
|
|
87
|
+
{
|
|
88
|
+
return ((unsigned long long)BIT_REVERSE_TABLE[value & 0x00000000000000ffULL] << 56) |
|
|
89
|
+
((unsigned long long)BIT_REVERSE_TABLE[(value >> 8) & 0x00000000000000ffULL] << 48) |
|
|
90
|
+
((unsigned long long)BIT_REVERSE_TABLE[(value >> 16) & 0x00000000000000ffULL] << 40) |
|
|
91
|
+
((unsigned long long)BIT_REVERSE_TABLE[(value >> 24) & 0x00000000000000ffULL] << 32) |
|
|
92
|
+
((unsigned long long)BIT_REVERSE_TABLE[(value >> 32) & 0x00000000000000ffULL] << 24) |
|
|
93
|
+
((unsigned long long)BIT_REVERSE_TABLE[(value >> 40) & 0x00000000000000ffULL] << 16) |
|
|
94
|
+
((unsigned long long)BIT_REVERSE_TABLE[(value >> 48) & 0x00000000000000ffULL] << 8) |
|
|
95
|
+
((unsigned long long)BIT_REVERSE_TABLE[(value >> 56) & 0x00000000000000ffULL]);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* Calculate a 16-bit CRC
|
|
100
|
+
*/
|
|
101
|
+
static VALUE crc16_calculate(int argc, VALUE *argv, VALUE self)
|
|
102
|
+
{
|
|
103
|
+
volatile VALUE param_data = Qnil;
|
|
104
|
+
volatile VALUE param_seed = Qnil;
|
|
105
|
+
unsigned char *data = NULL;
|
|
106
|
+
unsigned short *table = NULL;
|
|
107
|
+
int i = 0;
|
|
108
|
+
long length = 0;
|
|
109
|
+
unsigned short crc = 0;
|
|
110
|
+
|
|
111
|
+
switch (argc)
|
|
112
|
+
{
|
|
113
|
+
case 1:
|
|
114
|
+
Check_Type(argv[0], T_STRING);
|
|
115
|
+
param_data = argv[0];
|
|
116
|
+
param_seed = rb_ivar_get(self, id_ivar_seed);
|
|
117
|
+
break;
|
|
118
|
+
case 2:
|
|
119
|
+
Check_Type(argv[0], T_STRING);
|
|
120
|
+
param_data = argv[0];
|
|
121
|
+
if (argv[1] == Qnil)
|
|
122
|
+
{
|
|
123
|
+
param_seed = rb_ivar_get(self, id_ivar_seed);
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
{
|
|
127
|
+
param_seed = argv[1];
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
/* Invalid number of arguments given */
|
|
132
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
|
|
133
|
+
break;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
crc = NUM2UINT(param_seed);
|
|
137
|
+
data = (unsigned char *)RSTRING_PTR(param_data);
|
|
138
|
+
length = RSTRING_LEN(param_data);
|
|
139
|
+
table = (unsigned short *)RSTRING_PTR(rb_ivar_get(self, id_ivar_table));
|
|
140
|
+
|
|
141
|
+
if (RTEST(rb_ivar_get(self, id_ivar_reflect)))
|
|
142
|
+
{
|
|
143
|
+
for (i = 0; i < length; i++)
|
|
144
|
+
{
|
|
145
|
+
crc = (crc << 8) ^ table[(crc >> 8) ^ bit_reverse_8(data[i])];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (RTEST(rb_ivar_get(self, id_ivar_xor)))
|
|
149
|
+
{
|
|
150
|
+
return UINT2NUM(bit_reverse_16(crc ^ 0xFFFF));
|
|
151
|
+
}
|
|
152
|
+
else
|
|
153
|
+
{
|
|
154
|
+
return UINT2NUM(bit_reverse_16(crc));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else
|
|
158
|
+
{
|
|
159
|
+
for (i = 0; i < length; i++)
|
|
160
|
+
{
|
|
161
|
+
crc = (crc << 8) ^ table[(crc >> 8) ^ data[i]];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (RTEST(rb_ivar_get(self, id_ivar_xor)))
|
|
165
|
+
{
|
|
166
|
+
return UINT2NUM(crc ^ 0xFFFF);
|
|
167
|
+
}
|
|
168
|
+
else
|
|
169
|
+
{
|
|
170
|
+
return UINT2NUM(crc);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/*
|
|
176
|
+
* Calculate a 32-bit CRC
|
|
177
|
+
*/
|
|
178
|
+
static VALUE crc32_calculate(int argc, VALUE *argv, VALUE self)
|
|
179
|
+
{
|
|
180
|
+
volatile VALUE param_data = Qnil;
|
|
181
|
+
volatile VALUE param_seed = Qnil;
|
|
182
|
+
unsigned char *data = NULL;
|
|
183
|
+
unsigned int *table = NULL;
|
|
184
|
+
int i = 0;
|
|
185
|
+
long length = 0;
|
|
186
|
+
unsigned int crc = 0;
|
|
187
|
+
|
|
188
|
+
switch (argc)
|
|
189
|
+
{
|
|
190
|
+
case 1:
|
|
191
|
+
Check_Type(argv[0], T_STRING);
|
|
192
|
+
param_data = argv[0];
|
|
193
|
+
param_seed = rb_ivar_get(self, id_ivar_seed);
|
|
194
|
+
break;
|
|
195
|
+
case 2:
|
|
196
|
+
Check_Type(argv[0], T_STRING);
|
|
197
|
+
param_data = argv[0];
|
|
198
|
+
if (argv[1] == Qnil)
|
|
199
|
+
{
|
|
200
|
+
param_seed = rb_ivar_get(self, id_ivar_seed);
|
|
201
|
+
}
|
|
202
|
+
else
|
|
203
|
+
{
|
|
204
|
+
param_seed = argv[1];
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
default:
|
|
208
|
+
/* Invalid number of arguments given */
|
|
209
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
|
|
210
|
+
break;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
crc = NUM2UINT(param_seed);
|
|
214
|
+
data = (unsigned char *)RSTRING_PTR(param_data);
|
|
215
|
+
length = RSTRING_LEN(param_data);
|
|
216
|
+
table = (unsigned int *)RSTRING_PTR(rb_ivar_get(self, id_ivar_table));
|
|
217
|
+
|
|
218
|
+
if (RTEST(rb_ivar_get(self, id_ivar_reflect)))
|
|
219
|
+
{
|
|
220
|
+
for (i = 0; i < length; i++)
|
|
221
|
+
{
|
|
222
|
+
crc = (crc << 8) ^ table[((crc >> 24) ^ bit_reverse_8(data[i])) & 0x000000FF];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (RTEST(rb_ivar_get(self, id_ivar_xor)))
|
|
226
|
+
{
|
|
227
|
+
return UINT2NUM(bit_reverse_32(crc ^ 0xFFFFFFFF));
|
|
228
|
+
}
|
|
229
|
+
else
|
|
230
|
+
{
|
|
231
|
+
return UINT2NUM(bit_reverse_32(crc));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else
|
|
235
|
+
{
|
|
236
|
+
for (i = 0; i < length; i++)
|
|
237
|
+
{
|
|
238
|
+
crc = (crc << 8) ^ table[((crc >> 24) ^ data[i]) & 0x000000FF];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (RTEST(rb_ivar_get(self, id_ivar_xor)))
|
|
242
|
+
{
|
|
243
|
+
return UINT2NUM(crc ^ 0xFFFFFFFF);
|
|
244
|
+
}
|
|
245
|
+
else
|
|
246
|
+
{
|
|
247
|
+
return UINT2NUM(crc);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/*
|
|
253
|
+
* Calculate a 64-bit CRC
|
|
254
|
+
*/
|
|
255
|
+
static VALUE crc64_calculate(int argc, VALUE *argv, VALUE self)
|
|
256
|
+
{
|
|
257
|
+
volatile VALUE param_data = Qnil;
|
|
258
|
+
volatile VALUE param_seed = Qnil;
|
|
259
|
+
unsigned char *data = NULL;
|
|
260
|
+
unsigned long long *table = NULL;
|
|
261
|
+
int i = 0;
|
|
262
|
+
long length = 0;
|
|
263
|
+
unsigned long long crc = 0;
|
|
264
|
+
|
|
265
|
+
switch (argc)
|
|
266
|
+
{
|
|
267
|
+
case 1:
|
|
268
|
+
Check_Type(argv[0], T_STRING);
|
|
269
|
+
param_data = argv[0];
|
|
270
|
+
param_seed = rb_ivar_get(self, id_ivar_seed);
|
|
271
|
+
break;
|
|
272
|
+
case 2:
|
|
273
|
+
Check_Type(argv[0], T_STRING);
|
|
274
|
+
param_data = argv[0];
|
|
275
|
+
if (argv[1] == Qnil)
|
|
276
|
+
{
|
|
277
|
+
param_seed = rb_ivar_get(self, id_ivar_seed);
|
|
278
|
+
}
|
|
279
|
+
else
|
|
280
|
+
{
|
|
281
|
+
param_seed = argv[1];
|
|
282
|
+
}
|
|
283
|
+
break;
|
|
284
|
+
default:
|
|
285
|
+
/* Invalid number of arguments given */
|
|
286
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
|
|
287
|
+
break;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
crc = NUM2ULL(param_seed);
|
|
291
|
+
data = (unsigned char *)RSTRING_PTR(param_data);
|
|
292
|
+
length = RSTRING_LEN(param_data);
|
|
293
|
+
table = (unsigned long long *)RSTRING_PTR(rb_ivar_get(self, id_ivar_table));
|
|
294
|
+
|
|
295
|
+
if (RTEST(rb_ivar_get(self, id_ivar_reflect)))
|
|
296
|
+
{
|
|
297
|
+
for (i = 0; i < length; i++)
|
|
298
|
+
{
|
|
299
|
+
crc = (crc << 8) ^ table[((crc >> 56) ^ bit_reverse_8(data[i])) & 0x00000000000000FFULL];
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (RTEST(rb_ivar_get(self, id_ivar_xor)))
|
|
303
|
+
{
|
|
304
|
+
return ULL2NUM(bit_reverse_64(crc ^ 0xFFFFFFFFFFFFFFFFULL));
|
|
305
|
+
}
|
|
306
|
+
else
|
|
307
|
+
{
|
|
308
|
+
return ULL2NUM(bit_reverse_64(crc));
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
else
|
|
312
|
+
{
|
|
313
|
+
for (i = 0; i < length; i++)
|
|
314
|
+
{
|
|
315
|
+
crc = (crc << 8) ^ table[((crc >> 56) ^ data[i]) & 0x00000000000000FFULL];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (RTEST(rb_ivar_get(self, id_ivar_xor)))
|
|
319
|
+
{
|
|
320
|
+
return ULL2NUM(crc ^ 0xFFFFFFFFFFFFFFFFULL);
|
|
321
|
+
}
|
|
322
|
+
else
|
|
323
|
+
{
|
|
324
|
+
return ULL2NUM(crc);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/*
|
|
330
|
+
* Initialize methods for Crc
|
|
331
|
+
*/
|
|
332
|
+
void Init_crc()
|
|
333
|
+
{
|
|
334
|
+
id_ivar_seed = rb_intern("@seed");
|
|
335
|
+
id_ivar_xor = rb_intern("@xor");
|
|
336
|
+
id_ivar_reflect = rb_intern("@reflect");
|
|
337
|
+
id_ivar_table = rb_intern("@table");
|
|
338
|
+
|
|
339
|
+
mOpenC3 = rb_define_module("OpenC3");
|
|
340
|
+
|
|
341
|
+
cCrc = rb_define_class_under(mOpenC3, "Crc", rb_cObject);
|
|
342
|
+
|
|
343
|
+
cCrc16 = rb_define_class_under(mOpenC3, "Crc16", cCrc);
|
|
344
|
+
rb_define_method(cCrc16, "calc", crc16_calculate, -1);
|
|
345
|
+
|
|
346
|
+
cCrc32 = rb_define_class_under(mOpenC3, "Crc32", cCrc);
|
|
347
|
+
rb_define_method(cCrc32, "calc", crc32_calculate, -1);
|
|
348
|
+
|
|
349
|
+
cCrc64 = rb_define_class_under(mOpenC3, "Crc64", cCrc);
|
|
350
|
+
rb_define_method(cCrc64, "calc", crc64_calculate, -1);
|
|
351
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
|
4
|
+
$CFLAGS << ' -O3'
|
|
5
|
+
end
|
|
6
|
+
if /gcc/.match?(CONFIG['CC'])
|
|
7
|
+
$CFLAGS << ' -Wall'
|
|
8
|
+
if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
|
9
|
+
$CFLAGS << ' -O0 -ggdb'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_makefile 'openc3/ext/crc'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
|
4
|
+
$CFLAGS << ' -O3'
|
|
5
|
+
end
|
|
6
|
+
if /gcc/.match?(CONFIG['CC'])
|
|
7
|
+
$CFLAGS << ' -Wall'
|
|
8
|
+
if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
|
9
|
+
$CFLAGS << ' -O0 -ggdb'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_makefile 'openc3/ext/openc3_io'
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/*
|
|
2
|
+
# Copyright 2022 Ball Aerospace & Technologies Corp.
|
|
3
|
+
# All Rights Reserved.
|
|
4
|
+
#
|
|
5
|
+
# This program is free software; you can modify and/or redistribute it
|
|
6
|
+
# under the terms of the GNU Affero General Public License
|
|
7
|
+
# as published by the Free Software Foundation; version 3 with
|
|
8
|
+
# attribution addendums as found in the LICENSE.txt
|
|
9
|
+
#
|
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
# GNU Affero General Public License for more details.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
# Modified by OpenC3, Inc.
|
|
18
|
+
# All changes Copyright 2022, OpenC3, Inc.
|
|
19
|
+
# All Rights Reserved
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "ruby.h"
|
|
23
|
+
#include "stdio.h"
|
|
24
|
+
|
|
25
|
+
static const int endianness_check = 1;
|
|
26
|
+
#define HOST_ENDIANNESS (*((char *)&endianness_check))
|
|
27
|
+
#define OPENC3_BIG_ENDIAN 0
|
|
28
|
+
#define OPENC3_LITTLE_ENDIAN 1
|
|
29
|
+
|
|
30
|
+
VALUE mOpenC3IO = Qnil;
|
|
31
|
+
|
|
32
|
+
static ID id_method_read = 0;
|
|
33
|
+
|
|
34
|
+
/* Reads a length field and then return the String resulting from reading the
|
|
35
|
+
* number of bytes the length field indicates
|
|
36
|
+
*
|
|
37
|
+
* For example:
|
|
38
|
+
* io = StringIO.new
|
|
39
|
+
* # where io is "\x02\x01\x02\x03\x04...."
|
|
40
|
+
* result = io.read_length_bytes(1)
|
|
41
|
+
* # result will be "\x01x02" because the length field was given
|
|
42
|
+
* # to be 1 byte. We read 1 byte which is a 2. So we then read two
|
|
43
|
+
* # bytes and return.
|
|
44
|
+
*
|
|
45
|
+
* @param length_num_bytes [Integer] Number of bytes in the length field
|
|
46
|
+
* @return [String] A String of "length field" number of bytes
|
|
47
|
+
*/
|
|
48
|
+
static VALUE read_length_bytes(int argc, VALUE *argv, VALUE self)
|
|
49
|
+
{
|
|
50
|
+
int length_num_bytes = 0;
|
|
51
|
+
int max_read_size = 0;
|
|
52
|
+
unsigned char *string = NULL;
|
|
53
|
+
long string_length = 0;
|
|
54
|
+
unsigned short short_length = 0;
|
|
55
|
+
unsigned char *length_ptr = NULL;
|
|
56
|
+
volatile VALUE temp_string = Qnil;
|
|
57
|
+
volatile VALUE temp_string_length = Qnil;
|
|
58
|
+
volatile VALUE return_value = Qnil;
|
|
59
|
+
volatile VALUE param_length_num_bytes = Qnil;
|
|
60
|
+
volatile VALUE param_max_read_size = Qnil;
|
|
61
|
+
|
|
62
|
+
switch (argc)
|
|
63
|
+
{
|
|
64
|
+
case 1:
|
|
65
|
+
param_length_num_bytes = argv[0];
|
|
66
|
+
param_max_read_size = Qnil;
|
|
67
|
+
break;
|
|
68
|
+
case 2:
|
|
69
|
+
param_length_num_bytes = argv[0];
|
|
70
|
+
param_max_read_size = argv[1];
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
/* Invalid number of arguments given */
|
|
74
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
|
|
75
|
+
break;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
length_num_bytes = FIX2INT(param_length_num_bytes);
|
|
79
|
+
|
|
80
|
+
/* Read bytes for string length */
|
|
81
|
+
temp_string = rb_funcall(self, id_method_read, 1, param_length_num_bytes);
|
|
82
|
+
if (NIL_P(temp_string) || (RSTRING_LEN(temp_string) != length_num_bytes))
|
|
83
|
+
{
|
|
84
|
+
return Qnil;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
string = (unsigned char *)RSTRING_PTR(temp_string);
|
|
88
|
+
switch (length_num_bytes)
|
|
89
|
+
{
|
|
90
|
+
case 1:
|
|
91
|
+
string_length = (unsigned int)string[0];
|
|
92
|
+
break;
|
|
93
|
+
case 2:
|
|
94
|
+
length_ptr = (unsigned char *)&short_length;
|
|
95
|
+
if (HOST_ENDIANNESS == OPENC3_BIG_ENDIAN)
|
|
96
|
+
{
|
|
97
|
+
length_ptr[1] = string[1];
|
|
98
|
+
length_ptr[0] = string[0];
|
|
99
|
+
}
|
|
100
|
+
else
|
|
101
|
+
{
|
|
102
|
+
length_ptr[0] = string[1];
|
|
103
|
+
length_ptr[1] = string[0];
|
|
104
|
+
}
|
|
105
|
+
string_length = short_length;
|
|
106
|
+
break;
|
|
107
|
+
case 4:
|
|
108
|
+
length_ptr = (unsigned char *)&string_length;
|
|
109
|
+
if (HOST_ENDIANNESS == OPENC3_BIG_ENDIAN)
|
|
110
|
+
{
|
|
111
|
+
length_ptr[3] = string[3];
|
|
112
|
+
length_ptr[2] = string[2];
|
|
113
|
+
length_ptr[1] = string[1];
|
|
114
|
+
length_ptr[0] = string[0];
|
|
115
|
+
}
|
|
116
|
+
else
|
|
117
|
+
{
|
|
118
|
+
length_ptr[0] = string[3];
|
|
119
|
+
length_ptr[1] = string[2];
|
|
120
|
+
length_ptr[2] = string[1];
|
|
121
|
+
length_ptr[3] = string[0];
|
|
122
|
+
}
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
return Qnil;
|
|
126
|
+
break;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if (RTEST(param_max_read_size))
|
|
130
|
+
{
|
|
131
|
+
max_read_size = FIX2INT(param_max_read_size);
|
|
132
|
+
if (string_length > max_read_size)
|
|
133
|
+
{
|
|
134
|
+
return Qnil;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* Read String */
|
|
139
|
+
temp_string_length = UINT2NUM((unsigned int)string_length);
|
|
140
|
+
return_value = rb_funcall(self, id_method_read, 1, temp_string_length);
|
|
141
|
+
if (NIL_P(return_value) || (RSTRING_LEN(return_value) != string_length))
|
|
142
|
+
{
|
|
143
|
+
return Qnil;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return return_value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/*
|
|
150
|
+
* Initialize methods for OpenC3IO
|
|
151
|
+
*/
|
|
152
|
+
void Init_openc3_io(void)
|
|
153
|
+
{
|
|
154
|
+
id_method_read = rb_intern("read");
|
|
155
|
+
|
|
156
|
+
mOpenC3IO = rb_define_module("OpenC3IO");
|
|
157
|
+
rb_define_method(mOpenC3IO, "read_length_bytes", read_length_bytes, -1);
|
|
158
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
|
|
4
|
+
$CFLAGS << ' -O3'
|
|
5
|
+
end
|
|
6
|
+
if /gcc/.match?(CONFIG['CC'])
|
|
7
|
+
$CFLAGS << ' -Wall'
|
|
8
|
+
if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
|
9
|
+
$CFLAGS << ' -O0 -ggdb'
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_makefile 'openc3/ext/packet'
|