10000 Added `BoardIdentify` gRPC call. by cmaglie · Pull Request #2794 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

Added BoardIdentify gRPC call. #2794

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 9 commits into from
Jan 13, 2025
Merged
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
Prev Previous commit
Use BoardIdentify internally
This commit also fix a bug (the package manager was used after release).
  • Loading branch information
cmaglie committed Jan 7, 2025
commit 85cbc6348fbf8a557a69f007923689a86696b3f5
42 changes: 27 additions & 15 deletions commands/service_board_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-cli/commands/cmderrors"
"github.com/arduino/arduino-cli/commands/internal/instances"
f "github.com/arduino/arduino-cli/internal/algorithms"
"github.com/arduino/arduino-cli/internal/arduino/discovery/discoverymanager"
"github.com/arduino/arduino-cli/internal/i18n"
"github.com/arduino/arduino-cli/pkg/fqbn"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
Expand All @@ -46,14 +47,18 @@ func (s *arduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis
if err != nil {
return nil, err
}
defer release()
dm := pme.DiscoveryManager()
warnings := f.Map(dm.Start(), (error).Error)
release()
time.Sleep(time.Duration(req.GetTimeout()) * time.Millisecond)

ports := []*rpc.DetectedPort{}
for _, port := range dm.List() {
boards, err := identify(pme, port.Properties, s.settings, req.GetSkipCloudApiForBoardDetection())
resp, err := s.BoardIdentify(ctx, &rpc.BoardIdentifyRequest{
Instance: req.GetInstance(),
Properties: port.Properties.AsMap(),
UseCloudApiForUnknownBoardDetection: !req.GetSkipCloudApiForBoardDetection(),
})
if err != nil {
warnings = append(warnings, err.Error())
}
Expand All @@ -62,7 +67,7 @@ func (s *arduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis
// API managed to recognize the connected board
b := &rpc.DetectedPort{
Port: rpc.DiscoveryPortToRPC(port),
MatchingBoards: boards,
MatchingBoards: resp.GetBoards(),
}

if fqbnFilter == nil || hasMatchingBoard(b, fqbnFilter) {
Expand Down Expand Up @@ -106,16 +111,18 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s
return err
}

pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if err != nil {
return err
}
dm := pme.DiscoveryManager()

watcher, err := dm.Watch()
release()
if err != nil {
return err
var watcher *discoverymanager.PortWatcher
{
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
if err != nil {
return err
}
dm := pme.DiscoveryManager()
watcher, err = dm.Watch()
release()
if err != nil {
return err
}
}

go func() {
Expand All @@ -126,11 +133,16 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s

boardsError := ""
if event.Type == "add" {
boards, err := identify(pme, event.Port.Properties, s.settings, req.GetSkipCloudApiForBoardDetection())
resp, err := s.BoardIdentify(context.Background(), &rpc.BoardIdentifyRequest{
Instance: req.GetInstance(),
Properties: event.Port.Properties.AsMap(),
UseCloudApiForUnknownBoardDetection: !req.GetSkipCloudApiForBoardDetection(),
})
if err != nil {
boardsError = err.Error()
} else {
port.MatchingBoards = resp.GetBoards()
}
port.MatchingBoards = boards
}
stream.Send(&rpc.BoardListWatchResponse{
EventType: event.Type,
Expand Down
Loading
0