Added stdout buffering. Now functional as a Pybricks uploader. Takes a main.bin MPY bytecode and sends, executes, and recieves from a Pybricks-running Lego Robot.
This commit is contained in:
14
main.html
14
main.html
@@ -82,7 +82,7 @@
|
|||||||
let device, server, cmdChar;
|
let device, server, cmdChar;
|
||||||
let maxCharSize = 20;
|
let maxCharSize = 20;
|
||||||
let lastStatusFlags = 0;
|
let lastStatusFlags = 0;
|
||||||
|
let stdoutBuffer = '';
|
||||||
function log(msg) {
|
function log(msg) {
|
||||||
const el = document.getElementById('log');
|
const el = document.getElementById('log');
|
||||||
el.textContent += msg + '\n';
|
el.textContent += msg + '\n';
|
||||||
@@ -161,8 +161,16 @@
|
|||||||
const type = data[0];
|
const type = data[0];
|
||||||
|
|
||||||
if (type === EVT_WRITE_STDOUT) {
|
if (type === EVT_WRITE_STDOUT) {
|
||||||
const text = new TextDecoder().decode(data.slice(1));
|
// Buffer and reassemble split packets
|
||||||
log('[stdout] ' + text);
|
stdoutBuffer += new TextDecoder().decode(data.slice(1));
|
||||||
|
const lines = stdoutBuffer.split('\n');
|
||||||
|
stdoutBuffer = lines.pop() || ''; // Keep incomplete line
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.trim()) {
|
||||||
|
log('[stdout] ' + line);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (type === EVT_STATUS_REPORT) {
|
} else if (type === EVT_STATUS_REPORT) {
|
||||||
const view = new DataView(data.buffer);
|
const view = new DataView(data.buffer);
|
||||||
const flags = view.getUint32(1, true);
|
const flags = view.getUint32(1, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user