Compare commits
No commits in common. "4951861751c381515ab7900bd04043ff3c26c58e" and "72580bb5b2267860c14ec3d65ea79e23b8a089d1" have entirely different histories.
4951861751
...
72580bb5b2
23
otime.py
23
otime.py
@ -230,11 +230,10 @@ class runner:
|
||||
return splits_cpy
|
||||
|
||||
class card_punch:
|
||||
def __init__(self, card, controls, splits, read_time, s_time, f_time):
|
||||
def __init__(self, card, controls, splits, s_time, f_time):
|
||||
self.card = card
|
||||
self.controls = controls
|
||||
self.splits = splits
|
||||
self.read_time = read_time
|
||||
self.s_time = s_time
|
||||
self.f_time = f_time
|
||||
def __repr__(self):
|
||||
@ -269,14 +268,10 @@ class card_punch:
|
||||
milliseconds = int.from_bytes(datamsg[14:16], 'little')
|
||||
|
||||
read_time = datetime.datetime(year, month, day, hours, minutes, seconds, milliseconds)
|
||||
if len(controls) > 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
|
||||
start_time = read_time - datetime.timedelta(seconds = splits[-1])
|
||||
finish_time = read_time - datetime.timedelta(seconds = splits[-2])
|
||||
|
||||
return(card_punch(card, controls, splits, read_time, s_time, f_time))
|
||||
return(card_punch(card, controls, splits, start_time, finish_time))
|
||||
|
||||
def list_from_mtr_f(mtr_f):
|
||||
csvreader = csv.reader(open(mtr_f))
|
||||
@ -314,14 +309,12 @@ class card_punch:
|
||||
tl[1] = tl[1].split(':')
|
||||
tl[1][2] = float(tl[1][2])
|
||||
tl[1] = list(map(int, tl[1]))
|
||||
read_time = datetime.datetime(tl[0][2], tl[0][1], tl[0][0], tl[1][0], tl[1][1], tl[1][2])
|
||||
f_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:
|
||||
s_time = read_time - datetime.timedelta(seconds = splits[-1])
|
||||
f_time = read_time - (datetime.timedelta(seconds = splits[-1]) + datetime.timedelta(seconds = splits[-2]))
|
||||
s_time = f_time - datetime.timedelta(seconds = splits[-2])
|
||||
else:
|
||||
s_time = read_time
|
||||
f_time = read_time
|
||||
cards.append(card_punch(int(row[6]), controls, splits, read_time, s_time, f_time))
|
||||
s_time = f_time
|
||||
cards.append(card_punch(int(row[6]), controls, splits, s_time, f_time))
|
||||
return cards
|
||||
class course:
|
||||
def __init__(self, name, codes):
|
||||
|
@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
socat -d -d pty,rawer,b9600 pty,rawer,b9600
|
@ -1,76 +0,0 @@
|
||||
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