mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-09 02:18:32 +00:00
Solve ports conflicts with same address and different protocol
This commit is contained in:
committed by
Silvano Cerza
parent
b3b22795f8
commit
af33dce0f6
@@ -124,8 +124,22 @@ export class BoardDiscovery extends CoreClientAware {
|
||||
|
||||
const address = (detectedPort as any).getPort().getAddress();
|
||||
const protocol = (detectedPort as any).getPort().getProtocol();
|
||||
// Different discoveries can detect the same port with different
|
||||
// protocols, so we consider the combination of address and protocol
|
||||
// to be the id of a certain port to distinguish it from others.
|
||||
// If we'd use only the address of a port to store it in a map
|
||||
// we can have conflicts the same port is found with multiple
|
||||
// protocols.
|
||||
const portID = `${address}|${protocol}`;
|
||||
const label = (detectedPort as any).getPort().getLabel();
|
||||
const port = { address, protocol, label };
|
||||
const protocolLabel = (detectedPort as any).getPort().getProtocolLabel();
|
||||
const port = {
|
||||
id: portID,
|
||||
address,
|
||||
addressLabel: label,
|
||||
protocol,
|
||||
protocolLabel,
|
||||
};
|
||||
const boards: Board[] = [];
|
||||
for (const item of detectedPort.getMatchingBoardsList()) {
|
||||
boards.push({
|
||||
@@ -136,23 +150,21 @@ export class BoardDiscovery extends CoreClientAware {
|
||||
}
|
||||
|
||||
if (eventType === 'add') {
|
||||
if (newState[port.address]) {
|
||||
const [, knownBoards] = newState[port.address];
|
||||
if (newState[portID]) {
|
||||
const [, knownBoards] = newState[portID];
|
||||
console.warn(
|
||||
`Port '${
|
||||
port.address
|
||||
}' was already available. Known boards before override: ${JSON.stringify(
|
||||
`Port '${Port.toString(port)}' was already available. Known boards before override: ${JSON.stringify(
|
||||
knownBoards
|
||||
)}`
|
||||
);
|
||||
}
|
||||
newState[port.address] = [port, boards];
|
||||
newState[portID] = [port, boards];
|
||||
} else if (eventType === 'remove') {
|
||||
if (!newState[port.address]) {
|
||||
console.warn(`Port '${port.address}' was not available. Skipping`);
|
||||
if (!newState[portID]) {
|
||||
console.warn(`Port '${Port.toString(port)}' was not available. Skipping`);
|
||||
return;
|
||||
}
|
||||
delete newState[port.address];
|
||||
delete newState[portID];
|
||||
}
|
||||
|
||||
const oldAvailablePorts = this.getAvailablePorts(oldState);
|
||||
@@ -179,8 +191,8 @@ export class BoardDiscovery extends CoreClientAware {
|
||||
|
||||
getAttachedBoards(state: AvailablePorts = this.state): Board[] {
|
||||
const attachedBoards: Board[] = [];
|
||||
for (const address of Object.keys(state)) {
|
||||
const [, boards] = state[address];
|
||||
for (const portID of Object.keys(state)) {
|
||||
const [, boards] = state[portID];
|
||||
attachedBoards.push(...boards);
|
||||
}
|
||||
return attachedBoards;
|
||||
@@ -188,8 +200,8 @@ export class BoardDiscovery extends CoreClientAware {
|
||||
|
||||
getAvailablePorts(state: AvailablePorts = this.state): Port[] {
|
||||
const availablePorts: Port[] = [];
|
||||
for (const address of Object.keys(state)) {
|
||||
const [port] = state[address];
|
||||
for (const portID of Object.keys(state)) {
|
||||
const [port] = state[portID];
|
||||
availablePorts.push(port);
|
||||
}
|
||||
return availablePorts;
|
||||
|
||||
@@ -159,8 +159,9 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
|
||||
const p = new Port();
|
||||
if (port) {
|
||||
p.setAddress(port.address);
|
||||
p.setLabel(port.label || '');
|
||||
p.setLabel(port.addressLabel);
|
||||
p.setProtocol(port.protocol);
|
||||
p.setProtocolLabel(port.protocolLabel);
|
||||
}
|
||||
req.setPort(p);
|
||||
if (programmer) {
|
||||
@@ -229,8 +230,9 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
|
||||
const p = new Port();
|
||||
if (port) {
|
||||
p.setAddress(port.address);
|
||||
p.setLabel(port.label || '');
|
||||
p.setLabel(port.addressLabel);
|
||||
p.setProtocol(port.protocol);
|
||||
p.setProtocolLabel(port.protocolLabel);
|
||||
}
|
||||
burnReq.setPort(p);
|
||||
if (programmer) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
MonitorConfig as GrpcMonitorConfig,
|
||||
} from '../cli-protocol/cc/arduino/cli/monitor/v1/monitor_pb';
|
||||
import { MonitorClientProvider } from './monitor-client-provider';
|
||||
import { Board, Port } from '../../common/protocol/boards-service';
|
||||
import { Board } from '../../common/protocol/boards-service';
|
||||
import { WebSocketService } from '../web-socket/web-socket-service';
|
||||
import { SerialPlotter } from '../../browser/serial/plotter/protocol';
|
||||
import { Disposable } from '@theia/core/shared/vscode-languageserver-protocol';
|
||||
@@ -88,7 +88,7 @@ export class SerialServiceImpl implements SerialService {
|
||||
|
||||
@inject(WebSocketService)
|
||||
protected readonly webSocketService: WebSocketService
|
||||
) {}
|
||||
) { }
|
||||
|
||||
async isSerialPortOpen(): Promise<boolean> {
|
||||
return !!this.serialConnection;
|
||||
@@ -153,7 +153,7 @@ export class SerialServiceImpl implements SerialService {
|
||||
this.logger.info(
|
||||
`>>> Creating serial connection for ${Board.toString(
|
||||
this.serialConfig.board
|
||||
)} on port ${Port.toString(this.serialConfig.port)}...`
|
||||
)} on port ${this.serialConfig.port.address}...`
|
||||
);
|
||||
|
||||
if (this.serialConnection) {
|
||||
@@ -225,7 +225,7 @@ export class SerialServiceImpl implements SerialService {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
}
|
||||
);
|
||||
|
||||
@@ -272,12 +272,12 @@ export class SerialServiceImpl implements SerialService {
|
||||
serialConnection.duplex.write(req, () => {
|
||||
const boardName = this.serialConfig?.board
|
||||
? Board.toString(this.serialConfig.board, {
|
||||
useFqbn: false,
|
||||
})
|
||||
useFqbn: false,
|
||||
})
|
||||
: 'unknown board';
|
||||
|
||||
const portName = this.serialConfig?.port
|
||||
? Port.toString(this.serialConfig.port)
|
||||
? this.serialConfig.port.address
|
||||
: 'unknown port';
|
||||
this.logger.info(
|
||||
`<<< Serial connection created for ${boardName} on port ${portName}.`
|
||||
@@ -330,7 +330,7 @@ export class SerialServiceImpl implements SerialService {
|
||||
this.logger.info(
|
||||
`<<< Disposed serial connection for ${Board.toString(config.board, {
|
||||
useFqbn: false,
|
||||
})} on port ${Port.toString(config.port)}.`
|
||||
})} on port ${config.port.address}.`
|
||||
);
|
||||
|
||||
duplex.cancel();
|
||||
|
||||
Reference in New Issue
Block a user