1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-19 14:25:14 +03:00

Implemented switchable compression for MSP_DATAFLASH_READ

This commit is contained in:
DieHertz 2017-07-25 01:40:58 +03:00
parent ac0049db19
commit 0bf02e5398
2 changed files with 25 additions and 6 deletions

View file

@ -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
* 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 {
// Report address error
console.log('Expected address ' + address + ' but received ' + chunkAddress + ' - retrying');