Skip to content

Commit 7d2f436

Browse files
committed
Read upload port from sketch.json
1 parent 292277f commit 7d2f436

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

arduino/sketches/sketches.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Metadata struct {
4545
type BoardMetadata struct {
4646
Fqbn string `json:"fqbn,required"`
4747
Name string `json:"name,omitempty"`
48+
Port string `json:"port,omitepty"`
4849
}
4950

5051
// NewSketchBook returns a new SketchBook object

commands/board/attach.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachReq, taskCB commands.TaskPr
9898
sketch.Metadata.CPU = sketches.BoardMetadata{
9999
Fqbn: board.FQBN(),
100100
Name: board.Name(),
101+
Port: deviceURI.String(),
101102
}
102103
}
103104

commands/upload/upload.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"fmt"
2323
"io"
24+
"net/url"
2425
"os"
2526
"path/filepath"
2627
"strings"
@@ -55,6 +56,15 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
5556

5657
// FIXME: make a specification on how a port is specified via command line
5758
port := req.GetPort()
59+
if port == "" && sketch != nil && sketch.Metadata != nil {
60+
deviceURI, err := url.Parse(sketch.Metadata.CPU.Port)
61+
if err != nil {
62+
return nil, fmt.Errorf("invalid Device URL format: %s", err)
63+
}
64+
if deviceURI.Scheme == "serial" {
65+
port = deviceURI.Host + deviceURI.Path
66+
}
67+
}
5868
if port == "" {
5969
return nil, fmt.Errorf("no upload port provided")
6070
}

0 commit comments

Comments
 (0)