mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 11:29:53 +03:00
Convert to CommonJS Modules
This commit is contained in:
parent
7df8253099
commit
91f1699659
100 changed files with 9685 additions and 3735 deletions
|
@ -12,6 +12,9 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const { GUI, TABS } = require('./../gui');
|
||||
const i18n = require('./../localization');
|
||||
|
||||
var STM32DFU_protocol = function () {
|
||||
this.callback = null;
|
||||
this.hex = null;
|
||||
|
@ -106,7 +109,7 @@ STM32DFU_protocol.prototype.connect = function (usbDevices, hex, options, callba
|
|||
self.openDevice();
|
||||
} else {
|
||||
console.log('USB DFU not found');
|
||||
GUI.log(localization.getMessage('stm32UsbDfuNotFound'));
|
||||
GUI.log(i18n.getMessage('stm32UsbDfuNotFound'));
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -116,14 +119,14 @@ STM32DFU_protocol.prototype.openDevice = function () {
|
|||
var self = this;
|
||||
|
||||
self.usbDevice.open().then( () => {
|
||||
GUI.log(localization.getMessage('usbDeviceOpened'));
|
||||
GUI.log(i18n.getMessage('usbDeviceOpened'));
|
||||
console.log('USB-Device opened');
|
||||
self.claimInterface(0);
|
||||
}).catch(error => {
|
||||
console.log('Failed to open USB device: ' + error);
|
||||
GUI.log(localization.getMessage('usbDeviceOpenFail'));
|
||||
GUI.log(i18n.getMessage('usbDeviceOpenFail'));
|
||||
if(GUI.operating_system === 'Linux') {
|
||||
GUI.log(localization.getMessage('usbDeviceUdevNotice'));
|
||||
GUI.log(i18n.getMessage('usbDeviceUdevNotice'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
@ -132,11 +135,11 @@ STM32DFU_protocol.prototype.closeDevice = function () {
|
|||
var self = this;
|
||||
|
||||
self.usbDevice.close().then(() => {
|
||||
GUI.log(localization.getMessage('usbDeviceClosed'));
|
||||
GUI.log(i18n.getMessage('usbDeviceClosed'));
|
||||
console.log('USB-Device closed');
|
||||
}).catch(error => {
|
||||
console.log('Failed to close USB device!');
|
||||
GUI.log(localization.getMessage('usbDeviceCloseFail'));
|
||||
GUI.log(i18n.getMessage('usbDeviceCloseFail'));
|
||||
});
|
||||
|
||||
self.usbDevice = null;
|
||||
|
@ -305,9 +308,9 @@ STM32DFU_protocol.prototype.getFunctionalDescriptor = function (_interface, call
|
|||
'bcdDFUVersion': buf[7]
|
||||
};
|
||||
callback(descriptor, 0);
|
||||
} else {
|
||||
throw new Error(result.status);
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.status);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log('USB getFunctionalDescriptor failed! ' + error);
|
||||
callback({}, 1);
|
||||
|
@ -556,10 +559,10 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
self.flash_layout = chipInfo.internal_flash;
|
||||
self.available_flash_size = self.flash_layout.total_size - (self.hex.start_linear_address - self.flash_layout.start_address);
|
||||
|
||||
GUI.log(localization.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString()));
|
||||
GUI.log(i18n.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString()));
|
||||
|
||||
if (self.hex.bytes_total > self.available_flash_size) {
|
||||
GUI.log(localization.getMessage('dfu_error_image_size',
|
||||
GUI.log(i18n.getMessage('dfu_error_image_size',
|
||||
[(self.hex.bytes_total / 1024.0).toFixed(1),
|
||||
(self.available_flash_size / 1024.0).toFixed(1)]));
|
||||
self.cleanup();
|
||||
|
@ -583,10 +586,10 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
|
||||
self.available_flash_size = firmware_partition_size;
|
||||
|
||||
GUI.log(localization.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString()));
|
||||
GUI.log(i18n.getMessage('dfu_device_flash_info', (self.flash_layout.total_size / 1024).toString()));
|
||||
|
||||
if (self.hex.bytes_total > self.available_flash_size) {
|
||||
GUI.log(localization.getMessage('dfu_error_image_size',
|
||||
GUI.log(i18n.getMessage('dfu_error_image_size',
|
||||
[(self.hex.bytes_total / 1024.0).toFixed(1),
|
||||
(self.available_flash_size / 1024.0).toFixed(1)]));
|
||||
self.cleanup();
|
||||
|
@ -619,7 +622,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
|
||||
var unprotect = function() {
|
||||
console.log('Initiate read unprotect');
|
||||
let messageReadProtected = localization.getMessage('stm32ReadProtected');
|
||||
let messageReadProtected = i18n.getMessage('stm32ReadProtected');
|
||||
GUI.log(messageReadProtected);
|
||||
TABS.firmware_flasher.flashingMessage(messageReadProtected, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION);
|
||||
|
||||
|
@ -642,9 +645,9 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
self.controlTransfer('in', self.request.GETSTATUS, 0, 0, 6, 0, function (data, error) { // should stall/disconnect
|
||||
if(error) { // we encounter an error, but this is expected. should be a stall.
|
||||
console.log('Unprotect memory command ran successfully. Unplug flight controller. Connect again in DFU mode and try flashing again.');
|
||||
GUI.log(localization.getMessage('stm32UnprotectSuccessful'));
|
||||
GUI.log(i18n.getMessage('stm32UnprotectSuccessful'));
|
||||
|
||||
let messageUnprotectUnplug = localization.getMessage('stm32UnprotectUnplug');
|
||||
let messageUnprotectUnplug = i18n.getMessage('stm32UnprotectUnplug');
|
||||
GUI.log(messageUnprotectUnplug);
|
||||
|
||||
TABS.firmware_flasher.flashingMessage(messageUnprotectUnplug, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.ACTION)
|
||||
|
@ -653,8 +656,8 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
} else { // unprotecting the flight controller did not work. It did not reboot.
|
||||
console.log('Failed to execute unprotect memory command');
|
||||
|
||||
GUI.log(localization.getMessage('stm32UnprotectFailed'));
|
||||
TABS.firmware_flasher.flashingMessage(localization.getMessage('stm32UnprotectFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
GUI.log(i18n.getMessage('stm32UnprotectFailed'));
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32UnprotectFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
console.log(data);
|
||||
self.cleanup();
|
||||
}
|
||||
|
@ -662,7 +665,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
}, incr);
|
||||
} else {
|
||||
console.log('Failed to initiate unprotect memory command');
|
||||
let messageUnprotectInitFailed = localization.getMessage('stm32UnprotectInitFailed');
|
||||
let messageUnprotectInitFailed = i18n.getMessage('stm32UnprotectInitFailed');
|
||||
GUI.log(messageUnprotectInitFailed);
|
||||
TABS.firmware_flasher.flashingMessage(messageUnprotectInitFailed, TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
self.cleanup();
|
||||
|
@ -683,7 +686,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
if (data[4] == self.state.dfuUPLOAD_IDLE && ob_data.length == self.chipInfo.option_bytes.total_size) {
|
||||
console.log('Option bytes read successfully');
|
||||
console.log('Chip does not appear read protected');
|
||||
GUI.log(localization.getMessage('stm32NotReadProtected'));
|
||||
GUI.log(i18n.getMessage('stm32NotReadProtected'));
|
||||
// it is pretty safe to continue to erase flash
|
||||
self.clearStatus(function() {
|
||||
self.upload_procedure(2);
|
||||
|
@ -732,14 +735,14 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
// if address load fails with this specific error though, it is very likely bc of read protection
|
||||
if(loadAddressResponse[4] == self.state.dfuERROR && loadAddressResponse[0] == self.status.errVENDOR) {
|
||||
// read protected
|
||||
GUI.log(localization.getMessage('stm32AddressLoadFailed'));
|
||||
GUI.log(i18n.getMessage('stm32AddressLoadFailed'));
|
||||
self.clearStatus(unprotect);
|
||||
return;
|
||||
} else if(loadAddressResponse[4] == self.state.dfuDNLOAD_IDLE) {
|
||||
console.log('Address load for option bytes sector succeeded.');
|
||||
self.clearStatus(tryReadOB);
|
||||
} else {
|
||||
GUI.log(localization.getMessage('stm32AddressLoadUnknown'));
|
||||
GUI.log(i18n.getMessage('stm32AddressLoadUnknown'));
|
||||
self.cleanup();
|
||||
}
|
||||
};
|
||||
|
@ -781,13 +784,13 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
|
||||
if (erase_pages.length === 0) {
|
||||
console.log('Aborting, No flash pages to erase');
|
||||
TABS.firmware_flasher.flashingMessage(localization.getMessage('stm32InvalidHex'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32InvalidHex'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
self.cleanup();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
TABS.firmware_flasher.flashingMessage(localization.getMessage('stm32Erase'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32Erase'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
console.log('Executing local chip erase', erase_pages);
|
||||
|
||||
var page = 0;
|
||||
|
@ -799,7 +802,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
|
||||
if(page == erase_pages.length) {
|
||||
console.log("Erase: complete");
|
||||
GUI.log(localization.getMessage('dfu_erased_kilobytes', (total_erased / 1024).toString()));
|
||||
GUI.log(i18n.getMessage('dfu_erased_kilobytes', (total_erased / 1024).toString()));
|
||||
self.upload_procedure(4);
|
||||
} else {
|
||||
erase_page();
|
||||
|
@ -869,7 +872,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
// upload
|
||||
// we dont need to clear the state as we are already using DFU_DNLOAD
|
||||
console.log('Writing data ...');
|
||||
TABS.firmware_flasher.flashingMessage(localization.getMessage('stm32Flashing'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32Flashing'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
|
||||
var blocks = self.hex.data.length - 1;
|
||||
var flashing_block = 0;
|
||||
|
@ -941,7 +944,7 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
case 5:
|
||||
// verify
|
||||
console.log('Verifying data ...');
|
||||
TABS.firmware_flasher.flashingMessage(localization.getMessage('stm32Verifying'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32Verifying'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||
|
||||
var blocks = self.hex.data.length - 1;
|
||||
var reading_block = 0;
|
||||
|
@ -1009,14 +1012,14 @@ STM32DFU_protocol.prototype.upload_procedure = function (step) {
|
|||
if (verify) {
|
||||
console.log('Programming: SUCCESSFUL');
|
||||
// update progress bar
|
||||
TABS.firmware_flasher.flashingMessage(localization.getMessage('stm32ProgrammingSuccessful'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.VALID);
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32ProgrammingSuccessful'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.VALID);
|
||||
|
||||
// proceed to next step
|
||||
self.leave();
|
||||
} else {
|
||||
console.log('Programming: FAILED');
|
||||
// update progress bar
|
||||
TABS.firmware_flasher.flashingMessage(localization.getMessage('stm32ProgrammingFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
TABS.firmware_flasher.flashingMessage(i18n.getMessage('stm32ProgrammingFailed'), TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID);
|
||||
|
||||
// disconnect
|
||||
self.cleanup();
|
||||
|
@ -1070,4 +1073,5 @@ STM32DFU_protocol.prototype.cleanup = function () {
|
|||
};
|
||||
|
||||
// initialize object
|
||||
var STM32DFU = new STM32DFU_protocol();
|
||||
var STM32DFU = new STM32DFU_protocol();
|
||||
module.exports = STM32DFU;
|
Loading…
Add table
Add a link
Reference in a new issue