Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 34d6a27

Browse files
author
Akos Kitta
committedAug 24, 2022
Use port properties from the discovery.
Signed-off-by: Akos Kitta <[email protected]> Closes #740 Signed-off-by: Akos Kitta <[email protected]>
1 parent ca47e8a commit 34d6a27

File tree

14 files changed

+235
-193
lines changed

14 files changed

+235
-193
lines changed
 

‎arduino-ide-extension/src/browser/boards/boards-config.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export class BoardsConfig extends React.Component<
354354
<div className="ports list">
355355
{ports.map((port) => (
356356
<Item<Port>
357-
key={`${port.id}`}
357+
key={`${Port.keyOf(port)}`}
358358
item={port}
359359
label={Port.toString(port)}
360360
selected={Port.sameAs(this.state.selectedPort, port)}

‎arduino-ide-extension/src/browser/boards/boards-service-provider.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
AttachedBoardsChangeEvent,
1414
BoardWithPackage,
1515
BoardUserField,
16+
AvailablePorts,
1617
} from '../../common/protocol';
1718
import { BoardsConfig } from './boards-config';
1819
import { naturalCompare } from '../../common/utils';
@@ -21,6 +22,7 @@ import { StorageWrapper } from '../storage-wrapper';
2122
import { nls } from '@theia/core/lib/common';
2223
import { Deferred } from '@theia/core/lib/common/promise-util';
2324
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
25+
import { Unknown } from '../../common/nls';
2426

2527
@injectable()
2628
export class BoardsServiceProvider implements FrontendApplicationContribution {
@@ -92,11 +94,12 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
9294
);
9395

9496
this.appStateService.reachedState('ready').then(async () => {
95-
const [attachedBoards, availablePorts] = await Promise.all([
96-
this.boardsService.getAttachedBoards(),
97-
this.boardsService.getAvailablePorts(),
97+
const [state] = await Promise.all([
98+
this.boardsService.getState(),
9899
this.loadState(),
99100
]);
101+
const { boards: attachedBoards, ports: availablePorts } =
102+
AvailablePorts.split(state);
100103
this._attachedBoards = attachedBoards;
101104
this._availablePorts = availablePorts;
102105
this.onAvailablePortsChangedEmitter.fire(this._availablePorts);
@@ -473,7 +476,7 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
473476
};
474477
} else {
475478
availableBoard = {
476-
name: nls.localize('arduino/common/unknown', 'Unknown'),
479+
name: Unknown,
477480
port: boardPort,
478481
state: AvailableBoard.State.incomplete,
479482
};

‎arduino-ide-extension/src/browser/contributions/board-selection.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ PID: ${PID}`;
331331
}
332332
};
333333

334-
const grouped = AvailablePorts.byProtocol(availablePorts);
334+
const grouped = AvailablePorts.groupByProtocol(availablePorts);
335335
let protocolOrder = 100;
336336
// We first show serial and network ports, then all the rest
337337
['serial', 'network'].forEach((protocol) => {

‎arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ export class MonitorManagerProxyClientImpl
145145
if (
146146
selectedBoard?.fqbn !==
147147
this.lastConnectedBoard?.selectedBoard?.fqbn ||
148-
selectedPort?.id !== this.lastConnectedBoard?.selectedPort?.id
148+
Port.keyOf(selectedPort) !==
149+
(this.lastConnectedBoard.selectedPort
150+
? Port.keyOf(this.lastConnectedBoard.selectedPort)
151+
: undefined)
149152
) {
150153
this.onMonitorShouldResetEmitter.fire(null);
151154
this.lastConnectedBoard = {

‎arduino-ide-extension/src/browser/serial/monitor/serial-monitor-send-input.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isOSX } from '@theia/core/lib/common/os';
55
import { DisposableCollection, nls } from '@theia/core/lib/common';
66
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
77
import { MonitorModel } from '../../monitor-model';
8+
import { Unknown } from '../../../common/nls';
89

910
export namespace SerialMonitorSendInput {
1011
export interface Props {
@@ -86,8 +87,8 @@ export class SerialMonitorSendInput extends React.Component<
8687
? Board.toString(board, {
8788
useFqbn: false,
8889
})
89-
: 'unknown',
90-
port ? port.address : 'unknown'
90+
: Unknown,
91+
port ? port.address : Unknown
9192
);
9293
}
9394

‎arduino-ide-extension/src/browser/widgets/component-list/list-item-renderer.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Installable } from '../../../common/protocol/installable';
55
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
66
import { ComponentListItem } from './component-list-item';
77
import { nls } from '@theia/core/lib/common';
8+
import { Unknown } from '../../../common/nls';
89

910
@injectable()
1011
export class ListItemRenderer<T extends ArduinoComponent> {
@@ -42,11 +43,7 @@ export class ListItemRenderer<T extends ArduinoComponent> {
4243
} else if ((item as any).id) {
4344
nameAndAuthor = <span className="name">{(item as any).id}</span>;
4445
} else {
45-
nameAndAuthor = (
46-
<span className="name">
47-
{nls.localize('arduino/common/unknown', 'Unknown')}
48-
</span>
49-
);
46+
nameAndAuthor = <span className="name">{Unknown}</span>;
5047
}
5148
const onClickUninstall = () => uninstall(item);
5249
const installedVersion = !!item.installedVersion && (
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { nls } from '@theia/core/lib/common/nls';
2+
3+
export const Unknown = nls.localize('arduino/common/unknown', 'Unknown');

‎arduino-ide-extension/src/common/protocol/boards-service.ts

+57-25
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ArduinoComponent } from './arduino-component';
55

66
export type AvailablePorts = Record<string, [Port, Array<Board>]>;
77
export namespace AvailablePorts {
8-
export function byProtocol(
8+
export function groupByProtocol(
99
availablePorts: AvailablePorts
1010
): Map<string, AvailablePorts> {
1111
const grouped = new Map<string, AvailablePorts>();
@@ -20,6 +20,21 @@ export namespace AvailablePorts {
2020
}
2121
return grouped;
2222
}
23+
export function split(
24+
state: AvailablePorts
25+
): Readonly<{ boards: Board[]; ports: Port[] }> {
26+
const availablePorts: Port[] = [];
27+
const attachedBoards: Board[] = [];
28+
for (const key of Object.keys(state)) {
29+
const [port, boards] = state[key];
30+
availablePorts.push(port);
31+
attachedBoards.push(...boards);
32+
}
33+
return {
34+
boards: attachedBoards,
35+
ports: availablePorts,
36+
};
37+
}
2338
}
2439

2540
export interface AttachedBoardsChangeEvent {
@@ -116,16 +131,6 @@ export const BoardsService = Symbol('BoardsService');
116131
export interface BoardsService
117132
extends Installable<BoardsPackage>,
118133
Searchable<BoardsPackage> {
119-
/**
120-
* Deprecated. `getState` should be used to correctly map a board with a port.
121-
* @deprecated
122-
*/
123-
getAttachedBoards(): Promise<Board[]>;
124-
/**
125-
* Deprecated. `getState` should be used to correctly map a board with a port.
126-
* @deprecated
127-
*/
128-
getAvailablePorts(): Promise<Port[]>;
129134
getState(): Promise<AvailablePorts>;
130135
getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined>;
131136
getBoardPackage(options: { id: string }): Promise<BoardsPackage | undefined>;
@@ -140,28 +145,55 @@ export interface BoardsService
140145
}
141146

142147
export interface Port {
143-
// id is the combination of address and protocol
144-
// formatted like "<address>|<protocol>" used
145-
// to uniquely recognize a port
146-
readonly id: string;
147148
readonly address: string;
148149
readonly addressLabel: string;
149150
readonly protocol: string;
150151
readonly protocolLabel: string;
152+
readonly properties?: Record<string, string>;
151153
}
152154
export namespace Port {
153-
export function is(arg: any): arg is Port {
154-
return (
155-
!!arg &&
156-
'address' in arg &&
157-
typeof arg['address'] === 'string' &&
158-
'protocol' in arg &&
159-
typeof arg['protocol'] === 'string'
160-
);
155+
export type Properties = Record<string, string>;
156+
export namespace Properties {
157+
export function create(
158+
properties: [string, string][] | undefined
159+
): Properties {
160+
if (!properties) {
161+
return {};
162+
}
163+
return properties.reduce((acc, curr) => {
164+
const [key, value] = curr;
165+
acc[key] = value;
166+
return acc;
167+
}, {} as Record<string, string>);
168+
}
169+
}
170+
export function is(arg: unknown): arg is Port {
171+
if (typeof arg === 'object') {
172+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
173+
const object = arg as any;
174+
return (
175+
'address' in object &&
176+
typeof object['address'] === 'string' &&
177+
'addressLabel' in object &&
178+
typeof object['addressLabel'] === 'string' &&
179+
'protocol' in object &&
180+
typeof object['protocol'] === 'string' &&
181+
'protocolLabel' in object &&
182+
typeof object['protocolLabel'] === 'string'
183+
);
184+
}
185+
return false;
186+
}
187+
188+
/**
189+
* Key is the combination of address and protocol formatted like `'${address}|${protocol}'` used to uniquely identify a port.
190+
*/
191+
export function keyOf({ address, protocol }: Port): string {
192+
return `${address}|${protocol}`;
161193
}
162194

163-
export function toString(port: Port): string {
164-
return `${port.addressLabel} ${port.protocolLabel}`;
195+
export function toString({ addressLabel, protocolLabel }: Port): string {
196+
return `${addressLabel} ${protocolLabel}`;
165197
}
166198

167199
export function compare(left: Port, right: Port): number {

‎arduino-ide-extension/src/node/auth/utils.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { sha256 } from 'hash.js';
33
import { randomBytes } from 'crypto';
44
import btoa = require('btoa'); // TODO: check why we cannot
55
import { AuthenticationSession } from './types';
6+
import { Unknown } from '../../common/nls';
67

78
export interface IToken {
89
accessToken: string; // When unable to refresh due to network problems, the access token becomes undefined
@@ -62,10 +63,10 @@ export function token2IToken(token: Token): IToken {
6263
sessionId: parsedIdToken.sub,
6364
scope: token.scope,
6465
account: {
65-
id: parsedIdToken.sub || 'unknown',
66-
email: parsedIdToken.email || 'unknown',
67-
nickname: parsedIdToken.nickname || 'unknown',
68-
picture: parsedIdToken.picture || 'unknown',
66+
id: parsedIdToken.sub || Unknown,
67+
email: parsedIdToken.email || Unknown,
68+
nickname: parsedIdToken.nickname || Unknown,
69+
picture: parsedIdToken.picture || Unknown,
6970
},
7071
};
7172
}

‎arduino-ide-extension/src/node/board-discovery.ts

+134-124
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
import { injectable, inject, named } from '@theia/core/shared/inversify';
21
import { ClientDuplexStream } from '@grpc/grpc-js';
2+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
3+
import { Emitter, Event } from '@theia/core/lib/common/event';
34
import { ILogger } from '@theia/core/lib/common/logger';
45
import { deepClone } from '@theia/core/lib/common/objects';
5-
import { CoreClientAware } from './core-client-provider';
6-
import {
7-
BoardListWatchRequest,
8-
BoardListWatchResponse,
9-
} from './cli-protocol/cc/arduino/cli/commands/v1/board_pb';
6+
import { Deferred } from '@theia/core/lib/common/promise-util';
7+
import { BackendApplicationContribution } from '@theia/core/lib/node';
8+
import { inject, injectable, named } from '@theia/core/shared/inversify';
9+
import { Disposable } from '@theia/core/shared/vscode-languageserver-protocol';
10+
import { v4 } from 'uuid';
11+
import { Unknown } from '../common/nls';
1012
import {
13+
AttachedBoardsChangeEvent,
14+
AvailablePorts,
1115
Board,
12-
Port,
1316
NotificationServiceServer,
14-
AvailablePorts,
15-
AttachedBoardsChangeEvent,
17+
Port,
1618
} from '../common/protocol';
17-
import { Emitter, Event } from '@theia/core/lib/common/event';
18-
import { DisposableCollection } from '@theia/core/lib/common/disposable';
19-
import { Disposable } from '@theia/core/shared/vscode-languageserver-protocol';
19+
import {
20+
BoardListWatchRequest,
21+
BoardListWatchResponse,
22+
DetectedPort as RpcDetectedPort,
23+
} from './cli-protocol/cc/arduino/cli/commands/v1/board_pb';
2024
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
21-
import { v4 } from 'uuid';
25+
import { Port as RpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb';
26+
import { CoreClientAware } from './core-client-provider';
2227
import { ServiceError } from './service-error';
23-
import { BackendApplicationContribution } from '@theia/core/lib/node';
24-
import { Deferred } from '@theia/core/lib/common/promise-util';
2528

2629
type Duplex = ClientDuplexStream<BoardListWatchRequest, BoardListWatchResponse>;
2730
interface StreamWrapper extends Disposable {
@@ -210,7 +213,7 @@ export class BoardDiscovery
210213
} else {
211214
throw new Error(`Unhandled object type: ${arg}`);
212215
}
213-
return JSON.stringify(object);
216+
return JSON.stringify(object, null, 2); // TODO: remove `space`?
214217
}
215218

216219
async start(): Promise<void> {
@@ -228,102 +231,7 @@ export class BoardDiscovery
228231
this.logger.info('start new deferred');
229232
const { client, instance } = await this.coreClient;
230233
const wrapper = await this.createWrapper(client);
231-
wrapper.stream.on('data', async (resp: BoardListWatchResponse) => {
232-
this.logger.info('onData', this.toJson(resp));
233-
if (resp.getEventType() === 'quit') {
234-
this.logger.info('quit received');
235-
this.stop();
236-
return;
237-
}
238-
239-
const detectedPort = resp.getPort();
240-
if (detectedPort) {
241-
let eventType: 'add' | 'remove' | 'unknown' = 'unknown';
242-
if (resp.getEventType() === 'add') {
243-
eventType = 'add';
244-
} else if (resp.getEventType() === 'remove') {
245-
eventType = 'remove';
246-
} else {
247-
eventType = 'unknown';
248-
}
249-
250-
if (eventType === 'unknown') {
251-
throw new Error(`Unexpected event type: '${resp.getEventType()}'`);
252-
}
253-
254-
const oldState = deepClone(this._availablePorts);
255-
const newState = deepClone(this._availablePorts);
256-
257-
const address = (detectedPort as any).getPort().getAddress();
258-
const protocol = (detectedPort as any).getPort().getProtocol();
259-
// Different discoveries can detect the same port with different
260-
// protocols, so we consider the combination of address and protocol
261-
// to be the id of a certain port to distinguish it from others.
262-
// If we'd use only the address of a port to store it in a map
263-
// we can have conflicts the same port is found with multiple
264-
// protocols.
265-
const portID = `${address}|${protocol}`;
266-
const label = (detectedPort as any).getPort().getLabel();
267-
const protocolLabel = (detectedPort as any)
268-
.getPort()
269-
.getProtocolLabel();
270-
const port = {
271-
id: portID,
272-
address,
273-
addressLabel: label,
274-
protocol,
275-
protocolLabel,
276-
};
277-
const boards: Board[] = [];
278-
for (const item of detectedPort.getMatchingBoardsList()) {
279-
boards.push({
280-
fqbn: item.getFqbn(),
281-
name: item.getName() || 'unknown',
282-
port,
283-
});
284-
}
285-
286-
if (eventType === 'add') {
287-
if (newState[portID]) {
288-
const [, knownBoards] = newState[portID];
289-
this.logger.warn(
290-
`Port '${Port.toString(
291-
port
292-
)}' was already available. Known boards before override: ${JSON.stringify(
293-
knownBoards
294-
)}`
295-
);
296-
}
297-
newState[portID] = [port, boards];
298-
} else if (eventType === 'remove') {
299-
if (!newState[portID]) {
300-
this.logger.warn(
301-
`Port '${Port.toString(port)}' was not available. Skipping`
302-
);
303-
return;
304-
}
305-
delete newState[portID];
306-
}
307-
308-
const oldAvailablePorts = this.getAvailablePorts(oldState);
309-
const oldAttachedBoards = this.getAttachedBoards(oldState);
310-
const newAvailablePorts = this.getAvailablePorts(newState);
311-
const newAttachedBoards = this.getAttachedBoards(newState);
312-
const event: AttachedBoardsChangeEvent = {
313-
oldState: {
314-
ports: oldAvailablePorts,
315-
boards: oldAttachedBoards,
316-
},
317-
newState: {
318-
ports: newAvailablePorts,
319-
boards: newAttachedBoards,
320-
},
321-
};
322-
323-
this._availablePorts = newState;
324-
this.notificationService.notifyAttachedBoardsDidChange(event);
325-
}
326-
});
234+
wrapper.stream.on('data', (resp) => this.onBoardListWatchResponse(resp));
327235
this.logger.info('start request start watch');
328236
await this.requestStartWatch(
329237
new BoardListWatchRequest().setInstance(instance),
@@ -334,21 +242,123 @@ export class BoardDiscovery
334242
this.logger.info('start resolved watching');
335243
}
336244

337-
getAttachedBoards(state: AvailablePorts = this.availablePorts): Board[] {
338-
const attachedBoards: Board[] = [];
339-
for (const portID of Object.keys(state)) {
340-
const [, boards] = state[portID];
341-
attachedBoards.push(...boards);
245+
// XXX: make this `protected` and override for tests if IDE2 wants to mock events from the CLI.
246+
private onBoardListWatchResponse(resp: BoardListWatchResponse): void {
247+
this.logger.info(this.toJson(resp));
248+
const eventType = EventType.parse(resp.getEventType());
249+
250+
if (eventType === EventType.Quit) {
251+
this.logger.info('quit received');
252+
this.stop();
253+
return;
342254
}
343-
return attachedBoards;
255+
256+
const detectedPort = resp.getPort();
257+
if (detectedPort) {
258+
const { port, boards } = this.fromRpc(detectedPort);
259+
if (!port) {
260+
if (!!boards.length) {
261+
console.warn(
262+
`Could not detect the port, but unexpectedly received discovered boards. This is most likely a bug! Response was: ${this.toJson(
263+
resp
264+
)}`
265+
);
266+
}
267+
return;
268+
}
269+
const oldState = deepClone(this._availablePorts);
270+
const newState = deepClone(this._availablePorts);
271+
const key = Port.keyOf(port);
272+
273+
if (eventType === EventType.Add) {
274+
if (newState[key]) {
275+
const [, knownBoards] = newState[key];
276+
this.logger.warn(
277+
`Port '${Port.toString(
278+
port
279+
)}' was already available. Known boards before override: ${JSON.stringify(
280+
knownBoards
281+
)}`
282+
);
283+
}
284+
newState[key] = [port, boards];
285+
} else if (eventType === EventType.Remove) {
286+
if (!newState[key]) {
287+
this.logger.warn(
288+
`Port '${Port.toString(port)}' was not available. Skipping`
289+
);
290+
return;
291+
}
292+
delete newState[key];
293+
}
294+
295+
const event: AttachedBoardsChangeEvent = {
296+
oldState: {
297+
...AvailablePorts.split(oldState),
298+
},
299+
newState: {
300+
...AvailablePorts.split(newState),
301+
},
302+
};
303+
304+
this._availablePorts = newState;
305+
this.notificationService.notifyAttachedBoardsDidChange(event);
306+
}
307+
}
308+
309+
private fromRpc(detectedPort: RpcDetectedPort): DetectedPort {
310+
const rpcPort = detectedPort.getPort();
311+
const port = rpcPort && this.fromRpcPort(rpcPort);
312+
const boards = detectedPort.getMatchingBoardsList().map(
313+
(board) =>
314+
({
315+
fqbn: board.getFqbn(),
316+
name: board.getName() || Unknown,
317+
port,
318+
} as Board)
319+
);
320+
return {
321+
boards,
322+
port,
323+
};
344324
}
345325

346-
getAvailablePorts(state: AvailablePorts = this.availablePorts): Port[] {
347-
const availablePorts: Port[] = [];
348-
for (const portID of Object.keys(state)) {
349-
const [port] = state[portID];
350-
availablePorts.push(port);
326+
private fromRpcPort(rpcPort: RpcPort): Port {
327+
const port = {
328+
address: rpcPort.getAddress(),
329+
addressLabel: rpcPort.getLabel(),
330+
protocol: rpcPort.getProtocol(),
331+
protocolLabel: rpcPort.getProtocolLabel(),
332+
properties: Port.Properties.create(rpcPort.getPropertiesMap().toObject()),
333+
};
334+
return port;
335+
}
336+
}
337+
338+
enum EventType {
339+
Add,
340+
Remove,
341+
Quit,
342+
}
343+
namespace EventType {
344+
export function parse(type: string): EventType {
345+
const normalizedType = type.toLowerCase();
346+
switch (normalizedType) {
347+
case 'add':
348+
return EventType.Add;
349+
case 'remove':
350+
return EventType.Remove;
351+
case 'quit':
352+
return EventType.Quit;
353+
default:
354+
throw new Error(
355+
`Unexpected 'BoardListWatchResponse' event type: '${type}.'`
356+
);
351357
}
352-
return availablePorts;
353358
}
354359
}
360+
361+
interface DetectedPort {
362+
port: Port | undefined;
363+
boards: Board[];
364+
}

‎arduino-ide-extension/src/node/boards-service-impl.ts

-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Installable,
77
BoardsPackage,
88
Board,
9-
Port,
109
BoardDetails,
1110
Tool,
1211
ConfigOption,
@@ -65,14 +64,6 @@ export class BoardsServiceImpl
6564
return this.boardDiscovery.availablePorts;
6665
}
6766

68-
async getAttachedBoards(): Promise<Board[]> {
69-
return this.boardDiscovery.getAttachedBoards();
70-
}
71-
72-
async getAvailablePorts(): Promise<Port[]> {
73-
return this.boardDiscovery.getAvailablePorts();
74-
}
75-
7667
async getBoardDetails(options: {
7768
fqbn: string;
7869
}): Promise<BoardDetails | undefined> {

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

+13-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
import { ResponseService } from '../common/protocol/response-service';
2626
import { OutputMessage, Port, Status } from '../common/protocol';
2727
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb';
28-
import { Port as GrpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb';
28+
import { Port as RpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb';
2929
import { ApplicationError, CommandService, Disposable, nls } from '@theia/core';
3030
import { MonitorManager } from './monitor-manager';
3131
import { AutoFlushingBuffer } from './utils/buffers';
@@ -405,15 +405,20 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
405405
}
406406
}
407407

408-
private createPort(port: Port | undefined): GrpcPort {
409-
const grpcPort = new GrpcPort();
408+
private createPort(port: Port | undefined): RpcPort {
409+
const rpcPort = new RpcPort();
410410
if (port) {
411-
grpcPort.setAddress(port.address);
412-
grpcPort.setLabel(port.addressLabel);
413-
grpcPort.setProtocol(port.protocol);
414-
grpcPort.setProtocolLabel(port.protocolLabel);
411+
rpcPort.setAddress(port.address);
412+
rpcPort.setLabel(port.addressLabel);
413+
rpcPort.setProtocol(port.protocol);
414+
rpcPort.setProtocolLabel(port.protocolLabel);
415+
if (port.properties) {
416+
for (const [key, value] of Object.entries(port.properties)) {
417+
rpcPort.getPropertiesMap().set(key, value);
418+
}
419+
}
415420
}
416-
return grpcPort;
421+
return rpcPort;
417422
}
418423
}
419424
type StreamingResponse =

‎arduino-ide-extension/src/node/monitor-service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from './cli-protocol/cc/arduino/cli/commands/v1/monitor_pb';
1313
import { CoreClientAware } from './core-client-provider';
1414
import { WebSocketProvider } from './web-socket/web-socket-provider';
15-
import { Port as gRPCPort } from 'arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/port_pb';
15+
import { Port as RpcPort } from 'arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/port_pb';
1616
import {
1717
MonitorSettings,
1818
PluggableMonitorSettings,
@@ -193,10 +193,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
193193
monitorRequest.setFqbn(this.board.fqbn);
194194
}
195195
if (this.port?.address && this.port?.protocol) {
196-
const port = new gRPCPort();
197-
port.setAddress(this.port.address);
198-
port.setProtocol(this.port.protocol);
199-
monitorRequest.setPort(port);
196+
const rpcPort = new RpcPort();
197+
rpcPort.setAddress(this.port.address);
198+
rpcPort.setProtocol(this.port.protocol);
199+
monitorRequest.setPort(rpcPort);
200200
}
201201
const config = new MonitorPortConfiguration();
202202
for (const id in this.settings.pluggableMonitorSettings) {

‎arduino-ide-extension/src/test/browser/fixtures/boards.ts

-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ export const aBoard: Board = {
55
fqbn: 'some:board:fqbn',
66
name: 'Some Arduino Board',
77
port: {
8-
id: '/lol/port1234|serial',
98
address: '/lol/port1234',
109
addressLabel: '/lol/port1234',
1110
protocol: 'serial',
1211
protocolLabel: 'Serial Port (USB)',
1312
},
1413
};
1514
export const aPort: Port = {
16-
id: aBoard.port!.id,
1715
address: aBoard.port!.address,
1816
addressLabel: aBoard.port!.addressLabel,
1917
protocol: aBoard.port!.protocol,
@@ -27,15 +25,13 @@ export const anotherBoard: Board = {
2725
fqbn: 'another:board:fqbn',
2826
name: 'Another Arduino Board',
2927
port: {
30-
id: '/kek/port5678|serial',
3128
address: '/kek/port5678',
3229
addressLabel: '/kek/port5678',
3330
protocol: 'serial',
3431
protocolLabel: 'Serial Port (USB)',
3532
},
3633
};
3734
export const anotherPort: Port = {
38-
id: anotherBoard.port!.id,
3935
address: anotherBoard.port!.address,
4036
addressLabel: anotherBoard.port!.addressLabel,
4137
protocol: anotherBoard.port!.protocol,

0 commit comments

Comments
 (0)
Please sign in to comment.