Skip to content

Commit

Permalink
add debug dev inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed Mar 27, 2024
1 parent e0490b6 commit e352931
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
55 changes: 52 additions & 3 deletions support/device/src/usb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,14 @@ impl Device {
}


pub fn inspect(&self) {
pub fn debug_inspect(&mut self) {
inspect_device(self.info());

// try interfaces:

self.open().unwrap();
// let device = self.

//
}
}
Expand All @@ -224,6 +230,49 @@ pub fn inspect_device(dev: &DeviceInfo) {
dev.manufacturer_string().unwrap_or(""),
dev.product_string().unwrap_or("")
);


{
let bulk = dev.data_interface();
println!("bulk interface: {:#?}", bulk);
}
println!("---");

{
use usb_ids::FromId;

println!("interfaces:");
for i in dev.interfaces() {
let class = usb_ids::Class::from_id(i.class());

let subclass_id = i.subclass();
let subs = class.unwrap()
.sub_classes()
.filter(|sub| sub.id() == subclass_id)
.collect::<Vec<_>>();
let n = i.interface_number();
let name = i.interface_string().unwrap_or("_");
let protocol_id = i.protocol();

println!("{n}: {name}");
println!("class: ({:#02x}) {:?}", i.class(), class.map(|c| c.name()));
for sub in subs {
println!(" sub: ({:#02x}) {}", sub.id(), sub.name());
let protocols = sub.protocols()
.filter(|p| p.id() == protocol_id)
.collect::<Vec<_>>();
if protocols.is_empty() {
println!(" unknown protocol: {protocol_id:#02x}");
}
for p in protocols {
println!(" protocol: ({:#02x}) {}", p.id(), p.name());
}
}
}
}
println!("---");


let dev = match dev.open() {
Ok(dev) => dev,
Err(e) => {
Expand All @@ -240,8 +289,8 @@ pub fn inspect_device(dev: &DeviceInfo) {
for config in dev.configurations() {
println!("{config:#?}");
}
println!("");
println!("");

println!("----------------\n");
}


Expand Down
4 changes: 2 additions & 2 deletions support/tool2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ async fn main() -> miette::Result<()> {
volumes_for_map(usb::discover::devices()?).await?
.into_iter()
.map(|(dev, vol)| (dev, vol.map(|v| v.path().to_path_buf())))
.for_each(|(dev, path)| {
dev.inspect();
.for_each(|(mut dev, path)| {
dev.debug_inspect();
println!("vol: {path:?}");
});
Ok(())
Expand Down

0 comments on commit e352931

Please sign in to comment.