Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add args to conversion to be returnable as json #1512

Merged
merged 8 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions openc3.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
"settings": {
"rubyLsp.bundleGemfile": "openc3/Gemfile",
"vetur.validation.template": false,
"eslint.validate": [
"vue",
"html",
"javascript"
],
"eslint.workingDirectories": [
"./openc3-cosmos-init/plugins"
],
"eslint.validate": ["vue", "html", "javascript"],
"eslint.workingDirectories": ["./openc3-cosmos-init/plugins"],
"eslint.packageManager": "yarn",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
Expand All @@ -44,4 +38,4 @@
"ruby.format": "rubocop"
},
"files.associations": {}
}
}
1 change: 1 addition & 0 deletions openc3/lib/openc3/conversions/bit_reverse_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize(converted_type, converted_bit_size)
if @converted_type == :FLOAT
raise "Float Bit Reverse Not Yet Supported"
end
@params = [@converted_type, @converted_bit_size]
end

# Perform the conversion on the value.
Expand Down
6 changes: 5 additions & 1 deletion openc3/lib/openc3/conversions/conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ class Conversion
attr_reader :converted_bit_size
# @return [Integer] The size in bits of the converted array value
attr_reader :converted_array_size
# @return [Array] The arguments passed to the conversion
attr_reader :params

# Create a new conversion
def initialize
@converted_type = nil
@converted_bit_size = nil
@converted_array_size = nil
@params = nil
end

# Perform the conversion on the value.
Expand All @@ -61,12 +64,13 @@ def to_config(read_or_write)
" #{read_or_write}_CONVERSION #{self.class.name.class_name_to_filename}\n"
end

