Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a1fad63

Browse files
committed
Upload port detector improvements (#2288)
* If the upload port-detector fails detection, fallback to the user-provided port This will ensure that a port is always returned. * Increased debug level * Extend timeout if candidate port is lost in any case Even if `waitForUploadPort` is true, we should extend the timeout to allow USB enumeration to complete. In this case we extend by only 1 second instead of 5. * Revert "Extend timeout if candidate port is lost in any case" This reverts commit 7c77ed2. The latest commit is not necessary since the detector has already 5 seconds of timeout.
1 parent 98c0480 commit a1fad63

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

‎commands/upload/upload.go‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,8 @@ func runProgramAction(pme *packagemanager.Explorer,
519519

520520
updatedPort := updatedUploadPort.Await()
521521
if updatedPort == nil {
522-
return nil, nil
522+
// If the algorithms can not detect the new port, fallback to the user-provided port.
523+
return userPort, nil
523524
}
524525
return updatedPort.ToRPC(), nil
525526
}
@@ -531,7 +532,7 @@ func detectUploadPort(
531532
result f.Future[*discovery.Port],
532533
) {
533534
log := logrus.WithField("task", "port_detection")
534-
log.Tracef("Detecting new board port after upload")
535+
log.Debugf("Detecting new board port after upload")
535536

536537
candidate := uploadPort.Clone()
537538
defer func() {
@@ -547,11 +548,11 @@ func detectUploadPort(
547548
return
548549
}
549550
if candidate != nil && ev.Type == "remove" && ev.Port.Equals(candidate) {
550-
log.WithField("event", ev).Trace("User-specified port has been disconnected, forcing wait for upload port")
551+
log.WithField("event", ev).Debug("User-specified port has been disconnected, forcing wait for upload port")
551552
waitForUploadPort = true
552553
candidate = nil
553554
} else {
554-
log.WithField("event", ev).Trace("Ignored watcher event before upload")
555+
log.WithField("event", ev).Debug("Ignored watcher event before upload")
555556
}
556557
continue
557558
case <-uploadCtx.Done():
@@ -573,17 +574,17 @@ func detectUploadPort(
573574
return
574575
}
575576
if candidate != nil && ev.Type == "remove" && candidate.Equals(ev.Port) {
576-
log.WithField("event", ev).Trace("Candidate port is no longer available")
577+
log.WithField("event", ev).Debug("Candidate port is no longer available")
577578
candidate = nil
578579
if !waitForUploadPort {
579580
waitForUploadPort = true
580581
timeout = time.After(5 * time.Second)
581-
log.Trace("User-specified port has been disconnected, now waiting for upload port, timeout extended by 5 seconds")
582+
log.Debug("User-specified port has been disconnected, now waiting for upload port, timeout extended by 5 seconds")
582583
}
583584
continue
584585
}
585586
if ev.Type != "add" {
586-
log.WithField("event", ev).Trace("Ignored non-add event")
587+
log.WithField("event", ev).Debug("Ignored non-add event")
587588
continue
588589
}
589590

@@ -606,21 +607,21 @@ func detectUploadPort(
606607
evPortPriority := portPriority(ev.Port)
607608
candidatePriority := portPriority(candidate)
608609
if evPortPriority <= candidatePriority {
609-
log.WithField("event", ev).Tracef("New upload port candidate is worse than the current one (prio=%d)", evPortPriority)
610+
log.WithField("event", ev).Debugf("New upload port candidate is worse than the current one (prio=%d)", evPortPriority)
610611
continue
611612
}
612-
log.WithField("event", ev).Tracef("Found new upload port candidate (prio=%d)", evPortPriority)
613+
log.WithField("event", ev).Debugf("Found new upload port candidate (prio=%d)", evPortPriority)
613614
candidate = ev.Port
614615

615616
// If the current candidate have the desired HW-ID return it quickly.
616617
if candidate.HardwareID == ev.Port.HardwareID {
617618
timeout = time.After(time.Second)
618-
log.Trace("New candidate port match the desired HW ID, timeout reduced to 1 second.")
619+
log.Debug("New candidate port match the desired HW ID, timeout reduced to 1 second.")
619620
continue
620621
}
621622

622623
case <-timeout:
623-
log.WithField("selected_port", candidate).Trace("Timeout waiting for candidate port")
624+
log.WithField("selected_port", candidate).Debug("Timeout waiting for candidate port")
624625
return
625626
}
626627
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /