Class: CanFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/retrotoolkit/can_frame.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ CanFrame



3
4
5
# File 'lib/retrotoolkit/can_frame.rb', line 3

def initialize value
  @value = value
end

Instance Method Details

#crcObject



27
28
29
# File 'lib/retrotoolkit/can_frame.rb', line 27

def crc
  @value[-4..-1]
end

#data_fieldObject



23
24
25
# File 'lib/retrotoolkit/can_frame.rb', line 23

def data_field
  @value[4..-5]
end

#dlcObject



15
16
17
# File 'lib/retrotoolkit/can_frame.rb', line 15

def dlc
  @value[3].hex
end

#formatted_outputObject



39
40
41
# File 'lib/retrotoolkit/can_frame.rb', line 39

def formatted_output
  [identifier, dlc, data_field_bytes.join(' '), crc].join ' '
end

#identifierObject



19
20
21
# File 'lib/retrotoolkit/can_frame.rb', line 19

def identifier
  @value[0..2]
end

#match(integer) ⇒ Object



35
36
37
# File 'lib/retrotoolkit/can_frame.rb', line 35

def match integer
  data_field_values.select { |value| value.hex == integer }.size > 0
end

#reprObject



31
32
33
# File 'lib/retrotoolkit/can_frame.rb', line 31

def repr
  to_bits
end

#to_bitsObject



7
8
9
# File 'lib/retrotoolkit/can_frame.rb', line 7

def to_bits
  "%0#{@value.size * 4}d" % (@value.hex.to_s(2))
end

#to_hexObject



11
12
13
# File 'lib/retrotoolkit/can_frame.rb', line 11

def to_hex
  @value
end