-
Notifications
You must be signed in to change notification settings - Fork 1
/
serialHost.py
executable file
·62 lines (49 loc) · 1.26 KB
/
serialHost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /usr/bin/env python
import serial
import time
from disass import decode, render_instr
from glob import glob
port = glob("/dev/ttyUSB*")
assert( len(port) > 0 )
ser = serial.Serial(
port=port[0],
baudrate=115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0
)
print("connected to: " + ser.portstr)
#this will store the line
seq = []
count = 1
miss = 0
instr=[]
while True:
for c in ser.read():
if chr(c) != '\n':
seq.append(chr(c)) #convert to ascii
continue
ser_line = ''.join(str(v) for v in seq) #Make a string from array
seq = []
try:
addr_cursor, b, rw, sync = ser_line.split(" ")
except ValueError:
print(ser_line)
continue
if sync=="1":
# new instruction started
# opcode fetched
instr=[addr_cursor, b]
_,_,l = decode(b)
miss = l
else:
instr.append(b)
miss -= 1
if miss >= 0:
print("%s | %s" % (ser_line, render_instr(instr) ))
else:
#print("%s | %s" % (ser_line, 36*" "+ "Not an instruction" ))
print("%s |" % (ser_line))
#
ser.close()