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

Appearance settings

feature: Detect board port change after upload #2253

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 18 commits into from
Aug 18, 2023
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
Improved tracking algorithm for upload-port reconnection
The new algorithm takes into account the case where a single board may
expose multiple ports, in this case the selection will increase priority
to ports that:

  1. have the same HW id as the user specified port for upload
  2. have the same protocol as the user specified port for upload
  3. have the same address as the user specified port for upload
  • Loading branch information
cmaglie committed Aug 16, 2023
commit 862bbe243b0762ca92a41c9de12797f8195e1cf4
38 changes: 29 additions & 9 deletions 38 commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ func detectUploadPort(
}

// Pick the first port that is detected after the upload
desiredHwID := uploadPort.HardwareID
timeout := time.After(5 * time.Second)
if !waitForUploadPort {
timeout = time.After(time.Second)
Expand All @@ -582,20 +581,41 @@ func detectUploadPort(
log.WithField("event", ev).Trace("Ignored non-add event")
continue
}

portPriority := func(port *discovery.Port) int {
if port == nil {
return 0
}
prio := 0
if port.HardwareID == uploadPort.HardwareID {
prio += 1000
}
if port.Protocol == uploadPort.Protocol {
prio += 100
}
if port.Address == uploadPort.Address {
prio += 10
}
return prio
}
evPortPriority := portPriority(ev.Port)
candidatePriority := portPriority(candidate)
if evPortPriority <= candidatePriority {
log.WithField("event", ev).Tracef("New upload port candidate is worse than the current one (prio=%d)", evPortPriority)
continue
}
log.WithField("event", ev).Tracef("Found new upload port candidate (prio=%d)", evPortPriority)
candidate = ev.Port
log.WithField("event", ev).Trace("New upload port candidate")

// If the current candidate port does not have the desired HW-ID do
// not return it immediately.
if desiredHwID != "" && candidate.HardwareID != desiredHwID {
log.Trace("New candidate port did not match desired HW ID, keep watching...")
// If the current candidate have the desired HW-ID return it quickly.
if candidate.HardwareID == ev.Port.HardwareID {
timeout = time.After(time.Second)
log.Trace("New candidate port match the desired HW ID, timeout reduced to 1 second.")
continue
}

log.Trace("Found new upload port!")
return
case <-timeout:
log.Trace("Timeout waiting for candidate port")
log.WithField("selected_port", candidate).Trace("Timeout waiting for candidate port")
return
}
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.