Skip to content

Commit 273e6a5

Browse files
committed
Use BoardIdentify internally
This commit also fix a bug (the package manager was used after release).
1 parent 3116588 commit 273e6a5

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

commands/service_board_list.go

+27-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/arduino/arduino-cli/commands/cmderrors"
2424
"github.com/arduino/arduino-cli/commands/internal/instances"
2525
f "github.com/arduino/arduino-cli/internal/algorithms"
26+
"github.com/arduino/arduino-cli/internal/arduino/discovery/discoverymanager"
2627
"github.com/arduino/arduino-cli/internal/i18n"
2728
"github.com/arduino/arduino-cli/pkg/fqbn"
2829
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -46,14 +47,18 @@ func (s *arduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis
4647
if err != nil {
4748
return nil, err
4849
}
49-
defer release()
5050
dm := pme.DiscoveryManager()
5151
warnings := f.Map(dm.Start(), (error).Error)
52+
release()
5253
time.Sleep(time.Duration(req.GetTimeout()) * time.Millisecond)
5354

5455
ports := []*rpc.DetectedPort{}
5556
for _, port := range dm.List() {
56-
boards, err := identify(pme, port.Properties, s.settings, req.GetSkipCloudApiForBoardDetection())
57+
resp, err := s.BoardIdentify(ctx, &rpc.BoardIdentifyRequest{
58+
Instance: req.GetInstance(),
59+
Properties: port.Properties.AsMap(),
60+
UseCloudApiForUnknownBoardDetection: !req.GetSkipCloudApiForBoardDetection(),
61+
})
5762
if err != nil {
5863
warnings = append(warnings, err.Error())
5964
}
@@ -62,7 +67,7 @@ func (s *arduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis
6267
// API managed to recognize the connected board
6368
b := &rpc.DetectedPort{
6469
Port: rpc.DiscoveryPortToRPC(port),
65-
MatchingBoards: boards,
70+
MatchingBoards: resp.GetBoards(),
6671
}
6772

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

109-
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
110-
if err != nil {
111-
return err
112-
}
113-
dm := pme.DiscoveryManager()
114-
115-
watcher, err := dm.Watch()
116-
release()
117-
if err != nil {
118-
return err
114+
var watcher *discoverymanager.PortWatcher
115+
{
116+
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
117+
if err != nil {
118+
return err
119+
}
120+
dm := pme.DiscoveryManager()
121+
watcher, err = dm.Watch()
122+
release()
123+
if err != nil {
124+
return err
125+
}
119126
}
120127

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

127134
boardsError := ""
128135
if event.Type == "add" {
129-
boards, err := identify(pme, event.Port.Properties, s.settings, req.GetSkipCloudApiForBoardDetection())
136+
resp, err := s.BoardIdentify(context.Background(), &rpc.BoardIdentifyRequest{
137+
Instance: req.GetInstance(),
138+
Properties: event.Port.Properties.AsMap(),
139+
UseCloudApiForUnknownBoardDetection: !req.GetSkipCloudApiForBoardDetection(),
140+
})
130141
if err != nil {
131142
boardsError = err.Error()
143+
} else {
144+
port.MatchingBoards = resp.GetBoards()
132145
}
133-
port.MatchingBoards = boards
134146
}
135147
stream.Send(&rpc.BoardListWatchResponse{
136148
EventType: event.Type,

0 commit comments

Comments
 (0)