From 66e767881eb4848f2a506a70b8a287c17f646957 Mon Sep 17 00:00:00 2001 From: Nicholas Sherlock Date: Mon, 23 Feb 2015 22:47:47 +1300 Subject: [PATCH 1/2] Fix endianness of board version read --- js/msp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/msp.js b/js/msp.js index d772710e..3e437965 100644 --- a/js/msp.js +++ b/js/msp.js @@ -545,7 +545,7 @@ var MSP = { identifier += String.fromCharCode(data.getUint8(offset)); } CONFIG.boardIdentifier = identifier; - CONFIG.boardVersion = data.getUint16(offset); + CONFIG.boardVersion = data.getUint16(offset, 1); offset+=2; break; From ede3c367f29439dc0df1584c2b2f77fcd1fd2cc4 Mon Sep 17 00:00:00 2001 From: Nicholas Sherlock Date: Fri, 27 Feb 2015 09:14:47 +1300 Subject: [PATCH 2/2] Error message for saving to disallowed dir,fix flash save problem on osx --- _locales/en/messages.json | 3 ++ tabs/dataflash.js | 60 +++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 969a1a0a..e8f61491 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -887,6 +887,9 @@ "dataflashButtonEraseCancel": { "message": "Cancel" }, + "dataflashFileWriteFailed": { + "message": "Failed to write to the file you selected, are the permissions on that folder okay?" + }, "firmwareFlasherReleaseSummaryHead": { "message": "Release info" }, diff --git a/tabs/dataflash.js b/tabs/dataflash.js index 90980c5c..f1cde23d 100644 --- a/tabs/dataflash.js +++ b/tabs/dataflash.js @@ -139,31 +139,40 @@ TABS.dataflash.initialize = function (callback) { show_saving_dialog(); function onChunkRead(chunkAddress, chunkDataView) { - // If we didn't get a zero-byte chunk (indicating end-of-file), request more - if (chunkDataView.byteLength > 0) { - nextAddress += chunkDataView.byteLength; - - $(".dataflash-saving progress").attr("value", nextAddress / maxBytes * 100); - - var - blob = new Blob([chunkDataView]); - - fileWriter.write(blob); - - if (saveCancelled || nextAddress >= maxBytes) { - if (saveCancelled) { - dismiss_saving_dialog(); - } else { - mark_saving_dialog_done(); - } + if (chunkDataView != null) { + // Did we receive any data? + if (chunkDataView.byteLength > 0) { + nextAddress += chunkDataView.byteLength; + + $(".dataflash-saving progress").attr("value", nextAddress / maxBytes * 100); + + var + blob = new Blob([chunkDataView]); + + fileWriter.onwriteend = function(e) { + if (saveCancelled || nextAddress >= maxBytes) { + if (saveCancelled) { + dismiss_saving_dialog(); + } else { + mark_saving_dialog_done(); + } + } else { + MSP.dataflashRead(nextAddress, onChunkRead); + } + }; + + fileWriter.write(blob); } else { - MSP.dataflashRead(nextAddress, onChunkRead); + // A zero-byte block indicates end-of-file, so we're done + mark_saving_dialog_done(); } } else { - mark_saving_dialog_done(); + // There was an error with the received block (address didn't match the one we asked for), retry + MSP.dataflashRead(nextAddress, onChunkRead); } } + // Fetch the initial block MSP.dataflashRead(nextAddress, onChunkRead); }); } @@ -178,11 +187,17 @@ TABS.dataflash.initialize = function (callback) { chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: filename, accepts: [{extensions: ['TXT']}]}, function(fileEntry) { - if (!fileEntry) { - console.log('No file selected'); + var error = chrome.runtime.lastError; + + if (error) { + console.error(error.message); + + if (error.message != "User cancelled") { + GUI.log(chrome.i18n.getMessage('dataflashFileWriteFailed')); + } return; } - + // echo/console log path specified chrome.fileSystem.getDisplayPath(fileEntry, function(path) { console.log('Dataflash dump file path: ' + path); @@ -199,6 +214,7 @@ TABS.dataflash.initialize = function (callback) { }, function (e) { // File is not readable or does not exist! console.error(e); + GUI.log(chrome.i18n.getMessage('dataflashFileWriteFailed')); }); }); }