srec 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/srec.rb +73 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95267ac3800d4f13d42b6602cf1520cddfcf8437
4
+ data.tar.gz: 445799bb6521c0e56546f9150e423775a94c2463
5
+ SHA512:
6
+ metadata.gz: 0282d665d8b3faf0463af672eafbc1042ade6b8a51434d6bad25ed2c1d46c3266132873d7af4c254446ee4bd765561d242f566a9d2fbd5da2c0ed74b7b73d578
7
+ data.tar.gz: 2544c64f010c38b153725d6adcebbac2cedefc7ab02b8aef5226b61ce82b8a2fd406bd450598f989920b58725ed5f133bc01f34500c296f8ca110d69598a84e1
data/lib/srec.rb ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: UTF-8
3
+
4
+ require "pp"
5
+
6
+ class Srec
7
+ def initialize(hash={})
8
+ if hash[:file]
9
+ if not File.exist? hash[:file]
10
+ puts "Error: File not found #{hash[:file]}"
11
+ return nil
12
+ end
13
+ @data=IO.read(hash[:file]).gsub(/\r/,"")
14
+ else
15
+ puts "Error: File must be given!"
16
+ return nil
17
+ end
18
+ @lines=@data.split "\n"
19
+ @mem={}
20
+ @bytes=0
21
+ @lines.each do |l|
22
+ if l[0]=='S'
23
+ type=l[1].to_i
24
+ len=l[2...4].to_i(16)
25
+ case type
26
+ when 0,1,9,5
27
+ alen=2
28
+ when 2,8,6
29
+ alen=3
30
+ when 3,7
31
+ alen=4
32
+ else
33
+ next
34
+ end
35
+ addr=l[4...4+alen*2].to_i(16)
36
+ dp=4+alen*2
37
+ b=[]
38
+ (len-alen).times do |i|
39
+ b << l[dp+i*2..dp+i*2+1].to_i(16)
40
+ end
41
+ crc= b.pop
42
+ @bytes+=b.size
43
+ if [1,2,3].include? type
44
+ @mem[addr]=b
45
+ elsif [7,8,9].include? type
46
+ @boot=b
47
+ elsif type==0
48
+ @info=b.pack("c*")
49
+ else
50
+ puts "Warning: Unsupported line : #{l}"
51
+ end
52
+ end
53
+ end
54
+ puts "'#{@info}': #{@mem.length} Records, #{@bytes} Bytes"
55
+ end
56
+ def to_blocks min,max,size
57
+ blks={}
58
+ @mem.each do |a,b|
59
+ len=b.size
60
+ len.times do |i|
61
+ if a+i>max or a+i<min
62
+ puts "Error: data out of range #{(a+i).to_s(16)} [#{min.to_s(16)}..#{max.to_s(16)}]"
63
+ next
64
+ end
65
+ blk=(a+i-min)/size
66
+ oset=(a+i-min)%size
67
+ blks[blk]=Array.new(size,0) if not blks[blk]
68
+ blks[blk][oset]=b[i]
69
+ end
70
+ end
71
+ blks
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: srec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ari Siitonen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Pure Ruby Motorola s-record support for ruby -- library to access and
14
+ manipulate srec-files
15
+ email: jalopuuverstas@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/srec.rb
21
+ homepage: https://github.com/arisi/srec
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Pure Ruby Motorola s-record support for ruby
45
+ test_files: []