2 # Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the
15 # * All advertising materials mentioning features or use of this
16 # software must display the following acknowledgement: This product
17 # includes software developed by tm3d.de and its contributors.
18 # * Neither the name of tm3d.de nor the names of its contributors may
19 # be used to endorse or promote products derived from this software
20 # without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 def owcom(dev,send,rc):
43 f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)
44 f.write("".join(map(chr, send)))
46 res=map(ord,f.read(rc))
68 for c in s.lower()[:]:
69 if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):
84 print "Open Hex File ...",
85 fi=open(sys.argv[1],"r")
87 for l in fi.readlines():
93 chsm=bc+(fw>>8)+(fw&0xFF)+ty
99 chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF
101 print "Error Checksum...."
107 l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)
110 for g in (l.split("\n")):
117 print "No 1-Wire Device found"
119 n=int(raw_input("No. of Device: "))
124 sys.stdout.write('Go to Flashmode....')
130 l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)
133 sys.stdout.write(".")
135 for g in (l.split("\n")):
136 if (g[0:15]=="a3-55aa55aa55aa"):
138 if (g[0:15]!="a3-55aa55aa55aa"):
140 if (g[0:15]=="a3-55aa55aa55aa"):
143 print "ERROR Enter Flashmode!"
145 f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)
153 print "Code to big ... Max 7616 Byte (119 Pages)"
156 for i in range(64-(l%64)):
161 print "Code to big ... Max 7616 Byte (119 Pages)"
165 print "Programm Page (of ", pages,")"
167 for i in range(pages):
168 sys.stdout.write("%i " % (i+1) )
175 mem=[hl,hh]+prog[h:h+64]
178 owcom(s,[0x0F]+mem,0)
179 rmem=owcom(s,[0xAA],66)
184 print "WRITING ERROR ... "
189 owcom(s,[0xB8,hl,hh],0)
191 rmem=owcom(s,[0xAA],66)
193 print "error in flash"
198 print "WRITING ERROR ... "
202 # print "%02X " % (v),
207 f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0)
208 f.write("a3-55aa55aa55aa")
217 #for i in range (64):
219 #owcom(s,[0x0F]+mem,0)
220 #rmem=owcom(s,[0xAA],70)
224 #owcom(s,[0xB8,0x00,0x02],0)
226 #rmem=owcom(s,[0xAA],70)
229 # print "%02X " % (v)