Skip to content

Commit dfdd79f

Browse files
committed
Refactored gRPC Monitor API
1 parent b7ce9c8 commit dfdd79f

File tree

6 files changed

+289
-151
lines changed

6 files changed

+289
-151
lines changed

commands/daemon/daemon.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
438438
return err
439439
}
440440

441-
portProxy, _, err := monitor.Monitor(stream.Context(), req)
441+
openReq := req.GetOpenRequest()
442+
if openReq == nil {
443+
return &arduino.InvalidInstanceError{}
444+
}
445+
portProxy, _, err := monitor.Monitor(stream.Context(), openReq)
442446
if err != nil {
443447
return err
444448
}
@@ -458,7 +462,7 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
458462
syncSend.Send(&rpc.MonitorResponse{Error: err.Error()})
459463
return
460464
}
461-
if conf := msg.GetPortConfiguration(); conf != nil {
465+
if conf := msg.GetUpdatedConfiguration(); conf != nil {
462466
for _, c := range conf.GetSettings() {
463467
if err := portProxy.Config(c.SettingId, c.Value); err != nil {
464468
syncSend.Send(&rpc.MonitorResponse{Error: err.Error()})

commands/daemon/term_example/main.go

+6-4
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

+1-1
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 := instances.GetPackageManagerExplorer(req.GetInstance())
6565
if pme == nil {
6666
return nil, nil, &arduino.InvalidInstanceError{}

internal/cli/monitor/monitor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func runMonitorCmd(
199199
}
200200
}
201201
}
202-
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorRequest{
202+
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorPortOpenRequest{
203203
Instance: inst,
204204
Port: &rpc.Port{Address: portAddress, Protocol: portProtocol},
205205
Fqbn: fqbn,

0 commit comments

Comments
 (0)