Class: OpenC3::UnixTimeConversion
- Inherits:
-
Conversion
- Object
- Conversion
- OpenC3::UnixTimeConversion
- Defined in:
- lib/openc3/conversions/unix_time_conversion.rb
Overview
Converts a unix format time: Epoch Jan 1 1970, seconds and microseconds
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Conversion
#converted_array_size, #converted_bit_size, #converted_type
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#call(value, packet, buffer) ⇒ Float
Packet time in seconds since UNIX epoch.
-
#initialize(seconds_item_name, microseconds_item_name = nil) ⇒ UnixTimeConversion
constructor
Initializes the time item to grab from the packet.
-
#to_config(read_or_write) ⇒ String
Config fragment for this conversion.
-
#to_s ⇒ String
The name of the class followed by the time conversion.
Constructor Details
#initialize(seconds_item_name, microseconds_item_name = nil) ⇒ UnixTimeConversion
Initializes the time item to grab from the packet
34 35 36 37 38 |
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 34 def initialize(seconds_item_name, microseconds_item_name = nil) super() @seconds_item_name = seconds_item_name @microseconds_item_name = microseconds_item_name end |
Instance Method Details
#as_json(*a) ⇒ Object
65 66 67 68 69 |
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 65 def as_json(*a) result = super(*a) result['params'] = [@seconds_item_name, @microseconds_item_name] result end |
#call(value, packet, buffer) ⇒ Float
Returns Packet time in seconds since UNIX epoch.
42 43 44 45 46 47 48 |
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 42 def call(value, packet, buffer) if @microseconds_item_name return Time.at(packet.read(@seconds_item_name, :RAW, buffer), packet.read(@microseconds_item_name, :RAW, buffer)).sys else return Time.at(packet.read(@seconds_item_name, :RAW, buffer), 0).sys end end |
#to_config(read_or_write) ⇒ String
Returns Config fragment for this conversion.
61 62 63 |
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 61 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 |
#to_s ⇒ String
Returns The name of the class followed by the time conversion.
51 52 53 54 55 56 57 |
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 51 def to_s if @microseconds_item_name return "Time.at(packet.read('#{@seconds_item_name}', :RAW, buffer), packet.read('#{@microseconds_item_name}', :RAW, buffer)).sys" else return "Time.at(packet.read('#{@seconds_item_name}', :RAW, buffer), 0).sys" end end |