Skip to content

Commit 214e157

Browse files
committed
add ability to specify door access
1 parent c789085 commit 214e157

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Add user (using 10-digit format RFID number):
5050

5151
badge = ten_digit_to_comma_format(11111111) # badge number needs to be converted to "comma format"
5252

53-
client.add_user(badge)
53+
client.add_user(badge, [1, 2]) # add privileges for door 1 & 2
5454

5555
Remove user (using 10-digit format RFID number):
5656

examples/add_user.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66

77
badge = ten_digit_to_comma_format(11111111) # badge number needs to be in "comma format"
88

9-
client.add_user(badge)
9+
client.add_user(badge, [1]) # add badge to door 1
10+
client.add_user(badge, [1, 2]) # add badge to door 1 and 2
11+
client.add_user(badge, [1, 2, 3]) # add badge to door 1, 2, and 3
12+
client.add_user(badge, [1, 2, 3, 4]) # add badge to door 1, 2, 3, and 4

examples/webserver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def index(self, apiKey=None, action=None, badge=None):
2020
return "Failed To Remove User"
2121
elif (action == "add"):
2222
try:
23-
client.add_user(badge)
23+
client.add_user(badge, [1,2])
2424
return "User Added Successfully"
2525
except:
2626
return "Failed To Add User"

rfid.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,20 @@ def CRC_16_IBM(self, data):
9696
listString[4:8] = struct.pack('<H', code).encode('hex') # switch order to little endian and return unsigned short, then replace characters in list with the CRC values
9797
return "".join(listString)
9898

99-
def add_user(self, badge):
99+
def add_user(self, badge, doors):
100100
if not isinstance(badge, int):
101101
raise TypeError("RFID number must be set to an integer")
102102

103+
if not isinstance(doors, list):
104+
raise Exception("doors must be set to a list")
105+
106+
# create a list of "01"'s (enabled) and "00"'s (disabled), then later join to create "01000000" (which is only door 1 enabled)
107+
doorsList = []
108+
doorsList.append("01") if 1 in doors else doorsList.append("00") # door 1
109+
doorsList.append("01") if 2 in doors else doorsList.append("00") # door 2
110+
doorsList.append("01") if 3 in doors else doorsList.append("00") # door 3
111+
doorsList.append("01") if 4 in doors else doorsList.append("00") # door 4
112+
103113
badge = struct.pack('<I', badge).encode('hex') # pack as little endian integer
104114

105115
add_packet1 = self.CRC_16_IBM('2010' + self.source_port + '2800000000000000' + self.controller_serial + '00000200ffffffff').decode('hex')
@@ -109,7 +119,7 @@ def add_user(self, badge):
109119
if (recv_data1[:4] != '2011'):
110120
raise Exception("Unexpected Result Received: %s" % recv_data1)
111121

112-
add_packet2 = self.CRC_16_IBM('2320' + self.source_port + '2900000000000000' + self.controller_serial + '00000200' + badge + '00000000a04e4605' + '87' + '1c9f3b0100000000000000').decode('hex')
122+
add_packet2 = self.CRC_16_IBM('2320' + self.source_port + '2900000000000000' + self.controller_serial + '00000200' + badge + '00000000a04e4605' + '87' + '1c9f3b' + "".join(doorsList) + '00000000').decode('hex')
113123
self.s.send(self.start_transaction)
114124
self.s.send(add_packet2)
115125
recv_data2 = binascii.b2a_hex(self.s.recv(1024))

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
setup(
1212
name='Chinese-RFID-Access-Control-Library',
13-
version='0.0.5',
13+
version='0.0.6',
1414
description='A library for interfacing with one of the most common RFID Access Control System sold in China.',
1515
long_description=readme,
1616
author='Paul Brown',
1717
author_email='paul90brown@gmail.com',
1818
url='https://github.com/pawl/Chinese-RFID-Access-Control-Library',
1919
license=license,
20-
download_url = ['https://github.com/pawl/Chinese-RFID-Access-Control-Library/tarball/master#egg=package-0.0.5'],
20+
download_url = ['https://github.com/pawl/Chinese-RFID-Access-Control-Library/tarball/master#egg=package-0.0.6'],
2121
keywords = ['rfid', 'access control'],
2222
py_modules = ['rfid']
2323
)

0 commit comments

Comments
 (0)