class CanFrame
Public Class Methods
new(value)
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 3 def initialize value @value = value end
Public Instance Methods
crc()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 27 def crc @value[-4..-1] end
data_field()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 23 def data_field @value[4..-5] end
dlc()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 15 def dlc @value[3].hex end
formatted_output()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 39 def formatted_output [identifier, dlc, data_field_bytes.join(' '), crc].join ' ' end
identifier()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 19 def identifier @value[0..2] end
match(integer)
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 35 def match integer data_field_values.select { |value| value.hex == integer }.size > 0 end
repr()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 31 def repr to_bits end
to_bits()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 7 def to_bits "%0#{@value.size * 4}d" % (@value.hex.to_s(2)) end
to_hex()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 11 def to_hex @value end
Private Instance Methods
data_field_bytes()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 47 def data_field_bytes data_field.scan(/.{2}/) end
data_field_values()
click to toggle source
# File lib/retrotoolkit/can_frame.rb, line 51 def data_field_values values = [] dlc.times do |length| (dlc-length).times do |pos| values << data_field[(pos*2)..(pos*2+1+length*2)] end end values end