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:
2026-03-21 16:38:01 -05:00
parent 80097b7231
commit 506da717df

View File

@@ -82,7 +82,7 @@
let device, server, cmdChar;
let maxCharSize = 20;
let lastStatusFlags = 0;
let stdoutBuffer = '';
function log(msg) {
const el = document.getElementById('log');
el.textContent += msg + '\n';
@@ -161,8 +161,16 @@
const type = data[0];
if (type === EVT_WRITE_STDOUT) {
const text = new TextDecoder().decode(data.slice(1));
log('[stdout] ' + text);
// Buffer and reassemble split packets
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) {
const view = new DataView(data.buffer);
const flags = view.getUint32(1, true);