Implement replayer
This commit is contained in:
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pyserial
|
||||||
62
write.py
62
write.py
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user