Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

OTA enhancement. Split port and uploadPort in arduino.json #362

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions misc/arduinoValidator.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"type": "string",
"minLength": 1
},
"uploadPort": {
"description": "Upload port",
"type": "string",
"minLength": 1
},
"board": {
"description": "Arduino board type",
"type": "string",
Expand Down
15 changes: 10 additions & 5 deletions src/arduino/arduino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,21 @@ export class ArduinoApp {
if (!dc.sketch || !util.fileExistsSync(path.join(ArduinoWorkspace.rootPath, dc.sketch))) {
await this.getMainSketch(dc);
}
if (!dc.port) {
vscode.window.showErrorMessage("Please specify the upload serial port.");
if (!dc.uploadPort) {
vscode.window.showErrorMessage("Please specify the upload port.");
return;
}

arduinoChannel.show();
arduinoChannel.start(`Upload sketch - ${dc.sketch}`);

const serialMonitor = SerialMonitor.getInstance();
let serialMonitor;
let needRestore = false;
if (dc.port === dc.uploadPort) {
serialMonitor = SerialMonitor.getInstance();
needRestore = await serialMonitor.closeSerialMonitor(dc.port);
}

const needRestore = await serialMonitor.closeSerialMonitor(dc.port);
UsbDetector.getInstance().pauseListening();
await vscode.workspace.saveAll(false);

Expand All @@ -135,7 +139,8 @@ export class ArduinoApp {
}

const appPath = path.join(ArduinoWorkspace.rootPath, dc.sketch);
const args = ["--upload", "--board", boardDescriptor, "--port", dc.port, appPath];
const args = ["--upload", "--board", boardDescriptor, "--port", dc.uploadPort, appPath];

if (VscodeSettings.getInstance().logLevel === "verbose") {
args.push("--verbose");
}
Expand Down
22 changes: 22 additions & 0 deletions src/deviceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export interface IDeviceContext {
*/
port: string;

/**
* Port used for uploading the skecth.
* It can be a COM port or an IP address (OTA)
* If undefined, it uses port value.
* @property {string}
*/
uploadPort: string;

/**
* Current selected Arduino board alias.
* @property {string}
Expand Down Expand Up @@ -68,6 +76,8 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {

private _port: string;

private _uploadPort: string;

private _board: string;

private _sketch: string;
Expand Down Expand Up @@ -138,6 +148,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
deviceConfigJson = util.tryParseJSON(fs.readFileSync(configFile.fsPath, "utf8"));
if (deviceConfigJson) {
this._port = deviceConfigJson.port;
this._uploadPort = deviceConfigJson.uploadPort || deviceConfigJson.port;
this._board = deviceConfigJson.board;
this._sketch = deviceConfigJson.sketch;
this._configuration = deviceConfigJson.configuration;
Expand All @@ -150,6 +161,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
}
} else {
this._port = null;
this._uploadPort = null;
this._board = null;
this._sketch = null;
this._configuration = null;
Expand Down Expand Up @@ -203,6 +215,7 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
}
deviceConfigJson.sketch = this.sketch;
deviceConfigJson.port = this.port;
deviceConfigJson.uploadPort = this.uploadPort;
deviceConfigJson.board = this.board;
deviceConfigJson.output = this.output;
deviceConfigJson["debugger"] = this.debugger_;
Expand Down Expand Up @@ -230,6 +243,15 @@ export class DeviceContext implements IDeviceContext, vscode.Disposable {
this.saveContext();
}

public get uploadPort() {
return this._uploadPort;
}

public set uploadPort(value: string) {
this._uploadPort = value;
this.saveContext();
}

public get board() {
return this._board;
}
Expand Down
1 change: 1 addition & 0 deletions test/devicecontext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ suite("Arduino: Device Context config", () => {
deviceContext.loadContext().then(() => {
assert.equal(deviceContext.board, "arduino:avr:diecimila");
assert.equal(deviceContext.port, "COM4");
assert.equal(deviceContext.uploadPort, "COM4");
assert.equal(deviceContext.sketch, "blink.ino");
assert.equal(deviceContext.configuration, "cpu=atmega328");
assert.equal(deviceContext.output, null);
Expand Down