@@ -489,8 +489,8 @@ onboard_logging.initialize = function (callback) {
489
489
490
490
show_saving_dialog ( ) ;
491
491
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
494
494
495
495
async function onChunkRead ( St , blockAddr , blockData ) {
496
496
if ( ! blockData || blockData . byteLength === 0 ) {
@@ -500,14 +500,24 @@ async function onChunkRead(St, blockAddr, blockData) {
500
500
501
501
let retries = 0 ;
502
502
503
+ // Retry loop for CRC failures
503
504
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
+ }
505
512
activeRetries . add ( blockAddr ) ;
506
513
507
- const retryBlock = await St . dataflashRead ( blockAddr ) ;
514
+ const retryBlock = await requestBlock ( St , blockAddr ) ;
508
515
activeRetries . delete ( blockAddr ) ;
509
516
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
+ }
511
521
512
522
blockData = retryBlock ;
513
523
retries ++ ;
@@ -519,17 +529,24 @@ async function onChunkRead(St, blockAddr, blockData) {
519
529
}
520
530
521
531
try {
522
- St . process_data ( blockData ) ;
532
+ St . process_data ( blockData ) ; // feed valid block to parser
523
533
} catch ( err ) {
524
534
console . error ( `Processing error at ${ blockAddr } :` , err ) ;
525
535
}
526
536
}
527
537
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
+
529
547
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 ;
533
550
}
534
551
535
552
const startTime = new Date ( ) . getTime ( ) ;
0 commit comments