def as_json(*_a)
def as_json(*a)
result = {}
result['class'] = self.class.name.to_s
result['converted_type'] = @converted_type if @converted_type
result['converted_bit_size'] = @converted_bit_size if @converted_bit_size
result['converted_array_size'] = @converted_array_size if @converted_array_size
result['params'] = @params.as_json(*a) if @params
result
end
end
Expand Down
11 changes: 3 additions & 8 deletions openc3/lib/openc3/conversions/generic_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/conversions/conversion'
Expand Down Expand Up @@ -49,6 +49,7 @@ def initialize(code_to_eval, converted_type = nil, converted_bit_size = nil, con
end
@converted_bit_size = Integer(converted_bit_size) if ConfigParser.handle_nil(converted_bit_size)
@converted_array_size = Integer(converted_array_size) if ConfigParser.handle_nil(converted_array_size)
@params = [@code_to_eval, @converted_type, @converted_bit_size, @converted_array_size]
end

# (see OpenC3::Conversion#call)
Expand Down Expand Up @@ -76,11 +77,5 @@ def to_config(read_or_write)
config << " GENERIC_#{read_or_write}_CONVERSION_END\n"
config
end

def as_json(*a)
result = super(*a)
result['params'] = [@code_to_eval, @converted_type, @converted_bit_size, @converted_array_size]
result
end
end
end
9 changes: 1 addition & 8 deletions openc3/lib/openc3/conversions/object_read_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def initialize(cmd_or_tlm, target_name, packet_name)
@packet_name = packet_name.to_s.upcase
@converted_type = :OBJECT
@converted_bit_size = 0
@params = [@cmd_or_tlm, @target_name, @packet_name]
end

def lookup_packet
Expand Down Expand Up @@ -76,13 +77,5 @@ def to_s
def to_config(read_or_write)
" #{read_or_write}_CONVERSION #{self.class.name.class_name_to_filename} #{@cmd_or_tlm ? @cmd_or_tlm : "nil"} #{@target_name} #{@packet_name}\n"
end

def as_json(*a)
result = super(*a)
result['cmd_or_tlm'] = @cmd_or_tlm
result['target_name'] = @target_name
result['packet_name'] = @packet_name
return result
end
end
end
11 changes: 3 additions & 8 deletions openc3/lib/openc3/conversions/polynomial_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/conversions/conversion'
Expand All @@ -38,6 +38,7 @@ def initialize(*coeffs)
@coeffs = coeffs.map { |coeff| coeff.to_f }
@converted_type = :FLOAT
@converted_bit_size = 64
@params = @coeffs
end

if RUBY_ENGINE != 'ruby' or ENV['OPENC3_NO_EXT']
Expand Down Expand Up @@ -80,11 +81,5 @@ def to_s
def to_config(read_or_write)
" POLY_#{read_or_write}_CONVERSION #{@coeffs.join(' ')}\n"
end

def as_json(*a)
result = super(*a)
result['params'] = @coeffs
result
end
end
end
24 changes: 13 additions & 11 deletions openc3/lib/openc3/conversions/processor_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/conversions/conversion'
Expand All @@ -34,12 +34,20 @@ def initialize(processor_name, result_name, converted_type = nil, converted_bit_
super()
@processor_name = processor_name.to_s.upcase
@result_name = result_name.to_s.upcase.intern
@params = [@processor_name, @result_name]
if ConfigParser.handle_nil(converted_type)
@converted_type = converted_type.to_s.upcase.intern
raise ArgumentError, "Unknown converted type: #{converted_type}" if !BinaryAccessor::DATA_TYPES.include?(@converted_type)
@params << @converted_type
end
if ConfigParser.handle_nil(converted_bit_size)
@converted_bit_size = Integer(converted_bit_size)
@params << @converted_bit_size
end
if ConfigParser.handle_nil(converted_array_size)
@converted_array_size = Integer(converted_array_size)
@params << @converted_array_size
end
@converted_bit_size = Integer(converted_bit_size) if ConfigParser.handle_nil(converted_bit_size)
@converted_array_size = Integer(converted_array_size) if ConfigParser.handle_nil(converted_array_size)
end

# @param (see Conversion#call)
Expand All @@ -63,11 +71,5 @@ def to_config(read_or_write)
config << "\n"
config
end

def as_json(*a)
result = super(*a)
result['params'] = [@processor_name, @result_name, @converted_type, @converted_bit_size, @converted_array_size]
result
end
end # class ProcessorConversion
end
end
14 changes: 3 additions & 11 deletions openc3/lib/openc3/conversions/segmented_polynomial_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
Expand Down Expand Up @@ -93,6 +93,7 @@ def calculate(value)
# and the other entry is an array of the coefficients for that segment.
def initialize(segments = [])
super()
@params = []
@segments = []
segments.each { |lower_bound, coeffs| add_segment(lower_bound, *coeffs) }
@converted_type = :FLOAT
Expand All @@ -107,6 +108,7 @@ def initialize(segments = [])
# given coefficients.
# @param coeffs [Array<Integer>] The polynomial coefficients
def add_segment(lower_bound, *coeffs)
@params << [lower_bound, coeffs]
@segments << Segment.new(lower_bound, coeffs)
@segments.sort!
end
Expand Down Expand Up @@ -160,15 +162,5 @@ def to_config(read_or_write)
end
config
end

def as_json(*a)
params = []
@segments.each do |segment|
params << [segment.lower_bound, segment.coeffs]
end
result = super(*a)
result['params'] = [params]
result
end
end
end
11 changes: 4 additions & 7 deletions openc3/lib/openc3/conversions/unix_time_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def initialize(seconds_item_name, microseconds_item_name = nil, seconds_type = '
@converted_bit_size = 0
@seconds_type = seconds_type.to_sym
@microseconds_type = microseconds_type.to_sym
@params = [@seconds_item_name, @microseconds_item_name]
@params << @seconds_type if @seconds_type != :RAW
@params << @microseconds_type if @microseconds_type != :RAW
end

# @param (see Conversion#call)
Expand All @@ -65,11 +68,5 @@ def to_s
def to_config(read_or_write)
" #{read_or_write}_CONVERSION #{self.class.name.class_name_to_filename} #{@seconds_item_name} #{@microseconds_item_name}\n"
end

def as_json(*a)
result = super(*a)
result['params'] = [@seconds_item_name, @microseconds_item_name, @seconds_type, @microseconds_type]
result
end
end # class UnixTimeConversion
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/conversions/unix_time_conversion'
Expand All @@ -33,6 +33,7 @@ class UnixTimeFormattedConversion < UnixTimeConversion
# @param microseconds_item_name [String] The telemetry item in the packet
# which represents microseconds
def initialize(seconds_item_name, microseconds_item_name = nil)
# @params is set by the parent class in super()
super(seconds_item_name, microseconds_item_name)
@converted_type = :STRING
@converted_bit_size = 0
Expand All @@ -48,5 +49,5 @@ def call(value, packet, buffer)
def to_s
super << ".formatted"
end
end # class UnixTimeFormattedConversion
end
end
7 changes: 4 additions & 3 deletions openc3/lib/openc3/conversions/unix_time_seconds_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/conversions/unix_time_conversion'
Expand All @@ -33,6 +33,7 @@ class UnixTimeSecondsConversion < UnixTimeConversion
# @param microseconds_item_name [String] The telemetry item in the packet
# which represents microseconds
def initialize(seconds_item_name, microseconds_item_name = nil)
# @params is set by the parent class in super()
super(seconds_item_name, microseconds_item_name)
@converted_type = :FLOAT
@converted_bit_size = 64
Expand All @@ -48,5 +49,5 @@ def call(value, packet, buffer)
def to_s
super << ".to_f"
end
end # class UnixTimeSecondsConversion
end
end
1 change: 1 addition & 0 deletions openc3/python/openc3/conversions/bit_reverse_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self, converted_type, converted_bit_size):
self.converted_bit_size = int(converted_bit_size)
if self.converted_type == "FLOAT":
raise RuntimeError("Float Bit Reverse Not Yet Supported")
self.params = [self.converted_type, self.converted_bit_size]

# Perform the conversion on the value.
#
Expand Down
6 changes: 5 additions & 1 deletion openc3/python/openc3/conversions/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ class Conversion:
"""Performs a general conversion via the implementation of the call method"""

# self.return [Symbol] The converted data type. Must be one of
# {OpenC3:'S'tructureItem#data_type}
# {OpenC3::StructureItem#data_type}
# attr_reader :converted_type
# # self.return [Integer] The size in bits of the converted value
# attr_reader :converted_bit_size
# # self.return [Integer] The size in bits of the converted array value
# attr_reader :converted_array_size
# attr_reader :params

# Create a new conversion
def __init__(self):
self.converted_type = None
self.converted_bit_size = None
self.converted_array_size = None
self.params = None

# Perform the conversion on the value.
#
Expand Down Expand Up @@ -61,4 +63,6 @@ def as_json(self):
result["converted_bit_size"] = self.converted_bit_size
if self.converted_array_size is not None:
result["converted_array_size"] = self.converted_array_size
if self.params is not None:
result["params"] = self.params
return result
11 changes: 1 addition & 10 deletions openc3/python/openc3/conversions/generic_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
self.converted_bit_size = int(converted_bit_size)
if ConfigParser.handle_none(converted_array_size):
self.converted_array_size = int(converted_array_size)
self.params = [code_to_eval, converted_type, converted_bit_size, converted_array_size]

def call(self, value, packet, buffer):
myself = packet # For backwards compatibility
Expand All @@ -72,13 +73,3 @@ def to_config(self, read_or_write):
config << self.code_to_eval
config += f" GENERIC_{read_or_write}_CONVERSION_END\n"
return config

def as_json(self):
result = super().as_json()
result["params"] = [
self.code_to_eval,
self.converted_type,
self.converted_bit_size,
self.converted_array_size,
]
return result
8 changes: 1 addition & 7 deletions openc3/python/openc3/conversions/object_read_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, cmd_or_tlm, target_name, packet_name):
self.packet_name = str(packet_name).upper()
self.converted_type = "OBJECT"
self.converted_bit_size = 0
self.params = [self.cmd_or_tlm, self.target_name, self.packet_name]

def lookup_packet(self):
if self.cmd_or_tlm:
Expand Down Expand Up @@ -62,10 +63,3 @@ def __str__(self):
# @return [String] Config fragment for this conversion
def to_config(self, read_or_write):
return f"{read_or_write}_CONVERSION openc3/conversions/object_read_conversion.py {self.cmd_or_tlm if self.cmd_or_tlm else 'None'} {self.target_name} {self.packet_name}\n"

def as_json(self, *a):
result = super().as_json(*a)
result["cmd_or_tlm"] = self.cmd_or_tlm
result["target_name"] = self.target_name
result["packet_name"] = self.packet_name
return result
Loading
Loading