Skip to content

Commit

Permalink
Make params contain all params passed to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Oct 28, 2024
1 parent 1c6989b commit e8bf78f
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 15 deletions.
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
13 changes: 10 additions & 3 deletions openc3/lib/openc3/conversions/processor_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +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)
@params = [@processor_name, @result_name]
end

# @param (see Conversion#call)
Expand Down
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
5 changes: 4 additions & 1 deletion openc3/python/openc3/conversions/processor_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ def __init__(
super().__init__()
self.processor_name = str(processor_name).upper()
self.result_name = str(result_name).upper()
self.params = [self.processor_name, self.result_name]
if ConfigParser.handle_none(converted_type):
self.converted_type = str(converted_type).upper()
if self.converted_type not in BinaryAccessor.DATA_TYPES:
raise AttributeError(f"Unknown converted type: {converted_type}")
self.params.append(self.converted_type)
if ConfigParser.handle_none(converted_bit_size):
self.converted_bit_size = int(converted_bit_size)
self.params.append(self.converted_bit_size)
if ConfigParser.handle_none(converted_array_size):
self.converted_array_size = int(converted_array_size)
self.params = [self.processor_name, self.result_name]
self.params.append(self.converted_array_size)

# @param (see Conversion#call)
# @return [Varies] The result of the associated processor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 OpenC3, Inc.
# Copyright 2024 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand Down Expand Up @@ -29,6 +29,7 @@ class UnixTimeFormattedConversion(UnixTimeConversion):
# @param microseconds_item_name [String] The telemetry item in the packet
# which represents microseconds
def __init__(self, seconds_item_name, microseconds_item_name=None):
# self.params is set by the parent class in super()
super().__init__(seconds_item_name, microseconds_item_name)
self.converted_type = "STRING"
self.converted_bit_size = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 OpenC3, Inc.
# Copyright 2024 OpenC3, Inc.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
Expand Down Expand Up @@ -28,6 +28,7 @@ class UnixTimeSecondsConversion(UnixTimeConversion):
# @param microseconds_item_name [String] The telemetry item in the packet
# which represents microseconds
def __init__(self, seconds_item_name, microseconds_item_name=None):
# self.params is set by the parent class in super()
super().__init__(seconds_item_name, microseconds_item_name)
self.converted_type = "FLOAT"
self.converted_bit_size = 64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_creates_a_reproducable_format(self):
self.assertEqual(json["class"], "BitReverseConversion")
self.assertEqual(json["converted_type"], "UINT")
self.assertEqual(json["converted_bit_size"], 8)
new_brc = BitReverseConversion(json["converted_type"], json["converted_bit_size"])
new_brc = BitReverseConversion(*json["params"])
self.assertEqual(brc.converted_type, (new_brc.converted_type))
self.assertEqual(brc.converted_bit_size, (new_brc.converted_bit_size))
self.assertEqual(brc.call(0x11, None, None), 0x88)
Expand Down
16 changes: 16 additions & 0 deletions openc3/python/test/conversions/test_processor_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,19 @@ def test_returns_the_equation(self):
str(ProcessorConversion("TEST1", "TEST2", "FLOAT", "64", "128")),
"ProcessorConversion TEST1 TEST2",
)

def test_as_json_creates_a_reproducible_format(self):
pc = ProcessorConversion('TEST1', 'TEST2', 'FLOAT', '64', '128')
json = pc.as_json()
self.assertEqual(json['class'], "ProcessorConversion")
self.assertEqual(json['converted_type'], "FLOAT")
self.assertEqual(json['converted_bit_size'], 64)
self.assertEqual(json['converted_array_size'], 128)
self.assertEqual(json['params'], ['TEST1', 'TEST2', "FLOAT", 64, 128])
new_pc = ProcessorConversion(*json['params'])
packet = Packet("tgt", "pkt")
packet.append_item('ITEM1', 64, "FLOAT")
proc = Processor()
proc.results = {"TEST2": 6.0}
packet.processors['TEST1'] = proc
self.assertEqual(pc.call(1, packet, None), new_pc.call(1, packet, None))
2 changes: 1 addition & 1 deletion openc3/spec/conversions/bit_reverse_conversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module OpenC3
expect(json['converted_type']).to eql :UINT
expect(json['converted_bit_size']).to eql 8
expect(json['converted_array_size']).to eql nil
new_brc = OpenC3::const_get(json['class']).new(json['converted_type'], json['converted_bit_size'])
new_brc = OpenC3::const_get(json['class']).new(*json['params'])
expect(brc.converted_type).to eql(new_brc.converted_type)
expect(brc.converted_bit_size).to eql(new_brc.converted_bit_size)
expect(brc.converted_array_size).to eql(new_brc.converted_array_size)
Expand Down
2 changes: 1 addition & 1 deletion openc3/spec/conversions/processor_conversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module OpenC3
expect(json['converted_type']).to eql :FLOAT
expect(json['converted_bit_size']).to eql 64
expect(json['converted_array_size']).to eql 128
expect(json['params']).to eql ['TEST1', 'TEST2']
expect(json['params']).to eql ['TEST1', 'TEST2', "FLOAT", 64, 128]
new_pc = OpenC3::const_get(json['class']).new(*json['params'])
packet = Packet.new("tgt", "pkt")
packet.append_item('ITEM1', 64, :FLOAT)
Expand Down

0 comments on commit e8bf78f

Please sign in to comment.