Skip to content

Commit 756d246

Browse files
committed
Flash download progress
1 parent aeb95bd commit 756d246

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

functions.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ function renderInputControl(key, setting, value) {
639639
// 1) Custom input renderers
640640
else if (customInputRenderers[key]) {
641641
html += customInputRenderers[key](setting, value);
642+
if (key === 'device_pin') {
643+
value = normalizeDevicePinStorageValue(value);
644+
}
642645
}
643646

644647
// 2) If it's one of the bitmask settings -> render custom or port checkboxes
@@ -1644,7 +1647,10 @@ function validateInput(key, setting, value) {
16441647
throw new Error(`Must be 'true' or 'false'`);
16451648
}
16461649
} else if (setting.conversion === 'byte_array') {
1647-
stringToUint8Array(value, setting.length);
1650+
const byteArrayValue = key === 'device_pin'
1651+
? normalizeDevicePinStorageValue(value)
1652+
: value;
1653+
stringToUint8Array(byteArrayValue, setting.length);
16481654
} else if (setting.conversion === 'string') {
16491655
if (value.length > setting.length) {
16501656
throw new Error(`Max length is ${setting.length} characters`);

index.html

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,14 @@
148148
<div class="section-card-body">
149149
<div class="status-header">
150150
<div class="status-item"><span class="icon messages"></span>Flash log</div>
151-
<a href="#" onclick="requestFlashLogCount()">
151+
<a href="#" onclick="requestFlashLogCount(); return false;">
152152
<div class="status-item"><span class="icon refresh"></span>refresh</div>
153153
</a>
154154
</div>
155155
<div class="data-item">
156156
<span>Flash messages</span>
157157
<span id="flash-log-count">Not loaded</span>
158158
</div>
159-
<div class="data-item">
160-
<span>Status</span>
161-
<span id="flash-log-status">Waiting for settings...</span>
162-
</div>
163159
<div class="log-actions">
164160
<button type="button" class="log-action-button scan-button" onclick="requestFlashLogDownloadAll()">Download all logs</button>
165161
</div>
@@ -637,6 +633,8 @@ <h3 id="import-preview-title">Import preview</h3>
637633
active: false,
638634
lines: [],
639635
buffer: '',
636+
frameBuffer: new Uint8Array(0),
637+
decodedMessages: 0,
640638
startedAt: null,
641639
deviceName: '',
642640
logTypeLabel: 'all',
@@ -1788,6 +1786,8 @@ <h3 id="import-preview-title">Import preview</h3>
17881786
active: true,
17891787
lines: [],
17901788
buffer: '',
1789+
frameBuffer: new Uint8Array(0),
1790+
decodedMessages: 0,
17911791
startedAt: new Date(),
17921792
deviceName: device && device.name ? device.name : '',
17931793
logTypeLabel,
@@ -1813,6 +1813,35 @@ <h3 id="import-preview-title">Import preview</h3>
18131813
log(`Starting flash log download (${logTypeLabel})...`);
18141814
}
18151815

1816+
function parseFlashLogRecordCount(packetBytes, carryBuffer) {
1817+
const incoming = packetBytes.slice(1); // strip transport port byte
1818+
const merged = new Uint8Array((carryBuffer ? carryBuffer.length : 0) + incoming.length);
1819+
if (carryBuffer && carryBuffer.length) {
1820+
merged.set(carryBuffer, 0);
1821+
}
1822+
merged.set(incoming, carryBuffer ? carryBuffer.length : 0);
1823+
1824+
let index = 0;
1825+
let count = 0;
1826+
while (index + 2 < merged.length) {
1827+
const payloadLen = merged[index + 2];
1828+
const frameStart = index + 3;
1829+
const frameEnd = frameStart + payloadLen;
1830+
const metadataLen = 4;
1831+
const recordEnd = frameEnd + metadataLen;
1832+
if (recordEnd > merged.length) {
1833+
break;
1834+
}
1835+
count += 1;
1836+
index = recordEnd;
1837+
}
1838+
1839+
return {
1840+
count,
1841+
remainder: merged.slice(index)
1842+
};
1843+
}
1844+
18161845
function finishFlashLogCapture(reason) {
18171846
if (!flashLogState.active) {
18181847
return;
@@ -1878,7 +1907,16 @@ <h3 id="import-preview-title">Import preview</h3>
18781907

18791908
const base64Line = bytesToBase64(payload);
18801909
flashLogState.lines.push(base64Line);
1881-
const receivedCount = flashLogState.lines.length;
1910+
1911+
const parsed = parseFlashLogRecordCount(data, flashLogState.frameBuffer);
1912+
flashLogState.frameBuffer = parsed.remainder;
1913+
if (parsed.count > 0) {
1914+
flashLogState.decodedMessages += parsed.count;
1915+
}
1916+
1917+
const receivedCount = flashLogState.decodedMessages > 0
1918+
? flashLogState.decodedMessages
1919+
: flashLogState.lines.length;
18821920
const elapsedSeconds = Math.max(1, Math.round((Date.now() - flashLogState.startedAt.getTime()) / 1000));
18831921
const rate = (receivedCount / elapsedSeconds).toFixed(1);
18841922
const hasTotal = Number.isFinite(flashLogState.expectedTotal) && flashLogState.expectedTotal > 0;

0 commit comments

Comments
 (0)