Skip to content

Commit d556ee9

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
Use FQBN instead of Board for the monitor ID.
Closes #1278 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent d93c9ba commit d556ee9

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
7676
fqbn: firmware.board_fqbn,
7777
};
7878
try {
79-
await this.monitorManager.notifyUploadStarted(board, port);
79+
await this.monitorManager.notifyUploadStarted(board.fqbn, port);
8080
output = await this.runCommand([
8181
'firmware',
8282
'flash',
@@ -90,7 +90,7 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
9090
} catch (e) {
9191
throw e;
9292
} finally {
93-
await this.monitorManager.notifyUploadFinished(board, port);
93+
await this.monitorManager.notifyUploadFinished(board.fqbn, port);
9494
return output;
9595
}
9696
}

arduino-ide-extension/src/node/core-service-impl.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
UploadUsingProgrammerResponse,
2424
} from './cli-protocol/cc/arduino/cli/commands/v1/upload_pb';
2525
import { ResponseService } from '../common/protocol/response-service';
26-
import { Board, OutputMessage, Port, Status } from '../common/protocol';
26+
import { OutputMessage, Port, Status } from '../common/protocol';
2727
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
2828
import { Port as GrpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb';
2929
import { ApplicationError, CommandService, Disposable, nls } from '@theia/core';
@@ -376,23 +376,23 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
376376
}
377377

378378
private async notifyUploadWillStart({
379-
board,
379+
fqbn,
380380
port,
381381
}: {
382-
board?: Board | undefined;
382+
fqbn?: string | undefined;
383383
port?: Port | undefined;
384384
}): Promise<void> {
385-
return this.monitorManager.notifyUploadStarted(board, port);
385+
return this.monitorManager.notifyUploadStarted(fqbn, port);
386386
}
387387

388388
private async notifyUploadDidFinish({
389-
board,
389+
fqbn,
390390
port,
391391
}: {
392-
board?: Board | undefined;
392+
fqbn?: string | undefined;
393393
port?: Port | undefined;
394394
}): Promise<Status> {
395-
return this.monitorManager.notifyUploadFinished(board, port);
395+
return this.monitorManager.notifyUploadFinished(fqbn, port);
396396
}
397397

