-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Ingore CRC on dataFlash Reads #4619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -489,49 +489,50 @@ onboard_logging.initialize = function (callback) { | |
|
|
||
| show_saving_dialog(); | ||
|
|
||
| function onChunkRead(chunkAddress, chunkDataView, bytesCompressed) { | ||
| if (chunkDataView !== null) { | ||
| // Did we receive any data? | ||
| if (chunkDataView.byteLength > 0) { | ||
| nextAddress += chunkDataView.byteLength; | ||
| if (isNaN(bytesCompressed) || isNaN(totalBytesCompressed)) { | ||
| totalBytesCompressed = null; | ||
| } else { | ||
| totalBytesCompressed += bytesCompressed; | ||
| } | ||
|
|
||
| $(".dataflash-saving progress").attr("value", (nextAddress / maxBytes) * 100); | ||
|
|
||
| const blob = new Blob([chunkDataView]); | ||
| FileSystem.writeChunck(openedFile, blob).then(() => { | ||
| if (saveCancelled || nextAddress >= maxBytes) { | ||
| if (saveCancelled) { | ||
| dismiss_saving_dialog(); | ||
| } else { | ||
| mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); | ||
| } | ||
| FileSystem.closeFile(openedFile); | ||
| } else { | ||
| if (!self.writeError) { | ||
| mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead); | ||
| } else { | ||
| dismiss_saving_dialog(); | ||
| FileSystem.closeFile(openedFile); | ||
| } | ||
| } | ||
| }); | ||
| } else { | ||
| // A zero-byte block indicates end-of-file, so we're done | ||
| mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); | ||
| FileSystem.closeFile(openedFile); | ||
| } | ||
| } else { | ||
| // There was an error with the received block (address didn't match the one we asked for), retry | ||
| mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead); | ||
| } | ||
| } | ||
| function onChunkRead(chunkAddress, chunkDataView, bytesCompressed) { | ||
| if (chunkDataView && chunkDataView.byteLength > 0) { | ||
| // Always write non-empty data, even if CRC mismatch | ||
| const blob = new Blob([chunkDataView]); | ||
| FileSystem.writeChunck(openedFile, blob); | ||
|
|
||
| nextAddress += chunkDataView.byteLength; | ||
|
|
||
| // Track total compressed bytes, if provided | ||
| if (typeof bytesCompressed === "number") { | ||
| if (totalBytesCompressed == null) totalBytesCompressed = 0; // initialize if previously unknown | ||
| totalBytesCompressed += bytesCompressed; | ||
|
Comment on lines
+496
to
+503
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 🧩 Analysis chainConfirm write API returns a Promise. The fix relies on FileSystem.writeChunck being Promise-based. Verify and adjust (use callbacks/await) if not. 🏁 Script executed: #!/bin/bash
# Inspect FileSystem.writeChunck signature/usages
rg -n -C2 --type=js --type=ts 'writeChunck\s*\('
rg -n -C2 --type=js --type=ts 'export\s+default\s+class\s+FileSystem|class\s+FileSystem'Length of output: 1098 Await or handle FileSystem.writeChunck Promise FileSystem.writeChunck is async and returns a Promise (src/js/FileSystem.js:101). Update the call in src/js/tabs/onboard_logging.js (line 496) to await the call or attach .catch to handle errors — e.g. await FileSystem.writeChunck(openedFile, blob); or FileSystem.writeChunck(openedFile, blob).catch(err => console.error(err)); 🧰 Tools🪛 ESLint[error] 496-496: Expected indentation of 28 spaces but found 8. (indent) [error] 498-498: Expected indentation of 28 spaces but found 8. (indent) [error] 500-500: Expected indentation of 28 spaces but found 8. (indent) [error] 501-501: Expected indentation of 28 spaces but found 8. (indent) [error] 502-502: Expected indentation of 32 spaces but found 12. (indent) [error] 503-503: Expected indentation of 32 spaces but found 12. (indent) 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| $(".dataflash-saving progress").attr("value", (nextAddress / maxBytes) * 100); | ||
|
|
||
| if (saveCancelled || nextAddress >= maxBytes) { | ||
| mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); | ||
| FileSystem.closeFile(openedFile); | ||
| } else { | ||
| mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead); | ||
| } | ||
|
|
||
| } else if (chunkDataView && chunkDataView.byteLength === 0) { | ||
| // Zero-length block → EOF | ||
| mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); | ||
| FileSystem.closeFile(openedFile); | ||
|
|
||
|
Comment on lines
+515
to
+519
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainZero-length is not a safe EOF indicator. MSP can deliver empty payloads on CRC/mismatch; rely on nextAddress >= maxBytes for completion. 🏁 Script executed: #!/bin/bash
# Check MSPHelper.dataflashRead callback semantics for empty/partial deliveries
rg -n -C3 --type=js --type=ts 'dataflashRead\s*\(' src
rg -n -C5 --type=js --type=ts 'MSP_DATAFLASH_READ|crcError|compression' src/js/mspLength of output: 7908 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "### rg matches for dataflashRead and surrounding context:"
rg -n -C3 --hidden --no-ignore 'dataflashRead' src || true
echo
echo "### MSPHelper.js (around 2400-2525):"
sed -n '2400,2525p' src/js/msp/MSPHelper.js || true
echo
echo "### MSPHelper.js (process_data callback area around 1700-1788):"
sed -n '1700,1788p' src/js/msp/MSPHelper.js || true
echo
echo "### onboard_logging.js (around 480-540):"
sed -n '480,540p' src/js/tabs/onboard_logging.js || trueLength of output: 13388 Don’t treat zero-length chunks as EOF 🧰 Tools🪛 ESLint[error] 515-515: Expected indentation of 24 spaces but found 4. (indent) [error] 516-516: Expected indentation of 28 spaces but found 8. (indent) [error] 517-517: Expected indentation of 28 spaces but found 8. (indent) [error] 518-518: Expected indentation of 28 spaces but found 8. (indent) 🤖 Prompt for AI Agents |
||
| } else { | ||
| // Null block → skip ahead (hard error) | ||
| console.warn(`Skipping null block at address ${nextAddress}`); | ||
| nextAddress += self.blockSize; | ||
|
|
||
| if (nextAddress >= maxBytes) { | ||
| mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed); | ||
| FileSystem.closeFile(openedFile); | ||
| } else { | ||
| mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead); | ||
| } | ||
| } | ||
|
Comment on lines
+520
to
+531
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cancel not honored in skip path; progress not updated. Ensure saveCancelled gating and progress update also occur when skipping. Note: Addressed by the unified afterWrite() flow in the suggested diff. 🧰 Tools🪛 ESLint[error] 520-520: Expected indentation of 24 spaces but found 4. (indent) [error] 521-521: Expected indentation of 28 spaces but found 8. (indent) [error] 522-522: Expected indentation of 28 spaces but found 8. (indent) [error] 523-523: Expected indentation of 28 spaces but found 8. (indent) [error] 525-525: Expected indentation of 28 spaces but found 8. (indent) [error] 526-526: Expected indentation of 32 spaces but found 12. (indent) [error] 527-527: Expected indentation of 32 spaces but found 12. (indent) [error] 528-528: Expected indentation of 28 spaces but found 8. (indent) [error] 529-529: Expected indentation of 32 spaces but found 12. (indent) [error] 530-530: Expected indentation of 28 spaces but found 8. (indent) [error] 531-531: Expected indentation of 24 spaces but found 4. (indent) |
||
| } | ||
|
|
||
| const startTime = new Date().getTime(); // Start timestamp | ||
|
|
||
| const startTime = new Date().getTime(); | ||
| // Fetch the initial block | ||
| FileSystem.openFile(fileWriter).then((file) => { | ||
| openedFile = file; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.