mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-22 15:55:33 +03:00
Implemented switchable compression for MSP_DATAFLASH_READ
This commit is contained in:
parent
ac0049db19
commit
0bf02e5398
2 changed files with 25 additions and 6 deletions
|
@ -1488,7 +1488,18 @@ MspHelper.prototype.dataflashRead = function(address, blockSize, onDataCallback)
|
||||||
/* Strip that address off the front of the reply and deliver it separately so the caller doesn't have to
|
/* Strip that address off the front of the reply and deliver it separately so the caller doesn't have to
|
||||||
* figure out the reply format:
|
* figure out the reply format:
|
||||||
*/
|
*/
|
||||||
onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + headerSize, dataSize));
|
if (dataCompressionType == 0) {
|
||||||
|
onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + headerSize, dataSize), dataSize);
|
||||||
|
} else if (dataCompressionType == 1) {
|
||||||
|
// Read compressed char count to avoid decoding stray bit sequences as bytes
|
||||||
|
var compressedCharCount = response.data.readU16();
|
||||||
|
|
||||||
|
// Compressed format uses 2 additional bytes as a pseudo-header to denote the number of uncompressed bytes
|
||||||
|
var compressedArray = new Uint8Array(response.data.buffer, response.data.byteOffset + headerSize + 2, dataSize - 2);
|
||||||
|
var decompressedArray = huffmanDecodeBuf(compressedArray, compressedCharCount, defaultHuffmanTree, defaultHuffmanLenIndex);
|
||||||
|
|
||||||
|
onDataCallback(address, new DataView(decompressedArray.buffer), dataSize);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Report address error
|
// Report address error
|
||||||
console.log('Expected address ' + address + ' but received ' + chunkAddress + ' - retrying');
|
console.log('Expected address ' + address + ' but received ' + chunkAddress + ' - retrying');
|
||||||
|
|
|
@ -310,10 +310,13 @@ TABS.onboard_logging.initialize = function (callback) {
|
||||||
$(".dataflash-saving")[0].close();
|
$(".dataflash-saving")[0].close();
|
||||||
}
|
}
|
||||||
|
|
||||||
function mark_saving_dialog_done(startTime, totalBytes) {
|
function mark_saving_dialog_done(startTime, totalBytes, totalBytesCompressed) {
|
||||||
var totalTime = (new Date().getTime() - startTime) / 1000;
|
var totalTime = (new Date().getTime() - startTime) / 1000;
|
||||||
console.log('Received ' + totalBytes + ' bytes in ' + totalTime.toFixed(2) + 's ('
|
console.log('Received ' + totalBytes + ' bytes in ' + totalTime.toFixed(2) + 's ('
|
||||||
+ (totalBytes / totalTime / 1024).toFixed(2) + 'kB / s) with block size ' + self.blockSize + '.');
|
+ (totalBytes / totalTime / 1024).toFixed(2) + 'kB / s) with block size ' + self.blockSize + '.');
|
||||||
|
if (totalBytesCompressed) {
|
||||||
|
console.log('Compressed into', totalBytesCompressed, 'bytes with mean compression factor of', totalBytes / totalBytesCompressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$(".dataflash-saving").addClass("done");
|
$(".dataflash-saving").addClass("done");
|
||||||
|
@ -331,7 +334,10 @@ TABS.onboard_logging.initialize = function (callback) {
|
||||||
|
|
||||||
function flash_save_begin() {
|
function flash_save_begin() {
|
||||||
if (GUI.connected_to) {
|
if (GUI.connected_to) {
|
||||||
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) {
|
if (GUI.operating_system == "MacOS") {
|
||||||
|
// Address Chrome for macOS issue with large serial reads
|
||||||
|
self.blockSize = self.VCP_BLOCK_SIZE_3_0;
|
||||||
|
} else if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) {
|
||||||
if (semver.gte(CONFIG.apiVersion, "1.31.0")) {
|
if (semver.gte(CONFIG.apiVersion, "1.31.0")) {
|
||||||
self.blockSize = self.VCP_BLOCK_SIZE;
|
self.blockSize = self.VCP_BLOCK_SIZE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -347,14 +353,16 @@ TABS.onboard_logging.initialize = function (callback) {
|
||||||
|
|
||||||
prepare_file(function(fileWriter) {
|
prepare_file(function(fileWriter) {
|
||||||
var nextAddress = 0;
|
var nextAddress = 0;
|
||||||
|
var totalBytesCompressed = 0;
|
||||||
|
|
||||||
show_saving_dialog();
|
show_saving_dialog();
|
||||||
|
|
||||||
function onChunkRead(chunkAddress, chunkDataView) {
|
function onChunkRead(chunkAddress, chunkDataView, bytesCompressed) {
|
||||||
if (chunkDataView !== null) {
|
if (chunkDataView !== null) {
|
||||||
// Did we receive any data?
|
// Did we receive any data?
|
||||||
if (chunkDataView.byteLength > 0) {
|
if (chunkDataView.byteLength > 0) {
|
||||||
nextAddress += chunkDataView.byteLength;
|
nextAddress += chunkDataView.byteLength;
|
||||||
|
totalBytesCompressed += bytesCompressed;
|
||||||
|
|
||||||
$(".dataflash-saving progress").attr("value", nextAddress / maxBytes * 100);
|
$(".dataflash-saving progress").attr("value", nextAddress / maxBytes * 100);
|
||||||
|
|
||||||
|
@ -365,7 +373,7 @@ TABS.onboard_logging.initialize = function (callback) {
|
||||||
if (saveCancelled) {
|
if (saveCancelled) {
|
||||||
dismiss_saving_dialog();
|
dismiss_saving_dialog();
|
||||||
} else {
|
} else {
|
||||||
mark_saving_dialog_done(startTime, nextAddress);
|
mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead);
|
mspHelper.dataflashRead(nextAddress, self.blockSize, onChunkRead);
|
||||||
|
@ -375,7 +383,7 @@ TABS.onboard_logging.initialize = function (callback) {
|
||||||
fileWriter.write(blob);
|
fileWriter.write(blob);
|
||||||
} else {
|
} else {
|
||||||
// A zero-byte block indicates end-of-file, so we're done
|
// A zero-byte block indicates end-of-file, so we're done
|
||||||
mark_saving_dialog_done(startTime, nextAddress);
|
mark_saving_dialog_done(startTime, nextAddress, totalBytesCompressed);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// There was an error with the received block (address didn't match the one we asked for), retry
|
// There was an error with the received block (address didn't match the one we asked for), retry
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue