diff --git a/asm/comm.py b/asm/comm.py new file mode 100644 index 0000000..9a6c188 --- /dev/null +++ b/asm/comm.py @@ -0,0 +1,18 @@ +from creole import * +import socket + +def connect(ip, port): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((ip, port)) + return s + +def execute(creole_instance, socket): + code = creole_instance() + l = len(code) + assert l <= 0xFFFF + socket.sendall(bytes([l & 0xFF, l >> 8]) + code) + +def connect_exec(cr, ip="192.168.1.50", port=6626): + s = connect(ip, port) + execute(cr, s) + return s.recv(1024) diff --git a/asm/test_comm.py b/asm/test_comm.py new file mode 100644 index 0000000..f71f3d3 --- /dev/null +++ b/asm/test_comm.py @@ -0,0 +1,25 @@ +from comm import * + +# These require a connection! +def test_print_char(): + p = Program() + p.parse_asm_line(f"SENDVAL 100") + assert connect_exec(p) == b'100' + +def test_print_string(): + p = Program() + p.parse_lines([ + "j .l", + f"db d0 {[ord(x) for x in 'hello world']}", + ".l", + "senddat d0" + ]) + return connect_exec(p).decode() + +def test_run_adc(): + p = Program() + p.parse_lines([ + "read_adc 0 r0", + "sendval r0" + ]) + return connect_exec(p).decode()