@@ -23,6 +23,7 @@ import (
23
23
"github.com/arduino/arduino-cli/commands/cmderrors"
24
24
"github.com/arduino/arduino-cli/commands/internal/instances"
25
25
f "github.com/arduino/arduino-cli/internal/algorithms"
26
+ "github.com/arduino/arduino-cli/internal/arduino/discovery/discoverymanager"
26
27
"github.com/arduino/arduino-cli/internal/i18n"
27
28
"github.com/arduino/arduino-cli/pkg/fqbn"
28
29
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
46
47
if err != nil {
47
48
return nil , err
48
49
}
49
- defer release ()
50
50
dm := pme .DiscoveryManager ()
51
51
warnings := f .Map (dm .Start (), (error ).Error )
52
+ release ()
52
53
time .Sleep (time .Duration (req .GetTimeout ()) * time .Millisecond )
53
54
54
55
ports := []* rpc.DetectedPort {}
55
56
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
+ })
57
62
if err != nil {
58
63
warnings = append (warnings , err .Error ())
59
64
}
@@ -62,7 +67,7 @@ func (s *arduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardLis
62
67
// API managed to recognize the connected board
63
68
b := & rpc.DetectedPort {
64
69
Port : rpc .DiscoveryPortToRPC (port ),
65
- MatchingBoards : boards ,
70
+ MatchingBoards : resp . GetBoards () ,
66
71
}
67
72
68
73
if fqbnFilter == nil || hasMatchingBoard (b , fqbnFilter ) {
@@ -106,16 +111,18 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s
106
111
return err
107
112
}
108
113
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
+ }
119
126
}
120
127
121
128
go func () {
@@ -126,11 +133,16 @@ func (s *arduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, s
126
133
127
134
boardsError := ""
128
135
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
+ })
130
141
if err != nil {
131
142
boardsError = err .Error ()
143
+ } else {
144
+ port .MatchingBoards = resp .GetBoards ()
132
145
}
133
- port .MatchingBoards = boards
134
146
}
135
147
stream .Send (& rpc.BoardListWatchResponse {
136
148
EventType : event .Type ,
0 commit comments