398398
private mergeSourceOverrides(

arduino-ide-extension/src/node/monitor-manager.ts

+21-18
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class MonitorManager extends CoreClientAware {
5858
* combination specified, false in all other cases.
5959
*/
6060
isStarted(board: Board, port: Port): boolean {
61-
const monitorID = this.monitorID(board, port);
61+
const monitorID = this.monitorID(board.fqbn, port);
6262
const monitor = this.monitorServices.get(monitorID);
6363
if (monitor) {
6464
return monitor.isStarted();
@@ -106,7 +106,7 @@ export class MonitorManager extends CoreClientAware {
106106
port: Port,
107107
connectToClient: (status: Status) => void
108108
): Promise<void> {
109-
const monitorID = this.monitorID(board, port);
109+
const monitorID = this.monitorID(board.fqbn, port);
110110

111111
let monitor = this.monitorServices.get(monitorID);
112112
if (!monitor) {
@@ -138,7 +138,7 @@ export class MonitorManager extends CoreClientAware {
138138
* @param port port monitored
139139
*/
140140
async stopMonitor(board: Board, port: Port): Promise<void> {
141-
const monitorID = this.monitorID(board, port);
141+
const monitorID = this.monitorID(board.fqbn, port);
142142
const monitor = this.monitorServices.get(monitorID);
143143
if (!monitor) {
144144
// There's no monitor to stop, bail
@@ -155,7 +155,7 @@ export class MonitorManager extends CoreClientAware {
155155
* @returns port of the MonitorService's WebSocket
156156
*/
157157
getWebsocketAddressPort(board: Board, port: Port): number {
158-
const monitorID = this.monitorID(board, port);
158+
const monitorID = this.monitorID(board.fqbn, port);
159159
const monitor = this.monitorServices.get(monitorID);
160160
if (!monitor) {
161161
return -1;
@@ -168,17 +168,17 @@ export class MonitorManager extends CoreClientAware {
168168
* that an upload process started on that exact board/port combination.
169169
* This must be done so that we can stop the monitor for the time being
170170
* until the upload process finished.
171-
* @param board board connected to port
171+
* @param fqbn the FQBN of the board connected to port
172172
* @param port port to monitor
173173
*/
174-
async notifyUploadStarted(board?: Board, port?: Port): Promise<void> {
175-
if (!board || !port) {
174+
async notifyUploadStarted(fqbn?: string, port?: Port): Promise<void> {
175+
if (!fqbn || !port) {
176176
// We have no way of knowing which monitor
177177
// to retrieve if we don't have this information.
178178
return;
179179
}
180180

181-
const monitorID = this.monitorID(board, port);
181+
const monitorID = this.monitorID(fqbn, port);
182182
this.addToMonitorIDsByUploadState('uploadInProgress', monitorID);
183183

184184
const monitor = this.monitorServices.get(monitorID);
@@ -194,19 +194,22 @@ export class MonitorManager extends CoreClientAware {
194194
/**
195195
* Notifies the monitor service of that board/port combination
196196
* that an upload process started on that exact board/port combination.
197-
* @param board board connected to port
197+
* @param fqbn the FQBN of the board connected to port
198198
* @param port port to monitor
199199
* @returns a Status object to know if the process has been
200200
* started or if there have been errors.
201201
*/
202-
async notifyUploadFinished(board?: Board, port?: Port): Promise<Status> {
202+
async notifyUploadFinished(
203+
fqbn?: string | undefined,
204+
port?: Port
205+
): Promise<Status> {
203206
let status: Status = Status.NOT_CONNECTED;
204207
let portDidChangeOnUpload = false;
205208

206209
// We have no way of knowing which monitor
207210
// to retrieve if we don't have this information.
208-
if (board && port) {
209-
const monitorID = this.monitorID(board, port);
211+
if (fqbn && port) {
212+
const monitorID = this.monitorID(fqbn, port);
210213
this.removeFromMonitorIDsByUploadState('uploadInProgress', monitorID);
211214

212215
const monitor = this.monitorServices.get(monitorID);
@@ -277,7 +280,7 @@ export class MonitorManager extends CoreClientAware {
277280
port: Port,
278281
settings: PluggableMonitorSettings
279282
) {
280-
const monitorID = this.monitorID(board, port);
283+
const monitorID = this.monitorID(board.fqbn, port);
281284
let monitor = this.monitorServices.get(monitorID);
282285
if (!monitor) {
283286
monitor = this.createMonitor(board, port);
@@ -296,7 +299,7 @@ export class MonitorManager extends CoreClientAware {
296299
board: Board,
297300
port: Port
298301
): Promise<MonitorSettings> {
299-
const monitorID = this.monitorID(board, port);
302+
const monitorID = this.monitorID(board.fqbn, port);
300303
const monitor = this.monitorServices.get(monitorID);
301304
if (!monitor) {
302305
return {};
@@ -312,7 +315,7 @@ export class MonitorManager extends CoreClientAware {
312315
* @returns a new instance of MonitorService ready to use.
313316
*/
314317
private createMonitor(board: Board, port: Port): MonitorService {
315-
const monitorID = this.monitorID(board, port);
318+
const monitorID = this.monitorID(board.fqbn, port);
316319
const monitor = this.monitorServiceFactory({
317320
board,
318321
port,
@@ -341,12 +344,12 @@ export class MonitorManager extends CoreClientAware {
341344

342345
/**
343346
* Utility function to create a unique ID for a monitor service.
344-
* @param board
347+
* @param fqbn
345348
* @param port
346349
* @returns a unique monitor ID
347350
*/
348-
private monitorID(board: Board, port: Port): MonitorID {
349-
const splitFqbn = board?.fqbn?.split(':') || [];
351+
private monitorID(fqbn: string | undefined, port: Port): MonitorID {
352+
const splitFqbn = fqbn?.split(':') || [];
350353
const shortenedFqbn = splitFqbn.slice(0, 3).join(':') || '';
351354
return `${shortenedFqbn}-${port.address}-${port.protocol}`;
352355
}

0 commit comments

Comments
 (0)