Class: OpenC3::UnixTimeConversion

Inherits:
Conversion show all
Defined in:
lib/openc3/conversions/unix_time_conversion.rb

Overview

Converts a unix format time: Epoch Jan 1 1970, seconds and microseconds

Instance Attribute Summary

Attributes inherited from Conversion

#converted_array_size, #converted_bit_size, #converted_type, #params

Instance Method Summary collapse

Methods inherited from Conversion

#as_json

Constructor Details

#initialize(seconds_item_name, microseconds_item_name = nil, seconds_type = 'RAW', microseconds_type = 'RAW') ⇒ UnixTimeConversion

Initializes the time item to grab from the packet



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 34

def initialize(seconds_item_name, microseconds_item_name = nil, seconds_type = 'RAW', microseconds_type = 'RAW')
  super()
  @seconds_item_name = seconds_item_name
  @microseconds_item_name = microseconds_item_name
  @converted_type = :TIME
  @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

Instance Method Details

#call(value, packet, buffer) ⇒ Float



49
50
51
52
53
54
55
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 49

def call(value, packet, buffer)
  if @microseconds_item_name
    return Time.at(packet.read(@seconds_item_name, @seconds_type, buffer), packet.read(@microseconds_item_name, @microseconds_type, buffer)).sys
  else
    return Time.at(packet.read(@seconds_item_name, @seconds_type, buffer), 0).sys
  end
end

#to_config(read_or_write) ⇒ String



68
69
70
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 68

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_sString



58
59
60
61
62
63
64
# File 'lib/openc3/conversions/unix_time_conversion.rb', line 58

def to_s
  if @microseconds_item_name
    return "Time.at(packet.read('#{@seconds_item_name}', :#{@seconds_type}, buffer), packet.read('#{@microseconds_item_name}', :#{@microseconds_type}, buffer)).sys"
  else
    return "Time.at(packet.read('#{@seconds_item_name}', :#{@seconds_type}, buffer), 0).sys"
  end
end