Fixed indentation

This commit is contained in:
Mario Gomez 2013-11-11 01:12:06 -06:00
parent f14e5608c0
commit 2786a14420

View file

@ -103,7 +103,6 @@ class MFRC522:
serNum = []
def __init__(self,spd=1000000):
spi.openSPI(speed=spd)
GPIO.setmode(GPIO.BOARD)
@ -157,26 +156,31 @@ class MFRC522:
self.Write_MFRC522(self.CommIEnReg, irqEn|0x80)
self.ClearBitMask(self.CommIrqReg, 0x80)
self.SetBitMask(self.FIFOLevelReg, 0x80)
self.Write_MFRC522(self.CommandReg, self.PCD_IDLE);
while(i<len(sendData)):
self.Write_MFRC522(self.FIFODataReg, sendData[i])
i = i+1
self.Write_MFRC522(self.CommandReg, command)
self.Write_MFRC522(self.CommandReg, command)
if command == self.PCD_TRANSCEIVE:
self.SetBitMask(self.BitFramingReg, 0x80)
i = 2000
while True:
n = self.Read_MFRC522(self.CommIrqReg)
i = i - 1
if ~((i!=0) and ~(n&0x01) and ~(n&waitIRq)):
break
self.ClearBitMask(self.BitFramingReg, 0x80)
if i != 0:
if (self.Read_MFRC522(self.ErrorReg) & 0x1B)==0x00:
status = self.MI_OK
if n & irqEn & 0x01:
status = self.MI_NOTAGERR
@ -187,6 +191,7 @@ class MFRC522:
backLen = (n-1)*8 + lastBits
else:
backLen = n*8
if n == 0:
n = 1
if n > self.MAX_LEN:
@ -276,29 +281,32 @@ class MFRC522:
buf.append(pOut[0])
buf.append(pOut[1])
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, buf)
if (status == self.MI_OK) and (backLen == 0x18):
size = backData[0]
print "Size: " + str(backData[0])
return backData[0]
else:
size = 0
return size
return 0
def MFRC522_Auth(self, authMode, BlockAddr, Sectorkey, serNum):
buff = []
buff.append(authMode)
buff.append(BlockAddr)
i = 0
while(i < 6):
while(i < len(Sectorkey)):
buff.append(Sectorkey[i])
i = i + 1
i = 0
while(i < 4):
while(i < len(serNum)):
buff.append(serNum[i])
i = i +1
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_AUTHENT,buff)
if not(status == self.MI_OK):
print "AUTH ERROR!!"
if not(self.Read_MFRC522(self.Status2Reg) & 0x08):
print "AUTH ERROR(status2reg & 0x08 != 0"
if not (self.Read_MFRC522(self.Status2Reg) & 0x08) != 0:
print "AUTH ERROR(status2reg & 0x08) != 0"
return status
def MFRC522_Read(self, blockAddr):
recvData = []
@ -326,6 +334,7 @@ class MFRC522:
(status, backData, backLen) = self.MFRC522_ToCard(self.PCD_TRANSCEIVE, buff)
if not(status == self.MI_OK) or not(backLen == 4) or not((backData[0] & 0x0F) == 0x0A):
status = self.MI_ERR
print str(backLen)+" backdata &0x0F == 0x0A "+str(backData[0]&0x0F)
if status == self.MI_OK:
i = 0
@ -378,15 +387,14 @@ while continue_reading:
(status,backData) = MIFAREReader.MFRC522_Anticoll()
if status == MIFAREReader.MI_OK:
print "Card read UID: "+str(backData[0])+","+str(backData[1])+","+str(backData[2])+","+str(backData[3])+","+str(backData[4])
key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]
MIFAREReader.MFRC522_SelectTag(backData)
key = [0xFF,0xFF,0xFF,0xFF,0xFF]
MIFAREReader.MFRC522_Auth(0x60,0,keyA,backData)
MIFAREReader.MFRC522_Read(0)
i = 1
while i < 64:
MIFAREReader.MFRC522_Auth(0x60,i,keyA,backData)
IFAREReader.MFRC522_Read(i)
i = i + 1
status = MIFAREReader.MFRC522_Auth(MIFAREReader.PICC_AUTHENT1A, 11, key, backData)
if status == MIFAREReader.MI_OK:
print "AUTH OK"
else:
print "AUTH ERROR"