Class: IntelHex::FileReader
- Inherits:
-
Object
- Object
- IntelHex::FileReader
- Defined in:
- lib/intel_hex/file_reader.rb
Instance Method Summary collapse
- #each_byte_with_address ⇒ Object
- #each_record ⇒ Object
-
#initialize(filename) ⇒ FileReader
constructor
A new instance of FileReader.
Constructor Details
#initialize(filename) ⇒ FileReader
Returns a new instance of FileReader.
5 6 7 8 9 |
# File 'lib/intel_hex/file_reader.rb', line 5 def initialize(filename) @filename = filename @address_base = 0 @address_mask = 0xffff end |
Instance Method Details
#each_byte_with_address ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/intel_hex/file_reader.rb', line 27 def each_byte_with_address return enum_for(:each_byte_with_address) unless block_given? each_record do |record| case record.type when :data record.each_byte_with_address do |byte, offset| yield byte, (@address_base + (offset & 0xffff)) & @address_mask end when :esa @address_base = record.value << 4 # bits 4..19 of address @address_mask = 0xfffff # 20 bit address size when :ela @address_base = record.value << 16 # bits 16..31 of address @address_mask = 0xffffffff # 32 bit address size end end nil end |
#each_record ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/intel_hex/file_reader.rb', line 11 def each_record return enum_for(:each_record) unless block_given? file = File.open(@filename, "r") begin file.each_line do |line| yield Record.parse(line.chomp) end rescue EOFError return nil end nil end |