Skip to content

Commit bf067ea

Browse files
committed
Refactored gRPC Monitor API
1 parent 07cf265 commit bf067ea

File tree

6 files changed

+289
-151
lines changed

6 files changed

+289
-151
lines changed

commands/daemon/daemon.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,11 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
477477
return err
478478
}
479479

480-
portProxy, _, err := monitor.Monitor(stream.Context(), req)
480+
openReq := req.GetOpenRequest()
481+
if openReq == nil {
482+
return &cmderrors.InvalidInstanceError{}
483+
}
484+
portProxy, _, err := monitor.Monitor(stream.Context(), openReq)
481485
if err != nil {
482486
return err
483487
}
@@ -497,7 +501,7 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
497501
syncSend.Send(&rpc.MonitorResponse{Error: err.Error()})
498502
return
499503
}
500-
if conf := msg.GetPortConfiguration(); conf != nil {
504+
if conf := msg.GetUpdatedConfiguration(); conf != nil {
501505
for _, c := range conf.GetSettings() {
502506
if err := portProxy.Config(c.GetSettingId(), c.GetValue()); err != nil {
503507
syncSend.Send(&rpc.MonitorResponse{Error: err.Error()})

commands/daemon/term_example/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ func connectToPort(cli commands.ArduinoCoreServiceClient, instance *commands.Ins
8989
log.Fatal("Error opening Monitor:", err)
9090
}
9191
if err := monitorClient.Send(&commands.MonitorRequest{
92-
Instance: instance,
93-
Port: port,
92+
Message: &commands.MonitorRequest_OpenRequest{OpenRequest: &commands.MonitorPortOpenRequest{
93+
Instance: instance,
94+
Port: port,
95+
}},
9496
}); err != nil {
9597
log.Fatal("Error sending Monitor config:", err)
9698
}
@@ -106,9 +108,9 @@ func connectToPort(cli commands.ArduinoCoreServiceClient, instance *commands.Ins
106108
}
107109
}()
108110

109-
hello := &commands.MonitorRequest{
111+
hello := &commands.MonitorRequest{Message: &commands.MonitorRequest_TxData{
110112
TxData: []byte("HELLO!"),
111-
}
113+
}}
112114
fmt.Println("Send:", hello)
113115
if err := monitorClient.Send(hello); err != nil {
114116
log.Fatal("Monitor send HELLO:", err)

commands/monitor/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (p *PortProxy) Close() error {
6060

6161
// Monitor opens a communication port. It returns a PortProxy to communicate with the port and a PortDescriptor
6262
// that describes the available configuration settings.
63-
func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggableMonitor.PortDescriptor, error) {
63+
func Monitor(ctx context.Context, req *rpc.MonitorPortOpenRequest) (*PortProxy, *pluggableMonitor.PortDescriptor, error) {
6464
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
6565
if err != nil {
6666
return nil, nil, err

internal/cli/monitor/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func runMonitorCmd(
203203
}
204204
}
205205
}
206-
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorRequest{
206+
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorPortOpenRequest{
207207
Instance: inst,
208208
Port: &rpc.Port{Address: portAddress, Protocol: portProtocol},
209209
Fqbn: fqbn,

0 commit comments

Comments
 (0)