memberPlumbing/doorUtil.py

40 lines
949 B
Python
Raw Normal View History

#!/usr/bin/env python3
import bitstring
import requests
import csv
from io import StringIO
from common import *
# 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))
def codeToHex(facility, code):
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()
# hexToCode("01E29DA1") <-> codeToHex(241, 20176)
def forEachDoor(fxn):
2018-08-16 14:01:42 -04:00
for door in doors.values():
print(door.name)
fxn(door)
2018-08-16 14:01:42 -04:00
#forEachDoor(lambda door: door.sendCardFormat("A901146A-244", 1, 244))
#forEachDoor(lambda door: door.sendSchedules())