|
|
|
@ -239,6 +239,40 @@ class card_punch:
|
|
|
|
|
def __repr__(self):
|
|
|
|
|
return f'card({self.card}) controls({self.controls}) splits({self.splits})'
|
|
|
|
|
|
|
|
|
|
def from_mtr_bytes(datamsg):
|
|
|
|
|
card = int.from_bytes(datamsg[20:23], 'little')
|
|
|
|
|
|
|
|
|
|
#Extract codes and splits:
|
|
|
|
|
controls = []
|
|
|
|
|
splits = []
|
|
|
|
|
splits_offset = 26
|
|
|
|
|
code_numbytes = 1
|
|
|
|
|
time_numbytes = 2
|
|
|
|
|
split_numbytes = code_numbytes + time_numbytes
|
|
|
|
|
for split_index in range(50):
|
|
|
|
|
code_offset = splits_offset + split_index * split_numbytes
|
|
|
|
|
time_offset = code_offset + code_numbytes
|
|
|
|
|
code = int.from_bytes(datamsg[code_offset:code_offset+code_numbytes], 'little')
|
|
|
|
|
time = int.from_bytes(datamsg[time_offset:time_offset+time_numbytes], 'little')
|
|
|
|
|
if code != 0:
|
|
|
|
|
controls.append(code)
|
|
|
|
|
splits.append(time)
|
|
|
|
|
|
|
|
|
|
# Extract start time:
|
|
|
|
|
year = int.from_bytes(datamsg[8:9], 'little')
|
|
|
|
|
month = int.from_bytes(datamsg[9:10], 'little')
|
|
|
|
|
day = int.from_bytes(datamsg[10:11], 'little')
|
|
|
|
|
hours = int.from_bytes(datamsg[11:12], 'little')
|
|
|
|
|
minutes = int.from_bytes(datamsg[12:13], 'little')
|
|
|
|
|
seconds = int.from_bytes(datamsg[13:14], 'little')
|
|
|
|
|
milliseconds = int.from_bytes(datamsg[14:16], 'little')
|
|
|
|
|
|
|
|
|
|
read_time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds)
|
|
|
|
|
start_time = read_time - datetime.timedelta(seconds = splits[-1])
|
|
|
|
|
finish_time = read_time - datetime.timedelta(seconds = splits[-2])
|
|
|
|
|
|
|
|
|
|
return(card_punch(card, controls, splits, start_time, finish_time))
|
|
|
|
|
|
|
|
|
|
def list_from_mtr_f(mtr_f):
|
|
|
|
|
csvreader = csv.reader(open(mtr_f))
|
|
|
|
|
|
|
|
|
|