mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-25 17:25:16 +03:00
Improve debug logging (#4354)
* Improve debug logging * Remove condition * Update logHead
This commit is contained in:
parent
517bf7592d
commit
689fb7b894
7 changed files with 166 additions and 144 deletions
|
@ -9,6 +9,8 @@ const DEFAULT_PORT = "noselection";
|
|||
const DEFAULT_BAUDS = 115200;
|
||||
|
||||
const PortHandler = new (function () {
|
||||
this.logHead = "[PORTHANDLER]";
|
||||
|
||||
this.currentSerialPorts = [];
|
||||
this.currentUsbPorts = [];
|
||||
this.currentBluetoothPorts = [];
|
||||
|
@ -118,7 +120,7 @@ PortHandler.updateCurrentSerialPortsList = async function () {
|
|||
const ports = await serial.getDevices();
|
||||
const orderedPorts = this.sortPorts(ports);
|
||||
this.portAvailable = orderedPorts.length > 0;
|
||||
|
||||
console.log(`${this.logHead} Found serial port`, orderedPorts);
|
||||
this.currentSerialPorts = [...orderedPorts];
|
||||
};
|
||||
|
||||
|
@ -126,7 +128,7 @@ PortHandler.updateCurrentUsbPortsList = async function () {
|
|||
const ports = await usb.getDevices();
|
||||
const orderedPorts = this.sortPorts(ports);
|
||||
this.dfuAvailable = orderedPorts.length > 0;
|
||||
|
||||
console.log(`${this.logHead} Found DFU port`, orderedPorts);
|
||||
this.currentUsbPorts = [...orderedPorts];
|
||||
};
|
||||
|
||||
|
@ -135,7 +137,7 @@ PortHandler.updateCurrentBluetoothPortsList = async function () {
|
|||
const ports = await BT.getDevices();
|
||||
const orderedPorts = this.sortPorts(ports);
|
||||
this.bluetoothAvailable = orderedPorts.length > 0;
|
||||
|
||||
console.log(`${this.logHead} Found bluetooth port`, orderedPorts);
|
||||
this.currentBluetoothPorts = [...orderedPorts];
|
||||
}
|
||||
};
|
||||
|
@ -236,11 +238,10 @@ PortHandler.selectActivePort = function (suggestedDevice) {
|
|||
// Return the default port if no other port was selected
|
||||
this.portPicker.selectedPort = selectedPort || DEFAULT_PORT;
|
||||
|
||||
console.log(`[PORTHANDLER] automatically selected device is '${this.portPicker.selectedPort}'`);
|
||||
|
||||
// hack to update Vue component
|
||||
const p = document.getElementById("port");
|
||||
p.value = this.portPicker.selectedPort;
|
||||
console.log(
|
||||
`${this.logHead} Automatically selected device is '${this.portPicker.selectedPort}' - suggested:`,
|
||||
suggestedDevice,
|
||||
);
|
||||
|
||||
return selectedPort;
|
||||
};
|
||||
|
|
|
@ -58,6 +58,8 @@ class BT extends EventTarget {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.logHead = "[BLUETOOTH]";
|
||||
|
||||
if (!this.bluetooth && window && window.navigator && window.navigator.bluetooth) {
|
||||
this.bluetooth = navigator.bluetooth;
|
||||
} else {
|
||||
|
@ -77,8 +79,6 @@ class BT extends EventTarget {
|
|||
this.bytesReceived = 0;
|
||||
this.failed = 0;
|
||||
|
||||
this.logHead = "[BLUETOOTH]";
|
||||
|
||||
this.portCounter = 0;
|
||||
this.devices = [];
|
||||
this.device = null;
|
||||
|
|
|
@ -2,6 +2,8 @@ class WebsocketSerial extends EventTarget {
|
|||
constructor() {
|
||||
super();
|
||||
|
||||
this.logHead = "[WEBSOCKET]";
|
||||
|
||||
this.connected = false;
|
||||
this.connectionInfo = null;
|
||||
|
||||
|
@ -10,8 +12,6 @@ class WebsocketSerial extends EventTarget {
|
|||
this.bytesReceived = 0;
|
||||
this.failed = 0;
|
||||
|
||||
this.logHead = "[WEBSOCKET] ";
|
||||
|
||||
this.address = "ws://localhost:5761";
|
||||
|
||||
this.ws = null;
|
||||
|
|
|
@ -27,7 +27,7 @@ function readSerialAdapter(event) {
|
|||
|
||||
function onTimeoutHandler() {
|
||||
GUI.connect_lock = false;
|
||||
console.log("Looking for capabilities via MSP failed");
|
||||
console.log(`${STM32Protocol.logHead} Looking for capabilities via MSP failed`);
|
||||
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32RebootingToBootloaderFailed"),
|
||||
|
@ -42,6 +42,8 @@ function onFailureHandler() {
|
|||
|
||||
class STM32Protocol {
|
||||
constructor() {
|
||||
this.logHead = "[STM32]";
|
||||
|
||||
this.baud = null;
|
||||
this.options = {};
|
||||
this.callback = null;
|
||||
|
@ -87,7 +89,7 @@ class STM32Protocol {
|
|||
}
|
||||
|
||||
handleConnect(event) {
|
||||
console.log("Connected to serial port", event.detail, event);
|
||||
console.log(`${this.logHead} Connected to serial port`, event.detail, event);
|
||||
if (event) {
|
||||
// we are connected, disabling connect button in the UI
|
||||
GUI.connect_lock = true;
|
||||
|
@ -99,7 +101,7 @@ class STM32Protocol {
|
|||
}
|
||||
|
||||
handleDisconnect(disconnectionResult) {
|
||||
console.log("Waiting for DFU connection");
|
||||
console.log(`${this.logHead} Waiting for DFU connection`);
|
||||
|
||||
serial.removeEventListener("connect", (event) => this.handleConnect(event.detail));
|
||||
serial.removeEventListener("disconnect", (event) => this.handleDisconnect(event.detail));
|
||||
|
@ -108,20 +110,20 @@ class STM32Protocol {
|
|||
// If the firmware_flasher does not start flashing, we need to ask for permission to flash
|
||||
setTimeout(() => {
|
||||
if (this.rebootMode) {
|
||||
console.log("STM32 Requesting permission for device");
|
||||
console.log(`${this.logHead} STM32 Requesting permission for device`);
|
||||
|
||||
DFU.requestPermission()
|
||||
.then((device) => {
|
||||
if (device != null) {
|
||||
console.log("DFU request permission granted", device);
|
||||
console.log(`${this.logHead} DFU request permission granted`, device);
|
||||
} else {
|
||||
console.error("DFU request permission denied");
|
||||
console.error(`${this.logHead} DFU request permission denied`);
|
||||
this.rebootMode = 0;
|
||||
GUI.connect_lock = false;
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("DFU request permission failed", e);
|
||||
console.error(`${this.logHead} DFU request permission failed`, e);
|
||||
this.rebootMode = 0;
|
||||
GUI.connect_lock = false;
|
||||
});
|
||||
|
@ -147,34 +149,34 @@ class STM32Protocol {
|
|||
MSP.promise(MSPCodes.MSP_SET_REBOOT, buffer).then(() => {
|
||||
// if firmware doesn't flush MSP/serial send buffers and gracefully shutdown VCP connections we won't get a reply, so don't wait for it.
|
||||
this.mspConnector.disconnect((disconnectionResult) => {
|
||||
console.log("Disconnecting from MSP", disconnectionResult);
|
||||
console.log(`${this.logHead} Disconnecting from MSP`, disconnectionResult);
|
||||
this.handleDisconnect(disconnectionResult);
|
||||
});
|
||||
});
|
||||
console.log("Reboot request received by device");
|
||||
console.log(`${this.logHead} Reboot request received by device`);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
onAbort() {
|
||||
GUI.connect_lock = false;
|
||||
this.rebootMode = 0;
|
||||
console.log("User cancelled because selected target does not match verified board");
|
||||
console.log(`${this.logHead} User cancelled because selected target does not match verified board`);
|
||||
this.reboot();
|
||||
TABS.firmware_flasher.refresh();
|
||||
}
|
||||
|
||||
lookingForCapabilitiesViaMSP() {
|
||||
console.log("Looking for capabilities via MSP");
|
||||
console.log(`${this.logHead} Looking for capabilities via MSP`);
|
||||
|
||||
MSP.promise(MSPCodes.MSP_BOARD_INFO).then(() => {
|
||||
if (bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_FLASH_BOOTLOADER)) {
|
||||
// Board has flash bootloader
|
||||
gui_log(i18n.getMessage("deviceRebooting_flashBootloader"));
|
||||
console.log("flash bootloader detected");
|
||||
console.log(`${this.logHead} flash bootloader detected`);
|
||||
this.rebootMode = 4; // MSP_REBOOT_BOOTLOADER_FLASH
|
||||
} else {
|
||||
gui_log(i18n.getMessage("deviceRebooting_romBootloader"));
|
||||
console.log("no flash bootloader detected");
|
||||
console.log(`${this.logHead} no flash bootloader detected`);
|
||||
this.rebootMode = 1; // MSP_REBOOT_BOOTLOADER_ROM;
|
||||
}
|
||||
|
||||
|
@ -258,8 +260,6 @@ class STM32Protocol {
|
|||
|
||||
// initialize certain variables and start timers that oversee the communication
|
||||
initialize() {
|
||||
console.log(":exploding_head:");
|
||||
|
||||
// reset and set some variables before we start
|
||||
this.receive_buffer = [];
|
||||
this.verify_hex = [];
|
||||
|
@ -283,7 +283,7 @@ class STM32Protocol {
|
|||
// process is running
|
||||
this.upload_process_alive = false;
|
||||
} else {
|
||||
console.log("STM32 - timed out, programming failed ...");
|
||||
console.log(`${this.logHead} STM32 - timed out, programming failed ...`);
|
||||
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32TimedOut"),
|
||||
|
@ -300,7 +300,7 @@ class STM32Protocol {
|
|||
2000,
|
||||
);
|
||||
|
||||
console.log("STM32 - Initialization done, starting upload procedure");
|
||||
console.log(`${this.logHead} STM32 - Initialization done, starting upload procedure`);
|
||||
|
||||
this.upload_procedure(1);
|
||||
}
|
||||
|
@ -388,64 +388,64 @@ class STM32Protocol {
|
|||
verify_chip_signature(signature) {
|
||||
switch (signature) {
|
||||
case 0x412: // not tested
|
||||
console.log("Chip recognized as F1 Low-density");
|
||||
console.log(`${this.logHead} Chip recognized as F1 Low-density`);
|
||||
break;
|
||||
case 0x410:
|
||||
console.log("Chip recognized as F1 Medium-density");
|
||||
console.log(`${this.logHead} Chip recognized as F1 Medium-density`);
|
||||
this.available_flash_size = 131072;
|
||||
this.page_size = 1024;
|
||||
break;
|
||||
case 0x414:
|
||||
this.available_flash_size = 0x40000;
|
||||
this.page_size = 2048;
|
||||
console.log("Chip recognized as F1 High-density");
|
||||
console.log(`${this.logHead} Chip recognized as F1 High-density`);
|
||||
break;
|
||||
case 0x418: // not tested
|
||||
console.log("Chip recognized as F1 Connectivity line");
|
||||
console.log(`${this.logHead} Chip recognized as F1 Connectivity line`);
|
||||
break;
|
||||
case 0x420: // not tested
|
||||
console.log("Chip recognized as F1 Medium-density value line");
|
||||
console.log(`${this.logHead} Chip recognized as F1 Medium-density value line`);
|
||||
break;
|
||||
case 0x428: // not tested
|
||||
console.log("Chip recognized as F1 High-density value line");
|
||||
console.log(`${this.logHead} Chip recognized as F1 High-density value line`);
|
||||
break;
|
||||
case 0x430: // not tested
|
||||
console.log("Chip recognized as F1 XL-density value line");
|
||||
console.log(`${this.logHead} Chip recognized as F1 XL-density value line`);
|
||||
break;
|
||||
case 0x416: // not tested
|
||||
console.log("Chip recognized as L1 Medium-density ultralow power");
|
||||
console.log(`${this.logHead} Chip recognized as L1 Medium-density ultralow power`);
|
||||
break;
|
||||
case 0x436: // not tested
|
||||
console.log("Chip recognized as L1 High-density ultralow power");
|
||||
console.log(`${this.logHead} Chip recognized as L1 High-density ultralow power`);
|
||||
break;
|
||||
case 0x427: // not tested
|
||||
console.log("Chip recognized as L1 Medium-density plus ultralow power");
|
||||
console.log(`${this.logHead} Chip recognized as L1 Medium-density plus ultralow power`);
|
||||
break;
|
||||
case 0x411: // not tested
|
||||
console.log("Chip recognized as F2 STM32F2xxxx");
|
||||
console.log(`${this.logHead} Chip recognized as F2 STM32F2xxxx`);
|
||||
break;
|
||||
case 0x440: // not tested
|
||||
console.log("Chip recognized as F0 STM32F051xx");
|
||||
console.log(`${this.logHead} Chip recognized as F0 STM32F051xx`);
|
||||
break;
|
||||
case 0x444: // not tested
|
||||
console.log("Chip recognized as F0 STM32F050xx");
|
||||
console.log(`${this.logHead} Chip recognized as F0 STM32F050xx`);
|
||||
break;
|
||||
case 0x413: // not tested
|
||||
console.log("Chip recognized as F4 STM32F40xxx/41xxx");
|
||||
console.log(`${this.logHead} Chip recognized as F4 STM32F40xxx/41xxx`);
|
||||
break;
|
||||
case 0x419: // not tested
|
||||
console.log("Chip recognized as F4 STM32F427xx/437xx, STM32F429xx/439xx");
|
||||
console.log(`${this.logHead} Chip recognized as F4 STM32F427xx/437xx, STM32F429xx/439xx`);
|
||||
break;
|
||||
case 0x432: // not tested
|
||||
console.log("Chip recognized as F3 STM32F37xxx, STM32F38xxx");
|
||||
console.log(`${this.logHead} Chip recognized as F3 STM32F37xxx, STM32F38xxx`);
|
||||
break;
|
||||
case 0x422:
|
||||
console.log("Chip recognized as F3 STM32F30xxx, STM32F31xxx");
|
||||
console.log(`${this.logHead} Chip recognized as F3 STM32F30xxx, STM32F31xxx`);
|
||||
this.available_flash_size = 0x40000;
|
||||
this.page_size = 2048;
|
||||
break;
|
||||
default:
|
||||
console.log(`Chip NOT recognized: ${signature}`);
|
||||
console.log(`${this.logHead} Chip NOT recognized: ${signature}`);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -454,13 +454,13 @@ class STM32Protocol {
|
|||
return true;
|
||||
} else {
|
||||
console.log(
|
||||
`Supplied hex is bigger then flash available on the chip, HEX: ${this.hex.bytes_total} bytes, limit = ${this.available_flash_size} bytes`,
|
||||
`${this.logHead} Supplied hex is bigger then flash available on the chip, HEX: ${this.hex.bytes_total} bytes, limit = ${this.available_flash_size} bytes`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Chip NOT recognized: ${signature}`);
|
||||
console.log(`${this.logHead} Chip NOT recognized: ${signature}`);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ class STM32Protocol {
|
|||
for (let i = 0; i < firstArray.length; i++) {
|
||||
if (firstArray[i] !== secondArray[i]) {
|
||||
console.log(
|
||||
`Verification failed on byte: ${i} expected: 0x${firstArray[i].toString(
|
||||
`${this.logHead} Verification failed on byte: ${i} expected: 0x${firstArray[i].toString(
|
||||
16,
|
||||
)} received: 0x${secondArray[i].toString(16)}`,
|
||||
);
|
||||
|
@ -479,7 +479,7 @@ class STM32Protocol {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(`Verification successful, matching: ${firstArray.length} bytes`);
|
||||
console.log(`${this.logHead} Verification successful, matching: ${firstArray.length} bytes`);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ class STM32Protocol {
|
|||
this.send([0x7f], 1, (reply) => {
|
||||
if (reply[0] === 0x7f || reply[0] === this.status.ACK || reply[0] === this.status.NACK) {
|
||||
GUI.interval_remove("stm32_initialize_mcu");
|
||||
console.log("STM32 - Serial interface initialized on the MCU side");
|
||||
console.log(`${this.logHead} Serial interface initialized on the MCU side`);
|
||||
|
||||
// proceed to next step
|
||||
this.upload_procedure(2);
|
||||
|
@ -519,7 +519,7 @@ class STM32Protocol {
|
|||
|
||||
if (sendCounter++ > 3) {
|
||||
// stop retrying, its too late to get any response from MCU
|
||||
console.log("STM32 - no response from bootloader, disconnecting");
|
||||
console.log(`${this.logHead} No response from bootloader, disconnecting`);
|
||||
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32ResponseBootloaderFailed"),
|
||||
|
@ -545,7 +545,9 @@ class STM32Protocol {
|
|||
if (this.verify_response(this.status.ACK, data)) {
|
||||
this.retrieve(data[1] + 1 + 1, (data) => {
|
||||
console.log(
|
||||
`STM32 - Bootloader version: ${(parseInt(data[0].toString(16)) / 10).toFixed(1)}`,
|
||||
`${this.logHead} Bootloader version: ${(parseInt(data[0].toString(16)) / 10).toFixed(
|
||||
1,
|
||||
)}`,
|
||||
); // convert dec to hex, hex to dec and add floating point
|
||||
|
||||
this.useExtendedErase = data[7] === this.command.extended_erase;
|
||||
|
@ -564,7 +566,7 @@ class STM32Protocol {
|
|||
if (this.verify_response(this.status.ACK, data)) {
|
||||
this.retrieve(data[1] + 1 + 1, (data) => {
|
||||
const signature = (data[0] << 8) | data[1];
|
||||
console.log(`STM32 - Signature: 0x${signature.toString(16)}`); // signature in hex representation
|
||||
console.log(`${this.logHead} Signature: 0x${signature.toString(16)}`); // signature in hex representation
|
||||
|
||||
if (this.verify_chip_signature(signature)) {
|
||||
// proceed to next step
|
||||
|
@ -582,8 +584,7 @@ class STM32Protocol {
|
|||
// erase memory
|
||||
if (this.useExtendedErase) {
|
||||
if (this.options.erase_chip) {
|
||||
const message = "Executing global chip erase (via extended erase)";
|
||||
console.log(message);
|
||||
console.log(`${this.logHead} Executing global chip erase (via extended erase)`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32GlobalEraseExtended"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -593,15 +594,14 @@ class STM32Protocol {
|
|||
if (this.verify_response(this.status.ACK, reply)) {
|
||||
this.send([0xff, 0xff, 0x00], 1, (reply) => {
|
||||
if (this.verify_response(this.status.ACK, reply)) {
|
||||
console.log("Executing global chip extended erase: done");
|
||||
console.log(`${this.logHead} Executing global chip extended erase: done`);
|
||||
this.upload_procedure(5);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
const message = "Executing local erase (via extended erase)";
|
||||
console.log(message);
|
||||
console.log(`${this.logHead} Executing local erase (via extended erase)`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32LocalEraseExtended"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -638,14 +638,14 @@ class STM32Protocol {
|
|||
|
||||
buff.push(checksum);
|
||||
console.log(
|
||||
`Erasing. pages: 0x00 - 0x${erasePagesN.toString(
|
||||
`${this.logHead} Erasing. pages: 0x00 - 0x${erasePagesN.toString(
|
||||
16,
|
||||
)}, checksum: 0x${checksum.toString(16)}`,
|
||||
);
|
||||
|
||||
this.send(buff, 1, (_reply) => {
|
||||
if (this.verify_response(this.status.ACK, _reply)) {
|
||||
console.log("Erasing: done");
|
||||
console.log(`${this.logHead} Erasing: done`);
|
||||
// proceed to next step
|
||||
this.upload_procedure(5);
|
||||
}
|
||||
|
@ -657,8 +657,7 @@ class STM32Protocol {
|
|||
}
|
||||
|
||||
if (this.options.erase_chip) {
|
||||
const message = "Executing global chip erase";
|
||||
console.log(message);
|
||||
console.log(`${this.logHead} Executing global chip erase`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32GlobalErase"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -668,7 +667,7 @@ class STM32Protocol {
|
|||
if (this.verify_response(this.status.ACK, reply)) {
|
||||
this.send([0xff, 0x00], 1, (reply) => {
|
||||
if (this.verify_response(this.status.ACK, reply)) {
|
||||
console.log("Erasing: done");
|
||||
console.log(`${this.logHead} Erasing: done`);
|
||||
// proceed to next step
|
||||
this.upload_procedure(5);
|
||||
}
|
||||
|
@ -676,8 +675,7 @@ class STM32Protocol {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
const message = "Executing local erase";
|
||||
console.log(message);
|
||||
console.log(`${this.logHead} Executing local erase`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32LocalErase"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -705,7 +703,7 @@ class STM32Protocol {
|
|||
|
||||
this.send(buff, 1, (reply) => {
|
||||
if (this.verify_response(this.status.ACK, reply)) {
|
||||
console.log("Erasing: done");
|
||||
console.log(`${this.logHead} Erasing: done`);
|
||||
// proceed to next step
|
||||
this.upload_procedure(5);
|
||||
}
|
||||
|
@ -718,7 +716,7 @@ class STM32Protocol {
|
|||
}
|
||||
case 5: {
|
||||
// upload
|
||||
console.log("Writing data ...");
|
||||
console.log(`${this.logHead} Writing data ...`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32Flashing"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -797,7 +795,7 @@ class STM32Protocol {
|
|||
write();
|
||||
} else {
|
||||
// all blocks flashed
|
||||
console.log("Writing: done");
|
||||
console.log(`${this.logHead} Writing: done`);
|
||||
|
||||
// proceed to next step
|
||||
this.upload_procedure(6);
|
||||
|
@ -811,7 +809,7 @@ class STM32Protocol {
|
|||
}
|
||||
case 6: {
|
||||
// verify
|
||||
console.log("Verifying data ...");
|
||||
console.log(`${this.logHead} Verifying data ...`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32Verifying"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -905,7 +903,7 @@ class STM32Protocol {
|
|||
}
|
||||
|
||||
if (verify) {
|
||||
console.log("Programming: SUCCESSFUL");
|
||||
console.log(`${this.logHead} Programming: SUCCESSFUL`);
|
||||
// update progress bar
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32ProgrammingSuccessful"),
|
||||
|
@ -923,7 +921,7 @@ class STM32Protocol {
|
|||
// proceed to next step
|
||||
this.upload_procedure(7);
|
||||
} else {
|
||||
console.log("Programming: FAILED");
|
||||
console.log(`${this.logHead} Programming: FAILED`);
|
||||
// update progress bar
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32ProgrammingFailed"),
|
||||
|
@ -952,7 +950,7 @@ class STM32Protocol {
|
|||
case 7: {
|
||||
// go
|
||||
// memory address = 4 bytes, 1st high byte, 4th low byte, 5th byte = checksum XOR(byte 1, byte 2, byte 3, byte 4)
|
||||
console.log("Sending GO command: 0x8000000");
|
||||
console.log(`${this.logHead} Sending GO command: 0x8000000`);
|
||||
|
||||
this.send([this.command.go, 0xde], 1, (reply) => {
|
||||
if (this.verify_response(this.status.ACK, reply)) {
|
||||
|
@ -998,7 +996,7 @@ class STM32Protocol {
|
|||
// handle timing
|
||||
const timeSpent = new Date().getTime() - this.upload_time_start;
|
||||
|
||||
console.log(`Script finished after: ${timeSpent / 1000} seconds`);
|
||||
console.log(`${this.logHead} Script finished after: ${timeSpent / 1000} seconds`);
|
||||
|
||||
if (this.callback) {
|
||||
this.callback();
|
||||
|
|
|
@ -23,6 +23,9 @@ import { get as getConfig } from "../ConfigStorage";
|
|||
class WEBUSBDFU_protocol extends EventTarget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.logHead = "[WEBUSB DFU]";
|
||||
|
||||
this.callback = null;
|
||||
this.hex = null;
|
||||
this.verify_hex = [];
|
||||
|
@ -110,7 +113,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
const userSelectedPort = await navigator.usb.requestDevice(usbDevices);
|
||||
console.info("User selected USB device from permissions:", userSelectedPort);
|
||||
console.log(
|
||||
`WebUSB Version: ${userSelectedPort.deviceVersionMajor}.${userSelectedPort.deviceVersionMinor}.${userSelectedPort.deviceVersionSubminor}`,
|
||||
`${this.logHead} WebUSB Version: ${userSelectedPort.deviceVersionMajor}.${userSelectedPort.deviceVersionMinor}.${userSelectedPort.deviceVersionSubminor}`,
|
||||
);
|
||||
|
||||
newPermissionPort = this.handleNewDevice(userSelectedPort);
|
||||
|
@ -154,14 +157,14 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
.open()
|
||||
.then(async () => {
|
||||
// show key values for the device
|
||||
console.log(`USB Device opened: ${this.usbDevice.productName}`);
|
||||
console.log(`${this.logHead} USB Device opened: ${this.usbDevice.productName}`);
|
||||
if (this.usbDevice.configuration === null) {
|
||||
await this.usbDevice.selectConfiguration(1);
|
||||
}
|
||||
this.claimInterface(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Failed to open USB device:", error);
|
||||
console.log(`${this.logHead} Failed to open USB device:`, error);
|
||||
gui_log(i18n.getMessage("usbDeviceOpenFail"));
|
||||
});
|
||||
}
|
||||
|
@ -170,10 +173,10 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
.close()
|
||||
.then(() => {
|
||||
gui_log(i18n.getMessage("usbDeviceClosed"));
|
||||
console.log("DFU Device closed");
|
||||
console.log(`${this.logHead} DFU Device closed`);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Failed to close USB device:", error);
|
||||
console.log(`${this.logHead} Failed to close USB device:`, error);
|
||||
gui_log(i18n.getMessage("usbDeviceCloseFail"));
|
||||
});
|
||||
this.usbDevice = null;
|
||||
|
@ -182,7 +185,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
this.usbDevice
|
||||
.claimInterface(interfaceNumber)
|
||||
.then(() => {
|
||||
console.log(`Claimed interface: ${interfaceNumber}`);
|
||||
console.log(`${this.logHead} Claimed interface: ${interfaceNumber}`);
|
||||
if (this.options.exitDfu) {
|
||||
this.leave();
|
||||
} else {
|
||||
|
@ -190,17 +193,17 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Failed to claim USB device", error);
|
||||
console.log(`${this.logHead} Failed to claim USB device`, error);
|
||||
this.cleanup();
|
||||
});
|
||||
}
|
||||
releaseInterface(interfaceNumber) {
|
||||
this.usbDevice
|
||||
.releaseInterface(interfaceNumber, () => {
|
||||
console.log(`Released interface: ${interfaceNumber}`);
|
||||
console.log(`${this.logHead} Released interface: ${interfaceNumber}`);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`Could not release interface: ${interfaceNumber} (${error})`);
|
||||
console.log(`${this.logHead} Could not release interface: ${interfaceNumber} (${error})`);
|
||||
})
|
||||
.finally(() => {
|
||||
// releaseInterface does not work on some devices, so we close the device anyways
|
||||
|
@ -211,11 +214,11 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
this.usbDevice
|
||||
.reset()
|
||||
.then(() => {
|
||||
console.log("Reset Device");
|
||||
console.log(`${this.logHead} Reset Device`);
|
||||
callback?.();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`Could not reset device: ${error}`);
|
||||
console.log(`${this.logHead} Could not reset device: ${error}`);
|
||||
callback?.();
|
||||
});
|
||||
}
|
||||
|
@ -244,7 +247,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`USB getString failed! ${error}`);
|
||||
console.log(`${this.logHead} USB getString failed! ${error}`);
|
||||
callback("", 1);
|
||||
});
|
||||
}
|
||||
|
@ -303,7 +306,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
.then((result) => {
|
||||
if (result.status === "ok") {
|
||||
const buf = new Uint8Array(result.data.buffer, 9 + _interface * 9);
|
||||
console.log(`USB getInterfaceDescriptor: ${buf}`);
|
||||
console.log(`${this.logHead} USB getInterfaceDescriptor: ${buf}`);
|
||||
const descriptor = {
|
||||
bLength: buf[0],
|
||||
bDescriptorType: buf[1],
|
||||
|
@ -317,12 +320,12 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
};
|
||||
callback(descriptor, 0);
|
||||
} else {
|
||||
console.log(`USB getInterfaceDescriptor failed: ${result.status}`);
|
||||
console.log(`${this.logHead} USB getInterfaceDescriptor failed: ${result.status}`);
|
||||
throw new Error(result.status);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`USB getInterfaceDescriptor failed: ${error}`);
|
||||
console.log(`${this.logHead} USB getInterfaceDescriptor failed: ${error}`);
|
||||
callback({}, 1);
|
||||
return;
|
||||
});
|
||||
|
@ -355,7 +358,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`USB getFunctionalDescriptor failed: ${error}`);
|
||||
console.log(`${this.logHead} USB getFunctionalDescriptor failed: ${error}`);
|
||||
callback({}, 1);
|
||||
});
|
||||
}
|
||||
|
@ -402,7 +405,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
// May need to preserve the second bank if the configurator starts to really
|
||||
// support option bytes.
|
||||
if (tmp1.length > 3) {
|
||||
console.log(`parseDescriptor: shrinking long descriptor "${str}"`);
|
||||
console.log(`${this.logHead} parseDescriptor: shrinking long descriptor "${str}"`);
|
||||
tmp1.length = 3;
|
||||
}
|
||||
|
||||
|
@ -492,7 +495,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`USB controlTransfer IN failed for request: ${request}`);
|
||||
console.log(`${this.logHead} USB controlTransfer IN failed for request: ${request}`);
|
||||
callback([], 1);
|
||||
});
|
||||
} else {
|
||||
|
@ -517,7 +520,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(`USB controlTransfer OUT failed for request: ${request}`);
|
||||
console.log(`${this.logHead} USB controlTransfer OUT failed for request: ${request}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -560,7 +563,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
if (data[4] === this.state.dfuDNLOAD_IDLE) {
|
||||
callback(data);
|
||||
} else {
|
||||
console.log("Failed to execute address load");
|
||||
console.log(`${this.logHead} Failed to execute address load`);
|
||||
if (typeof abort === "undefined" || abort) {
|
||||
this.cleanup();
|
||||
} else {
|
||||
|
@ -570,7 +573,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
});
|
||||
}, delay);
|
||||
} else {
|
||||
console.log("Failed to request address load");
|
||||
console.log(`${this.logHead} Failed to request address load`);
|
||||
this.cleanup();
|
||||
}
|
||||
});
|
||||
|
@ -584,7 +587,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
for (let i = 0; i < first_array.length; i++) {
|
||||
if (first_array[i] !== second_array[i]) {
|
||||
console.log(
|
||||
`Verification failed on byte: ${i} expected: 0x${first_array[i].toString(
|
||||
`${this.logHead} Verification failed on byte: ${i} expected: 0x${first_array[i].toString(
|
||||
16,
|
||||
)} received: 0x${second_array[i].toString(16)}`,
|
||||
);
|
||||
|
@ -592,7 +595,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(`Verification successful, matching: ${first_array.length} bytes`);
|
||||
console.log(`${this.logHead} Verification successful, matching: ${first_array.length} bytes`);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -644,7 +647,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
case 0:
|
||||
this.getChipInfo(0, (chipInfo, resultCode) => {
|
||||
if (resultCode !== 0 || typeof chipInfo === "undefined") {
|
||||
console.log(`Failed to detect chip info, resultCode: ${resultCode}`);
|
||||
console.log(`${this.logHead} Failed to detect chip info, resultCode: ${resultCode}`);
|
||||
this.cleanup();
|
||||
} else {
|
||||
let nextAction;
|
||||
|
@ -661,7 +664,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
const boardSize = chipInfo.internal_flash.total_size;
|
||||
const bareBoard = TABS.firmware_flasher.bareBoard;
|
||||
console.log(
|
||||
`Firmware size ${firmwareSize} exceeds board memory size ${boardSize} (${bareBoard})`,
|
||||
`${this.logHead} Firmware size ${firmwareSize} exceeds board memory size ${boardSize} (${bareBoard})`,
|
||||
);
|
||||
}
|
||||
} else if (typeof chipInfo.external_flash !== "undefined") {
|
||||
|
@ -671,7 +674,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
this.chipInfo = chipInfo;
|
||||
this.flash_layout = chipInfo.external_flash;
|
||||
} else {
|
||||
console.log("Failed to detect internal or external flash");
|
||||
console.log(`${this.logHead} Failed to detect internal or external flash`);
|
||||
this.cleanup();
|
||||
}
|
||||
|
||||
|
@ -703,7 +706,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
} else {
|
||||
this.getFunctionalDescriptor(0, (descriptor, resultCode) => {
|
||||
this.transferSize = resultCode ? 2048 : descriptor.wTransferSize;
|
||||
console.log(`Using transfer size: ${this.transferSize}`);
|
||||
console.log(`${this.logHead} Using transfer size: ${this.transferSize}`);
|
||||
this.clearStatus(() => {
|
||||
this.upload_procedure(nextAction);
|
||||
});
|
||||
|
@ -715,12 +718,12 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
break;
|
||||
case 1: {
|
||||
if (typeof this.chipInfo.option_bytes === "undefined") {
|
||||
console.log("Failed to detect option bytes");
|
||||
console.log(`${this.logHead} Failed to detect option bytes`);
|
||||
this.cleanup();
|
||||
}
|
||||
|
||||
const unprotect = () => {
|
||||
console.log("Initiate read unprotect");
|
||||
console.log(`${this.logHead} Initiate read unprotect`);
|
||||
const messageReadProtected = i18n.getMessage("stm32ReadProtected");
|
||||
gui_log(messageReadProtected);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
|
@ -758,7 +761,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
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.",
|
||||
`${this.logHead} Unprotect memory command ran successfully. Unplug flight controller. Connect again in DFU mode and try flashing again.`,
|
||||
);
|
||||
gui_log(i18n.getMessage("stm32UnprotectSuccessful"));
|
||||
|
||||
|
@ -774,14 +777,16 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
.flashProgress(0);
|
||||
} else {
|
||||
// unprotecting the flight controller did not work. It did not reboot.
|
||||
console.log("Failed to execute unprotect memory command");
|
||||
console.log(
|
||||
`${this.logHead} Failed to execute unprotect memory command`,
|
||||
);
|
||||
|
||||
gui_log(i18n.getMessage("stm32UnprotectFailed"));
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32UnprotectFailed"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID,
|
||||
);
|
||||
console.log(data);
|
||||
console.log(`${this.logHead} `, data);
|
||||
this.cleanup();
|
||||
}
|
||||
},
|
||||
|
@ -789,7 +794,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}, 2000); // this should stall/disconnect anyways. so we only wait 2 sec max.
|
||||
}, incr);
|
||||
} else {
|
||||
console.log("Failed to initiate unprotect memory command");
|
||||
console.log(`${this.logHead} Failed to initiate unprotect memory command`);
|
||||
let messageUnprotectInitFailed = i18n.getMessage("stm32UnprotectInitFailed");
|
||||
gui_log(messageUnprotectInitFailed);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
|
@ -825,15 +830,17 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
data[4] === this.state.dfuUPLOAD_IDLE &&
|
||||
ob_data.length === this.chipInfo.option_bytes.total_size
|
||||
) {
|
||||
console.log("Option bytes read successfully");
|
||||
console.log("Chip does not appear read protected");
|
||||
console.log(`${this.logHead} Option bytes read successfully`);
|
||||
console.log(`${this.logHead} Chip does not appear read protected`);
|
||||
gui_log(i18n.getMessage("stm32NotReadProtected"));
|
||||
// it is pretty safe to continue to erase flash
|
||||
this.clearStatus(() => {
|
||||
this.upload_procedure(2);
|
||||
});
|
||||
} else {
|
||||
console.log("Option bytes could not be read. Quite possibly read protected.");
|
||||
console.log(
|
||||
`${this.logHead} Option bytes could not be read. Quite possibly read protected.`,
|
||||
);
|
||||
this.clearStatus(unprotect);
|
||||
}
|
||||
});
|
||||
|
@ -853,7 +860,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
this.clearStatus(unprotect);
|
||||
return;
|
||||
} else if (loadAddressResponse[4] === this.state.dfuDNLOAD_IDLE) {
|
||||
console.log("Address load for option bytes sector succeeded.");
|
||||
console.log(`${this.logHead} Address load for option bytes sector succeeded.`);
|
||||
this.clearStatus(tryReadOB);
|
||||
} else {
|
||||
gui_log(i18n.getMessage("stm32AddressLoadUnknown"));
|
||||
|
@ -901,7 +908,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
|
||||
if (erase_pages.length === 0) {
|
||||
console.log("Aborting, No flash pages to erase");
|
||||
console.log(`${this.logHead} Aborting, No flash pages to erase`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32InvalidHex"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.INVALID,
|
||||
|
@ -914,7 +921,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
i18n.getMessage("stm32Erase"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
);
|
||||
console.log("Executing local chip erase", erase_pages);
|
||||
console.log(`${this.logHead} Executing local chip erase`, erase_pages);
|
||||
|
||||
let page = 0;
|
||||
let total_erased = 0; // bytes
|
||||
|
@ -924,7 +931,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
page++;
|
||||
|
||||
if (page === erase_pages.length) {
|
||||
console.log("Erase: complete");
|
||||
console.log(`${this.logHead} Erase: complete`);
|
||||
gui_log(i18n.getMessage("dfu_erased_kilobytes", (total_erased / 1024).toString()));
|
||||
this.upload_procedure(4);
|
||||
} else {
|
||||
|
@ -945,7 +952,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
];
|
||||
total_erased += this.flash_layout.sectors[erase_pages[page].sector].page_size;
|
||||
console.log(
|
||||
`Erasing. sector ${erase_pages[page].sector}, page ${
|
||||
`${this.logHead} Erasing. sector ${erase_pages[page].sector}, page ${
|
||||
erase_pages[page].page
|
||||
} @ 0x${page_addr.toString(16)}`,
|
||||
);
|
||||
|
@ -967,7 +974,9 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
// 3. Treat the current erase successfully finished.
|
||||
// Here, we call clarStatus to get to the dfuIDLE state.
|
||||
//
|
||||
console.log("erase_page: dfuDNBUSY after timeout, clearing");
|
||||
console.log(
|
||||
`${this.logHead} erase_page: dfuDNBUSY after timeout, clearing`,
|
||||
);
|
||||
|
||||
this.clearStatus(() => {
|
||||
this.controlTransfer(
|
||||
|
@ -982,7 +991,9 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
erase_page_next();
|
||||
} else {
|
||||
console.log(
|
||||
`Failed to erase page 0x${page_addr.toString(
|
||||
`${
|
||||
this.logHead
|
||||
} Failed to erase page 0x${page_addr.toString(
|
||||
16,
|
||||
)} (did not reach dfuIDLE after clearing`,
|
||||
);
|
||||
|
@ -994,13 +1005,17 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
} else if (data[4] === this.state.dfuDNLOAD_IDLE) {
|
||||
erase_page_next();
|
||||
} else {
|
||||
console.log(`Failed to erase page 0x${page_addr.toString(16)}`);
|
||||
console.log(
|
||||
`${this.logHead} Failed to erase page 0x${page_addr.toString(16)}`,
|
||||
);
|
||||
this.cleanup();
|
||||
}
|
||||
});
|
||||
}, delay);
|
||||
} else {
|
||||
console.log(`Failed to initiate page erase, page 0x${page_addr.toString(16)}`);
|
||||
console.log(
|
||||
`${this.logHead} Failed to initiate page erase, page 0x${page_addr.toString(16)}`,
|
||||
);
|
||||
this.cleanup();
|
||||
}
|
||||
});
|
||||
|
@ -1014,7 +1029,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
case 4: {
|
||||
// upload
|
||||
// we dont need to clear the state as we are already using DFU_DNLOAD
|
||||
console.log("Writing data ...");
|
||||
console.log(`${this.logHead} Writing data ...`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32Flashing"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -1061,7 +1076,9 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
write();
|
||||
} else {
|
||||
console.log(
|
||||
`Failed to write ${bytes_to_write}bytes to 0x${address.toString(
|
||||
`${
|
||||
this.logHead
|
||||
} Failed to write ${bytes_to_write}bytes to 0x${address.toString(
|
||||
16,
|
||||
)}`,
|
||||
);
|
||||
|
@ -1071,7 +1088,9 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}, delay);
|
||||
} else {
|
||||
console.log(
|
||||
`Failed to initiate write ${bytes_to_write}bytes to 0x${address.toString(16)}`,
|
||||
`${
|
||||
this.logHead
|
||||
} Failed to initiate write ${bytes_to_write}bytes to 0x${address.toString(16)}`,
|
||||
);
|
||||
this.cleanup();
|
||||
}
|
||||
|
@ -1089,7 +1108,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
this.loadAddress(address, write);
|
||||
} else {
|
||||
// all blocks flashed
|
||||
console.log("Writing: done");
|
||||
console.log(`${this.logHead} Writing: done`);
|
||||
|
||||
// proceed to next step
|
||||
this.upload_procedure(5);
|
||||
|
@ -1104,7 +1123,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
case 5: {
|
||||
// verify
|
||||
console.log("Verifying data ...");
|
||||
console.log(`${this.logHead} Verifying data ...`);
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32Verifying"),
|
||||
TABS.firmware_flasher.FLASH_MESSAGE_TYPES.NEUTRAL,
|
||||
|
@ -1186,7 +1205,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
}
|
||||
|
||||
if (verify) {
|
||||
console.log("Programming: SUCCESSFUL");
|
||||
console.log(`${this.logHead} Programming: SUCCESSFUL`);
|
||||
// update progress bar
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32ProgrammingSuccessful"),
|
||||
|
@ -1204,7 +1223,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
// proceed to next step
|
||||
this.leave();
|
||||
} else {
|
||||
console.log("Programming: FAILED");
|
||||
console.log(`${this.logHead} Programming: FAILED`);
|
||||
// update progress bar
|
||||
TABS.firmware_flasher.flashingMessage(
|
||||
i18n.getMessage("stm32ProgrammingFailed"),
|
||||
|
@ -1251,7 +1270,7 @@ class WEBUSBDFU_protocol extends EventTarget {
|
|||
|
||||
const timeSpent = new Date().getTime() - this.upload_time_start;
|
||||
|
||||
console.log(`Script finished after: ${timeSpent / 1000} seconds`);
|
||||
console.log(`${this.logHead} Script finished after: ${timeSpent / 1000} seconds`);
|
||||
|
||||
if (this.callback) {
|
||||
this.callback();
|
||||
|
|
|
@ -27,6 +27,8 @@ import { serialShim } from "./serial_shim.js";
|
|||
import { EventBus } from "../components/eventBus";
|
||||
import { ispConnected } from "./utils/connection";
|
||||
|
||||
const logHead = "[SERIAL-BACKEND]";
|
||||
|
||||
let serial = serialShim();
|
||||
|
||||
let mspHelper;
|
||||
|
@ -109,7 +111,7 @@ function connectDisconnect() {
|
|||
return;
|
||||
}
|
||||
|
||||
console.log(`[SERIAL-BACKEND] Connecting to: ${portName}`);
|
||||
console.log(`${logHead} Connecting to: ${portName}`);
|
||||
GUI.connecting_to = portName;
|
||||
|
||||
// lock port select & baud while we are connecting / connected
|
||||
|
@ -297,7 +299,7 @@ function onOpen(openInfo) {
|
|||
mspHelper = new MspHelper();
|
||||
MSP.listen(mspHelper.process_data.bind(mspHelper));
|
||||
MSP.timeout = 250;
|
||||
console.log(`[SERIAL-BACKEND] Requesting configuration data`);
|
||||
console.log(`${logHead} Requesting configuration data`);
|
||||
|
||||
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () {
|
||||
gui_log(i18n.getMessage("apiVersionReceived", FC.CONFIG.apiVersion));
|
||||
|
@ -706,7 +708,7 @@ function onClosed(result) {
|
|||
$("#dataflash_wrapper_global").hide();
|
||||
$("#quad-status_wrapper").hide();
|
||||
|
||||
console.log("[SERIAL-BACKEND] Connection closed:", result);
|
||||
console.log(`${logHead} Connection closed:`, result);
|
||||
|
||||
resetConnection();
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ firmware_flasher.initialize = function (callback) {
|
|||
self.intel_hex = undefined;
|
||||
self.parsed_hex = undefined;
|
||||
|
||||
self.logHead = "[FIRMWARE_FLASHER]";
|
||||
|
||||
function onDocumentLoad() {
|
||||
function parseHex(str, callback) {
|
||||
read_hex_file(str).then((data) => {
|
||||
|
@ -386,7 +388,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
);
|
||||
if (self.parsed_hex && self.parsed_hex.bytes_total) {
|
||||
// Changing the board triggers a version change, so we need only dump it here.
|
||||
console.log("throw out loaded hex");
|
||||
console.log(`${self.logHead} throw out loaded hex`);
|
||||
self.intel_hex = undefined;
|
||||
self.parsed_hex = undefined;
|
||||
}
|
||||
|
@ -530,7 +532,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
|
||||
if (!GUI.connect_lock) {
|
||||
self.selectedBoard = target;
|
||||
console.log("board changed to", target);
|
||||
console.log(`${self.logHead} board changed to`, target);
|
||||
|
||||
self.flashingMessage(
|
||||
i18n.getMessage("firmwareFlasherLoadFirmwareFile"),
|
||||
|
@ -621,8 +623,8 @@ firmware_flasher.initialize = function (callback) {
|
|||
function detectedUsbDevice(device) {
|
||||
const isFlashOnConnect = $("input.flash_on_connect").is(":checked");
|
||||
|
||||
console.log("Detected USB device:", device);
|
||||
console.log("Reboot mode: %s, flash on connect", STM32.rebootMode, isFlashOnConnect);
|
||||
console.log(`${self.logHead} Detected USB device:`, device);
|
||||
console.log(`${self.logHead} Reboot mode: %s, flash on connect`, STM32.rebootMode, isFlashOnConnect);
|
||||
|
||||
if (STM32.rebootMode || isFlashOnConnect) {
|
||||
STM32.rebootMode = 0;
|
||||
|
@ -647,7 +649,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
const isSerial = port.startsWith("serial_");
|
||||
const isDFU = port.startsWith("usb_");
|
||||
|
||||
console.log("Selected port:", port);
|
||||
console.log(`${self.logHead} Selected port:`, port);
|
||||
|
||||
if (isDFU) {
|
||||
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, "DFU Flashing", {
|
||||
|
@ -671,7 +673,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
STM32.connect(port, baud, firmware, options);
|
||||
} else {
|
||||
// Maybe the board is in DFU mode, but it does not have permissions. Ask for them.
|
||||
console.log("No valid port detected, asking for permissions");
|
||||
console.log(`${self.logHead} No valid port detected, asking for permissions`);
|
||||
DFU.requestPermission().then((device) => {
|
||||
DFU.connect(device.path, firmware, options);
|
||||
});
|
||||
|
@ -770,7 +772,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
|
||||
FileSystem.pickOpenFile(i18n.getMessage("fileSystemPickerFiles", { typeof: "HEX" }), ".hex")
|
||||
.then((file) => {
|
||||
console.log("Saving firmware to:", file.name);
|
||||
console.log(`${self.logHead} Saving firmware to:`, file.name);
|
||||
FileSystem.readFile(file).then((data) => {
|
||||
if (file.name.split(".").pop() === "hex") {
|
||||
self.intel_hex = data;
|
||||
|
@ -1048,12 +1050,12 @@ firmware_flasher.initialize = function (callback) {
|
|||
// button disabled while flashing is in progress
|
||||
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, "ExitDfu", null);
|
||||
try {
|
||||
console.log("Closing DFU");
|
||||
console.log(`${self.logHead} Closing DFU`);
|
||||
DFU.requestPermission().then((device) => {
|
||||
DFU.connect(device.path, self.parsed_hex, { exitDfu: true });
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(`Exiting DFU failed: ${e.message}`);
|
||||
console.log(`${self.logHead} Exiting DFU failed: ${e.message}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1194,14 +1196,14 @@ firmware_flasher.initialize = function (callback) {
|
|||
if (configInserter.insertConfig(self.parsed_hex, self.config)) {
|
||||
self.parsed_hex.configInserted = true;
|
||||
} else {
|
||||
console.log("Firmware does not support custom defaults.");
|
||||
console.log(`${self.logHead} Firmware does not support custom defaults.`);
|
||||
clearBoardConfig();
|
||||
}
|
||||
}
|
||||
|
||||
flashFirmware(self.parsed_hex);
|
||||
} catch (e) {
|
||||
console.log(`Flashing failed: ${e.message}`);
|
||||
console.log(`${self.logHead} Flashing failed: ${e.message}`);
|
||||
}
|
||||
// Disable flash on connect after flashing to prevent continuous flashing
|
||||
$("input.flash_on_connect").prop("checked", false).change();
|
||||
|
@ -1221,7 +1223,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
".hex",
|
||||
)
|
||||
.then((file) => {
|
||||
console.log("Saving firmware to:", file.name);
|
||||
console.log(`${self.logHead} Saving firmware to:`, file.name);
|
||||
FileSystem.writeFile(file, self.intel_hex);
|
||||
|
||||
tracking.sendEvent(tracking.EVENT_CATEGORIES.FLASHING, "SaveFirmware");
|
||||
|
@ -1241,7 +1243,7 @@ firmware_flasher.initialize = function (callback) {
|
|||
}
|
||||
|
||||
self.buildApi.loadTargets(() => {
|
||||
console.log("Targets loaded");
|
||||
console.log(`${self.logHead} Targets loaded`);
|
||||
$("#content").load("./tabs/firmware_flasher.html", onDocumentLoad);
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue