From de03010ddeeca5a0c445b59ae510dc3fc0b9c551 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 1 Aug 2016 14:33:31 +0300 Subject: [PATCH 1/5] webrepl_cli.py: Update "get file" protocol. "Get" protocol now requires receiving a lead byte from client before transferring each new packet with file contents. This makes it naturally non-blocking (while webrepl waits to receive this byte, MicroPython can execute other tasks). --- webrepl_cli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/webrepl_cli.py b/webrepl_cli.py index c47402e..5ee086a 100755 --- a/webrepl_cli.py +++ b/webrepl_cli.py @@ -130,6 +130,7 @@ def get_file(ws, local_file, remote_file): with open(local_file, "wb") as f: cnt = 0 while True: + ws.write(b"\0") (sz,) = struct.unpack(" Date: Thu, 4 Aug 2016 00:09:57 +0300 Subject: [PATCH 2/5] webrepl.html: Update "get file" protocol. "Get" protocol now requires receiving a lead byte from client before transferring each new packet with file contents. This makes it naturally non-blocking (while webrepl waits to receive this byte, MicroPython can execute other tasks). --- webrepl.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/webrepl.html b/webrepl.html index 785699a..ea02f12 100644 --- a/webrepl.html +++ b/webrepl.html @@ -181,6 +181,9 @@ // first response for get if (decode_resp(data) == 0) { binary_state = 22; + var rec = new Uint8Array(1); + rec[0] = 0; + ws.send(rec); } break; case 22: { @@ -198,6 +201,10 @@ new_buf.set(data.slice(2), get_file_data.length); get_file_data = new_buf; update_file_status('Getting ' + get_file_name + ', ' + get_file_data.length + ' bytes'); + + var rec = new Uint8Array(1); + rec[0] = 0; + ws.send(rec); } } else { binary_state = 0; From 466ad57575c9b950f81f7356d6541ae43cee6429 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sat, 6 Aug 2016 23:35:06 +0300 Subject: [PATCH 3/5] webrepl_cli.py: Add get_ver() method to query remote version. --- webrepl_cli.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/webrepl_cli.py b/webrepl_cli.py index 5ee086a..10b9de4 100755 --- a/webrepl_cli.py +++ b/webrepl_cli.py @@ -19,6 +19,8 @@ WEBREPL_REQ_S = "<2sBBQLH64s" WEBREPL_PUT_FILE = 1 WEBREPL_GET_FILE = 2 +WEBREPL_GET_VER = 3 + def debugmsg(msg): if DEBUG: @@ -100,6 +102,20 @@ def read_resp(ws): assert sig == b"WB" return code + +def send_req(ws, op, sz=0, fname=""): + rec = struct.pack(WEBREPL_REQ_S, b"WA", op, 0, 0, sz, len(fname), fname) + debugmsg("%r %d" % (rec, len(rec))) + ws.write(rec) + + +def get_ver(ws): + send_req(ws, WEBREPL_GET_VER) + d = ws.read(3) + d = struct.unpack(" Date: Mon, 8 Aug 2016 22:38:24 +1000 Subject: [PATCH 4/5] webrepl.html: Add function to query uPy version via GET_VER. Currently this function is not used but it can be tested by running get_ver() at the JS console in the browser. --- webrepl.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/webrepl.html b/webrepl.html index ea02f12..15a102f 100644 --- a/webrepl.html +++ b/webrepl.html @@ -221,6 +221,11 @@ } binary_state = 0; break; + case 31: + // first (and last) response for GET_VER + console.log('GET_VER', data); + binary_state = 0; + break; } } term.write(event.data); @@ -300,6 +305,19 @@ ws.send(rec); } +function get_ver() { + // WEBREPL_REQ_S = "<2sBBQLH64s" + var rec = new Uint8Array(2 + 1 + 1 + 8 + 4 + 2 + 64); + rec[0] = 'W'.charCodeAt(0); + rec[1] = 'A'.charCodeAt(0); + rec[2] = 3; // GET_VER + // rest of "rec" is zero + + // initiate GET_VER + binary_state = 31; + ws.send(rec); +} + function handle_put_file_select(evt) { // The event holds a FileList object which is a list of File objects, // but we only support single file selection at the moment. From aefdad6560872dc5935727a468f1733953197271 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 9 Aug 2016 23:06:07 +1000 Subject: [PATCH 5/5] webrepl_cli.py: Use empty bytes object as default fname, to pack 's'. --- webrepl_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webrepl_cli.py b/webrepl_cli.py index 10b9de4..04e0591 100755 --- a/webrepl_cli.py +++ b/webrepl_cli.py @@ -103,7 +103,7 @@ def read_resp(ws): return code -def send_req(ws, op, sz=0, fname=""): +def send_req(ws, op, sz=0, fname=b""): rec = struct.pack(WEBREPL_REQ_S, b"WA", op, 0, 0, sz, len(fname), fname) debugmsg("%r %d" % (rec, len(rec))) ws.write(rec)