Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4079684

Browse files
authoredOct 28, 2020
[skip-changelog] Added UploadUsingProgrammer gRPC API (#1045)
* Added UploadUsingProgrammer gRPC call * fix indent
1 parent bf6bb1e commit 4079684

File tree

6 files changed

+628
-233
lines changed

6 files changed

+628
-233
lines changed
 

‎commands/daemon/daemon.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadReq, stream rpc.ArduinoCor
258258
return stream.Send(resp)
259259
}
260260

261+
// UploadUsingProgrammer FIXMEDOC
262+
func (s *ArduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgrammerReq, stream rpc.ArduinoCore_UploadUsingProgrammerServer) error {
263+
resp, err := upload.UsingProgrammer(
264+
stream.Context(), req,
265+
utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.UploadUsingProgrammerResp{OutStream: data}) }),
266+
utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.UploadUsingProgrammerResp{ErrStream: data}) }),
267+
)
268+
if err != nil {
269+
return err
270+
}
271+
return stream.Send(resp)
272+
}
273+
261274
// BurnBootloader FIXMEDOC
262275
func (s *ArduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderReq, stream rpc.ArduinoCore_BurnBootloaderServer) error {
263276
resp, err := upload.BurnBootloader(

‎commands/upload/upload.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStr
7171
return &rpc.UploadResp{}, nil
7272
}
7373

74+
// UsingProgrammer FIXMEDOC
75+
func UsingProgrammer(ctx context.Context, req *rpc.UploadUsingProgrammerReq, outStream io.Writer, errStream io.Writer) (*rpc.UploadUsingProgrammerResp, error) {
76+
logrus.Tracef("Upload using programmer %s on %s started", req.GetSketchPath(), req.GetFqbn())
77+
78+
if req.GetProgrammer() == "" {
79+
return nil, errors.New("programmer not specified")
80+
}
81+
_, err := Upload(ctx, &rpc.UploadReq{
82+
Instance: req.GetInstance(),
83+
SketchPath: req.GetSketchPath(),
84+
ImportFile: req.GetImportFile(),
85+
ImportDir: req.GetImportDir(),
86+
Fqbn: req.GetFqbn(),
87+
Port: req.GetPort(),
88+
Programmer: req.GetProgrammer(),
89+
Verbose: req.GetVerbose(),
90+
Verify: req.GetVerify(),
91+
}, outStream, errStream)
92+
return &rpc.UploadUsingProgrammerResp{}, err
93+
}
94+
7495
func runProgramAction(pm *packagemanager.PackageManager,
7596
sketch *sketches.Sketch,
7697
importFile, importDir, fqbnIn, port string,

‎rpc/commands/commands.pb.go

Lines changed: 239 additions & 160 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rpc/commands/commands.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ service ArduinoCore {
9797
// Upgrade an installed platform to the latest version.
9898
rpc PlatformUpgrade(PlatformUpgradeReq) returns (stream PlatformUpgradeResp);
9999

100-
// Upload a compiled sketch to an Arduino board.
100+
// Upload a compiled sketch to a board.
101101
rpc Upload(UploadReq) returns (stream UploadResp);
102102

103+
// Upload a compiled sketch to a board using a programmer.
104+
rpc UploadUsingProgrammer(UploadUsingProgrammerReq) returns (stream UploadUsingProgrammerResp);
105+
106+
// List programmers available for a board.
103107
rpc ListProgrammersAvailableForUpload(ListProgrammersAvailableForUploadReq) returns (ListProgrammersAvailableForUploadResp);
104108

105109
// Burn bootloader to a board.

‎rpc/commands/upload.pb.go

Lines changed: 309 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rpc/commands/upload.proto

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ import "commands/common.proto";
2323

2424
message UploadReq {
2525
// Arduino Core Service instance from the `Init` response.
26-
Instance instance = 1;
26+
Instance instance = 1;
2727
// Fully qualified board name of the target board (e.g., `arduino:avr:uno`).
2828
// If this field is not defined, the FQBN of the board attached to the sketch
2929
// via the `BoardAttach` method is used.
30-
string fqbn = 2;
30+
string fqbn = 2;
3131
// Path where the sketch to be uploaded is stored. Unless the `import_file`
3232
// field is defined, the compiled binary is assumed to be at the location and
3333
// filename under this path where it is saved by the `Compile` method.
34-
string sketch_path = 3;
34+
string sketch_path = 3;
3535
// The port of the board.
3636
string port = 4;
3737
// Whether to turn on verbose output during the upload.
@@ -45,6 +45,9 @@ message UploadReq {
4545
// Custom path to a directory containing compiled files. When `import_dir` is
4646
// not specified, the standard build directory under `sketch_path` is used.
4747
string import_dir = 8;
48+
// The programmer to use for upload. If set an UploadUsingProgrammer is triggered
49+
// instead of a normal upload. The UploadUsingProgrammer call may also be used for
50+
// explicit error check.
4851
string programmer = 9;
4952
}
5053

@@ -55,6 +58,41 @@ message UploadResp {
5558
bytes err_stream = 2;
5659
}
5760

61+
message UploadUsingProgrammerReq {
62+
// Arduino Core Service instance from the `Init` response.
63+
Instance instance = 1;
64+
// Fully qualified board name of the target board (e.g., `arduino:avr:uno`).
65+
// If this field is not defined, the FQBN of the board attached to the sketch
66+
// via the `BoardAttach` method is used.
67+
string fqbn = 2;
68+
// Path where the sketch to be uploaded is stored. Unless the `import_file`
69+
// field is defined, the compiled binary is assumed to be at the location and
70+
// filename under this path where it is saved by the `Compile` method.
71+
string sketch_path = 3;
72+
// The port of the board.
73+
string port = 4;
74+
// Whether to turn on verbose output during the upload.
75+
bool verbose = 5;
76+
// After upload, verify that the contents of the memory on the board match the
77+
// uploaded binary.
78+
bool verify = 6;
79+
// When `import_file` is specified, it overrides the `import_dir` and `sketch_path`
80+
// params.
81+
string import_file = 7;
82+
// Custom path to a directory containing compiled files. When `import_dir` is
83+
// not specified, the standard build directory under `sketch_path` is used.
84+
string import_dir = 8;
85+
// The programmer to use for upload.
86+
string programmer = 9;
87+
}
88+
89+
message UploadUsingProgrammerResp {
90+
// The output of the upload process.
91+
bytes out_stream = 1;
92+
// The error output of the upload process.
93+
bytes err_stream = 2;
94+
}
95+
5896
message BurnBootloaderReq {
5997
// Arduino Core Service instance from the `Init` response.
6098
Instance instance = 1;

0 commit comments

Comments
 (0)
Please sign in to comment.