mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-15 04:15:28 +03:00
processing hex file in different thread
This commit is contained in:
parent
2cc056e2a1
commit
f490f99596
3 changed files with 48 additions and 18 deletions
|
@ -16,7 +16,6 @@
|
|||
<script type="text/javascript" src="./js/msp.js"></script>
|
||||
<script type="text/javascript" src="./main.js"></script>
|
||||
<script type="text/javascript" src="./js/backup_restore.js"></script>
|
||||
<script type="text/javascript" src="./js/hex_reader.js"></script>
|
||||
<script type="text/javascript" src="./js/stm32.js"></script>
|
||||
|
||||
<!-- Various tabs are divided into separate files (for clarity) -->
|
||||
|
|
|
@ -28,13 +28,21 @@ function tab_initialize_firmware_flasher() {
|
|||
|
||||
reader.onloadend = function(e) {
|
||||
console.log('File loaded');
|
||||
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
|
||||
|
||||
intel_hex = e.target.result;
|
||||
parsed_hex = read_hex_file(intel_hex);
|
||||
|
||||
parse_hex(intel_hex, function(data) {
|
||||
parsed_hex = data;
|
||||
|
||||
if (parsed_hex) {
|
||||
STM32.GUI_status('<span style="color: green">Firmware loaded, ready for flashing</span>');
|
||||
$('a.flash_firmware').removeClass('locked');
|
||||
|
||||
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
|
||||
$('a.flash_firmware').removeClass('locked');
|
||||
} else {
|
||||
STM32.GUI_status('<span style="color: red">HEX file appears to be corrupted</span>');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
|
@ -52,13 +60,20 @@ function tab_initialize_firmware_flasher() {
|
|||
|
||||
$.get('https://raw.github.com/multiwii/baseflight/master/obj/baseflight.hex', function(data) {
|
||||
intel_hex = data;
|
||||
parsed_hex = read_hex_file(intel_hex);
|
||||
|
||||
parse_hex(intel_hex, function(data) {
|
||||
parsed_hex = data;
|
||||
|
||||
if (parsed_hex) {
|
||||
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>');
|
||||
$('a.flash_firmware').removeClass('locked');
|
||||
|
||||
$('span.path').html('Using remote Firmware');
|
||||
$('span.size').html((parsed_hex.bytes / 1000) + ' kB');
|
||||
$('a.flash_firmware').removeClass('locked');
|
||||
|
||||
STM32.GUI_status('<span style="color: green">Remote Firmware loaded, ready for flashing</span>');
|
||||
} else {
|
||||
STM32.GUI_status('<span style="color: red">HEX file appears to be corrupted</span>');
|
||||
}
|
||||
});
|
||||
}).fail(function() {
|
||||
STM32.GUI_status('<span style="color: red">Failed to load remote firmware</span>');
|
||||
$('a.flash_firmware').addClass('locked');
|
||||
|
@ -88,3 +103,16 @@ function tab_initialize_firmware_flasher() {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
function parse_hex(str, callback) {
|
||||
// parsing hex in different thread
|
||||
var worker = new Worker('./workers/hex_parser.js');
|
||||
|
||||
// "callback"
|
||||
worker.onmessage = function (event) {
|
||||
callback(event.data);
|
||||
};
|
||||
|
||||
// send data/string over for processing
|
||||
worker.postMessage(str);
|
||||
}
|
|
@ -69,13 +69,16 @@ function read_hex_file(data) {
|
|||
}
|
||||
}
|
||||
|
||||
if (hexfile_valid) {
|
||||
console.log('HEX file parsed: ' + result.bytes + ' bytes');
|
||||
|
||||
return result;
|
||||
if (result.end_of_file && hexfile_valid) {
|
||||
postMessage(result);
|
||||
} else {
|
||||
console.log('HEX file parsed, CRC check failed: ' + result.bytes + ' bytes');
|
||||
|
||||
return false;
|
||||
postMessage(false);
|
||||
}
|
||||
}
|
||||
|
||||
onmessage = function(event) {
|
||||
read_hex_file(event.data);
|
||||
|
||||
// terminate worker
|
||||
close();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue