2018-08-13 12:32:04 -04:00
|
|
|
#!/usr/bin/env python3
|
2019-11-08 14:46:23 -05:00
|
|
|
import bitstring
|
|
|
|
|
2018-08-13 12:32:04 -04:00
|
|
|
import requests
|
|
|
|
import csv
|
|
|
|
from io import StringIO
|
|
|
|
|
|
|
|
from common import *
|
|
|
|
|
2019-11-08 14:46:23 -05:00
|
|
|
# Reference for H10301 card format:
|
|
|
|
# https://www.hidglobal.com/sites/default/files/hid-understanding_card_data_formats-wp-en.pdf
|
|
|
|
|
|
|
|
|
|
|
|
def hexToCode(h):
|
|
|
|
b = bitstring.Bits(hex=h)
|
|
|
|
facility = b[7:15].uint
|
|
|
|
code = b[15:31].uint
|
|
|
|
return ((facility, code))
|
|
|
|
|
2018-08-13 12:32:04 -04:00
|
|
|
|
|
|
|
def codeToHex(facility, code):
|
2019-11-08 14:46:23 -05:00
|
|
|
b = bitstring.pack('0b000000, uint:1, uint:8, uint:16, uint:1', 0,
|
|
|
|
facility, code, 0)
|
|
|
|
# calculate parity bits
|
|
|
|
b[6] = b[7:19].count(1) % 2 # even parity
|
|
|
|
b[31] = not (b[19:31].count(1) % 2) # odd parity
|
|
|
|
return b.hex.upper()
|
|
|
|
|
2018-08-13 12:32:04 -04:00
|
|
|
|
|
|
|
# hexToCode("01E29DA1") <-> codeToHex(241, 20176)
|
|
|
|
|
2019-11-08 14:46:23 -05:00
|
|
|
|
2018-08-13 12:32:04 -04:00
|
|
|
def forEachDoor(fxn):
|
2018-08-16 14:01:42 -04:00
|
|
|
for door in doors.values():
|
|
|
|
print(door.name)
|
|
|
|
fxn(door)
|
2018-08-13 12:32:04 -04:00
|
|
|
|
2018-08-16 14:01:42 -04:00
|
|
|
#forEachDoor(lambda door: door.sendCardFormat("A901146A-244", 1, 244))
|
|
|
|
#forEachDoor(lambda door: door.sendSchedules())
|