Skip to content

Added external programmer support #720

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 14 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Added scaffolding for external programmer support
  • Loading branch information
cmaglie committed Jun 12, 2020
commit 2ba8bf450b1092d50daa4e463f4963eaa1be9c06
46 changes: 41 additions & 5 deletions cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ import (
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/upload"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/arduino-cli/table"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var (
fqbn string
port string
verbose bool
verify bool
importDir string
fqbn string
port string
verbose bool
verify bool
importDir string
programmer string
)

// NewCommand created a new `upload` command
Expand All @@ -53,6 +55,7 @@ func NewCommand() *cobra.Command {
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Direcory containing binaries to upload.")
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
uploadCommand.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload or 'list' to list supported programmers.")

return uploadCommand
}
Expand All @@ -64,6 +67,21 @@ func run(command *cobra.Command, args []string) {
os.Exit(errorcodes.ErrGeneric)
}

if programmer == "list" {
resp, err := upload.ListProgrammersAvailableForUpload(context.Background(), &rpc.ListProgrammersAvailableForUploadReq{
Instance: instance,
Fqbn: fqbn,
})
if err != nil {
feedback.Errorf("Error listing programmers: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
feedback.PrintResult(&programmersList{
Programmers: resp.GetProgrammers(),
})
os.Exit(0)
}

var path *paths.Path
if len(args) > 0 {
path = paths.New(args[0])
Expand All @@ -78,6 +96,7 @@ func run(command *cobra.Command, args []string) {
Verbose: verbose,
Verify: verify,
ImportDir: importDir,
Programmer: programmer,
}, os.Stdout, os.Stderr); err != nil {
feedback.Errorf("Error during Upload: %v", err)
os.Exit(errorcodes.ErrGeneric)
Expand All @@ -98,3 +117,20 @@ func initSketchPath(sketchPath *paths.Path) *paths.Path {
logrus.Infof("Reading sketch from dir: %s", wd)
return wd
}

type programmersList struct {
Programmers []*rpc.Programmer
}

func (p *programmersList) Data() interface{} {
return p.Programmers
}

func (p *programmersList) String() string {
t := table.New()
t.SetHeader("Programmer Name", "ID", "Platform")
for _, prog := range p.Programmers {
t.AddRow(prog.GetName(), prog.GetId(), prog.GetPlatform())
}
return t.Render()
}
5 changes: 5 additions & 0 deletions commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadReq, stream rpc.ArduinoCor
return stream.Send(resp)
}

// ListProgrammersAvailableForUpload FIXMEDOC
func (s *ArduinoCoreServerImpl) ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadReq) (*rpc.ListProgrammersAvailableForUploadResp, error) {
return upload.ListProgrammersAvailableForUpload(ctx, req)
}

// LibraryDownload FIXMEDOC
func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadReq, stream rpc.ArduinoCore_LibraryDownloadServer) error {
resp, err := lib.LibraryDownload(
Expand Down
160 changes: 99 additions & 61 deletions rpc/commands/commands.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rpc/commands/commands.proto
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ service ArduinoCore {
// Upload a compiled sketch to an Arduino board.
rpc Upload(UploadReq) returns (stream UploadResp);

rpc ListProgrammersAvailableForUpload(ListProgrammersAvailableForUploadReq) returns (ListProgrammersAvailableForUploadResp);

// Search for a platform in the platforms indexes.
rpc PlatformSearch(PlatformSearchReq) returns (PlatformSearchResp);

Expand Down
Loading