Commit 84bd336c by Sebastian Renner

Encoding is fun!

parent 26b36a28
...@@ -6,6 +6,8 @@ import struct ...@@ -6,6 +6,8 @@ import struct
import serial import serial
from subprocess import Popen, PIPE, run from subprocess import Popen, PIPE, run
ser = serial.Serial('/dev/ttyUSB0', 115200)
def flash(): def flash():
run("JLinkExe flash.jlink", shell=True, check=True) run("JLinkExe flash.jlink", shell=True, check=True)
...@@ -20,7 +22,7 @@ def read(channel, l): ...@@ -20,7 +22,7 @@ def read(channel, l):
raise Exception("could not read %d bytes of data (got %d)" % (l, len(data))) raise Exception("could not read %d bytes of data (got %d)" % (l, len(data)))
return data return data
def write(channel, data, direction): def write(channel, data):
if channel == 'ser': if channel == 'ser':
l = ser.write(data) l = ser.write(data)
elif channel == 'std': elif channel == 'std':
...@@ -32,18 +34,17 @@ def write(channel, data, direction): ...@@ -32,18 +34,17 @@ def write(channel, data, direction):
def obtain(channel): def obtain(channel):
l = read(channel, 4) l = read(channel, 4)
print(l) l = str.encode(l)
(l, ) = struct.unpack("<I", l) (l, ) = struct.unpack("<I", l)
return read(channel, l) return read(channel, l)
def submit(channel, action, data): def submit(channel, action, data):
h = struct.pack("<BI", ord(action), len(data)) h = struct.pack("<BI", ord(action), len(data))
write(channel, h) write(channel, h)
write(channel, data) write(channel, str.encode(data))
def main(): def main():
#flash() #flash()
ser = serial.Serial('/dev/ttyUSB0', 115200)
while(1): while(1):
action = read('std', 1) action = read('std', 1)
if (action): if (action):
...@@ -52,10 +53,10 @@ def main(): ...@@ -52,10 +53,10 @@ def main():
submit('ser', action, data) submit('ser', action, data)
elif action == 'e' or action == 'd': elif action == 'e' or action == 'd':
write('ser', action) write('ser', str.encode(action))
elif action == 'C' or action == 'M' or action == 'A' or action == 'K' or action == 'S' or action == 'P': elif action == 'C' or action == 'M' or action == 'A' or action == 'K' or action == 'S' or action == 'P':
write('ser', action) write('ser', str.encode(action))
data = obtain('ser') data = obtain('ser')
submit('std', action, data) submit('std', action, data)
else: else:
......
...@@ -37,8 +37,8 @@ def main(argv): ...@@ -37,8 +37,8 @@ def main(argv):
(l, ) = struct.unpack("<I", l) (l, ) = struct.unpack("<I", l)
return read(l) return read(l)
if read(14) != b"Hello, World!\n": #if read(14) != b"Hello, World!\n":
raise Exception("Unexpected output") # raise Exception("Unexpected output")
m = b"" m = b""
ad = b"" ad = b""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment