Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
517 ligi 1
#require 'rubygems'
2
require 'rio'
3
 
4
 
5
def hex2bin ( source_file , dest_file )
6
 
7
  plain_str=""
8
  last_addr=-1
9
  line_id=0;
10
  lines=0
11
  block=false
12
  File.read(source_file).each_line {|l|
13
    lines=lines+1
14
  }
15
  File.read(source_file).each_line {|l|
16
    line_id=line_id+1
17
    l.delete!("\n\r") # just to make sure
18
    data= l[9,(l.length-11)]
19
    size=l[1,2].to_i(16)
20
    addr=l[3,4].to_i(16)
21
    rectype=l[7,2].to_i(16)
22
    if rectype!=0
23
      p "rectype " + rectype.to_s
24
    end
25
    if ((last_addr!=-1)&&(addr!=last_addr))
26
      block=true
27
#      p "addr invalid" + addr.to_s(16)
28
#      p "data" + data
29
      p "line " +line_id.to_s +  "/" + lines.to_s + "=" + l
30
#      exit
31
    end
32
    last_addr=addr+size
33
    if size!= data.length/2
34
      p "data size not matching" + size +"vs"+ data.length.to_s
35
      exit
36
    end
37
 
38
 
39
    plain_str<<data if (rectype!=2)
40
    if rectype==2
41
     p "dropping rectype2"
42
    end
43
#    puts ">"+ l[9,(l.length-11)]
44
  }
45
 
46
 
47
  puts "size:" + (plain_str.length/2.0).to_s
48
 
49
  #return
50
  new = []
51
  (plain_str.length/2).times {|i|
52
    new << (plain_str[(i*2)..(i*2+1)].to_i(16))
53
  }
54
 
55
 
56
  foo=rio( dest_file)
57
  foo.write( ((new.length >> 24 )&0xff).chr)
58
  foo.write( ((new.length >> 16 )&0xff).chr)
59
  foo.write( ((new.length >> 8 )&0xff).chr)
60
  foo.write( ((new.length&0xff)).chr)
61
  new.each { |c|
62
    foo.write( c.chr)
63
  }
64
end
65
 
66
fc_lst=[]
67
nc_lst=[]
68
 
69
`rm firmwares/ -rf`
70
`mkdir -p firmwares/fc_mk3mag_firmwares`
71
`mkdir firmwares/all_firmwares`
72
`mkdir firmwares/no_firmwares`
73
 
74
Dir["orig/firmwares/public/*"].each { |hex_file|
75
  file_base=hex_file.split("/").last.gsub!(".hex","")
76
  p "processing: " +hex_file
77
  case hex_file
78
  when  /Navi/
79
    version=file_base.gsub("Navi-Ctrl","").gsub("_STR9","").gsub("_V","").gsub("_",".")
80
    p "navi " + version
81
    hex2bin(hex_file,"firmwares/all_firmwares/fw_224_" + nc_lst.length.to_s+".bin")
82
    nc_lst<<version
83
  when /Flight-Ctrl/
84
    version=file_base.gsub("Flight-Ctrl","").gsub("_MEGA644","").gsub("_V","").gsub("_",".")
85
    p "fc" + version
86
 
87
    hex2bin(hex_file,"firmwares/all_firmwares/fw_116_" + fc_lst.length.to_s+".bin")
88
    hex2bin(hex_file,"firmwares/fc_mk3mag_firmwares/fw_116_" + nc_lst.length.to_s+".bin")
89
 
90
    fc_lst<<version
91
    #    fc_fw_count=fc_fw_count+1
92
  end
93
}
94
 
95
 
96
 
97
rio("firmwares/fc_mk3mag_firmwares/fw_116.lst") < fc_lst.join("\n")
98
rio("firmwares/fc_mk3mag_firmwares/fw_116.lst") << "\n"
99
 
100
rio("firmwares/all_firmwares/fw_116.lst") < fc_lst.join("\n")
101
rio("firmwares/all_firmwares/fw_116.lst") << "\n"
102
 
103
 
104
 
105
rio("firmwares/all_firmwares/fw_224.lst") < nc_lst.join("\n")
106
rio("firmwares/all_firmwares/fw_224.lst") << "\n"
107
 
108
 
109