Skip to content

Commit

Permalink
Remove flashing progress
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 17, 2024
1 parent c4a4abc commit a1f1e28
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
25 changes: 20 additions & 5 deletions src/cmd/device-protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {

const localBootloaderPath = await this._downloadBootloader();

await this._flashBootloader(localBootloaderPath);
await this._flashBootloader(localBootloaderPath, 'disable');

this.ui.stdout.write(os.EOL);

Expand Down Expand Up @@ -197,7 +197,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {

const resPath = await this.protectBinary(localBootloaderPath);

await this._flashBootloader(resPath);
await this._flashBootloader(resPath, 'enable');

const success = await this._markAsDevelopmentDevice(false);

Expand All @@ -210,9 +210,24 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
});
}

async _flashBootloader(path) {
const flashCmdInstance = new FlashCommand( { ui: undefined } );
await flashCmdInstance.flashLocal({ files: [path], applicationOnly: true });
async _flashBootloader(path, action) {
let msg;
switch (action) {
case 'enable':
msg = 'Enabling protection on the device. Please wait...';
break;
case 'disable':
msg = 'Disabling protection on the device. Please wait...';
break;
default:
throw new Error('Invalid action');
}

const flashCmdInstance = new FlashCommand();

const flashPromise = flashCmdInstance.flashLocal({ files: [path], applicationOnly: true, verbose: false });

await this.ui.showBusySpinnerUntilResolved(msg, flashPromise);
}

async _markAsDevelopmentDevice(state) {
Expand Down
8 changes: 5 additions & 3 deletions src/cmd/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module.exports = class FlashCommand extends CLICommandBase {
return new SerialCommands().flashDevice(binary, { port, yes });
}

async flashLocal({ files, applicationOnly, target }) {
async flashLocal({ files, applicationOnly, target, verbose=true }) {
const { files: parsedFiles, deviceIdOrName, knownApp } = await this._analyzeFiles(files);
const { api, auth } = this._particleApi();
const device = await usbUtils.getOneUsbDevice({ idOrName: deviceIdOrName, api, auth, ui: this.ui });
Expand All @@ -124,7 +124,9 @@ module.exports = class FlashCommand extends CLICommandBase {
const platformName = platformForId(platformId).name;
const currentDeviceOsVersion = device.firmwareVersion;

this.ui.write(`Flashing ${platformName} ${deviceIdOrName || device.id}`);
if (verbose) {
this.ui.write(`Flashing ${platformName} ${deviceIdOrName || device.id}`);
}

validateDFUSupport({ device, ui: this.ui });

Expand Down Expand Up @@ -160,7 +162,7 @@ module.exports = class FlashCommand extends CLICommandBase {
platformId
});

await flashFiles({ device, flashSteps, ui: this.ui });
await flashFiles({ device, flashSteps, ui: this.ui, verbose });
}

async _analyzeFiles(files) {
Expand Down
10 changes: 7 additions & 3 deletions src/lib/flash-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const ensureError = utilities.ensureError;
// Flashing an NCP firmware can take a few minutes
const FLASH_TIMEOUT = 4 * 60000;

async function flashFiles({ device, flashSteps, resetAfterFlash = true, ui }) {
const progress = _createFlashProgress({ flashSteps, ui });
async function flashFiles({ device, flashSteps, resetAfterFlash = true, ui, verbose=true }) {
let progress = null;
progress = verbose ? _createFlashProgress({ flashSteps, ui, verbose }) : null;
let success = false;
let lastStepDfu = false;
try {
Expand All @@ -35,7 +36,9 @@ async function flashFiles({ device, flashSteps, resetAfterFlash = true, ui }) {
}
success = true;
} finally {
progress({ event: 'finish', success });
if (progress) {
progress({ event: 'finish', success });
}
if (device.isOpen) {
// only reset the device if the last step was in DFU mode
if (resetAfterFlash && lastStepDfu) {
Expand Down Expand Up @@ -135,6 +138,7 @@ async function _flashDeviceInDfuMode(device, data, { name, altSetting, startAddr
}

function _createFlashProgress({ flashSteps, ui }) {
console.log('verbose: ' , verbose);
const NORMAL_MULTIPLIER = 10; // flashing in normal mode is slower so count each byte more
const { isInteractive } = ui;
let progressBar;
Expand Down

0 comments on commit a1f1e28

Please sign in to comment.