Implement replayer

This commit is contained in:
Johannes Wendel
2023-06-09 23:14:59 +02:00
parent c6408f755c
commit ad20fe5469
2 changed files with 33 additions and 30 deletions

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
pyserial

View File

@@ -1,41 +1,43 @@
import serial import datetime
from time import sleep from pathlib import Path
from dataclasses import dataclass
# Set up the serial port
ser = serial.Serial('/dev/ttyUSB0', 115200) # Replace with the appropriate port name and baud rate
# Define a list of hexadecimal numbers to send import serial
error = bytes.fromhex('ff e3')
ser = serial.Serial('/dev/ttyUSB0', 187500, parity=serial.PARITY_EVEN)
input_file_path = Path("recordings/b_2_2_tx.txt")
numbers = [i for i in range(255)] numbers = [i for i in range(255)]
@dataclass
class Result:
sent: bytes = b''
result: bytes = b''
results = [] def replay():
for num in numbers: with open(input_file_path) as input_file:
byt = num.to_bytes(num, "big") lines = input_file.readlines()
print("Writing: " + hex(num))
ser.write(byt)
sleep(0.01)
ser.write(bytes.fromhex('f9')) begin = datetime.datetime.now()
count = 1
for line in lines:
if "bit" in line:
continue
if "error" in line:
continue
data = ser.read(ser.in_waiting) int_to_send = int(line.split("TX: ")[1])
byte_to_send = int_to_send.to_bytes(int_to_send, "big")
ser.write(byte_to_send)
print(data) ser.read(1)
print(error)
if data not in error and data != b'': # wait for 2 acks
result = Result(sent=num, result=hex(int.from_bytes(data, "big"))) if (count % 3) == 0:
results.append(result) ser.read(1)
sleep(0.1)
count += 1
end = datetime.datetime.now()
print(end - begin)
replay()
for res in results:
print(res)
# Close the serial port
ser.close() ser.close()