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

View File

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