Class: WOoo::Electronics::IntelHexFile
- Inherits:
-
Object
- Object
- WOoo::Electronics::IntelHexFile
- Defined in:
- lib/wo_oo/electronics/intel_hex_file.rb
Class Method Summary collapse
-
.checksum(data) ⇒ Object
—————————————————————-.
- .read(path) ⇒ Object
-
.write(path, data, start_address = 0) ⇒ Object
—————————————————————-.
Class Method Details
.checksum(data) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/wo_oo/electronics/intel_hex_file.rb', line 56 def self.checksum(data) checksum = 0 data.scan(/../).each do |value| checksum += WOoo::Util::HexUtil.to_i(value) end checksum = ((checksum & 255) ^ 255) + 1 checksum end |
.read(path) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wo_oo/electronics/intel_hex_file.rb', line 8 def self.read(path) file_content = File.read(path) parser = WOoo::Electronics::IntelHexParser.new result = parser.parse(file_content) unless result.nil? hex_data = result.eval WOoo::Util::HexUtil.to_i(hex_data.scan(/../)) else # TO FIX puts "PARSING ERROR!" puts parser.terminal_failures.join("\n") puts "----" end end |
.write(path, data, start_address = 0) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wo_oo/electronics/intel_hex_file.rb', line 28 def self.write(path, data, start_address = 0) next_address = start_address File.open(path, "w") do |file| while (line_data = data.slice!(0..15)).size > 0 line_size = line_data.size file.print ":" line = WOoo::Util::HexUtil.to_hex8(line_size) line += WOoo::Util::HexUtil.to_hex16(next_address) line += "00" line += WOoo::Util::HexUtil.to_hex8(line_data).join("") file.print line file.print WOoo::Util::HexUtil.to_hex8(checksum(line)) file.print "\n" next_address += line_size end file.print ":00000001FF" end end |