Class: Msp430Bsl::HexLine

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Raises:

  • (StandardError)


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

#addrObject (readonly)

Returns the value of attribute addr.



7
8
9
# File 'lib/msp430_bsl/hex_line.rb', line 7

def addr
  @addr
end

#crcObject (readonly)

Returns the value of attribute crc.



7
8
9
# File 'lib/msp430_bsl/hex_line.rb', line 7

def crc
  @crc
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/msp430_bsl/hex_line.rb', line 7

def data
  @data
end

#data_lengthObject (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_addrObject (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

#numberObject (readonly)

Returns the value of attribute number.



7
8
9
# File 'lib/msp430_bsl/hex_line.rb', line 7

def number
  @number
end

#raw_dataObject (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

#typeObject (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

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (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