@@ -40,7 +40,7 @@ import (
40
40
type Port struct {
41
41
address string
42
42
protocol string
43
- timeout time. Duration
43
+ timeout DiscoveryTimeout
44
44
}
45
45
46
46
// AddToCommand adds the flags used to set port and protocol to the specified Command
@@ -53,7 +53,7 @@ func (p *Port) AddToCommand(cmd *cobra.Command) {
53
53
cmd .RegisterFlagCompletionFunc ("protocol" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
54
54
return GetInstalledProtocols (), cobra .ShellCompDirectiveDefault
55
55
})
56
- cmd . Flags (). DurationVar ( & p .timeout , "discovery-timeout" , 5 * time . Second , tr ( "Max time to wait for port discovery, e.g.: 30s, 1m" ) )
56
+ p .timeout . AddToCommand ( cmd )
57
57
}
58
58
59
59
// GetPortAddressAndProtocol returns only the port address and the port protocol
@@ -127,7 +127,7 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
127
127
}
128
128
}()
129
129
130
- deadline := time .After (p .timeout )
130
+ deadline := time .After (p .timeout . Get () )
131
131
for {
132
132
select {
133
133
case portEvent := <- eventChan :
@@ -154,14 +154,17 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
154
154
155
155
// GetSearchTimeout returns the timeout
156
156
func (p * Port ) GetSearchTimeout () time.Duration {
157
- return p .timeout
157
+ return p .timeout . Get ()
158
158
}
159
159
160
160
// DetectFQBN tries to identify the board connected to the port and returns the
161
161
// discovered Port object together with the FQBN. If the port does not match
162
162
// exactly 1 board,
163
163
func (p * Port ) DetectFQBN (inst * rpc.Instance ) (string , * rpc.Port ) {
164
- detectedPorts , err := board .List (& rpc.BoardListRequest {Instance : inst })
164
+ detectedPorts , err := board .List (& rpc.BoardListRequest {
165
+ Instance : inst ,
166
+ Timeout : p .timeout .Get ().Milliseconds (),
167
+ })
165
168
if err != nil {
166
169
feedback .Errorf (tr ("Error during FQBN detection: %v" , err ))
167
170
os .Exit (errorcodes .ErrGeneric )
0 commit comments