Skip to content

Commit

Permalink
Use FQBN instead of Board for the monitor ID.
Browse files Browse the repository at this point in the history
Closes #1278

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Aug 3, 2022
1 parent d93c9ba commit 3cee66b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
fqbn: firmware.board_fqbn,
};
try {
await this.monitorManager.notifyUploadStarted(board, port);
await this.monitorManager.notifyUploadStarted(board.fqbn, port);
output = await this.runCommand([
'firmware',
'flash',
Expand All @@ -90,7 +90,7 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
} catch (e) {
throw e;
} finally {
await this.monitorManager.notifyUploadFinished(board, port);
await this.monitorManager.notifyUploadFinished(board.fqbn, port);
return output;
}
}
Expand Down
14 changes: 7 additions & 7 deletions arduino-ide-extension/src/node/core-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
UploadUsingProgrammerResponse,
} from './cli-protocol/cc/arduino/cli/commands/v1/upload_pb';
import { ResponseService } from '../common/protocol/response-service';
import { Board, OutputMessage, Port, Status } from '../common/protocol';
import { OutputMessage, Port, Status } from '../common/protocol';
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
import { Port as GrpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb';
import { ApplicationError, CommandService, Disposable, nls } from '@theia/core';
Expand Down Expand Up @@ -376,23 +376,23 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
}

private async notifyUploadWillStart({
board,
fqbn,
port,
}: {
board?: Board | undefined;
fqbn?: string | undefined;
port?: Port | undefined;
}): Promise<void> {
return this.monitorManager.notifyUploadStarted(board, port);
return this.monitorManager.notifyUploadStarted(fqbn, port);
}

private async notifyUploadDidFinish({
board,
fqbn,
port,
}: {
board?: Board | undefined;
fqbn?: string | undefined;
port?: Port | undefined;
}): Promise<Status> {
return this.monitorManager.notifyUploadFinished(board, port);
return this.monitorManager.notifyUploadFinished(fqbn, port);
}

private mergeSourceOverrides(
Expand Down
39 changes: 21 additions & 18 deletions arduino-ide-extension/src/node/monitor-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class MonitorManager extends CoreClientAware {
* combination specified, false in all other cases.
*/
isStarted(board: Board, port: Port): boolean {
const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(board.fqbn, port);
const monitor = this.monitorServices.get(monitorID);
if (monitor) {
return monitor.isStarted();
Expand Down Expand Up @@ -106,7 +106,7 @@ export class MonitorManager extends CoreClientAware {
port: Port,
connectToClient: (status: Status) => void
): Promise<void> {
const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(board.fqbn, port);

let monitor = this.monitorServices.get(monitorID);
if (!monitor) {
Expand Down Expand Up @@ -138,7 +138,7 @@ export class MonitorManager extends CoreClientAware {
* @param port port monitored
*/
async stopMonitor(board: Board, port: Port): Promise<void> {
const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(board.fqbn, port);
const monitor = this.monitorServices.get(monitorID);
if (!monitor) {
// There's no monitor to stop, bail
Expand All @@ -155,7 +155,7 @@ export class MonitorManager extends CoreClientAware {
* @returns port of the MonitorService's WebSocket
*/
getWebsocketAddressPort(board: Board, port: Port): number {
const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(board.fqbn, port);
const monitor = this.monitorServices.get(monitorID);
if (!monitor) {
return -1;
Expand All @@ -168,17 +168,17 @@ export class MonitorManager extends CoreClientAware {
* that an upload process started on that exact board/port combination.
* This must be done so that we can stop the monitor for the time being
* until the upload process finished.
* @param board board connected to port
* @param fqbn the FQBN of the board connected to port
* @param port port to monitor
*/
async notifyUploadStarted(board?: Board, port?: Port): Promise<void> {
if (!board || !port) {
async notifyUploadStarted(fqbn?: string, port?: Port): Promise<void> {
if (!fqbn || !port) {
// We have no way of knowing which monitor
// to retrieve if we don't have this information.
return;
}

const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(fqbn, port);
this.addToMonitorIDsByUploadState('uploadInProgress', monitorID);

const monitor = this.monitorServices.get(monitorID);
Expand All @@ -194,19 +194,22 @@ export class MonitorManager extends CoreClientAware {
/**
* Notifies the monitor service of that board/port combination
* that an upload process started on that exact board/port combination.
* @param board board connected to port
* @param fqbn board connected to port
* @param port port to monitor
* @returns a Status object to know if the process has been
* started or if there have been errors.
*/
async notifyUploadFinished(board?: Board, port?: Port): Promise<Status> {
async notifyUploadFinished(
fqbn?: string | undefined,
port?: Port
): Promise<Status> {
let status: Status = Status.NOT_CONNECTED;
let portDidChangeOnUpload = false;

// We have no way of knowing which monitor
// to retrieve if we don't have this information.
if (board && port) {
const monitorID = this.monitorID(board, port);
if (fqbn && port) {
const monitorID = this.monitorID(fqbn, port);
this.removeFromMonitorIDsByUploadState('uploadInProgress', monitorID);

const monitor = this.monitorServices.get(monitorID);
Expand Down Expand Up @@ -277,7 +280,7 @@ export class MonitorManager extends CoreClientAware {
port: Port,
settings: PluggableMonitorSettings
) {
const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(board.fqbn, port);
let monitor = this.monitorServices.get(monitorID);
if (!monitor) {
monitor = this.createMonitor(board, port);
Expand All @@ -296,7 +299,7 @@ export class MonitorManager extends CoreClientAware {
board: Board,
port: Port
): Promise<MonitorSettings> {
const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(board.fqbn, port);
const monitor = this.monitorServices.get(monitorID);
if (!monitor) {
return {};
Expand All @@ -312,7 +315,7 @@ export class MonitorManager extends CoreClientAware {
* @returns a new instance of MonitorService ready to use.
*/
private createMonitor(board: Board, port: Port): MonitorService {
const monitorID = this.monitorID(board, port);
const monitorID = this.monitorID(board.fqbn, port);
const monitor = this.monitorServiceFactory({
board,
port,
Expand Down Expand Up @@ -341,12 +344,12 @@ export class MonitorManager extends CoreClientAware {

/**
* Utility function to create a unique ID for a monitor service.
* @param board
* @param fqbn
* @param port
* @returns a unique monitor ID
*/
private monitorID(board: Board, port: Port): MonitorID {
const splitFqbn = board?.fqbn?.split(':') || [];
private monitorID(fqbn: string | undefined, port: Port): MonitorID {
const splitFqbn = fqbn?.split(':') || [];
const shortenedFqbn = splitFqbn.slice(0, 3).join(':') || '';
return `${shortenedFqbn}-${port.address}-${port.protocol}`;
}
Expand Down

0 comments on commit 3cee66b

Please sign in to comment.