Cleanup of Notebook Adapter emulator

Removed the CTS line watching. Just restart the software
manually for each new transfer :)

Line endings after each group of sync bytes and after each packet
This commit is contained in:
Simon Larsson
2021-08-10 17:09:03 +02:00
parent 6feafe6675
commit f863e19425
+14 -26
View File
@@ -15,9 +15,6 @@ On reset the device can respond to 3 commands:
In transmit mode, all bytes should be echoed back to the PC and the
commands above should not be answered. Transmit mode is only left upon
reset.
The device is powered from the CTS control line, so this is pulled down
at the beginning of transmission to make sure the device is reset.
"""
@@ -36,31 +33,20 @@ if len(sys.argv) == 4:
# Used for rudimentary packet parsing
pastSync = 0
packetLeft = 0
packetLeft = -1
with serial.Serial(serialPort, 9600, timeout=0.1) as sp:
with serial.Serial(serialPort, 9600) as sp:
# Used to control state of device
transmitState = False
def send(data):
# print("Sending: '{}'".format(data))
sp.write(data)
while True:
while True:
# CTS control line is used for powering device, and therefore also reset it
# Inactivated due to not available on all USB-Serial converters
if False and sp.cts == False:
if transmitState:
print("Leaving transmit state")
logfile.close()
transmitState = False
inb = sp.read(1)
if len(inb) != 0:
break
print("Received: {}".format(inb))
inb = sp.read(1)
if len(inb) == 0:
break
if not transmitState:
if inb == b"x":
@@ -81,21 +67,23 @@ with serial.Serial(serialPort, 9600, timeout=0.1) as sp:
print("Received unknown byte ({}) outside of transmit state".format(inb))
else:
if inb != b'U':
if pastSync == 0 and inb != b'U':
pastSync = 1
if pastSync and inb != b'\xAA':
if packetLeft == 0:
logfile.write("\n".encode())
logfile.write("\n".encode())
if pastSync == 1 and inb != b'\xAA':
pastSync = 2
packetLeft = 0
if pastSync == 2 and packetLeft == 0:
packetLeft = ord(inb)
logfile.write("\n".encode())
if logText:
logfile.write(("0x{:02x} ".format(ord(inb))).encode())
if pastSync==2:
if packetLeft > 0:
packetLeft -= 1
if packetLeft > 0:
packetLeft -= 1
else:
logfile.write(inb)
send(inb)