Class: CanFrame
- Inherits:
-
Object
- Object
- CanFrame
- Defined in:
- lib/retrotoolkit/can_frame.rb
Instance Method Summary collapse
- #crc ⇒ Object
- #data_field ⇒ Object
- #dlc ⇒ Object
- #formatted_output ⇒ Object
- #identifier ⇒ Object
-
#initialize(value) ⇒ CanFrame
constructor
A new instance of CanFrame.
- #match(integer) ⇒ Object
- #repr ⇒ Object
- #to_bits ⇒ Object
- #to_hex ⇒ Object
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
#crc ⇒ Object
27 28 29 |
# File 'lib/retrotoolkit/can_frame.rb', line 27 def crc @value[-4..-1] end |
#data_field ⇒ Object
23 24 25 |
# File 'lib/retrotoolkit/can_frame.rb', line 23 def data_field @value[4..-5] end |
#dlc ⇒ Object
15 16 17 |
# File 'lib/retrotoolkit/can_frame.rb', line 15 def dlc @value[3].hex end |
#formatted_output ⇒ Object
39 40 41 |
# File 'lib/retrotoolkit/can_frame.rb', line 39 def formatted_output [identifier, dlc, data_field_bytes.join(' '), crc].join ' ' end |
#identifier ⇒ Object
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 |
#repr ⇒ Object
31 32 33 |
# File 'lib/retrotoolkit/can_frame.rb', line 31 def repr to_bits end |
#to_bits ⇒ Object
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_hex ⇒ Object
11 12 13 |
# File 'lib/retrotoolkit/can_frame.rb', line 11 def to_hex @value end |