Compare commits
No commits in common. "72580bb5b2267860c14ec3d65ea79e23b8a089d1" and "c717f723b6efbade659804bdf3f961eb12acb8d9" have entirely different histories.
72580bb5b2
...
c717f723b6
14
mtrlog.py
14
mtrlog.py
@ -23,13 +23,13 @@ class MtrLogFormatter:
|
|||||||
'"%s"' % datetime_extracted.strftime('%d.%m.%y %H:%M:%S.000'))
|
'"%s"' % datetime_extracted.strftime('%d.%m.%y %H:%M:%S.000'))
|
||||||
log_line.append(
|
log_line.append(
|
||||||
'"%02d.%02d.%02d %02d:%02d:%02d.%03d"' % (
|
'"%02d.%02d.%02d %02d:%02d:%02d.%03d"' % (
|
||||||
msg.day(),
|
msg.timestamp_day(),
|
||||||
msg.month(),
|
msg.timestamp_month(),
|
||||||
msg.year(),
|
msg.timestamp_year(),
|
||||||
msg.hours(),
|
msg.timestamp_hours(),
|
||||||
msg.minutes(),
|
msg.timestamp_minutes(),
|
||||||
msg.seconds(),
|
msg.timestamp_seconds(),
|
||||||
msg.milliseconds()))
|
msg.timestamp_milliseconds()))
|
||||||
log_line.append('%06d' % msg.card_id())
|
log_line.append('%06d' % msg.card_id())
|
||||||
log_line.append('%04d' % 0) # skipped product week
|
log_line.append('%04d' % 0) # skipped product week
|
||||||
log_line.append('%04d' % 0) # skipped product year
|
log_line.append('%04d' % 0) # skipped product year
|
||||||
|
28
mtrreader.py
28
mtrreader.py
@ -170,25 +170,25 @@ class MtrStatusMessage:
|
|||||||
def mtr_id(self):
|
def mtr_id(self):
|
||||||
return int.from_bytes(self.message_bytes[6:8], 'little')
|
return int.from_bytes(self.message_bytes[6:8], 'little')
|
||||||
|
|
||||||
def year(self):
|
def timestamp_year(self):
|
||||||
return int.from_bytes(self.message_bytes[8:9], 'little')
|
return int.from_bytes(self.message_bytes[8:9], 'little')
|
||||||
|
|
||||||
def month(self):
|
def timestamp_month(self):
|
||||||
return int.from_bytes(self.message_bytes[9:10], 'little')
|
return int.from_bytes(self.message_bytes[9:10], 'little')
|
||||||
|
|
||||||
def day(self):
|
def timestamp_day(self):
|
||||||
return int.from_bytes(self.message_bytes[10:11], 'little')
|
return int.from_bytes(self.message_bytes[10:11], 'little')
|
||||||
|
|
||||||
def hours(self):
|
def timestamp_hours(self):
|
||||||
return int.from_bytes(self.message_bytes[11:12], 'little')
|
return int.from_bytes(self.message_bytes[11:12], 'little')
|
||||||
|
|
||||||
def minutes(self):
|
def timestamp_minutes(self):
|
||||||
return int.from_bytes(self.message_bytes[12:13], 'little')
|
return int.from_bytes(self.message_bytes[12:13], 'little')
|
||||||
|
|
||||||
def seconds(self):
|
def timestamp_seconds(self):
|
||||||
return int.from_bytes(self.message_bytes[13:14], 'little')
|
return int.from_bytes(self.message_bytes[13:14], 'little')
|
||||||
|
|
||||||
def milliseconds(self):
|
def timestamp_milliseconds(self):
|
||||||
return int.from_bytes(self.message_bytes[14:16], 'little')
|
return int.from_bytes(self.message_bytes[14:16], 'little')
|
||||||
|
|
||||||
def battery_status(self):
|
def battery_status(self):
|
||||||
@ -214,25 +214,25 @@ class MtrDataMessage:
|
|||||||
def mtr_id(self):
|
def mtr_id(self):
|
||||||
return int.from_bytes(self.message_bytes[6:8], 'little')
|
return int.from_bytes(self.message_bytes[6:8], 'little')
|
||||||
|
|
||||||
def year(self):
|
def timestamp_year(self):
|
||||||
return int.from_bytes(self.message_bytes[8:9], 'little')
|
return int.from_bytes(self.message_bytes[8:9], 'little')
|
||||||
|
|
||||||
def month(self):
|
def timestamp_month(self):
|
||||||
return int.from_bytes(self.message_bytes[9:10], 'little')
|
return int.from_bytes(self.message_bytes[9:10], 'little')
|
||||||
|
|
||||||
def day(self):
|
def timestamp_day(self):
|
||||||
return int.from_bytes(self.message_bytes[10:11], 'little')
|
return int.from_bytes(self.message_bytes[10:11], 'little')
|
||||||
|
|
||||||
def hours(self):
|
def timestamp_hours(self):
|
||||||
return int.from_bytes(self.message_bytes[11:12], 'little')
|
return int.from_bytes(self.message_bytes[11:12], 'little')
|
||||||
|
|
||||||
def minutes(self):
|
def timestamp_minutes(self):
|
||||||
return int.from_bytes(self.message_bytes[12:13], 'little')
|
return int.from_bytes(self.message_bytes[12:13], 'little')
|
||||||
|
|
||||||
def seconds(self):
|
def timestamp_seconds(self):
|
||||||
return int.from_bytes(self.message_bytes[13:14], 'little')
|
return int.from_bytes(self.message_bytes[13:14], 'little')
|
||||||
|
|
||||||
def milliseconds(self):
|
def timestamp_milliseconds(self):
|
||||||
return int.from_bytes(self.message_bytes[14:16], 'little')
|
return int.from_bytes(self.message_bytes[14:16], 'little')
|
||||||
|
|
||||||
def packet_num(self):
|
def packet_num(self):
|
||||||
|
34
otime.py
34
otime.py
@ -239,40 +239,6 @@ class card_punch:
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'card({self.card}) controls({self.controls}) splits({self.splits})'
|
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):
|
def list_from_mtr_f(mtr_f):
|
||||||
csvreader = csv.reader(open(mtr_f))
|
csvreader = csv.reader(open(mtr_f))
|
||||||
|
|
||||||
|
@ -3,36 +3,17 @@ import mtrreader
|
|||||||
from rich import inspect
|
from rich import inspect
|
||||||
import mtrlog
|
import mtrlog
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import binascii
|
|
||||||
import otime
|
|
||||||
|
|
||||||
mtr = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=40)
|
mtr = serial.Serial(port='/dev/ttyUSB0', baudrate=9600, timeout=40)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pree = mtr.read_until(expected=b'\xFF\xFF\xFF\xFF')
|
data = mtr.read_until(expected='FFFFFFFFFF', size=230)
|
||||||
size = mtr.read(size=1)
|
print('START')
|
||||||
if size == b'\xe6':
|
msg = mtrreader.MtrDataMessage(data)
|
||||||
meat = mtr.read(229)
|
f = mtrlog.MtrLogFormatter
|
||||||
print('START')
|
print(f.format(f, msg, datetime.now()))
|
||||||
|
print('END')
|
||||||
full = b'\xFF\xFF\xFF\xFF' + size + meat
|
|
||||||
print(binascii.hexlify(full))
|
|
||||||
msg = mtrreader.MtrDataMessage(full)
|
|
||||||
f = mtrlog.MtrLogFormatter
|
|
||||||
#print(f.format(f, msg, datetime.now()))
|
|
||||||
#card_r_from_mtr_bytes(full)
|
|
||||||
inspect(otime.card_punch.from_mtr_bytes(full))
|
|
||||||
print('END')
|
|
||||||
elif size == b'\x37':
|
|
||||||
meat = mtr.read(55)
|
|
||||||
status = mtrreader.MtrStatusMessage(meat)
|
|
||||||
inspect(status)
|
|
||||||
print(status.year(),status.month(),status.day(),status.hours(),status.minutes())
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
def send_status_command(mtr):
|
|
||||||
mtr.write(b'/ST')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#send_status_command(mtr)
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user