Class: Msp430Bsl::HexLine
- Inherits:
-
Object
- Object
- Msp430Bsl::HexLine
- Includes:
- Utils
- Defined in:
- lib/msp430_bsl/hex_line.rb
Constant Summary collapse
- RECORD_TYPES =
{ data: 0x00, eof: 0x01, ext_seg_addr: 0x02, start_seg_addr: 0x03, ext_lin_addr: 0x04, start_lin_addr: 0x05 }.freeze
Instance Attribute Summary collapse
-
#addr ⇒ Object
readonly
Returns the value of attribute addr.
-
#crc ⇒ Object
readonly
Returns the value of attribute crc.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#data_length ⇒ Object
readonly
Returns the value of attribute data_length.
-
#end_addr ⇒ Object
readonly
Returns the value of attribute end_addr.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #crc_ok? ⇒ Boolean
-
#has_addr_contiguous_to?(another_line) ⇒ Boolean
Checks if this line’s address is contiguous with the one of the given line Obviously this can be true only if the given line has an address that precedes this line’s one.
-
#initialize(data, num: nil) ⇒ HexLine
constructor
A new instance of HexLine.
- #is_of_type?(ty) ⇒ Boolean
Methods included from Utils
#build_logger_from, #crc16, #crc8, #normalize_log_level
Constructor Details
#initialize(data, num: nil) ⇒ HexLine
Returns a new instance of HexLine.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/msp430_bsl/hex_line.rb', line 18 def initialize(data, num: nil) raise StandardError, 'raw_data must be a String' unless data.is_a?(String) # Strip String, remove first char i.e. ':' and convert char couples to its hex value. @raw_data = data.strip[1..-1].to_hex_ary @data_length = raw_data[0] @addr = (raw_data[1] << 8) | raw_data[2] @type = raw_data[3] @data = raw_data.slice 4, data_length @crc = raw_data[-1] @number = num @end_addr = addr + data_length end |
Instance Attribute Details
#addr ⇒ Object (readonly)
Returns the value of attribute addr.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def addr @addr end |
#crc ⇒ Object (readonly)
Returns the value of attribute crc.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def crc @crc end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def data @data end |
#data_length ⇒ Object (readonly)
Returns the value of attribute data_length.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def data_length @data_length end |
#end_addr ⇒ Object (readonly)
Returns the value of attribute end_addr.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def end_addr @end_addr end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def number @number end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def raw_data @raw_data end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/msp430_bsl/hex_line.rb', line 7 def type @type end |
Instance Method Details
#crc_ok? ⇒ Boolean
39 40 41 |
# File 'lib/msp430_bsl/hex_line.rb', line 39 def crc_ok? crc == crc8(raw_data[0..-2]) end |
#has_addr_contiguous_to?(another_line) ⇒ Boolean
Checks if this line’s address is contiguous with the one of the given line Obviously this can be true only if the given line has an address that precedes this line’s one
35 36 37 |
# File 'lib/msp430_bsl/hex_line.rb', line 35 def has_addr_contiguous_to?(another_line) another_line.end_addr == addr end |
#is_of_type?(ty) ⇒ Boolean
43 44 45 46 |
# File 'lib/msp430_bsl/hex_line.rb', line 43 def is_of_type?(ty) ty = ty.to_sym type == RECORD_TYPES[ty] end |