Skip to content

Read upload port from sketch.json #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arduino/sketches/sketches.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Metadata struct {
type BoardMetadata struct {
Fqbn string `json:"fqbn,required"`
Name string `json:"name,omitempty"`
Port string `json:"port,omitepty"`
}

// NewSketchFromPath loads a sketch from the specified path
Expand Down
6 changes: 3 additions & 3 deletions cli/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func initAttachCommand() *cobra.Command {
Use: "attach <port>|<FQBN> [sketchPath]",
Short: "Attaches a sketch to a board.",
Long: "Attaches a sketch to a board.",
Example: " " + os.Args[0] + " board attach serial:///dev/tty/ACM0\n" +
" " + os.Args[0] + " board attach serial:///dev/tty/ACM0 HelloWorld\n" +
Example: " " + os.Args[0] + " board attach serial:///dev/ttyACM0\n" +
" " + os.Args[0] + " board attach serial:///dev/ttyACM0 HelloWorld\n" +
" " + os.Args[0] + " board attach arduino:samd:mkr1000",
Args: cobra.RangeArgs(1, 2),
Run: runAttachCommand,
}
attachCommand.Flags().StringVar(&attachFlags.searchTimeout, "timeout", "5s",
"The timeout of the search of connected devices, try to high it if your board is not found (e.g. to 10s).")
"The connected devices search timeout, raise it if your board doesn't show up (e.g. to 10s).")
return attachCommand
}

Expand Down
1 change: 1 addition & 0 deletions commands/board/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func Attach(ctx context.Context, req *rpc.BoardAttachReq, taskCB commands.TaskPr
sketch.Metadata.CPU = sketches.BoardMetadata{
Fqbn: board.FQBN(),
Name: board.Name(),
Port: deviceURI.String(),
}
}

Expand Down
10 changes: 10 additions & 0 deletions commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"io"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -53,6 +54,15 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr

// FIXME: make a specification on how a port is specified via command line
port := req.GetPort()
if port == "" && sketch != nil && sketch.Metadata != nil {
deviceURI, err := url.Parse(sketch.Metadata.CPU.Port)
if err != nil {
return nil, fmt.Errorf("invalid Device URL format: %s", err)
}
if deviceURI.Scheme == "serial" {
port = deviceURI.Host + deviceURI.Path
}
}
if port == "" {
return nil, fmt.Errorf("no upload port provided")
}
Expand Down