This repository has been archived on 2024-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
memberPlumbing/doorUtil.py

40 lines
949 B
Python

#!/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):
for door in doors.values():
print(door.name)
fxn(door)
#forEachDoor(lambda door: door.sendCardFormat("A901146A-244", 1, 244))
#forEachDoor(lambda door: door.sendSchedules())