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.
40 def owcom(dev,send,rc):
42 f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)
43 f.write("".join(map(chr, send)))
45 res=map(ord,f.read(rc))
67 for c in s.lower()[:]:
68 if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):
83 l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)
86 for g in (l.split("\n")):
93 print "No 1-Wire Device found"
95 n=int(raw_input("No. of Device: "))
99 print dl[n], "will be changed"
101 nr=[int(s[0:2],16),int(s[13:15],16),int(s[11:13],16),int(s[9:11],16),int(s[7:9],16),int(s[5:7],16),int(s[3:5],16)]
107 print "Number: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(nr)
108 print "1) Increment the old ID"
109 print "2) Add a value to the old ID (value < 255)"
110 print "3) Input 6 hex numbers like AA,B5,00,32,12,F1"
112 cho=int(raw_input("Press the number of your choice: "))
116 val=int(raw_input("Add value <255: "))
119 hn=raw_input("Input six numbers in hex (like AA,B5,00,32,12,F1): ")
121 for hnt in hn.split(","):
129 print "New ID: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(nr)
130 cho=raw_input("Set this ID? [Y/n): ")
136 nnr=owcom(s,[0xA7],8)
137 print "New ID: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(nnr)
139 print "ERROR writing new ID\nMaybe it's no simulatet ow device from tm3d.de"
141 print "Old ID: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(onr)
142 owcom(s,[0x79,onr[1],onr[5],onr[6]],0)
143 print "Done.\nWait for a new Searchrom from Master\nSometimes the old nr keeps in the directory"