openc3 5.0.6
Sign up to get free protection for your applications and to get access to all the features.
- 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,318 @@
|
|
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
|
+
#include "../structure/structure.c"
|
26
|
+
|
27
|
+
static VALUE cPacket = Qnil;
|
28
|
+
static VALUE cPacketItem = Qnil;
|
29
|
+
|
30
|
+
static ID id_method_class = 0;
|
31
|
+
static ID id_method_target_name_equals = 0;
|
32
|
+
static ID id_method_packet_name_equals = 0;
|
33
|
+
static ID id_method_description_equals = 0;
|
34
|
+
static ID id_method_upcase = 0;
|
35
|
+
static ID id_method_clone = 0;
|
36
|
+
static ID id_method_to_utf8 = 0;
|
37
|
+
static ID id_method_clear = 0;
|
38
|
+
|
39
|
+
static ID id_ivar_id_items = 0;
|
40
|
+
static ID id_ivar_received_time = 0;
|
41
|
+
static ID id_ivar_received_count = 0;
|
42
|
+
static ID id_ivar_hazardous = 0;
|
43
|
+
static ID id_ivar_hazardous_description = 0;
|
44
|
+
static ID id_ivar_given_values = 0;
|
45
|
+
static ID id_ivar_limits_items = 0;
|
46
|
+
static ID id_ivar_processors = 0;
|
47
|
+
static ID id_ivar_stale = 0;
|
48
|
+
static ID id_ivar_limits_change_callback = 0;
|
49
|
+
static ID id_ivar_read_conversion_cache = 0;
|
50
|
+
static ID id_ivar_raw = 0;
|
51
|
+
static ID id_ivar_messages_disabled = 0;
|
52
|
+
static ID id_ivar_meta = 0;
|
53
|
+
static ID id_ivar_hidden = 0;
|
54
|
+
static ID id_ivar_disabled = 0;
|
55
|
+
static ID id_ivar_target_name = 0;
|
56
|
+
static ID id_ivar_packet_name = 0;
|
57
|
+
static ID id_ivar_description = 0;
|
58
|
+
static ID id_ivar_stored = 0;
|
59
|
+
static ID id_ivar_extra = 0;
|
60
|
+
|
61
|
+
/* Sets the target name this packet is associated with. Unidentified packets
|
62
|
+
* will have target name set to nil.
|
63
|
+
*
|
64
|
+
* @param target_name [String] Name of the target this packet is associated with */
|
65
|
+
static VALUE target_name_equals(VALUE self, VALUE target_name)
|
66
|
+
{
|
67
|
+
if (RTEST(target_name))
|
68
|
+
{
|
69
|
+
if (rb_funcall(target_name, id_method_class, 0) != rb_cString)
|
70
|
+
{
|
71
|
+
rb_raise(rb_eArgError, "target_name must be a String but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(target_name, id_method_class, 0), id_method_to_s, 0)));
|
72
|
+
}
|
73
|
+
rb_ivar_set(self, id_ivar_target_name, rb_funcall(rb_funcall(target_name, id_method_upcase, 0), id_method_freeze, 0));
|
74
|
+
}
|
75
|
+
else
|
76
|
+
{
|
77
|
+
rb_ivar_set(self, id_ivar_target_name, Qnil);
|
78
|
+
}
|
79
|
+
return rb_ivar_get(self, id_ivar_target_name);
|
80
|
+
}
|
81
|
+
|
82
|
+
/* Sets the packet name. Unidentified packets will have packet name set to
|
83
|
+
* nil.
|
84
|
+
*
|
85
|
+
* @param packet_name [String] Name of the packet */
|
86
|
+
static VALUE packet_name_equals(VALUE self, VALUE packet_name)
|
87
|
+
{
|
88
|
+
if (RTEST(packet_name))
|
89
|
+
{
|
90
|
+
if (rb_funcall(packet_name, id_method_class, 0) != rb_cString)
|
91
|
+
{
|
92
|
+
rb_raise(rb_eArgError, "packet_name must be a String but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(packet_name, id_method_class, 0), id_method_to_s, 0)));
|
93
|
+
}
|
94
|
+
rb_ivar_set(self, id_ivar_packet_name, rb_funcall(rb_funcall(packet_name, id_method_upcase, 0), id_method_freeze, 0));
|
95
|
+
}
|
96
|
+
else
|
97
|
+
{
|
98
|
+
rb_ivar_set(self, id_ivar_packet_name, Qnil);
|
99
|
+
}
|
100
|
+
return rb_ivar_get(self, id_ivar_packet_name);
|
101
|
+
}
|
102
|
+
|
103
|
+
/* Sets the description of the packet
|
104
|
+
*
|
105
|
+
* @param description [String] Description of the packet */
|
106
|
+
static VALUE description_equals(VALUE self, VALUE description)
|
107
|
+
{
|
108
|
+
if (RTEST(description))
|
109
|
+
{
|
110
|
+
if (rb_funcall(description, id_method_class, 0) != rb_cString)
|
111
|
+
{
|
112
|
+
rb_raise(rb_eArgError, "description must be a String but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(description, id_method_class, 0), id_method_to_s, 0)));
|
113
|
+
}
|
114
|
+
rb_ivar_set(self, id_ivar_description, rb_funcall(rb_funcall(description, id_method_to_utf8, 0), id_method_freeze, 0));
|
115
|
+
}
|
116
|
+
else
|
117
|
+
{
|
118
|
+
rb_ivar_set(self, id_ivar_description, Qnil);
|
119
|
+
}
|
120
|
+
return rb_ivar_get(self, id_ivar_description);
|
121
|
+
}
|
122
|
+
|
123
|
+
/* Sets the received time of the packet
|
124
|
+
*
|
125
|
+
* @param received_time [Time] Time this packet was received */
|
126
|
+
static VALUE received_time_equals(VALUE self, VALUE received_time)
|
127
|
+
{
|
128
|
+
volatile VALUE read_conversion_cache = rb_ivar_get(self, id_ivar_read_conversion_cache);
|
129
|
+
if (RTEST(received_time))
|
130
|
+
{
|
131
|
+
if (rb_funcall(received_time, id_method_class, 0) != rb_cTime)
|
132
|
+
{
|
133
|
+
rb_raise(rb_eArgError, "received_time must be a Time but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(received_time, id_method_class, 0), id_method_to_s, 0)));
|
134
|
+
}
|
135
|
+
rb_ivar_set(self, id_ivar_received_time, rb_funcall(rb_funcall(received_time, id_method_clone, 0), id_method_freeze, 0));
|
136
|
+
}
|
137
|
+
else
|
138
|
+
{
|
139
|
+
rb_ivar_set(self, id_ivar_received_time, Qnil);
|
140
|
+
}
|
141
|
+
if (RTEST(read_conversion_cache))
|
142
|
+
{
|
143
|
+
rb_funcall(read_conversion_cache, id_method_clear, 0);
|
144
|
+
}
|
145
|
+
return rb_ivar_get(self, id_ivar_received_time);
|
146
|
+
}
|
147
|
+
|
148
|
+
/* Sets the received count of the packet
|
149
|
+
*
|
150
|
+
* @param received_count [Integer] Number of times this packet has been
|
151
|
+
* received */
|
152
|
+
static VALUE received_count_equals(VALUE self, VALUE received_count)
|
153
|
+
{
|
154
|
+
volatile VALUE read_conversion_cache = rb_ivar_get(self, id_ivar_read_conversion_cache);
|
155
|
+
#ifdef RUBY_INTEGER_UNIFICATION /* Ruby 2.4.0 unified Fixnum and Bignum into Integer. This check allows the code to build pre- and post-2.4.0. */
|
156
|
+
if (rb_funcall(received_count, id_method_class, 0) != rb_cInteger)
|
157
|
+
{
|
158
|
+
rb_raise(rb_eArgError, "received_count must be an Integer but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(received_count, id_method_class, 0), id_method_to_s, 0)));
|
159
|
+
}
|
160
|
+
#else
|
161
|
+
if ((rb_funcall(received_count, id_method_class, 0) != rb_cFixnum) && (rb_funcall(received_count, id_method_class, 0) != rb_cBignum))
|
162
|
+
{
|
163
|
+
rb_raise(rb_eArgError, "received_count must be an Integer but is a %s", RSTRING_PTR(rb_funcall(rb_funcall(received_count, id_method_class, 0), id_method_to_s, 0)));
|
164
|
+
}
|
165
|
+
#endif
|
166
|
+
rb_ivar_set(self, id_ivar_received_count, received_count);
|
167
|
+
if (RTEST(read_conversion_cache))
|
168
|
+
{
|
169
|
+
rb_funcall(read_conversion_cache, id_method_clear, 0);
|
170
|
+
}
|
171
|
+
return rb_ivar_get(self, id_ivar_received_count);
|
172
|
+
}
|
173
|
+
|
174
|
+
/* Creates a new packet by initalizing the attributes.
|
175
|
+
*
|
176
|
+
* @param target_name [String] Name of the target this packet is associated with
|
177
|
+
* @param packet_name [String] Name of the packet
|
178
|
+
* @param default_endianness [Symbol] One of {BinaryAccessor::ENDIANNESS}
|
179
|
+
* @param description [String] Description of the packet
|
180
|
+
* @param buffer [String] String buffer to hold the packet data
|
181
|
+
* @param item_class [Class] Class used to instantiate items (Must be a
|
182
|
+
* subclass of PacketItem)
|
183
|
+
*/
|
184
|
+
static VALUE packet_initialize(int argc, VALUE *argv, VALUE self)
|
185
|
+
{
|
186
|
+
volatile VALUE target_name = Qnil;
|
187
|
+
volatile VALUE packet_name = Qnil;
|
188
|
+
volatile VALUE default_endianness = Qnil;
|
189
|
+
volatile VALUE description = Qnil;
|
190
|
+
volatile VALUE buffer = Qnil;
|
191
|
+
volatile VALUE item_class = Qnil;
|
192
|
+
volatile VALUE super_args[3] = {Qnil, Qnil, Qnil};
|
193
|
+
|
194
|
+
switch (argc)
|
195
|
+
{
|
196
|
+
case 2:
|
197
|
+
target_name = argv[0];
|
198
|
+
packet_name = argv[1];
|
199
|
+
default_endianness = symbol_BIG_ENDIAN;
|
200
|
+
description = Qnil;
|
201
|
+
buffer = Qnil;
|
202
|
+
item_class = cPacketItem;
|
203
|
+
break;
|
204
|
+
case 3:
|
205
|
+
target_name = argv[0];
|
206
|
+
packet_name = argv[1];
|
207
|
+
default_endianness = argv[2];
|
208
|
+
description = Qnil;
|
209
|
+
buffer = Qnil;
|
210
|
+
item_class = cPacketItem;
|
211
|
+
break;
|
212
|
+
case 4:
|
213
|
+
target_name = argv[0];
|
214
|
+
packet_name = argv[1];
|
215
|
+
default_endianness = argv[2];
|
216
|
+
description = argv[3];
|
217
|
+
buffer = Qnil;
|
218
|
+
item_class = cPacketItem;
|
219
|
+
break;
|
220
|
+
case 5:
|
221
|
+
target_name = argv[0];
|
222
|
+
packet_name = argv[1];
|
223
|
+
default_endianness = argv[2];
|
224
|
+
description = argv[3];
|
225
|
+
buffer = argv[4];
|
226
|
+
item_class = cPacketItem;
|
227
|
+
break;
|
228
|
+
case 6:
|
229
|
+
target_name = argv[0];
|
230
|
+
packet_name = argv[1];
|
231
|
+
default_endianness = argv[2];
|
232
|
+
description = argv[3];
|
233
|
+
buffer = argv[4];
|
234
|
+
item_class = argv[5];
|
235
|
+
break;
|
236
|
+
default:
|
237
|
+
/* Invalid number of arguments given */
|
238
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..6)", argc);
|
239
|
+
break;
|
240
|
+
};
|
241
|
+
|
242
|
+
super_args[0] = default_endianness;
|
243
|
+
super_args[1] = buffer;
|
244
|
+
super_args[2] = item_class;
|
245
|
+
rb_call_super(3, (VALUE *)super_args);
|
246
|
+
target_name_equals(self, target_name);
|
247
|
+
packet_name_equals(self, packet_name);
|
248
|
+
description_equals(self, description);
|
249
|
+
rb_ivar_set(self, id_ivar_received_time, Qnil);
|
250
|
+
rb_ivar_set(self, id_ivar_received_count, INT2FIX(0));
|
251
|
+
rb_ivar_set(self, id_ivar_id_items, Qnil);
|
252
|
+
rb_ivar_set(self, id_ivar_hazardous, Qfalse);
|
253
|
+
rb_ivar_set(self, id_ivar_hazardous_description, Qnil);
|
254
|
+
rb_ivar_set(self, id_ivar_given_values, Qnil);
|
255
|
+
rb_ivar_set(self, id_ivar_limits_items, Qnil);
|
256
|
+
rb_ivar_set(self, id_ivar_processors, Qnil);
|
257
|
+
rb_ivar_set(self, id_ivar_stale, Qtrue);
|
258
|
+
rb_ivar_set(self, id_ivar_limits_change_callback, Qnil);
|
259
|
+
rb_ivar_set(self, id_ivar_read_conversion_cache, Qnil);
|
260
|
+
rb_ivar_set(self, id_ivar_raw, Qnil);
|
261
|
+
rb_ivar_set(self, id_ivar_messages_disabled, Qfalse);
|
262
|
+
rb_ivar_set(self, id_ivar_meta, Qnil);
|
263
|
+
rb_ivar_set(self, id_ivar_hidden, Qfalse);
|
264
|
+
rb_ivar_set(self, id_ivar_disabled, Qfalse);
|
265
|
+
rb_ivar_set(self, id_ivar_stored, Qfalse);
|
266
|
+
rb_ivar_set(self, id_ivar_extra, Qnil);
|
267
|
+
|
268
|
+
return self;
|
269
|
+
}
|
270
|
+
|
271
|
+
/*
|
272
|
+
* Initialize all Packet methods
|
273
|
+
*/
|
274
|
+
void Init_packet(void)
|
275
|
+
{
|
276
|
+
Init_structure();
|
277
|
+
|
278
|
+
id_method_class = rb_intern("class");
|
279
|
+
id_method_target_name_equals = rb_intern("target_name=");
|
280
|
+
id_method_packet_name_equals = rb_intern("packet_name=");
|
281
|
+
id_method_description_equals = rb_intern("description=");
|
282
|
+
id_method_upcase = rb_intern("upcase");
|
283
|
+
id_method_clone = rb_intern("clone");
|
284
|
+
id_method_to_utf8 = rb_intern("to_utf8");
|
285
|
+
id_method_clear = rb_intern("clear");
|
286
|
+
|
287
|
+
id_ivar_id_items = rb_intern("@id_items");
|
288
|
+
id_ivar_received_time = rb_intern("@received_time");
|
289
|
+
id_ivar_received_count = rb_intern("@received_count");
|
290
|
+
id_ivar_hazardous = rb_intern("@hazardous");
|
291
|
+
id_ivar_hazardous_description = rb_intern("@hazardous_description");
|
292
|
+
id_ivar_given_values = rb_intern("@given_values");
|
293
|
+
id_ivar_limits_items = rb_intern("@limits_items");
|
294
|
+
id_ivar_processors = rb_intern("@processors");
|
295
|
+
id_ivar_stale = rb_intern("@stale");
|
296
|
+
id_ivar_limits_change_callback = rb_intern("@limits_change_callback");
|
297
|
+
id_ivar_read_conversion_cache = rb_intern("@read_conversion_cache");
|
298
|
+
id_ivar_raw = rb_intern("@raw");
|
299
|
+
id_ivar_messages_disabled = rb_intern("@messages_disabled");
|
300
|
+
id_ivar_meta = rb_intern("@meta");
|
301
|
+
id_ivar_hidden = rb_intern("@hidden");
|
302
|
+
id_ivar_disabled = rb_intern("@disabled");
|
303
|
+
id_ivar_target_name = rb_intern("@target_name");
|
304
|
+
id_ivar_packet_name = rb_intern("@packet_name");
|
305
|
+
id_ivar_description = rb_intern("@description");
|
306
|
+
id_ivar_stored = rb_intern("@stored");
|
307
|
+
id_ivar_extra = rb_intern("@extra");
|
308
|
+
|
309
|
+
cPacket = rb_define_class_under(mOpenC3, "Packet", cStructure);
|
310
|
+
rb_define_method(cPacket, "initialize", packet_initialize, -1);
|
311
|
+
rb_define_method(cPacket, "packet_name=", packet_name_equals, 1);
|
312
|
+
rb_define_method(cPacket, "target_name=", target_name_equals, 1);
|
313
|
+
rb_define_method(cPacket, "description=", description_equals, 1);
|
314
|
+
rb_define_method(cPacket, "received_time=", received_time_equals, 1);
|
315
|
+
rb_define_method(cPacket, "received_count=", received_count_equals, 1);
|
316
|
+
|
317
|
+
cPacketItem = rb_define_class_under(mOpenC3, "PacketItem", cStructureItem);
|
318
|
+
}
|
@@ -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 << ' -g -Wall'
|
8
|
+
if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
|
9
|
+
$CFLAGS << ' -O0 -ggdb'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
create_makefile 'openc3/ext/platform'
|
@@ -0,0 +1,134 @@
|
|
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
|
+
/* OpenC3 module reference */
|
26
|
+
VALUE mOpenC3 = Qnil;
|
27
|
+
|
28
|
+
/* SegFault class reference */
|
29
|
+
VALUE cSegFault = Qnil;
|
30
|
+
|
31
|
+
#ifdef _WIN32
|
32
|
+
/* OpenC3 5 drops segfault catching support for running directly on Windows - Usually in linux containers */
|
33
|
+
#else
|
34
|
+
#include <signal.h>
|
35
|
+
#include <unistd.h>
|
36
|
+
#include <time.h>
|
37
|
+
#include <string.h>
|
38
|
+
#include <sys/stat.h>
|
39
|
+
|
40
|
+
/* Mark that this function does not return (it exits) to remove compiler warning */
|
41
|
+
__attribute__((noreturn)) static void catch_sigsegv(int sig_num)
|
42
|
+
{
|
43
|
+
const int FILENAME_LEN = 256;
|
44
|
+
char *openc3_log_dir = NULL;
|
45
|
+
time_t rawtime;
|
46
|
+
struct tm timeinfo;
|
47
|
+
struct tm *timeinfo_ptr;
|
48
|
+
struct stat stats;
|
49
|
+
char filename[FILENAME_LEN];
|
50
|
+
FILE *file = NULL;
|
51
|
+
|
52
|
+
signal(SIGSEGV, SIG_DFL);
|
53
|
+
signal(SIGILL, SIG_DFL);
|
54
|
+
|
55
|
+
openc3_log_dir = getenv("OPENC3_LOGS_DIR");
|
56
|
+
// If the OPENC3_LOGS_DIR env var isn't set or if it's too big set to "."
|
57
|
+
// NOTE: The filename buffer will be written to by snprintf which appends
|
58
|
+
// a null terminator so we have 1 less byte available minus the length
|
59
|
+
// of the fixed filename structure
|
60
|
+
if ((openc3_log_dir == NULL) || (strlen(openc3_log_dir) > (FILENAME_LEN - 1 - strlen("/YYYY_MM_DD_HH_MM_SS_segfault.txt"))))
|
61
|
+
{
|
62
|
+
openc3_log_dir = (char *)".";
|
63
|
+
}
|
64
|
+
// Validate that we can write to this directory
|
65
|
+
if (stat(openc3_log_dir, &stats) == 0)
|
66
|
+
{
|
67
|
+
if (!((stats.st_mode & W_OK) && S_ISDIR(stats.st_mode)))
|
68
|
+
{
|
69
|
+
openc3_log_dir = (char *)".";
|
70
|
+
}
|
71
|
+
}
|
72
|
+
else
|
73
|
+
{
|
74
|
+
openc3_log_dir = (char *)".";
|
75
|
+
}
|
76
|
+
|
77
|
+
time(&rawtime);
|
78
|
+
timeinfo_ptr = localtime_r(&rawtime, &timeinfo);
|
79
|
+
if (timeinfo_ptr == NULL)
|
80
|
+
{
|
81
|
+
// If localtime returns NULL we set our own and set to 1919 to make it interesting
|
82
|
+
strptime("1919-01-01 00:00:00", "%Y-%m-%d %H:%M:%S", &timeinfo);
|
83
|
+
}
|
84
|
+
snprintf(filename, FILENAME_LEN, "%s/%04u_%02u_%02u_%02u_%02u_%02u_segfault.txt",
|
85
|
+
openc3_log_dir,
|
86
|
+
1900 + timeinfo.tm_year,
|
87
|
+
1 + timeinfo.tm_mon,
|
88
|
+
timeinfo.tm_mday,
|
89
|
+
timeinfo.tm_hour,
|
90
|
+
timeinfo.tm_min,
|
91
|
+
timeinfo.tm_sec);
|
92
|
+
|
93
|
+
// Fortify warns about Path Manipulation here. We explictly allow this to let
|
94
|
+
// segfault files be written to a directory of their choosing.
|
95
|
+
// The input is validated above for length and to ensure it is a writable directory.
|
96
|
+
// If the checks fail the directory is set to the current directory without additional info.
|
97
|
+
file = freopen(filename, "a", stderr);
|
98
|
+
/* Using file removes a warning */
|
99
|
+
if (file)
|
100
|
+
{
|
101
|
+
rb_bug("OpenC3 caught segfault");
|
102
|
+
}
|
103
|
+
else
|
104
|
+
{
|
105
|
+
rb_bug("OpenC3 caught segfault");
|
106
|
+
}
|
107
|
+
}
|
108
|
+
#endif
|
109
|
+
|
110
|
+
/* NOTE: Uncomment and rebuild for testing the handler */
|
111
|
+
// static VALUE segfault(VALUE self)
|
112
|
+
// {
|
113
|
+
// char *a = 0;
|
114
|
+
// *a = 50;
|
115
|
+
// return Qnil;
|
116
|
+
// }
|
117
|
+
|
118
|
+
/*
|
119
|
+
* Initialize methods for Platform specific C code
|
120
|
+
*/
|
121
|
+
void Init_platform(void)
|
122
|
+
{
|
123
|
+
#ifdef _WIN32
|
124
|
+
/* Only supprt linux segfault catching */
|
125
|
+
#else
|
126
|
+
signal(SIGSEGV, catch_sigsegv);
|
127
|
+
signal(SIGILL, catch_sigsegv);
|
128
|
+
#endif
|
129
|
+
|
130
|
+
/* NOTE: Uncomment and rebuild for testing the handler */
|
131
|
+
// mOpenC3 = rb_define_module("OpenC3");
|
132
|
+
// cSegFault = rb_define_class_under(mOpenC3, "SegFault", rb_cObject);
|
133
|
+
// rb_define_singleton_method(cSegFault, "segfault", segfault, 0);
|
134
|
+
}
|
@@ -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/polynomial_conversion'
|
@@ -0,0 +1,79 @@
|
|
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
|
+
#include "math.h"
|
25
|
+
|
26
|
+
#ifndef RFLOAT_VALUE
|
27
|
+
#define RFLOAT_VALUE(v) (RFLOAT(v)->value)
|
28
|
+
#endif
|
29
|
+
|
30
|
+
VALUE mOpenC3;
|
31
|
+
VALUE cConversion;
|
32
|
+
VALUE cPolynomialConversion;
|
33
|
+
|
34
|
+
static ID id_ivar_coeffs = 0;
|
35
|
+
static ID id_method_to_f = 0;
|
36
|
+
|
37
|
+
/*
|
38
|
+
* Calling this method performs a polynomial conversion on the given value.
|
39
|
+
*
|
40
|
+
* conversion.call(1, packet) #=> 2.5
|
41
|
+
*/
|
42
|
+
static VALUE polynomial_conversion_call(VALUE self, VALUE value, VALUE myself, VALUE buffer)
|
43
|
+
{
|
44
|
+
int index = 0;
|
45
|
+
double converted = 0.0;
|
46
|
+
double raised_to_power = 1.0;
|
47
|
+
volatile VALUE coeffs = rb_ivar_get(self, id_ivar_coeffs);
|
48
|
+
long coeffs_length = RARRAY_LEN(coeffs);
|
49
|
+
double double_value = RFLOAT_VALUE(rb_funcall(value, id_method_to_f, 0));
|
50
|
+
|
51
|
+
/* Handle C0 */
|
52
|
+
double coeff = RFLOAT_VALUE(rb_ary_entry(coeffs, 0));
|
53
|
+
converted += coeff;
|
54
|
+
|
55
|
+
/* Handle Coefficients raised to a power */
|
56
|
+
for (index = 1; index < coeffs_length; index++)
|
57
|
+
{
|
58
|
+
raised_to_power *= double_value;
|
59
|
+
coeff = RFLOAT_VALUE(rb_ary_entry(coeffs, index));
|
60
|
+
converted += (coeff * raised_to_power);
|
61
|
+
}
|
62
|
+
|
63
|
+
return rb_float_new(converted);
|
64
|
+
}
|
65
|
+
|
66
|
+
/*
|
67
|
+
* Initialize methods for PolynomialConversion
|
68
|
+
*/
|
69
|
+
void Init_polynomial_conversion(void)
|
70
|
+
{
|
71
|
+
id_ivar_coeffs = rb_intern("@coeffs");
|
72
|
+
id_method_to_f = rb_intern("to_f");
|
73
|
+
|
74
|
+
mOpenC3 = rb_define_module("OpenC3");
|
75
|
+
rb_require("openc3/conversions/conversion");
|
76
|
+
cConversion = rb_const_get(mOpenC3, rb_intern("Conversion"));
|
77
|
+
cPolynomialConversion = rb_define_class_under(mOpenC3, "PolynomialConversion", cConversion);
|
78
|
+
rb_define_method(cPolynomialConversion, "call", polynomial_conversion_call, 3);
|
79
|
+
}
|
@@ -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/string'
|
@@ -0,0 +1,63 @@
|
|
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
|
+
/*
|
26
|
+
* Removes quotes from the given string if present.
|
27
|
+
*
|
28
|
+
* "'quoted string'".remove_quotes #=> "quoted string"
|
29
|
+
*/
|
30
|
+
static VALUE string_remove_quotes(VALUE self)
|
31
|
+
{
|
32
|
+
long length = RSTRING_LEN(self);
|
33
|
+
char *ptr = RSTRING_PTR(self);
|
34
|
+
char first_char = 0;
|
35
|
+
char last_char = 0;
|
36
|
+
|
37
|
+
if (length < 2)
|
38
|
+
{
|
39
|
+
return self;
|
40
|
+
}
|
41
|
+
|
42
|
+
first_char = ptr[0];
|
43
|
+
if ((first_char != 34) && (first_char != 39))
|
44
|
+
{
|
45
|
+
return self;
|
46
|
+
}
|
47
|
+
|
48
|
+
last_char = ptr[length - 1];
|
49
|
+
if (last_char != first_char)
|
50
|
+
{
|
51
|
+
return self;
|
52
|
+
}
|
53
|
+
|
54
|
+
return rb_str_new(ptr + 1, length - 2);
|
55
|
+
}
|
56
|
+
|
57
|
+
/*
|
58
|
+
* Initialize methods for String Core Ext
|
59
|
+
*/
|
60
|
+
void Init_string(void)
|
61
|
+
{
|
62
|
+
rb_define_method(rb_cString, "remove_quotes", string_remove_quotes, 0);
|
63
|
+
}
|