Class: Msp430Bsl::HexFile

Inherits:
Object
  • Object
show all
Defined in:
lib/msp430_bsl/hex_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ HexFile

Returns a new instance of HexFile.



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

def initialize(path)
  @path = File.expand_path path
  @raw_data = File.read path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/msp430_bsl/hex_file.rb', line 4

def path
  @path
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



4
5
6
# File 'lib/msp430_bsl/hex_file.rb', line 4

def raw_data
  @raw_data
end

Instance Method Details

#data_lines_grouped_by_contiguous_addrObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/msp430_bsl/hex_file.rb', line 19

def data_lines_grouped_by_contiguous_addr
  return @grouped_lines if @grouped_lines

  @grouped_lines = []
  curr_group = nil
  curr_addr = nil
  prev_line = nil
  lines.each do |line|
    next unless line.is_of_type? :data

    if curr_addr.nil?
      # We just started a new group
      curr_addr = line.addr
      curr_group = [line]
    elsif line.has_addr_contiguous_to? prev_line
      # We already have a current group
      curr_group << line
      curr_addr = line.addr
    else
      @grouped_lines << curr_group
      curr_addr = nil
      redo
    end

    prev_line = line
  end

  @grouped_lines << curr_group if curr_group.any?

  @grouped_lines
end

#linesObject



11
12
13
14
15
16
17
# File 'lib/msp430_bsl/hex_file.rb', line 11

def lines
  return @lines if @lines

  @lines = []
  raw_data.each_line.with_index { |line, i| @lines << HexLine.new(line, num: i) }
  @lines
end