Commit 84bd336c by Sebastian Renner

Encoding is fun!

parent 26b36a28
......@@ -6,6 +6,8 @@ import struct
import serial
from subprocess import Popen, PIPE, run
ser = serial.Serial('/dev/ttyUSB0', 115200)
def flash():
run("JLinkExe flash.jlink", shell=True, check=True)
......@@ -20,7 +22,7 @@ def read(channel, l):
raise Exception("could not read %d bytes of data (got %d)" % (l, len(data)))
return data
def write(channel, data, direction):
def write(channel, data):
if channel == 'ser':
l = ser.write(data)
elif channel == 'std':
......@@ -32,18 +34,17 @@ def write(channel, data, direction):
def obtain(channel):
l = read(channel, 4)
print(l)
l = str.encode(l)
(l, ) = struct.unpack("<I", l)
return read(channel, l)
def submit(channel, action, data):
h = struct.pack("<BI", ord(action), len(data))
write(channel, h)
write(channel, data)
write(channel, str.encode(data))
def main():
#flash()
ser = serial.Serial('/dev/ttyUSB0', 115200)
while(1):
action = read('std', 1)
if (action):
......@@ -52,10 +53,10 @@ def main():
submit('ser', action, data)
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':
write('ser', action)
write('ser', str.encode(action))
data = obtain('ser')
submit('std', action, data)
else:
......
......@@ -37,8 +37,8 @@ def main(argv):
(l, ) = struct.unpack("<I", l)
return read(l)
if read(14) != b"Hello, World!\n":
raise Exception("Unexpected output")
#if read(14) != b"Hello, World!\n":
# raise Exception("Unexpected output")
m = 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