Skip to content
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
64 changes: 63 additions & 1 deletion commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package daemon

import (
"context"
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -475,5 +476,66 @@ func (s *ArduinoCoreServerImpl) EnumerateMonitorPortSettings(ctx context.Context

// Monitor FIXMEDOC
func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorServer) error {
return status.New(codes.Unimplemented, "Not implemented").Err()
// The configuration must be sent on the first message
req, err := stream.Recv()
if err != nil {
return err
}

portProxy, _, err := monitor.Monitor(stream.Context(), req)
if err != nil {
return err
}
ctx, cancel := context.WithCancel(stream.Context())
go func() {
defer cancel()
for {
msg, err := stream.Recv()
if errors.Is(err, io.EOF) {
return
}
if err != nil {
stream.Send(&rpc.MonitorResponse{Error: err.Error()})
return
}
if conf := msg.GetPortConfiguration(); conf != nil {
for _, c := range conf.GetSettings() {
if err := portProxy.Config(c.SettingId, c.Value); err != nil {
stream.Send(&rpc.MonitorResponse{Error: err.Error()})
}
}
}
tx := msg.GetTxData()
for len(tx) > 0 {
n, err := portProxy.Write(tx)
if errors.Is(err, io.EOF) {
return
}
if err != nil {
stream.Send(&rpc.MonitorResponse{Error: err.Error()})
return
}
tx = tx[n:]
}
}
}()
go func() {
defer cancel()
buff := make([]byte, 4096)
for {
n, err := portProxy.Read(buff)
if errors.Is(err, io.EOF) {
return
}
if err != nil {
stream.Send(&rpc.MonitorResponse{Error: err.Error()})
return
}
if err := stream.Send(&rpc.MonitorResponse{RxData: buff[:n]}); err != nil {
return
}
}
}()
<-ctx.Done()
return nil
}
11 changes: 0 additions & 11 deletions commands/daemon/term_example/go.mod

This file was deleted.

Loading