Skip to content

Commit 8ad1835

Browse files
committed
Added get_access_bits function
1 parent 0b4323a commit 8ad1835

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pirc522/util.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ def read_out(self, block_address):
135135
else:
136136
print("Error on " + self.sector_string(block_address))
137137

138+
def get_access_bits(self, c1, c2, c3):
139+
"""
140+
Calculates the access bits for a sector trailer based on their access conditions
141+
c1, c2, c3, c4 are 4 items tuples containing the values for each block
142+
returns the 3 bytes for the sector trailer
143+
"""
144+
byte_6 = ((~c2[3] & 1) << 7) + ((~c2[2] & 1) << 6) + ((~c2[1] & 1) << 5) + ((~c2[0] & 1) << 4) + \
145+
((~c1[3] & 1) << 3) + ((~c1[2] & 1) << 2) + ((~c1[1] & 1) << 1) + (~c1[0] & 1)
146+
byte_7 = ((c1[3] & 1) << 7) + ((c1[2] & 1) << 6) + ((c1[1] & 1) << 5) + ((c1[0] & 1) << 4) + \
147+
((~c3[3] & 1) << 3) + ((~c3[2] & 1) << 2) + ((~c3[1] & 1) << 1) + (~c3[0] & 1)
148+
byte_8 = ((c3[3] & 1) << 7) + ((c3[2] & 1) << 6) + ((c3[1] & 1) << 5) + ((c3[0] & 1) << 4) + \
149+
((c2[3] & 1) << 3) + ((c2[2] & 1) << 2) + ((c2[1] & 1) << 1) + (c2[0] & 1)
150+
return byte_6, byte_7, byte_8
151+
138152
def dump(self, sectors=16):
139153
for i in range(sectors * 4):
140154
self.read_out(i)

0 commit comments

Comments
 (0)