2 # Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
\r
3 # All rights reserved.
\r
5 # Redistribution and use in source and binary forms, with or without
\r
6 # modification, are permitted provided that the following conditions are
\r
9 # * Redistributions of source code must retain the above copyright
\r
10 # notice, this list of conditions and the following disclaimer.
\r
11 # * Redistributions in binary form must reproduce the above copyright
\r
12 # notice, this list of conditions and the following disclaimer in the
\r
13 # documentation and/or other materials provided with the
\r
15 # * All advertising materials mentioning features or use of this
\r
16 # software must display the following acknowledgement: This product
\r
17 # includes software developed by tm3d.de and its contributors.
\r
18 # * Neither the name of tm3d.de nor the names of its contributors may
\r
19 # be used to endorse or promote products derived from this software
\r
20 # without specific prior written permission.
\r
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
\r
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
\r
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
\r
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
\r
26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
41 def owcom(dev,send,rc):
\r
44 f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)
\r
46 l=subprocess.check_output("rmmod w1_therm",shell=True)
\r
47 f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)
\r
48 f.write("".join(map(chr, send)))
\r
50 res=map(ord,f.read(rc))
\r
67 lscrc=(lscrc>>1)^0x8c
\r
74 for c in s.lower()[:]:
\r
75 if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):
\r
92 print "A hex-File is needed! \n"
\r
93 print "sudo python owflash.py test.hex"
\r
100 f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)
\r
106 print "Open Hex File ...",
\r
107 fi=open(sys.argv[1],"r")
\r
109 for l in fi.readlines():
\r
110 sys.stdout.write(".")
\r
115 chsm=bc+(fw>>8)+(fw&0xFF)+ty
\r
116 for i in range(bc):
\r
121 chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF
\r
123 print "Error Checksum...."
\r
125 #print bc,fw,ty,chsm
\r
129 l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)
\r
132 for g in (l.split("\n")):
\r
139 print "No 1-Wire Device found"
\r
141 n=int(raw_input("No. of Device: "))
\r
143 if (n>dc-1)or(n<0):
\r
146 if (s!="a3-55aa55aa55aa"):
\r
147 sys.stdout.write('Go to Flashmode....')
\r
152 for i in range (20):
\r
153 l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)
\r
156 sys.stdout.write(".")
\r
158 for g in (l.split("\n")):
\r
159 if (g[0:15]=="a3-55aa55aa55aa"):
\r
161 if (g[0:15]!="a3-55aa55aa55aa"):
\r
163 if (g[0:15]=="a3-55aa55aa55aa"):
\r
166 print "ERROR Enter Flashmode!"
\r
168 f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)
\r
174 print("Disable Device Search (Wait 15s)")
\r
175 f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)
\r
180 s="a3-55aa55aa55aa"
\r
184 print "Code to big ... Max 7552 Byte (118 Pages)"
\r
187 for i in range(64-(l%64)):
\r
190 pages= len(prog)/64
\r
192 print "Code to big ... Max 7552 Byte (118 Pages)"
\r
196 print "Programm Page (of ", pages,")"
\r
198 for i in range(pages):
\r
199 sys.stdout.write("%i " % (i+1) )
\r
206 mem=[hl,hh]+prog[h:h+64]
\r
209 owcom(s,[0x0F]+mem,0)
\r
210 rmem=owcom(s,[0xAA],66)
\r
215 print "WRITING ERROR ... "
\r
220 owcom(s,[0xB8,hl,hh],0)
\r
222 rmem=owcom(s,[0xAA],66)
\r
224 print "error in flash"
\r
229 print "WRITING ERROR ... "
\r
233 # print "%02X " % (v),
\r
235 print "\nReset AVR"
\r
238 f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)
\r
239 f.write("a3-55aa55aa55aa")
\r
242 print("Enable Device Search")
\r
243 f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0)
\r
253 #for i in range (64):
\r
255 #owcom(s,[0x0F]+mem,0)
\r
256 #rmem=owcom(s,[0xAA],70)
\r
260 #owcom(s,[0xB8,0x00,0x02],0)
\r
262 #rmem=owcom(s,[0xAA],70)
\r
265 # print "%02X " % (v)
\r