Class: OrigenMemoryImage::Binary
- Defined in:
- lib/origen_memory_image/binary.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #create_test_file ⇒ Object
-
#start_address ⇒ Object
Always returns 0 since binary files do not contain addresses.
Methods inherited from Base
#file_name, #flip_endianness, #has_start_record, #initialize, #lines, #to_a
Constructor Details
This class inherits a constructor from OrigenMemoryImage::Base
Class Method Details
.match?(file, snippet = false) ⇒ Boolean
3 4 5 6 7 8 9 10 11 |
# File 'lib/origen_memory_image/binary.rb', line 3 def self.match?(file, snippet = false) if snippet file.all? { |l| l.strip =~ /^[01]*$/ } else # detect whether the data is mostly not alpha numeric filedata = (File.read(file, 256) || '') (filedata.gsub(/\s+/, '').gsub(/\w/, '').length.to_f / filedata.length.to_f) > 0.3 end end |
Instance Method Details
#create_test_file ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/origen_memory_image/binary.rb', line 18 def create_test_file data = [ 0x1EE0021C, 0x22401BE0, 0x021C2243, 0x18E0021C, 0x5A780A43, 0x03E0034B, 0xF7215A78, 0x0A400020, 0x22E08442, 0x22D31FE0, 0x84421FD9, 0x1CE08442, 0x002B20D1, 0x03E0012A, 0x01D1002B, 0x1BD00223, 0x2340022A, 0x02D1002B, 0x15D103E0, 0x032A01D1, 0x78000018, 0x7C000018, 0x82000018, 0x88000018 ] data = data.map { |d| d.to_s(2).rjust(32, '0') }.join File.open('examples/bin1.bin', 'wb') do |output| output.write [data].pack('B*') end end |
#start_address ⇒ Object
Always returns 0 since binary files do not contain addresses
14 15 16 |
# File 'lib/origen_memory_image/binary.rb', line 14 def start_address 0 end |