Compare commits
2 Commits
72580bb5b2
...
4951861751
Author | SHA1 | Date | |
---|---|---|---|
4951861751 | |||
a0d9f5edae |
23
otime.py
23
otime.py
@ -230,10 +230,11 @@ class runner:
|
|||||||
return splits_cpy
|
return splits_cpy
|
||||||
|
|
||||||
class card_punch:
|
class card_punch:
|
||||||
def __init__(self, card, controls, splits, s_time, f_time):
|
def __init__(self, card, controls, splits, read_time, s_time, f_time):
|
||||||
self.card = card
|
self.card = card
|
||||||
self.controls = controls
|
self.controls = controls
|
||||||
self.splits = splits
|
self.splits = splits
|
||||||
|
self.read_time = read_time
|
||||||
self.s_time = s_time
|
self.s_time = s_time
|
||||||
self.f_time = f_time
|
self.f_time = f_time
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@ -268,10 +269,14 @@ class card_punch:
|
|||||||
milliseconds = int.from_bytes(datamsg[14:16], 'little')
|
milliseconds = int.from_bytes(datamsg[14:16], 'little')
|
||||||
|
|
||||||
read_time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds)
|
read_time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds)
|
||||||
start_time = read_time - datetime.timedelta(seconds = splits[-1])
|
if len(controls) > 2:
|
||||||
finish_time = read_time - datetime.timedelta(seconds = splits[-2])
|
s_time = read_time - datetime.timedelta(seconds = splits[-1])
|
||||||
|
f_time = read_time - (datetime.timedelta(seconds = splits[-1]) + datetime.timedelta(seconds = splits[-2]))
|
||||||
|
else:
|
||||||
|
s_time = read_time
|
||||||
|
f_time = read_time
|
||||||
|
|
||||||
return(card_punch(card, controls, splits, start_time, finish_time))
|
return(card_punch(card, controls, splits, read_time, s_time, f_time))
|
||||||
|
|
||||||
def list_from_mtr_f(mtr_f):
|
def list_from_mtr_f(mtr_f):
|
||||||
csvreader = csv.reader(open(mtr_f))
|
csvreader = csv.reader(open(mtr_f))
|
||||||
@ -309,12 +314,14 @@ class card_punch:
|
|||||||
tl[1] = tl[1].split(':')
|
tl[1] = tl[1].split(':')
|
||||||
tl[1][2] = float(tl[1][2])
|
tl[1][2] = float(tl[1][2])
|
||||||
tl[1] = list(map(int, tl[1]))
|
tl[1] = list(map(int, tl[1]))
|
||||||
f_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2])
|
read_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2])
|
||||||
if len(controls) > 2:
|
if len(controls) > 2:
|
||||||
s_time = f_time - datetime.timedelta(seconds = splits[-2])
|
s_time = read_time - datetime.timedelta(seconds = splits[-1])
|
||||||
|
f_time = read_time - (datetime.timedelta(seconds = splits[-1]) + datetime.timedelta(seconds = splits[-2]))
|
||||||
else:
|
else:
|
||||||
s_time = f_time
|
s_time = read_time
|
||||||
cards.append(card_punch(int(row[6]), controls, splits, s_time, f_time))
|
f_time = read_time
|
||||||
|
cards.append(card_punch(int(row[6]), controls, splits, read_time, s_time, f_time))
|
||||||
return cards
|
return cards
|
||||||
class course:
|
class course:
|
||||||
def __init__(self, name, codes):
|
def __init__(self, name, codes):
|
||||||
|
3
utilities/create_virt_serial.sh
Normal file
3
utilities/create_virt_serial.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
socat -d -d pty,rawer,b9600 pty,rawer,b9600
|
76
utilities/mtr_sim.py
Normal file
76
utilities/mtr_sim.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import argparse
|
||||||
|
import serial
|
||||||
|
import otime
|
||||||
|
from rich import inspect
|
||||||
|
def main():
|
||||||
|
global package_n
|
||||||
|
package_n = 0
|
||||||
|
argparser = argparse.ArgumentParser(
|
||||||
|
description=("Acts as a live mtr reading data line by line from a log file and sending them over serial"))
|
||||||
|
argparser.add_argument('port', help='Serial port identifier')
|
||||||
|
argparser.add_argument(
|
||||||
|
'-f', '--file',
|
||||||
|
help=(
|
||||||
|
"Mtr log file to use"))
|
||||||
|
argparser.add_argument(
|
||||||
|
'-v', '--verbose', action='store_true', help='Verbose output')
|
||||||
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
port = serial.Serial(port=args.port, baudrate=9600)
|
||||||
|
event = otime.event(0, 'NoName')
|
||||||
|
event.import_mtr_file(args.file)
|
||||||
|
|
||||||
|
for card in event.card_punches:
|
||||||
|
input('Press enter to send next card')
|
||||||
|
if args.verbose == True:
|
||||||
|
inspect(card)
|
||||||
|
data = card_to_bytes(card)
|
||||||
|
port.write(data)
|
||||||
|
|
||||||
|
def card_to_bytes(card):
|
||||||
|
global package_n
|
||||||
|
package_n += 1
|
||||||
|
msg = b'\xFF\xFF\xFF\xFF\xE6\x4D\x9C\x3E'
|
||||||
|
year = int(str(card.read_time.year)[2:4])
|
||||||
|
month = card.read_time.month
|
||||||
|
day = card.read_time.day
|
||||||
|
hour = card.read_time.hour
|
||||||
|
minute = card.read_time.minute
|
||||||
|
second = card.read_time.second
|
||||||
|
msg += year.to_bytes(1, byteorder='little')
|
||||||
|
msg += month.to_bytes(1, byteorder='little')
|
||||||
|
msg += day.to_bytes(1, byteorder='little')
|
||||||
|
msg += hour.to_bytes(1, byteorder='little')
|
||||||
|
msg += minute.to_bytes(1, byteorder='little')
|
||||||
|
msg += second.to_bytes(1, byteorder='little')
|
||||||
|
#ms
|
||||||
|
msg += b'\x00\x00'
|
||||||
|
|
||||||
|
msg += package_n.to_bytes(4, byteorder='little')
|
||||||
|
msg += card.card.to_bytes(3, byteorder='little')
|
||||||
|
|
||||||
|
# Gidder ikke å finne ut hva Producweek Producyear er
|
||||||
|
msg += b'\x00\x00'
|
||||||
|
|
||||||
|
# Hopper overogså over ECardHeadSum
|
||||||
|
msg += b'\x00'
|
||||||
|
|
||||||
|
for n in range(50):
|
||||||
|
try:
|
||||||
|
control = card.controls[n]
|
||||||
|
split = card.splits[n]
|
||||||
|
except:
|
||||||
|
control = 0
|
||||||
|
split = 0
|
||||||
|
msg += control.to_bytes(1, byteorder='little')
|
||||||
|
msg += split.to_bytes(2, byteorder='little')
|
||||||
|
# 56 byte string
|
||||||
|
msg += int(0).to_bytes(56, byteorder='little')
|
||||||
|
# Checksum
|
||||||
|
csum = sum(msg) % 256
|
||||||
|
msg += csum.to_bytes(1, byteorder='little')
|
||||||
|
msg += b'\x00'
|
||||||
|
return msg
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user