Compare commits
No commits in common. "b9562c04e00b7bb35a61bd2123e950b614151cd7" and "ed0f7f47f9ae773b001f0b6929f5fccca582cb6f" have entirely different histories.
b9562c04e0
...
ed0f7f47f9
|
@ -13,20 +13,6 @@ color_lookup = { "red": 31, "green": 32, "cyan": 36, "yellow": 33 }
|
||||||
def color(name, text):
|
def color(name, text):
|
||||||
return "\033[%dm%s\033[0m" % (color_lookup[name], text);
|
return "\033[%dm%s\033[0m" % (color_lookup[name], text);
|
||||||
|
|
||||||
try:
|
|
||||||
# On Unix systems, print an additional marker in the output stream
|
|
||||||
# when SIGUSR1 or SIGUSR2 is received. This is just to help clarify
|
|
||||||
# output when the chip is externally reset, etc.
|
|
||||||
import signal
|
|
||||||
def sigusr1_handler(signum, frame):
|
|
||||||
print(color("yellow", "--- mark ---"))
|
|
||||||
def sigusr2_handler(signum, frame):
|
|
||||||
print(color("yellow", "--- reset ---"))
|
|
||||||
signal.signal(signal.SIGUSR1, sigusr1_handler)
|
|
||||||
signal.signal(signal.SIGUSR2, sigusr2_handler)
|
|
||||||
except AttributeError as e:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class ResyncException(Exception):
|
class ResyncException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -83,7 +69,6 @@ class ITMParser:
|
||||||
except TimeoutException as e:
|
except TimeoutException as e:
|
||||||
# Timeout inside a parser should be reported.
|
# Timeout inside a parser should be reported.
|
||||||
print(color("red", "Timeout"))
|
print(color("red", "Timeout"))
|
||||||
break
|
|
||||||
except ResyncException as e:
|
except ResyncException as e:
|
||||||
print(color("red", "Resync"))
|
print(color("red", "Resync"))
|
||||||
|
|
||||||
|
@ -168,32 +153,15 @@ def main(argv):
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
ser = serial.Serial(args.device, args.baudrate)
|
ser = serial.Serial(args.device, args.baudrate)
|
||||||
|
ser.timeout = 1
|
||||||
print(color('green', 'ready'))
|
|
||||||
|
|
||||||
def input_stream():
|
def input_stream():
|
||||||
while True:
|
while True:
|
||||||
# Read one byte with a 1s timeout.
|
|
||||||
ser.timeout = 1
|
|
||||||
data = ser.read(1)
|
data = ser.read(1)
|
||||||
if len(data) == 0:
|
if len(data) == 0:
|
||||||
# Timeout
|
|
||||||
yield None
|
yield None
|
||||||
continue
|
else:
|
||||||
yield data[0]
|
yield data[0]
|
||||||
|
|
||||||
# Then read as many more as there are immediately
|
|
||||||
# available, and send them. This is more efficient than
|
|
||||||
# reading each individual byte, when they're coming in
|
|
||||||
# fast. Once they stop, we'll go back to the normal
|
|
||||||
# 1 byte read with timeout.
|
|
||||||
ser.timeout = 0
|
|
||||||
while True:
|
|
||||||
data = ser.read(65536)
|
|
||||||
if len(data) == 0:
|
|
||||||
break
|
|
||||||
for c in data:
|
|
||||||
yield c
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ITMParser(input_stream()).process()
|
ITMParser(input_stream()).process()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user