X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=tools%2Fchowid.py;fp=tools%2Fchowid.py;h=0000000000000000000000000000000000000000;hp=0eed2c5b22d9d43bfd5c712e12ca2dfaf15544fe;hb=5398c69061a72e7a6ad3423c4e17516ee6d09de6;hpb=22b81b6c288ca56f58d064627c310e437f9453a4 diff --git a/tools/chowid.py b/tools/chowid.py deleted file mode 100644 index 0eed2c5..0000000 --- a/tools/chowid.py +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/python -# Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the -# distribution. -# * All advertising materials mentioning features or use of this -# software must display the following acknowledgement: This product -# includes software developed by tm3d.de and its contributors. -# * Neither the name of tm3d.de nor the names of its contributors may -# be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - - -import time -import subprocess - -def owcom(dev,send,rc): - res=[] - f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) - f.write("".join(map(chr, send))) - if (rc!=0): - res=map(ord,f.read(rc)) - f.close() - return res - - -def crc8(arr): - lscrc=0x0; - for v in arr: - bit=1; - while bit<256: - if (v&bit)==bit: - lb=1 - else: - lb=0 - if (lscrc&1)!=lb: - lscrc=(lscrc>>1)^0x8c - else: - lscrc=(lscrc>>1) - bit=bit*2 - return lscrc - -def testnr(s): - for c in s.lower()[:]: - if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): - return False - return True - -def addid(id,val): - for i in range(7): - id[i+1]=id[i+1]+val - if id[i+1]>254: - id[i+1]=id[i+1]-254 - val=1 - else: - return id - return id -# - -l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) -dc=0 -dl=[] -for g in (l.split("\n")): - if len(g)>2: - if testnr(g[0:2]): - dl.append(g) - dc=dc+1 - print dc,") ",g -if dc==0: - print "No 1-Wire Device found" - exit(0) -n=int(raw_input("No. of Device: ")) -n=n-1 -if (n>dc-1)or(n<0): - exit(0) -print dl[n], "will be changed" -s=dl[n] -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)] -nr.append(crc8(nr)) -onr=nr[:] -re=1 -while re: - re=0 - print "Number: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(nr) - print "1) Increment the old ID" - print "2) Add a value to the old ID (value < 255)" - print "3) Input 6 hex numbers like AA,B5,00,32,12,F1" - print "4) Exit" - cho=int(raw_input("Press the number of your choice: ")) - if cho==1: - nr=addid(nr,1) - elif cho==2: - val=int(raw_input("Add value <255: ")) - nr=addid(nr,val) - elif cho==3: - hn=raw_input("Input six numbers in hex (like AA,B5,00,32,12,F1): ") - i=1 - for hnt in hn.split(","): - nr[i]=int(hnt,16) - i=i+1 - elif cho==4: - exit() - else: - re=1 -nr[7]=crc8(nr[:-1]) -print "New ID: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(nr) -cho=raw_input("Set this ID? [Y/n): ") -if (cho!='Y'): - exit() - - -owcom(s,[0x75]+nr,0) -nnr=owcom(s,[0xA7],8) -print "New ID: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(nnr) -if nr!=nnr: - print "ERROR writing new ID\nMaybe it's no simulatet ow device from tm3d.de" - exit(0) -print "Old ID: %02X %02X %02X %02X %02X %02X %02X %02X" % tuple(onr) -owcom(s,[0x79,onr[1],onr[5],onr[6]],0) -print "Done.\nWait for a new Searchrom from Master\nSometimes the old nr keeps in the directory"