Skip to content
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

Don't fail on uhubctl error, primitive guard for uhubctl #13

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Changes from all commits
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
11 changes: 9 additions & 2 deletions teleprobe/src/probe/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
mod specifier;

use std::process::Command;
use std::sync::Mutex;
use anyhow::{bail, Result};
use clap::Parser;
use probe_rs::{DebugProbeInfo, MemoryInterface, Permissions, Probe, Session};
pub use specifier::ProbeSpecifier;

static UHUBCTL_MUTEX: Mutex<()> = Mutex::new(());

#[derive(Clone, Parser)]
pub struct Opts {
/// The probe to use (specified by eg. `VID:PID`, `VID:PID:Serial`, or just `Serial`).
Expand Down Expand Up @@ -60,7 +63,9 @@ pub fn connect(opts: &Opts) -> Result<Session> {
bail!("power reset requires a serial number");
}
log::debug!("probe power reset");
power_reset(&probes[0].serial_number.as_ref().unwrap())?;
if let Err(err) = power_reset(&probes[0].serial_number.as_ref().unwrap()){
log::warn!("power reset failed for: {}", err);
}
}
probes = get_probe(&opts)?;
}
Expand Down Expand Up @@ -166,20 +171,22 @@ pub fn probes_filter(probes: &[DebugProbeInfo], selector: &ProbeSpecifier) -> Ve

#[cfg(feature = "power_reset")]
fn power_reset(probe_serial: &str) -> Result<()> {
let _guard = UHUBCTL_MUTEX.lock();
let output = Command::new("uhubctl")
.arg("-a")
.arg("cycle")
.arg("-s")
.arg(probe_serial)
.output();
drop(_guard);

match output {
Ok(output) => {
if output.status.success() {
std::thread::sleep(std::time::Duration::from_millis(1000));
Ok(())
} else {
bail!("uhubctl failed: {}", String::from_utf8_lossy(&output.stderr))
bail!("uhubctl failed for serial \'{}\': {}", probe_serial, String::from_utf8_lossy(&output.stderr))
}
}
Err(e) => bail!("uhubctl failed: {}", e)
Expand Down
Loading