mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-05-05 12:38:41 +00:00

* 1032 failing upload flag for monitor mgr * move upload failure fix logic to frontend * misc corrections * avoid starting monitor when upload is in progress * avoid starting monitor when upload is in progress * prevent monitor side effects on upload (WIP) * send upload req after notifying mgr * dispose instead of pause on upld (code not final) * Revert "dispose instead of pause on upld (code not final)" This reverts commit 2d5dff2a2d85754467470b5973b7ecac8017aa58. * force wait before upload (test) * always start queued services after uplaod finishes * test cli with monitor close delay * clean up unnecessary await(s) * remove unused dependency * revert CLI to 0.23 * use master cli for testing, await in upload finish * remove upload port from pending monitor requests * fix startQueuedServices * refinements queued monitors * clean up monitor mgr state * fix typo from prev cleanup * avoid dupl queued monitor services * variable name changes * reference latest cli commit in package.json Co-authored-by: Alberto Iannaccone <a.iannaccone@arduino.cc>
98 lines
2.6 KiB
TypeScript
98 lines
2.6 KiB
TypeScript
import {
|
|
ArduinoFirmwareUploader,
|
|
FirmwareInfo,
|
|
} from '../common/protocol/arduino-firmware-uploader';
|
|
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
import { ExecutableService, Port } from '../common/protocol';
|
|
import { getExecPath, spawnCommand } from './exec-util';
|
|
import { ILogger } from '@theia/core/lib/common/logger';
|
|
import { MonitorManager } from './monitor-manager';
|
|
|
|
@injectable()
|
|
export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
|
|
@inject(ExecutableService)
|
|
protected executableService: ExecutableService;
|
|
|
|
protected _execPath: string | undefined;
|
|
|
|
@inject(ILogger)
|
|
@named('fwuploader')
|
|
protected readonly logger: ILogger;
|
|
|
|
@inject(MonitorManager)
|
|
protected readonly monitorManager: MonitorManager;
|
|
|
|
protected onError(error: any): void {
|
|
this.logger.error(error);
|
|
}
|
|
|
|
async getExecPath(): Promise<string> {
|
|
if (this._execPath) {
|
|
return this._execPath;
|
|
}
|
|
this._execPath = await getExecPath('arduino-fwuploader');
|
|
return this._execPath;
|
|
}
|
|
|
|
async runCommand(args: string[]): Promise<any> {
|
|
const execPath = await this.getExecPath();
|
|
return await spawnCommand(`"${execPath}"`, args, this.onError.bind(this));
|
|
}
|
|
|
|
async uploadCertificates(command: string): Promise<any> {
|
|
return await this.runCommand(['certificates', 'flash', command]);
|
|
}
|
|
|
|
async list(fqbn?: string): Promise<FirmwareInfo[]> {
|
|
const fqbnFlag = fqbn ? ['--fqbn', fqbn] : [];
|
|
const firmwares: FirmwareInfo[] =
|
|
JSON.parse(
|
|
await this.runCommand([
|
|
'firmware',
|
|
'list',
|
|
...fqbnFlag,
|
|
'--format',
|
|
'json',
|
|
])
|
|
) || [];
|
|
return firmwares.reverse();
|
|
}
|
|
|
|
async updatableBoards(): Promise<string[]> {
|
|
return (await this.list()).reduce(
|
|
(a, b) => (a.includes(b.board_fqbn) ? a : [...a, b.board_fqbn]),
|
|
[] as string[]
|
|
);
|
|
}
|
|
|
|
async availableFirmwares(fqbn: string): Promise<FirmwareInfo[]> {
|
|
return await this.list(fqbn);
|
|
}
|
|
|
|
async flash(firmware: FirmwareInfo, port: Port): Promise<string> {
|
|
let output;
|
|
const board = {
|
|
name: firmware.board_name,
|
|
fqbn: firmware.board_fqbn,
|
|
};
|
|
try {
|
|
await this.monitorManager.notifyUploadStarted(board, port);
|
|
output = await this.runCommand([
|
|
'firmware',
|
|
'flash',
|
|
'--fqbn',
|
|
firmware.board_fqbn,
|
|
'--address',
|
|
port.address,
|
|
'--module',
|
|
`${firmware.module}@${firmware.firmware_version}`,
|
|
]);
|
|
} catch (e) {
|
|
throw e;
|
|
} finally {
|
|
await this.monitorManager.notifyUploadFinished(board, port);
|
|
return output;
|
|
}
|
|
}
|
|
}
|