Skip to content

Commit 834d083

Browse files
committed
LAST TIME
1 parent f61daf7 commit 834d083

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/js/tabs/onboard_logging.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,8 @@ onboard_logging.initialize = function (callback) {
489489

490490
show_saving_dialog();
491491

492-
const activeRetries = new Set();
493-
const MAX_RETRIES = 3;
492+
const activeRetries = new Set(); // tracks blocks currently retrying
493+
const MAX_RETRIES = 3; // maximum number of retries per block
494494

495495
async function onChunkRead(St, blockAddr, blockData) {
496496
if (!blockData || blockData.byteLength === 0) {
@@ -500,14 +500,24 @@ async function onChunkRead(St, blockAddr, blockData) {
500500

501501
let retries = 0;
502502

503+
// Retry loop for CRC failures
503504
while (!checkCRC(blockData) && retries < MAX_RETRIES) {
504-
if (activeRetries.has(blockAddr)) return;
505+
console.warn(`CRC failed at ${blockAddr}, retrying (${retries + 1}/${MAX_RETRIES})`);
506+
507+
// Prevent multiple concurrent retries for the same block
508+
if (activeRetries.has(blockAddr)) {
509+
console.warn(`Already retrying block at ${blockAddr}, skipping`);
510+
return;
511+
}
505512
activeRetries.add(blockAddr);
506513

507-
const retryBlock = await St.dataflashRead(blockAddr);
514+
const retryBlock = await requestBlock(St, blockAddr);
508515
activeRetries.delete(blockAddr);
509516

510-
if (!retryBlock || retryBlock.byteLength === 0) break;
517+
if (!retryBlock || retryBlock.byteLength === 0) {
518+
console.error(`Retry failed for block at ${blockAddr}`);
519+
break; // abort retries
520+
}
511521

512522
blockData = retryBlock;
513523
retries++;
@@ -519,17 +529,24 @@ async function onChunkRead(St, blockAddr, blockData) {
519529
}
520530

521531
try {
522-
St.process_data(blockData);
532+
St.process_data(blockData); // feed valid block to parser
523533
} catch (err) {
524534
console.error(`Processing error at ${blockAddr}:`, err);
525535
}
526536
}
527537

528-
// CRC check for DataView
538+
async function requestBlock(St, addr) {
539+
try {
540+
return await St.dataflashRead(addr); // must return a Promise
541+
} catch (e) {
542+
console.error(`Request failed for block at ${addr}:`, e);
543+
return null;
544+
}
545+
}
546+
529547
function checkCRC(block) {
530-
// Example: compute CRC from bytes in DataView if needed
531-
// For now, just assume valid if block has content
532-
return block && block.byteLength > 0;
548+
// Replace with your actual CRC logic
549+
return block.crcValid === true;
533550
}
534551

535552
const startTime = new Date().getTime();

0 commit comments

Comments
 (0)